@nestia/editor 12.0.0-rc.2 → 12.0.0-rc.4

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 (100) hide show
  1. package/LICENSE +21 -21
  2. package/dist/assets/index-Wyu3BnMf.js +4289 -0
  3. package/dist/index.html +19 -19
  4. package/lib/NestiaEditorApplication.mjs +66 -3
  5. package/lib/NestiaEditorApplication.mjs.map +1 -1
  6. package/lib/NestiaEditorIframe.js +11 -17
  7. package/lib/NestiaEditorIframe.js.map +1 -1
  8. package/lib/NestiaEditorIframe.mjs +159 -3
  9. package/lib/NestiaEditorIframe.mjs.map +1 -1
  10. package/lib/NestiaEditorModule.mjs +51 -3
  11. package/lib/NestiaEditorModule.mjs.map +1 -1
  12. package/lib/NestiaEditorUploader.js +4 -11
  13. package/lib/NestiaEditorUploader.js.map +1 -1
  14. package/lib/NestiaEditorUploader.mjs +129 -3
  15. package/lib/NestiaEditorUploader.mjs.map +1 -1
  16. package/lib/index.mjs +4 -2
  17. package/lib/internal/NestiaEditorArchiver.d.ts +20 -0
  18. package/lib/internal/NestiaEditorArchiver.js +38 -0
  19. package/lib/internal/NestiaEditorArchiver.js.map +1 -0
  20. package/lib/internal/NestiaEditorArchiver.mjs +24 -0
  21. package/lib/internal/NestiaEditorArchiver.mjs.map +1 -0
  22. package/lib/internal/NestiaEditorComposer.mjs +52 -3
  23. package/lib/internal/NestiaEditorComposer.mjs.map +1 -1
  24. package/lib/internal/NestiaEditorFileUploader.mjs +43 -3
  25. package/lib/internal/NestiaEditorFileUploader.mjs.map +1 -1
  26. package/lib/main.mjs +9 -3
  27. package/lib/main.mjs.map +1 -1
  28. package/package.json +9 -12
  29. package/src/NestiaEditorApplication.tsx +94 -94
  30. package/src/NestiaEditorIframe.tsx +258 -245
  31. package/src/NestiaEditorModule.ts +136 -136
  32. package/src/NestiaEditorUploader.tsx +146 -154
  33. package/src/index.ts +3 -3
  34. package/src/internal/NestiaEditorArchiver.ts +43 -0
  35. package/src/internal/NestiaEditorComposer.ts +89 -89
  36. package/src/internal/NestiaEditorFileUploader.tsx +65 -65
  37. package/src/main.tsx +10 -10
  38. package/src/typings/react-mui-fileuploader.d.ts +27 -27
  39. package/src/vite-env.d.ts +1 -1
  40. package/README.md +0 -93
  41. package/dist/assets/index-tCs1FGcC.js +0 -4318
  42. package/lib/NestiaEditorApplication2.mjs +0 -86
  43. package/lib/NestiaEditorApplication2.mjs.map +0 -1
  44. package/lib/NestiaEditorIframe2.mjs +0 -139
  45. package/lib/NestiaEditorIframe2.mjs.map +0 -1
  46. package/lib/NestiaEditorModule2.mjs +0 -124
  47. package/lib/NestiaEditorModule2.mjs.map +0 -1
  48. package/lib/NestiaEditorUploader2.mjs +0 -90
  49. package/lib/NestiaEditorUploader2.mjs.map +0 -1
  50. package/lib/_virtual/NestiaEditorApplication.mjs +0 -4
  51. package/lib/_virtual/NestiaEditorApplication.mjs.map +0 -1
  52. package/lib/_virtual/NestiaEditorComposer.mjs +0 -4
  53. package/lib/_virtual/NestiaEditorComposer.mjs.map +0 -1
  54. package/lib/_virtual/NestiaEditorFileUploader.mjs +0 -4
  55. package/lib/_virtual/NestiaEditorFileUploader.mjs.map +0 -1
  56. package/lib/_virtual/NestiaEditorIframe.mjs +0 -4
  57. package/lib/_virtual/NestiaEditorIframe.mjs.map +0 -1
  58. package/lib/_virtual/NestiaEditorModule.mjs +0 -4
  59. package/lib/_virtual/NestiaEditorModule.mjs.map +0 -1
  60. package/lib/_virtual/NestiaEditorUploader.mjs +0 -4
  61. package/lib/_virtual/NestiaEditorUploader.mjs.map +0 -1
  62. package/lib/_virtual/_commonjsHelpers.mjs +0 -35
  63. package/lib/_virtual/_commonjsHelpers.mjs.map +0 -1
  64. package/lib/_virtual/_js-yaml.mjs +0 -7
  65. package/lib/_virtual/_js-yaml.mjs.map +0 -1
  66. package/lib/_virtual/_node_fs.mjs +0 -7
  67. package/lib/_virtual/_node_fs.mjs.map +0 -1
  68. package/lib/_virtual/_react-mui-fileuploader.mjs +0 -7
  69. package/lib/_virtual/_react-mui-fileuploader.mjs.map +0 -1
  70. package/lib/_virtual/_react.mjs +0 -7
  71. package/lib/_virtual/_react.mjs.map +0 -1
  72. package/lib/_virtual/client.mjs +0 -7
  73. package/lib/_virtual/client.mjs.map +0 -1
  74. package/lib/_virtual/estree.mjs +0 -7
  75. package/lib/_virtual/estree.mjs.map +0 -1
  76. package/lib/_virtual/index.mjs +0 -4
  77. package/lib/_virtual/index.mjs.map +0 -1
  78. package/lib/_virtual/jsx-runtime.mjs +0 -7
  79. package/lib/_virtual/jsx-runtime.mjs.map +0 -1
  80. package/lib/_virtual/main.mjs +0 -4
  81. package/lib/_virtual/main.mjs.map +0 -1
  82. package/lib/_virtual/material.mjs +0 -7
  83. package/lib/_virtual/material.mjs.map +0 -1
  84. package/lib/_virtual/migrate.mjs +0 -7
  85. package/lib/_virtual/migrate.mjs.map +0 -1
  86. package/lib/_virtual/sdk.mjs +0 -7
  87. package/lib/_virtual/sdk.mjs.map +0 -1
  88. package/lib/_virtual/standalone.mjs +0 -7
  89. package/lib/_virtual/standalone.mjs.map +0 -1
  90. package/lib/_virtual/typescript.mjs +0 -7
  91. package/lib/_virtual/typescript.mjs.map +0 -1
  92. package/lib/index.mjs.map +0 -1
  93. package/lib/index2.mjs +0 -35
  94. package/lib/index2.mjs.map +0 -1
  95. package/lib/internal/NestiaEditorComposer2.mjs +0 -110
  96. package/lib/internal/NestiaEditorComposer2.mjs.map +0 -1
  97. package/lib/internal/NestiaEditorFileUploader2.mjs +0 -51
  98. package/lib/internal/NestiaEditorFileUploader2.mjs.map +0 -1
  99. package/lib/main2.mjs +0 -16
  100. package/lib/main2.mjs.map +0 -1
