@nestia/editor 0.1.3 → 0.2.1

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,75 +1,77 @@
1
- import { Typography } from "@mui/material";
2
- import { useEffect, useState } from "react";
3
-
4
- import { NestiaEditorIframe } from "./NestiaEditorIframe.js";
5
- import { NestiaEditorUploader } from "./NestiaEditorUploader.js";
6
-
7
- export function NestiaEditorApplication() {
8
- const [ready, setReady] = useState(false);
9
- const [asset, setAsset] = useState<IAsset | null>(null);
10
- useEffect(() => {
11
- (async () => {
12
- try {
13
- setAsset(await getAsset());
14
- } catch {
15
- setAsset(null);
16
- }
17
- setReady(true);
18
- })().catch(() => {});
19
- }, []);
20
- if (ready === false) return <></>;
21
- return asset !== null ? (
22
- <NestiaEditorIframe
23
- swagger={asset.url}
24
- simulate={asset.simulate}
25
- e2e={asset.e2e}
26
- />
27
- ) : (
28
- <div
29
- style={{
30
- padding: 25,
31
- }}
32
- >
33
- <Typography variant="h4">Nestia Editor</Typography>
34
- <hr />
35
- <br />
36
- <NestiaEditorUploader />
37
- </div>
38
- );
39
- }
40
-
41
- async function getAsset(): Promise<IAsset | null> {
42
- const index: number = window.location.href.indexOf("?");
43
- if (index === -1) return null;
44
-
45
- const query: URLSearchParams = new URLSearchParams(
46
- window.location.href.substring(index + 1),
47
- );
48
- const url: string | null = query.get("url") ?? (await findSwagger());
49
- if (url === null) return null;
50
- try {
51
- new URL(url);
52
- } catch {
53
- return null;
54
- }
55
-
56
- const simulate: string | null = query.get("simulate");
57
- const e2e: string | null = query.get("e2e");
58
- return {
59
- url,
60
- simulate:
61
- simulate !== null ? simulate === "true" || simulate === "1" : true,
62
- e2e: e2e !== null ? e2e === "true" || e2e === "1" : true,
63
- };
64
- }
65
-
66
- async function findSwagger(): Promise<string | null> {
67
- const response: Response = await fetch("./swagger.json");
68
- return response.status === 200 ? "./swagger.json" : null;
69
- }
70
-
71
- interface IAsset {
72
- url: string;
73
- simulate: boolean;
74
- e2e: boolean;
75
- }
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
+ simulate={asset.simulate}
27
+ e2e={asset.e2e}
28
+ />
29
+ ) : (
30
+ <div
31
+ style={{
32
+ padding: 25,
33
+ }}
34
+ >
35
+ <Typography variant="h4">Nestia Editor</Typography>
36
+ <hr />
37
+ <br />
38
+ <NestiaEditorUploader />
39
+ </div>
40
+ );
41
+ }
42
+
43
+ async function getAsset(): Promise<IAsset | null> {
44
+ const index: number = window.location.href.indexOf("?");
45
+ if (index === -1) return null;
46
+
47
+ const query: URLSearchParams = new URLSearchParams(
48
+ window.location.href.substring(index + 1),
49
+ );
50
+ const url: string | null = query.get("url") ?? (await findSwagger());
51
+ if (url === null) return null;
52
+ try {
53
+ new URL(url);
54
+ } catch {
55
+ return null;
56
+ }
57
+
58
+ const simulate: string | null = query.get("simulate");
59
+ const e2e: string | null = query.get("e2e");
60
+ return {
61
+ url,
62
+ simulate:
63
+ simulate !== null ? simulate === "true" || simulate === "1" : true,
64
+ e2e: e2e !== null ? e2e === "true" || e2e === "1" : true,
65
+ };
66
+ }
67
+
68
+ async function findSwagger(): Promise<string | null> {
69
+ const response: Response = await fetch("./swagger.json");
70
+ return response.status === 200 ? "./swagger.json" : null;
71
+ }
72
+
73
+ interface IAsset {
74
+ url: string;
75
+ simulate: boolean;
76
+ e2e: boolean;
77
+ }
@@ -10,22 +10,23 @@ import {
10
10
  } from "@mui/material";
