@typespec/playground 0.1.0-alpha.4-dev.17 → 0.1.0-alpha.4-dev.18
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 +201 -4
- package/dist/index.js +1 -1
- package/dist/react/index.js +145 -115
- package/dist/react/index.js.map +1 -1
- package/dist/react/viewers/index.js +19 -0
- package/dist/react/viewers/index.js.map +1 -0
- package/dist/src/editor-command-bar/editor-command-bar.d.ts.map +1 -0
- package/dist/src/react/diagnostic-list/diagnostic-list.d.ts +8 -0
- package/dist/src/react/diagnostic-list/diagnostic-list.d.ts.map +1 -0
- package/dist/src/react/{file-output.d.ts → file-output/file-output.d.ts} +1 -1
- package/dist/src/react/file-output/file-output.d.ts.map +1 -0
- package/dist/src/react/footer/footer-version-item.d.ts +1 -1
- package/dist/src/react/footer/footer-version-item.d.ts.map +1 -1
- package/dist/src/react/index.d.ts +1 -1
- package/dist/src/react/index.d.ts.map +1 -1
- package/dist/src/react/{output-tabs.d.ts → output-tabs/output-tabs.d.ts} +2 -8
- package/dist/src/react/output-tabs/output-tabs.d.ts.map +1 -0
- package/dist/src/react/{output-view.d.ts → output-view/output-view.d.ts} +2 -2
- package/dist/src/react/output-view/output-view.d.ts.map +1 -0
- package/dist/src/react/playground.d.ts.map +1 -1
- package/dist/src/react/problem-pane/header.d.ts +9 -0
- package/dist/src/react/problem-pane/header.d.ts.map +1 -0
- package/dist/src/react/problem-pane/index.d.ts +2 -0
- package/dist/src/react/problem-pane/index.d.ts.map +1 -0
- package/dist/src/react/problem-pane/problem-pane.d.ts +11 -0
- package/dist/src/react/problem-pane/problem-pane.d.ts.map +1 -0
- package/dist/src/react/settings/compiler-settings-dialog-button.d.ts +8 -0
- package/dist/src/react/settings/compiler-settings-dialog-button.d.ts.map +1 -0
- package/dist/src/react/settings/compiler-settings.d.ts +6 -6
- package/dist/src/react/settings/compiler-settings.d.ts.map +1 -1
- package/dist/src/react/settings/emitter-options-form.d.ts +3 -3
- package/dist/src/react/settings/emitter-options-form.d.ts.map +1 -1
- package/dist/src/react/split-pane/pane.d.ts +1 -1
- package/dist/src/react/split-pane/pane.d.ts.map +1 -1
- package/dist/src/react/split-pane/sash.d.ts +1 -1
- package/dist/src/react/split-pane/sash.d.ts.map +1 -1
- package/dist/src/react/split-pane/split-pane.d.ts +2 -2
- package/dist/src/react/split-pane/split-pane.d.ts.map +1 -1
- package/dist/src/react/standalone.d.ts +1 -1
- package/dist/src/react/standalone.d.ts.map +1 -1
- package/dist/src/react/{viewers.d.ts → viewers/index.d.ts} +2 -2
- package/dist/src/react/viewers/index.d.ts.map +1 -0
- package/dist/src/react/{swagger-ui.d.ts → viewers/swagger-ui.d.ts} +1 -1
- package/dist/src/react/viewers/swagger-ui.d.ts.map +1 -0
- package/dist/src/services.d.ts +2 -2
- package/dist/src/services.d.ts.map +1 -1
- package/dist/src/vite/index.d.ts.map +1 -1
- package/dist/{state-storage-2a373027.js → state-storage-5b3bbcd1.js} +3 -3
- package/dist/state-storage-5b3bbcd1.js.map +1 -0
- package/dist/vite/index.js +1 -6
- package/dist/vite/index.js.map +1 -1
- package/package.json +3 -4
- package/dist/react/viewers.js +0 -29
- package/dist/react/viewers.js.map +0 -1
- package/dist/src/react/diagnostic-list.d.ts +0 -11
- package/dist/src/react/diagnostic-list.d.ts.map +0 -1
- package/dist/src/react/editor-command-bar.d.ts.map +0 -1
- package/dist/src/react/error-tab.d.ts +0 -12
- package/dist/src/react/error-tab.d.ts.map +0 -1
- package/dist/src/react/file-output.d.ts.map +0 -1
- package/dist/src/react/output-tabs.d.ts.map +0 -1
- package/dist/src/react/output-view.d.ts.map +0 -1
- package/dist/src/react/swagger-ui.d.ts.map +0 -1
- package/dist/src/react/viewers.d.ts.map +0 -1
- package/dist/state-storage-2a373027.js.map +0 -1
- /package/dist/src/{react → editor-command-bar}/editor-command-bar.d.ts +0 -0
package/dist/react/index.js
CHANGED
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
import { createContext, useContext, memo, useCallback, useMemo, useRef, useEffect, useState, useId as useId$1 } from 'react';
|
|
2
|
-
import { jsx, jsxs, Fragment } from '
|
|
3
|
-
import { mergeClasses, Popover, PopoverTrigger, PopoverSurface, Title3, Table, TableHeader, TableRow, TableHeaderCell, TableBody, TableCell, Select, useId, Label, RadioGroup, Radio, Input, Switch, Checkbox,
|
|
2
|
+
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
3
|
+
import { mergeClasses, Popover, PopoverTrigger, PopoverSurface, Title3, Table, TableHeader, TableRow, TableHeaderCell, TableBody, TableCell, Select, useId, Label, RadioGroup, Radio, Input, Switch, Checkbox, Divider, Dialog, DialogTrigger, ToolbarButton, DialogSurface, DialogBody, DialogTitle, DialogContent, Link, Toolbar, Tooltip, TabList, Tab, tokens, useToastController, Toast, ToastTitle, ToastBody, Toaster, FluentProvider, webLightTheme } from '@fluentui/react-components';
|
|
4
4
|
import debounce from 'debounce';
|
|
5
5
|
import { editor, Uri, MarkerSeverity, KeyMod, KeyCode } from 'monaco-editor';
|
|
6
6
|
import { CompletionItemTag } from 'vscode-languageserver';
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import { css } from '@emotion/react';
|
|
7
|
+
import { Settings24Regular, Save16Regular, Broom16Filled, Bug16Regular, ErrorCircle16Filled, Warning16Filled, ChevronDown16Regular } from '@fluentui/react-icons';
|
|
8
|
+
import { g as getMonacoRange, c as createBrowserHost, r as registerMonacoLanguage, a as createUrlStateStorage } from '../state-storage-5b3bbcd1.js';
|
|
10
9
|
import { ColorProvider, TypeSpecProgramViewer } from '@typespec/html-program-viewer';
|
|
10
|
+
import { getSourceLocation } from '@typespec/compiler';
|
|
11
11
|
import { createRoot } from 'react-dom/client';
|
|
12
|
-
import '@typespec/compiler';
|
|
13
12
|
import 'vscode-languageserver-textdocument';
|
|
14
13
|
import 'lzutf8';
|
|
15
14
|
|
|
@@ -23,21 +22,21 @@ function usePlaygroundContext() {
|
|
|
23
22
|
return context;
|
|
24
23
|
}
|
|
25
24
|
|
|
26
|
-
var style$
|
|
25
|
+
var style$b = {"footer":"footer-module_footer__QqUEE","footer-item":"footer-module_footer-item__7rhbZ"};
|
|
27
26
|
|
|
28
27
|
const FooterItem = ({ children, link, className }) => {
|
|
29
|
-
const resolvedClassName = mergeClasses(style$
|
|
28
|
+
const resolvedClassName = mergeClasses(style$b["footer-item"], className);
|
|
30
29
|
return link ? (jsx("a", { className: resolvedClassName, href: link, target: "_blank", children: children })) : (jsx("div", { className: resolvedClassName, children: children }));
|
|
31
30
|
};
|
|
32
31
|
|
|
33
|
-
var style$
|
|
32
|
+
var style$a = {"version-item":"footer-version-item-module_version-item__pjuvV","button":"footer-version-item-module_button__70iqf"};
|
|
34
33
|
|
|
35
34
|
const FooterVersionItem = memo(({ versionSelector }) => {
|
|
36
35
|
var _a;
|
|
37
36
|
const { host } = usePlaygroundContext();
|
|
38
37
|
const latest = versionSelector === null || versionSelector === void 0 ? void 0 : versionSelector.latest;
|
|
39
38
|
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$
|
|
39
|
+
return (jsx(FooterItem, { className: style$a["version-item"], children: jsxs(Popover, { children: [jsx(PopoverTrigger, { disableButtonEnhancement: true, children: jsxs("div", { className: style$a["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
40
|
});
|
|
42
41
|
const VersionsPopup = memo(({ versionSelector }) => {
|
|
43
42
|
const { host } = usePlaygroundContext();
|
|
@@ -55,11 +54,7 @@ const VersionSelector = memo(({ versions, selected, latest, onChange }) => {
|
|
|
55
54
|
});
|
|
56
55
|
|
|
57
56
|
const Footer = ({ className, children }) => {
|
|
58
|
-
return jsx("div", { className: mergeClasses(style$
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
const DefaultFooter = () => {
|
|
62
|
-
return (jsx(Footer, { children: jsx(FooterVersionItem, {}) }));
|
|
57
|
+
return jsx("div", { className: mergeClasses(style$b.footer, className), children: children });
|
|
63
58
|
};
|
|
64
59
|
|
|
65
60
|
const EmitterDropdown = ({ emitters, onSelectedEmitterChange, selectedEmitter, }) => {
|
|
@@ -84,6 +79,8 @@ const SamplesDropdown = ({ samples, selectedSampleName, onSelectedSampleNameChan
|
|
|
84
79
|
return (jsxs(Select, { className: "sample-dropdown", onChange: handleSelected, value: selectedSampleName !== null && selectedSampleName !== void 0 ? selectedSampleName : "", children: [jsx("option", { value: "", disabled: true, children: "Select sample..." }), options] }));
|
|
85
80
|
};
|
|
86
81
|
|
|
82
|
+
var style$9 = {"form":"emitter-options-form-module_form__dm2RP","item":"emitter-options-form-module_item__WocHP","switch":"emitter-options-form-module_switch__d4EQs"};
|
|
83
|
+
|
|
87
84
|
const EmitterOptionsForm = ({ library, options, optionsChanged, }) => {
|
|
88
85
|
var _a, _b, _c;
|
|
89
86
|
const emitterOptionsSchema = (_c = (_b = (_a = library.definition) === null || _a === void 0 ? void 0 : _a.emitter) === null || _b === void 0 ? void 0 : _b.options) === null || _c === void 0 ? void 0 : _c.properties;
|
|
@@ -100,9 +97,9 @@ const EmitterOptionsForm = ({ library, options, optionsChanged, }) => {
|
|
|
100
97
|
},
|
|
101
98
|
});
|
|
102
99
|
}, [options, optionsChanged]);
|
|
103
|
-
return (jsx("div", { children: entries.map(([key, value]) => {
|
|
100
|
+
return (jsx("div", { className: style$9["form"], children: entries.map(([key, value]) => {
|
|
104
101
|
var _a;
|
|
105
|
-
return (jsx("div", {
|
|
102
|
+
return (jsx("div", { className: style$9["form-item"], children: jsx(JsonSchemaPropertyInput, { emitterOptions: (_a = options[library.name]) !== null && _a !== void 0 ? _a : {}, name: key, prop: value, onChange: handleChange }) }, key));
|
|
106
103
|
}) }));
|
|
107
104
|
};
|
|
108
105
|
const JsonSchemaPropertyInput = ({ emitterOptions, name, prop, onChange, }) => {
|
|
@@ -113,10 +110,10 @@ const JsonSchemaPropertyInput = ({ emitterOptions, name, prop, onChange, }) => {
|
|
|
113
110
|
const handleChange = useCallback((_, data) => onChange({ name, value: "value" in data ? data.value : data.checked }), [onChange]);
|
|
114
111
|
switch (prop.type) {
|
|
115
112
|
case "boolean":
|
|
116
|
-
return jsx(Switch, { label: prettyName, checked: value, onChange: handleChange });
|
|
113
|
+
return (jsx(Switch, { className: style$9["switch"], label: prettyName, labelPosition: "above", checked: value, onChange: handleChange }));
|
|
117
114
|
case "string":
|
|
118
115
|
default:
|
|
119
|
-
return (jsxs("div", {
|
|
116
|
+
return (jsxs("div", { className: style$9["item"], children: [jsx(Label, { htmlFor: inputId, title: name, children: prettyName }), prop.enum ? (jsx(RadioGroup, { layout: "horizontal", id: inputId, value: value, onChange: handleChange, children: prop.enum.map((x) => (jsx(Radio, { value: x, label: x }, x))) })) : (jsx(Input, { id: inputId, value: value, onChange: handleChange }))] }));
|
|
120
117
|
}
|
|
121
118
|
};
|
|
122
119
|
|
|
@@ -166,19 +163,30 @@ const CompilerSettings = ({ selectedEmitter, host, options, onOptionsChanged, })
|
|
|
166
163
|
linterRuleSet,
|
|
167
164
|
});
|
|
168
165
|
}, [options]);
|
|
169
|
-
return (jsxs("div", {
|
|
166
|
+
return (jsxs("div", { children: [jsxs(Fragment, { children: ["Emitter: ", selectedEmitter] }), jsx(Divider, { style: { marginTop: 20 } }), jsx("h3", { children: "Options" }), library && (jsx(EmitterOptionsForm, { library: library, options: (_b = options.options) !== null && _b !== void 0 ? _b : {}, optionsChanged: emitterOptionsChanged })), jsx(Divider, { style: { marginTop: 20 } }), jsx("h3", { children: "Linter" }), jsx(LinterForm, { libraries: host.libraries, linterRuleSet: linterRuleSet, onLinterRuleSetChanged: linterRuleSetChanged })] }));
|
|
167
|
+
};
|
|
168
|
+
|
|
169
|
+
const CompilerSettingsDialogButton = ({ selectedEmitter, compilerOptions, onCompilerOptionsChange, }) => {
|
|
170
|
+
const { host } = usePlaygroundContext();
|
|
171
|
+
return (jsxs(Dialog, { children: [jsx(DialogTrigger, { children: jsx(ToolbarButton, { icon: jsx(Settings24Regular, {}) }) }), jsx(DialogSurface, { children: jsxs(DialogBody, { children: [jsx(DialogTitle, { children: "Settings" }), jsx(DialogContent, { children: jsx(CompilerSettings, { host: host, selectedEmitter: selectedEmitter, options: compilerOptions, onOptionsChanged: onCompilerOptionsChange }) })] }) })] }));
|
|
170
172
|
};
|
|
171
173
|
|
|
172
|
-
|
|
174
|
+
var style$8 = {"bar":"editor-command-bar-module_bar__5q4D5","divider":"editor-command-bar-module_divider__iDahk","spacer":"editor-command-bar-module_spacer__hlHE9"};
|
|
175
|
+
|
|
176
|
+
const EditorCommandBar = ({ documentationUrl, saveCode, formatCode, newIssue, host, selectedEmitter, onSelectedEmitterChange, compilerOptions, onCompilerOptionsChange, samples, selectedSampleName, onSelectedSampleNameChange, }) => {
|
|
173
177
|
const documentation = documentationUrl ? (jsx("label", { children: jsx(Link, { href: documentationUrl, target: "_blank", children: "Docs" }) })) : undefined;
|
|
174
178
|
const bugButton = newIssue ? jsx(FileBugButton, { onClick: newIssue }) : undefined;
|
|
175
179
|
const emitters = useMemo(() => Object.values(host.libraries)
|
|
176
180
|
.filter((x) => x.isEmitter)
|
|
177
181
|
.map((x) => x.name), [host.libraries]);
|
|
178
|
-
return (jsx("div", {
|
|
182
|
+
return (jsx("div", { className: style$8["bar"], children: jsxs(Toolbar, { children: [jsx(Tooltip, { content: "Save", relationship: "description", withArrow: true, children: jsx(ToolbarButton, { "aria-label": "Save", icon: jsx(Save16Regular, {}), onClick: saveCode }) }), jsx(Tooltip, { content: "Format", relationship: "description", withArrow: true, children: jsx(ToolbarButton, { "aria-label": "Format", icon: jsx(Broom16Filled, {}), onClick: formatCode }) }), samples && (jsxs(Fragment, { children: [jsx(SamplesDropdown, { samples: samples, selectedSampleName: selectedSampleName, onSelectedSampleNameChange: onSelectedSampleNameChange }), jsx("div", { className: style$8["spacer"] })] })), jsx(EmitterDropdown, { emitters: emitters, onSelectedEmitterChange: onSelectedEmitterChange, selectedEmitter: selectedEmitter }), documentation && (jsxs(Fragment, { children: [jsx("div", { className: style$8["spacer"] }), documentation] })), jsx("div", { className: style$8["divider"] }), bugButton, jsx(CompilerSettingsDialogButton, { compilerOptions: compilerOptions, onCompilerOptionsChange: onCompilerOptionsChange, selectedEmitter: selectedEmitter })] }) }));
|
|
179
183
|
};
|
|
180
184
|
const FileBugButton = ({ onClick }) => {
|
|
181
|
-
return (jsx(Tooltip, { content: "File Bug Report", relationship: "description", withArrow: true, children: jsx(ToolbarButton, { appearance: "subtle", "aria-label": "File Bug Report", icon: jsx(Bug16Regular, {}), onClick: onClick
|
|
185
|
+
return (jsx(Tooltip, { content: "File Bug Report", relationship: "description", withArrow: true, children: jsx(ToolbarButton, { appearance: "subtle", "aria-label": "File Bug Report", icon: jsx(Bug16Regular, {}), onClick: onClick }) }));
|
|
186
|
+
};
|
|
187
|
+
|
|
188
|
+
const DefaultFooter = () => {
|
|
189
|
+
return (jsx(Footer, { children: jsx(FooterVersionItem, {}) }));
|
|
182
190
|
};
|
|
183
191
|
|
|
184
192
|
const Editor = ({ model, options, actions, onMount }) => {
|
|
@@ -210,7 +218,7 @@ const Editor = ({ model, options, actions, onMount }) => {
|
|
|
210
218
|
editorRef.current.setModel(model);
|
|
211
219
|
}
|
|
212
220
|
}, [model]);
|
|
213
|
-
return (jsx("div", { className: "monaco-editor-container",
|
|
221
|
+
return (jsx("div", { className: "monaco-editor-container", style: { width: "100%", height: "100%", overflow: "hidden" }, ref: editorContainerRef }));
|
|
214
222
|
};
|
|
215
223
|
function useMonacoModel(uri, language) {
|
|
216
224
|
return useMemo(() => {
|
|
@@ -269,36 +277,7 @@ function useAsyncMemo(callback, defaultValue, deps) {
|
|
|
269
277
|
return value;
|
|
270
278
|
}
|
|
271
279
|
|
|
272
|
-
|
|
273
|
-
if (diagnostics.length === 0) {
|
|
274
|
-
return jsx("div", { className: "center", children: "No errors" });
|
|
275
|
-
}
|
|
276
|
-
return (jsx("div", { css: { height: "100%", overflow: "auto" }, children: diagnostics.map((x, i) => {
|
|
277
|
-
return jsx(DiagnosticItem, { diagnostic: x }, i);
|
|
278
|
-
}) }));
|
|
279
|
-
};
|
|
280
|
-
const DiagnosticItem = ({ diagnostic }) => {
|
|
281
|
-
return (jsxs("div", { css: { display: "flex" }, children: [jsx("div", { css: [{ padding: "0 5px" }, diagnostic.severity === "error" ? errorColor : warningColor], children: diagnostic.severity }), jsx("div", { css: { padding: "0 5px", color: tokens.colorNeutralForeground2 }, children: diagnostic.code }), jsx("div", { css: { padding: "0 5px" }, children: diagnostic.message })] }));
|
|
282
|
-
};
|
|
283
|
-
const errorColor = css({ color: tokens.colorStatusDangerForeground1 });
|
|
284
|
-
const warningColor = css({ color: tokens.colorStatusWarningForeground1 });
|
|
285
|
-
|
|
286
|
-
const ErrorTab = ({ internalCompilerError, diagnostics, }) => {
|
|
287
|
-
return (jsxs(Fragment, { children: [internalCompilerError && jsx(InternalCompilerError, { error: internalCompilerError }), diagnostics && jsx(DiagnosticList, { diagnostics: diagnostics })] }));
|
|
288
|
-
};
|
|
289
|
-
const InternalCompilerError = ({ error }) => {
|
|
290
|
-
return (jsx("div", { css: { CenterStyles }, children: jsxs("div", { css: {
|
|
291
|
-
border: `1px solid ${tokens.colorStatusDangerBorder1}`,
|
|
292
|
-
padding: "10px",
|
|
293
|
-
margin: "20px",
|
|
294
|
-
}, children: [jsx("h3", { children: "Internal Compiler error" }), jsx("div", { children: "File issue at https://github.com/microsoft/typespec" }), jsx("hr", {}), jsx("div", { children: error.stack })] }) }));
|
|
295
|
-
};
|
|
296
|
-
const CenterStyles = css({
|
|
297
|
-
display: "flex",
|
|
298
|
-
height: "100%",
|
|
299
|
-
alignItems: "center",
|
|
300
|
-
justifyContent: "center",
|
|
301
|
-
});
|
|
280
|
+
var style$7 = {"file-output":"file-output-module_file-output__YBaE7","viewer-selector":"file-output-module_viewer-selector__fNWoo"};
|
|
302
281
|
|
|
303
282
|
/**
|
|
304
283
|
* Display a file output using different viewers.
|
|
@@ -318,36 +297,24 @@ const FileOutput = ({ filename, content, viewers }) => {
|
|
|
318
297
|
var _a;
|
|
319
298
|
return (_a = viewers.find((x) => x.key === selected)) === null || _a === void 0 ? void 0 : _a.render;
|
|
320
299
|
}, [selected, viewers]);
|
|
321
|
-
return (jsxs("div", {
|
|
300
|
+
return (jsxs("div", { className: style$7["file-output"], children: [jsx("div", { className: style$7["viewer-selector"], children: jsx(Select, { value: selected, onChange: handleSelected, children: viewers.map(({ key, label }) => (jsx("option", { value: key, children: label }, key))) }) }), selectedRender && selectedRender({ filename, content })] }));
|
|
322
301
|
};
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
position: "absolute",
|
|
326
|
-
"z-index": 1,
|
|
327
|
-
right: 0,
|
|
328
|
-
});
|
|
302
|
+
|
|
303
|
+
var style$6 = {"tabs":"output-tabs-module_tabs__MFCRl","tab-divider":"output-tabs-module_tab-divider__9Fv--","tab":"output-tabs-module_tab__FJ78k","tab--selected":"output-tabs-module_tab--selected__GjCZY"};
|
|
329
304
|
|
|
330
305
|
const OutputTabs = ({ tabs, selected, onSelect }) => {
|
|
331
306
|
const [leftTabs, rightTabs] = chunk(tabs, (x) => x.align === "left");
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
307
|
+
const onTabSelect = useCallback((event, data) => {
|
|
308
|
+
onSelect(data.value);
|
|
309
|
+
}, [onSelect]);
|
|
310
|
+
return (jsxs(TabList, { selectedValue: selected, onTabSelect: onTabSelect, className: style$6["tabs"], children: [leftTabs.map((tab) => {
|
|
311
|
+
return (jsx(OutputTabEl, { value: tab.id, className: tab.id === selected && style$6["tab--selected"], children: tab.name }, tab.id));
|
|
312
|
+
}), jsx("div", { className: style$6["tab-divider"] }), rightTabs.map((tab) => {
|
|
313
|
+
return (jsx(OutputTabEl, { value: tab.id, className: tab.id === selected && style$6["tab--selected"], children: tab.name }, tab.id));
|
|
336
314
|
})] }));
|
|
337
315
|
};
|
|
338
|
-
const
|
|
339
|
-
return
|
|
340
|
-
{
|
|
341
|
-
height: "26px",
|
|
342
|
-
padding: "0 5px",
|
|
343
|
-
borderRight: `1px solid ${tokens.colorNeutralStroke1}`,
|
|
344
|
-
borderTop: "none",
|
|
345
|
-
borderBottom: "none",
|
|
346
|
-
textDecoration: "none",
|
|
347
|
-
cursor: "pointer",
|
|
348
|
-
},
|
|
349
|
-
selected ? { fontWeight: "bold", backgroundColor: tokens.colorNeutralBackground5 } : {},
|
|
350
|
-
], onClick: () => onSelect(tab.id), children: tab.name }));
|
|
316
|
+
const OutputTabEl = (props) => {
|
|
317
|
+
return jsx(Tab, { ...props, className: mergeClasses(style$6["tab"], props.className) });
|
|
351
318
|
};
|
|
352
319
|
function chunk(items, condition) {
|
|
353
320
|
const match = [];
|
|
@@ -392,12 +359,14 @@ const OutputEditor = ({ filename, value, editorOptions }) => {
|
|
|
392
359
|
return jsx(Editor, { model: model, options: options });
|
|
393
360
|
};
|
|
394
361
|
|
|
362
|
+
var style$5 = {"output-view":"output-view-module_output-view__uT5Ae","output-content":"output-view-module_output-content__Lis-G","type-graph-viewer":"output-view-module_type-graph-viewer__tUDEV"};
|
|
363
|
+
|
|
395
364
|
const OutputView = ({ compilationState, viewers, editorOptions, }) => {
|
|
396
365
|
if (compilationState === undefined) {
|
|
397
366
|
return jsx(Fragment, {});
|
|
398
367
|
}
|
|
399
368
|
if ("internalCompilerError" in compilationState) {
|
|
400
|
-
return jsx(
|
|
369
|
+
return jsx(Fragment, {});
|
|
401
370
|
}
|
|
402
371
|
return (jsx(OutputViewInternal, { compilationResult: compilationState, viewers: viewers, editorOptions: editorOptions }));
|
|
403
372
|
};
|
|
@@ -432,25 +401,17 @@ const OutputViewInternal = ({ compilationResult, viewers, editorOptions }) => {
|
|
|
432
401
|
id: x,
|
|
433
402
|
})),
|
|
434
403
|
{ id: "type-graph", name: "Type Graph", align: "right" },
|
|
435
|
-
{
|
|
436
|
-
id: "errors",
|
|
437
|
-
name: jsx(ErrorTabLabel, { diagnostics: diagnostics }),
|
|
438
|
-
align: "right",
|
|
439
|
-
},
|
|
440
404
|
];
|
|
441
405
|
}, [outputFiles, diagnostics]);
|
|
442
406
|
const handleTabSelection = useCallback((tabId) => {
|
|
443
407
|
if (tabId === "type-graph") {
|
|
444
408
|
setViewSelection({ type: "type-graph" });
|
|
445
409
|
}
|
|
446
|
-
else if (tabId === "errors") {
|
|
447
|
-
setViewSelection({ type: "errors" });
|
|
448
|
-
}
|
|
449
410
|
else {
|
|
450
411
|
void loadOutputFile(tabId);
|
|
451
412
|
}
|
|
452
413
|
}, []);
|
|
453
|
-
return (jsxs(
|
|
414
|
+
return (jsxs("div", { className: style$5["output-view"], children: [jsx(OutputTabs, { tabs: tabs, selected: viewSelection.type === "file" ? viewSelection.filename : viewSelection.type, onSelect: handleTabSelection }), jsx("div", { className: style$5["output-content"], children: jsx(OutputContent, { viewSelection: viewSelection, editorOptions: editorOptions, program: program, viewers: viewers }) })] }));
|
|
454
415
|
};
|
|
455
416
|
function getRawFileViewer(editorOptions) {
|
|
456
417
|
return {
|
|
@@ -464,27 +425,12 @@ const OutputContent = ({ viewSelection, program, viewers, editorOptions, }) => {
|
|
|
464
425
|
switch (viewSelection.type) {
|
|
465
426
|
case "file":
|
|
466
427
|
return (jsx(FileOutput, { filename: viewSelection.filename, content: viewSelection.content, viewers: resolvedViewers }));
|
|
467
|
-
case "errors":
|
|
468
|
-
return jsx(ErrorTab, { diagnostics: program === null || program === void 0 ? void 0 : program.diagnostics });
|
|
469
428
|
default:
|
|
470
|
-
return
|
|
471
|
-
height: "100%",
|
|
472
|
-
overflow: "scroll",
|
|
473
|
-
}, children: program && jsx(TypeGraphViewer, { program: program }) }));
|
|
429
|
+
return program && jsx(TypeGraphViewer, { program: program });
|
|
474
430
|
}
|
|
475
431
|
};
|
|
476
|
-
const ErrorTabLabel = ({ diagnostics }) => {
|
|
477
|
-
const errorCount = diagnostics ? diagnostics.length : 0;
|
|
478
|
-
return (jsxs("div", { children: ["Errors ", errorCount > 0 ? jsx("span", { css: ErrorTabCountStyles, children: errorCount }) : ""] }));
|
|
479
|
-
};
|
|
480
|
-
const ErrorTabCountStyles = css({
|
|
481
|
-
backgroundColor: tokens.colorStatusDangerBackground3,
|
|
482
|
-
color: tokens.colorNeutralForegroundOnBrand,
|
|
483
|
-
padding: "0 5px",
|
|
484
|
-
borderRadius: "20px",
|
|
485
|
-
});
|
|
486
432
|
const TypeGraphViewer = ({ program }) => {
|
|
487
|
-
return (jsx(ColorProvider, { colors: TypeGraphColors, children: jsx(TypeSpecProgramViewer, { program: program }) }));
|
|
433
|
+
return (jsx("div", { className: style$5["type-graph-viewer"], children: jsx(ColorProvider, { colors: TypeGraphColors, children: jsx(TypeSpecProgramViewer, { program: program }) }) }));
|
|
488
434
|
};
|
|
489
435
|
const TypeGraphColors = {
|
|
490
436
|
background: tokens.colorNeutralBackground1,
|
|
@@ -497,6 +443,76 @@ const TypeGraphColors = {
|
|
|
497
443
|
property: tokens.colorPaletteMarigoldForeground2,
|
|
498
444
|
};
|
|
499
445
|
|
|
446
|
+
var style$4 = {"layout":"playground-module_layout__SCPgt"};
|
|
447
|
+
|
|
448
|
+
var style$3 = {"list":"diagnostic-list-module_list__6tVpz","item":"diagnostic-list-module_item__BE8Fr","item--error":"diagnostic-list-module_item--error__tnhWA","item--warning":"diagnostic-list-module_item--warning__J7vIN","item-code":"diagnostic-list-module_item-code__AgVjZ","item-loc":"diagnostic-list-module_item-loc__IeYnW"};
|
|
449
|
+
|
|
450
|
+
const DiagnosticList = ({ diagnostics, onDiagnosticSelected, }) => {
|
|
451
|
+
if (diagnostics.length === 0) {
|
|
452
|
+
return jsx("div", { className: style$3["list"], children: "No errors" });
|
|
453
|
+
}
|
|
454
|
+
const handleItemSelected = useCallback((diagnostic) => {
|
|
455
|
+
onDiagnosticSelected === null || onDiagnosticSelected === void 0 ? void 0 : onDiagnosticSelected(diagnostic);
|
|
456
|
+
}, [onDiagnosticSelected]);
|
|
457
|
+
return (jsx("div", { className: style$3["list"], children: diagnostics.map((x, i) => {
|
|
458
|
+
return jsx(DiagnosticItem, { diagnostic: x, onItemSelected: handleItemSelected }, i);
|
|
459
|
+
}) }));
|
|
460
|
+
};
|
|
461
|
+
const DiagnosticItem = ({ diagnostic, onItemSelected }) => {
|
|
462
|
+
const handleClick = useCallback(() => {
|
|
463
|
+
onItemSelected(diagnostic);
|
|
464
|
+
}, [diagnostic, onItemSelected]);
|
|
465
|
+
return (jsxs("div", { tabIndex: 0, className: style$3["item"], onClick: handleClick, children: [jsx("div", { className: mergeClasses((style$3["item-severity"],
|
|
466
|
+
style$3[diagnostic.severity === "error" ? "item--error" : "item--warning"])), children: diagnostic.severity }), jsx("div", { className: style$3["item-code"], children: diagnostic.code }), jsx("div", { className: style$3["item-message"], children: diagnostic.message }), jsx("div", { className: style$3["item-loc"], children: jsx(DiagnosticTargetLink, { target: diagnostic.target }) })] }));
|
|
467
|
+
};
|
|
468
|
+
const DiagnosticTargetLink = memo(({ target }) => {
|
|
469
|
+
if (typeof target === "symbol") {
|
|
470
|
+
return jsx("span", {});
|
|
471
|
+
}
|
|
472
|
+
const location = getSourceLocation(target);
|
|
473
|
+
const file = location.file.path === "/test/main.tsp" ? "" : `${location.file.path}:`;
|
|
474
|
+
const { line, character } = location.file.getLineAndCharacterOfPosition(location.pos);
|
|
475
|
+
return (jsxs("span", { children: [file, line + 1, ":", character + 1] }));
|
|
476
|
+
});
|
|
477
|
+
|
|
478
|
+
var style$2 = {"header":"header-module_header__LyUNg","header--error":"header-module_header--error__8MKzf","error-icon":"header-module_error-icon__gb-oB","header--warning":"header-module_header--warning__QPFEE","warning-icon":"header-module_warning-icon__u14P3","header-content":"header-module_header-content__Uc4HJ","header-chevron":"header-module_header-chevron__HXm6b","header-chevron--collapsed":"header-module_header-chevron--collapsed__wKyHV"};
|
|
479
|
+
|
|
480
|
+
const ProblemPaneHeader = memo(({ compilationState, ...props }) => {
|
|
481
|
+
const noProblem = (jsx(Container, { status: "none", ...props, children: "No problems" }));
|
|
482
|
+
if (compilationState === undefined) {
|
|
483
|
+
return noProblem;
|
|
484
|
+
}
|
|
485
|
+
if ("internalCompilerError" in compilationState) {
|
|
486
|
+
return (jsxs(Container, { status: "error", ...props, children: [jsx(ErrorCircle16Filled, {}), " Internal Compiler Error"] }));
|
|
487
|
+
}
|
|
488
|
+
const diagnostics = compilationState.program.diagnostics;
|
|
489
|
+
if (diagnostics.length === 0) {
|
|
490
|
+
return noProblem;
|
|
491
|
+
}
|
|
492
|
+
const errors = diagnostics.filter((x) => x.severity === "error");
|
|
493
|
+
const warnings = diagnostics.filter((x) => x.severity === "warning");
|
|
494
|
+
return (jsxs(Container, { status: errors.length > 0 ? "error" : "warning", ...props, children: [errors.length > 0 ? (jsxs(Fragment, { children: [jsx(ErrorCircle16Filled, { className: style$2["error-icon"] }), " ", errors.length, " errors"] })) : null, warnings.length > 0 ? (jsxs(Fragment, { children: [jsx(Warning16Filled, { className: style$2["warning-icon"] }), " ", warnings.length, " warnings"] })) : null] }));
|
|
495
|
+
});
|
|
496
|
+
const Container = ({ children, className, status, onClick, collaped }) => {
|
|
497
|
+
return (jsxs("div", { tabIndex: onClick === undefined ? undefined : 0, className: mergeClasses(style$2["header"], status === "error" && style$2["header--error"], status === "warning" && style$2["header--warning"], className), onClick: onClick, children: [jsx("div", { className: style$2["header-content"], children: children }), jsx(ChevronDown16Regular, { className: mergeClasses(style$2["header-chevron"], collaped && style$2["header-chevron--collapsed"]) })] }));
|
|
498
|
+
};
|
|
499
|
+
|
|
500
|
+
var style$1 = {"problem-pane":"problem-pane-module_problem-pane__GJKF4","problem-content":"problem-pane-module_problem-content__rYzbh","no-problems":"problem-pane-module_no-problems__Ub8R-","internal-compiler-error":"problem-pane-module_internal-compiler-error__laE4f"};
|
|
501
|
+
|
|
502
|
+
const ProblemPane = ({ collapsed, compilationState, onHeaderClick, onDiagnosticSelected, }) => {
|
|
503
|
+
return (jsxs("div", { className: style$1["problem-pane"], children: [jsx(ProblemPaneHeader, { compilationState: compilationState, onClick: onHeaderClick, collaped: collapsed }), jsx("div", { className: style$1["problem-content"], children: jsx(ProblemPaneContent, { compilationState: compilationState, onDiagnosticSelected: onDiagnosticSelected }) })] }));
|
|
504
|
+
};
|
|
505
|
+
const ProblemPaneContent = ({ compilationState, onDiagnosticSelected, }) => {
|
|
506
|
+
if (compilationState === undefined) {
|
|
507
|
+
return jsx(Fragment, {});
|
|
508
|
+
}
|
|
509
|
+
if ("internalCompilerError" in compilationState) {
|
|
510
|
+
return (jsx("pre", { className: style$1["internal-compiler-error"], children: compilationState.internalCompilerError.stack }));
|
|
511
|
+
}
|
|
512
|
+
const diagnostics = compilationState.program.diagnostics;
|
|
513
|
+
return diagnostics.length === 0 ? (jsx("div", { className: style$1["no-problems"], children: " No problems" })) : (jsx(DiagnosticList, { diagnostics: diagnostics, onDiagnosticSelected: onDiagnosticSelected }));
|
|
514
|
+
};
|
|
515
|
+
|
|
500
516
|
function Pane({ children, ...props }) {
|
|
501
517
|
return jsx("div", { ...props, children: children });
|
|
502
518
|
}
|
|
@@ -593,7 +609,9 @@ const SplitPane = ({ children, sizes: propSizes, initialSizes: defaultSizes, all
|
|
|
593
609
|
onDragStart(e);
|
|
594
610
|
}, [onDragStart, sizes, sashPosSizes]);
|
|
595
611
|
const resetPosition = useCallback(() => {
|
|
596
|
-
|
|
612
|
+
if (defaultSizes) {
|
|
613
|
+
updateSizes(defaultSizes);
|
|
614
|
+
}
|
|
597
615
|
}, [defaultSizes, updateSizes]);
|
|
598
616
|
const dragEnd = useCallback((e) => {
|
|
599
617
|
var _a, _b;
|
|
@@ -678,7 +696,7 @@ const Playground = (props) => {
|
|
|
678
696
|
setCompilationState(state);
|
|
679
697
|
if ("program" in state) {
|
|
680
698
|
const markers = state.program.diagnostics.map((diag) => ({
|
|
681
|
-
...
|
|
699
|
+
...getMonacoRange(typespecCompiler, diag.target),
|
|
682
700
|
message: diag.message,
|
|
683
701
|
severity: diag.severity === "error" ? MarkerSeverity.Error : MarkerSeverity.Warning,
|
|
684
702
|
tags: diag.code === "deprecated" ? [CompletionItemTag.Deprecated] : undefined,
|
|
@@ -758,14 +776,26 @@ const Playground = (props) => {
|
|
|
758
776
|
const onTypeSpecEditorMount = useCallback(({ editor }) => {
|
|
759
777
|
editorRef.current = editor;
|
|
760
778
|
}, []);
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
779
|
+
const [verticalPaneSizes, setVerticalPaneSizes] = useState(verticalPaneSizesConst.collapsed);
|
|
780
|
+
const toggleProblemPane = useCallback(() => {
|
|
781
|
+
setVerticalPaneSizes((value) => {
|
|
782
|
+
return value === verticalPaneSizesConst.collapsed
|
|
783
|
+
? verticalPaneSizesConst.expanded
|
|
784
|
+
: verticalPaneSizesConst.collapsed;
|
|
785
|
+
});
|
|
786
|
+
}, [setVerticalPaneSizes]);
|
|
787
|
+
const onVerticalPaneSizeChange = useCallback((sizes) => {
|
|
788
|
+
setVerticalPaneSizes(sizes);
|
|
789
|
+
}, [setVerticalPaneSizes]);
|
|
790
|
+
const handleDiagnosticSelected = useCallback((diagnostic) => {
|
|
791
|
+
var _a;
|
|
792
|
+
(_a = editorRef.current) === null || _a === void 0 ? void 0 : _a.setSelection(getMonacoRange(host.compiler, diagnostic.target));
|
|
793
|
+
}, [setVerticalPaneSizes]);
|
|
794
|
+
return (jsx(PlaygroundContextProvider, { value: { host }, children: jsxs("div", { className: style$4["layout"], children: [jsxs(SplitPane, { sizes: verticalPaneSizes, onChange: onVerticalPaneSizeChange, split: "horizontal", children: [jsx(Pane, { children: jsxs(SplitPane, { initialSizes: ["50%", "50%"], 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(Pane, { minSize: 30, children: jsx(ProblemPane, { collapsed: verticalPaneSizes[1] === verticalPaneSizesConst.collapsed[1], compilationState: compilationState, onHeaderClick: toggleProblemPane, onDiagnosticSelected: handleDiagnosticSelected }) })] }), (_e = props.footer) !== null && _e !== void 0 ? _e : jsx(DefaultFooter, {})] }) }));
|
|
795
|
+
};
|
|
796
|
+
const verticalPaneSizesConst = {
|
|
797
|
+
collapsed: [undefined, 30],
|
|
798
|
+
expanded: [undefined, 200],
|
|
769
799
|
};
|
|
770
800
|
const outputDir = "./tsp-output";
|
|
771
801
|
async function compile(host, content, selectedEmitter, options) {
|