package/lib/index.mjs CHANGED
@@ -1,2 +1,4 @@
1
- export { default } from './index2.mjs';
2
- //# sourceMappingURL=index.mjs.map
1
+ import { NestiaEditorIframe } from "./NestiaEditorIframe.mjs";
2
+ import { NestiaEditorUploader } from "./NestiaEditorUploader.mjs";
3
+ import { NestiaEditorApplication } from "./NestiaEditorApplication.mjs";
4
+ export { NestiaEditorApplication, NestiaEditorIframe, NestiaEditorUploader };
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Archives a composed project into a zip file and hands it to the browser.
3
+ *
4
+ * StackBlitz can no longer run nestia projects: the generated projects build
5
+ * through `ttsc`, whose TypeScript compiler is a native Go binary that a
6
+ * WebContainer cannot execute. The editor therefore delivers the composed
7
+ * project as a downloadable zip archive instead of an embedded StackBlitz
8
+ * workspace.
9
+ */
10
+ export declare namespace NestiaEditorArchiver {
11
+ /** Pack the composed project files into a zip archive. */
12
+ const pack: (files: Record<string, string>) => Uint8Array;
13
+ /** Compose a safe archive file name from a package name. */
14
+ const name: (packageName: string) => string;
15
+ /** Trigger a browser download of the packed archive. */
16
+ const download: (props: {
17
+ name: string;
18
+ files: Record<string, string>;
19
+ }) => void;
20
+ }
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.NestiaEditorArchiver = void 0;
4
+ const fflate_1 = require("fflate");
5
+ /**
6
+ * Archives a composed project into a zip file and hands it to the browser.
7
+ *
8
+ * StackBlitz can no longer run nestia projects: the generated projects build
9
+ * through `ttsc`, whose TypeScript compiler is a native Go binary that a
10
+ * WebContainer cannot execute. The editor therefore delivers the composed
11
+ * project as a downloadable zip archive instead of an embedded StackBlitz
12
+ * workspace.
13
+ */
14
+ var NestiaEditorArchiver;
15
+ (function (NestiaEditorArchiver) {
16
+ /** Pack the composed project files into a zip archive. */
17
+ NestiaEditorArchiver.pack = (files) => {
18
+ const entries = {};
19
+ for (const [key, value] of Object.entries(files))
20
+ entries[key] = (0, fflate_1.strToU8)(value);
21
+ return (0, fflate_1.zipSync)(entries);
22
+ };
23
+ /** Compose a safe archive file name from a package name. */
24
+ NestiaEditorArchiver.name = (packageName) => `${packageName.replace(/^@/, "").replace(/[^A-Za-z0-9._-]+/g, "-")}.zip`;
25
+ /** Trigger a browser download of the packed archive. */
26
+ NestiaEditorArchiver.download = (props) => {
27
+ const blob = new Blob([NestiaEditorArchiver.pack(props.files)], {
28
+ type: "application/zip",
29
+ });
30
+ const url = URL.createObjectURL(blob);
31
+ const anchor = window.document.createElement("a");
32
+ anchor.href = url;
33
+ anchor.download = props.name;
34
+ anchor.click();
35
+ setTimeout(() => URL.revokeObjectURL(url), 30000);
36
+ };
37
+ })(NestiaEditorArchiver || (exports.NestiaEditorArchiver = NestiaEditorArchiver = {}));
38
+ //# sourceMappingURL=NestiaEditorArchiver.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"NestiaEditorArchiver.js","sourceRoot":"","sources":["../../src/internal/NestiaEditorArchiver.ts"],"names":[],"mappings":";;;AAAA,mCAA0C;AAE1C;;;;;;;;GAQG;AACH,IAAiB,oBAAoB,CA+BpC;AA/BD,WAAiB,oBAAoB;IACnC,0DAA0D;IAC7C,yBAAI,GAAG,CAAC,KAA6B,EAAc,EAAE;QAChE,MAAM,OAAO,GAA+B,EAAE,CAAC;QAC/C,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC;YAC9C,OAAO,CAAC,GAAG,CAAC,GAAG,IAAA,gBAAO,EAAC,KAAK,CAAC,CAAC;QAChC,OAAO,IAAA,gBAAO,EAAC,OAAO,CAAC,CAAC;IAC1B,CAAC,CAAC;IAEF,4DAA4D;IAC/C,yBAAI,GAAG,CAAC,WAAmB,EAAU,EAAE,CAClD,GAAG,WAAW,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,mBAAmB,EAAE,GAAG,CAAC,MAAM,CAAC;IAE3E,wDAAwD;IAC3C,6BAAQ,GAAG,CAAC,KAGxB,EAAQ,EAAE;QACT,MAAM,IAAI,GAAS,IAAI,IAAI,CACzB,CAAC,yBAAI,CAAC,KAAK,CAAC,KAAK,CAA4B,CAAC,EAC9C;YACE,IAAI,EAAE,iBAAiB;SACxB,CACF,CAAC;QACF,MAAM,GAAG,GAAW,GAAG,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC;QAC9C,MAAM,MAAM,GAAsB,MAAM,CAAC,QAAQ,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC;QACrE,MAAM,CAAC,IAAI,GAAG,GAAG,CAAC;QAClB,MAAM,CAAC,QAAQ,GAAG,KAAK,CAAC,IAAI,CAAC;QAC7B,MAAM,CAAC,KAAK,EAAE,CAAC;QACf,UAAU,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,eAAe,CAAC,GAAG,CAAC,EAAE,KAAM,CAAC,CAAC;IACrD,CAAC,CAAC;AACJ,CAAC,EA/BgB,oBAAoB,aAApB,oBAAoB,GAApB,oBAAoB,QA+BpC"}
@@ -0,0 +1,24 @@
1
+ import { strToU8, zipSync } from "fflate";
2
+ //#region src/internal/NestiaEditorArchiver.ts
3
+ let NestiaEditorArchiver;
4
+ (function(_NestiaEditorArchiver) {
5
+ const pack = _NestiaEditorArchiver.pack = (files) => {
6
+ const entries = {};
7
+ for (const [key, value] of Object.entries(files)) entries[key] = strToU8(value);
8
+ return zipSync(entries);
9
+ };
10
+ _NestiaEditorArchiver.name = (packageName) => `${packageName.replace(/^@/, "").replace(/[^A-Za-z0-9._-]+/g, "-")}.zip`;
11
+ _NestiaEditorArchiver.download = (props) => {
12
+ const blob = new Blob([pack(props.files)], { type: "application/zip" });
13
+ const url = URL.createObjectURL(blob);
14
+ const anchor = window.document.createElement("a");
15
+ anchor.href = url;
16
+ anchor.download = props.name;
17
+ anchor.click();
18
+ setTimeout(() => URL.revokeObjectURL(url), 3e4);
19
+ };
20
+ })(NestiaEditorArchiver || (NestiaEditorArchiver = {}));
21
+ //#endregion
22
+ export { NestiaEditorArchiver };
23
+
24
+ //# sourceMappingURL=NestiaEditorArchiver.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"NestiaEditorArchiver.mjs","names":[],"sources":[],"mappings":""}
@@ -1,3 +1,52 @@
1
- export { NestiaEditorComposer } from './NestiaEditorComposer2.mjs';
2
- export { __exports as default } from '../_virtual/NestiaEditorComposer.mjs';
3
- //# sourceMappingURL=NestiaEditorComposer.mjs.map
1
+ import migrate from "@nestia/migrate";
2
+ import * as prettierEsTreePlugin from "prettier/plugins/estree";
3
+ import * as prettierTsPlugin from "prettier/plugins/typescript";
4
+ import { format } from "prettier/standalone";
5
+ //#region src/internal/NestiaEditorComposer.ts
6
+ let NestiaEditorComposer;
7
+ (function(_NestiaEditorComposer) {
8
+ _NestiaEditorComposer.nest = (props) => compose({
9
+ openFile: "README.md,test/start.ts",
10
+ startScript: ["build:test,test", ""],
11
+ migrate: (app) => app.nest(props)
12
+ })(props);
13
+ _NestiaEditorComposer.sdk = async (props) => compose({
14
+ openFile: "README.md,test/start.ts",
15
+ startScript: ["swagger", "hello"],
16
+ migrate: (app) => app.sdk(props)
17
+ })(props);
18
+ const compose = (config) => async (props) => {
19
+ if (props.files !== void 0) return {
20
+ success: true,
21
+ data: {
22
+ files: props.files,
23
+ openFile: config.openFile,
24
+ startScript: config.startScript
25
+ }
26
+ };
27
+ const result = await migrate.NestiaMigrateApplication.validate(props.document);
28
+ if (result.success === false) return result;
29
+ const app = result.data;
30
+ const files = config.migrate(app);
31
+ for (const [key, value] of Object.entries(files)) if (key.substring(key.length - 3) === ".ts") try {
32
+ files[key] = await format(value, {
33
+ parser: "typescript",
34
+ plugins: [prettierEsTreePlugin, prettierTsPlugin]
35
+ });
36
+ } catch (exp) {
37
+ console.log(exp);
38
+ }
39
+ return {
40
+ success: true,
41
+ data: {
42
+ files,
43
+ openFile: config.openFile,
44
+ startScript: config.startScript
45
+ }
46
+ };
47
+ };
48
+ })(NestiaEditorComposer || (NestiaEditorComposer = {}));
49
+ //#endregion
50
+ export { NestiaEditorComposer };
51
+
52
+ //# sourceMappingURL=NestiaEditorComposer.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"NestiaEditorComposer.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";"}
1
+ {"version":3,"file":"NestiaEditorComposer.mjs","names":[],"sources":[],"mappings":""}
@@ -1,3 +1,43 @@
1
- export { NestiaEditorFileUploader } from './NestiaEditorFileUploader2.mjs';
2
- export { __exports as default } from '../_virtual/NestiaEditorFileUploader.mjs';
3
- //# sourceMappingURL=NestiaEditorFileUploader.mjs.map
1
+ import React from "react";
2
+ import { load } from "js-yaml";
3
+ import { jsx } from "react/jsx-runtime";
4
+ import FileUpload from "react-mui-fileuploader";
5
+ //#region src/internal/NestiaEditorFileUploader.tsx
6
+ function NestiaEditorFileUploader(props) {
7
+ const [elements, setElements] = React.useState([]);
8
+ const onChange = async (array) => {
9
+ if (array.length === 0) {
10
+ props.onChange(null, null);
11
+ return;
12
+ }
13
+ const file = array[array.length - 1];
14
+ const buffer = await file.arrayBuffer();
15
+ const content = new TextDecoder().decode(buffer);
16
+ const extension = file.name.split(".").pop();
17
+ try {
18
+ const json = extension === "json" ? JSON.parse(content) : load(content);
19
+ props.onChange(json, null);
20
+ } catch {
21
+ props.onChange(null, extension === "json" ? "Invalid JSON file" : "Invalid YAML file");
22
+ return;
23
+ }
24
+ if (array.length > 1) setElements([file]);
25
+ };
26
+ return /* @__PURE__ */ jsx(FileUpload, {
27
+ defaultFiles: elements,
28
+ onFilesChange: onChange,
29
+ acceptedType: ".json, .yaml",
30
+ getBase64: false,
31
+ multiFile: false,
32
+ maxUploadFiles: 1,
33
+ title: "Swagger file uploader",
34
+ header: "Drag and drop a Swagger file here",
35
+ buttonLabel: "Click Here",
36
+ rightLabel: "to select swagger.json/yaml file",
37
+ buttonRemoveLabel: "Clear"
38
+ });
39
+ }
40
+ //#endregion
41
+ export { NestiaEditorFileUploader };
42
+
43
+ //# sourceMappingURL=NestiaEditorFileUploader.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"NestiaEditorFileUploader.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";"}
1
+ {"version":3,"file":"NestiaEditorFileUploader.mjs","names":[],"sources":[],"mappings":""}
package/lib/main.mjs CHANGED
@@ -1,3 +1,9 @@
1
- import './main2.mjs';
2
- export { __exports as default } from './_virtual/main.mjs';
3
- //# sourceMappingURL=main.mjs.map
1
+ import { NestiaEditorApplication } from "./NestiaEditorApplication.mjs";
2
+ import { StrictMode } from "react";
3
+ import { jsx } from "react/jsx-runtime";
4
+ import { createRoot } from "react-dom/client";
5
+ //#region src/main.tsx
6
+ createRoot(document.getElementById("root")).render(/* @__PURE__ */ jsx(StrictMode, { children: /* @__PURE__ */ jsx(NestiaEditorApplication, {}) }));
7
+ //#endregion
8
+
9
+ //# sourceMappingURL=main.mjs.map
package/lib/main.mjs.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"main.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";"}
1
+ {"version":3,"file":"main.mjs","names":[],"sources":[],"mappings":""}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nestia/editor",
3
- "version": "12.0.0-rc.2",
3
+ "version": "12.0.0-rc.4",
4
4
  "main": "lib/index.js",
