@nestia/editor 8.0.5-dev.20250904-2 → 8.0.6

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.
@@ -1,154 +1,154 @@
1
- import {
2
- Button,
3
- FormControl,
4
- FormControlLabel,
5
- FormLabel,
6
- Radio,
7
- RadioGroup,
8
- Switch,
9
- TextField,
10
- } from "@mui/material";
11
- import { OpenApiV3, OpenApiV3_1, SwaggerV2 } from "@samchon/openapi";
12
- import StackBlitzSDK from "@stackblitz/sdk";
13
- import React from "react";
14
-
15
- import { NestiaEditorComposer } from "./internal/NestiaEditorComposer";
16
- import { NestiaEditorFileUploader } from "./internal/NestiaEditorFileUploader";
17
-
18
- export function NestiaEditorUploader(props: NestiaEditorUploader.IProps) {
19
- // PARAMETERS
20
- const [mode, setMode] = React.useState<"nest" | "sdk">("sdk");
21
- const [keyword, setKeyword] = React.useState(true);
22
- const [simulate, setSimulate] = React.useState(true);
23
- const [e2e, setE2e] = React.useState(true);
24
- const [name, setName] = React.useState("@ORGINIZATION/PROJECT");
25
-
26
- // RESULT
27
- const [document, setDocument] = React.useState<
28
- SwaggerV2.IDocument | OpenApiV3.IDocument | OpenApiV3_1.IDocument | null
29
- >(null);
30
- const [progress, setProgress] = React.useState(false);
31
-
32
- const handleError = (error: string) => {
33
- if (props.onError) props.onError(error);
34
- else alert(error);
35
- };
36
- const handleSwagger = (
37
- document:
38
- | SwaggerV2.IDocument
39
- | OpenApiV3.IDocument
40
- | OpenApiV3_1.IDocument
41
- | null,
42
- error: string | null,
43
- ) => {
44
- setDocument(document);
45
- if (error !== null) handleError(error);
46
- };
47
-
48
- const generate = async () => {
49
- if (document === null) return;
50
-
51
- setProgress(true);
52
- try {
53
- const result = await NestiaEditorComposer[mode]({
54
- document,
55
- keyword,
56
- e2e,
57
- simulate,
58
- package: name,
59
- });
60
- if (result.success === true) {
61
- StackBlitzSDK.openProject(
62
- {
63
- title: document.info?.title ?? "Nestia Editor",
64
- template: "node",
65
- files: result.data.files,
66
- },
67
- {
68
- newWindow: true,
69
- openFile: result.data.openFile,
70
- startScript: result.data.startScript as any,
71
- },
72
- );
73
- } else {
74
- handleError(JSON.stringify(result.errors, null, 2));
75
- }
76
- } catch (exp) {
77
- handleError(exp instanceof Error ? exp.message : "unknown error");
78
- }
79
- setProgress(false);
80
- };
81
-
82
- return (
83
- <>
84
- <NestiaEditorFileUploader onChange={handleSwagger} />
85
- <br />
86
- <FormControl fullWidth style={{ paddingLeft: 15 }}>
87
- <TextField
88
- onChange={(e) => setName(e.target.value)}
89
- defaultValue={name}
90
- label="Package Name"
91
- variant="outlined"
92
- />
93
- <FormLabel style={{ paddingTop: 20 }}> Mode </FormLabel>
94
- <RadioGroup
95
- defaultValue={mode}
96
- onChange={(_e, value) => setMode(value as "nest" | "sdk")}
97
- style={{ paddingLeft: 15 }}
98
- >
99
- <FormControlLabel
100
- value="sdk"
101
- control={<Radio />}
102
- label="Software Development Kit"
103
- />
104
- <FormControlLabel
105
- value="nest"
106
- control={<Radio />}
107
- label="NestJS Project"
108
- />
109
- </RadioGroup>
110
- <FormLabel style={{ paddingTop: 20 }}> Options </FormLabel>
111
- <FormControlLabel
112
- label="Keyword Parameter"
113
- style={{ paddingTop: 5, paddingLeft: 15 }}
114
- control={
115
- <Switch checked={keyword} onChange={() => setKeyword(!keyword)} />
116
- }
117
- />
118
- <FormControlLabel
119
- label="Mockup Simulator"
120
- style={{ paddingTop: 5, paddingLeft: 15 }}
121
- control={
122
- <Switch
123
- checked={simulate}
124
- onChange={() => setSimulate(!simulate)}
125
- />
126
- }
127
- />
128
- <FormControlLabel
129
- label="E2E Test Functions"
130
- style={{ paddingLeft: 15 }}
131
- control={<Switch checked={e2e} onChange={() => setE2e(!e2e)} />}
132
- />
133
- </FormControl>
134
- <br />
135
- <br />
136
- <Button
137
- component="a"
138
- fullWidth
139
- variant="contained"
140
- color={"info"}
141
- size="large"
142
- disabled={progress === true || document === null}
143
- onClick={() => generate()}
144
- >
145
- {progress ? "Generating..." : "Generate Editor"}
146
- </Button>
147
- </>
148
- );
149
- }
150
- export namespace NestiaEditorUploader {
151
- export interface IProps {
152
- onError?: (error: string) => void;
153
- }
154
- }
1
+ import {
2
+ Button,
3
+ FormControl,
4
+ FormControlLabel,
5
+ FormLabel,
6
+ Radio,
7
+ RadioGroup,
8
+ Switch,
9
+ TextField,
10
+ } from "@mui/material";
11
+ import { OpenApiV3, OpenApiV3_1, SwaggerV2 } from "@samchon/openapi";
12
+ import StackBlitzSDK from "@stackblitz/sdk";
13
+ import React from "react";
14
+
15
+ import { NestiaEditorComposer } from "./internal/NestiaEditorComposer";
16
+ import { NestiaEditorFileUploader } from "./internal/NestiaEditorFileUploader";
17
+
18
+ export function NestiaEditorUploader(props: NestiaEditorUploader.IProps) {
19
+ // PARAMETERS
20
+ const [mode, setMode] = React.useState<"nest" | "sdk">("sdk");
21
+ const [keyword, setKeyword] = React.useState(true);
22
+ const [simulate, setSimulate] = React.useState(true);
23
+ const [e2e, setE2e] = React.useState(true);
24
+ const [name, setName] = React.useState("@ORGINIZATION/PROJECT");
25
+
26
+ // RESULT
27
+ const [document, setDocument] = React.useState<
28
+ SwaggerV2.IDocument | OpenApiV3.IDocument | OpenApiV3_1.IDocument | null
29
+ >(null);
30
+ const [progress, setProgress] = React.useState(false);
31
+
32
+ const handleError = (error: string) => {
33
+ if (props.onError) props.onError(error);
34
+ else alert(error);
35
+ };
36
+ const handleSwagger = (
37
+ document:
38
+ | SwaggerV2.IDocument
39
+ | OpenApiV3.IDocument
40
+ | OpenApiV3_1.IDocument
41
+ | null,
42
+ error: string | null,
43
+ ) => {
44
+ setDocument(document);
45
+ if (error !== null) handleError(error);
46
+ };
47
+
48
+ const generate = async () => {
49
+ if (document === null) return;
50
+
51
+ setProgress(true);
52
+ try {
53
+ const result = await NestiaEditorComposer[mode]({
54
+ document,
55
+ keyword,
56
+ e2e,
57
+ simulate,
58
+ package: name,
59
+ });
60
+ if (result.success === true) {
61
+ StackBlitzSDK.openProject(
62
+ {
63
+ title: document.info?.title ?? "Nestia Editor",
64
+ template: "node",
65
+ files: result.data.files,
66
+ },
67
+ {
68
+ newWindow: true,
69
+ openFile: result.data.openFile,
70
+ startScript: result.data.startScript as any,
71
+ },
72
+ );
73
+ } else {
74
+ handleError(JSON.stringify(result.errors, null, 2));
75
+ }
76
+ } catch (exp) {
77
+ handleError(exp instanceof Error ? exp.message : "unknown error");
78
+ }
79
+ setProgress(false);
80
+ };
81
+
82
+ return (
83
+ <>
84
+ <NestiaEditorFileUploader onChange={handleSwagger} />
85
+ <br />
86
+ <FormControl fullWidth style={{ paddingLeft: 15 }}>
87
+ <TextField
88
+ onChange={(e) => setName(e.target.value)}
89
+ defaultValue={name}
90
+ label="Package Name"
91
+ variant="outlined"
92
+ />
93
+ <FormLabel style={{ paddingTop: 20 }}> Mode </FormLabel>
94
+ <RadioGroup
95
+ defaultValue={mode}
96
+ onChange={(_e, value) => setMode(value as "nest" | "sdk")}
97
+ style={{ paddingLeft: 15 }}
98
+ >
99
+ <FormControlLabel
100
+ value="sdk"
101
+ control={<Radio />}
102
+ label="Software Development Kit"
103
+ />
104
+ <FormControlLabel
105
+ value="nest"
106
+ control={<Radio />}
107
+ label="NestJS Project"
108
+ />
109
+ </RadioGroup>
110
+ <FormLabel style={{ paddingTop: 20 }}> Options </FormLabel>
111
+ <FormControlLabel
112
+ label="Keyword Parameter"
113
+ style={{ paddingTop: 5, paddingLeft: 15 }}
114
+ control={
115
+ <Switch checked={keyword} onChange={() => setKeyword(!keyword)} />
116
+ }
117
+ />
118
+ <FormControlLabel
119
+ label="Mockup Simulator"
120
+ style={{ paddingTop: 5, paddingLeft: 15 }}
121
+ control={
122
+ <Switch
123
+ checked={simulate}
124
+ onChange={() => setSimulate(!simulate)}
125
+ />
126
+ }
127
+ />
128
+ <FormControlLabel
129
+ label="E2E Test Functions"
130
+ style={{ paddingLeft: 15 }}
131
+ control={<Switch checked={e2e} onChange={() => setE2e(!e2e)} />}
132
+ />
133
+ </FormControl>
134
+ <br />
135
+ <br />
136
+ <Button
137
+ component="a"
138
+ fullWidth
139
+ variant="contained"
140
+ color={"info"}
141
+ size="large"
142
+ disabled={progress === true || document === null}
143
+ onClick={() => generate()}
144
+ >
145
+ {progress ? "Generating..." : "Generate Editor"}
146
+ </Button>
147
+ </>
148
+ );
149
+ }
150
+ export namespace NestiaEditorUploader {
151
+ export interface IProps {
152
+ onError?: (error: string) => void;
153
+ }
154
+ }
@@ -1,68 +1,68 @@
1
- import { OpenApiV3, OpenApiV3_1, SwaggerV2 } from "@samchon/openapi";
2
- import { load } from "js-yaml";
3
- import React from "react";
4
- // @ts-ignore
5
- import FileUpload from "react-mui-fileuploader";
6
- // @ts-ignore
7
- import { ExtendedFileProps } from "react-mui-fileuploader/dist/types/index.types";
8
-
9
- export function NestiaEditorFileUploader(
10
- props: NestiaEditorFileUploader.IProps,
11
- ) {
12
- const [elements, setElements] = React.useState<ExtendedFileProps[]>([]);
13
- const onChange = async (array: ExtendedFileProps[]) => {
14
- if (array.length === 0) {
15
- props.onChange(null, null);
16
- return;
17
- }
18
- const file: ExtendedFileProps = array[array.length - 1]!;
19
- const buffer: ArrayBuffer = await file.arrayBuffer();
20
- const content: string = new TextDecoder().decode(buffer);
21
- const extension: "json" | "yaml" = file.name.split(".").pop()! as
22
- | "json"
23
- | "yaml";
24
-
25
- try {
26
- const json:
27
- | SwaggerV2.IDocument
28
- | OpenApiV3.IDocument
29
- | OpenApiV3_1.IDocument =
30
- extension === "json" ? JSON.parse(content) : load(content);
31
- props.onChange(json, null);
32
- } catch {
33
- props.onChange(
34
- null,
35
- extension === "json" ? "Invalid JSON file" : "Invalid YAML file",
36
- );
37
- return;
38
- }
39
- if (array.length > 1) setElements([file]);
40
- };
41
- return (
42
- <FileUpload
43
- defaultFiles={elements}
44
- onFilesChange={onChange}
45
- acceptedType=".json, .yaml"
46
- getBase64={false}
47
- multiFile={false}
48
- maxUploadFiles={1}
49
- title="Swagger file uploader"
50
- header="Drag and drop a Swagger file here"
51
- buttonLabel="Click Here"
52
- rightLabel="to select swagger.json/yaml file"
53
- buttonRemoveLabel="Clear"
54
- />
55
- );
56
- }
57
- export namespace NestiaEditorFileUploader {
58
- export interface IProps {
59
- onChange: (
60
- swagger:
61
- | SwaggerV2.IDocument
62
- | OpenApiV3.IDocument
63
- | OpenApiV3_1.IDocument
64
- | null,
65
- error: string | null,
66
- ) => void;
67
- }
68
- }
1
+ import { OpenApiV3, OpenApiV3_1, SwaggerV2 } from "@samchon/openapi";
2
+ import { load } from "js-yaml";
3
+ import React from "react";
4
+ // @ts-ignore
5
+ import FileUpload from "react-mui-fileuploader";
6
+ // @ts-ignore
7
+ import { ExtendedFileProps } from "react-mui-fileuploader/dist/types/index.types";
8
+
9
+ export function NestiaEditorFileUploader(
10
+ props: NestiaEditorFileUploader.IProps,
11
+ ) {
12
+ const [elements, setElements] = React.useState<ExtendedFileProps[]>([]);
13
+ const onChange = async (array: ExtendedFileProps[]) => {
14
+ if (array.length === 0) {
15
+ props.onChange(null, null);
16
+ return;
17
+ }
18
+ const file: ExtendedFileProps = array[array.length - 1]!;
19
+ const buffer: ArrayBuffer = await file.arrayBuffer();
20
+ const content: string = new TextDecoder().decode(buffer);
21
+ const extension: "json" | "yaml" = file.name.split(".").pop()! as
22
+ | "json"
23
+ | "yaml";
24
+
25
+ try {
26
+ const json:
27
+ | SwaggerV2.IDocument
28
+ | OpenApiV3.IDocument
29
+ | OpenApiV3_1.IDocument =
30
+ extension === "json" ? JSON.parse(content) : load(content);
31
+ props.onChange(json, null);
32
+ } catch {
33
+ props.onChange(
34
+ null,
35
+ extension === "json" ? "Invalid JSON file" : "Invalid YAML file",
36
+ );
37
+ return;
38
+ }
39
+ if (array.length > 1) setElements([file]);
40
+ };
41
+ return (
42
+ <FileUpload
43
+ defaultFiles={elements}
44
+ onFilesChange={onChange}
45
+ acceptedType=".json, .yaml"
46
+ getBase64={false}
47
+ multiFile={false}
48
+ maxUploadFiles={1}
49
+ title="Swagger file uploader"
50
+ header="Drag and drop a Swagger file here"
51
+ buttonLabel="Click Here"
52
+ rightLabel="to select swagger.json/yaml file"
53
+ buttonRemoveLabel="Clear"
54
+ />
55
+ );
56
+ }
57
+ export namespace NestiaEditorFileUploader {
58
+ export interface IProps {
59
+ onChange: (
60
+ swagger:
61
+ | SwaggerV2.IDocument
62
+ | OpenApiV3.IDocument
63
+ | OpenApiV3_1.IDocument
64
+ | null,
65
+ error: string | null,
66
+ ) => void;
67
+ }
68
+ }
package/src/main.tsx CHANGED
@@ -1,10 +1,10 @@
1
- import { StrictMode } from "react";
2
- import { createRoot } from "react-dom/client";
3
-
4
- import { NestiaEditorApplication } from "./NestiaEditorApplication";
5
-
6
- createRoot(document.getElementById("root")!).render(
7
- <StrictMode>
8
- <NestiaEditorApplication />
9
- </StrictMode>,
10
- );
1
+ import { StrictMode } from "react";
2
+ import { createRoot } from "react-dom/client";
3
+
4
+ import { NestiaEditorApplication } from "./NestiaEditorApplication";
5
+
6
+ createRoot(document.getElementById("root")!).render(
7
+ <StrictMode>
8
+ <NestiaEditorApplication />
9
+ </StrictMode>,
10
+ );