@typespec/playground 0.3.0-dev.9 → 0.3.0
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/.storybook/main.d.ts +5 -0
- package/dist/.storybook/main.d.ts.map +1 -0
- package/dist/.storybook/preview.d.ts +5 -0
- package/dist/.storybook/preview.d.ts.map +1 -0
- package/dist/index.js +31 -34
- package/dist/react/index.js +1430 -783
- package/dist/react/viewers/index.js +8 -7
- package/dist/react-wrapper-CT3xxCSW.js +20 -0
- package/dist/src/browser-host.d.ts +3 -2
- package/dist/src/browser-host.d.ts.map +1 -1
- package/dist/src/core.d.ts +1 -1
- package/dist/src/core.d.ts.map +1 -1
- package/dist/src/editor-command-bar/editor-command-bar.d.ts +4 -3
- package/dist/src/editor-command-bar/editor-command-bar.d.ts.map +1 -1
- package/dist/src/index.d.ts +5 -5
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/lsp/monaco-to-lsp.d.ts +1 -1
- package/dist/src/manifest.d.ts +2 -4
- package/dist/src/manifest.d.ts.map +1 -1
- package/dist/src/react/context/index.d.ts +1 -1
- package/dist/src/react/context/index.d.ts.map +1 -1
- package/dist/src/react/context/playground-context.d.ts +4 -4
- package/dist/src/react/context/playground-context.d.ts.map +1 -1
- package/dist/src/react/default-footer.d.ts +2 -1
- package/dist/src/react/default-footer.d.ts.map +1 -1
- package/dist/src/react/diagnostic-list/diagnostic-list.d.ts +3 -2
- package/dist/src/react/diagnostic-list/diagnostic-list.d.ts.map +1 -1
- package/dist/src/react/editor.d.ts +3 -2
- package/dist/src/react/editor.d.ts.map +1 -1
- package/dist/src/react/emitter-dropdown.d.ts +2 -1
- package/dist/src/react/emitter-dropdown.d.ts.map +1 -1
- package/dist/src/react/file-output/file-output.d.ts +6 -5
- package/dist/src/react/file-output/file-output.d.ts.map +1 -1
- package/dist/src/react/footer/footer-item.d.ts +2 -1
- package/dist/src/react/footer/footer-item.d.ts.map +1 -1
- package/dist/src/react/footer/footer-version-item.d.ts +1 -1
- package/dist/src/react/footer/footer.d.ts +2 -1
- package/dist/src/react/footer/footer.d.ts.map +1 -1
- package/dist/src/react/footer/index.d.ts +3 -3
- package/dist/src/react/footer/index.d.ts.map +1 -1
- package/dist/src/react/index.d.ts +6 -6
- package/dist/src/react/index.d.ts.map +1 -1
- package/dist/src/react/output-tabs/output-tabs.d.ts +3 -7
- package/dist/src/react/output-tabs/output-tabs.d.ts.map +1 -1
- package/dist/src/react/output-view/file-viewer.d.ts +4 -0
- package/dist/src/react/output-view/file-viewer.d.ts.map +1 -0
- package/dist/src/react/output-view/output-view.d.ts +9 -4
- package/dist/src/react/output-view/output-view.d.ts.map +1 -1
- package/dist/src/react/output-view/type-graph-viewer.d.ts +4 -0
- package/dist/src/react/output-view/type-graph-viewer.d.ts.map +1 -0
- package/dist/src/react/playground.d.ts +8 -5
- package/dist/src/react/playground.d.ts.map +1 -1
- package/dist/src/react/problem-pane/header.d.ts +4 -3
- package/dist/src/react/problem-pane/header.d.ts.map +1 -1
- package/dist/src/react/problem-pane/index.d.ts +1 -1
- package/dist/src/react/problem-pane/problem-pane.d.ts +4 -3
- package/dist/src/react/problem-pane/problem-pane.d.ts.map +1 -1
- package/dist/src/react/samples-dropdown.d.ts +3 -2
- package/dist/src/react/samples-dropdown.d.ts.map +1 -1
- package/dist/src/react/settings/compiler-settings-dialog-button.d.ts +2 -1
- package/dist/src/react/settings/compiler-settings.d.ts +4 -3
- package/dist/src/react/settings/compiler-settings.d.ts.map +1 -1
- package/dist/src/react/settings/emitter-options-form.d.ts +4 -3
- package/dist/src/react/settings/emitter-options-form.d.ts.map +1 -1
- package/dist/src/react/settings/linter-form.d.ts +4 -3
- package/dist/src/react/settings/linter-form.d.ts.map +1 -1
- package/dist/src/react/split-pane/index.d.ts +1 -1
- package/dist/src/react/split-pane/index.d.ts.map +1 -1
- package/dist/src/react/split-pane/pane.d.ts +2 -1
- package/dist/src/react/split-pane/pane.d.ts.map +1 -1
- package/dist/src/react/split-pane/sash-content.d.ts +2 -1
- package/dist/src/react/split-pane/sash-content.d.ts.map +1 -1
- package/dist/src/react/split-pane/sash.d.ts +2 -1
- package/dist/src/react/split-pane/sash.d.ts.map +1 -1
- package/dist/src/react/split-pane/split-pane.d.ts +2 -1
- package/dist/src/react/split-pane/split-pane.d.ts.map +1 -1
- package/dist/src/react/standalone.d.ts +5 -4
- package/dist/src/react/standalone.d.ts.map +1 -1
- package/dist/src/react/types.d.ts +20 -8
- package/dist/src/react/types.d.ts.map +1 -1
- package/dist/src/react/typespec-editor.d.ts +5 -4
- package/dist/src/react/typespec-editor.d.ts.map +1 -1
- package/dist/src/react/viewers/index.d.ts +2 -1
- package/dist/src/react/viewers/index.d.ts.map +1 -1
- package/dist/src/react/viewers/swagger-ui.d.ts +2 -2
- package/dist/src/react/viewers/swagger-ui.d.ts.map +1 -1
- package/dist/src/services.d.ts +3 -2
- package/dist/src/services.d.ts.map +1 -1
- package/dist/src/tooling/index.d.ts +2 -1
- package/dist/src/tooling/index.d.ts.map +1 -1
- package/dist/src/tooling/types.d.ts +2 -1
- package/dist/src/tooling/types.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/index.d.ts +3 -2
- package/dist/src/vite/index.d.ts.map +1 -1
- package/dist/src/vite/types.d.ts +4 -3
- package/dist/src/vite/types.d.ts.map +1 -1
- package/dist/state-storage-BjOULkS3.js +654 -0
- package/dist/stories/footer/footer-item.stories.d.ts +9 -0
- package/dist/stories/footer/footer-item.stories.d.ts.map +1 -0
- package/dist/stories/footer/footer-version-item.stories.d.ts +9 -0
- package/dist/stories/footer/footer-version-item.stories.d.ts.map +1 -0
- package/dist/stories/footer/footer.stories.d.ts +9 -0
- package/dist/stories/footer/footer.stories.d.ts.map +1 -0
- package/dist/stories/playground.stories.d.ts +9 -0
- package/dist/stories/playground.stories.d.ts.map +1 -0
- package/dist/{index.css → style.css} +168 -161
- package/dist/tooling/index.js +18 -23
- package/dist/vite/index.js +74 -76
- package/dist/vite.config.d.ts +3 -0
- package/dist/vite.config.d.ts.map +1 -0
- package/package.json +39 -38
- package/dist/index.js.map +0 -1
- package/dist/react/index.js.map +0 -1
- package/dist/react/viewers/index.js.map +0 -1
- package/dist/react-wrapper-uSmRU7Jg.js +0 -21
- package/dist/react-wrapper-uSmRU7Jg.js.map +0 -1
- package/dist/state-storage-CObxFEXn.js +0 -657
- package/dist/state-storage-CObxFEXn.js.map +0 -1
- package/dist/tooling/index.js.map +0 -1
- package/dist/vite/index.js.map +0 -1
package/dist/react/index.js
CHANGED
|
@@ -1,919 +1,1566 @@
|
|
|
1
1
|
import { createContext, useContext, memo, useCallback, useMemo, useRef, useEffect, useState, useId as useId$1 } from 'react';
|
|
2
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,
|
|
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, Toolbar, Tooltip, Link, TabList, Tab, tokens, useToastController, Toast, ToastTitle, ToastBody, Toaster, FluentProvider, webLightTheme } from '@fluentui/react-components';
|
|
4
4
|
import debounce from 'debounce';
|
|
5
|
-
import {
|
|
5
|
+
import { Uri, editor, MarkerSeverity, KeyMod, KeyCode } from 'monaco-editor';
|
|
6
6
|
import { CompletionItemTag } from 'vscode-languageserver';
|
|
7
|
-
import { Settings24Regular, Save16Regular, Broom16Filled, Bug16Regular, ErrorCircle16Filled, Warning16Filled, ChevronDown16Regular } from '@fluentui/react-icons';
|
|
8
|
-
import { g as getMonacoRange,
|
|
7
|
+
import { Settings24Regular, Save16Regular, Broom16Filled, Bug16Regular, FolderListRegular, DataLineRegular, ErrorCircle16Filled, Warning16Filled, ChevronDown16Regular } from '@fluentui/react-icons';
|
|
8
|
+
import { g as getMonacoRange, a as createUrlStateStorage, c as createBrowserHost, r as registerMonacoLanguage } from '../state-storage-BjOULkS3.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';
|
|
12
|
-
import 'vscode-languageserver-textdocument';
|
|
13
|
-
import 'lzutf8';
|
|
14
12
|
|
|
15
|
-
const PlaygroundContext = createContext(
|
|
13
|
+
const PlaygroundContext = createContext(void 0);
|
|
16
14
|
const PlaygroundContextProvider = PlaygroundContext.Provider;
|
|
17
15
|
function usePlaygroundContext() {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
16
|
+
const context = useContext(PlaygroundContext);
|
|
17
|
+
if (context === void 0) {
|
|
18
|
+
throw new Error("usePlaygroundContext must be used within a PlaygroundContextProvider");
|
|
19
|
+
}
|
|
20
|
+
return context;
|
|
23
21
|
}
|
|
24
22
|
|
|
25
|
-
|
|
23
|
+
const footer = "_footer_cn8nf_1";
|
|
24
|
+
const style$b = {
|
|
25
|
+
footer: footer,
|
|
26
|
+
"footer-item": "_footer-item_cn8nf_9"
|
|
27
|
+
};
|
|
26
28
|
|
|
27
29
|
const FooterItem = ({ children, link, className }) => {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
+
const resolvedClassName = mergeClasses(style$b["footer-item"], className);
|
|
31
|
+
return link ? /* @__PURE__ */ jsx("a", { className: resolvedClassName, href: link, target: "_blank", rel: "noopener noreferrer", children }) : /* @__PURE__ */ jsx("div", { className: resolvedClassName, children });
|
|
30
32
|
};
|
|
31
33
|
|
|
32
|
-
|
|
34
|
+
const button = "_button_1c15n_4";
|
|
35
|
+
const style$a = {
|
|
36
|
+
"version-item": "_version-item_1c15n_1",
|
|
37
|
+
button: button
|
|
38
|
+
};
|
|
33
39
|
|
|
34
40
|
const FooterVersionItem = memo(({ versionSelector }) => {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
41
|
+
const { host } = usePlaygroundContext();
|
|
42
|
+
const latest = versionSelector?.latest;
|
|
43
|
+
const selected = versionSelector?.selected ?? host.compiler.MANIFEST.version;
|
|
44
|
+
return /* @__PURE__ */ jsx(FooterItem, { className: style$a["version-item"], children: /* @__PURE__ */ jsxs(Popover, { children: [
|
|
45
|
+
/* @__PURE__ */ jsx(PopoverTrigger, { disableButtonEnhancement: true, children: /* @__PURE__ */ jsxs("div", { className: style$a["button"], children: [
|
|
46
|
+
/* @__PURE__ */ jsx("span", { children: "Version " }),
|
|
47
|
+
/* @__PURE__ */ jsx("span", { children: selected }),
|
|
48
|
+
/* @__PURE__ */ jsx("span", { children: latest ? latest === selected ? " (latest)" : " (old)" : "" })
|
|
49
|
+
] }) }),
|
|
50
|
+
/* @__PURE__ */ jsx(PopoverSurface, { children: /* @__PURE__ */ jsx(VersionsPopup, { versionSelector }) })
|
|
51
|
+
] }) });
|
|
39
52
|
});
|
|
40
53
|
const VersionsPopup = memo(({ versionSelector }) => {
|
|
41
|
-
|
|
42
|
-
|
|
54
|
+
const { host } = usePlaygroundContext();
|
|
55
|
+
return /* @__PURE__ */ jsxs("div", { style: { maxWidth: "400px" }, children: [
|
|
56
|
+
versionSelector && /* @__PURE__ */ jsx(VersionSelector, { ...versionSelector }),
|
|
57
|
+
/* @__PURE__ */ jsxs("div", { children: [
|
|
58
|
+
/* @__PURE__ */ jsx(Title3, { children: "Loaded libraries" }),
|
|
59
|
+
/* @__PURE__ */ jsxs(Table, { size: "small", children: [
|
|
60
|
+
/* @__PURE__ */ jsx(TableHeader, { children: /* @__PURE__ */ jsx(TableRow, { children: columns.map((column) => /* @__PURE__ */ jsx(TableHeaderCell, { children: column.label }, column.columnKey)) }) }),
|
|
61
|
+
/* @__PURE__ */ jsx(TableBody, { children: Object.values(host.libraries).map((item) => /* @__PURE__ */ jsxs(TableRow, { children: [
|
|
62
|
+
/* @__PURE__ */ jsx(TableCell, { children: item.name }),
|
|
63
|
+
/* @__PURE__ */ jsx(TableCell, { children: item.packageJson.version })
|
|
64
|
+
] }, item.name)) })
|
|
65
|
+
] })
|
|
66
|
+
] })
|
|
67
|
+
] });
|
|
43
68
|
});
|
|
44
69
|
const columns = [
|
|
45
|
-
|
|
46
|
-
|
|
70
|
+
{ columnKey: "name", label: "Library" },
|
|
71
|
+
{ columnKey: "version", label: "Version" }
|
|
47
72
|
];
|
|
48
73
|
const VersionSelector = memo(({ versions, selected, latest, onChange }) => {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
74
|
+
const changeVersion = useCallback(
|
|
75
|
+
(ev, data) => {
|
|
76
|
+
onChange(versions.find((x) => x.name === data.value));
|
|
77
|
+
},
|
|
78
|
+
[versions, onChange]
|
|
79
|
+
);
|
|
80
|
+
return /* @__PURE__ */ jsxs("div", { children: [
|
|
81
|
+
/* @__PURE__ */ jsx(Title3, { children: "Select release" }),
|
|
82
|
+
/* @__PURE__ */ jsx(Select, { value: selected, onChange: changeVersion, "aria-label": "Select version", children: versions.map((version) => /* @__PURE__ */ jsxs("option", { value: version.name, children: [
|
|
83
|
+
version.label,
|
|
84
|
+
" ",
|
|
85
|
+
version.name === latest ? "(latest)" : ""
|
|
86
|
+
] }, version.name)) })
|
|
87
|
+
] });
|
|
53
88
|
});
|
|
54
89
|
|
|
55
90
|
const Footer = ({ className, children }) => {
|
|
56
|
-
|
|
91
|
+
return /* @__PURE__ */ jsx("div", { className: mergeClasses(style$b.footer, className), children });
|
|
57
92
|
};
|
|
58
93
|
|
|
59
|
-
const EmitterDropdown = ({
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
},
|
|
66
|
-
|
|
94
|
+
const EmitterDropdown = ({
|
|
95
|
+
emitters,
|
|
96
|
+
onSelectedEmitterChange,
|
|
97
|
+
selectedEmitter
|
|
98
|
+
}) => {
|
|
99
|
+
const options = emitters.map((emitterName) => {
|
|
100
|
+
return /* @__PURE__ */ jsx("option", { children: emitterName }, emitterName);
|
|
101
|
+
});
|
|
102
|
+
const handleSelected = useCallback(
|
|
103
|
+
(evt) => {
|
|
104
|
+
onSelectedEmitterChange(evt.target.value);
|
|
105
|
+
},
|
|
106
|
+
[onSelectedEmitterChange]
|
|
107
|
+
);
|
|
108
|
+
return /* @__PURE__ */ jsxs(
|
|
109
|
+
Select,
|
|
110
|
+
{
|
|
111
|
+
className: "sample-dropdown",
|
|
112
|
+
onChange: handleSelected,
|
|
113
|
+
value: selectedEmitter,
|
|
114
|
+
"aria-label": "Select an emitter",
|
|
115
|
+
children: [
|
|
116
|
+
/* @__PURE__ */ jsx("option", { value: "", disabled: true, children: "Select emitter..." }),
|
|
117
|
+
options
|
|
118
|
+
]
|
|
119
|
+
}
|
|
120
|
+
);
|
|
67
121
|
};
|
|
68
122
|
|
|
69
|
-
const SamplesDropdown = ({
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
123
|
+
const SamplesDropdown = ({
|
|
124
|
+
samples,
|
|
125
|
+
selectedSampleName,
|
|
126
|
+
onSelectedSampleNameChange
|
|
127
|
+
}) => {
|
|
128
|
+
const options = Object.keys(samples).map((sample) => {
|
|
129
|
+
return /* @__PURE__ */ jsx("option", { children: sample }, sample);
|
|
130
|
+
});
|
|
131
|
+
const handleSelected = useCallback(
|
|
132
|
+
(evt) => {
|
|
133
|
+
if (samples[evt.target.value]) {
|
|
134
|
+
onSelectedSampleNameChange(evt.target.value);
|
|
135
|
+
}
|
|
136
|
+
},
|
|
137
|
+
[onSelectedSampleNameChange]
|
|
138
|
+
);
|
|
139
|
+
return /* @__PURE__ */ jsxs(
|
|
140
|
+
Select,
|
|
141
|
+
{
|
|
142
|
+
className: "sample-dropdown",
|
|
143
|
+
onChange: handleSelected,
|
|
144
|
+
value: selectedSampleName ?? "",
|
|
145
|
+
"aria-label": "Select a sample",
|
|
146
|
+
children: [
|
|
147
|
+
/* @__PURE__ */ jsx("option", { value: "", disabled: true, children: "Select sample..." }),
|
|
148
|
+
options
|
|
149
|
+
]
|
|
150
|
+
}
|
|
151
|
+
);
|
|
79
152
|
};
|
|
80
153
|
|
|
81
|
-
|
|
154
|
+
const form = "_form_sqeas_1";
|
|
155
|
+
const item$1 = "_item_sqeas_7";
|
|
156
|
+
const style$9 = {
|
|
157
|
+
form: form,
|
|
158
|
+
item: item$1,
|
|
159
|
+
"switch": "_switch_sqeas_13"
|
|
160
|
+
};
|
|
82
161
|
|
|
83
|
-
const EmitterOptionsForm = ({
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
}
|
|
101
|
-
};
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
162
|
+
const EmitterOptionsForm = ({
|
|
163
|
+
library,
|
|
164
|
+
options,
|
|
165
|
+
optionsChanged
|
|
166
|
+
}) => {
|
|
167
|
+
const emitterOptionsSchema = library.definition?.emitter?.options?.properties;
|
|
168
|
+
if (emitterOptionsSchema === void 0) {
|
|
169
|
+
return /* @__PURE__ */ jsx(Fragment, { children: '"No options"' });
|
|
170
|
+
}
|
|
171
|
+
const entries = Object.entries(emitterOptionsSchema);
|
|
172
|
+
const handleChange = useCallback(
|
|
173
|
+
({ name, value }) => {
|
|
174
|
+
optionsChanged({
|
|
175
|
+
...options,
|
|
176
|
+
[library.name]: {
|
|
177
|
+
...options[library.name],
|
|
178
|
+
[name]: value
|
|
179
|
+
}
|
|
180
|
+
});
|
|
181
|
+
},
|
|
182
|
+
[options, optionsChanged]
|
|
183
|
+
);
|
|
184
|
+
return /* @__PURE__ */ jsx("div", { className: style$9["form"], children: entries.map(([key, value]) => {
|
|
185
|
+
return /* @__PURE__ */ jsx("div", { className: style$9["form-item"], children: /* @__PURE__ */ jsx(
|
|
186
|
+
JsonSchemaPropertyInput,
|
|
187
|
+
{
|
|
188
|
+
emitterOptions: options[library.name] ?? {},
|
|
189
|
+
name: key,
|
|
190
|
+
prop: value,
|
|
191
|
+
onChange: handleChange
|
|
192
|
+
}
|
|
193
|
+
) }, key);
|
|
194
|
+
}) });
|
|
195
|
+
};
|
|
196
|
+
const JsonSchemaPropertyInput = ({
|
|
197
|
+
emitterOptions,
|
|
198
|
+
name,
|
|
199
|
+
prop,
|
|
200
|
+
onChange
|
|
201
|
+
}) => {
|
|
202
|
+
const prettyName = useMemo(
|
|
203
|
+
() => name[0].toUpperCase() + name.slice(1).replace(/-/g, " "),
|
|
204
|
+
[name]
|
|
205
|
+
);
|
|
206
|
+
const inputId = useId("input");
|
|
207
|
+
const value = emitterOptions[name] ?? prop.default;
|
|
208
|
+
const handleChange = useCallback(
|
|
209
|
+
(_, data) => onChange({ name, value: "value" in data ? data.value : data.checked }),
|
|
210
|
+
[onChange]
|
|
211
|
+
);
|
|
212
|
+
switch (prop.type) {
|
|
213
|
+
case "boolean":
|
|
214
|
+
return /* @__PURE__ */ jsx(
|
|
215
|
+
Switch,
|
|
216
|
+
{
|
|
217
|
+
className: style$9["switch"],
|
|
218
|
+
label: prettyName,
|
|
219
|
+
labelPosition: "above",
|
|
220
|
+
checked: value,
|
|
221
|
+
onChange: handleChange
|
|
222
|
+
}
|
|
223
|
+
);
|
|
224
|
+
case "string":
|
|
225
|
+
default:
|
|
226
|
+
return /* @__PURE__ */ jsxs("div", { className: style$9["item"], children: [
|
|
227
|
+
/* @__PURE__ */ jsx(Label, { htmlFor: inputId, title: name, children: prettyName }),
|
|
228
|
+
prop.enum ? /* @__PURE__ */ jsx(RadioGroup, { layout: "horizontal", id: inputId, value, onChange: handleChange, children: prop.enum.map((x) => /* @__PURE__ */ jsx(Radio, { value: x, label: x }, x)) }) : /* @__PURE__ */ jsx(Input, { id: inputId, value, onChange: handleChange })
|
|
229
|
+
] });
|
|
230
|
+
}
|
|
114
231
|
};
|
|
115
232
|
|
|
116
|
-
const LinterForm = ({
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
233
|
+
const LinterForm = ({
|
|
234
|
+
libraries,
|
|
235
|
+
linterRuleSet,
|
|
236
|
+
onLinterRuleSetChanged
|
|
237
|
+
}) => {
|
|
238
|
+
const rulesets = Object.values(libraries).flatMap((lib) => {
|
|
239
|
+
const linter = lib.linter ?? lib.definition?.linter;
|
|
240
|
+
return Object.keys(linter?.ruleSets ?? {}).map((x) => `${lib.name}/${x}`);
|
|
241
|
+
});
|
|
242
|
+
if (rulesets.length === 0) {
|
|
243
|
+
return /* @__PURE__ */ jsx(Fragment, { children: "No ruleset available" });
|
|
244
|
+
}
|
|
245
|
+
const handleChange = (ruleSet, checked) => {
|
|
246
|
+
const ruleSets = linterRuleSet.extends ?? [];
|
|
247
|
+
const updatedRuleSets = checked ? [...ruleSets, ruleSet] : ruleSets.filter((x) => x !== ruleSet);
|
|
248
|
+
onLinterRuleSetChanged({
|
|
249
|
+
extends: updatedRuleSets
|
|
121
250
|
});
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
return (jsx(Fragment, { children: rulesets.map((ruleSet) => {
|
|
135
|
-
return (jsx(RuleSetCheckbox, { ruleSet: ruleSet, checked: linterRuleSet.extends?.includes(ruleSet), onChange: handleChange }, ruleSet));
|
|
136
|
-
}) }));
|
|
251
|
+
};
|
|
252
|
+
return /* @__PURE__ */ jsx(Fragment, { children: rulesets.map((ruleSet) => {
|
|
253
|
+
return /* @__PURE__ */ jsx(
|
|
254
|
+
RuleSetCheckbox,
|
|
255
|
+
{
|
|
256
|
+
ruleSet,
|
|
257
|
+
checked: linterRuleSet.extends?.includes(ruleSet),
|
|
258
|
+
onChange: handleChange
|
|
259
|
+
},
|
|
260
|
+
ruleSet
|
|
261
|
+
);
|
|
262
|
+
}) });
|
|
137
263
|
};
|
|
138
264
|
const RuleSetCheckbox = ({ ruleSet, checked, onChange }) => {
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
265
|
+
const handleChange = useCallback(
|
|
266
|
+
(_, data) => {
|
|
267
|
+
onChange(ruleSet, !!data.checked);
|
|
268
|
+
},
|
|
269
|
+
[ruleSet, checked, onChange]
|
|
270
|
+
);
|
|
271
|
+
return /* @__PURE__ */ jsx(Checkbox, { label: ruleSet, checked, onChange: handleChange });
|
|
143
272
|
};
|
|
144
273
|
|
|
145
|
-
const CompilerSettings = ({
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
274
|
+
const CompilerSettings = ({
|
|
275
|
+
selectedEmitter,
|
|
276
|
+
host,
|
|
277
|
+
options,
|
|
278
|
+
onOptionsChanged
|
|
279
|
+
}) => {
|
|
280
|
+
const emitterOptionsChanged = useCallback(
|
|
281
|
+
(emitterOptions) => {
|
|
282
|
+
onOptionsChanged({
|
|
283
|
+
...options,
|
|
284
|
+
options: emitterOptions
|
|
285
|
+
});
|
|
286
|
+
},
|
|
287
|
+
[options]
|
|
288
|
+
);
|
|
289
|
+
const library = host.libraries[selectedEmitter];
|
|
290
|
+
const linterRuleSet = options.linterRuleSet ?? {};
|
|
291
|
+
const linterRuleSetChanged = useCallback(
|
|
292
|
+
(linterRuleSet2) => {
|
|
293
|
+
onOptionsChanged({
|
|
294
|
+
...options,
|
|
295
|
+
linterRuleSet: linterRuleSet2
|
|
296
|
+
});
|
|
297
|
+
},
|
|
298
|
+
[options]
|
|
299
|
+
);
|
|
300
|
+
return /* @__PURE__ */ jsxs("div", { children: [
|
|
301
|
+
/* @__PURE__ */ jsxs(Fragment, { children: [
|
|
302
|
+
"Emitter: ",
|
|
303
|
+
selectedEmitter
|
|
304
|
+
] }),
|
|
305
|
+
/* @__PURE__ */ jsx(Divider, { style: { marginTop: 20 } }),
|
|
306
|
+
/* @__PURE__ */ jsx("h3", { children: "Options" }),
|
|
307
|
+
library && /* @__PURE__ */ jsx(
|
|
308
|
+
EmitterOptionsForm,
|
|
309
|
+
{
|
|
310
|
+
library,
|
|
311
|
+
options: options.options ?? {},
|
|
312
|
+
optionsChanged: emitterOptionsChanged
|
|
313
|
+
}
|
|
314
|
+
),
|
|
315
|
+
/* @__PURE__ */ jsx(Divider, { style: { marginTop: 20 } }),
|
|
316
|
+
/* @__PURE__ */ jsx("h3", { children: "Linter" }),
|
|
317
|
+
/* @__PURE__ */ jsx(
|
|
318
|
+
LinterForm,
|
|
319
|
+
{
|
|
320
|
+
libraries: host.libraries,
|
|
321
|
+
linterRuleSet,
|
|
322
|
+
onLinterRuleSetChanged: linterRuleSetChanged
|
|
323
|
+
}
|
|
324
|
+
)
|
|
325
|
+
] });
|
|
161
326
|
};
|
|
162
327
|
|
|
163
|
-
const CompilerSettingsDialogButton = ({
|
|
164
|
-
|
|
165
|
-
|
|
328
|
+
const CompilerSettingsDialogButton = ({
|
|
329
|
+
selectedEmitter,
|
|
330
|
+
compilerOptions,
|
|
331
|
+
onCompilerOptionsChange
|
|
332
|
+
}) => {
|
|
333
|
+
const { host } = usePlaygroundContext();
|
|
334
|
+
return /* @__PURE__ */ jsxs(Dialog, { children: [
|
|
335
|
+
/* @__PURE__ */ jsx(DialogTrigger, { children: /* @__PURE__ */ jsx(ToolbarButton, { icon: /* @__PURE__ */ jsx(Settings24Regular, {}), "aria-label": "Open Settings" }) }),
|
|
336
|
+
/* @__PURE__ */ jsx(DialogSurface, { children: /* @__PURE__ */ jsxs(DialogBody, { children: [
|
|
337
|
+
/* @__PURE__ */ jsx(DialogTitle, { children: "Settings" }),
|
|
338
|
+
/* @__PURE__ */ jsx(DialogContent, { children: /* @__PURE__ */ jsx(
|
|
339
|
+
CompilerSettings,
|
|
340
|
+
{
|
|
341
|
+
host,
|
|
342
|
+
selectedEmitter,
|
|
343
|
+
options: compilerOptions,
|
|
344
|
+
onOptionsChanged: onCompilerOptionsChange
|
|
345
|
+
}
|
|
346
|
+
) })
|
|
347
|
+
] }) })
|
|
348
|
+
] });
|
|
166
349
|
};
|
|
167
350
|
|
|
168
|
-
|
|
351
|
+
const bar = "_bar_15c2c_1";
|
|
352
|
+
const divider = "_divider_15c2c_5";
|
|
353
|
+
const spacer = "_spacer_15c2c_9";
|
|
354
|
+
const style$8 = {
|
|
355
|
+
bar: bar,
|
|
356
|
+
divider: divider,
|
|
357
|
+
spacer: spacer
|
|
358
|
+
};
|
|
169
359
|
|
|
170
|
-
const EditorCommandBar = ({
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
360
|
+
const EditorCommandBar = ({
|
|
361
|
+
documentationUrl,
|
|
362
|
+
saveCode,
|
|
363
|
+
formatCode,
|
|
364
|
+
fileBug,
|
|
365
|
+
host,
|
|
366
|
+
selectedEmitter,
|
|
367
|
+
onSelectedEmitterChange,
|
|
368
|
+
compilerOptions,
|
|
369
|
+
onCompilerOptionsChange,
|
|
370
|
+
samples,
|
|
371
|
+
selectedSampleName,
|
|
372
|
+
onSelectedSampleNameChange
|
|
373
|
+
}) => {
|
|
374
|
+
const documentation = documentationUrl ? /* @__PURE__ */ jsx("label", { children: /* @__PURE__ */ jsx(Link, { href: documentationUrl, target: "_blank", children: "Docs" }) }) : void 0;
|
|
375
|
+
const bugButton = fileBug ? /* @__PURE__ */ jsx(FileBugButton, { onClick: fileBug }) : void 0;
|
|
376
|
+
const emitters = useMemo(
|
|
377
|
+
() => Object.values(host.libraries).filter((x) => x.isEmitter).map((x) => x.name),
|
|
378
|
+
[host.libraries]
|
|
379
|
+
);
|
|
380
|
+
return /* @__PURE__ */ jsx("div", { className: style$8["bar"], children: /* @__PURE__ */ jsxs(Toolbar, { children: [
|
|
381
|
+
/* @__PURE__ */ jsx(Tooltip, { content: "Save", relationship: "description", withArrow: true, children: /* @__PURE__ */ jsx(ToolbarButton, { "aria-label": "Save", icon: /* @__PURE__ */ jsx(Save16Regular, {}), onClick: saveCode }) }),
|
|
382
|
+
/* @__PURE__ */ jsx(Tooltip, { content: "Format", relationship: "description", withArrow: true, children: /* @__PURE__ */ jsx(ToolbarButton, { "aria-label": "Format", icon: /* @__PURE__ */ jsx(Broom16Filled, {}), onClick: formatCode }) }),
|
|
383
|
+
samples && /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
384
|
+
/* @__PURE__ */ jsx(
|
|
385
|
+
SamplesDropdown,
|
|
386
|
+
{
|
|
387
|
+
samples,
|
|
388
|
+
selectedSampleName,
|
|
389
|
+
onSelectedSampleNameChange
|
|
390
|
+
}
|
|
391
|
+
),
|
|
392
|
+
/* @__PURE__ */ jsx("div", { className: style$8["spacer"] })
|
|
393
|
+
] }),
|
|
394
|
+
/* @__PURE__ */ jsx(
|
|
395
|
+
EmitterDropdown,
|
|
396
|
+
{
|
|
397
|
+
emitters,
|
|
398
|
+
onSelectedEmitterChange,
|
|
399
|
+
selectedEmitter
|
|
400
|
+
}
|
|
401
|
+
),
|
|
402
|
+
documentation && /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
403
|
+
/* @__PURE__ */ jsx("div", { className: style$8["spacer"] }),
|
|
404
|
+
documentation
|
|
405
|
+
] }),
|
|
406
|
+
/* @__PURE__ */ jsx("div", { className: style$8["divider"] }),
|
|
407
|
+
bugButton,
|
|
408
|
+
/* @__PURE__ */ jsx(
|
|
409
|
+
CompilerSettingsDialogButton,
|
|
410
|
+
{
|
|
411
|
+
compilerOptions,
|
|
412
|
+
onCompilerOptionsChange,
|
|
413
|
+
selectedEmitter
|
|
414
|
+
}
|
|
415
|
+
)
|
|
416
|
+
] }) });
|
|
177
417
|
};
|
|
178
418
|
const FileBugButton = ({ onClick }) => {
|
|
179
|
-
|
|
419
|
+
return /* @__PURE__ */ jsx(Tooltip, { content: "File Bug Report", relationship: "description", withArrow: true, children: /* @__PURE__ */ jsx(
|
|
420
|
+
ToolbarButton,
|
|
421
|
+
{
|
|
422
|
+
appearance: "subtle",
|
|
423
|
+
"aria-label": "File Bug Report",
|
|
424
|
+
icon: /* @__PURE__ */ jsx(Bug16Regular, {}),
|
|
425
|
+
onClick
|
|
426
|
+
}
|
|
427
|
+
) });
|
|
180
428
|
};
|
|
181
429
|
|
|
182
430
|
const DefaultFooter = () => {
|
|
183
|
-
|
|
431
|
+
return /* @__PURE__ */ jsx(Footer, { children: /* @__PURE__ */ jsx(FooterVersionItem, {}) });
|
|
184
432
|
};
|
|
185
433
|
|
|
186
434
|
const Editor = ({ model, options, actions, onMount }) => {
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
435
|
+
const editorContainerRef = useRef(null);
|
|
436
|
+
const editorRef = useRef(null);
|
|
437
|
+
useEffect(() => {
|
|
438
|
+
editorRef.current = editor.create(editorContainerRef.current, {
|
|
439
|
+
model,
|
|
440
|
+
automaticLayout: true,
|
|
441
|
+
...options
|
|
442
|
+
});
|
|
443
|
+
onMount?.({ editor: editorRef.current });
|
|
444
|
+
}, []);
|
|
445
|
+
useEffect(() => {
|
|
446
|
+
editor.setTheme(options.theme ?? "typespec");
|
|
447
|
+
}, [options.theme]);
|
|
448
|
+
useEffect(() => {
|
|
449
|
+
const disposables = [];
|
|
450
|
+
for (const command of actions ?? []) {
|
|
451
|
+
disposables.push(editorRef.current.addAction(command));
|
|
452
|
+
}
|
|
453
|
+
return () => {
|
|
454
|
+
disposables.forEach((x) => x.dispose());
|
|
455
|
+
};
|
|
456
|
+
}, [actions]);
|
|
457
|
+
useEffect(() => {
|
|
458
|
+
if (editorRef.current) {
|
|
459
|
+
editorRef.current.setModel(model);
|
|
460
|
+
}
|
|
461
|
+
}, [model]);
|
|
462
|
+
return /* @__PURE__ */ jsx(
|
|
463
|
+
"div",
|
|
464
|
+
{
|
|
465
|
+
className: "monaco-editor-container",
|
|
466
|
+
style: { width: "100%", height: "100%" },
|
|
467
|
+
ref: editorContainerRef,
|
|
468
|
+
"data-tabster": '{"uncontrolled": {}}'
|
|
469
|
+
}
|
|
470
|
+
);
|
|
216
471
|
};
|
|
217
472
|
function useMonacoModel(uri, language) {
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
473
|
+
return useMemo(() => {
|
|
474
|
+
const monacoUri = Uri.parse(uri);
|
|
475
|
+
return editor.getModel(monacoUri) ?? editor.createModel("", language, monacoUri);
|
|
476
|
+
}, [uri, language]);
|
|
222
477
|
}
|
|
223
478
|
|
|
224
|
-
/**
|
|
225
|
-
* Hook to manage a value that could be either controlled or uncontrolled, such as a checked state or
|
|
226
|
-
* text box string.
|
|
227
|
-
* @param controlledValue - The controlled value passed in the props. This value will always be used if provided,
|
|
228
|
-
* and the internal state will be updated to reflect it.
|
|
229
|
-
* @param defaultUncontrolledValue - Initial value for the internal state in the uncontrolled case.
|
|
230
|
-
* @returns An array of the current value and an updater callback. Like `React.useState`, the updater
|
|
231
|
-
* callback always has the same identity, and it can take either a new value, or a function which
|
|
232
|
-
* is passed the previous value and returns the new value.
|
|
233
|
-
* @see https://reactjs.org/docs/uncontrolled-components.html
|
|
234
|
-
*/
|
|
235
479
|
function useControllableValue(controlledValue, defaultUncontrolledValue, onChange) {
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
}
|
|
259
|
-
}, []);
|
|
260
|
-
return [currentValue, setValueOrCallOnChange];
|
|
261
|
-
}
|
|
262
|
-
function useAsyncMemo(callback, defaultValue, deps) {
|
|
263
|
-
const [value, setValue] = useState(defaultValue);
|
|
264
|
-
useEffect(() => {
|
|
265
|
-
callback()
|
|
266
|
-
.then(setValue)
|
|
267
|
-
// eslint-disable-next-line no-console
|
|
268
|
-
.catch(() => console.error("Failed to load async memo"));
|
|
269
|
-
}, deps);
|
|
270
|
-
return value;
|
|
480
|
+
const [value, setValue] = useState(defaultUncontrolledValue);
|
|
481
|
+
const isControlled = useMemo(() => controlledValue !== void 0, []);
|
|
482
|
+
const currentValue = isControlled ? controlledValue : value;
|
|
483
|
+
const valueRef = useRef(currentValue);
|
|
484
|
+
const onChangeRef = useRef(onChange);
|
|
485
|
+
useEffect(() => {
|
|
486
|
+
valueRef.current = currentValue;
|
|
487
|
+
onChangeRef.current = onChange;
|
|
488
|
+
});
|
|
489
|
+
const setValueOrCallOnChange = useMemo(
|
|
490
|
+
() => (update) => {
|
|
491
|
+
const newValue = typeof update === "function" ? update(valueRef.current) : update;
|
|
492
|
+
if (onChangeRef.current) {
|
|
493
|
+
onChangeRef.current(newValue);
|
|
494
|
+
}
|
|
495
|
+
if (!isControlled) {
|
|
496
|
+
setValue(newValue);
|
|
497
|
+
}
|
|
498
|
+
},
|
|
499
|
+
[]
|
|
500
|
+
);
|
|
501
|
+
return [currentValue, setValueOrCallOnChange];
|
|
271
502
|
}
|
|
272
503
|
|
|
273
|
-
|
|
504
|
+
const TypeSpecEditor = ({
|
|
505
|
+
actions,
|
|
506
|
+
options,
|
|
507
|
+
...other
|
|
508
|
+
}) => {
|
|
509
|
+
const resolvedOptions = {
|
|
510
|
+
"semanticHighlighting.enabled": true,
|
|
511
|
+
automaticLayout: true,
|
|
512
|
+
tabSize: 2,
|
|
513
|
+
minimap: {
|
|
514
|
+
enabled: false
|
|
515
|
+
},
|
|
516
|
+
...options
|
|
517
|
+
};
|
|
518
|
+
return /* @__PURE__ */ jsx(Editor, { actions, options: resolvedOptions, ...other });
|
|
519
|
+
};
|
|
520
|
+
const OutputEditor = ({ filename, value, editorOptions }) => {
|
|
521
|
+
if (filename === "") {
|
|
522
|
+
return null;
|
|
523
|
+
}
|
|
524
|
+
const options = {
|
|
525
|
+
...editorOptions,
|
|
526
|
+
readOnly: true,
|
|
527
|
+
automaticLayout: true,
|
|
528
|
+
minimap: {
|
|
529
|
+
enabled: false
|
|
530
|
+
}
|
|
531
|
+
};
|
|
532
|
+
const model = useMonacoModel(filename);
|
|
533
|
+
model.setValue(value);
|
|
534
|
+
return /* @__PURE__ */ jsx(Editor, { model, options });
|
|
535
|
+
};
|
|
536
|
+
|
|
537
|
+
const style$7 = {
|
|
538
|
+
"file-output": "_file-output_jzw6j_1",
|
|
539
|
+
"viewer-selector": "_viewer-selector_jzw6j_5"
|
|
540
|
+
};
|
|
274
541
|
|
|
275
|
-
/**
|
|
276
|
-
* Display a file output using different viewers.
|
|
277
|
-
*/
|
|
278
542
|
const FileOutput = ({ filename, content, viewers }) => {
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
}
|
|
311
|
-
|
|
312
|
-
const match = [];
|
|
313
|
-
const unMatch = [];
|
|
314
|
-
for (const item of items) {
|
|
315
|
-
if (condition(item)) {
|
|
316
|
-
match.push(item);
|
|
317
|
-
}
|
|
318
|
-
else {
|
|
319
|
-
unMatch.push(item);
|
|
320
|
-
}
|
|
321
|
-
}
|
|
322
|
-
return [match, unMatch];
|
|
323
|
-
}
|
|
543
|
+
const resolvedViewers = useMemo(
|
|
544
|
+
() => ({
|
|
545
|
+
[RawFileViewer.key]: RawFileViewer,
|
|
546
|
+
...viewers
|
|
547
|
+
}),
|
|
548
|
+
[viewers]
|
|
549
|
+
);
|
|
550
|
+
const keys = Object.keys(resolvedViewers);
|
|
551
|
+
if (keys.length === 0) {
|
|
552
|
+
return /* @__PURE__ */ jsx(Fragment, { children: "No viewers" });
|
|
553
|
+
} else if (keys.length === 1) {
|
|
554
|
+
return resolvedViewers[keys[0]].render({ filename, content });
|
|
555
|
+
}
|
|
556
|
+
const [selected, setSelected] = useState(keys[0]);
|
|
557
|
+
const handleSelected = useCallback(
|
|
558
|
+
(_, data) => {
|
|
559
|
+
setSelected(data.value);
|
|
560
|
+
},
|
|
561
|
+
[selected]
|
|
562
|
+
);
|
|
563
|
+
const selectedRender = useMemo(() => {
|
|
564
|
+
return resolvedViewers[selected].render;
|
|
565
|
+
}, [selected, resolvedViewers]);
|
|
566
|
+
return /* @__PURE__ */ jsxs("div", { className: style$7["file-output"], children: [
|
|
567
|
+
/* @__PURE__ */ jsx("div", { className: style$7["viewer-selector"], children: /* @__PURE__ */ jsx(Select, { value: selected, onChange: handleSelected, "aria-label": "Select viewer", children: Object.values(resolvedViewers).map(({ key, label }) => /* @__PURE__ */ jsx("option", { value: key, children: label }, key)) }) }),
|
|
568
|
+
selectedRender && selectedRender({ filename, content })
|
|
569
|
+
] });
|
|
570
|
+
};
|
|
571
|
+
const RawFileViewer = {
|
|
572
|
+
key: "raw",
|
|
573
|
+
label: "File",
|
|
574
|
+
render: ({ filename, content }) => /* @__PURE__ */ jsx(OutputEditor, { filename, value: content })
|
|
575
|
+
};
|
|
324
576
|
|
|
325
|
-
const
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
},
|
|
333
|
-
...options,
|
|
334
|
-
};
|
|
335
|
-
return jsx(Editor, { actions: actions, options: resolvedOptions, ...other });
|
|
577
|
+
const tabs = "_tabs_1x6x2_1";
|
|
578
|
+
const tab = "_tab_1x6x2_1";
|
|
579
|
+
const style$6 = {
|
|
580
|
+
tabs: tabs,
|
|
581
|
+
"tab-divider": "_tab-divider_1x6x2_7",
|
|
582
|
+
tab: tab,
|
|
583
|
+
"tab--selected": "_tab--selected_1x6x2_18"
|
|
336
584
|
};
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
585
|
+
|
|
586
|
+
const OutputTabs = ({
|
|
587
|
+
filenames,
|
|
588
|
+
selected,
|
|
589
|
+
onSelect
|
|
590
|
+
}) => {
|
|
591
|
+
const onTabSelect = useCallback(
|
|
592
|
+
(event, data) => {
|
|
593
|
+
onSelect(data.value);
|
|
594
|
+
},
|
|
595
|
+
[onSelect]
|
|
596
|
+
);
|
|
597
|
+
return /* @__PURE__ */ jsx(TabList, { selectedValue: selected, onTabSelect, className: style$6["tabs"], children: filenames.map((filename) => {
|
|
598
|
+
return /* @__PURE__ */ jsx(
|
|
599
|
+
Tab,
|
|
600
|
+
{
|
|
601
|
+
value: filename,
|
|
602
|
+
className: mergeClasses(style$6["tab"], filename === selected && style$6["tab--selected"]),
|
|
603
|
+
children: filename
|
|
604
|
+
},
|
|
605
|
+
filename
|
|
606
|
+
);
|
|
607
|
+
}) });
|
|
352
608
|
};
|
|
353
609
|
|
|
354
|
-
|
|
610
|
+
const style$5 = {
|
|
611
|
+
"output-view": "_output-view_18pnu_1",
|
|
612
|
+
"file-viewer": "_file-viewer_18pnu_6",
|
|
613
|
+
"output-content": "_output-content_18pnu_12",
|
|
614
|
+
"file-viewer-content": "_file-viewer-content_18pnu_16",
|
|
615
|
+
"type-graph-viewer": "_type-graph-viewer_18pnu_21",
|
|
616
|
+
"viewer-tabs-container": "_viewer-tabs-container_18pnu_26"
|
|
617
|
+
};
|
|
355
618
|
|
|
356
|
-
const
|
|
357
|
-
|
|
358
|
-
|
|
619
|
+
const FileViewerComponent = ({
|
|
620
|
+
program,
|
|
621
|
+
outputFiles,
|
|
622
|
+
fileViewers
|
|
623
|
+
}) => {
|
|
624
|
+
const [filename, setFilename] = useState("");
|
|
625
|
+
const [content, setContent] = useState("");
|
|
626
|
+
useEffect(() => {
|
|
627
|
+
if (outputFiles.length > 0) {
|
|
628
|
+
const fileStillThere = outputFiles.find((x) => x === filename);
|
|
629
|
+
const newFilename = fileStillThere ?? outputFiles[0];
|
|
630
|
+
setFilename(newFilename);
|
|
631
|
+
void loadOutputFile(fileStillThere ?? outputFiles[0]);
|
|
632
|
+
} else {
|
|
633
|
+
setFilename("");
|
|
359
634
|
}
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
635
|
+
}, [program, outputFiles]);
|
|
636
|
+
async function loadOutputFile(path) {
|
|
637
|
+
const contents = await program.host.readFile("./tsp-output/" + path);
|
|
638
|
+
setContent(contents.text);
|
|
639
|
+
}
|
|
640
|
+
const handleTabSelection = useCallback(
|
|
641
|
+
(newFilename) => {
|
|
642
|
+
setFilename(newFilename);
|
|
643
|
+
void loadOutputFile(newFilename);
|
|
644
|
+
},
|
|
645
|
+
[setFilename]
|
|
646
|
+
);
|
|
647
|
+
if (outputFiles.length === 0) {
|
|
648
|
+
return /* @__PURE__ */ jsx(Fragment, { children: "No files emitted." });
|
|
649
|
+
}
|
|
650
|
+
return /* @__PURE__ */ jsxs("div", { className: style$5["file-viewer"], children: [
|
|
651
|
+
/* @__PURE__ */ jsx(OutputTabs, { filenames: outputFiles, selected: filename, onSelect: handleTabSelection }),
|
|
652
|
+
/* @__PURE__ */ jsx("div", { className: style$5["file-viewer-content"], children: /* @__PURE__ */ jsx(FileOutput, { filename, content, viewers: fileViewers }) })
|
|
653
|
+
] });
|
|
364
654
|
};
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
if (viewSelection.type === "file") {
|
|
374
|
-
if (outputFiles.length > 0) {
|
|
375
|
-
const fileStillThere = outputFiles.find((x) => x === viewSelection.filename);
|
|
376
|
-
void loadOutputFile(fileStillThere ?? outputFiles[0]);
|
|
377
|
-
}
|
|
378
|
-
else {
|
|
379
|
-
setViewSelection({ type: "file", filename: viewSelection.filename, content: "" });
|
|
380
|
-
}
|
|
381
|
-
}
|
|
382
|
-
}, [program, outputFiles]);
|
|
383
|
-
async function loadOutputFile(path) {
|
|
384
|
-
const contents = await program.host.readFile("./tsp-output/" + path);
|
|
385
|
-
setViewSelection({ type: "file", filename: path, content: contents.text });
|
|
655
|
+
function createFileViewer(fileViewers) {
|
|
656
|
+
const viewerMap = Object.fromEntries(fileViewers.map((x) => [x.key, x]));
|
|
657
|
+
return {
|
|
658
|
+
key: "file-output",
|
|
659
|
+
label: "Output explorer",
|
|
660
|
+
icon: /* @__PURE__ */ jsx(FolderListRegular, {}),
|
|
661
|
+
render: (props) => {
|
|
662
|
+
return /* @__PURE__ */ jsx(FileViewerComponent, { ...props, fileViewers: viewerMap });
|
|
386
663
|
}
|
|
387
|
-
|
|
388
|
-
const tabs = useMemo(() => {
|
|
389
|
-
return [
|
|
390
|
-
...outputFiles.map((x) => ({
|
|
391
|
-
align: "left",
|
|
392
|
-
name: x,
|
|
393
|
-
id: x,
|
|
394
|
-
})),
|
|
395
|
-
{ id: "type-graph", name: "Type Graph", align: "right" },
|
|
396
|
-
];
|
|
397
|
-
}, [outputFiles, diagnostics]);
|
|
398
|
-
const handleTabSelection = useCallback((tabId) => {
|
|
399
|
-
if (tabId === "type-graph") {
|
|
400
|
-
setViewSelection({ type: "type-graph" });
|
|
401
|
-
}
|
|
402
|
-
else {
|
|
403
|
-
void loadOutputFile(tabId);
|
|
404
|
-
}
|
|
405
|
-
}, []);
|
|
406
|
-
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 }) })] }));
|
|
407
|
-
};
|
|
408
|
-
function getRawFileViewer(editorOptions) {
|
|
409
|
-
return {
|
|
410
|
-
key: "raw",
|
|
411
|
-
label: "File",
|
|
412
|
-
render: ({ filename, content }) => (jsx(OutputEditor, { editorOptions: editorOptions, filename: filename, value: content })),
|
|
413
|
-
};
|
|
664
|
+
};
|
|
414
665
|
}
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
case "file":
|
|
419
|
-
return (jsx(FileOutput, { filename: viewSelection.filename, content: viewSelection.content, viewers: resolvedViewers }));
|
|
420
|
-
default:
|
|
421
|
-
return program && jsx(TypeGraphViewer, { program: program });
|
|
422
|
-
}
|
|
423
|
-
};
|
|
424
|
-
const TypeGraphViewer = ({ program }) => {
|
|
425
|
-
return (jsx("div", { className: style$5["type-graph-viewer"], children: jsx(ColorProvider, { colors: TypeGraphColors, children: jsx(TypeSpecProgramViewer, { program: program }) }) }));
|
|
666
|
+
|
|
667
|
+
const TypeGraphViewerComponent = ({ program }) => {
|
|
668
|
+
return /* @__PURE__ */ jsx("div", { className: style$5["type-graph-viewer"], children: /* @__PURE__ */ jsx(ColorProvider, { colors: TypeGraphColors, children: /* @__PURE__ */ jsx(TypeSpecProgramViewer, { program }) }) });
|
|
426
669
|
};
|
|
427
670
|
const TypeGraphColors = {
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
671
|
+
background: tokens.colorNeutralBackground1,
|
|
672
|
+
typeKind: tokens.colorPaletteBerryForeground2,
|
|
673
|
+
typeName: tokens.colorNeutralForeground2,
|
|
674
|
+
dataKey: tokens.colorNeutralForeground2,
|
|
675
|
+
ref: tokens.colorBrandForeground1,
|
|
676
|
+
literal: tokens.colorPaletteLightGreenForeground2,
|
|
677
|
+
indentationGuide: tokens.colorNeutralForeground4,
|
|
678
|
+
property: tokens.colorPaletteMarigoldForeground2
|
|
679
|
+
};
|
|
680
|
+
const TypeGraphViewer = {
|
|
681
|
+
key: "type-graph",
|
|
682
|
+
label: "Type graph",
|
|
683
|
+
icon: /* @__PURE__ */ jsx(DataLineRegular, {}),
|
|
684
|
+
render: TypeGraphViewerComponent
|
|
436
685
|
};
|
|
437
686
|
|
|
438
|
-
|
|
687
|
+
const OutputView = ({
|
|
688
|
+
compilationState,
|
|
689
|
+
viewers,
|
|
690
|
+
fileViewers,
|
|
691
|
+
editorOptions
|
|
692
|
+
}) => {
|
|
693
|
+
if (compilationState === void 0) {
|
|
694
|
+
return /* @__PURE__ */ jsx(Fragment, {});
|
|
695
|
+
}
|
|
696
|
+
if ("internalCompilerError" in compilationState) {
|
|
697
|
+
return /* @__PURE__ */ jsx(Fragment, {});
|
|
698
|
+
}
|
|
699
|
+
const resolvedViewers = useMemo(() => resolveViewers(viewers, fileViewers), [viewers]);
|
|
700
|
+
return /* @__PURE__ */ jsx(
|
|
701
|
+
OutputViewInternal,
|
|
702
|
+
{
|
|
703
|
+
compilationResult: compilationState,
|
|
704
|
+
viewers: resolvedViewers,
|
|
705
|
+
editorOptions
|
|
706
|
+
}
|
|
707
|
+
);
|
|
708
|
+
};
|
|
709
|
+
function resolveViewers(viewers, fileViewers) {
|
|
710
|
+
const fileViewer = createFileViewer(fileViewers ?? []);
|
|
711
|
+
const output = {
|
|
712
|
+
programViewers: {
|
|
713
|
+
[fileViewer.key]: fileViewer,
|
|
714
|
+
[TypeGraphViewer.key]: TypeGraphViewer
|
|
715
|
+
}
|
|
716
|
+
};
|
|
717
|
+
for (const item of viewers ?? []) {
|
|
718
|
+
output.programViewers[item.key] = item;
|
|
719
|
+
}
|
|
720
|
+
return output;
|
|
721
|
+
}
|
|
722
|
+
const OutputViewInternal = ({ compilationResult, viewers, editorOptions }) => {
|
|
723
|
+
const viewerList = Object.values(viewers.programViewers);
|
|
724
|
+
const [selected, setSelected] = useState(viewerList[0].key);
|
|
725
|
+
const onTabSelect = useCallback(
|
|
726
|
+
(_, data) => setSelected(data.value),
|
|
727
|
+
[setSelected]
|
|
728
|
+
);
|
|
729
|
+
const viewer = useMemo(() => {
|
|
730
|
+
return viewers.programViewers[selected];
|
|
731
|
+
}, [viewers.programViewers, selected]);
|
|
732
|
+
return /* @__PURE__ */ jsxs("div", { className: style$5["output-view"], children: [
|
|
733
|
+
/* @__PURE__ */ jsx("div", { className: style$5["output-content"], children: /* @__PURE__ */ jsx(
|
|
734
|
+
viewer.render,
|
|
735
|
+
{
|
|
736
|
+
program: compilationResult.program,
|
|
737
|
+
outputFiles: compilationResult.outputFiles
|
|
738
|
+
}
|
|
739
|
+
) }),
|
|
740
|
+
/* @__PURE__ */ jsx("div", { className: style$5["viewer-tabs-container"], children: /* @__PURE__ */ jsx(
|
|
741
|
+
TabList,
|
|
742
|
+
{
|
|
743
|
+
vertical: true,
|
|
744
|
+
size: "large",
|
|
745
|
+
selectedValue: selected,
|
|
746
|
+
onTabSelect,
|
|
747
|
+
className: style$5["viewer-tabs"],
|
|
748
|
+
children: viewerList.map((viewer2) => {
|
|
749
|
+
return /* @__PURE__ */ jsx(Tab, { value: viewer2.key, className: style$5["viewer-tab"], children: /* @__PURE__ */ jsx("span", { title: viewer2.label, children: viewer2.icon }) }, viewer2.key);
|
|
750
|
+
})
|
|
751
|
+
}
|
|
752
|
+
) })
|
|
753
|
+
] });
|
|
754
|
+
};
|
|
439
755
|
|
|
440
|
-
|
|
756
|
+
const layout = "_layout_l03ni_1";
|
|
757
|
+
const style$4 = {
|
|
758
|
+
layout: layout,
|
|
759
|
+
"edit-pane": "_edit-pane_l03ni_9"
|
|
760
|
+
};
|
|
441
761
|
|
|
442
|
-
const
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
762
|
+
const list = "_list_wrnwm_1";
|
|
763
|
+
const item = "_item_wrnwm_4";
|
|
764
|
+
const style$3 = {
|
|
765
|
+
list: list,
|
|
766
|
+
item: item,
|
|
767
|
+
"item--error": "_item--error_wrnwm_15",
|
|
768
|
+
"item--warning": "_item--warning_wrnwm_19",
|
|
769
|
+
"item-code": "_item-code_wrnwm_23",
|
|
770
|
+
"item-loc": "_item-loc_wrnwm_27"
|
|
771
|
+
};
|
|
772
|
+
|
|
773
|
+
const DiagnosticList = ({
|
|
774
|
+
diagnostics,
|
|
775
|
+
onDiagnosticSelected
|
|
776
|
+
}) => {
|
|
777
|
+
if (diagnostics.length === 0) {
|
|
778
|
+
return /* @__PURE__ */ jsx("div", { className: style$3["list"], children: "No errors" });
|
|
779
|
+
}
|
|
780
|
+
const handleItemSelected = useCallback(
|
|
781
|
+
(diagnostic) => {
|
|
782
|
+
onDiagnosticSelected?.(diagnostic);
|
|
783
|
+
},
|
|
784
|
+
[onDiagnosticSelected]
|
|
785
|
+
);
|
|
786
|
+
return /* @__PURE__ */ jsx("div", { className: style$3["list"], children: diagnostics.map((x, i) => {
|
|
787
|
+
return /* @__PURE__ */ jsx(DiagnosticItem, { diagnostic: x, onItemSelected: handleItemSelected }, i);
|
|
788
|
+
}) });
|
|
452
789
|
};
|
|
453
790
|
const DiagnosticItem = ({ diagnostic, onItemSelected }) => {
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
791
|
+
const handleClick = useCallback(() => {
|
|
792
|
+
onItemSelected(diagnostic);
|
|
793
|
+
}, [diagnostic, onItemSelected]);
|
|
794
|
+
return /* @__PURE__ */ jsxs("div", { tabIndex: 0, className: style$3["item"], onClick: handleClick, children: [
|
|
795
|
+
/* @__PURE__ */ jsx(
|
|
796
|
+
"div",
|
|
797
|
+
{
|
|
798
|
+
className: mergeClasses(
|
|
799
|
+
(style$3[diagnostic.severity === "error" ? "item--error" : "item--warning"])
|
|
800
|
+
),
|
|
801
|
+
children: diagnostic.severity
|
|
802
|
+
}
|
|
803
|
+
),
|
|
804
|
+
/* @__PURE__ */ jsx("div", { className: style$3["item-code"], children: diagnostic.code }),
|
|
805
|
+
/* @__PURE__ */ jsx("div", { className: style$3["item-message"], children: diagnostic.message }),
|
|
806
|
+
/* @__PURE__ */ jsx("div", { className: style$3["item-loc"], children: /* @__PURE__ */ jsx(DiagnosticTargetLink, { target: diagnostic.target }) })
|
|
807
|
+
] });
|
|
459
808
|
};
|
|
460
809
|
const DiagnosticTargetLink = memo(({ target }) => {
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
810
|
+
if (typeof target === "symbol") {
|
|
811
|
+
return /* @__PURE__ */ jsx("span", {});
|
|
812
|
+
}
|
|
813
|
+
const location = getSourceLocation(target);
|
|
814
|
+
const file = location.file.path === "/test/main.tsp" ? "" : `${location.file.path}:`;
|
|
815
|
+
const { line, character } = location.file.getLineAndCharacterOfPosition(location.pos);
|
|
816
|
+
return /* @__PURE__ */ jsxs("span", { children: [
|
|
817
|
+
file,
|
|
818
|
+
line + 1,
|
|
819
|
+
":",
|
|
820
|
+
character + 1
|
|
821
|
+
] });
|
|
468
822
|
});
|
|
469
823
|
|
|
470
|
-
|
|
824
|
+
const header = "_header_1qhql_1";
|
|
825
|
+
const style$2 = {
|
|
826
|
+
header: header,
|
|
827
|
+
"header--error": "_header--error_1qhql_12",
|
|
828
|
+
"error-icon": "_error-icon_1qhql_17",
|
|
829
|
+
"header--warning": "_header--warning_1qhql_21",
|
|
830
|
+
"warning-icon": "_warning-icon_1qhql_26",
|
|
831
|
+
"header-content": "_header-content_1qhql_30",
|
|
832
|
+
"header-chevron": "_header-chevron_1qhql_36",
|
|
833
|
+
"header-chevron--collapsed": "_header-chevron--collapsed_1qhql_39"
|
|
834
|
+
};
|
|
471
835
|
|
|
472
836
|
const ProblemPaneHeader = memo(({ compilationState, ...props }) => {
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
837
|
+
const noProblem = /* @__PURE__ */ jsx(Container, { status: "none", ...props, children: "No problems" });
|
|
838
|
+
if (compilationState === void 0) {
|
|
839
|
+
return noProblem;
|
|
840
|
+
}
|
|
841
|
+
if ("internalCompilerError" in compilationState) {
|
|
842
|
+
return /* @__PURE__ */ jsxs(Container, { status: "error", ...props, children: [
|
|
843
|
+
/* @__PURE__ */ jsx(ErrorCircle16Filled, {}),
|
|
844
|
+
" Internal Compiler Error"
|
|
845
|
+
] });
|
|
846
|
+
}
|
|
847
|
+
const diagnostics = compilationState.program.diagnostics;
|
|
848
|
+
if (diagnostics.length === 0) {
|
|
849
|
+
return noProblem;
|
|
850
|
+
}
|
|
851
|
+
const errors = diagnostics.filter((x) => x.severity === "error");
|
|
852
|
+
const warnings = diagnostics.filter((x) => x.severity === "warning");
|
|
853
|
+
return /* @__PURE__ */ jsxs(Container, { status: errors.length > 0 ? "error" : "warning", ...props, children: [
|
|
854
|
+
errors.length > 0 ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
855
|
+
/* @__PURE__ */ jsx(ErrorCircle16Filled, { className: style$2["error-icon"] }),
|
|
856
|
+
" ",
|
|
857
|
+
errors.length,
|
|
858
|
+
" errors"
|
|
859
|
+
] }) : null,
|
|
860
|
+
warnings.length > 0 ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
861
|
+
/* @__PURE__ */ jsx(Warning16Filled, { className: style$2["warning-icon"] }),
|
|
862
|
+
" ",
|
|
863
|
+
warnings.length,
|
|
864
|
+
" warnings"
|
|
865
|
+
] }) : null
|
|
866
|
+
] });
|
|
487
867
|
});
|
|
488
868
|
const Container = ({ children, className, status, onClick, collaped }) => {
|
|
489
|
-
|
|
869
|
+
return /* @__PURE__ */ jsxs(
|
|
870
|
+
"div",
|
|
871
|
+
{
|
|
872
|
+
tabIndex: onClick === void 0 ? void 0 : 0,
|
|
873
|
+
className: mergeClasses(
|
|
874
|
+
style$2["header"],
|
|
875
|
+
status === "error" && style$2["header--error"],
|
|
876
|
+
status === "warning" && style$2["header--warning"],
|
|
877
|
+
className
|
|
878
|
+
),
|
|
879
|
+
onClick,
|
|
880
|
+
children: [
|
|
881
|
+
/* @__PURE__ */ jsx("div", { className: style$2["header-content"], children }),
|
|
882
|
+
/* @__PURE__ */ jsx(
|
|
883
|
+
ChevronDown16Regular,
|
|
884
|
+
{
|
|
885
|
+
className: mergeClasses(
|
|
886
|
+
style$2["header-chevron"],
|
|
887
|
+
collaped && style$2["header-chevron--collapsed"]
|
|
888
|
+
)
|
|
889
|
+
}
|
|
890
|
+
)
|
|
891
|
+
]
|
|
892
|
+
}
|
|
893
|
+
);
|
|
490
894
|
};
|
|
491
895
|
|
|
492
|
-
|
|
896
|
+
const style$1 = {
|
|
897
|
+
"problem-pane": "_problem-pane_kxgwp_1",
|
|
898
|
+
"problem-content": "_problem-content_kxgwp_9",
|
|
899
|
+
"no-problems": "_no-problems_kxgwp_12",
|
|
900
|
+
"internal-compiler-error": "_internal-compiler-error_kxgwp_16"
|
|
901
|
+
};
|
|
493
902
|
|
|
494
|
-
const ProblemPane = ({
|
|
495
|
-
|
|
903
|
+
const ProblemPane = ({
|
|
904
|
+
collapsed,
|
|
905
|
+
compilationState,
|
|
906
|
+
onHeaderClick,
|
|
907
|
+
onDiagnosticSelected
|
|
908
|
+
}) => {
|
|
909
|
+
return /* @__PURE__ */ jsxs("div", { className: style$1["problem-pane"], children: [
|
|
910
|
+
/* @__PURE__ */ jsx(
|
|
911
|
+
ProblemPaneHeader,
|
|
912
|
+
{
|
|
913
|
+
compilationState,
|
|
914
|
+
onClick: onHeaderClick,
|
|
915
|
+
collaped: collapsed
|
|
916
|
+
}
|
|
917
|
+
),
|
|
918
|
+
/* @__PURE__ */ jsx("div", { className: style$1["problem-content"], "aria-hidden": collapsed, children: /* @__PURE__ */ jsx(
|
|
919
|
+
ProblemPaneContent,
|
|
920
|
+
{
|
|
921
|
+
compilationState,
|
|
922
|
+
onDiagnosticSelected
|
|
923
|
+
}
|
|
924
|
+
) })
|
|
925
|
+
] });
|
|
496
926
|
};
|
|
497
|
-
const ProblemPaneContent = ({
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
return
|
|
927
|
+
const ProblemPaneContent = ({
|
|
928
|
+
compilationState,
|
|
929
|
+
onDiagnosticSelected
|
|
930
|
+
}) => {
|
|
931
|
+
if (compilationState === void 0) {
|
|
932
|
+
return /* @__PURE__ */ jsx(Fragment, {});
|
|
933
|
+
}
|
|
934
|
+
if ("internalCompilerError" in compilationState) {
|
|
935
|
+
return /* @__PURE__ */ jsx("pre", { className: style$1["internal-compiler-error"], children: String(compilationState.internalCompilerError) });
|
|
936
|
+
}
|
|
937
|
+
const diagnostics = compilationState.program.diagnostics;
|
|
938
|
+
return diagnostics.length === 0 ? /* @__PURE__ */ jsx("div", { className: style$1["no-problems"], children: " No problems" }) : /* @__PURE__ */ jsx(DiagnosticList, { diagnostics, onDiagnosticSelected });
|
|
506
939
|
};
|
|
507
940
|
|
|
508
|
-
function Pane({
|
|
509
|
-
|
|
941
|
+
function Pane({
|
|
942
|
+
children,
|
|
943
|
+
...props
|
|
944
|
+
}) {
|
|
945
|
+
return /* @__PURE__ */ jsx("div", { ...props, children });
|
|
510
946
|
}
|
|
511
947
|
|
|
512
|
-
|
|
948
|
+
const sash = "_sash_v2eo6_20";
|
|
949
|
+
const pane = "_pane_v2eo6_70";
|
|
950
|
+
const style = {
|
|
951
|
+
"split-pane": "_split-pane_v2eo6_1",
|
|
952
|
+
"split-disabled": "_split-disabled_v2eo6_8",
|
|
953
|
+
"split-pane-dragging": "_split-pane-dragging_v2eo6_12",
|
|
954
|
+
"react-split-vertical": "_react-split-vertical_v2eo6_12",
|
|
955
|
+
"react-split-horizontal": "_react-split-horizontal_v2eo6_16",
|
|
956
|
+
sash: sash,
|
|
957
|
+
"sash-disabled": "_sash-disabled_v2eo6_29",
|
|
958
|
+
"sash-vertical": "_sash-vertical_v2eo6_33",
|
|
959
|
+
"sash-horizontal": "_sash-horizontal_v2eo6_37",
|
|
960
|
+
"sash-content": "_sash-content_v2eo6_41",
|
|
961
|
+
"sash-content-dragging": "_sash-content-dragging_v2eo6_47",
|
|
962
|
+
pane: pane
|
|
963
|
+
};
|
|
513
964
|
|
|
514
|
-
const SashContent = ({
|
|
515
|
-
|
|
965
|
+
const SashContent = ({
|
|
966
|
+
className,
|
|
967
|
+
children,
|
|
968
|
+
dragging,
|
|
969
|
+
...others
|
|
970
|
+
}) => {
|
|
971
|
+
return /* @__PURE__ */ jsx(
|
|
972
|
+
"div",
|
|
973
|
+
{
|
|
974
|
+
className: mergeClasses(
|
|
975
|
+
style["sash-content"],
|
|
976
|
+
dragging && style["sash-content-dragging"],
|
|
977
|
+
className
|
|
978
|
+
),
|
|
979
|
+
...others,
|
|
980
|
+
children
|
|
981
|
+
}
|
|
982
|
+
);
|
|
516
983
|
};
|
|
517
984
|
|
|
518
|
-
const Sash = ({
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
985
|
+
const Sash = ({
|
|
986
|
+
className,
|
|
987
|
+
render,
|
|
988
|
+
onDragStart,
|
|
989
|
+
onDragging,
|
|
990
|
+
onDragEnd,
|
|
991
|
+
onReset,
|
|
992
|
+
...others
|
|
993
|
+
}) => {
|
|
994
|
+
const [draging, setDrag] = useState(false);
|
|
995
|
+
const handleMouseMove = (e) => {
|
|
996
|
+
onDragging(e);
|
|
997
|
+
};
|
|
998
|
+
const handleMouseUp = (e) => {
|
|
999
|
+
setDrag(false);
|
|
1000
|
+
onDragEnd(e);
|
|
1001
|
+
window.removeEventListener("mousemove", handleMouseMove);
|
|
1002
|
+
window.removeEventListener("mouseup", handleMouseUp);
|
|
1003
|
+
};
|
|
1004
|
+
return /* @__PURE__ */ jsx(
|
|
1005
|
+
"div",
|
|
1006
|
+
{
|
|
1007
|
+
className: mergeClasses(style["sash"], className),
|
|
1008
|
+
onMouseDown: (e) => {
|
|
1009
|
+
setDrag(true);
|
|
1010
|
+
onDragStart(e);
|
|
1011
|
+
window.addEventListener("mousemove", handleMouseMove);
|
|
1012
|
+
window.addEventListener("mouseup", handleMouseUp);
|
|
1013
|
+
},
|
|
1014
|
+
onDoubleClick: onReset,
|
|
1015
|
+
...others,
|
|
1016
|
+
children: render(draging)
|
|
1017
|
+
}
|
|
1018
|
+
);
|
|
1019
|
+
};
|
|
1020
|
+
|
|
1021
|
+
const SplitPane = ({
|
|
1022
|
+
children,
|
|
1023
|
+
sizes: propSizes,
|
|
1024
|
+
initialSizes: defaultSizes,
|
|
1025
|
+
allowResize = true,
|
|
1026
|
+
split = "vertical",
|
|
1027
|
+
className: wrapClassName,
|
|
1028
|
+
sashRender = (_, active) => /* @__PURE__ */ jsx(SashContent, { dragging: active }),
|
|
1029
|
+
resizerSize = 4,
|
|
1030
|
+
performanceMode = false,
|
|
1031
|
+
onChange = () => null,
|
|
1032
|
+
onDragStart = () => null,
|
|
1033
|
+
onDragEnd = () => null,
|
|
1034
|
+
...others
|
|
1035
|
+
}) => {
|
|
1036
|
+
const [resolvedPropSize, updateSizes] = useControllableValue(
|
|
1037
|
+
propSizes,
|
|
1038
|
+
defaultSizes,
|
|
1039
|
+
onChange
|
|
1040
|
+
);
|
|
1041
|
+
const axis = useRef({ x: 0, y: 0 });
|
|
1042
|
+
const wrapper = useRef(null);
|
|
1043
|
+
const cacheSizes = useRef({ sizes: [], sashPosSizes: [] });
|
|
1044
|
+
const [wrapperRect, setWrapperRect] = useState({});
|
|
1045
|
+
const [isDragging, setDragging] = useState(false);
|
|
1046
|
+
useEffect(() => {
|
|
1047
|
+
const resizeObserver = new ResizeObserver(() => {
|
|
1048
|
+
setWrapperRect(wrapper?.current?.getBoundingClientRect() ?? {});
|
|
1049
|
+
});
|
|
1050
|
+
resizeObserver.observe(wrapper.current);
|
|
1051
|
+
return () => {
|
|
1052
|
+
resizeObserver.disconnect();
|
|
528
1053
|
};
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
}
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
1054
|
+
}, []);
|
|
1055
|
+
const { sizeName, splitPos, splitAxis } = useMemo(
|
|
1056
|
+
() => ({
|
|
1057
|
+
sizeName: split === "vertical" ? "width" : "height",
|
|
1058
|
+
splitPos: split === "vertical" ? "left" : "top",
|
|
1059
|
+
splitAxis: split === "vertical" ? "x" : "y"
|
|
1060
|
+
}),
|
|
1061
|
+
[split]
|
|
1062
|
+
);
|
|
1063
|
+
const wrapSize = wrapperRect[sizeName] ?? 0;
|
|
1064
|
+
const paneLimitSizes = useMemo(
|
|
1065
|
+
() => children.map((childNode) => {
|
|
1066
|
+
const limits = [0, Infinity];
|
|
1067
|
+
if (childNode?.type === Pane) {
|
|
1068
|
+
const { minSize, maxSize } = childNode.props;
|
|
1069
|
+
limits[0] = assertsSize(minSize, wrapSize, 0);
|
|
1070
|
+
limits[1] = assertsSize(maxSize, wrapSize);
|
|
1071
|
+
}
|
|
1072
|
+
return limits;
|
|
1073
|
+
}),
|
|
1074
|
+
[children, wrapSize]
|
|
1075
|
+
);
|
|
1076
|
+
const sizes = useMemo(
|
|
1077
|
+
function() {
|
|
1078
|
+
let count = 0;
|
|
1079
|
+
let curSum = 0;
|
|
1080
|
+
const res = children.map((_, index) => {
|
|
1081
|
+
const size = assertsSize(resolvedPropSize[index], wrapSize);
|
|
1082
|
+
size === Infinity ? count++ : curSum += size;
|
|
1083
|
+
return size;
|
|
1084
|
+
});
|
|
1085
|
+
if (curSum > wrapSize || !count && curSum < wrapSize) {
|
|
1086
|
+
const cacheNum = (curSum - wrapSize) / curSum;
|
|
1087
|
+
return res.map((size) => {
|
|
1088
|
+
return size === Infinity ? 0 : size - size * cacheNum;
|
|
547
1089
|
});
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
const { sizeName, splitPos, splitAxis } = useMemo(() => ({
|
|
554
|
-
sizeName: split === "vertical" ? "width" : "height",
|
|
555
|
-
splitPos: split === "vertical" ? "left" : "top",
|
|
556
|
-
splitAxis: split === "vertical" ? "x" : "y",
|
|
557
|
-
}), [split]);
|
|
558
|
-
const wrapSize = wrapperRect[sizeName] ?? 0;
|
|
559
|
-
// Get limit sizes via children
|
|
560
|
-
const paneLimitSizes = useMemo(() => children.map((childNode) => {
|
|
561
|
-
const limits = [0, Infinity];
|
|
562
|
-
if (childNode?.type === Pane) {
|
|
563
|
-
const { minSize, maxSize } = childNode.props;
|
|
564
|
-
limits[0] = assertsSize(minSize, wrapSize, 0);
|
|
565
|
-
limits[1] = assertsSize(maxSize, wrapSize);
|
|
566
|
-
}
|
|
567
|
-
return limits;
|
|
568
|
-
}), [children, wrapSize]);
|
|
569
|
-
const sizes = useMemo(function () {
|
|
570
|
-
let count = 0;
|
|
571
|
-
let curSum = 0;
|
|
572
|
-
const res = children.map((_, index) => {
|
|
573
|
-
const size = assertsSize(resolvedPropSize[index], wrapSize);
|
|
574
|
-
size === Infinity ? count++ : (curSum += size);
|
|
575
|
-
return size;
|
|
1090
|
+
}
|
|
1091
|
+
if (count > 0) {
|
|
1092
|
+
const average = (wrapSize - curSum) / count;
|
|
1093
|
+
return res.map((size) => {
|
|
1094
|
+
return size === Infinity ? average : size;
|
|
576
1095
|
});
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
}
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
1096
|
+
}
|
|
1097
|
+
return res;
|
|
1098
|
+
},
|
|
1099
|
+
[...resolvedPropSize, children.length, wrapSize]
|
|
1100
|
+
);
|
|
1101
|
+
const sashPosSizes = useMemo(
|
|
1102
|
+
() => sizes.reduce((a, b) => [...a, a[a.length - 1] + b], [0]),
|
|
1103
|
+
[...sizes]
|
|
1104
|
+
);
|
|
1105
|
+
const dragStart = useCallback(
|
|
1106
|
+
(e) => {
|
|
1107
|
+
document?.body?.classList?.add(style["split-disabled"]);
|
|
1108
|
+
axis.current = { x: e.pageX, y: e.pageY };
|
|
1109
|
+
cacheSizes.current = { sizes, sashPosSizes };
|
|
1110
|
+
setDragging(true);
|
|
1111
|
+
onDragStart(e);
|
|
1112
|
+
},
|
|
1113
|
+
[onDragStart, sizes, sashPosSizes]
|
|
1114
|
+
);
|
|
1115
|
+
const resetPosition = useCallback(() => {
|
|
1116
|
+
if (defaultSizes) {
|
|
1117
|
+
updateSizes(defaultSizes);
|
|
1118
|
+
}
|
|
1119
|
+
}, [defaultSizes, updateSizes]);
|
|
1120
|
+
const dragEnd = useCallback(
|
|
1121
|
+
(e) => {
|
|
1122
|
+
document?.body?.classList?.remove(style["split-disabled"]);
|
|
1123
|
+
axis.current = { x: e.pageX, y: e.pageY };
|
|
1124
|
+
cacheSizes.current = { sizes, sashPosSizes };
|
|
1125
|
+
setDragging(false);
|
|
1126
|
+
onDragEnd(e);
|
|
1127
|
+
},
|
|
1128
|
+
[onDragEnd, sizes, sashPosSizes]
|
|
1129
|
+
);
|
|
1130
|
+
const onDragging = useCallback(
|
|
1131
|
+
function(e, i) {
|
|
1132
|
+
const curAxis = { x: e.pageX, y: e.pageY };
|
|
1133
|
+
let distanceX = curAxis[splitAxis] - axis.current[splitAxis];
|
|
1134
|
+
const leftBorder = -Math.min(
|
|
1135
|
+
sizes[i] - paneLimitSizes[i][0],
|
|
1136
|
+
paneLimitSizes[i + 1][1] - sizes[i + 1]
|
|
1137
|
+
);
|
|
1138
|
+
const rightBorder = Math.min(
|
|
1139
|
+
sizes[i + 1] - paneLimitSizes[i + 1][0],
|
|
1140
|
+
paneLimitSizes[i][1] - sizes[i]
|
|
1141
|
+
);
|
|
1142
|
+
if (distanceX < leftBorder) {
|
|
1143
|
+
distanceX = leftBorder;
|
|
1144
|
+
}
|
|
1145
|
+
if (distanceX > rightBorder) {
|
|
1146
|
+
distanceX = rightBorder;
|
|
1147
|
+
}
|
|
1148
|
+
const nextSizes = [...sizes];
|
|
1149
|
+
nextSizes[i] += distanceX;
|
|
1150
|
+
nextSizes[i + 1] -= distanceX;
|
|
1151
|
+
updateSizes(nextSizes);
|
|
1152
|
+
},
|
|
1153
|
+
[paneLimitSizes, onChange]
|
|
1154
|
+
);
|
|
1155
|
+
const paneFollow = !(performanceMode && isDragging);
|
|
1156
|
+
const paneSizes = paneFollow ? sizes : cacheSizes.current.sizes;
|
|
1157
|
+
const panePoses = paneFollow ? sashPosSizes : cacheSizes.current.sashPosSizes;
|
|
1158
|
+
return /* @__PURE__ */ jsxs(
|
|
1159
|
+
"div",
|
|
1160
|
+
{
|
|
1161
|
+
className: mergeClasses(
|
|
1162
|
+
style["split-pane"],
|
|
1163
|
+
split === "vertical" && style["split-pane-vertical"],
|
|
1164
|
+
split === "horizontal" && style["split-pane-horizontal"],
|
|
1165
|
+
isDragging && style["split-pane-dragging"],
|
|
1166
|
+
wrapClassName
|
|
1167
|
+
),
|
|
1168
|
+
ref: wrapper,
|
|
1169
|
+
...others,
|
|
1170
|
+
children: [
|
|
1171
|
+
children.map((childNode, childIndex) => {
|
|
1172
|
+
const isPane = childNode.type === Pane;
|
|
1173
|
+
const paneProps = isPane ? childNode.props : {};
|
|
1174
|
+
return /* @__PURE__ */ jsx(
|
|
1175
|
+
Pane,
|
|
1176
|
+
{
|
|
1177
|
+
className: mergeClasses(style["pane"], paneProps.className),
|
|
1178
|
+
style: {
|
|
1179
|
+
...paneProps.style,
|
|
1180
|
+
[sizeName]: paneSizes[childIndex],
|
|
1181
|
+
[splitPos]: panePoses[childIndex]
|
|
1182
|
+
},
|
|
1183
|
+
children: isPane ? paneProps.children : childNode
|
|
1184
|
+
},
|
|
1185
|
+
childIndex
|
|
1186
|
+
);
|
|
1187
|
+
}),
|
|
1188
|
+
sashPosSizes.slice(1, -1).map((posSize, index) => /* @__PURE__ */ jsx(
|
|
1189
|
+
Sash,
|
|
1190
|
+
{
|
|
1191
|
+
className: mergeClasses(
|
|
1192
|
+
!allowResize && style["sash-disabled"],
|
|
1193
|
+
split === "vertical" ? style["sash-vertical"] : style["sash-horizontal"]
|
|
1194
|
+
),
|
|
1195
|
+
style: {
|
|
1196
|
+
[sizeName]: resizerSize,
|
|
1197
|
+
[splitPos]: posSize - resizerSize / 2
|
|
1198
|
+
},
|
|
1199
|
+
render: sashRender.bind(null, index),
|
|
1200
|
+
onReset: resetPosition,
|
|
1201
|
+
onDragStart: dragStart,
|
|
1202
|
+
onDragging: (e) => onDragging(e, index),
|
|
1203
|
+
onDragEnd: dragEnd
|
|
1204
|
+
},
|
|
1205
|
+
index
|
|
1206
|
+
))
|
|
1207
|
+
]
|
|
1208
|
+
}
|
|
1209
|
+
);
|
|
1210
|
+
};
|
|
653
1211
|
function assertsSize(size, sum, defaultValue = Infinity) {
|
|
654
|
-
|
|
655
|
-
return defaultValue;
|
|
656
|
-
if (typeof size === "number")
|
|
657
|
-
return size;
|
|
658
|
-
if (size.endsWith("%"))
|
|
659
|
-
return sum * (+size.replace("%", "") / 100);
|
|
660
|
-
if (size.endsWith("px"))
|
|
661
|
-
return +size.replace("px", "");
|
|
1212
|
+
if (typeof size === "undefined")
|
|
662
1213
|
return defaultValue;
|
|
1214
|
+
if (typeof size === "number")
|
|
1215
|
+
return size;
|
|
1216
|
+
if (size.endsWith("%"))
|
|
1217
|
+
return sum * (+size.replace("%", "") / 100);
|
|
1218
|
+
if (size.endsWith("px"))
|
|
1219
|
+
return +size.replace("px", "");
|
|
1220
|
+
return defaultValue;
|
|
663
1221
|
}
|
|
664
1222
|
|
|
665
1223
|
const Playground = (props) => {
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
1224
|
+
const { host, onSave } = props;
|
|
1225
|
+
const editorRef = useRef(void 0);
|
|
1226
|
+
const [selectedEmitter, onSelectedEmitterChange] = useControllableValue(
|
|
1227
|
+
props.emitter,
|
|
1228
|
+
props.defaultEmitter,
|
|
1229
|
+
props.onEmitterChange
|
|
1230
|
+
);
|
|
1231
|
+
const [compilerOptions, onCompilerOptionsChange] = useControllableValue(
|
|
1232
|
+
props.compilerOptions,
|
|
1233
|
+
props.defaultCompilerOptions ?? {},
|
|
1234
|
+
props.onCompilerOptionsChange
|
|
1235
|
+
);
|
|
1236
|
+
const [selectedSampleName, onSelectedSampleNameChange] = useControllableValue(
|
|
1237
|
+
props.sampleName,
|
|
1238
|
+
props.defaultSampleName,
|
|
1239
|
+
props.onSampleNameChange
|
|
1240
|
+
);
|
|
1241
|
+
const [content, setContent] = useState(props.defaultContent);
|
|
1242
|
+
const isSampleUntouched = useMemo(() => {
|
|
1243
|
+
return Boolean(selectedSampleName && content === props.samples?.[selectedSampleName]?.content);
|
|
1244
|
+
}, [content, selectedSampleName, props.samples]);
|
|
1245
|
+
const typespecModel = useMonacoModel("inmemory://test/main.tsp", "typespec");
|
|
1246
|
+
const [compilationState, setCompilationState] = useState(void 0);
|
|
1247
|
+
const doCompile = useCallback(async () => {
|
|
1248
|
+
const content2 = typespecModel.getValue();
|
|
1249
|
+
setContent(content2);
|
|
1250
|
+
const typespecCompiler = host.compiler;
|
|
1251
|
+
const state = await compile(host, content2, selectedEmitter, compilerOptions);
|
|
1252
|
+
setCompilationState(state);
|
|
1253
|
+
if ("program" in state) {
|
|
1254
|
+
const markers = state.program.diagnostics.map((diag) => ({
|
|
1255
|
+
...getMonacoRange(typespecCompiler, diag.target),
|
|
1256
|
+
message: diag.message,
|
|
1257
|
+
severity: diag.severity === "error" ? MarkerSeverity.Error : MarkerSeverity.Warning,
|
|
1258
|
+
tags: diag.code === "deprecated" ? [CompletionItemTag.Deprecated] : void 0
|
|
1259
|
+
}));
|
|
1260
|
+
editor.setModelMarkers(typespecModel, "owner", markers ?? []);
|
|
1261
|
+
} else {
|
|
1262
|
+
editor.setModelMarkers(typespecModel, "owner", []);
|
|
1263
|
+
}
|
|
1264
|
+
}, [host, selectedEmitter, compilerOptions, typespecModel, setContent]);
|
|
1265
|
+
const updateTypeSpec = useCallback(
|
|
1266
|
+
(value) => {
|
|
1267
|
+
if (typespecModel.getValue() !== value) {
|
|
1268
|
+
typespecModel.setValue(value);
|
|
1269
|
+
}
|
|
1270
|
+
},
|
|
1271
|
+
[typespecModel]
|
|
1272
|
+
);
|
|
1273
|
+
useEffect(() => {
|
|
1274
|
+
updateTypeSpec(props.defaultContent ?? "");
|
|
1275
|
+
}, []);
|
|
1276
|
+
useEffect(() => {
|
|
1277
|
+
if (selectedSampleName && props.samples) {
|
|
1278
|
+
const config = props.samples[selectedSampleName];
|
|
1279
|
+
if (config.content) {
|
|
1280
|
+
updateTypeSpec(config.content);
|
|
1281
|
+
if (config.preferredEmitter) {
|
|
1282
|
+
onSelectedEmitterChange(config.preferredEmitter);
|
|
694
1283
|
}
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
if (typespecModel.getValue() !== value) {
|
|
698
|
-
typespecModel.setValue(value);
|
|
1284
|
+
if (config.compilerOptions) {
|
|
1285
|
+
onCompilerOptionsChange(config.compilerOptions);
|
|
699
1286
|
}
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
1287
|
+
}
|
|
1288
|
+
}
|
|
1289
|
+
}, [updateTypeSpec, selectedSampleName]);
|
|
1290
|
+
useEffect(() => {
|
|
1291
|
+
const debouncer = debounce(() => doCompile(), 200);
|
|
1292
|
+
const disposable = typespecModel.onDidChangeContent(debouncer);
|
|
1293
|
+
return () => {
|
|
1294
|
+
debouncer.clear();
|
|
1295
|
+
disposable.dispose();
|
|
1296
|
+
};
|
|
1297
|
+
}, [typespecModel, doCompile]);
|
|
1298
|
+
useEffect(() => {
|
|
1299
|
+
void doCompile();
|
|
1300
|
+
}, [doCompile]);
|
|
1301
|
+
const saveCode = useCallback(() => {
|
|
1302
|
+
if (onSave) {
|
|
1303
|
+
onSave({
|
|
1304
|
+
content: typespecModel.getValue(),
|
|
1305
|
+
emitter: selectedEmitter,
|
|
1306
|
+
options: compilerOptions,
|
|
1307
|
+
sampleName: isSampleUntouched ? selectedSampleName : void 0
|
|
1308
|
+
});
|
|
1309
|
+
}
|
|
1310
|
+
}, [
|
|
1311
|
+
typespecModel,
|
|
1312
|
+
onSave,
|
|
1313
|
+
selectedEmitter,
|
|
1314
|
+
compilerOptions,
|
|
1315
|
+
selectedSampleName,
|
|
1316
|
+
isSampleUntouched
|
|
1317
|
+
]);
|
|
1318
|
+
const formatCode = useCallback(() => {
|
|
1319
|
+
void editorRef.current?.getAction("editor.action.formatDocument")?.run();
|
|
1320
|
+
}, [typespecModel]);
|
|
1321
|
+
const fileBug = useCallback(async () => {
|
|
1322
|
+
if (props.onFileBug) {
|
|
1323
|
+
saveCode();
|
|
1324
|
+
props.onFileBug();
|
|
1325
|
+
}
|
|
1326
|
+
}, [saveCode, typespecModel, props.onFileBug]);
|
|
1327
|
+
const typespecEditorActions = useMemo(
|
|
1328
|
+
() => [
|
|
1329
|
+
// ctrl/cmd+S => save
|
|
1330
|
+
{ id: "save", label: "Save", keybindings: [KeyMod.CtrlCmd | KeyCode.KeyS], run: saveCode }
|
|
1331
|
+
],
|
|
1332
|
+
[saveCode]
|
|
1333
|
+
);
|
|
1334
|
+
const onTypeSpecEditorMount = useCallback(({ editor: editor2 }) => {
|
|
1335
|
+
editorRef.current = editor2;
|
|
1336
|
+
}, []);
|
|
1337
|
+
const [verticalPaneSizes, setVerticalPaneSizes] = useState(
|
|
1338
|
+
verticalPaneSizesConst.collapsed
|
|
1339
|
+
);
|
|
1340
|
+
const toggleProblemPane = useCallback(() => {
|
|
1341
|
+
setVerticalPaneSizes((value) => {
|
|
1342
|
+
return value === verticalPaneSizesConst.collapsed ? verticalPaneSizesConst.expanded : verticalPaneSizesConst.collapsed;
|
|
1343
|
+
});
|
|
1344
|
+
}, [setVerticalPaneSizes]);
|
|
1345
|
+
const onVerticalPaneSizeChange = useCallback(
|
|
1346
|
+
(sizes) => {
|
|
1347
|
+
setVerticalPaneSizes(sizes);
|
|
1348
|
+
},
|
|
1349
|
+
[setVerticalPaneSizes]
|
|
1350
|
+
);
|
|
1351
|
+
const handleDiagnosticSelected = useCallback(
|
|
1352
|
+
(diagnostic) => {
|
|
1353
|
+
editorRef.current?.setSelection(getMonacoRange(host.compiler, diagnostic.target));
|
|
1354
|
+
},
|
|
1355
|
+
[setVerticalPaneSizes]
|
|
1356
|
+
);
|
|
1357
|
+
return /* @__PURE__ */ jsx(PlaygroundContextProvider, { value: { host }, children: /* @__PURE__ */ jsxs("div", { className: style$4["layout"], children: [
|
|
1358
|
+
/* @__PURE__ */ jsxs(SplitPane, { sizes: verticalPaneSizes, onChange: onVerticalPaneSizeChange, split: "horizontal", children: [
|
|
1359
|
+
/* @__PURE__ */ jsx(Pane, { children: /* @__PURE__ */ jsxs(SplitPane, { initialSizes: ["50%", "50%"], children: [
|
|
1360
|
+
/* @__PURE__ */ jsxs(Pane, { className: style$4["edit-pane"], children: [
|
|
1361
|
+
/* @__PURE__ */ jsx(
|
|
1362
|
+
EditorCommandBar,
|
|
1363
|
+
{
|
|
1364
|
+
host,
|
|
1365
|
+
selectedEmitter,
|
|
1366
|
+
onSelectedEmitterChange,
|
|
1367
|
+
compilerOptions,
|
|
1368
|
+
onCompilerOptionsChange,
|
|
1369
|
+
samples: props.samples,
|
|
1370
|
+
selectedSampleName,
|
|
1371
|
+
onSelectedSampleNameChange,
|
|
1372
|
+
saveCode,
|
|
1373
|
+
formatCode,
|
|
1374
|
+
fileBug: props.onFileBug ? fileBug : void 0,
|
|
1375
|
+
documentationUrl: props.links?.documentationUrl
|
|
715
1376
|
}
|
|
1377
|
+
),
|
|
1378
|
+
/* @__PURE__ */ jsx(
|
|
1379
|
+
TypeSpecEditor,
|
|
1380
|
+
{
|
|
1381
|
+
model: typespecModel,
|
|
1382
|
+
actions: typespecEditorActions,
|
|
1383
|
+
options: props.editorOptions,
|
|
1384
|
+
onMount: onTypeSpecEditorMount
|
|
1385
|
+
}
|
|
1386
|
+
)
|
|
1387
|
+
] }),
|
|
1388
|
+
/* @__PURE__ */ jsx(Pane, { children: /* @__PURE__ */ jsx(
|
|
1389
|
+
OutputView,
|
|
1390
|
+
{
|
|
1391
|
+
compilationState,
|
|
1392
|
+
editorOptions: props.editorOptions,
|
|
1393
|
+
viewers: props.viewers,
|
|
1394
|
+
fileViewers: props.emitterViewers?.[selectedEmitter]
|
|
1395
|
+
}
|
|
1396
|
+
) })
|
|
1397
|
+
] }) }),
|
|
1398
|
+
/* @__PURE__ */ jsx(Pane, { minSize: 30, children: /* @__PURE__ */ jsx(
|
|
1399
|
+
ProblemPane,
|
|
1400
|
+
{
|
|
1401
|
+
collapsed: verticalPaneSizes[1] === verticalPaneSizesConst.collapsed[1],
|
|
1402
|
+
compilationState,
|
|
1403
|
+
onHeaderClick: toggleProblemPane,
|
|
1404
|
+
onDiagnosticSelected: handleDiagnosticSelected
|
|
716
1405
|
}
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
return () => {
|
|
722
|
-
debouncer.clear();
|
|
723
|
-
disposable.dispose();
|
|
724
|
-
};
|
|
725
|
-
}, [typespecModel, doCompile]);
|
|
726
|
-
useEffect(() => {
|
|
727
|
-
void doCompile();
|
|
728
|
-
}, [doCompile]);
|
|
729
|
-
const saveCode = useCallback(() => {
|
|
730
|
-
if (onSave) {
|
|
731
|
-
onSave({
|
|
732
|
-
content: typespecModel.getValue(),
|
|
733
|
-
emitter: selectedEmitter,
|
|
734
|
-
options: compilerOptions,
|
|
735
|
-
sampleName: isSampleUntouched ? selectedSampleName : undefined,
|
|
736
|
-
});
|
|
737
|
-
}
|
|
738
|
-
}, [
|
|
739
|
-
typespecModel,
|
|
740
|
-
onSave,
|
|
741
|
-
selectedEmitter,
|
|
742
|
-
compilerOptions,
|
|
743
|
-
selectedSampleName,
|
|
744
|
-
isSampleUntouched,
|
|
745
|
-
]);
|
|
746
|
-
const formatCode = useCallback(() => {
|
|
747
|
-
void editorRef.current?.getAction("editor.action.formatDocument")?.run();
|
|
748
|
-
}, [typespecModel]);
|
|
749
|
-
const fileBug = useCallback(async () => {
|
|
750
|
-
if (props.onFileBug) {
|
|
751
|
-
saveCode();
|
|
752
|
-
props.onFileBug();
|
|
753
|
-
}
|
|
754
|
-
}, [saveCode, typespecModel, props.onFileBug]);
|
|
755
|
-
const typespecEditorActions = useMemo(() => [
|
|
756
|
-
// ctrl/cmd+S => save
|
|
757
|
-
{ id: "save", label: "Save", keybindings: [KeyMod.CtrlCmd | KeyCode.KeyS], run: saveCode },
|
|
758
|
-
], [saveCode]);
|
|
759
|
-
const onTypeSpecEditorMount = useCallback(({ editor }) => {
|
|
760
|
-
editorRef.current = editor;
|
|
761
|
-
}, []);
|
|
762
|
-
const [verticalPaneSizes, setVerticalPaneSizes] = useState(verticalPaneSizesConst.collapsed);
|
|
763
|
-
const toggleProblemPane = useCallback(() => {
|
|
764
|
-
setVerticalPaneSizes((value) => {
|
|
765
|
-
return value === verticalPaneSizesConst.collapsed
|
|
766
|
-
? verticalPaneSizesConst.expanded
|
|
767
|
-
: verticalPaneSizesConst.collapsed;
|
|
768
|
-
});
|
|
769
|
-
}, [setVerticalPaneSizes]);
|
|
770
|
-
const onVerticalPaneSizeChange = useCallback((sizes) => {
|
|
771
|
-
setVerticalPaneSizes(sizes);
|
|
772
|
-
}, [setVerticalPaneSizes]);
|
|
773
|
-
const handleDiagnosticSelected = useCallback((diagnostic) => {
|
|
774
|
-
editorRef.current?.setSelection(getMonacoRange(host.compiler, diagnostic.target));
|
|
775
|
-
}, [setVerticalPaneSizes]);
|
|
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, {})] }) }));
|
|
1406
|
+
) })
|
|
1407
|
+
] }),
|
|
1408
|
+
props.footer ?? /* @__PURE__ */ jsx(DefaultFooter, {})
|
|
1409
|
+
] }) });
|
|
777
1410
|
};
|
|
778
1411
|
const verticalPaneSizesConst = {
|
|
779
|
-
|
|
780
|
-
|
|
1412
|
+
collapsed: [void 0, 30],
|
|
1413
|
+
expanded: [void 0, 200]
|
|
781
1414
|
};
|
|
782
1415
|
const outputDir = "./tsp-output";
|
|
783
1416
|
async function compile(host, content, selectedEmitter, options) {
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
return { internalCompilerError: error };
|
|
807
|
-
}
|
|
1417
|
+
await host.writeFile("main.tsp", content);
|
|
1418
|
+
await emptyOutputDir(host);
|
|
1419
|
+
try {
|
|
1420
|
+
const typespecCompiler = host.compiler;
|
|
1421
|
+
const program = await typespecCompiler.compile(host, "main.tsp", {
|
|
1422
|
+
...options,
|
|
1423
|
+
options: {
|
|
1424
|
+
...options.options,
|
|
1425
|
+
[selectedEmitter]: {
|
|
1426
|
+
...options.options?.[selectedEmitter],
|
|
1427
|
+
"emitter-output-dir": "tsp-output"
|
|
1428
|
+
}
|
|
1429
|
+
},
|
|
1430
|
+
outputDir: "tsp-output",
|
|
1431
|
+
emit: selectedEmitter ? [selectedEmitter] : []
|
|
1432
|
+
});
|
|
1433
|
+
const outputFiles = await findOutputFiles(host);
|
|
1434
|
+
return { program, outputFiles };
|
|
1435
|
+
} catch (error) {
|
|
1436
|
+
console.error("Internal compiler error", error);
|
|
1437
|
+
return { internalCompilerError: error };
|
|
1438
|
+
}
|
|
808
1439
|
}
|
|
809
1440
|
async function findOutputFiles(host) {
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
}
|
|
821
|
-
}
|
|
1441
|
+
const files = [];
|
|
1442
|
+
async function addFiles(dir) {
|
|
1443
|
+
const items = await host.readDir(outputDir + dir);
|
|
1444
|
+
for (const item of items) {
|
|
1445
|
+
const itemPath = `${dir}/${item}`;
|
|
1446
|
+
if ((await host.stat(outputDir + itemPath)).isDirectory()) {
|
|
1447
|
+
await addFiles(itemPath);
|
|
1448
|
+
} else {
|
|
1449
|
+
files.push(dir === "" ? item : `${dir}/${item}`);
|
|
1450
|
+
}
|
|
822
1451
|
}
|
|
823
|
-
|
|
824
|
-
|
|
1452
|
+
}
|
|
1453
|
+
await addFiles("");
|
|
1454
|
+
return files;
|
|
825
1455
|
}
|
|
826
1456
|
async function emptyOutputDir(host) {
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
model.dispose();
|
|
835
|
-
}
|
|
836
|
-
await host.rm(path, { recursive: true });
|
|
1457
|
+
const dirs = await host.readDir("./tsp-output");
|
|
1458
|
+
for (const file of dirs) {
|
|
1459
|
+
const path = "./tsp-output/" + file;
|
|
1460
|
+
const uri = Uri.parse(host.pathToFileURL(path));
|
|
1461
|
+
const model = editor.getModel(uri);
|
|
1462
|
+
if (model) {
|
|
1463
|
+
model.dispose();
|
|
837
1464
|
}
|
|
1465
|
+
await host.rm(path, { recursive: true });
|
|
1466
|
+
}
|
|
838
1467
|
}
|
|
839
1468
|
|
|
840
1469
|
function useStandalonePlaygroundContext(config) {
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
1470
|
+
const [context, setContext] = useState();
|
|
1471
|
+
useEffect(() => {
|
|
1472
|
+
const load = async () => {
|
|
1473
|
+
const host = await createBrowserHost(config.libraries, config.importConfig);
|
|
1474
|
+
await registerMonacoLanguage(host);
|
|
1475
|
+
const stateStorage = createStandalonePlaygroundStateStorage();
|
|
1476
|
+
const initialState = stateStorage.load();
|
|
1477
|
+
setContext({ host, initialState, stateStorage });
|
|
1478
|
+
};
|
|
1479
|
+
void load();
|
|
1480
|
+
}, []);
|
|
1481
|
+
return context;
|
|
853
1482
|
}
|
|
854
1483
|
const StandalonePlayground = (config) => {
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
1484
|
+
const context = useStandalonePlaygroundContext(config);
|
|
1485
|
+
const toasterId = useId$1();
|
|
1486
|
+
const { dispatchToast } = useToastController(toasterId);
|
|
1487
|
+
const onSave = useCallback(
|
|
1488
|
+
(value) => {
|
|
1489
|
+
if (!context) {
|
|
1490
|
+
return;
|
|
1491
|
+
}
|
|
1492
|
+
context.stateStorage.save(value);
|
|
1493
|
+
void navigator.clipboard.writeText(window.location.toString());
|
|
1494
|
+
dispatchToast(
|
|
1495
|
+
/* @__PURE__ */ jsxs(Toast, { children: [
|
|
1496
|
+
/* @__PURE__ */ jsx(ToastTitle, { children: "Saved!" }),
|
|
1497
|
+
/* @__PURE__ */ jsx(ToastBody, { children: "Playground link has been copied to the clipboard." })
|
|
1498
|
+
] }),
|
|
1499
|
+
{ intent: "success" }
|
|
1500
|
+
);
|
|
1501
|
+
},
|
|
1502
|
+
[dispatchToast, context]
|
|
1503
|
+
);
|
|
1504
|
+
const fixedOptions = useMemo(
|
|
1505
|
+
() => context && {
|
|
1506
|
+
host: context.host,
|
|
1507
|
+
libraries: config.libraries,
|
|
1508
|
+
defaultContent: context.initialState.content,
|
|
1509
|
+
defaultEmitter: context.initialState.emitter ?? config.defaultEmitter,
|
|
1510
|
+
defaultCompilerOptions: context.initialState.options,
|
|
1511
|
+
defaultSampleName: context.initialState.sampleName
|
|
1512
|
+
},
|
|
1513
|
+
[context]
|
|
1514
|
+
);
|
|
1515
|
+
if (context === void 0 || fixedOptions === void 0) {
|
|
1516
|
+
return config.fallback;
|
|
1517
|
+
}
|
|
1518
|
+
const options = {
|
|
1519
|
+
...config,
|
|
1520
|
+
...fixedOptions,
|
|
1521
|
+
onSave
|
|
1522
|
+
};
|
|
1523
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
1524
|
+
/* @__PURE__ */ jsx(Toaster, { toasterId }),
|
|
1525
|
+
options && /* @__PURE__ */ jsx(Playground, { ...options })
|
|
1526
|
+
] });
|
|
883
1527
|
};
|
|
884
1528
|
async function createReactPlayground(config) {
|
|
885
|
-
|
|
1529
|
+
return /* @__PURE__ */ jsx(StandalonePlayground, { ...config });
|
|
886
1530
|
}
|
|
887
1531
|
async function renderReactPlayground(config) {
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
1532
|
+
const app = await createReactPlayground(config);
|
|
1533
|
+
const root = createRoot(document.getElementById("root"));
|
|
1534
|
+
root.render(
|
|
1535
|
+
/* @__PURE__ */ jsx(FluentProvider, { theme: webLightTheme, style: { height: "100vh" }, children: app })
|
|
1536
|
+
);
|
|
891
1537
|
}
|
|
892
1538
|
function createStandalonePlaygroundStateStorage() {
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
}
|
|
915
|
-
|
|
1539
|
+
const stateStorage = createUrlStateStorage({
|
|
1540
|
+
content: {
|
|
1541
|
+
queryParam: "c",
|
|
1542
|
+
compress: "lz-base64"
|
|
1543
|
+
},
|
|
1544
|
+
emitter: {
|
|
1545
|
+
queryParam: "e"
|
|
1546
|
+
},
|
|
1547
|
+
options: {
|
|
1548
|
+
type: "object",
|
|
1549
|
+
queryParam: "options"
|
|
1550
|
+
},
|
|
1551
|
+
sampleName: {
|
|
1552
|
+
queryParam: "sample"
|
|
1553
|
+
}
|
|
1554
|
+
});
|
|
1555
|
+
return {
|
|
1556
|
+
load: stateStorage.load,
|
|
1557
|
+
resolveSearchParams: stateStorage.resolveSearchParams,
|
|
1558
|
+
save(data) {
|
|
1559
|
+
stateStorage.save(
|
|
1560
|
+
data.sampleName ? { sampleName: data.sampleName, options: data.options } : data
|
|
1561
|
+
);
|
|
1562
|
+
}
|
|
1563
|
+
};
|
|
916
1564
|
}
|
|
917
1565
|
|
|
918
1566
|
export { Footer, FooterItem, FooterVersionItem, Playground, StandalonePlayground, createReactPlayground, createStandalonePlaygroundStateStorage, renderReactPlayground, usePlaygroundContext };
|
|
919
|
-
//# sourceMappingURL=index.js.map
|