5
5
  "exports": {
6
6
  ".": {
@@ -38,13 +38,13 @@
38
38
  "homepage": "https://nestia.io",
39
39
  "dependencies": {
40
40
  "@mui/material": "^5.15.6",
41
- "@stackblitz/sdk": "^1.11.0",
42
- "@typia/interface": "^13.0.0-rc.1",
41
+ "@typia/interface": "^13.0.1",
42
+ "fflate": "^0.8.2",
43
43
  "js-yaml": "^4.1.0",
44
44
  "prettier": "^3.8.1",
45
45
  "react-mui-fileuploader": "^0.5.2",
46
- "typia": "^13.0.0-rc.1",
47
- "@nestia/migrate": "^12.0.0-rc.2"
46
+ "typia": "^13.0.1",
47
+ "@nestia/migrate": "^12.0.0-rc.4"
48
48
  },
49
49
  "devDependencies": {
50
50
  "@eslint/js": "^9.13.0",
@@ -52,9 +52,7 @@
52
52
  "@nestjs/core": "^11.1.6",
53
53
  "@nestjs/platform-express": "^11.1.6",
54
54
  "@nestjs/platform-fastify": "^11.1.6",
55
- "@rollup/plugin-commonjs": "^29.0.0",
56
- "@rollup/plugin-esm-shim": "^0.1.8",
57
- "@rollup/plugin-node-resolve": "^16.0.3",
55
+ "@ttsc/unplugin": "^0.18.1",
58
56
  "@types/js-yaml": "^4.0.9",
59
57
  "@types/node": "^25.3.3",
60
58
  "@types/react": "^18.3.11",
@@ -66,9 +64,8 @@
66
64
  "globals": "^15.11.0",
67
65
  "react": "^18.3.1",
68
66
  "react-dom": "^18.3.1",
69
- "rollup": "^4.56.0",
70
- "rollup-plugin-node-externals": "^8.1.2",
71
- "typescript": "7.0.1-rc",
67
+ "rolldown": "^1.1.5",
68
+ "typescript": "^7.0.2",
72
69
  "vite": "^5.4.9"
73
70
  },
74
71
  "files": [
@@ -85,7 +82,7 @@
85
82
  "scripts": {
86
83
  "build": "npm run build:static && npm run build:lib",
87
84
  "build:static": "rimraf dist && ttsc && vite build",
88
- "build:lib": "rimraf lib && ttsc --project tsconfig.lib.json && tsc --project tsconfig.lib.json --emitDeclarationOnly && rollup -c",
85
+ "build:lib": "rimraf lib && ttsc --project tsconfig.lib.json && tsc --project tsconfig.lib.json --emitDeclarationOnly && rolldown -c && node ../../deploy/verify-package-exports.cjs --esm-static",
89
86
  "dev": "vite",
90
87
  "lint": "eslint .",
91
88
  "preview": "vite preview"
@@ -1,94 +1,94 @@
1
- import { Typography } from "@mui/material";
2
- import React from "react";
3
-
4
- import { NestiaEditorIframe } from "./NestiaEditorIframe";
5
- import { NestiaEditorUploader } from "./NestiaEditorUploader";
6
-
7
- export function NestiaEditorApplication() {
8
- const [ready, setReady] = React.useState(false);
9
- const [asset, setAsset] = React.useState<IAsset | null>(null);
10
-
11
- React.useEffect(() => {
12
- (async () => {
13
- try {
14
- setAsset(await getAsset());
15
- } catch {
16
- setAsset(null);
17
- }
18
- setReady(true);
19
- })().catch(() => {});
20
- }, []);
21
- if (ready === false) return <></>;
22
-
23
- return asset !== null ? (
24
- <NestiaEditorIframe
25
- swagger={asset.url}
26
- package={asset.package}
27
- simulate={asset.simulate}
28
- e2e={asset.e2e}
29
- mode={asset.mode}
30
- />
31
- ) : (
32
- <div
33
- style={{
34
- padding: 25,
35
- }}
36
- >
37
- <Typography variant="h4">Nestia Editor</Typography>
38
- <hr />
39
- <br />
40
- <NestiaEditorUploader />
41
- </div>
42
- );
43
- }
44
-
45
- async function getAsset(): Promise<IAsset | null> {
46
- const index: number = window.location.href.indexOf("?");
47
- const query: URLSearchParams = new URLSearchParams(
48
- index === -1 ? "" : window.location.href.substring(index + 1),
49
- );
50
- if (query.has("uploader")) return null;
51
-
52
- const url: string | null =
53
- query.get("url") ??
54
- (await findSwagger("./swagger.json")) ??
55
- (await findSwagger("./swagger.yaml"));
56
- if (url === null) return null;
57
-
58
- const mode: string | null = query.get("mode");
59
- const packageName: string | null =
60
- query.get("package") ?? (window as any).package;
61
- const keyword: boolean | string | null =
62
- query.get("keyword") ?? (window as any).keyword;
63
- const simulate: boolean | string | null =
64
- query.get("simulate") ?? (window as any).simulate;
65
- const e2e: boolean | string | null = query.get("e2e") ?? (window as any).e2e;
66
- return {
67
- mode: mode === "nest" ? "nest" : "sdk",
68
- package: packageName ?? "@ORGANIZATION/PROJECT",
69
- url,
70
- keyword:
71
- keyword !== null
72
- ? keyword === true || keyword === "true" || keyword === "1"
73
- : false,
74
- simulate:
75
- simulate !== null
76
- ? simulate === true || simulate === "true" || simulate === "1"
77
- : false,
78
- e2e: e2e !== null ? e2e === true || e2e === "true" || e2e === "1" : false,
79
- };
80
- }
81
-
82
- async function findSwagger(file: string): Promise<string | null> {
83
- const response: Response = await fetch(file);
84
- return response.status === 200 ? file : null;
85
- }
86
-
87
- interface IAsset {
88
- mode: "nest" | "sdk";
89
- package: string;
90
- url: string;
91
- keyword: boolean;
92
- simulate: boolean;
93
- e2e: boolean;
94
- }
1
+ import { Typography } from "@mui/material";
2
+ import React from "react";
3
+
4
+ import { NestiaEditorIframe } from "./NestiaEditorIframe";
5
+ import { NestiaEditorUploader } from "./NestiaEditorUploader";
6
+
7
+ export function NestiaEditorApplication() {
8
+ const [ready, setReady] = React.useState(false);
9
+ const [asset, setAsset] = React.useState<IAsset | null>(null);
10
+
11
+ React.useEffect(() => {
12
+ (async () => {
13
+ try {
14
+ setAsset(await getAsset());
15
+ } catch {
16
+ setAsset(null);
17
+ }
18
+ setReady(true);
19
+ })().catch(() => {});
20
+ }, []);
21
+ if (ready === false) return <></>;
22
+
23
+ return asset !== null ? (
24
+ <NestiaEditorIframe
25
+ swagger={asset.url}
26
+ package={asset.package}
27
+ simulate={asset.simulate}
28
+ e2e={asset.e2e}
29
+ mode={asset.mode}
30
+ />
31
+ ) : (
32
+ <div
33
+ style={{
34
+ padding: 25,
35
+ }}
36
+ >
37
+ <Typography variant="h4">Nestia Editor</Typography>
38
+ <hr />
39
+ <br />
40
+ <NestiaEditorUploader />
41
+ </div>
42
+ );
43
+ }
44
+
45
+ async function getAsset(): Promise<IAsset | null> {
46
+ const index: number = window.location.href.indexOf("?");
47
+ const query: URLSearchParams = new URLSearchParams(
48
+ index === -1 ? "" : window.location.href.substring(index + 1),
49
+ );
50
+ if (query.has("uploader")) return null;
51
+
52
+ const url: string | null =
53
+ query.get("url") ??
54
+ (await findSwagger("./swagger.json")) ??
55
+ (await findSwagger("./swagger.yaml"));
56
+ if (url === null) return null;
57
+
58
+ const mode: string | null = query.get("mode");
59
+ const packageName: string | null =
60
+ query.get("package") ?? (window as any).package;
61
+ const keyword: boolean | string | null =
62
+ query.get("keyword") ?? (window as any).keyword;
63
+ const simulate: boolean | string | null =
64
+ query.get("simulate") ?? (window as any).simulate;
65
+ const e2e: boolean | string | null = query.get("e2e") ?? (window as any).e2e;
66
+ return {
67
+ mode: mode === "nest" ? "nest" : "sdk",
68
+ package: packageName ?? "@ORGANIZATION/PROJECT",
69
+ url,
70
+ keyword:
71
+ keyword !== null
72
+ ? keyword === true || keyword === "true" || keyword === "1"
73
+ : false,
74
+ simulate:
75
+ simulate !== null
76
+ ? simulate === true || simulate === "true" || simulate === "1"
77
+ : false,
78
+ e2e: e2e !== null ? e2e === true || e2e === "true" || e2e === "1" : false,
79
+ };
80
+ }
81
+
82
+ async function findSwagger(file: string): Promise<string | null> {
83
+ const response: Response = await fetch(file);
84
+ return response.status === 200 ? file : null;
85
+ }
86
+
87
+ interface IAsset {
88
+ mode: "nest" | "sdk";
89
+ package: string;
90
+ url: string;
91
+ keyword: boolean;
92
+ simulate: boolean;
93
+ e2e: boolean;
94
+ }