11
11
  import { OpenApiV3, OpenApiV3_1, SwaggerV2 } from "@samchon/openapi";
12
12
  import StackBlitzSDK from "@stackblitz/sdk";
13
- import { useEffect, useState } from "react";
14
- import { JSONTree } from "react-json-tree";
13
+ import React from "react";
15
14
  import { IValidation } from "typia";
16
15
 
17
- import { NestiaEditorComposer } from "./internal/NestiaEditorComposer.js";
16
+ import { NestiaEditorComposer } from "./internal/NestiaEditorComposer";
18
17
 
19
18
  export function NestiaEditorIframe(props: NestiaEditorIframe.IProps) {
20
- const [id] = useState(
19
+ const [id] = React.useState(
21
20
  `reactia-editor-div-${Math.random().toString().substring(2)}`,
22
21
  );
23
- const [step, setStep] = useState(0);
24
- const [fetchError, setFetchError] = useState<string | null>(null);
25
- const [operations, setOperationCount] = useState<Record<string, number>>({});
26
- const [composerError, setComposerError] = useState<any | null>(null);
22
+ const [step, setStep] = React.useState(0);
23
+ const [fetchError, setFetchError] = React.useState<string | null>(null);
24
+ const [operations, setOperationCount] = React.useState<
25
+ Record<string, number>
26
+ >({});
27
+ const [composerError, setComposerError] = React.useState<any | null>(null);
27
28
 
28
- useEffect(() => {
29
+ React.useEffect(() => {
29
30
  (async () => {
30
31
  // LOADING OPENAPI DOCUMENTS
31
32
  setStep(0);
@@ -152,7 +153,7 @@ export function NestiaEditorIframe(props: NestiaEditorIframe.IProps) {
152
153
  <br />
153
154
  <Alert severity="error">
154
155
  <AlertTitle>Composition Error</AlertTitle>
155
- <JSONTree data={composerError} />
156
+ <pre>{JSON.stringify(composerError, null, 2)}</pre>
156
157
  </Alert>
157
158
  </>
158
159
  ) : null}
@@ -9,22 +9,22 @@ import {
9
9
  } from "@mui/material";
10
10
  import { OpenApiV3, OpenApiV3_1, SwaggerV2 } from "@samchon/openapi";
11
11
  import StackBlitzSDK from "@stackblitz/sdk";
12
- import { useState } from "react";
12
+ import React from "react";
13
13
 
14
- import { NestiaEditorComposer } from "./internal/NestiaEditorComposer.js";
15
- import { NestiaEditorFileUploader } from "./internal/NestiaEditorFileUploader.js";
14
+ import { NestiaEditorComposer } from "./internal/NestiaEditorComposer";
15
+ import { NestiaEditorFileUploader } from "./internal/NestiaEditorFileUploader";
16
16
 
17
17
  export function NestiaEditorUploader(props: NestiaEditorUploader.IProps) {
18
18
  // PARAMETERS
19
- const [mode, setMode] = useState<"nest" | "sdk">("sdk");
20
- const [simulate, setSimulate] = useState(true);
21
- const [e2e, setE2e] = useState(true);
19
+ const [mode, setMode] = React.useState<"nest" | "sdk">("sdk");
20
+ const [simulate, setSimulate] = React.useState(true);
21
+ const [e2e, setE2e] = React.useState(true);
22
22
 
23
23
  // RESULT
24
- const [document, setDocument] = useState<
24
+ const [document, setDocument] = React.useState<
25
25
  SwaggerV2.IDocument | OpenApiV3.IDocument | OpenApiV3_1.IDocument | null
26
26
  >(null);
27
- const [progress, setProgress] = useState(false);
27
+ const [progress, setProgress] = React.useState(false);
28
28
 
29
29
  const handleError = (error: string) => {
30
30
  if (props.onError) props.onError(error);
package/src/index.ts CHANGED
@@ -1,2 +1,2 @@
1
- export * from "./NestiaEditorIframe.js";
2
- export * from "./NestiaEditorUploader.js";
1
+ export * from "./NestiaEditorIframe";
2
+ export * from "./NestiaEditorUploader";
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.js";
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
+ );