@typespec/playground 0.1.0-alpha.3 → 0.1.0-alpha.4-dev.14
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 +2 -2
- package/dist/index.js +1 -1
- package/dist/react/index.js +89 -61
- package/dist/react/index.js.map +1 -1
- package/dist/src/core.d.ts.map +1 -1
- package/dist/src/index.d.ts +2 -2
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/react/diagnostic-list.d.ts.map +1 -1
- package/dist/src/react/editor-command-bar.d.ts.map +1 -1
- package/dist/src/react/editor.d.ts.map +1 -1
- package/dist/src/react/error-tab.d.ts.map +1 -1
- package/dist/src/react/footer.d.ts +5 -1
- package/dist/src/react/footer.d.ts.map +1 -1
- package/dist/src/react/index.d.ts +2 -2
- package/dist/src/react/index.d.ts.map +1 -1
- package/dist/src/react/output-tabs.d.ts.map +1 -1
- package/dist/src/react/output-view.d.ts +2 -0
- package/dist/src/react/output-view.d.ts.map +1 -1
- package/dist/src/react/playground.d.ts +4 -0
- package/dist/src/react/playground.d.ts.map +1 -1
- package/dist/src/react/settings/compiler-settings.d.ts.map +1 -1
- package/dist/src/react/standalone.d.ts +2 -0
- package/dist/src/react/standalone.d.ts.map +1 -1
- package/dist/src/react/typespec-editor.d.ts +2 -0
- package/dist/src/react/typespec-editor.d.ts.map +1 -1
- package/dist/src/tooling/index.d.ts +6 -0
- package/dist/src/tooling/index.d.ts.map +1 -0
- package/dist/src/tooling/types.d.ts +3 -0
- package/dist/src/tooling/types.d.ts.map +1 -0
- package/dist/src/vite/types.d.ts +2 -3
- package/dist/src/vite/types.d.ts.map +1 -1
- package/dist/{state-storage-ad8a9d39.js → state-storage-e765354d.js} +5 -3
- package/dist/state-storage-e765354d.js.map +1 -0
- package/dist/tooling/index.js +30 -0
- package/dist/tooling/index.js.map +1 -0
- package/dist/vite/index.js +2 -2
- package/dist/vite/index.js.map +1 -1
- package/package.json +17 -12
- package/dist/state-storage-ad8a9d39.js.map +0 -1
package/dist/index.css
CHANGED
|
@@ -41,12 +41,12 @@
|
|
|
41
41
|
.split-pane-module_sash-content__DLAt4 {
|
|
42
42
|
width: 100%;
|
|
43
43
|
height: 100%;
|
|
44
|
-
background-color:
|
|
44
|
+
background-color: var(--colorNeutralStroke2);
|
|
45
45
|
}
|
|
46
46
|
|
|
47
47
|
.split-pane-module_sash-content-dragging__NkKQP,
|
|
48
48
|
.split-pane-module_sash-content__DLAt4:hover {
|
|
49
|
-
background-color:
|
|
49
|
+
background-color: var(--colorNeutralStroke1Pressed);
|
|
50
50
|
}
|
|
51
51
|
|
|
52
52
|
.split-pane-module_pane__m1zQB {
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { c as createBrowserHost, b as createUrlStateStorage, r as registerMonacoDefaultWorkers, a as registerMonacoLanguage } from './state-storage-
|
|
1
|
+
export { c as createBrowserHost, b as createUrlStateStorage, r as registerMonacoDefaultWorkers, a as registerMonacoLanguage } from './state-storage-e765354d.js';
|
|
2
2
|
import '@typespec/compiler';
|
|
3
3
|
import 'monaco-editor';
|
|
4
4
|
import 'vscode-languageserver';
|
package/dist/react/index.js
CHANGED
|
@@ -3,13 +3,13 @@ import debounce from 'debounce';
|
|
|
3
3
|
import { editor, Uri, MarkerSeverity, KeyMod, KeyCode } from 'monaco-editor';
|
|
4
4
|
import { useCallback, useMemo, useState, useEffect, useRef, useId as useId$1 } from 'react';
|
|
5
5
|
import { CompletionItemTag } from 'vscode-languageserver';
|
|
6
|
-
import { g as getMarkerLocation, c as createBrowserHost, a as registerMonacoLanguage, r as registerMonacoDefaultWorkers, b as createUrlStateStorage } from '../state-storage-
|
|
7
|
-
import { Select, useId, Label, RadioGroup, Radio, Input, Switch, Checkbox, Link, Toolbar, Tooltip, ToolbarButton, Dialog, DialogTrigger, DialogSurface, DialogBody, mergeClasses, useToastController, Toast, ToastTitle, ToastBody, FluentProvider, webLightTheme
|
|
6
|
+
import { i as importLibrary, g as getMarkerLocation, c as createBrowserHost, a as registerMonacoLanguage, r as registerMonacoDefaultWorkers, b as createUrlStateStorage } from '../state-storage-e765354d.js';
|
|
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';
|
|
8
8
|
import { Save16Regular, Broom16Filled, Settings24Regular, Bug16Regular } from '@fluentui/react-icons';
|
|
9
9
|
import { css } from '@emotion/react';
|
|
10
|
-
import { MANIFEST } from '@typespec/compiler';
|
|
11
10
|
import { TypeSpecProgramViewer } from '@typespec/html-program-viewer';
|
|
12
11
|
import { createRoot } from 'react-dom/client';
|
|
12
|
+
import '@typespec/compiler';
|
|
13
13
|
import 'vscode-languageserver-textdocument';
|
|
14
14
|
import 'lzutf8';
|
|
15
15
|
|
|
@@ -123,7 +123,7 @@ function useTypeSpecLibrary(name) {
|
|
|
123
123
|
const [lib, setLib] = useState();
|
|
124
124
|
useEffect(() => {
|
|
125
125
|
setLib(undefined);
|
|
126
|
-
|
|
126
|
+
importLibrary(name, {})
|
|
127
127
|
.then((module) => {
|
|
128
128
|
if (module.$lib === undefined) {
|
|
129
129
|
// eslint-disable-next-line no-console
|
|
@@ -142,7 +142,7 @@ function useTypeSpecLibrary(name) {
|
|
|
142
142
|
const EditorCommandBar = ({ documentationUrl, saveCode, formatCode, newIssue, libraries, selectedEmitter, onSelectedEmitterChange, compilerOptions: emitterOptions, onCompilerOptionsChange, samples, selectedSampleName, onSelectedSampleNameChange, }) => {
|
|
143
143
|
const documentation = documentationUrl ? (jsx("label", { children: jsx(Link, { href: documentationUrl, target: "_blank", children: "Docs" }) })) : undefined;
|
|
144
144
|
const bugButton = newIssue ? jsx(FileBugButton, { onClick: newIssue }) : undefined;
|
|
145
|
-
return (jsx("div", { css: { borderBottom:
|
|
145
|
+
return (jsx("div", { css: { borderBottom: `1px solid ${tokens.colorNeutralStroke1}` }, 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 && (jsx(SamplesDropdown, { samples: samples, selectedSampleName: selectedSampleName, onSelectedSampleNameChange: onSelectedSampleNameChange })), jsx(EmitterDropdown, { emitters: libraries.filter((x) => x.isEmitter).map((x) => x.name), onSelectedEmitterChange: onSelectedEmitterChange, selectedEmitter: selectedEmitter }), jsxs(Dialog, { children: [jsx(DialogTrigger, { children: jsx(ToolbarButton, { icon: jsx(Settings24Regular, {}) }) }), jsx(DialogSurface, { children: jsx(DialogBody, { children: jsx(CompilerSettings, { libraries: libraries, selectedEmitter: selectedEmitter, options: emitterOptions, onOptionsChanged: onCompilerOptionsChange }) }) })] }), documentation, jsx("div", { css: { flex: "1" } }), bugButton] }) }));
|
|
146
146
|
};
|
|
147
147
|
const FileBugButton = ({ onClick }) => {
|
|
148
148
|
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, children: "File bug" }) }));
|
|
@@ -159,6 +159,10 @@ const Editor = ({ model, options, actions, onMount }) => {
|
|
|
159
159
|
});
|
|
160
160
|
onMount === null || onMount === void 0 ? void 0 : onMount({ editor: editorRef.current });
|
|
161
161
|
}, []);
|
|
162
|
+
useEffect(() => {
|
|
163
|
+
var _a;
|
|
164
|
+
editor.setTheme((_a = options.theme) !== null && _a !== void 0 ? _a : "vs");
|
|
165
|
+
}, [options.theme]);
|
|
162
166
|
useEffect(() => {
|
|
163
167
|
const disposables = [];
|
|
164
168
|
for (const command of actions !== null && actions !== void 0 ? actions : []) {
|
|
@@ -183,7 +187,8 @@ function useMonacoModel(uri, language) {
|
|
|
183
187
|
}, [uri, language]);
|
|
184
188
|
}
|
|
185
189
|
|
|
186
|
-
const Footer = () => {
|
|
190
|
+
const Footer = ({ host }) => {
|
|
191
|
+
const { MANIFEST } = host.compiler;
|
|
187
192
|
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, {}));
|
|
188
193
|
return (jsxs("div", { css: [
|
|
189
194
|
{
|
|
@@ -267,17 +272,17 @@ const DiagnosticList = ({ diagnostics }) => {
|
|
|
267
272
|
}) }));
|
|
268
273
|
};
|
|
269
274
|
const DiagnosticItem = ({ diagnostic }) => {
|
|
270
|
-
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:
|
|
275
|
+
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 })] }));
|
|
271
276
|
};
|
|
272
|
-
const errorColor = css({ color:
|
|
273
|
-
const warningColor = css({ color:
|
|
277
|
+
const errorColor = css({ color: tokens.colorStatusDangerForeground1 });
|
|
278
|
+
const warningColor = css({ color: tokens.colorStatusWarningForeground1 });
|
|
274
279
|
|
|
275
280
|
const ErrorTab = ({ internalCompilerError, diagnostics, }) => {
|
|
276
281
|
return (jsxs(Fragment, { children: [internalCompilerError && jsx(InternalCompilerError, { error: internalCompilerError }), diagnostics && jsx(DiagnosticList, { diagnostics: diagnostics })] }));
|
|
277
282
|
};
|
|
278
283
|
const InternalCompilerError = ({ error }) => {
|
|
279
284
|
return (jsx("div", { css: { CenterStyles }, children: jsxs("div", { css: {
|
|
280
|
-
border:
|
|
285
|
+
border: `1px solid ${tokens.colorStatusDangerBorder1}`,
|
|
281
286
|
padding: "10px",
|
|
282
287
|
margin: "20px",
|
|
283
288
|
}, 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 })] }) }));
|
|
@@ -318,25 +323,24 @@ const DropdownStyle = css({
|
|
|
318
323
|
|
|
319
324
|
const OutputTabs = ({ tabs, selected, onSelect }) => {
|
|
320
325
|
const [leftTabs, rightTabs] = chunk(tabs, (x) => x.align === "left");
|
|
321
|
-
return (jsxs("div", { css: { display: "flex", borderBottom:
|
|
326
|
+
return (jsxs("div", { css: { display: "flex", borderBottom: `1px solid ${tokens.colorNeutralStroke1}` }, children: [leftTabs.map((tab) => {
|
|
322
327
|
return (jsx(OutputTab, { tab: tab, selected: selected === tab.id, onSelect: onSelect }, tab.id));
|
|
323
|
-
}), jsx("span", { css: { flex: 1, borderRight:
|
|
328
|
+
}), jsx("span", { css: { flex: 1, borderRight: `1px solid ${tokens.colorNeutralStroke1}` } }), rightTabs.map((tab) => {
|
|
324
329
|
return (jsx(OutputTab, { tab: tab, selected: selected === tab.id, onSelect: onSelect }, tab.id));
|
|
325
330
|
})] }));
|
|
326
331
|
};
|
|
327
332
|
const OutputTab = ({ tab, selected, onSelect }) => {
|
|
328
|
-
return (jsx("
|
|
333
|
+
return (jsx("div", { tabIndex: 0, css: [
|
|
329
334
|
{
|
|
330
335
|
height: "26px",
|
|
331
336
|
padding: "0 5px",
|
|
332
|
-
borderRight:
|
|
337
|
+
borderRight: `1px solid ${tokens.colorNeutralStroke1}`,
|
|
333
338
|
borderTop: "none",
|
|
334
339
|
borderBottom: "none",
|
|
335
|
-
color: "#000",
|
|
336
340
|
textDecoration: "none",
|
|
337
341
|
cursor: "pointer",
|
|
338
342
|
},
|
|
339
|
-
selected ? { fontWeight: "bold", backgroundColor:
|
|
343
|
+
selected ? { fontWeight: "bold", backgroundColor: tokens.colorNeutralBackground5 } : {},
|
|
340
344
|
], onClick: () => onSelect(tab.id), children: tab.name }));
|
|
341
345
|
};
|
|
342
346
|
function chunk(items, condition) {
|
|
@@ -365,11 +369,12 @@ const TypeSpecEditor = ({ actions, options, ...other }) => {
|
|
|
365
369
|
};
|
|
366
370
|
return jsx(Editor, { actions: actions, options: resolvedOptions, ...other });
|
|
367
371
|
};
|
|
368
|
-
const OutputEditor = ({ filename, value, }) => {
|
|
372
|
+
const OutputEditor = ({ filename, value, editorOptions }) => {
|
|
369
373
|
if (filename === "") {
|
|
370
374
|
return null;
|
|
371
375
|
}
|
|
372
376
|
const options = {
|
|
377
|
+
...editorOptions,
|
|
373
378
|
readOnly: true,
|
|
374
379
|
automaticLayout: true,
|
|
375
380
|
minimap: {
|
|
@@ -381,16 +386,16 @@ const OutputEditor = ({ filename, value, }) => {
|
|
|
381
386
|
return jsx(Editor, { model: model, options: options });
|
|
382
387
|
};
|
|
383
388
|
|
|
384
|
-
const OutputView = ({ compilationState, viewers }) => {
|
|
389
|
+
const OutputView = ({ compilationState, viewers, editorOptions, }) => {
|
|
385
390
|
if (compilationState === undefined) {
|
|
386
391
|
return jsx(Fragment, {});
|
|
387
392
|
}
|
|
388
393
|
if ("internalCompilerError" in compilationState) {
|
|
389
394
|
return jsx(InternalCompilerError, { error: compilationState.internalCompilerError });
|
|
390
395
|
}
|
|
391
|
-
return jsx(OutputViewInternal, { compilationResult: compilationState, viewers: viewers });
|
|
396
|
+
return (jsx(OutputViewInternal, { compilationResult: compilationState, viewers: viewers, editorOptions: editorOptions }));
|
|
392
397
|
};
|
|
393
|
-
const OutputViewInternal = ({ compilationResult, viewers }) => {
|
|
398
|
+
const OutputViewInternal = ({ compilationResult, viewers, editorOptions }) => {
|
|
394
399
|
const { program, outputFiles } = compilationResult;
|
|
395
400
|
const [viewSelection, setViewSelection] = useState({
|
|
396
401
|
type: "file",
|
|
@@ -439,15 +444,17 @@ const OutputViewInternal = ({ compilationResult, viewers }) => {
|
|
|
439
444
|
void loadOutputFile(tabId);
|
|
440
445
|
}
|
|
441
446
|
}, []);
|
|
442
|
-
return (jsxs(Fragment, { children: [jsx(OutputTabs, { tabs: tabs, selected: viewSelection.type === "file" ? viewSelection.filename : viewSelection.type, onSelect: handleTabSelection }), jsx("div", { className: "output-content", css: { width: "100%", height: "100%", overflow: "hidden" }, children: jsx(OutputContent, { viewSelection: viewSelection, program: program, viewers: viewers }) })] }));
|
|
443
|
-
};
|
|
444
|
-
const rawFileViewer = {
|
|
445
|
-
key: "raw",
|
|
446
|
-
label: "File",
|
|
447
|
-
render: ({ filename, content }) => (jsx(OutputEditor, { filename: filename, value: content })),
|
|
447
|
+
return (jsxs(Fragment, { children: [jsx(OutputTabs, { tabs: tabs, selected: viewSelection.type === "file" ? viewSelection.filename : viewSelection.type, onSelect: handleTabSelection }), jsx("div", { className: "output-content", css: { width: "100%", height: "100%", overflow: "hidden" }, children: jsx(OutputContent, { viewSelection: viewSelection, editorOptions: editorOptions, program: program, viewers: viewers }) })] }));
|
|
448
448
|
};
|
|
449
|
-
|
|
450
|
-
|
|
449
|
+
function getRawFileViewer(editorOptions) {
|
|
450
|
+
return {
|
|
451
|
+
key: "raw",
|
|
452
|
+
label: "File",
|
|
453
|
+
render: ({ filename, content }) => (jsx(OutputEditor, { editorOptions: editorOptions, filename: filename, value: content })),
|
|
454
|
+
};
|
|
455
|
+
}
|
|
456
|
+
const OutputContent = ({ viewSelection, program, viewers, editorOptions, }) => {
|
|
457
|
+
const resolvedViewers = useMemo(() => [getRawFileViewer(editorOptions), ...(viewers !== null && viewers !== void 0 ? viewers : [])], [viewers]);
|
|
451
458
|
switch (viewSelection.type) {
|
|
452
459
|
case "file":
|
|
453
460
|
return (jsx(FileOutput, { filename: viewSelection.filename, content: viewSelection.content, viewers: resolvedViewers }));
|
|
@@ -465,8 +472,8 @@ const ErrorTabLabel = ({ diagnostics }) => {
|
|
|
465
472
|
return (jsxs("div", { children: ["Errors ", errorCount > 0 ? jsx("span", { css: ErrorTabCountStyles, children: errorCount }) : ""] }));
|
|
466
473
|
};
|
|
467
474
|
const ErrorTabCountStyles = css({
|
|
468
|
-
backgroundColor:
|
|
469
|
-
color:
|
|
475
|
+
backgroundColor: tokens.colorStatusDangerBackground3,
|
|
476
|
+
color: tokens.colorNeutralForegroundOnBrand,
|
|
470
477
|
padding: "0 5px",
|
|
471
478
|
borderRadius: "20px",
|
|
472
479
|
});
|
|
@@ -742,7 +749,7 @@ const Playground = (props) => {
|
|
|
742
749
|
height: "100%",
|
|
743
750
|
overflow: "hidden",
|
|
744
751
|
fontFamily: `"Segoe UI", Tahoma, Geneva, Verdana, sans-serif`,
|
|
745
|
-
}, children: [jsxs(SplitPane, { initialSizes: ["50%", "50%"], css: { gridArea: "typespeceditor", width: "100%", height: "100%", overflow: "hidden" }, children: [jsxs(Pane, { children: [jsx(EditorCommandBar, { libraries: libraries, 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, onMount: onTypeSpecEditorMount })] }), jsx(Pane, { children: jsx(OutputView, { compilationState: compilationState, viewers: (_d = props.emitterViewers) === null || _d === void 0 ? void 0 : _d[selectedEmitter] }) })] }), jsx(Footer, {})] }));
|
|
752
|
+
}, children: [jsxs(SplitPane, { initialSizes: ["50%", "50%"], css: { gridArea: "typespeceditor", width: "100%", height: "100%", overflow: "hidden" }, children: [jsxs(Pane, { children: [jsx(EditorCommandBar, { libraries: libraries, 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 })] }));
|
|
746
753
|
};
|
|
747
754
|
const outputDir = "./tsp-output";
|
|
748
755
|
async function compile(host, content, selectedEmitter, options) {
|
|
@@ -803,40 +810,61 @@ async function emptyOutputDir(host) {
|
|
|
803
810
|
}
|
|
804
811
|
}
|
|
805
812
|
|
|
806
|
-
|
|
807
|
-
const
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
},
|
|
832
|
-
|
|
813
|
+
function useStandalonePlaygroundContext(config) {
|
|
814
|
+
const [context, setContext] = useState();
|
|
815
|
+
useEffect(() => {
|
|
816
|
+
const load = async () => {
|
|
817
|
+
const host = await createBrowserHost(config.libraries, config.importConfig);
|
|
818
|
+
await registerMonacoLanguage(host);
|
|
819
|
+
registerMonacoDefaultWorkers();
|
|
820
|
+
const stateStorage = createStandalonePlaygroundStateStorage();
|
|
821
|
+
const initialState = stateStorage.load();
|
|
822
|
+
setContext({ host, initialState, stateStorage });
|
|
823
|
+
};
|
|
824
|
+
void load();
|
|
825
|
+
}, []);
|
|
826
|
+
return context;
|
|
827
|
+
}
|
|
828
|
+
const StandalonePlayground = (config) => {
|
|
829
|
+
const context = useStandalonePlaygroundContext(config);
|
|
830
|
+
const toasterId = useId$1();
|
|
831
|
+
const { dispatchToast } = useToastController(toasterId);
|
|
832
|
+
const onSave = useCallback((value) => {
|
|
833
|
+
if (!context) {
|
|
834
|
+
return;
|
|
835
|
+
}
|
|
836
|
+
context.stateStorage.save(value);
|
|
837
|
+
void navigator.clipboard.writeText(window.location.toString());
|
|
838
|
+
dispatchToast(jsxs(Toast, { children: [jsx(ToastTitle, { children: "Saved!" }), jsx(ToastBody, { children: "Playground link has been copied to the clipboard." })] }), { intent: "success" });
|
|
839
|
+
}, [dispatchToast, context]);
|
|
840
|
+
const fixedOptions = useMemo(() => {
|
|
841
|
+
var _a;
|
|
842
|
+
return context && {
|
|
843
|
+
host: context.host,
|
|
844
|
+
libraries: config.libraries,
|
|
845
|
+
defaultContent: context.initialState.content,
|
|
846
|
+
defaultEmitter: (_a = context.initialState.emitter) !== null && _a !== void 0 ? _a : config.defaultEmitter,
|
|
847
|
+
defaultCompilerOptions: context.initialState.options,
|
|
848
|
+
defaultSampleName: context.initialState.sampleName,
|
|
849
|
+
};
|
|
850
|
+
}, [context]);
|
|
851
|
+
if (context === undefined || fixedOptions === undefined) {
|
|
852
|
+
return jsx(Fragment, {});
|
|
853
|
+
}
|
|
854
|
+
const options = {
|
|
855
|
+
...config,
|
|
856
|
+
...fixedOptions,
|
|
857
|
+
onSave,
|
|
833
858
|
};
|
|
834
|
-
return jsx(
|
|
859
|
+
return (jsxs(Fragment, { children: [jsx(Toaster, { toasterId: toasterId }), options && jsx(Playground, { ...options })] }));
|
|
860
|
+
};
|
|
861
|
+
async function createReactPlayground(config) {
|
|
862
|
+
return jsx(StandalonePlayground, { ...config });
|
|
835
863
|
}
|
|
836
864
|
async function renderReactPlayground(config) {
|
|
837
865
|
const app = await createReactPlayground(config);
|
|
838
866
|
const root = createRoot(document.getElementById("root"));
|
|
839
|
-
root.render(app);
|
|
867
|
+
root.render(jsx(FluentProvider, { theme: webLightTheme, style: { height: "100vh" }, children: app }));
|
|
840
868
|
}
|
|
841
869
|
function createStandalonePlaygroundStateStorage() {
|
|
842
870
|
const stateStorage = createUrlStateStorage({
|
|
@@ -863,5 +891,5 @@ function createStandalonePlaygroundStateStorage() {
|
|
|
863
891
|
};
|
|
864
892
|
}
|
|
865
893
|
|
|
866
|
-
export { Playground, createReactPlayground, renderReactPlayground };
|
|
894
|
+
export { Playground, StandalonePlayground, createReactPlayground, renderReactPlayground };
|
|
867
895
|
//# sourceMappingURL=index.js.map
|