@typespec/playground 0.14.0-dev.3 → 0.14.0-dev.5
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/dist/index.js +17 -19
- package/dist/react/index.js +2597 -3056
- package/dist/react/viewers/index.js +23 -17
- package/dist/react-wrapper-B-poU4Lv.js +18 -0
- package/dist/services-CELCHECS.js +723 -0
- package/dist/state-storage.js +65 -79
- package/dist/style.css +2 -1
- package/dist/tooling/index.js +24 -23
- package/dist/vite/index.js +54 -78
- package/package.json +13 -13
- package/dist/react-wrapper-BE4armyk.js +0 -20
- package/dist/services-Z619RuQS.js +0 -760
package/dist/state-storage.js
CHANGED
|
@@ -1,82 +1,68 @@
|
|
|
1
|
-
import lzutf8 from
|
|
2
|
-
|
|
1
|
+
import lzutf8 from "lzutf8";
|
|
2
|
+
//#region src/state-storage.ts
|
|
3
|
+
/**
|
|
4
|
+
* Generic storage mechanism for data in the playground.
|
|
5
|
+
* @param schema Schema of the data to be serialized in the query
|
|
6
|
+
* @returns
|
|
7
|
+
*/
|
|
3
8
|
function createUrlStateStorage(schema) {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
params.delete(item.queryParam);
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
return params;
|
|
65
|
-
}
|
|
66
|
-
function compress(item, value) {
|
|
67
|
-
if (item.compress) {
|
|
68
|
-
return lzutf8.compress(value, { outputEncoding: "Base64" });
|
|
69
|
-
} else {
|
|
70
|
-
return value;
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
function serialize(item, value) {
|
|
74
|
-
if (item.type === "object") {
|
|
75
|
-
return JSON.stringify(value);
|
|
76
|
-
} else {
|
|
77
|
-
return value;
|
|
78
|
-
}
|
|
79
|
-
}
|
|
9
|
+
return {
|
|
10
|
+
load,
|
|
11
|
+
save,
|
|
12
|
+
resolveSearchParams
|
|
13
|
+
};
|
|
14
|
+
function load() {
|
|
15
|
+
const result = {};
|
|
16
|
+
const parsed = new URLSearchParams(window.location.search);
|
|
17
|
+
for (const [key, item] of Object.entries(schema)) {
|
|
18
|
+
const value = parsed.get(item.queryParam);
|
|
19
|
+
const decompressed = value && decompress(item, value);
|
|
20
|
+
const deserialized = decompressed && deserialize(item, decompressed);
|
|
21
|
+
if (deserialized) result[key] = deserialized;
|
|
22
|
+
}
|
|
23
|
+
return result;
|
|
24
|
+
}
|
|
25
|
+
function decompress(item, value) {
|
|
26
|
+
if (item.compress) try {
|
|
27
|
+
return lzutf8.decompress(value, { inputEncoding: "Base64" });
|
|
28
|
+
} catch (e) {
|
|
29
|
+
console.error(`Error decompressing query parameter ${item.queryParam} with content:`, value);
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
else return value;
|
|
33
|
+
}
|
|
34
|
+
function deserialize(item, value) {
|
|
35
|
+
if (item.type === "object") try {
|
|
36
|
+
return JSON.parse(value);
|
|
37
|
+
} catch (e) {
|
|
38
|
+
console.error(`Error decompressing query parameter ${item.queryParam} with content:`, value);
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
else return value;
|
|
42
|
+
}
|
|
43
|
+
function save(data) {
|
|
44
|
+
const params = resolveSearchParams(data, true);
|
|
45
|
+
history.pushState(null, "", window.location.pathname + "?" + params.toString());
|
|
46
|
+
}
|
|
47
|
+
function resolveSearchParams(data, mergeWithExisting = false) {
|
|
48
|
+
const params = new URLSearchParams(mergeWithExisting ? location.search : void 0);
|
|
49
|
+
for (const [key, item] of Object.entries(schema)) {
|
|
50
|
+
const value = data[key];
|
|
51
|
+
if (value) {
|
|
52
|
+
const compressed = compress(item, serialize(item, value));
|
|
53
|
+
params.set(item.queryParam, compressed);
|
|
54
|
+
} else params.delete(item.queryParam);
|
|
55
|
+
}
|
|
56
|
+
return params;
|
|
57
|
+
}
|
|
58
|
+
function compress(item, value) {
|
|
59
|
+
if (item.compress) return lzutf8.compress(value, { outputEncoding: "Base64" });
|
|
60
|
+
else return value;
|
|
61
|
+
}
|
|
62
|
+
function serialize(item, value) {
|
|
63
|
+
if (item.type === "object") return JSON.stringify(value);
|
|
64
|
+
else return value;
|
|
65
|
+
}
|
|
80
66
|
}
|
|
81
|
-
|
|
67
|
+
//#endregion
|
|
82
68
|
export { createUrlStateStorage };
|
package/dist/style.css
CHANGED
|
@@ -175,7 +175,7 @@
|
|
|
175
175
|
._tree-row_16t0l_4 ._column_16t0l_44:last-child {
|
|
176
176
|
margin-right: 5px;
|
|
177
177
|
}
|
|
178
|
-
|
|
178
|
+
/*$vite$:1*/._bar_1gurd_1 {
|
|
179
179
|
border-bottom: 1px solid var(--colorNeutralStroke1);
|
|
180
180
|
}
|
|
181
181
|
|
|
@@ -560,3 +560,4 @@
|
|
|
560
560
|
height: 100%;
|
|
561
561
|
overflow: auto;
|
|
562
562
|
}
|
|
563
|
+
/*$vite$:1*/
|
package/dist/tooling/index.js
CHANGED
|
@@ -1,26 +1,27 @@
|
|
|
1
|
-
import { getDirectoryPath } from
|
|
2
|
-
import {
|
|
3
|
-
|
|
1
|
+
import { getDirectoryPath } from "@typespec/compiler";
|
|
2
|
+
import { mkdir, readFile, writeFile } from "fs/promises";
|
|
3
|
+
//#region src/tooling/index.ts
|
|
4
|
+
/**
|
|
5
|
+
* @experimental This API is experimental
|
|
6
|
+
*/
|
|
4
7
|
async function buildSamples_experimental(rootDir, output, samples) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
].join("\n");
|
|
23
|
-
await writeFile(output, dts);
|
|
8
|
+
const resolvedSamples = {};
|
|
9
|
+
for (const [name, config] of Object.entries(samples)) {
|
|
10
|
+
const content = await readFile(`${rootDir}/${config.filename}`, "utf-8");
|
|
11
|
+
resolvedSamples[name] = {
|
|
12
|
+
filename: config.filename,
|
|
13
|
+
content,
|
|
14
|
+
preferredEmitter: config.preferredEmitter,
|
|
15
|
+
description: config.description,
|
|
16
|
+
compilerOptions: config.compilerOptions
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
await mkdir(getDirectoryPath(output), { recursive: true });
|
|
20
|
+
await writeFile(output, [
|
|
21
|
+
`import type { PlaygroundSample } from "@typespec/playground";`,
|
|
22
|
+
`const samples: Record<string, PlaygroundSample> = ${JSON.stringify(resolvedSamples, null, 2)};`,
|
|
23
|
+
`export default samples;`
|
|
24
|
+
].join("\n"));
|
|
24
25
|
}
|
|
25
|
-
|
|
26
|
+
//#endregion
|
|
26
27
|
export { buildSamples_experimental };
|
package/dist/vite/index.js
CHANGED
|
@@ -1,91 +1,67 @@
|
|
|
1
|
-
import { typespecBundlePlugin } from
|
|
2
|
-
import react from
|
|
3
|
-
|
|
1
|
+
import { typespecBundlePlugin } from "@typespec/bundler/vite";
|
|
2
|
+
import react from "@vitejs/plugin-react";
|
|
3
|
+
//#region src/vite/index.ts
|
|
4
4
|
function definePlaygroundViteConfig(config) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
},
|
|
28
|
-
plugins: [
|
|
29
|
-
react({}),
|
|
30
|
-
playgroundManifestPlugin(config),
|
|
31
|
-
!config.skipBundleLibraries ? typespecBundlePlugin({
|
|
32
|
-
folderName: "libs",
|
|
33
|
-
libraries: config.libraries
|
|
34
|
-
}) : void 0
|
|
35
|
-
],
|
|
36
|
-
server: {
|
|
37
|
-
fs: {
|
|
38
|
-
strict: false
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
};
|
|
5
|
+
return {
|
|
6
|
+
base: "./",
|
|
7
|
+
build: {
|
|
8
|
+
target: "esnext",
|
|
9
|
+
chunkSizeWarningLimit: 5e3,
|
|
10
|
+
rollupOptions: { output: { manualChunks(id) {
|
|
11
|
+
if (id.includes("/node_modules/monaco-editor/esm/vs/editor")) return "monaco";
|
|
12
|
+
} } }
|
|
13
|
+
},
|
|
14
|
+
esbuild: { logOverride: { "this-is-undefined-in-esm": "silent" } },
|
|
15
|
+
assetsInclude: [/\.tsp$/],
|
|
16
|
+
optimizeDeps: { exclude: ["swagger-ui"] },
|
|
17
|
+
plugins: [
|
|
18
|
+
react({}),
|
|
19
|
+
playgroundManifestPlugin(config),
|
|
20
|
+
!config.skipBundleLibraries ? typespecBundlePlugin({
|
|
21
|
+
folderName: "libs",
|
|
22
|
+
libraries: config.libraries
|
|
23
|
+
}) : void 0
|
|
24
|
+
],
|
|
25
|
+
server: { fs: { strict: false } }
|
|
26
|
+
};
|
|
42
27
|
}
|
|
43
28
|
function playgroundManifestPlugin(config) {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
const sampleObj = [
|
|
65
|
-
"{",
|
|
66
|
-
...Object.entries(samples ?? {}).map(
|
|
67
|
-
([label, config2], index) => `${JSON.stringify(label)}: {
|
|
68
|
-
fileName: ${JSON.stringify(config2.filename)},
|
|
69
|
-
preferredEmitter: ${config2.preferredEmitter ? JSON.stringify(config2.preferredEmitter) : "undefined"},
|
|
29
|
+
const { samples, ...manifest } = config;
|
|
30
|
+
let viteConfig;
|
|
31
|
+
return {
|
|
32
|
+
name: "playground-manifest",
|
|
33
|
+
enforce: "pre",
|
|
34
|
+
async configResolved(c) {
|
|
35
|
+
viteConfig = c;
|
|
36
|
+
},
|
|
37
|
+
resolveId(id) {
|
|
38
|
+
if (id === "@typespec/playground/manifest") return id;
|
|
39
|
+
return null;
|
|
40
|
+
},
|
|
41
|
+
load(id) {
|
|
42
|
+
if (id === `@typespec/playground/manifest`) {
|
|
43
|
+
const sampleImport = Object.values(samples ?? {}).map((sampleValue, index) => `import s${index} from "${viteConfig.root}/${sampleValue.filename}?raw"`).join("\n");
|
|
44
|
+
const sampleObj = [
|
|
45
|
+
"{",
|
|
46
|
+
...Object.entries(samples ?? {}).map(([label, config], index) => `${JSON.stringify(label)}: {
|
|
47
|
+
fileName: ${JSON.stringify(config.filename)},
|
|
48
|
+
preferredEmitter: ${config.preferredEmitter ? JSON.stringify(config.preferredEmitter) : "undefined"},
|
|
70
49
|
content: s${index},
|
|
71
|
-
${
|
|
50
|
+
${config.compilerOptions ? `compilerOptions: ${JSON.stringify(config.compilerOptions)},` : ""}
|
|
72
51
|
|
|
73
|
-
}, `
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
const file = `
|
|
52
|
+
}, `),
|
|
53
|
+
"}"
|
|
54
|
+
].join("\n");
|
|
55
|
+
return `
|
|
78
56
|
${sampleImport};
|
|
79
57
|
|
|
80
58
|
export default {
|
|
81
59
|
...${JSON.stringify(manifest)},
|
|
82
60
|
samples: ${sampleObj}
|
|
83
61
|
};`;
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
}
|
|
88
|
-
};
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
};
|
|
89
65
|
}
|
|
90
|
-
|
|
66
|
+
//#endregion
|
|
91
67
|
export { definePlaygroundViteConfig };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@typespec/playground",
|
|
3
|
-
"version": "0.14.0-dev.
|
|
3
|
+
"version": "0.14.0-dev.5",
|
|
4
4
|
"author": "Microsoft Corporation",
|
|
5
5
|
"description": "TypeSpec playground UI components.",
|
|
6
6
|
"homepage": "https://typespec.io",
|
|
@@ -61,15 +61,15 @@
|
|
|
61
61
|
"dependencies": {
|
|
62
62
|
"@fluentui/react-components": "~9.73.3",
|
|
63
63
|
"@fluentui/react-icons": "^2.0.321",
|
|
64
|
-
"@typespec/bundler": "^0.5.1 || >= 0.5.2-dev.
|
|
65
|
-
"@typespec/compiler": "^1.10.0 || >= 1.11.0-dev.
|
|
66
|
-
"@typespec/html-program-viewer": "^0.80.0 || >= 0.81.0-dev.
|
|
67
|
-
"@typespec/http": "^1.10.0 || >= 1.11.0-dev.
|
|
68
|
-
"@typespec/openapi": "^1.10.0 || >= 1.11.0-dev.
|
|
69
|
-
"@typespec/openapi3": "^1.10.0 || >= 1.11.0-dev.
|
|
70
|
-
"@typespec/protobuf": "^0.80.0 || >= 0.81.0-dev.
|
|
71
|
-
"@typespec/rest": "^0.80.0 || >= 0.81.0-dev.
|
|
72
|
-
"@typespec/versioning": "^0.80.0 || >= 0.81.0-dev.
|
|
64
|
+
"@typespec/bundler": "^0.5.1 || >= 0.5.2-dev.4",
|
|
65
|
+
"@typespec/compiler": "^1.10.0 || >= 1.11.0-dev.6",
|
|
66
|
+
"@typespec/html-program-viewer": "^0.80.0 || >= 0.81.0-dev.3",
|
|
67
|
+
"@typespec/http": "^1.10.0 || >= 1.11.0-dev.3",
|
|
68
|
+
"@typespec/openapi": "^1.10.0 || >= 1.11.0-dev.2",
|
|
69
|
+
"@typespec/openapi3": "^1.10.0 || >= 1.11.0-dev.4",
|
|
70
|
+
"@typespec/protobuf": "^0.80.0 || >= 0.81.0-dev.2",
|
|
71
|
+
"@typespec/rest": "^0.80.0 || >= 0.81.0-dev.2",
|
|
72
|
+
"@typespec/versioning": "^0.80.0 || >= 0.81.0-dev.2",
|
|
73
73
|
"clsx": "^2.1.1",
|
|
74
74
|
"debounce": "~3.0.0",
|
|
75
75
|
"lzutf8": "0.6.3",
|
|
@@ -95,15 +95,15 @@
|
|
|
95
95
|
"@types/react": "~19.2.14",
|
|
96
96
|
"@types/react-dom": "~19.2.3",
|
|
97
97
|
"@types/swagger-ui-dist": "~3.30.6",
|
|
98
|
-
"@typespec/bundler": "^0.5.1 || >= 0.5.2-dev.
|
|
99
|
-
"@vitejs/plugin-react": "~
|
|
98
|
+
"@typespec/bundler": "^0.5.1 || >= 0.5.2-dev.4",
|
|
99
|
+
"@vitejs/plugin-react": "~6.0.1",
|
|
100
100
|
"c8": "^11.0.0",
|
|
101
101
|
"cross-env": "~10.1.0",
|
|
102
102
|
"es-module-shims": "~2.8.0",
|
|
103
103
|
"rimraf": "~6.1.3",
|
|
104
104
|
"storybook": "^10.2.19",
|
|
105
105
|
"typescript": "~5.9.3",
|
|
106
|
-
"vite": "^
|
|
106
|
+
"vite": "^8.0.1",
|
|
107
107
|
"vite-plugin-checker": "^0.12.0",
|
|
108
108
|
"vite-plugin-dts": "4.5.4",
|
|
109
109
|
"vitest": "^4.1.0",
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { jsx } from 'react/jsx-runtime';
|
|
2
|
-
import { useRef, useEffect } from 'react';
|
|
3
|
-
import SwaggerUIBundle from 'swagger-ui-dist/swagger-ui-es-bundle.js';
|
|
4
|
-
|
|
5
|
-
const reactWrapper = (props) => {
|
|
6
|
-
const uiRef = useRef(null);
|
|
7
|
-
const uiInstance = useRef(null);
|
|
8
|
-
useEffect(() => {
|
|
9
|
-
if (uiInstance.current === null) {
|
|
10
|
-
uiInstance.current = SwaggerUIBundle({
|
|
11
|
-
domNode: uiRef.current,
|
|
12
|
-
spec: {}
|
|
13
|
-
});
|
|
14
|
-
}
|
|
15
|
-
uiInstance.current.specActions.updateSpec(props.spec);
|
|
16
|
-
}, [props.spec]);
|
|
17
|
-
return /* @__PURE__ */ jsx("div", { ref: uiRef });
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
export { reactWrapper as default };
|