rasengan 1.0.0-beta.7 → 1.0.0-beta.8

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.
Files changed (123) hide show
  1. package/lib/cjs/cli/dirname.js +16 -0
  2. package/lib/cjs/cli/index.js +154 -0
  3. package/lib/cjs/config/index.js +140 -0
  4. package/lib/cjs/config/type.js +2 -0
  5. package/lib/cjs/core/components/index.js +178 -0
  6. package/lib/cjs/core/index.js +6 -0
  7. package/lib/cjs/core/interfaces.js +189 -0
  8. package/lib/cjs/core/types.js +2 -0
  9. package/lib/cjs/decorators/index.js +1 -0
  10. package/lib/cjs/decorators/route.js +24 -0
  11. package/lib/cjs/decorators/router.js +38 -0
  12. package/lib/cjs/decorators/types.js +2 -0
  13. package/lib/cjs/entries/entry-client.js +40 -0
  14. package/lib/cjs/entries/entry-server.js +80 -0
  15. package/lib/cjs/index.js +28 -0
  16. package/lib/cjs/routing/components/index.js +114 -0
  17. package/lib/cjs/routing/index.js +26 -0
  18. package/lib/cjs/routing/interfaces.js +94 -0
  19. package/lib/cjs/routing/types.js +2 -0
  20. package/lib/cjs/routing/utils/index.js +413 -0
  21. package/lib/cjs/scripts/generate-package-json.js +28 -0
  22. package/lib/cjs/scripts/refresh-hack.js +24 -0
  23. package/lib/cjs/server/functions/vercel/api/index.js +155 -0
  24. package/lib/cjs/server/utils/createFetchRequest.js +38 -0
  25. package/lib/cjs/server/utils/getIp.js +35 -0
  26. package/lib/cjs/server/utils/handleError.js +46 -0
  27. package/lib/cjs/server/utils/index.js +15 -0
  28. package/lib/cjs/server/utils/log.js +126 -0
  29. package/lib/esm/cli/dirname.js +14 -0
  30. package/lib/esm/cli/index.js +149 -0
  31. package/lib/esm/config/index.js +135 -0
  32. package/lib/esm/core/components/index.js +144 -0
  33. package/lib/esm/core/index.js +1 -0
  34. package/lib/esm/core/interfaces.js +183 -0
  35. package/lib/esm/decorators/index.js +1 -0
  36. package/lib/{decorators → esm/decorators}/router.js +5 -5
  37. package/lib/esm/entries/entry-client.js +12 -0
  38. package/lib/esm/entries/entry-server.js +49 -0
  39. package/lib/{index.js → esm/index.js} +1 -2
  40. package/lib/{routing → esm/routing}/components/index.js +40 -16
  41. package/lib/{routing → esm/routing}/index.js +4 -1
  42. package/lib/esm/routing/interfaces.js +91 -0
  43. package/lib/esm/routing/utils/index.js +404 -0
  44. package/lib/esm/scripts/generate-package-json.js +23 -0
  45. package/lib/esm/scripts/refresh-hack.js +22 -0
  46. package/lib/esm/server/functions/vercel/api/index.js +126 -0
  47. package/lib/esm/server/functions/vercel/vercel.json +16 -0
  48. package/lib/{server → esm/server}/utils/createFetchRequest.js +11 -9
  49. package/lib/{server → esm/server}/utils/getIp.js +6 -6
  50. package/lib/{server → esm/server}/utils/handleError.js +1 -9
  51. package/lib/esm/server/utils/log.js +119 -0
  52. package/lib/types/cli/dirname.d.ts +2 -0
  53. package/lib/{config → types/config}/index.d.ts +2 -0
  54. package/lib/{config → types/config}/type.d.ts +7 -0
  55. package/lib/types/core/components/index.d.ts +50 -0
  56. package/lib/types/core/index.d.ts +3 -0
  57. package/lib/{core → types/core}/interfaces.d.ts +1 -1
  58. package/lib/types/core/types.d.ts +142 -0
  59. package/lib/types/decorators/index.d.ts +0 -0
  60. package/lib/{decorators → types/decorators}/types.d.ts +2 -2
  61. package/lib/{entries → types/entries}/entry-server.d.ts +8 -0
  62. package/lib/types/hooks/index.d.ts +0 -0
  63. package/lib/{index.d.ts → types/index.d.ts} +1 -1
  64. package/lib/{routing → types/routing}/components/index.d.ts +3 -3
  65. package/lib/{routing → types/routing}/index.d.ts +1 -1
  66. package/lib/{routing → types/routing}/interfaces.d.ts +1 -1
  67. package/lib/types/routing/types.d.ts +48 -0
  68. package/lib/{routing → types/routing}/utils/index.d.ts +2 -1
  69. package/lib/types/scripts/generate-package-json.d.ts +1 -0
  70. package/lib/types/scripts/refresh-hack.d.ts +1 -0
  71. package/package.json +40 -17
  72. package/server.js +52 -51
  73. package/tsconfig.base.json +29 -0
  74. package/tsconfig.cjs.json +8 -0
  75. package/tsconfig.esm.json +8 -0
  76. package/tsconfig.json +24 -26
  77. package/tsconfig.types.json +9 -0
  78. package/types/client.d.ts +2 -0
  79. package/vite.config.ts +15 -4
  80. package/lib/cli/dirname.d.ts +0 -2
  81. package/lib/cli/dirname.js +0 -5
  82. package/lib/cli/index.js +0 -99
  83. package/lib/config/index.js +0 -106
  84. package/lib/core/components/index.d.ts +0 -22
  85. package/lib/core/components/index.js +0 -67
  86. package/lib/core/index.d.ts +0 -2
  87. package/lib/core/index.js +0 -1
  88. package/lib/core/interfaces.js +0 -114
  89. package/lib/core/types.d.ts +0 -45
  90. package/lib/decorators/index.d.ts +0 -2
  91. package/lib/decorators/index.js +0 -2
  92. package/lib/entries/entry-client.js +0 -14
  93. package/lib/entries/entry-server.js +0 -21
  94. package/lib/routing/interfaces.js +0 -87
  95. package/lib/routing/types.d.ts +0 -16
  96. package/lib/routing/utils/index.js +0 -260
  97. package/lib/server/functions/vercel/_rasengan/server/index.js +0 -91
  98. package/lib/server/functions/vercel/api/index.d.ts +0 -2
  99. package/lib/server/functions/vercel/api/index.js +0 -91
  100. package/lib/server/utils/log.js +0 -74
  101. package/tsconfig.lib.json +0 -41
  102. package/tsconfig.node.json +0 -11
  103. package/types/image.d.ts +0 -44
  104. package/types/style.d.ts +0 -4
  105. /package/lib/{hooks → cjs/hooks}/index.js +0 -0
  106. /package/lib/{server → cjs/server}/functions/vercel/vercel.json +0 -0
  107. /package/lib/{config → esm/config}/type.js +0 -0
  108. /package/lib/{core → esm/core}/types.js +0 -0
  109. /package/lib/{decorators → esm/decorators}/route.js +0 -0
  110. /package/lib/{decorators → esm/decorators}/types.js +0 -0
  111. /package/lib/{hooks/index.d.ts → esm/hooks/index.js} +0 -0
  112. /package/lib/{routing → esm/routing}/types.js +0 -0
  113. /package/lib/{server → esm/server}/utils/index.js +0 -0
  114. /package/lib/{cli → types/cli}/index.d.ts +0 -0
  115. /package/lib/{decorators → types/decorators}/route.d.ts +0 -0
  116. /package/lib/{decorators → types/decorators}/router.d.ts +0 -0
  117. /package/lib/{entries → types/entries}/entry-client.d.ts +0 -0
  118. /package/lib/{server/functions/vercel/_rasengan/server → types/server/functions/vercel/api}/index.d.ts +0 -0
  119. /package/lib/{server → types/server}/utils/createFetchRequest.d.ts +0 -0
  120. /package/lib/{server → types/server}/utils/getIp.d.ts +0 -0
  121. /package/lib/{server → types/server}/utils/handleError.d.ts +0 -0
  122. /package/lib/{server → types/server}/utils/index.d.ts +0 -0
  123. /package/lib/{server → types/server}/utils/log.d.ts +0 -0
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ var node_url_1 = require("node:url");
4
+ var node_path_1 = require("node:path");
5
+ function getDirname() {
6
+ if (typeof exports === 'object' && typeof module !== 'undefined') {
7
+ return __dirname;
8
+ }
9
+ else {
10
+ // @ts-ignore
11
+ var __filename_1 = (0, node_url_1.fileURLToPath)(import.meta.url);
12
+ var __dirname_1 = (0, node_path_1.dirname)(__filename_1);
13
+ return __dirname_1;
14
+ }
15
+ }
16
+ exports.default = getDirname();
@@ -0,0 +1,154 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ var __assign = (this && this.__assign) || function () {
4
+ __assign = Object.assign || function(t) {
5
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
6
+ s = arguments[i];
7
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
8
+ t[p] = s[p];
9
+ }
10
+ return t;
11
+ };
12
+ return __assign.apply(this, arguments);
13
+ };
14
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
15
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
16
+ return new (P || (P = Promise))(function (resolve, reject) {
17
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
18
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
19
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
20
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
21
+ });
22
+ };
23
+ var __generator = (this && this.__generator) || function (thisArg, body) {
24
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
25
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
26
+ function verb(n) { return function (v) { return step([n, v]); }; }
27
+ function step(op) {
28
+ if (f) throw new TypeError("Generator is already executing.");
29
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
30
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
31
+ if (y = 0, t) op = [op[0] & 2, t.value];
32
+ switch (op[0]) {
33
+ case 0: case 1: t = op; break;
34
+ case 4: _.label++; return { value: op[1], done: false };
35
+ case 5: _.label++; y = op[1]; op = [0]; continue;
36
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
37
+ default:
38
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
39
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
40
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
41
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
42
+ if (t[2]) _.ops.pop();
43
+ _.trys.pop(); continue;
44
+ }
45
+ op = body.call(thisArg, _);
46
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
47
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
48
+ }
49
+ };
50
+ var __importDefault = (this && this.__importDefault) || function (mod) {
51
+ return (mod && mod.__esModule) ? mod : { "default": mod };
52
+ };
53
+ Object.defineProperty(exports, "__esModule", { value: true });
54
+ var chalk_1 = __importDefault(require("chalk"));
55
+ var commander_1 = require("commander");
56
+ var execa_1 = require("execa");
57
+ // Config
58
+ // @ts-ignore
59
+ var rasengan_config_js_1 = __importDefault(require("../../../../../rasengan.config.js"));
60
+ var program = new commander_1.Command();
61
+ program
62
+ .name(chalk_1.default.blue("rasengan"))
63
+ .version("1.0.0", "-v, --version", "Output the current version number");
64
+ // Handle the dev command
65
+ program
66
+ .command("dev")
67
+ .option("-p <port>")
68
+ .description("Start development server")
69
+ .action(function (_a) {
70
+ var port = _a.p;
71
+ return __awaiter(void 0, void 0, void 0, function () {
72
+ var convertedPort;
73
+ return __generator(this, function (_b) {
74
+ convertedPort = Number(port);
75
+ // Checking port
76
+ if (port &&
77
+ (isNaN(convertedPort) || convertedPort < 0 || convertedPort > 65535)) {
78
+ console.log("");
79
+ console.log(chalk_1.default.red("Please provide a valid port number between 0-65535"));
80
+ console.log("");
81
+ process.exit(1);
82
+ }
83
+ (0, execa_1.execa)("node", ["node_modules/rasengan/server"], {
84
+ stdio: "inherit",
85
+ env: __assign(__assign({}, process.env), { PORT: convertedPort ? convertedPort.toString() : undefined }),
86
+ });
87
+ return [2 /*return*/];
88
+ });
89
+ });
90
+ });
91
+ // Handle the build command
92
+ program
93
+ .command("build")
94
+ .description("Build the project")
95
+ .action(function () {
96
+ (0, execa_1.execa)("npm", ["run", "build"], {
97
+ cwd: "node_modules/rasengan",
98
+ stdio: "inherit", // Pipe child process output to the parent process
99
+ });
100
+ });
101
+ // Handle the prebuild command
102
+ program
103
+ .command("prepare")
104
+ .description("Prepare the project")
105
+ .action(function () {
106
+ var _a, _b;
107
+ // Displaying the message
108
+ console.log("");
109
+ console.log(chalk_1.default.blue("Preparing your project for production..."));
110
+ console.log("");
111
+ // Checking the config file in order to know about hosting strategy
112
+ var server = rasengan_config_js_1.default.server;
113
+ var hostingStrategy = (_b = (_a = server === null || server === void 0 ? void 0 : server.production) === null || _a === void 0 ? void 0 : _a.hosting) !== null && _b !== void 0 ? _b : "custom";
114
+ if (hostingStrategy === "vercel") {
115
+ // Displaying the message
116
+ console.log("Your project is configured to be hosted on ".concat(chalk_1.default.bold.blue(hostingStrategy), "\n"));
117
+ // Copying the api folder to the root directory
118
+ (0, execa_1.execa)("cp", ["-r", "node_modules/rasengan/lib/server/functions/vercel/api", "."], {
119
+ stdio: "inherit",
120
+ });
121
+ // Copying the vercel.json file to the root directory
122
+ (0, execa_1.execa)("cp", ["node_modules/rasengan/lib/server/functions/vercel/vercel.json", "."], {
123
+ stdio: "inherit",
124
+ });
125
+ // Removing index.d.ts and index.js.map files from the api folder
126
+ (0, execa_1.execa)("rm", ["api/index.d.ts"], {
127
+ stdio: "inherit",
128
+ });
129
+ }
130
+ else if (hostingStrategy === "netlify") {
131
+ // Copying the netlify.toml file to the root directory
132
+ // execa(
133
+ // "cp",
134
+ // ["node_modules/rasengan/src/server/functions/netlify/netlify.toml", "."],
135
+ // {
136
+ // stdio: "inherit",
137
+ // }
138
+ // );
139
+ }
140
+ });
141
+ // Handle the start command
142
+ program
143
+ .command("start")
144
+ .description("Start the project in production mode")
145
+ .action(function () { return __awaiter(void 0, void 0, void 0, function () {
146
+ return __generator(this, function (_a) {
147
+ (0, execa_1.execa)("npm", ["run", "preview"], {
148
+ cwd: "node_modules/rasengan",
149
+ stdio: "inherit", // Pipe child process output to the parent process
150
+ });
151
+ return [2 /*return*/];
152
+ });
153
+ }); });
154
+ program.parse(process.argv);
@@ -0,0 +1,140 @@
1
+ "use strict";
2
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
3
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
4
+ if (ar || !(i in from)) {
5
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
6
+ ar[i] = from[i];
7
+ }
8
+ }
9
+ return to.concat(ar || Array.prototype.slice.call(from));
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.adaptPath = exports.defineConfig = void 0;
13
+ /**
14
+ * Function to define the config for the app
15
+ * It will be used by vite.config.ts and other files in other to configure the app
16
+ * @param {AppConfig} loadedConfig
17
+ */
18
+ var defineConfig = function (loadedConfig) {
19
+ var _a, _b, _c, _d, _e, _f, _g, _h;
20
+ var reactStrictMode = loadedConfig.reactStrictMode, server = loadedConfig.server, vite = loadedConfig.vite;
21
+ // Define default values for vite config coming from loadedConfig.vite
22
+ var defaultViteConfig = {
23
+ plugins: (vite === null || vite === void 0 ? void 0 : vite.plugins) || [],
24
+ optimizeDeps: {
25
+ exclude: ((_a = vite === null || vite === void 0 ? void 0 : vite.optimizeDeps) === null || _a === void 0 ? void 0 : _a.exclude) || [],
26
+ include: ((_b = vite === null || vite === void 0 ? void 0 : vite.optimizeDeps) === null || _b === void 0 ? void 0 : _b.include) || [],
27
+ },
28
+ css: {
29
+ postcss: ((_c = vite === null || vite === void 0 ? void 0 : vite.css) === null || _c === void 0 ? void 0 : _c.postcss) || undefined,
30
+ },
31
+ build: {
32
+ external: ((_d = vite === null || vite === void 0 ? void 0 : vite.build) === null || _d === void 0 ? void 0 : _d.external) || [],
33
+ },
34
+ resolve: {
35
+ alias: ((_e = vite === null || vite === void 0 ? void 0 : vite.resolve) === null || _e === void 0 ? void 0 : _e.alias) || [],
36
+ },
37
+ };
38
+ // Define default values for server config coming from loadedConfig.server
39
+ var defaultServerConfig = {
40
+ development: {
41
+ port: ((_f = server === null || server === void 0 ? void 0 : server.development) === null || _f === void 0 ? void 0 : _f.port) || undefined,
42
+ open: ((_g = server === null || server === void 0 ? void 0 : server.development) === null || _g === void 0 ? void 0 : _g.open) || false,
43
+ },
44
+ production: {
45
+ hosting: ((_h = server === null || server === void 0 ? void 0 : server.production) === null || _h === void 0 ? void 0 : _h.hosting) || "custom",
46
+ },
47
+ };
48
+ try {
49
+ var config = {
50
+ reactStrictMode: reactStrictMode === undefined ? true : reactStrictMode,
51
+ server: defaultServerConfig,
52
+ vite: {
53
+ plugins: defaultViteConfig.plugins,
54
+ optimizeDeps: {
55
+ exclude: __spreadArray([
56
+ "node:http",
57
+ "node-fetch"
58
+ ], defaultViteConfig.optimizeDeps.exclude, true),
59
+ include: __spreadArray([
60
+ "react-fast-compare",
61
+ "invariant",
62
+ "shallowequal",
63
+ "react-dom/client",
64
+ "react-dom",
65
+ "react",
66
+ "react-router-dom",
67
+ "react-helmet-async"
68
+ ], defaultViteConfig.optimizeDeps.include, true),
69
+ },
70
+ css: {
71
+ postcss: defaultViteConfig.css.postcss,
72
+ },
73
+ build: {
74
+ external: defaultViteConfig.build.external,
75
+ },
76
+ resolve: {
77
+ // concat two arrays
78
+ alias: __spreadArray([
79
+ {
80
+ find: "@/",
81
+ replacement: "src/",
82
+ }
83
+ ], defaultViteConfig.resolve.alias, true),
84
+ },
85
+ appType: "custom",
86
+ },
87
+ // More config options...
88
+ };
89
+ return config;
90
+ }
91
+ catch (error) {
92
+ console.error(error);
93
+ return {
94
+ reactStrictMode: true,
95
+ vite: {
96
+ optimizeDeps: {
97
+ exclude: ["node:http", "node-fetch"],
98
+ include: [
99
+ "react-fast-compare",
100
+ "invariant",
101
+ "shallowequal",
102
+ "react-dom/client",
103
+ "react-dom",
104
+ "react",
105
+ "react-router-dom",
106
+ "react-helmet-async",
107
+ ],
108
+ },
109
+ appType: "custom",
110
+ resolve: {
111
+ alias: [
112
+ {
113
+ find: "@/",
114
+ replacement: "src/",
115
+ },
116
+ ],
117
+ },
118
+ },
119
+ };
120
+ }
121
+ };
122
+ exports.defineConfig = defineConfig;
123
+ /**
124
+ * Function to adapt the path for dev and prod
125
+ * @param {string | Array<string>} paths
126
+ */
127
+ var adaptPath = function (paths) {
128
+ // Check if we are in dev mode or prod
129
+ var isProduction = process.env.NODE_ENV === "production";
130
+ var prefix = isProduction ? "./../../../" : "";
131
+ // Chech if the path is an array
132
+ var isArray = Array.isArray(paths);
133
+ // If the path is an array
134
+ if (isArray) {
135
+ return paths.map(function (path) { return "".concat(prefix).concat(path); });
136
+ }
137
+ // If the path is a string
138
+ return "".concat(prefix).concat(paths);
139
+ };
140
+ exports.adaptPath = adaptPath;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,178 @@
1
+ "use strict";
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ if (typeof b !== "function" && b !== null)
11
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
+ extendStatics(d, b);
13
+ function __() { this.constructor = d; }
14
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
+ };
16
+ })();
17
+ var __assign = (this && this.__assign) || function () {
18
+ __assign = Object.assign || function(t) {
19
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
20
+ s = arguments[i];
21
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
22
+ t[p] = s[p];
23
+ }
24
+ return t;
25
+ };
26
+ return __assign.apply(this, arguments);
27
+ };
28
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
29
+ if (k2 === undefined) k2 = k;
30
+ var desc = Object.getOwnPropertyDescriptor(m, k);
31
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
32
+ desc = { enumerable: true, get: function() { return m[k]; } };
33
+ }
34
+ Object.defineProperty(o, k2, desc);
35
+ }) : (function(o, m, k, k2) {
36
+ if (k2 === undefined) k2 = k;
37
+ o[k2] = m[k];
38
+ }));
39
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
40
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
41
+ }) : function(o, v) {
42
+ o["default"] = v;
43
+ });
44
+ var __importStar = (this && this.__importStar) || function (mod) {
45
+ if (mod && mod.__esModule) return mod;
46
+ var result = {};
47
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
48
+ __setModuleDefault(result, mod);
49
+ return result;
50
+ };
51
+ var __importDefault = (this && this.__importDefault) || function (mod) {
52
+ return (mod && mod.__esModule) ? mod : { "default": mod };
53
+ };
54
+ Object.defineProperty(exports, "__esModule", { value: true });
55
+ exports.DefaultLayout = exports.Scripts = exports.Body = exports.Heads = exports.ErrorBoundary = exports.PageToRender = exports.Component = void 0;
56
+ var jsx_runtime_1 = require("react/jsx-runtime");
57
+ var react_1 = __importDefault(require("react"));
58
+ var index_js_1 = require("../../routing/utils/index.js");
59
+ var react_router_dom_1 = require("react-router-dom");
60
+ var HelmetAsync = __importStar(require("react-helmet-async"));
61
+ // @ts-ignore
62
+ var H = HelmetAsync.default ? HelmetAsync.default : HelmetAsync;
63
+ /**
64
+ * App component that represent the entry point of the application
65
+ */
66
+ var Component = function (_a) {
67
+ var AppRouter = _a.router, _b = _a.children, children = _b === void 0 ? undefined : _b;
68
+ // Return children if they exist
69
+ if (children)
70
+ return children;
71
+ var Router = null;
72
+ // Otherwise, get the router and return it
73
+ Router = (0, index_js_1.getRouter)(AppRouter);
74
+ return (0, jsx_runtime_1.jsx)(Router, {});
75
+ };
76
+ exports.Component = Component;
77
+ /**
78
+ * Page component that defines title and description to a page
79
+ */
80
+ var PageToRender = function (_a) {
81
+ var _b, _c;
82
+ var Page = _a.page, data = _a.data;
83
+ // Get the page props
84
+ var props = data.props || {};
85
+ // Generate meta tags
86
+ var metaTags = react_1.default.useMemo(function () {
87
+ if (!Page.metadata)
88
+ return [];
89
+ return (0, index_js_1.generateMetadata)([Page.metadata]);
90
+ }, []);
91
+ return ((0, jsx_runtime_1.jsxs)(react_1.default.Fragment, { children: [(0, jsx_runtime_1.jsxs)(H.Helmet, { children: [metaTags.map(function (meta) { return meta; }), (0, jsx_runtime_1.jsx)("meta", { name: "description", content: ((_b = Page.metadata) === null || _b === void 0 ? void 0 : _b.description) || "" }), (0, jsx_runtime_1.jsx)("title", { children: ((_c = Page.metadata) === null || _c === void 0 ? void 0 : _c.title) || Page.name })] }), (0, jsx_runtime_1.jsx)(Page, __assign({}, props))] }));
92
+ };
93
+ exports.PageToRender = PageToRender;
94
+ /**
95
+ * Error fallback component that will be displayed if an error occurs
96
+ */
97
+ var ErrorBoundary = /** @class */ (function (_super) {
98
+ __extends(ErrorBoundary, _super);
99
+ function ErrorBoundary() {
100
+ var _this = _super !== null && _super.apply(this, arguments) || this;
101
+ _this.state = { hasError: false, error: null, info: null };
102
+ return _this;
103
+ }
104
+ ErrorBoundary.prototype.componentDidCatch = function (error, info) {
105
+ this.setState({ hasError: true, error: error, info: info });
106
+ };
107
+ ErrorBoundary.prototype.render = function () {
108
+ var _a = this.state, error = _a.error, info = _a.info;
109
+ if (this.state.hasError) {
110
+ return (0, jsx_runtime_1.jsx)(ErrorFallbackComponent, { error: error, info: info });
111
+ }
112
+ // @ts-ignore
113
+ return this.props.children;
114
+ };
115
+ return ErrorBoundary;
116
+ }(react_1.default.Component));
117
+ exports.ErrorBoundary = ErrorBoundary;
118
+ /**
119
+ * Error fallback component that will be displayed if an error occurs
120
+ */
121
+ var ErrorFallbackComponent = function (_a) {
122
+ var error = _a.error, info = _a.info;
123
+ return ((0, jsx_runtime_1.jsx)("div", { style: {
124
+ width: "calc(100% - 80px)",
125
+ height: "calc(100vh - 80px)",
126
+ padding: "40px",
127
+ backgroundColor: "#fff",
128
+ }, children: (0, jsx_runtime_1.jsxs)("div", { children: [(0, jsx_runtime_1.jsx)("h1", { style: { fontSize: "2rem" }, children: "Something went wrong" }), (0, jsx_runtime_1.jsx)("p", { children: error.toString() }), (0, jsx_runtime_1.jsx)("div", { style: {
129
+ width: "100%",
130
+ height: "auto",
131
+ borderRadius: 10,
132
+ padding: "20px",
133
+ marginTop: "10px",
134
+ backgroundColor: "#f0f0f0",
135
+ }, children: (0, jsx_runtime_1.jsx)("p", { children: info.componentStack }) })] }) }));
136
+ };
137
+ /**
138
+ * Head component
139
+ * @params data - Helmet context
140
+ * @returns
141
+ */
142
+ var Heads = function (_a) {
143
+ var data = _a.data, _b = _a.children, children = _b === void 0 ? undefined : _b, _c = _a.bootstrap, bootstrap = _c === void 0 ? "" : _c;
144
+ if (!data)
145
+ return null;
146
+ return ((0, jsx_runtime_1.jsxs)("head", { children: [children, data.helmet && data.helmet.meta.toComponent({}), data.helmet && data.helmet.title.toComponent({}), bootstrap && ((0, jsx_runtime_1.jsx)("script", { type: "module", src: bootstrap, defer: true }))] }));
147
+ };
148
+ exports.Heads = Heads;
149
+ /**
150
+ * Body component
151
+ */
152
+ var Body = function (_a) {
153
+ var _b = _a.children, children = _b === void 0 ? undefined : _b;
154
+ return ((0, jsx_runtime_1.jsxs)("body", { children: [(0, jsx_runtime_1.jsx)("noscript", { dangerouslySetInnerHTML: {
155
+ __html: "<b>Enable JavaScript to run this app.</b>",
156
+ } }), (0, jsx_runtime_1.jsx)("div", { id: "root", children: "rasengan-body-app" }), children] }));
157
+ };
158
+ exports.Body = Body;
159
+ /**
160
+ * Scripts component
161
+ */
162
+ var Scripts = function (_a) {
163
+ var _b = _a.children, children = _b === void 0 ? undefined : _b, _c = _a.bootstrap, bootstrap = _c === void 0 ? "" : _c;
164
+ var folder = "esm";
165
+ if (typeof exports === "object" && typeof module !== "undefined") {
166
+ folder = "cjs";
167
+ }
168
+ return ((0, jsx_runtime_1.jsxs)(react_1.default.Fragment, { children: [bootstrap === "" && ((0, jsx_runtime_1.jsx)("script", { type: "module", src: "/node_modules/rasengan/lib/".concat(folder, "/entries/entry-client.js"), defer: true })), children] }));
169
+ };
170
+ exports.Scripts = Scripts;
171
+ /**
172
+ * Default layout component
173
+ */
174
+ var DefaultLayout = function () {
175
+ return ((0, jsx_runtime_1.jsx)(react_1.default.Fragment, { children: (0, jsx_runtime_1.jsx)(react_router_dom_1.Outlet, {}) }));
176
+ };
177
+ exports.DefaultLayout = DefaultLayout;
178
+ DefaultLayout.path = "/";
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Scripts = exports.Body = void 0;
4
+ var index_js_1 = require("./components/index.js");
5
+ Object.defineProperty(exports, "Body", { enumerable: true, get: function () { return index_js_1.Body; } });
6
+ Object.defineProperty(exports, "Scripts", { enumerable: true, get: function () { return index_js_1.Scripts; } });