@typespec/playground 0.1.0-alpha.4-dev.15 → 0.1.0-alpha.4-dev.17
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.css +28 -0
- package/dist/index.js +1 -1
- package/dist/react/index.js +77 -44
- package/dist/react/index.js.map +1 -1
- package/dist/src/browser-host.d.ts +1 -1
- package/dist/src/browser-host.d.ts.map +1 -1
- package/dist/src/react/context/index.d.ts +2 -0
- package/dist/src/react/context/index.d.ts.map +1 -0
- package/dist/src/react/context/playground-context.d.ts +8 -0
- package/dist/src/react/context/playground-context.d.ts.map +1 -0
- package/dist/src/react/default-footer.d.ts +3 -0
- package/dist/src/react/default-footer.d.ts.map +1 -0
- package/dist/src/react/footer/footer-item.d.ts +8 -0
- package/dist/src/react/footer/footer-item.d.ts.map +1 -0
- package/dist/src/react/footer/footer-version-item.d.ts +20 -0
- package/dist/src/react/footer/footer-version-item.d.ts.map +1 -0
- package/dist/src/react/footer/footer.d.ts +7 -0
- package/dist/src/react/footer/footer.d.ts.map +1 -0
- package/dist/src/react/footer/index.d.ts +4 -0
- package/dist/src/react/footer/index.d.ts.map +1 -0
- package/dist/src/react/index.d.ts +2 -0
- package/dist/src/react/index.d.ts.map +1 -1
- package/dist/src/react/playground.d.ts +6 -2
- package/dist/src/react/playground.d.ts.map +1 -1
- package/dist/src/react/standalone.d.ts +2 -2
- package/dist/src/react/standalone.d.ts.map +1 -1
- package/dist/src/state-storage.d.ts.map +1 -1
- package/dist/src/types.d.ts +2 -1
- package/dist/src/types.d.ts.map +1 -1
- package/dist/src/vite/types.d.ts +6 -7
- package/dist/src/vite/types.d.ts.map +1 -1
- package/dist/{state-storage-1ccb8536.js → state-storage-2a373027.js} +12 -4
- package/dist/state-storage-2a373027.js.map +1 -0
- package/package.json +3 -2
- package/dist/src/react/footer.d.ts +0 -7
- package/dist/src/react/footer.d.ts.map +0 -1
- package/dist/state-storage-1ccb8536.js.map +0 -1
package/dist/index.css
CHANGED
|
@@ -1,3 +1,22 @@
|
|
|
1
|
+
.footer-module_footer__QqUEE {
|
|
2
|
+
grid-area: footer;
|
|
3
|
+
display: flex;
|
|
4
|
+
font-size: 14px;
|
|
5
|
+
|
|
6
|
+
background-color: #007acc;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
.footer-module_footer-item__7rhbZ {
|
|
10
|
+
text-decoration: none;
|
|
11
|
+
color: #fefefe;
|
|
12
|
+
border-right: 1px solid #d5d5d5;
|
|
13
|
+
padding: 0 5px;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
.footer-module_footer-item__7rhbZ:hover {
|
|
17
|
+
background-color: #063a5c;
|
|
18
|
+
}
|
|
19
|
+
|
|
1
20
|
.split-pane-module_split-pane__XCqR8 {
|
|
2
21
|
flex: 1;
|
|
3
22
|
height: 100%;
|
|
@@ -56,3 +75,12 @@
|
|
|
56
75
|
width: 100%;
|
|
57
76
|
overflow: hidden;
|
|
58
77
|
}
|
|
78
|
+
|
|
79
|
+
.footer-version-item-module_version-item__pjuvV {
|
|
80
|
+
padding: 0;
|
|
81
|
+
}
|
|
82
|
+
.footer-version-item-module_button__70iqf {
|
|
83
|
+
cursor: pointer;
|
|
84
|
+
height: 100%;
|
|
85
|
+
padding: 0 5px;
|
|
86
|
+
}
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { c as createBrowserHost, a as createUrlStateStorage, r as registerMonacoLanguage } from './state-storage-
|
|
1
|
+
export { c as createBrowserHost, a as createUrlStateStorage, r as registerMonacoLanguage } from './state-storage-2a373027.js';
|
|
2
2
|
import '@typespec/compiler';
|
|
3
3
|
import 'monaco-editor';
|
|
4
4
|
import 'vscode-languageserver';
|
package/dist/react/index.js
CHANGED
|
@@ -1,18 +1,67 @@
|
|
|
1
|
+
import { createContext, useContext, memo, useCallback, useMemo, useRef, useEffect, useState, useId as useId$1 } from 'react';
|
|
1
2
|
import { jsx, jsxs, Fragment } from '@emotion/react/jsx-runtime';
|
|
3
|
+
import { mergeClasses, Popover, PopoverTrigger, PopoverSurface, Title3, Table, TableHeader, TableRow, TableHeaderCell, TableBody, TableCell, Select, useId, Label, RadioGroup, Radio, Input, Switch, Checkbox, Link, tokens, Toolbar, Tooltip, ToolbarButton, Dialog, DialogTrigger, DialogSurface, DialogBody, useToastController, Toast, ToastTitle, ToastBody, Toaster, FluentProvider, webLightTheme } from '@fluentui/react-components';
|
|
2
4
|
import debounce from 'debounce';
|
|
3
5
|
import { editor, Uri, MarkerSeverity, KeyMod, KeyCode } from 'monaco-editor';
|
|
4
|
-
import { useCallback, useMemo, useRef, useEffect, useState, useId as useId$1 } from 'react';
|
|
5
6
|
import { CompletionItemTag } from 'vscode-languageserver';
|
|
6
|
-
import { g as getMarkerLocation, c as createBrowserHost, r as registerMonacoLanguage, a as createUrlStateStorage } from '../state-storage-
|
|
7
|
-
import { Select, useId, Label, RadioGroup, Radio, Input, Switch, Checkbox, Link, tokens, Toolbar, Tooltip, ToolbarButton, Dialog, DialogTrigger, DialogSurface, DialogBody, mergeClasses, useToastController, Toast, ToastTitle, ToastBody, Toaster, FluentProvider, webLightTheme } from '@fluentui/react-components';
|
|
7
|
+
import { g as getMarkerLocation, c as createBrowserHost, r as registerMonacoLanguage, a as createUrlStateStorage } from '../state-storage-2a373027.js';
|
|
8
8
|
import { Save16Regular, Broom16Filled, Settings24Regular, Bug16Regular } from '@fluentui/react-icons';
|
|
9
9
|
import { css } from '@emotion/react';
|
|
10
|
-
import { TypeSpecProgramViewer } from '@typespec/html-program-viewer';
|
|
10
|
+
import { ColorProvider, TypeSpecProgramViewer } from '@typespec/html-program-viewer';
|
|
11
11
|
import { createRoot } from 'react-dom/client';
|
|
12
12
|
import '@typespec/compiler';
|
|
13
13
|
import 'vscode-languageserver-textdocument';
|
|
14
14
|
import 'lzutf8';
|
|
15
15
|
|
|
16
|
+
const PlaygroundContext = createContext(undefined);
|
|
17
|
+
const PlaygroundContextProvider = PlaygroundContext.Provider;
|
|
18
|
+
function usePlaygroundContext() {
|
|
19
|
+
const context = useContext(PlaygroundContext);
|
|
20
|
+
if (context === undefined) {
|
|
21
|
+
throw new Error("usePlaygroundContext must be used within a PlaygroundContextProvider");
|
|
22
|
+
}
|
|
23
|
+
return context;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
var style$2 = {"footer":"footer-module_footer__QqUEE","footer-item":"footer-module_footer-item__7rhbZ"};
|
|
27
|
+
|
|
28
|
+
const FooterItem = ({ children, link, className }) => {
|
|
29
|
+
const resolvedClassName = mergeClasses(style$2["footer-item"], className);
|
|
30
|
+
return link ? (jsx("a", { className: resolvedClassName, href: link, target: "_blank", children: children })) : (jsx("div", { className: resolvedClassName, children: children }));
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
var style$1 = {"version-item":"footer-version-item-module_version-item__pjuvV","button":"footer-version-item-module_button__70iqf"};
|
|
34
|
+
|
|
35
|
+
const FooterVersionItem = memo(({ versionSelector }) => {
|
|
36
|
+
var _a;
|
|
37
|
+
const { host } = usePlaygroundContext();
|
|
38
|
+
const latest = versionSelector === null || versionSelector === void 0 ? void 0 : versionSelector.latest;
|
|
39
|
+
const selected = (_a = versionSelector === null || versionSelector === void 0 ? void 0 : versionSelector.selected) !== null && _a !== void 0 ? _a : host.compiler.MANIFEST.version;
|
|
40
|
+
return (jsx(FooterItem, { className: style$1["version-item"], children: jsxs(Popover, { children: [jsx(PopoverTrigger, { disableButtonEnhancement: true, children: jsxs("div", { className: style$1["button"], children: [jsx("span", { children: "Version " }), jsx("span", { children: selected }), jsx("span", { children: latest ? (latest === selected ? " (latest)" : " (old)") : "" })] }) }), jsx(PopoverSurface, { children: jsx(VersionsPopup, { versionSelector: versionSelector }) })] }) }));
|
|
41
|
+
});
|
|
42
|
+
const VersionsPopup = memo(({ versionSelector }) => {
|
|
43
|
+
const { host } = usePlaygroundContext();
|
|
44
|
+
return (jsxs("div", { style: { maxWidth: "400px" }, children: [versionSelector && jsx(VersionSelector, { ...versionSelector }), jsxs("div", { children: [jsx(Title3, { children: "Loaded libraries" }), jsxs(Table, { size: "small", children: [jsx(TableHeader, { children: jsx(TableRow, { children: columns.map((column) => (jsx(TableHeaderCell, { children: column.label }, column.columnKey))) }) }), jsx(TableBody, { children: Object.values(host.libraries).map((item) => (jsxs(TableRow, { children: [jsx(TableCell, { children: item.name }), jsx(TableCell, { children: item.packageJson.version })] }, item.name))) })] })] })] }));
|
|
45
|
+
});
|
|
46
|
+
const columns = [
|
|
47
|
+
{ columnKey: "name", label: "Library" },
|
|
48
|
+
{ columnKey: "version", label: "Version" },
|
|
49
|
+
];
|
|
50
|
+
const VersionSelector = memo(({ versions, selected, latest, onChange }) => {
|
|
51
|
+
const changeVersion = useCallback((ev, data) => {
|
|
52
|
+
onChange(versions.find((x) => x.name === data.value));
|
|
53
|
+
}, [versions, onChange]);
|
|
54
|
+
return (jsxs("div", { children: [jsx(Title3, { children: "Select release" }), jsx(Select, { value: selected, onChange: changeVersion, children: versions.map((version) => (jsxs("option", { value: version.name, children: [version.label, " ", version.name === latest ? "(latest)" : ""] }, version.name))) })] }));
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
const Footer = ({ className, children }) => {
|
|
58
|
+
return jsx("div", { className: mergeClasses(style$2.footer, className), children: children });
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
const DefaultFooter = () => {
|
|
62
|
+
return (jsx(Footer, { children: jsx(FooterVersionItem, {}) }));
|
|
63
|
+
};
|
|
64
|
+
|
|
16
65
|
const EmitterDropdown = ({ emitters, onSelectedEmitterChange, selectedEmitter, }) => {
|
|
17
66
|
const options = emitters.map((emitterName) => {
|
|
18
67
|
return jsx("option", { children: emitterName }, emitterName);
|
|
@@ -171,33 +220,6 @@ function useMonacoModel(uri, language) {
|
|
|
171
220
|
}, [uri, language]);
|
|
172
221
|
}
|
|
173
222
|
|
|
174
|
-
const Footer = ({ host }) => {
|
|
175
|
-
const { MANIFEST } = host.compiler;
|
|
176
|
-
const prItem = MANIFEST.pr ? (jsxs(FooterItem, { link: `https://github.com/microsoft/typespec/pull/${MANIFEST.pr}`, children: [jsx("span", { children: "PR " }), jsx("span", { children: MANIFEST.pr })] })) : (jsx(Fragment, {}));
|
|
177
|
-
return (jsxs("div", { css: [
|
|
178
|
-
{
|
|
179
|
-
gridArea: "footer",
|
|
180
|
-
gridRow: "3",
|
|
181
|
-
backgroundColor: "#007acc",
|
|
182
|
-
display: "flex",
|
|
183
|
-
fontSize: "14px",
|
|
184
|
-
},
|
|
185
|
-
MANIFEST.pr ? { backgroundColor: "#ce662a" } : {},
|
|
186
|
-
], children: [prItem, jsxs(FooterItem, { children: [jsx("span", { children: "TypeSpec Version " }), jsx("span", { children: MANIFEST.version })] }), jsxs(FooterItem, { link: `https://github.com/microsoft/typespec/commit/${MANIFEST.commit}`, children: [jsx("span", { children: "Commit " }), jsx("span", { children: MANIFEST.commit.slice(0, 6) })] })] }));
|
|
187
|
-
};
|
|
188
|
-
const FooterItem = ({ children, link }) => {
|
|
189
|
-
return link ? (jsx("a", { css: FooterItemStyles, href: link, target: "_blank", children: children })) : (jsx("div", { css: FooterItemStyles, children: children }));
|
|
190
|
-
};
|
|
191
|
-
const FooterItemStyles = css({
|
|
192
|
-
textDecoration: "none",
|
|
193
|
-
color: "#fefefe",
|
|
194
|
-
borderRight: "1px solid #d5d5d5",
|
|
195
|
-
padding: "0 5px",
|
|
196
|
-
"&:hover": {
|
|
197
|
-
backgroundColor: "#063a5c",
|
|
198
|
-
},
|
|
199
|
-
});
|
|
200
|
-
|
|
201
223
|
/**
|
|
202
224
|
* Hook to manage a value that could be either controlled or uncontrolled, such as a checked state or
|
|
203
225
|
* text box string.
|
|
@@ -448,7 +470,7 @@ const OutputContent = ({ viewSelection, program, viewers, editorOptions, }) => {
|
|
|
448
470
|
return (jsx("div", { css: {
|
|
449
471
|
height: "100%",
|
|
450
472
|
overflow: "scroll",
|
|
451
|
-
}, children: program && jsx(
|
|
473
|
+
}, children: program && jsx(TypeGraphViewer, { program: program }) }));
|
|
452
474
|
}
|
|
453
475
|
};
|
|
454
476
|
const ErrorTabLabel = ({ diagnostics }) => {
|
|
@@ -461,6 +483,19 @@ const ErrorTabCountStyles = css({
|
|
|
461
483
|
padding: "0 5px",
|
|
462
484
|
borderRadius: "20px",
|
|
463
485
|
});
|
|
486
|
+
const TypeGraphViewer = ({ program }) => {
|
|
487
|
+
return (jsx(ColorProvider, { colors: TypeGraphColors, children: jsx(TypeSpecProgramViewer, { program: program }) }));
|
|
488
|
+
};
|
|
489
|
+
const TypeGraphColors = {
|
|
490
|
+
background: tokens.colorNeutralBackground1,
|
|
491
|
+
typeKind: tokens.colorPaletteBerryForeground2,
|
|
492
|
+
typeName: tokens.colorNeutralForeground2,
|
|
493
|
+
dataKey: tokens.colorNeutralForeground2,
|
|
494
|
+
ref: tokens.colorBrandForeground1,
|
|
495
|
+
literal: tokens.colorPaletteLightGreenForeground2,
|
|
496
|
+
indentationGuide: tokens.colorNeutralForeground4,
|
|
497
|
+
property: tokens.colorPaletteMarigoldForeground2,
|
|
498
|
+
};
|
|
464
499
|
|
|
465
500
|
function Pane({ children, ...props }) {
|
|
466
501
|
return jsx("div", { ...props, children: children });
|
|
@@ -622,7 +657,7 @@ function assertsSize(size, sum, defaultValue = Infinity) {
|
|
|
622
657
|
}
|
|
623
658
|
|
|
624
659
|
const Playground = (props) => {
|
|
625
|
-
var _a, _b, _c, _d;
|
|
660
|
+
var _a, _b, _c, _d, _e;
|
|
626
661
|
const { host, onSave } = props;
|
|
627
662
|
const editorRef = useRef(undefined);
|
|
628
663
|
const [selectedEmitter, onSelectedEmitterChange] = useControllableValue(props.emitter, props.defaultEmitter, props.onEmitterChange);
|
|
@@ -723,16 +758,14 @@ const Playground = (props) => {
|
|
|
723
758
|
const onTypeSpecEditorMount = useCallback(({ editor }) => {
|
|
724
759
|
editorRef.current = editor;
|
|
725
760
|
}, []);
|
|
726
|
-
return (jsxs("div", { css: {
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
overflow: "hidden",
|
|
734
|
-
fontFamily: `"Segoe UI", Tahoma, Geneva, Verdana, sans-serif`,
|
|
735
|
-
}, children: [jsxs(SplitPane, { initialSizes: ["50%", "50%"], css: { gridArea: "typespeceditor", width: "100%", height: "100%", overflow: "hidden" }, children: [jsxs(Pane, { children: [jsx(EditorCommandBar, { host: host, selectedEmitter: selectedEmitter, onSelectedEmitterChange: onSelectedEmitterChange, compilerOptions: compilerOptions, onCompilerOptionsChange: onCompilerOptionsChange, samples: props.samples, selectedSampleName: selectedSampleName, onSelectedSampleNameChange: onSelectedSampleNameChange, saveCode: saveCode, formatCode: formatCode, newIssue: ((_b = props === null || props === void 0 ? void 0 : props.links) === null || _b === void 0 ? void 0 : _b.githubIssueUrl) ? newIssue : undefined, documentationUrl: (_c = props.links) === null || _c === void 0 ? void 0 : _c.documentationUrl }), jsx(TypeSpecEditor, { model: typespecModel, actions: typespecEditorActions, options: props.editorOptions, onMount: onTypeSpecEditorMount })] }), jsx(Pane, { children: jsx(OutputView, { compilationState: compilationState, editorOptions: props.editorOptions, viewers: (_d = props.emitterViewers) === null || _d === void 0 ? void 0 : _d[selectedEmitter] }) })] }), jsx(Footer, { host: host })] }));
|
|
761
|
+
return (jsx(PlaygroundContextProvider, { value: { host }, children: jsxs("div", { css: {
|
|
762
|
+
display: "flex",
|
|
763
|
+
flexDirection: "column",
|
|
764
|
+
width: "100%",
|
|
765
|
+
height: "100%",
|
|
766
|
+
overflow: "hidden",
|
|
767
|
+
fontFamily: `"Segoe UI", Tahoma, Geneva, Verdana, sans-serif`,
|
|
768
|
+
}, children: [jsxs(SplitPane, { initialSizes: ["50%", "50%"], css: { gridArea: "typespeceditor", width: "100%", height: "100%", overflow: "hidden" }, children: [jsxs(Pane, { children: [jsx(EditorCommandBar, { host: host, selectedEmitter: selectedEmitter, onSelectedEmitterChange: onSelectedEmitterChange, compilerOptions: compilerOptions, onCompilerOptionsChange: onCompilerOptionsChange, samples: props.samples, selectedSampleName: selectedSampleName, onSelectedSampleNameChange: onSelectedSampleNameChange, saveCode: saveCode, formatCode: formatCode, newIssue: ((_b = props === null || props === void 0 ? void 0 : props.links) === null || _b === void 0 ? void 0 : _b.githubIssueUrl) ? newIssue : undefined, documentationUrl: (_c = props.links) === null || _c === void 0 ? void 0 : _c.documentationUrl }), jsx(TypeSpecEditor, { model: typespecModel, actions: typespecEditorActions, options: props.editorOptions, onMount: onTypeSpecEditorMount })] }), jsx(Pane, { children: jsx(OutputView, { compilationState: compilationState, editorOptions: props.editorOptions, viewers: (_d = props.emitterViewers) === null || _d === void 0 ? void 0 : _d[selectedEmitter] }) })] }), (_e = props.footer) !== null && _e !== void 0 ? _e : jsx(DefaultFooter, {})] }) }));
|
|
736
769
|
};
|
|
737
770
|
const outputDir = "./tsp-output";
|
|
738
771
|
async function compile(host, content, selectedEmitter, options) {
|
|
@@ -873,5 +906,5 @@ function createStandalonePlaygroundStateStorage() {
|
|
|
873
906
|
};
|
|
874
907
|
}
|
|
875
908
|
|
|
876
|
-
export { Playground, StandalonePlayground, createReactPlayground, renderReactPlayground };
|
|
909
|
+
export { Footer, FooterItem, FooterVersionItem, Playground, StandalonePlayground, createReactPlayground, renderReactPlayground, usePlaygroundContext };
|
|
877
910
|
//# sourceMappingURL=index.js.map
|