@typespec/playground 0.3.0-dev.5 → 0.3.0-dev.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.
- package/dist/index.js +1 -1
- package/dist/react/index.js +41 -65
- package/dist/react/index.js.map +1 -1
- package/dist/{state-storage-BtJ3x1w_.js → state-storage-CShFsmVH.js} +14 -23
- package/dist/state-storage-CShFsmVH.js.map +1 -0
- package/dist/vite/index.js +2 -2
- package/dist/vite/index.js.map +1 -1
- package/package.json +1 -1
- package/dist/state-storage-BtJ3x1w_.js.map +0 -1
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-CShFsmVH.js';
|
|
2
2
|
import '@typespec/compiler';
|
|
3
3
|
import 'monaco-editor';
|
|
4
4
|
import 'vscode-languageserver';
|
package/dist/react/index.js
CHANGED
|
@@ -5,7 +5,7 @@ import debounce from 'debounce';
|
|
|
5
5
|
import { editor, Uri, MarkerSeverity, KeyMod, KeyCode } from 'monaco-editor';
|
|
6
6
|
import { CompletionItemTag } from 'vscode-languageserver';
|
|
7
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-
|
|
8
|
+
import { g as getMonacoRange, c as createBrowserHost, r as registerMonacoLanguage, a as createUrlStateStorage } from '../state-storage-CShFsmVH.js';
|
|
9
9
|
import { ColorProvider, TypeSpecProgramViewer } from '@typespec/html-program-viewer';
|
|
10
10
|
import { getSourceLocation } from '@typespec/compiler';
|
|
11
11
|
import { createRoot } from 'react-dom/client';
|
|
@@ -32,10 +32,9 @@ const FooterItem = ({ children, link, className }) => {
|
|
|
32
32
|
var style$a = {"version-item":"footer-version-item-module_version-item__pjuvV","button":"footer-version-item-module_button__70iqf"};
|
|
33
33
|
|
|
34
34
|
const FooterVersionItem = memo(({ versionSelector }) => {
|
|
35
|
-
var _a;
|
|
36
35
|
const { host } = usePlaygroundContext();
|
|
37
|
-
const latest = versionSelector
|
|
38
|
-
const selected =
|
|
36
|
+
const latest = versionSelector?.latest;
|
|
37
|
+
const selected = versionSelector?.selected ?? host.compiler.MANIFEST.version;
|
|
39
38
|
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 }) })] }) }));
|
|
40
39
|
});
|
|
41
40
|
const VersionsPopup = memo(({ versionSelector }) => {
|
|
@@ -76,14 +75,13 @@ const SamplesDropdown = ({ samples, selectedSampleName, onSelectedSampleNameChan
|
|
|
76
75
|
onSelectedSampleNameChange(evt.target.value);
|
|
77
76
|
}
|
|
78
77
|
}, [onSelectedSampleNameChange]);
|
|
79
|
-
return (jsxs(Select, { className: "sample-dropdown", onChange: handleSelected, value: selectedSampleName
|
|
78
|
+
return (jsxs(Select, { className: "sample-dropdown", onChange: handleSelected, value: selectedSampleName ?? "", "aria-label": "Select a sample", children: [jsx("option", { value: "", disabled: true, children: "Select sample..." }), options] }));
|
|
80
79
|
};
|
|
81
80
|
|
|
82
81
|
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
82
|
|
|
84
83
|
const EmitterOptionsForm = ({ library, options, optionsChanged, }) => {
|
|
85
|
-
|
|
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;
|
|
84
|
+
const emitterOptionsSchema = library.definition?.emitter?.options?.properties;
|
|
87
85
|
if (emitterOptionsSchema === undefined) {
|
|
88
86
|
return jsx(Fragment, { children: "\"No options\"" });
|
|
89
87
|
}
|
|
@@ -98,15 +96,13 @@ const EmitterOptionsForm = ({ library, options, optionsChanged, }) => {
|
|
|
98
96
|
});
|
|
99
97
|
}, [options, optionsChanged]);
|
|
100
98
|
return (jsx("div", { className: style$9["form"], children: entries.map(([key, value]) => {
|
|
101
|
-
|
|
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));
|
|
99
|
+
return (jsx("div", { className: style$9["form-item"], children: jsx(JsonSchemaPropertyInput, { emitterOptions: options[library.name] ?? {}, name: key, prop: value, onChange: handleChange }) }, key));
|
|
103
100
|
}) }));
|
|
104
101
|
};
|
|
105
102
|
const JsonSchemaPropertyInput = ({ emitterOptions, name, prop, onChange, }) => {
|
|
106
|
-
var _a;
|
|
107
103
|
const prettyName = useMemo(() => name[0].toUpperCase() + name.slice(1).replace(/-/g, " "), [name]);
|
|
108
104
|
const inputId = useId("input");
|
|
109
|
-
const value =
|
|
105
|
+
const value = emitterOptions[name] ?? prop.default;
|
|
110
106
|
const handleChange = useCallback((_, data) => onChange({ name, value: "value" in data ? data.value : data.checked }), [onChange]);
|
|
111
107
|
switch (prop.type) {
|
|
112
108
|
case "boolean":
|
|
@@ -119,17 +115,15 @@ const JsonSchemaPropertyInput = ({ emitterOptions, name, prop, onChange, }) => {
|
|
|
119
115
|
|
|
120
116
|
const LinterForm = ({ libraries, linterRuleSet, onLinterRuleSetChanged, }) => {
|
|
121
117
|
const rulesets = Object.values(libraries).flatMap((lib) => {
|
|
122
|
-
var _a, _b, _c;
|
|
123
118
|
// eslint-disable-next-line deprecation/deprecation
|
|
124
|
-
const linter =
|
|
125
|
-
return Object.keys(
|
|
119
|
+
const linter = lib.linter ?? lib.definition?.linter;
|
|
120
|
+
return Object.keys(linter?.ruleSets ?? {}).map((x) => `${lib.name}/${x}`);
|
|
126
121
|
});
|
|
127
122
|
if (rulesets.length === 0) {
|
|
128
123
|
return jsx(Fragment, { children: "No ruleset available" });
|
|
129
124
|
}
|
|
130
125
|
const handleChange = (ruleSet, checked) => {
|
|
131
|
-
|
|
132
|
-
const ruleSets = (_a = linterRuleSet.extends) !== null && _a !== void 0 ? _a : [];
|
|
126
|
+
const ruleSets = linterRuleSet.extends ?? [];
|
|
133
127
|
const updatedRuleSets = checked
|
|
134
128
|
? [...ruleSets, ruleSet]
|
|
135
129
|
: ruleSets.filter((x) => x !== ruleSet);
|
|
@@ -138,8 +132,7 @@ const LinterForm = ({ libraries, linterRuleSet, onLinterRuleSetChanged, }) => {
|
|
|
138
132
|
});
|
|
139
133
|
};
|
|
140
134
|
return (jsx(Fragment, { children: rulesets.map((ruleSet) => {
|
|
141
|
-
|
|
142
|
-
return (jsx(RuleSetCheckbox, { ruleSet: ruleSet, checked: (_a = linterRuleSet.extends) === null || _a === void 0 ? void 0 : _a.includes(ruleSet), onChange: handleChange }, ruleSet));
|
|
135
|
+
return (jsx(RuleSetCheckbox, { ruleSet: ruleSet, checked: linterRuleSet.extends?.includes(ruleSet), onChange: handleChange }, ruleSet));
|
|
143
136
|
}) }));
|
|
144
137
|
};
|
|
145
138
|
const RuleSetCheckbox = ({ ruleSet, checked, onChange }) => {
|
|
@@ -150,7 +143,6 @@ const RuleSetCheckbox = ({ ruleSet, checked, onChange }) => {
|
|
|
150
143
|
};
|
|
151
144
|
|
|
152
145
|
const CompilerSettings = ({ selectedEmitter, host, options, onOptionsChanged, }) => {
|
|
153
|
-
var _a, _b;
|
|
154
146
|
const emitterOptionsChanged = useCallback((emitterOptions) => {
|
|
155
147
|
onOptionsChanged({
|
|
156
148
|
...options,
|
|
@@ -158,14 +150,14 @@ const CompilerSettings = ({ selectedEmitter, host, options, onOptionsChanged, })
|
|
|
158
150
|
});
|
|
159
151
|
}, [options]);
|
|
160
152
|
const library = host.libraries[selectedEmitter];
|
|
161
|
-
const linterRuleSet =
|
|
153
|
+
const linterRuleSet = options.linterRuleSet ?? {};
|
|
162
154
|
const linterRuleSetChanged = useCallback((linterRuleSet) => {
|
|
163
155
|
onOptionsChanged({
|
|
164
156
|
...options,
|
|
165
157
|
linterRuleSet,
|
|
166
158
|
});
|
|
167
159
|
}, [options]);
|
|
168
|
-
return (jsxs("div", { children: [jsxs(Fragment, { children: ["Emitter: ", selectedEmitter] }), jsx(Divider, { style: { marginTop: 20 } }), jsx("h3", { children: "Options" }), library && (jsx(EmitterOptionsForm, { library: library, options:
|
|
160
|
+
return (jsxs("div", { children: [jsxs(Fragment, { children: ["Emitter: ", selectedEmitter] }), jsx(Divider, { style: { marginTop: 20 } }), jsx("h3", { children: "Options" }), library && (jsx(EmitterOptionsForm, { library: library, options: options.options ?? {}, optionsChanged: emitterOptionsChanged })), jsx(Divider, { style: { marginTop: 20 } }), jsx("h3", { children: "Linter" }), jsx(LinterForm, { libraries: host.libraries, linterRuleSet: linterRuleSet, onLinterRuleSetChanged: linterRuleSetChanged })] }));
|
|
169
161
|
};
|
|
170
162
|
|
|
171
163
|
const CompilerSettingsDialogButton = ({ selectedEmitter, compilerOptions, onCompilerOptionsChange, }) => {
|
|
@@ -200,15 +192,14 @@ const Editor = ({ model, options, actions, onMount }) => {
|
|
|
200
192
|
automaticLayout: true,
|
|
201
193
|
...options,
|
|
202
194
|
});
|
|
203
|
-
onMount
|
|
195
|
+
onMount?.({ editor: editorRef.current });
|
|
204
196
|
}, []);
|
|
205
197
|
useEffect(() => {
|
|
206
|
-
|
|
207
|
-
editor.setTheme((_a = options.theme) !== null && _a !== void 0 ? _a : "typespec");
|
|
198
|
+
editor.setTheme(options.theme ?? "typespec");
|
|
208
199
|
}, [options.theme]);
|
|
209
200
|
useEffect(() => {
|
|
210
201
|
const disposables = [];
|
|
211
|
-
for (const command of actions
|
|
202
|
+
for (const command of actions ?? []) {
|
|
212
203
|
disposables.push(editorRef.current.addAction(command));
|
|
213
204
|
}
|
|
214
205
|
return () => {
|
|
@@ -225,9 +216,8 @@ const Editor = ({ model, options, actions, onMount }) => {
|
|
|
225
216
|
};
|
|
226
217
|
function useMonacoModel(uri, language) {
|
|
227
218
|
return useMemo(() => {
|
|
228
|
-
var _a;
|
|
229
219
|
const monacoUri = Uri.parse(uri);
|
|
230
|
-
return
|
|
220
|
+
return editor.getModel(monacoUri) ?? editor.createModel("", language, monacoUri);
|
|
231
221
|
}, [uri, language]);
|
|
232
222
|
}
|
|
233
223
|
|
|
@@ -297,8 +287,7 @@ const FileOutput = ({ filename, content, viewers }) => {
|
|
|
297
287
|
setSelected(data.value);
|
|
298
288
|
}, [selected]);
|
|
299
289
|
const selectedRender = useMemo(() => {
|
|
300
|
-
|
|
301
|
-
return (_a = viewers.find((x) => x.key === selected)) === null || _a === void 0 ? void 0 : _a.render;
|
|
290
|
+
return viewers.find((x) => x.key === selected)?.render;
|
|
302
291
|
}, [selected, viewers]);
|
|
303
292
|
return (jsxs("div", { className: style$7["file-output"], children: [jsx("div", { className: style$7["viewer-selector"], children: jsx(Select, { value: selected, onChange: handleSelected, "aria-label": "Select viewer", children: viewers.map(({ key, label }) => (jsx("option", { value: key, children: label }, key))) }) }), selectedRender && selectedRender({ filename, content })] }));
|
|
304
293
|
};
|
|
@@ -384,7 +373,7 @@ const OutputViewInternal = ({ compilationResult, viewers, editorOptions }) => {
|
|
|
384
373
|
if (viewSelection.type === "file") {
|
|
385
374
|
if (outputFiles.length > 0) {
|
|
386
375
|
const fileStillThere = outputFiles.find((x) => x === viewSelection.filename);
|
|
387
|
-
void loadOutputFile(fileStillThere
|
|
376
|
+
void loadOutputFile(fileStillThere ?? outputFiles[0]);
|
|
388
377
|
}
|
|
389
378
|
else {
|
|
390
379
|
setViewSelection({ type: "file", filename: viewSelection.filename, content: "" });
|
|
@@ -424,7 +413,7 @@ function getRawFileViewer(editorOptions) {
|
|
|
424
413
|
};
|
|
425
414
|
}
|
|
426
415
|
const OutputContent = ({ viewSelection, program, viewers, editorOptions, }) => {
|
|
427
|
-
const resolvedViewers = useMemo(() => [getRawFileViewer(editorOptions), ...(viewers
|
|
416
|
+
const resolvedViewers = useMemo(() => [getRawFileViewer(editorOptions), ...(viewers ?? [])], [viewers]);
|
|
428
417
|
switch (viewSelection.type) {
|
|
429
418
|
case "file":
|
|
430
419
|
return (jsx(FileOutput, { filename: viewSelection.filename, content: viewSelection.content, viewers: resolvedViewers }));
|
|
@@ -455,7 +444,7 @@ const DiagnosticList = ({ diagnostics, onDiagnosticSelected, }) => {
|
|
|
455
444
|
return jsx("div", { className: style$3["list"], children: "No errors" });
|
|
456
445
|
}
|
|
457
446
|
const handleItemSelected = useCallback((diagnostic) => {
|
|
458
|
-
onDiagnosticSelected
|
|
447
|
+
onDiagnosticSelected?.(diagnostic);
|
|
459
448
|
}, [onDiagnosticSelected]);
|
|
460
449
|
return (jsx("div", { className: style$3["list"], children: diagnostics.map((x, i) => {
|
|
461
450
|
return jsx(DiagnosticItem, { diagnostic: x, onItemSelected: handleItemSelected }, i);
|
|
@@ -546,7 +535,6 @@ const Sash = ({ className, render, onDragStart, onDragging, onDragEnd, onReset,
|
|
|
546
535
|
};
|
|
547
536
|
|
|
548
537
|
const SplitPane = ({ children, sizes: propSizes, initialSizes: defaultSizes, allowResize = true, split = "vertical", className: wrapClassName, sashRender = (_, active) => jsx(SashContent, { dragging: active }), resizerSize = 4, performanceMode = false, onChange = () => null, onDragStart = () => null, onDragEnd = () => null, ...others }) => {
|
|
549
|
-
var _a;
|
|
550
538
|
const [resolvedPropSize, updateSizes] = useControllableValue(propSizes, defaultSizes, onChange);
|
|
551
539
|
const axis = useRef({ x: 0, y: 0 });
|
|
552
540
|
const wrapper = useRef(null);
|
|
@@ -555,8 +543,7 @@ const SplitPane = ({ children, sizes: propSizes, initialSizes: defaultSizes, all
|
|
|
555
543
|
const [isDragging, setDragging] = useState(false);
|
|
556
544
|
useEffect(() => {
|
|
557
545
|
const resizeObserver = new ResizeObserver(() => {
|
|
558
|
-
|
|
559
|
-
setWrapperRect((_b = (_a = wrapper === null || wrapper === void 0 ? void 0 : wrapper.current) === null || _a === void 0 ? void 0 : _a.getBoundingClientRect()) !== null && _b !== void 0 ? _b : {});
|
|
546
|
+
setWrapperRect(wrapper?.current?.getBoundingClientRect() ?? {});
|
|
560
547
|
});
|
|
561
548
|
resizeObserver.observe(wrapper.current);
|
|
562
549
|
return () => {
|
|
@@ -568,11 +555,11 @@ const SplitPane = ({ children, sizes: propSizes, initialSizes: defaultSizes, all
|
|
|
568
555
|
splitPos: split === "vertical" ? "left" : "top",
|
|
569
556
|
splitAxis: split === "vertical" ? "x" : "y",
|
|
570
557
|
}), [split]);
|
|
571
|
-
const wrapSize =
|
|
558
|
+
const wrapSize = wrapperRect[sizeName] ?? 0;
|
|
572
559
|
// Get limit sizes via children
|
|
573
560
|
const paneLimitSizes = useMemo(() => children.map((childNode) => {
|
|
574
561
|
const limits = [0, Infinity];
|
|
575
|
-
if (
|
|
562
|
+
if (childNode?.type === Pane) {
|
|
576
563
|
const { minSize, maxSize } = childNode.props;
|
|
577
564
|
limits[0] = assertsSize(minSize, wrapSize, 0);
|
|
578
565
|
limits[1] = assertsSize(maxSize, wrapSize);
|
|
@@ -604,8 +591,7 @@ const SplitPane = ({ children, sizes: propSizes, initialSizes: defaultSizes, all
|
|
|
604
591
|
}, [...resolvedPropSize, children.length, wrapSize]);
|
|
605
592
|
const sashPosSizes = useMemo(() => sizes.reduce((a, b) => [...a, a[a.length - 1] + b], [0]), [...sizes]);
|
|
606
593
|
const dragStart = useCallback((e) => {
|
|
607
|
-
|
|
608
|
-
(_b = (_a = document === null || document === void 0 ? void 0 : document.body) === null || _a === void 0 ? void 0 : _a.classList) === null || _b === void 0 ? void 0 : _b.add(style["split-disabled"]);
|
|
594
|
+
document?.body?.classList?.add(style["split-disabled"]);
|
|
609
595
|
axis.current = { x: e.pageX, y: e.pageY };
|
|
610
596
|
cacheSizes.current = { sizes, sashPosSizes };
|
|
611
597
|
setDragging(true);
|
|
@@ -617,8 +603,7 @@ const SplitPane = ({ children, sizes: propSizes, initialSizes: defaultSizes, all
|
|
|
617
603
|
}
|
|
618
604
|
}, [defaultSizes, updateSizes]);
|
|
619
605
|
const dragEnd = useCallback((e) => {
|
|
620
|
-
|
|
621
|
-
(_b = (_a = document === null || document === void 0 ? void 0 : document.body) === null || _a === void 0 ? void 0 : _a.classList) === null || _b === void 0 ? void 0 : _b.remove(style["split-disabled"]);
|
|
606
|
+
document?.body?.classList?.remove(style["split-disabled"]);
|
|
622
607
|
axis.current = { x: e.pageX, y: e.pageY };
|
|
623
608
|
cacheSizes.current = { sizes, sashPosSizes };
|
|
624
609
|
setDragging(false);
|
|
@@ -678,16 +663,14 @@ function assertsSize(size, sum, defaultValue = Infinity) {
|
|
|
678
663
|
}
|
|
679
664
|
|
|
680
665
|
const Playground = (props) => {
|
|
681
|
-
var _a, _b, _c, _d;
|
|
682
666
|
const { host, onSave } = props;
|
|
683
667
|
const editorRef = useRef(undefined);
|
|
684
668
|
const [selectedEmitter, onSelectedEmitterChange] = useControllableValue(props.emitter, props.defaultEmitter, props.onEmitterChange);
|
|
685
|
-
const [compilerOptions, onCompilerOptionsChange] = useControllableValue(props.compilerOptions,
|
|
669
|
+
const [compilerOptions, onCompilerOptionsChange] = useControllableValue(props.compilerOptions, props.defaultCompilerOptions ?? {}, props.onCompilerOptionsChange);
|
|
686
670
|
const [selectedSampleName, onSelectedSampleNameChange] = useControllableValue(props.sampleName, props.defaultSampleName, props.onSampleNameChange);
|
|
687
671
|
const [content, setContent] = useState(props.defaultContent);
|
|
688
672
|
const isSampleUntouched = useMemo(() => {
|
|
689
|
-
|
|
690
|
-
return Boolean(selectedSampleName && content === ((_b = (_a = props.samples) === null || _a === void 0 ? void 0 : _a[selectedSampleName]) === null || _b === void 0 ? void 0 : _b.content));
|
|
673
|
+
return Boolean(selectedSampleName && content === props.samples?.[selectedSampleName]?.content);
|
|
691
674
|
}, [content, selectedSampleName, props.samples]);
|
|
692
675
|
const typespecModel = useMonacoModel("inmemory://test/main.tsp", "typespec");
|
|
693
676
|
const [compilationState, setCompilationState] = useState(undefined);
|
|
@@ -704,7 +687,7 @@ const Playground = (props) => {
|
|
|
704
687
|
severity: diag.severity === "error" ? MarkerSeverity.Error : MarkerSeverity.Warning,
|
|
705
688
|
tags: diag.code === "deprecated" ? [CompletionItemTag.Deprecated] : undefined,
|
|
706
689
|
}));
|
|
707
|
-
editor.setModelMarkers(typespecModel, "owner", markers
|
|
690
|
+
editor.setModelMarkers(typespecModel, "owner", markers ?? []);
|
|
708
691
|
}
|
|
709
692
|
else {
|
|
710
693
|
editor.setModelMarkers(typespecModel, "owner", []);
|
|
@@ -716,8 +699,7 @@ const Playground = (props) => {
|
|
|
716
699
|
}
|
|
717
700
|
}, [typespecModel]);
|
|
718
701
|
useEffect(() => {
|
|
719
|
-
|
|
720
|
-
updateTypeSpec((_a = props.defaultContent) !== null && _a !== void 0 ? _a : "");
|
|
702
|
+
updateTypeSpec(props.defaultContent ?? "");
|
|
721
703
|
}, []);
|
|
722
704
|
useEffect(() => {
|
|
723
705
|
if (selectedSampleName && props.samples) {
|
|
@@ -762,8 +744,7 @@ const Playground = (props) => {
|
|
|
762
744
|
isSampleUntouched,
|
|
763
745
|
]);
|
|
764
746
|
const formatCode = useCallback(() => {
|
|
765
|
-
|
|
766
|
-
void ((_b = (_a = editorRef.current) === null || _a === void 0 ? void 0 : _a.getAction("editor.action.formatDocument")) === null || _b === void 0 ? void 0 : _b.run());
|
|
747
|
+
void editorRef.current?.getAction("editor.action.formatDocument")?.run();
|
|
767
748
|
}, [typespecModel]);
|
|
768
749
|
const fileBug = useCallback(async () => {
|
|
769
750
|
if (props.onFileBug) {
|
|
@@ -790,10 +771,9 @@ const Playground = (props) => {
|
|
|
790
771
|
setVerticalPaneSizes(sizes);
|
|
791
772
|
}, [setVerticalPaneSizes]);
|
|
792
773
|
const handleDiagnosticSelected = useCallback((diagnostic) => {
|
|
793
|
-
|
|
794
|
-
(_a = editorRef.current) === null || _a === void 0 ? void 0 : _a.setSelection(getMonacoRange(host.compiler, diagnostic.target));
|
|
774
|
+
editorRef.current?.setSelection(getMonacoRange(host.compiler, diagnostic.target));
|
|
795
775
|
}, [setVerticalPaneSizes]);
|
|
796
|
-
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, fileBug: props.onFileBug ? fileBug : undefined, documentationUrl:
|
|
776
|
+
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, fileBug: props.onFileBug ? fileBug : undefined, documentationUrl: props.links?.documentationUrl }), jsx(TypeSpecEditor, { model: typespecModel, actions: typespecEditorActions, options: props.editorOptions, onMount: onTypeSpecEditorMount })] }), jsx(Pane, { children: jsx(OutputView, { compilationState: compilationState, editorOptions: props.editorOptions, viewers: props.emitterViewers?.[selectedEmitter] }) })] }) }), jsx(Pane, { minSize: 30, children: jsx(ProblemPane, { collapsed: verticalPaneSizes[1] === verticalPaneSizesConst.collapsed[1], compilationState: compilationState, onHeaderClick: toggleProblemPane, onDiagnosticSelected: handleDiagnosticSelected }) })] }), props.footer ?? jsx(DefaultFooter, {})] }) }));
|
|
797
777
|
};
|
|
798
778
|
const verticalPaneSizesConst = {
|
|
799
779
|
collapsed: [undefined, 30],
|
|
@@ -801,7 +781,6 @@ const verticalPaneSizesConst = {
|
|
|
801
781
|
};
|
|
802
782
|
const outputDir = "./tsp-output";
|
|
803
783
|
async function compile(host, content, selectedEmitter, options) {
|
|
804
|
-
var _a;
|
|
805
784
|
await host.writeFile("main.tsp", content);
|
|
806
785
|
await emptyOutputDir(host);
|
|
807
786
|
try {
|
|
@@ -811,7 +790,7 @@ async function compile(host, content, selectedEmitter, options) {
|
|
|
811
790
|
options: {
|
|
812
791
|
...options.options,
|
|
813
792
|
[selectedEmitter]: {
|
|
814
|
-
...
|
|
793
|
+
...options.options?.[selectedEmitter],
|
|
815
794
|
"emitter-output-dir": "tsp-output",
|
|
816
795
|
},
|
|
817
796
|
},
|
|
@@ -884,16 +863,13 @@ const StandalonePlayground = (config) => {
|
|
|
884
863
|
void navigator.clipboard.writeText(window.location.toString());
|
|
885
864
|
dispatchToast(jsxs(Toast, { children: [jsx(ToastTitle, { children: "Saved!" }), jsx(ToastBody, { children: "Playground link has been copied to the clipboard." })] }), { intent: "success" });
|
|
886
865
|
}, [dispatchToast, context]);
|
|
887
|
-
const fixedOptions = useMemo(() => {
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
defaultCompilerOptions: context.initialState.options,
|
|
895
|
-
defaultSampleName: context.initialState.sampleName,
|
|
896
|
-
};
|
|
866
|
+
const fixedOptions = useMemo(() => context && {
|
|
867
|
+
host: context.host,
|
|
868
|
+
libraries: config.libraries,
|
|
869
|
+
defaultContent: context.initialState.content,
|
|
870
|
+
defaultEmitter: context.initialState.emitter ?? config.defaultEmitter,
|
|
871
|
+
defaultCompilerOptions: context.initialState.options,
|
|
872
|
+
defaultSampleName: context.initialState.sampleName,
|
|
897
873
|
}, [context]);
|
|
898
874
|
if (context === undefined || fixedOptions === undefined) {
|
|
899
875
|
return config.fallback;
|