@typespec/playground 0.3.0-dev.0 → 0.3.0-dev.10

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.
Files changed (122) hide show
  1. package/dist/.storybook/main.d.ts +5 -0
  2. package/dist/.storybook/main.d.ts.map +1 -0
  3. package/dist/.storybook/preview.d.ts +5 -0
  4. package/dist/.storybook/preview.d.ts.map +1 -0
  5. package/dist/index.js +31 -34
  6. package/dist/react/index.js +1432 -809
  7. package/dist/react/viewers/index.js +9 -8
  8. package/dist/react-wrapper-CT3xxCSW.js +20 -0
  9. package/dist/src/browser-host.d.ts +3 -2
  10. package/dist/src/browser-host.d.ts.map +1 -1
  11. package/dist/src/core.d.ts +1 -1
  12. package/dist/src/core.d.ts.map +1 -1
  13. package/dist/src/editor-command-bar/editor-command-bar.d.ts +4 -3
  14. package/dist/src/editor-command-bar/editor-command-bar.d.ts.map +1 -1
  15. package/dist/src/index.d.ts +5 -5
  16. package/dist/src/index.d.ts.map +1 -1
  17. package/dist/src/lsp/monaco-to-lsp.d.ts +1 -1
  18. package/dist/src/manifest.d.ts +2 -4
  19. package/dist/src/manifest.d.ts.map +1 -1
  20. package/dist/src/react/context/index.d.ts +1 -1
  21. package/dist/src/react/context/index.d.ts.map +1 -1
  22. package/dist/src/react/context/playground-context.d.ts +4 -4
  23. package/dist/src/react/context/playground-context.d.ts.map +1 -1
  24. package/dist/src/react/default-footer.d.ts +2 -1
  25. package/dist/src/react/default-footer.d.ts.map +1 -1
  26. package/dist/src/react/diagnostic-list/diagnostic-list.d.ts +3 -2
  27. package/dist/src/react/diagnostic-list/diagnostic-list.d.ts.map +1 -1
  28. package/dist/src/react/editor.d.ts +3 -2
  29. package/dist/src/react/editor.d.ts.map +1 -1
  30. package/dist/src/react/emitter-dropdown.d.ts +2 -1
  31. package/dist/src/react/emitter-dropdown.d.ts.map +1 -1
  32. package/dist/src/react/file-output/file-output.d.ts +6 -5
  33. package/dist/src/react/file-output/file-output.d.ts.map +1 -1
  34. package/dist/src/react/footer/footer-item.d.ts +2 -1
  35. package/dist/src/react/footer/footer-item.d.ts.map +1 -1
  36. package/dist/src/react/footer/footer-version-item.d.ts +1 -1
  37. package/dist/src/react/footer/footer.d.ts +2 -1
  38. package/dist/src/react/footer/footer.d.ts.map +1 -1
  39. package/dist/src/react/footer/index.d.ts +3 -3
  40. package/dist/src/react/footer/index.d.ts.map +1 -1
  41. package/dist/src/react/index.d.ts +6 -6
  42. package/dist/src/react/index.d.ts.map +1 -1
  43. package/dist/src/react/output-tabs/output-tabs.d.ts +3 -7
  44. package/dist/src/react/output-tabs/output-tabs.d.ts.map +1 -1
  45. package/dist/src/react/output-view/file-viewer.d.ts +4 -0
  46. package/dist/src/react/output-view/file-viewer.d.ts.map +1 -0
  47. package/dist/src/react/output-view/output-view.d.ts +9 -4
  48. package/dist/src/react/output-view/output-view.d.ts.map +1 -1
  49. package/dist/src/react/output-view/type-graph-viewer.d.ts +4 -0
  50. package/dist/src/react/output-view/type-graph-viewer.d.ts.map +1 -0
  51. package/dist/src/react/playground.d.ts +8 -5
  52. package/dist/src/react/playground.d.ts.map +1 -1
  53. package/dist/src/react/problem-pane/header.d.ts +4 -3
  54. package/dist/src/react/problem-pane/header.d.ts.map +1 -1
  55. package/dist/src/react/problem-pane/index.d.ts +1 -1
  56. package/dist/src/react/problem-pane/problem-pane.d.ts +4 -3
  57. package/dist/src/react/problem-pane/problem-pane.d.ts.map +1 -1
  58. package/dist/src/react/samples-dropdown.d.ts +3 -2
  59. package/dist/src/react/samples-dropdown.d.ts.map +1 -1
  60. package/dist/src/react/settings/compiler-settings-dialog-button.d.ts +2 -1
  61. package/dist/src/react/settings/compiler-settings.d.ts +4 -3
  62. package/dist/src/react/settings/compiler-settings.d.ts.map +1 -1
  63. package/dist/src/react/settings/emitter-options-form.d.ts +4 -3
  64. package/dist/src/react/settings/emitter-options-form.d.ts.map +1 -1
  65. package/dist/src/react/settings/linter-form.d.ts +4 -3
  66. package/dist/src/react/settings/linter-form.d.ts.map +1 -1
  67. package/dist/src/react/split-pane/index.d.ts +1 -1
  68. package/dist/src/react/split-pane/index.d.ts.map +1 -1
  69. package/dist/src/react/split-pane/pane.d.ts +2 -1
  70. package/dist/src/react/split-pane/pane.d.ts.map +1 -1
  71. package/dist/src/react/split-pane/sash-content.d.ts +2 -1
  72. package/dist/src/react/split-pane/sash-content.d.ts.map +1 -1
  73. package/dist/src/react/split-pane/sash.d.ts +2 -1
  74. package/dist/src/react/split-pane/sash.d.ts.map +1 -1
  75. package/dist/src/react/split-pane/split-pane.d.ts +2 -1
  76. package/dist/src/react/split-pane/split-pane.d.ts.map +1 -1
  77. package/dist/src/react/standalone.d.ts +5 -4
  78. package/dist/src/react/standalone.d.ts.map +1 -1
  79. package/dist/src/react/types.d.ts +20 -8
  80. package/dist/src/react/types.d.ts.map +1 -1
  81. package/dist/src/react/typespec-editor.d.ts +5 -4
  82. package/dist/src/react/typespec-editor.d.ts.map +1 -1
  83. package/dist/src/react/viewers/index.d.ts +2 -2
  84. package/dist/src/react/viewers/index.d.ts.map +1 -1
  85. package/dist/src/react/viewers/react-wrapper.d.ts +5 -0
  86. package/dist/src/react/viewers/react-wrapper.d.ts.map +1 -0
  87. package/dist/src/react/viewers/swagger-ui.d.ts +2 -1
  88. package/dist/src/react/viewers/swagger-ui.d.ts.map +1 -1
  89. package/dist/src/services.d.ts +3 -2
  90. package/dist/src/services.d.ts.map +1 -1
  91. package/dist/src/tooling/index.d.ts +2 -1
  92. package/dist/src/tooling/index.d.ts.map +1 -1
  93. package/dist/src/tooling/types.d.ts +2 -1
  94. package/dist/src/tooling/types.d.ts.map +1 -1
  95. package/dist/src/types.d.ts +2 -1
  96. package/dist/src/types.d.ts.map +1 -1
  97. package/dist/src/vite/index.d.ts +3 -2
  98. package/dist/src/vite/index.d.ts.map +1 -1
  99. package/dist/src/vite/types.d.ts +4 -3
  100. package/dist/src/vite/types.d.ts.map +1 -1
  101. package/dist/state-storage-Bj5MQoKS.js +640 -0
  102. package/dist/stories/footer/footer-item.stories.d.ts +9 -0
  103. package/dist/stories/footer/footer-item.stories.d.ts.map +1 -0
  104. package/dist/stories/footer/footer-version-item.stories.d.ts +9 -0
  105. package/dist/stories/footer/footer-version-item.stories.d.ts.map +1 -0
  106. package/dist/stories/footer/footer.stories.d.ts +9 -0
  107. package/dist/stories/footer/footer.stories.d.ts.map +1 -0
  108. package/dist/stories/playground.stories.d.ts +9 -0
  109. package/dist/stories/playground.stories.d.ts.map +1 -0
  110. package/dist/{index.css → style.css} +170 -163
  111. package/dist/tooling/index.js +19 -24
  112. package/dist/vite/index.js +74 -76
  113. package/dist/vite.config.d.ts +3 -0
  114. package/dist/vite.config.d.ts.map +1 -0
  115. package/package.json +41 -43
  116. package/dist/index.js.map +0 -1
  117. package/dist/react/index.js.map +0 -1
  118. package/dist/react/viewers/index.js.map +0 -1
  119. package/dist/state-storage-O7CGHf8F.js +0 -660
  120. package/dist/state-storage-O7CGHf8F.js.map +0 -1
  121. package/dist/tooling/index.js.map +0 -1
  122. package/dist/vite/index.js.map +0 -1
@@ -1,943 +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, Link, Toolbar, Tooltip, TabList, Tab, tokens, useToastController, Toast, ToastTitle, ToastBody, Toaster, FluentProvider, webLightTheme } from '@fluentui/react-components';
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 { editor, Uri, MarkerSeverity, KeyMod, KeyCode } from 'monaco-editor';
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, c as createBrowserHost, r as registerMonacoLanguage, a as createUrlStateStorage } from '../state-storage-O7CGHf8F.js';
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-Bj5MQoKS.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(undefined);
13
+ const PlaygroundContext = createContext(void 0);
16
14
  const PlaygroundContextProvider = PlaygroundContext.Provider;
17
15
  function usePlaygroundContext() {
18
- const context = useContext(PlaygroundContext);
19
- if (context === undefined) {
20
- throw new Error("usePlaygroundContext must be used within a PlaygroundContextProvider");
21
- }
22
- return context;
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
- var style$b = {"footer":"footer-module_footer__QqUEE","footer-item":"footer-module_footer-item__7rhbZ"};
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
- const resolvedClassName = mergeClasses(style$b["footer-item"], className);
29
- return link ? (jsx("a", { className: resolvedClassName, href: link, target: "_blank", rel: "noopener noreferrer", children: children })) : (jsx("div", { className: resolvedClassName, children: children }));
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
- var style$a = {"version-item":"footer-version-item-module_version-item__pjuvV","button":"footer-version-item-module_button__70iqf"};
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
- var _a;
36
- const { host } = usePlaygroundContext();
37
- const latest = versionSelector === null || versionSelector === void 0 ? void 0 : versionSelector.latest;
38
- const selected = (_a = versionSelector === null || versionSelector === void 0 ? void 0 : versionSelector.selected) !== null && _a !== void 0 ? _a : host.compiler.MANIFEST.version;
39
- return (jsx(FooterItem, { className: style$a["version-item"], children: jsxs(Popover, { children: [jsx(PopoverTrigger, { disableButtonEnhancement: true, children: jsxs("div", { className: style$a["button"], children: [jsx("span", { children: "Version " }), jsx("span", { children: selected }), jsx("span", { children: latest ? (latest === selected ? " (latest)" : " (old)") : "" })] }) }), jsx(PopoverSurface, { children: jsx(VersionsPopup, { versionSelector: versionSelector }) })] }) }));
41
+ 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
+ ] }) });
40
52
  });
41
53
  const VersionsPopup = memo(({ versionSelector }) => {
42
- const { host } = usePlaygroundContext();
43
- return (jsxs("div", { style: { maxWidth: "400px" }, children: [versionSelector && jsx(VersionSelector, { ...versionSelector }), jsxs("div", { children: [jsx(Title3, { children: "Loaded libraries" }), jsxs(Table, { size: "small", children: [jsx(TableHeader, { children: jsx(TableRow, { children: columns.map((column) => (jsx(TableHeaderCell, { children: column.label }, column.columnKey))) }) }), jsx(TableBody, { children: Object.values(host.libraries).map((item) => (jsxs(TableRow, { children: [jsx(TableCell, { children: item.name }), jsx(TableCell, { children: item.packageJson.version })] }, item.name))) })] })] })] }));
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
+ ] });
44
68
  });
45
69
  const columns = [
46
- { columnKey: "name", label: "Library" },
47
- { columnKey: "version", label: "Version" },
70
+ { columnKey: "name", label: "Library" },
71
+ { columnKey: "version", label: "Version" }
48
72
  ];
49
73
  const VersionSelector = memo(({ versions, selected, latest, onChange }) => {
50
- const changeVersion = useCallback((ev, data) => {
51
- onChange(versions.find((x) => x.name === data.value));
52
- }, [versions, onChange]);
53
- return (jsxs("div", { children: [jsx(Title3, { children: "Select release" }), jsx(Select, { value: selected, onChange: changeVersion, children: versions.map((version) => (jsxs("option", { value: version.name, children: [version.label, " ", version.name === latest ? "(latest)" : ""] }, version.name))) })] }));
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
+ ] });
54
88
  });
55
89
 
56
90
  const Footer = ({ className, children }) => {
57
- return jsx("div", { className: mergeClasses(style$b.footer, className), children: children });
91
+ return /* @__PURE__ */ jsx("div", { className: mergeClasses(style$b.footer, className), children });
58
92
  };
59
93
 
60
- const EmitterDropdown = ({ emitters, onSelectedEmitterChange, selectedEmitter, }) => {
61
- const options = emitters.map((emitterName) => {
62
- return jsx("option", { children: emitterName }, emitterName);
63
- });
64
- const handleSelected = useCallback((evt) => {
65
- onSelectedEmitterChange(evt.target.value);
66
- }, [onSelectedEmitterChange]);
67
- return (jsxs(Select, { className: "sample-dropdown", onChange: handleSelected, value: selectedEmitter, children: [jsx("option", { value: "", disabled: true, children: "Select emitter..." }), options] }));
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
+ );
68
121
  };
69
122
 
70
- const SamplesDropdown = ({ samples, selectedSampleName, onSelectedSampleNameChange, }) => {
71
- const options = Object.keys(samples).map((sample) => {
72
- return jsx("option", { children: sample }, sample);
73
- });
74
- const handleSelected = useCallback((evt) => {
75
- if (samples[evt.target.value]) {
76
- onSelectedSampleNameChange(evt.target.value);
77
- }
78
- }, [onSelectedSampleNameChange]);
79
- return (jsxs(Select, { className: "sample-dropdown", onChange: handleSelected, value: selectedSampleName !== null && selectedSampleName !== void 0 ? selectedSampleName : "", children: [jsx("option", { value: "", disabled: true, children: "Select sample..." }), options] }));
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
+ );
80
152
  };
81
153
 
82
- var style$9 = {"form":"emitter-options-form-module_form__dm2RP","item":"emitter-options-form-module_item__WocHP","switch":"emitter-options-form-module_switch__d4EQs"};
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
+ };
83
161
 
84
- const EmitterOptionsForm = ({ library, options, optionsChanged, }) => {
85
- var _a, _b, _c;
86
- const emitterOptionsSchema = (_c = (_b = (_a = library.definition) === null || _a === void 0 ? void 0 : _a.emitter) === null || _b === void 0 ? void 0 : _b.options) === null || _c === void 0 ? void 0 : _c.properties;
87
- if (emitterOptionsSchema === undefined) {
88
- return jsx(Fragment, { children: "\"No options\"" });
89
- }
90
- const entries = Object.entries(emitterOptionsSchema);
91
- const handleChange = useCallback(({ name, value }) => {
92
- optionsChanged({
93
- ...options,
94
- [library.name]: {
95
- ...options[library.name],
96
- [name]: value,
97
- },
98
- });
99
- }, [options, optionsChanged]);
100
- return (jsx("div", { className: style$9["form"], children: entries.map(([key, value]) => {
101
- var _a;
102
- return (jsx("div", { className: style$9["form-item"], children: jsx(JsonSchemaPropertyInput, { emitterOptions: (_a = options[library.name]) !== null && _a !== void 0 ? _a : {}, name: key, prop: value, onChange: handleChange }) }, key));
103
- }) }));
104
- };
105
- const JsonSchemaPropertyInput = ({ emitterOptions, name, prop, onChange, }) => {
106
- var _a;
107
- const prettyName = useMemo(() => name[0].toUpperCase() + name.slice(1).replace(/-/g, " "), [name]);
108
- const inputId = useId("input");
109
- const value = (_a = emitterOptions[name]) !== null && _a !== void 0 ? _a : prop.default;
110
- const handleChange = useCallback((_, data) => onChange({ name, value: "value" in data ? data.value : data.checked }), [onChange]);
111
- switch (prop.type) {
112
- case "boolean":
113
- return (jsx(Switch, { className: style$9["switch"], label: prettyName, labelPosition: "above", checked: value, onChange: handleChange }));
114
- case "string":
115
- default:
116
- return (jsxs("div", { className: style$9["item"], children: [jsx(Label, { htmlFor: inputId, title: name, children: prettyName }), prop.enum ? (jsx(RadioGroup, { layout: "horizontal", id: inputId, value: value, onChange: handleChange, children: prop.enum.map((x) => (jsx(Radio, { value: x, label: x }, x))) })) : (jsx(Input, { id: inputId, value: value, onChange: handleChange }))] }));
117
- }
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
+ }
118
231
  };
119
232
 
120
- const LinterForm = ({ libraries, linterRuleSet, onLinterRuleSetChanged, }) => {
121
- const rulesets = Object.values(libraries).flatMap((lib) => {
122
- var _a, _b, _c;
123
- // eslint-disable-next-line deprecation/deprecation
124
- const linter = (_a = lib.linter) !== null && _a !== void 0 ? _a : (_b = lib.definition) === null || _b === void 0 ? void 0 : _b.linter;
125
- return Object.keys((_c = linter === null || linter === void 0 ? void 0 : linter.ruleSets) !== null && _c !== void 0 ? _c : {}).map((x) => `${lib.name}/${x}`);
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
126
250
  });
127
- if (rulesets.length === 0) {
128
- return jsx(Fragment, { children: "No ruleset available" });
129
- }
130
- const handleChange = (ruleSet, checked) => {
131
- var _a;
132
- const ruleSets = (_a = linterRuleSet.extends) !== null && _a !== void 0 ? _a : [];
133
- const updatedRuleSets = checked
134
- ? [...ruleSets, ruleSet]
135
- : ruleSets.filter((x) => x !== ruleSet);
136
- onLinterRuleSetChanged({
137
- extends: updatedRuleSets,
138
- });
139
- };
140
- return (jsx(Fragment, { children: rulesets.map((ruleSet) => {
141
- var _a;
142
- return (jsx(RuleSetCheckbox, { ruleSet: ruleSet, checked: (_a = linterRuleSet.extends) === null || _a === void 0 ? void 0 : _a.includes(ruleSet), onChange: handleChange }, ruleSet));
143
- }) }));
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
+ }) });
144
263
  };
145
264
  const RuleSetCheckbox = ({ ruleSet, checked, onChange }) => {
146
- const handleChange = useCallback((_, data) => {
147
- onChange(ruleSet, !!data.checked);
148
- }, [ruleSet, checked, onChange]);
149
- return jsx(Checkbox, { label: ruleSet, checked: checked, onChange: handleChange });
150
- };
151
-
152
- const CompilerSettings = ({ selectedEmitter, host, options, onOptionsChanged, }) => {
153
- var _a, _b;
154
- const emitterOptionsChanged = useCallback((emitterOptions) => {
155
- onOptionsChanged({
156
- ...options,
157
- options: emitterOptions,
158
- });
159
- }, [options]);
160
- const library = host.libraries[selectedEmitter];
161
- const linterRuleSet = (_a = options.linterRuleSet) !== null && _a !== void 0 ? _a : {};
162
- const linterRuleSetChanged = useCallback((linterRuleSet) => {
163
- onOptionsChanged({
164
- ...options,
165
- linterRuleSet,
166
- });
167
- }, [options]);
168
- return (jsxs("div", { children: [jsxs(Fragment, { children: ["Emitter: ", selectedEmitter] }), jsx(Divider, { style: { marginTop: 20 } }), jsx("h3", { children: "Options" }), library && (jsx(EmitterOptionsForm, { library: library, options: (_b = options.options) !== null && _b !== void 0 ? _b : {}, optionsChanged: emitterOptionsChanged })), jsx(Divider, { style: { marginTop: 20 } }), jsx("h3", { children: "Linter" }), jsx(LinterForm, { libraries: host.libraries, linterRuleSet: linterRuleSet, onLinterRuleSetChanged: linterRuleSetChanged })] }));
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 });
169
272
  };
170
273
 
171
- const CompilerSettingsDialogButton = ({ selectedEmitter, compilerOptions, onCompilerOptionsChange, }) => {
172
- const { host } = usePlaygroundContext();
173
- return (jsxs(Dialog, { children: [jsx(DialogTrigger, { children: jsx(ToolbarButton, { icon: jsx(Settings24Regular, {}) }) }), jsx(DialogSurface, { children: jsxs(DialogBody, { children: [jsx(DialogTitle, { children: "Settings" }), jsx(DialogContent, { children: jsx(CompilerSettings, { host: host, selectedEmitter: selectedEmitter, options: compilerOptions, onOptionsChanged: onCompilerOptionsChange }) })] }) })] }));
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
+ ] });
174
326
  };
175
327
 
176
- var style$8 = {"bar":"editor-command-bar-module_bar__5q4D5","divider":"editor-command-bar-module_divider__iDahk","spacer":"editor-command-bar-module_spacer__hlHE9"};
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
+ ] });
349
+ };
177
350
 
178
- const EditorCommandBar = ({ documentationUrl, saveCode, formatCode, fileBug, host, selectedEmitter, onSelectedEmitterChange, compilerOptions, onCompilerOptionsChange, samples, selectedSampleName, onSelectedSampleNameChange, }) => {
179
- const documentation = documentationUrl ? (jsx("label", { children: jsx(Link, { href: documentationUrl, target: "_blank", children: "Docs" }) })) : undefined;
180
- const bugButton = fileBug ? jsx(FileBugButton, { onClick: fileBug }) : undefined;
181
- const emitters = useMemo(() => Object.values(host.libraries)
182
- .filter((x) => x.isEmitter)
183
- .map((x) => x.name), [host.libraries]);
184
- return (jsx("div", { className: style$8["bar"], children: jsxs(Toolbar, { children: [jsx(Tooltip, { content: "Save", relationship: "description", withArrow: true, children: jsx(ToolbarButton, { "aria-label": "Save", icon: jsx(Save16Regular, {}), onClick: saveCode }) }), jsx(Tooltip, { content: "Format", relationship: "description", withArrow: true, children: jsx(ToolbarButton, { "aria-label": "Format", icon: jsx(Broom16Filled, {}), onClick: formatCode }) }), samples && (jsxs(Fragment, { children: [jsx(SamplesDropdown, { samples: samples, selectedSampleName: selectedSampleName, onSelectedSampleNameChange: onSelectedSampleNameChange }), jsx("div", { className: style$8["spacer"] })] })), jsx(EmitterDropdown, { emitters: emitters, onSelectedEmitterChange: onSelectedEmitterChange, selectedEmitter: selectedEmitter }), documentation && (jsxs(Fragment, { children: [jsx("div", { className: style$8["spacer"] }), documentation] })), jsx("div", { className: style$8["divider"] }), bugButton, jsx(CompilerSettingsDialogButton, { compilerOptions: compilerOptions, onCompilerOptionsChange: onCompilerOptionsChange, selectedEmitter: selectedEmitter })] }) }));
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
+ };
359
+
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
+ ] }) });
185
417
  };
186
418
  const FileBugButton = ({ onClick }) => {
187
- 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 }) }));
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
+ ) });
188
428
  };
189
429
 
190
430
  const DefaultFooter = () => {
191
- return (jsx(Footer, { children: jsx(FooterVersionItem, {}) }));
431
+ return /* @__PURE__ */ jsx(Footer, { children: /* @__PURE__ */ jsx(FooterVersionItem, {}) });
192
432
  };
193
433
 
194
434
  const Editor = ({ model, options, actions, onMount }) => {
195
- const editorContainerRef = useRef(null);
196
- const editorRef = useRef(null);
197
- useEffect(() => {
198
- editorRef.current = editor.create(editorContainerRef.current, {
199
- model,
200
- automaticLayout: true,
201
- ...options,
202
- });
203
- onMount === null || onMount === void 0 ? void 0 : onMount({ editor: editorRef.current });
204
- }, []);
205
- useEffect(() => {
206
- var _a;
207
- editor.setTheme((_a = options.theme) !== null && _a !== void 0 ? _a : "typespec");
208
- }, [options.theme]);
209
- useEffect(() => {
210
- const disposables = [];
211
- for (const command of actions !== null && actions !== void 0 ? actions : []) {
212
- disposables.push(editorRef.current.addAction(command));
213
- }
214
- return () => {
215
- disposables.forEach((x) => x.dispose());
216
- };
217
- }, [actions]);
218
- useEffect(() => {
219
- if (editorRef.current) {
220
- editorRef.current.setModel(model);
221
- }
222
- }, [model]);
223
- return (jsx("div", { className: "monaco-editor-container", style: { width: "100%", height: "100%", overflow: "hidden" }, ref: editorContainerRef, "data-tabster": '{"uncontrolled": {}}' // https://github.com/microsoft/tabster/issues/316
224
- }));
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
+ );
225
471
  };
226
472
  function useMonacoModel(uri, language) {
227
- return useMemo(() => {
228
- var _a;
229
- const monacoUri = Uri.parse(uri);
230
- return (_a = editor.getModel(monacoUri)) !== null && _a !== void 0 ? _a : editor.createModel("", language, monacoUri);
231
- }, [uri, language]);
473
+ return useMemo(() => {
474
+ const monacoUri = Uri.parse(uri);
475
+ return editor.getModel(monacoUri) ?? editor.createModel("", language, monacoUri);
476
+ }, [uri, language]);
232
477
  }
233
478
 
234
- /**
235
- * Hook to manage a value that could be either controlled or uncontrolled, such as a checked state or
236
- * text box string.
237
- * @param controlledValue - The controlled value passed in the props. This value will always be used if provided,
238
- * and the internal state will be updated to reflect it.
239
- * @param defaultUncontrolledValue - Initial value for the internal state in the uncontrolled case.
240
- * @returns An array of the current value and an updater callback. Like `React.useState`, the updater
241
- * callback always has the same identity, and it can take either a new value, or a function which
242
- * is passed the previous value and returns the new value.
243
- * @see https://reactjs.org/docs/uncontrolled-components.html
244
- */
245
479
  function useControllableValue(controlledValue, defaultUncontrolledValue, onChange) {
246
- const [value, setValue] = useState(defaultUncontrolledValue);
247
- const isControlled = useMemo(() => controlledValue !== undefined, []);
248
- const currentValue = isControlled ? controlledValue : value;
249
- // Duplicate the current value and onChange in refs so they're accessible from
250
- // setValueOrCallOnChange without creating a new callback every time
251
- const valueRef = useRef(currentValue);
252
- const onChangeRef = useRef(onChange);
253
- useEffect(() => {
254
- valueRef.current = currentValue;
255
- onChangeRef.current = onChange;
256
- });
257
- // To match the behavior of the setter returned by React.useState, this callback's identity
258
- // should never change. This means it MUST NOT directly reference variables that can change.
259
- const setValueOrCallOnChange = useMemo(() => (update) => {
260
- // Assuming here that TValue is not a function, because a controllable value will typically
261
- // be something a user can enter as input
262
- const newValue = typeof update === "function" ? update(valueRef.current) : update;
263
- if (onChangeRef.current) {
264
- onChangeRef.current(newValue);
265
- }
266
- if (!isControlled) {
267
- setValue(newValue);
268
- }
269
- }, []);
270
- return [currentValue, setValueOrCallOnChange];
271
- }
272
- function useAsyncMemo(callback, defaultValue, deps) {
273
- const [value, setValue] = useState(defaultValue);
274
- useEffect(() => {
275
- callback()
276
- .then(setValue)
277
- // eslint-disable-next-line no-console
278
- .catch(() => console.error("Failed to load async memo"));
279
- }, deps);
280
- 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];
281
502
  }
282
503
 
283
- var style$7 = {"file-output":"file-output-module_file-output__YBaE7","viewer-selector":"file-output-module_viewer-selector__fNWoo"};
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
+ };
284
541
 
285
- /**
286
- * Display a file output using different viewers.
287
- */
288
542
  const FileOutput = ({ filename, content, viewers }) => {
289
- if (viewers.length === 0) {
290
- return jsx(Fragment, { children: "No viewers" });
291
- }
292
- else if (viewers.length === 1) {
293
- return viewers[0].render({ filename, content });
294
- }
295
- const [selected, setSelected] = useState(viewers[0].key);
296
- const handleSelected = useCallback((_, data) => {
297
- setSelected(data.value);
298
- }, [selected]);
299
- const selectedRender = useMemo(() => {
300
- var _a;
301
- return (_a = viewers.find((x) => x.key === selected)) === null || _a === void 0 ? void 0 : _a.render;
302
- }, [selected, viewers]);
303
- return (jsxs("div", { className: style$7["file-output"], children: [jsx("div", { className: style$7["viewer-selector"], children: jsx(Select, { value: selected, onChange: handleSelected, children: viewers.map(({ key, label }) => (jsx("option", { value: key, children: label }, key))) }) }), selectedRender && selectedRender({ filename, content })] }));
304
- };
305
-
306
- var style$6 = {"tabs":"output-tabs-module_tabs__MFCRl","tab-divider":"output-tabs-module_tab-divider__9Fv--","tab":"output-tabs-module_tab__FJ78k","tab--selected":"output-tabs-module_tab--selected__GjCZY"};
307
-
308
- const OutputTabs = ({ tabs, selected, onSelect }) => {
309
- const [leftTabs, rightTabs] = chunk(tabs, (x) => x.align === "left");
310
- const onTabSelect = useCallback((event, data) => {
311
- onSelect(data.value);
312
- }, [onSelect]);
313
- return (jsxs(TabList, { selectedValue: selected, onTabSelect: onTabSelect, className: style$6["tabs"], children: [leftTabs.map((tab) => {
314
- return (jsx(OutputTabEl, { value: tab.id, className: tab.id === selected && style$6["tab--selected"], children: tab.name }, tab.id));
315
- }), jsx("div", { className: style$6["tab-divider"] }), rightTabs.map((tab) => {
316
- return (jsx(OutputTabEl, { value: tab.id, className: tab.id === selected && style$6["tab--selected"], children: tab.name }, tab.id));
317
- })] }));
318
- };
319
- const OutputTabEl = (props) => {
320
- return jsx(Tab, { ...props, className: mergeClasses(style$6["tab"], props.className) });
321
- };
322
- function chunk(items, condition) {
323
- const match = [];
324
- const unMatch = [];
325
- for (const item of items) {
326
- if (condition(item)) {
327
- match.push(item);
328
- }
329
- else {
330
- unMatch.push(item);
331
- }
332
- }
333
- return [match, unMatch];
334
- }
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
+ };
335
576
 
336
- const TypeSpecEditor = ({ actions, options, ...other }) => {
337
- const resolvedOptions = {
338
- "semanticHighlighting.enabled": true,
339
- automaticLayout: true,
340
- tabSize: 2,
341
- minimap: {
342
- enabled: false,
343
- },
344
- ...options,
345
- };
346
- 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"
347
584
  };
348
- const OutputEditor = ({ filename, value, editorOptions }) => {
349
- if (filename === "") {
350
- return null;
351
- }
352
- const options = {
353
- ...editorOptions,
354
- readOnly: true,
355
- automaticLayout: true,
356
- minimap: {
357
- enabled: false,
358
- },
359
- };
360
- const model = useMonacoModel(filename);
361
- model.setValue(value);
362
- return jsx(Editor, { model: model, options: options });
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
+ }) });
363
608
  };
364
609
 
365
- var style$5 = {"output-view":"output-view-module_output-view__uT5Ae","output-content":"output-view-module_output-content__Lis-G","type-graph-viewer":"output-view-module_type-graph-viewer__tUDEV"};
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
+ };
366
618
 
367
- const OutputView = ({ compilationState, viewers, editorOptions, }) => {
368
- if (compilationState === undefined) {
369
- return jsx(Fragment, {});
370
- }
371
- if ("internalCompilerError" in compilationState) {
372
- return jsx(Fragment, {});
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("");
373
634
  }
374
- return (jsx(OutputViewInternal, { compilationResult: compilationState, viewers: viewers, editorOptions: editorOptions }));
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
+ ] });
375
654
  };
376
- const OutputViewInternal = ({ compilationResult, viewers, editorOptions }) => {
377
- const { program, outputFiles } = compilationResult;
378
- const [viewSelection, setViewSelection] = useState({
379
- type: "file",
380
- filename: "",
381
- content: "",
382
- });
383
- useEffect(() => {
384
- if (viewSelection.type === "file") {
385
- if (outputFiles.length > 0) {
386
- const fileStillThere = outputFiles.find((x) => x === viewSelection.filename);
387
- void loadOutputFile(fileStillThere !== null && fileStillThere !== void 0 ? fileStillThere : outputFiles[0]);
388
- }
389
- else {
390
- setViewSelection({ type: "file", filename: viewSelection.filename, content: "" });
391
- }
392
- }
393
- }, [program, outputFiles]);
394
- async function loadOutputFile(path) {
395
- const contents = await program.host.readFile("./tsp-output/" + path);
396
- 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 });
397
663
  }
398
- const diagnostics = program.diagnostics;
399
- const tabs = useMemo(() => {
400
- return [
401
- ...outputFiles.map((x) => ({
402
- align: "left",
403
- name: x,
404
- id: x,
405
- })),
406
- { id: "type-graph", name: "Type Graph", align: "right" },
407
- ];
408
- }, [outputFiles, diagnostics]);
409
- const handleTabSelection = useCallback((tabId) => {
410
- if (tabId === "type-graph") {
411
- setViewSelection({ type: "type-graph" });
412
- }
413
- else {
414
- void loadOutputFile(tabId);
415
- }
416
- }, []);
417
- 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 }) })] }));
418
- };
419
- function getRawFileViewer(editorOptions) {
420
- return {
421
- key: "raw",
422
- label: "File",
423
- render: ({ filename, content }) => (jsx(OutputEditor, { editorOptions: editorOptions, filename: filename, value: content })),
424
- };
664
+ };
425
665
  }
426
- const OutputContent = ({ viewSelection, program, viewers, editorOptions, }) => {
427
- const resolvedViewers = useMemo(() => [getRawFileViewer(editorOptions), ...(viewers !== null && viewers !== void 0 ? viewers : [])], [viewers]);
428
- switch (viewSelection.type) {
429
- case "file":
430
- return (jsx(FileOutput, { filename: viewSelection.filename, content: viewSelection.content, viewers: resolvedViewers }));
431
- default:
432
- return program && jsx(TypeGraphViewer, { program: program });
433
- }
434
- };
435
- const TypeGraphViewer = ({ program }) => {
436
- 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 }) }) });
437
669
  };
438
670
  const TypeGraphColors = {
439
- background: tokens.colorNeutralBackground1,
440
- typeKind: tokens.colorPaletteBerryForeground2,
441
- typeName: tokens.colorNeutralForeground2,
442
- dataKey: tokens.colorNeutralForeground2,
443
- ref: tokens.colorBrandForeground1,
444
- literal: tokens.colorPaletteLightGreenForeground2,
445
- indentationGuide: tokens.colorNeutralForeground4,
446
- property: tokens.colorPaletteMarigoldForeground2,
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
447
685
  };
448
686
 
449
- var style$4 = {"layout":"playground-module_layout__SCPgt"};
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
+ };
450
755
 
451
- var style$3 = {"list":"diagnostic-list-module_list__6tVpz","item":"diagnostic-list-module_item__BE8Fr","item--error":"diagnostic-list-module_item--error__tnhWA","item--warning":"diagnostic-list-module_item--warning__J7vIN","item-code":"diagnostic-list-module_item-code__AgVjZ","item-loc":"diagnostic-list-module_item-loc__IeYnW"};
756
+ const layout = "_layout_l03ni_1";
757
+ const style$4 = {
758
+ layout: layout,
759
+ "edit-pane": "_edit-pane_l03ni_9"
760
+ };
452
761
 
453
- const DiagnosticList = ({ diagnostics, onDiagnosticSelected, }) => {
454
- if (diagnostics.length === 0) {
455
- return jsx("div", { className: style$3["list"], children: "No errors" });
456
- }
457
- const handleItemSelected = useCallback((diagnostic) => {
458
- onDiagnosticSelected === null || onDiagnosticSelected === void 0 ? void 0 : onDiagnosticSelected(diagnostic);
459
- }, [onDiagnosticSelected]);
460
- return (jsx("div", { className: style$3["list"], children: diagnostics.map((x, i) => {
461
- return jsx(DiagnosticItem, { diagnostic: x, onItemSelected: handleItemSelected }, i);
462
- }) }));
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
+ }) });
463
789
  };
464
790
  const DiagnosticItem = ({ diagnostic, onItemSelected }) => {
465
- const handleClick = useCallback(() => {
466
- onItemSelected(diagnostic);
467
- }, [diagnostic, onItemSelected]);
468
- return (jsxs("div", { tabIndex: 0, className: style$3["item"], onClick: handleClick, children: [jsx("div", { className: mergeClasses((style$3["item-severity"],
469
- style$3[diagnostic.severity === "error" ? "item--error" : "item--warning"])), children: diagnostic.severity }), jsx("div", { className: style$3["item-code"], children: diagnostic.code }), jsx("div", { className: style$3["item-message"], children: diagnostic.message }), jsx("div", { className: style$3["item-loc"], children: jsx(DiagnosticTargetLink, { target: diagnostic.target }) })] }));
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
+ ] });
470
808
  };
471
809
  const DiagnosticTargetLink = memo(({ target }) => {
472
- if (typeof target === "symbol") {
473
- return jsx("span", {});
474
- }
475
- const location = getSourceLocation(target);
476
- const file = location.file.path === "/test/main.tsp" ? "" : `${location.file.path}:`;
477
- const { line, character } = location.file.getLineAndCharacterOfPosition(location.pos);
478
- return (jsxs("span", { children: [file, line + 1, ":", character + 1] }));
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
+ ] });
479
822
  });
480
823
 
481
- var style$2 = {"header":"header-module_header__LyUNg","header--error":"header-module_header--error__8MKzf","error-icon":"header-module_error-icon__gb-oB","header--warning":"header-module_header--warning__QPFEE","warning-icon":"header-module_warning-icon__u14P3","header-content":"header-module_header-content__Uc4HJ","header-chevron":"header-module_header-chevron__HXm6b","header-chevron--collapsed":"header-module_header-chevron--collapsed__wKyHV"};
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
+ };
482
835
 
483
836
  const ProblemPaneHeader = memo(({ compilationState, ...props }) => {
484
- const noProblem = (jsx(Container, { status: "none", ...props, children: "No problems" }));
485
- if (compilationState === undefined) {
486
- return noProblem;
487
- }
488
- if ("internalCompilerError" in compilationState) {
489
- return (jsxs(Container, { status: "error", ...props, children: [jsx(ErrorCircle16Filled, {}), " Internal Compiler Error"] }));
490
- }
491
- const diagnostics = compilationState.program.diagnostics;
492
- if (diagnostics.length === 0) {
493
- return noProblem;
494
- }
495
- const errors = diagnostics.filter((x) => x.severity === "error");
496
- const warnings = diagnostics.filter((x) => x.severity === "warning");
497
- return (jsxs(Container, { status: errors.length > 0 ? "error" : "warning", ...props, children: [errors.length > 0 ? (jsxs(Fragment, { children: [jsx(ErrorCircle16Filled, { className: style$2["error-icon"] }), " ", errors.length, " errors"] })) : null, warnings.length > 0 ? (jsxs(Fragment, { children: [jsx(Warning16Filled, { className: style$2["warning-icon"] }), " ", warnings.length, " warnings"] })) : null] }));
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
+ ] });
498
867
  });
499
868
  const Container = ({ children, className, status, onClick, collaped }) => {
500
- return (jsxs("div", { tabIndex: onClick === undefined ? undefined : 0, className: mergeClasses(style$2["header"], status === "error" && style$2["header--error"], status === "warning" && style$2["header--warning"], className), onClick: onClick, children: [jsx("div", { className: style$2["header-content"], children: children }), jsx(ChevronDown16Regular, { className: mergeClasses(style$2["header-chevron"], collaped && style$2["header-chevron--collapsed"]) })] }));
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
+ );
501
894
  };
502
895
 
503
- var style$1 = {"problem-pane":"problem-pane-module_problem-pane__GJKF4","problem-content":"problem-pane-module_problem-content__rYzbh","no-problems":"problem-pane-module_no-problems__Ub8R-","internal-compiler-error":"problem-pane-module_internal-compiler-error__laE4f"};
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
+ };
504
902
 
505
- const ProblemPane = ({ collapsed, compilationState, onHeaderClick, onDiagnosticSelected, }) => {
506
- return (jsxs("div", { className: style$1["problem-pane"], children: [jsx(ProblemPaneHeader, { compilationState: compilationState, onClick: onHeaderClick, collaped: collapsed }), jsx("div", { className: style$1["problem-content"], children: jsx(ProblemPaneContent, { compilationState: compilationState, onDiagnosticSelected: onDiagnosticSelected }) })] }));
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
+ ] });
507
926
  };
508
- const ProblemPaneContent = ({ compilationState, onDiagnosticSelected, }) => {
509
- if (compilationState === undefined) {
510
- return jsx(Fragment, {});
511
- }
512
- if ("internalCompilerError" in compilationState) {
513
- return (jsx("pre", { className: style$1["internal-compiler-error"], children: String(compilationState.internalCompilerError) }));
514
- }
515
- const diagnostics = compilationState.program.diagnostics;
516
- return diagnostics.length === 0 ? (jsx("div", { className: style$1["no-problems"], children: " No problems" })) : (jsx(DiagnosticList, { diagnostics: diagnostics, onDiagnosticSelected: onDiagnosticSelected }));
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 });
517
939
  };
518
940
 
519
- function Pane({ children, ...props }) {
520
- return jsx("div", { ...props, children: children });
941
+ function Pane({
942
+ children,
943
+ ...props
944
+ }) {
945
+ return /* @__PURE__ */ jsx("div", { ...props, children });
521
946
  }
522
947
 
523
- var style = {"split-pane":"split-pane-module_split-pane__XCqR8","split-disabled":"split-pane-module_split-disabled__fZ0Sg","split-pane-dragging":"split-pane-module_split-pane-dragging__mQJnZ","react-split-vertical":"split-pane-module_react-split-vertical__WTUQ1","react-split-horizontal":"split-pane-module_react-split-horizontal__Fpls-","sash":"split-pane-module_sash__hNWH6","sash-disabled":"split-pane-module_sash-disabled__z6uCV","sash-vertical":"split-pane-module_sash-vertical__S8HbH","sash-horizontal":"split-pane-module_sash-horizontal__BTUaN","sash-content":"split-pane-module_sash-content__DLAt4","sash-content-dragging":"split-pane-module_sash-content-dragging__NkKQP","pane":"split-pane-module_pane__m1zQB"};
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
+ };
964
+
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
+ );
983
+ };
524
984
 
525
- const SashContent = ({ className, children, dragging, ...others }) => {
526
- return (jsx("div", { className: mergeClasses(style["sash-content"], dragging && style["sash-content-dragging"], className), ...others, children: children }));
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
+ );
527
1019
  };
528
1020
 
529
- const Sash = ({ className, render, onDragStart, onDragging, onDragEnd, onReset, ...others }) => {
530
- const [draging, setDrag] = useState(false);
531
- const handleMouseMove = (e) => {
532
- onDragging(e);
533
- };
534
- const handleMouseUp = (e) => {
535
- setDrag(false);
536
- onDragEnd(e);
537
- window.removeEventListener("mousemove", handleMouseMove);
538
- window.removeEventListener("mouseup", handleMouseUp);
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();
539
1053
  };
540
- return (jsx("div", { className: mergeClasses(style["sash"], className), onMouseDown: (e) => {
541
- setDrag(true);
542
- onDragStart(e);
543
- window.addEventListener("mousemove", handleMouseMove);
544
- window.addEventListener("mouseup", handleMouseUp);
545
- }, onDoubleClick: onReset, ...others, children: render(draging) }));
546
- };
547
-
548
- const SplitPane = ({ children, sizes: propSizes, initialSizes: defaultSizes, allowResize = true, split = "vertical", className: wrapClassName, sashRender = (_, active) => jsx(SashContent, { dragging: active }), resizerSize = 4, performanceMode = false, onChange = () => null, onDragStart = () => null, onDragEnd = () => null, ...others }) => {
549
- var _a;
550
- const [resolvedPropSize, updateSizes] = useControllableValue(propSizes, defaultSizes, onChange);
551
- const axis = useRef({ x: 0, y: 0 });
552
- const wrapper = useRef(null);
553
- const cacheSizes = useRef({ sizes: [], sashPosSizes: [] });
554
- const [wrapperRect, setWrapperRect] = useState({});
555
- const [isDragging, setDragging] = useState(false);
556
- useEffect(() => {
557
- const resizeObserver = new ResizeObserver(() => {
558
- var _a, _b;
559
- setWrapperRect((_b = (_a = wrapper === null || wrapper === void 0 ? void 0 : wrapper.current) === null || _a === void 0 ? void 0 : _a.getBoundingClientRect()) !== null && _b !== void 0 ? _b : {});
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;
560
1089
  });
561
- resizeObserver.observe(wrapper.current);
562
- return () => {
563
- resizeObserver.disconnect();
564
- };
565
- }, []);
566
- const { sizeName, splitPos, splitAxis } = useMemo(() => ({
567
- sizeName: split === "vertical" ? "width" : "height",
568
- splitPos: split === "vertical" ? "left" : "top",
569
- splitAxis: split === "vertical" ? "x" : "y",
570
- }), [split]);
571
- const wrapSize = (_a = wrapperRect[sizeName]) !== null && _a !== void 0 ? _a : 0;
572
- // Get limit sizes via children
573
- const paneLimitSizes = useMemo(() => children.map((childNode) => {
574
- const limits = [0, Infinity];
575
- if ((childNode === null || childNode === void 0 ? void 0 : childNode.type) === Pane) {
576
- const { minSize, maxSize } = childNode.props;
577
- limits[0] = assertsSize(minSize, wrapSize, 0);
578
- limits[1] = assertsSize(maxSize, wrapSize);
579
- }
580
- return limits;
581
- }), [children, wrapSize]);
582
- const sizes = useMemo(function () {
583
- let count = 0;
584
- let curSum = 0;
585
- const res = children.map((_, index) => {
586
- const size = assertsSize(resolvedPropSize[index], wrapSize);
587
- size === Infinity ? count++ : (curSum += size);
588
- return size;
1090
+ }
1091
+ if (count > 0) {
1092
+ const average = (wrapSize - curSum) / count;
1093
+ return res.map((size) => {
1094
+ return size === Infinity ? average : size;
589
1095
  });
590
- // resize or illegal size input,recalculate pane sizes
591
- if (curSum > wrapSize || (!count && curSum < wrapSize)) {
592
- const cacheNum = (curSum - wrapSize) / curSum;
593
- return res.map((size) => {
594
- return size === Infinity ? 0 : size - size * cacheNum;
595
- });
596
- }
597
- if (count > 0) {
598
- const average = (wrapSize - curSum) / count;
599
- return res.map((size) => {
600
- return size === Infinity ? average : size;
601
- });
602
- }
603
- return res;
604
- }, [...resolvedPropSize, children.length, wrapSize]);
605
- const sashPosSizes = useMemo(() => sizes.reduce((a, b) => [...a, a[a.length - 1] + b], [0]), [...sizes]);
606
- const dragStart = useCallback((e) => {
607
- var _a, _b;
608
- (_b = (_a = document === null || document === void 0 ? void 0 : document.body) === null || _a === void 0 ? void 0 : _a.classList) === null || _b === void 0 ? void 0 : _b.add(style["split-disabled"]);
609
- axis.current = { x: e.pageX, y: e.pageY };
610
- cacheSizes.current = { sizes, sashPosSizes };
611
- setDragging(true);
612
- onDragStart(e);
613
- }, [onDragStart, sizes, sashPosSizes]);
614
- const resetPosition = useCallback(() => {
615
- if (defaultSizes) {
616
- updateSizes(defaultSizes);
617
- }
618
- }, [defaultSizes, updateSizes]);
619
- const dragEnd = useCallback((e) => {
620
- var _a, _b;
621
- (_b = (_a = document === null || document === void 0 ? void 0 : document.body) === null || _a === void 0 ? void 0 : _a.classList) === null || _b === void 0 ? void 0 : _b.remove(style["split-disabled"]);
622
- axis.current = { x: e.pageX, y: e.pageY };
623
- cacheSizes.current = { sizes, sashPosSizes };
624
- setDragging(false);
625
- onDragEnd(e);
626
- }, [onDragEnd, sizes, sashPosSizes]);
627
- const onDragging = useCallback(function (e, i) {
628
- const curAxis = { x: e.pageX, y: e.pageY };
629
- let distanceX = curAxis[splitAxis] - axis.current[splitAxis];
630
- const leftBorder = -Math.min(sizes[i] - paneLimitSizes[i][0], paneLimitSizes[i + 1][1] - sizes[i + 1]);
631
- const rightBorder = Math.min(sizes[i + 1] - paneLimitSizes[i + 1][0], paneLimitSizes[i][1] - sizes[i]);
632
- if (distanceX < leftBorder) {
633
- distanceX = leftBorder;
634
- }
635
- if (distanceX > rightBorder) {
636
- distanceX = rightBorder;
637
- }
638
- const nextSizes = [...sizes];
639
- nextSizes[i] += distanceX;
640
- nextSizes[i + 1] -= distanceX;
641
- updateSizes(nextSizes);
642
- }, [paneLimitSizes, onChange]);
643
- const paneFollow = !(performanceMode && isDragging);
644
- const paneSizes = paneFollow ? sizes : cacheSizes.current.sizes;
645
- const panePoses = paneFollow ? sashPosSizes : cacheSizes.current.sashPosSizes;
646
- return (jsxs("div", { className: mergeClasses(style["split-pane"], split === "vertical" && style["split-pane-vertical"], split === "horizontal" && style["split-pane-horizontal"], isDragging && style["split-pane-dragging"], wrapClassName), ref: wrapper, ...others, children: [children.map((childNode, childIndex) => {
647
- const isPane = childNode.type === Pane;
648
- const paneProps = isPane ? childNode.props : {};
649
- return (jsx(Pane, { className: mergeClasses(style["pane"], paneProps.className), style: {
650
- ...paneProps.style,
651
- [sizeName]: paneSizes[childIndex],
652
- [splitPos]: panePoses[childIndex],
653
- }, children: isPane ? paneProps.children : childNode }, childIndex));
654
- }), sashPosSizes.slice(1, -1).map((posSize, index) => (jsx(Sash, { className: mergeClasses(!allowResize && style["sash-disabled"], split === "vertical" ? style["sash-vertical"] : style["sash-horizontal"]), style: {
655
- [sizeName]: resizerSize,
656
- [splitPos]: posSize - resizerSize / 2,
657
- }, render: sashRender.bind(null, index), onReset: resetPosition, onDragStart: dragStart, onDragging: (e) => onDragging(e, index), onDragEnd: dragEnd }, index)))] }));
658
- };
659
- /**
660
- * Convert size to absolute number or Infinity
661
- * SplitPane allows sizes in string and number, but the state sizes only support number,
662
- * so convert string and number to number in here
663
- * 'auto' -> divide the remaining space equally
664
- * 'xxx px' -> xxx
665
- * 'xxx%' -> wrapper.size * xxx/100
666
- * xxx -> xxx
667
- */
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
+ };
668
1211
  function assertsSize(size, sum, defaultValue = Infinity) {
669
- if (typeof size === "undefined")
670
- return defaultValue;
671
- if (typeof size === "number")
672
- return size;
673
- if (size.endsWith("%"))
674
- return sum * (+size.replace("%", "") / 100);
675
- if (size.endsWith("px"))
676
- return +size.replace("px", "");
1212
+ if (typeof size === "undefined")
677
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;
678
1221
  }
679
1222
 
680
1223
  const Playground = (props) => {
681
- var _a, _b, _c, _d;
682
- const { host, onSave } = props;
683
- const editorRef = useRef(undefined);
684
- const [selectedEmitter, onSelectedEmitterChange] = useControllableValue(props.emitter, props.defaultEmitter, props.onEmitterChange);
685
- const [compilerOptions, onCompilerOptionsChange] = useControllableValue(props.compilerOptions, (_a = props.defaultCompilerOptions) !== null && _a !== void 0 ? _a : {}, props.onCompilerOptionsChange);
686
- const [selectedSampleName, onSelectedSampleNameChange] = useControllableValue(props.sampleName, props.defaultSampleName, props.onSampleNameChange);
687
- const [content, setContent] = useState(props.defaultContent);
688
- const isSampleUntouched = useMemo(() => {
689
- var _a, _b;
690
- return Boolean(selectedSampleName && content === ((_b = (_a = props.samples) === null || _a === void 0 ? void 0 : _a[selectedSampleName]) === null || _b === void 0 ? void 0 : _b.content));
691
- }, [content, selectedSampleName, props.samples]);
692
- const typespecModel = useMonacoModel("inmemory://test/main.tsp", "typespec");
693
- const [compilationState, setCompilationState] = useState(undefined);
694
- const doCompile = useCallback(async () => {
695
- const content = typespecModel.getValue();
696
- setContent(content);
697
- const typespecCompiler = host.compiler;
698
- const state = await compile(host, content, selectedEmitter, compilerOptions);
699
- setCompilationState(state);
700
- if ("program" in state) {
701
- const markers = state.program.diagnostics.map((diag) => ({
702
- ...getMonacoRange(typespecCompiler, diag.target),
703
- message: diag.message,
704
- severity: diag.severity === "error" ? MarkerSeverity.Error : MarkerSeverity.Warning,
705
- tags: diag.code === "deprecated" ? [CompletionItemTag.Deprecated] : undefined,
706
- }));
707
- editor.setModelMarkers(typespecModel, "owner", markers !== null && markers !== void 0 ? markers : []);
708
- }
709
- else {
710
- editor.setModelMarkers(typespecModel, "owner", []);
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);
711
1283
  }
712
- }, [host, selectedEmitter, compilerOptions, typespecModel, setContent]);
713
- const updateTypeSpec = useCallback((value) => {
714
- if (typespecModel.getValue() !== value) {
715
- typespecModel.setValue(value);
1284
+ if (config.compilerOptions) {
1285
+ onCompilerOptionsChange(config.compilerOptions);
716
1286
  }
717
- }, [typespecModel]);
718
- useEffect(() => {
719
- var _a;
720
- updateTypeSpec((_a = props.defaultContent) !== null && _a !== void 0 ? _a : "");
721
- }, []);
722
- useEffect(() => {
723
- if (selectedSampleName && props.samples) {
724
- const config = props.samples[selectedSampleName];
725
- if (config.content) {
726
- updateTypeSpec(config.content);
727
- if (config.preferredEmitter) {
728
- onSelectedEmitterChange(config.preferredEmitter);
729
- }
730
- if (config.compilerOptions) {
731
- onCompilerOptionsChange(config.compilerOptions);
732
- }
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
733
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
734
1405
  }
735
- }, [updateTypeSpec, selectedSampleName]);
736
- useEffect(() => {
737
- const debouncer = debounce(() => doCompile(), 200);
738
- const disposable = typespecModel.onDidChangeContent(debouncer);
739
- return () => {
740
- debouncer.clear();
741
- disposable.dispose();
742
- };
743
- }, [typespecModel, doCompile]);
744
- useEffect(() => {
745
- void doCompile();
746
- }, [doCompile]);
747
- const saveCode = useCallback(() => {
748
- if (onSave) {
749
- onSave({
750
- content: typespecModel.getValue(),
751
- emitter: selectedEmitter,
752
- options: compilerOptions,
753
- sampleName: isSampleUntouched ? selectedSampleName : undefined,
754
- });
755
- }
756
- }, [
757
- typespecModel,
758
- onSave,
759
- selectedEmitter,
760
- compilerOptions,
761
- selectedSampleName,
762
- isSampleUntouched,
763
- ]);
764
- const formatCode = useCallback(() => {
765
- var _a, _b;
766
- void ((_b = (_a = editorRef.current) === null || _a === void 0 ? void 0 : _a.getAction("editor.action.formatDocument")) === null || _b === void 0 ? void 0 : _b.run());
767
- }, [typespecModel]);
768
- const fileBug = useCallback(async () => {
769
- if (props.onFileBug) {
770
- saveCode();
771
- props.onFileBug();
772
- }
773
- }, [saveCode, typespecModel, props.onFileBug]);
774
- const typespecEditorActions = useMemo(() => [
775
- // ctrl/cmd+S => save
776
- { id: "save", label: "Save", keybindings: [KeyMod.CtrlCmd | KeyCode.KeyS], run: saveCode },
777
- ], [saveCode]);
778
- const onTypeSpecEditorMount = useCallback(({ editor }) => {
779
- editorRef.current = editor;
780
- }, []);
781
- const [verticalPaneSizes, setVerticalPaneSizes] = useState(verticalPaneSizesConst.collapsed);
782
- const toggleProblemPane = useCallback(() => {
783
- setVerticalPaneSizes((value) => {
784
- return value === verticalPaneSizesConst.collapsed
785
- ? verticalPaneSizesConst.expanded
786
- : verticalPaneSizesConst.collapsed;
787
- });
788
- }, [setVerticalPaneSizes]);
789
- const onVerticalPaneSizeChange = useCallback((sizes) => {
790
- setVerticalPaneSizes(sizes);
791
- }, [setVerticalPaneSizes]);
792
- const handleDiagnosticSelected = useCallback((diagnostic) => {
793
- var _a;
794
- (_a = editorRef.current) === null || _a === void 0 ? void 0 : _a.setSelection(getMonacoRange(host.compiler, diagnostic.target));
795
- }, [setVerticalPaneSizes]);
796
- return (jsx(PlaygroundContextProvider, { value: { host }, children: jsxs("div", { className: style$4["layout"], children: [jsxs(SplitPane, { sizes: verticalPaneSizes, onChange: onVerticalPaneSizeChange, split: "horizontal", children: [jsx(Pane, { children: jsxs(SplitPane, { initialSizes: ["50%", "50%"], children: [jsxs(Pane, { children: [jsx(EditorCommandBar, { host: host, selectedEmitter: selectedEmitter, onSelectedEmitterChange: onSelectedEmitterChange, compilerOptions: compilerOptions, onCompilerOptionsChange: onCompilerOptionsChange, samples: props.samples, selectedSampleName: selectedSampleName, onSelectedSampleNameChange: onSelectedSampleNameChange, saveCode: saveCode, formatCode: formatCode, fileBug: props.onFileBug ? fileBug : undefined, documentationUrl: (_b = props.links) === null || _b === void 0 ? void 0 : _b.documentationUrl }), jsx(TypeSpecEditor, { model: typespecModel, actions: typespecEditorActions, options: props.editorOptions, onMount: onTypeSpecEditorMount })] }), jsx(Pane, { children: jsx(OutputView, { compilationState: compilationState, editorOptions: props.editorOptions, viewers: (_c = props.emitterViewers) === null || _c === void 0 ? void 0 : _c[selectedEmitter] }) })] }) }), jsx(Pane, { minSize: 30, children: jsx(ProblemPane, { collapsed: verticalPaneSizes[1] === verticalPaneSizesConst.collapsed[1], compilationState: compilationState, onHeaderClick: toggleProblemPane, onDiagnosticSelected: handleDiagnosticSelected }) })] }), (_d = props.footer) !== null && _d !== void 0 ? _d : jsx(DefaultFooter, {})] }) }));
1406
+ ) })
1407
+ ] }),
1408
+ props.footer ?? /* @__PURE__ */ jsx(DefaultFooter, {})
1409
+ ] }) });
797
1410
  };
798
1411
  const verticalPaneSizesConst = {
799
- collapsed: [undefined, 30],
800
- expanded: [undefined, 200],
1412
+ collapsed: [void 0, 30],
1413
+ expanded: [void 0, 200]
801
1414
  };
802
1415
  const outputDir = "./tsp-output";
803
1416
  async function compile(host, content, selectedEmitter, options) {
804
- var _a;
805
- await host.writeFile("main.tsp", content);
806
- await emptyOutputDir(host);
807
- try {
808
- const typespecCompiler = host.compiler;
809
- const program = await typespecCompiler.compile(host, "main.tsp", {
810
- ...options,
811
- options: {
812
- ...options.options,
813
- [selectedEmitter]: {
814
- ...(_a = options.options) === null || _a === void 0 ? void 0 : _a[selectedEmitter],
815
- "emitter-output-dir": "tsp-output",
816
- },
817
- },
818
- outputDir: "tsp-output",
819
- emit: [selectedEmitter],
820
- });
821
- const outputFiles = await findOutputFiles(host);
822
- return { program, outputFiles };
823
- }
824
- catch (error) {
825
- // eslint-disable-next-line no-console
826
- console.error("Internal compiler error", error);
827
- return { internalCompilerError: error };
828
- }
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
+ }
829
1439
  }
830
1440
  async function findOutputFiles(host) {
831
- const files = [];
832
- async function addFiles(dir) {
833
- const items = await host.readDir(outputDir + dir);
834
- for (const item of items) {
835
- const itemPath = `${dir}/${item}`;
836
- if ((await host.stat(outputDir + itemPath)).isDirectory()) {
837
- await addFiles(itemPath);
838
- }
839
- else {
840
- files.push(dir === "" ? item : `${dir}/${item}`);
841
- }
842
- }
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
+ }
843
1451
  }
844
- await addFiles("");
845
- return files;
1452
+ }
1453
+ await addFiles("");
1454
+ return files;
846
1455
  }
847
1456
  async function emptyOutputDir(host) {
848
- // empty output directory
849
- const dirs = await host.readDir("./tsp-output");
850
- for (const file of dirs) {
851
- const path = "./tsp-output/" + file;
852
- const uri = Uri.parse(host.pathToFileURL(path));
853
- const model = editor.getModel(uri);
854
- if (model) {
855
- model.dispose();
856
- }
857
- 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();
858
1464
  }
1465
+ await host.rm(path, { recursive: true });
1466
+ }
859
1467
  }
860
1468
 
861
1469
  function useStandalonePlaygroundContext(config) {
862
- const [context, setContext] = useState();
863
- useEffect(() => {
864
- const load = async () => {
865
- const host = await createBrowserHost(config.libraries, config.importConfig);
866
- await registerMonacoLanguage(host);
867
- const stateStorage = createStandalonePlaygroundStateStorage();
868
- const initialState = stateStorage.load();
869
- setContext({ host, initialState, stateStorage });
870
- };
871
- void load();
872
- }, []);
873
- return context;
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;
874
1482
  }
875
1483
  const StandalonePlayground = (config) => {
876
- const context = useStandalonePlaygroundContext(config);
877
- const toasterId = useId$1();
878
- const { dispatchToast } = useToastController(toasterId);
879
- const onSave = useCallback((value) => {
880
- if (!context) {
881
- return;
882
- }
883
- context.stateStorage.save(value);
884
- void navigator.clipboard.writeText(window.location.toString());
885
- dispatchToast(jsxs(Toast, { children: [jsx(ToastTitle, { children: "Saved!" }), jsx(ToastBody, { children: "Playground link has been copied to the clipboard." })] }), { intent: "success" });
886
- }, [dispatchToast, context]);
887
- const fixedOptions = useMemo(() => {
888
- var _a;
889
- return context && {
890
- host: context.host,
891
- libraries: config.libraries,
892
- defaultContent: context.initialState.content,
893
- defaultEmitter: (_a = context.initialState.emitter) !== null && _a !== void 0 ? _a : config.defaultEmitter,
894
- defaultCompilerOptions: context.initialState.options,
895
- defaultSampleName: context.initialState.sampleName,
896
- };
897
- }, [context]);
898
- if (context === undefined || fixedOptions === undefined) {
899
- return config.fallback;
900
- }
901
- const options = {
902
- ...config,
903
- ...fixedOptions,
904
- onSave,
905
- };
906
- return (jsxs(Fragment, { children: [jsx(Toaster, { toasterId: toasterId }), options && jsx(Playground, { ...options })] }));
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
+ ] });
907
1527
  };
908
1528
  async function createReactPlayground(config) {
909
- return jsx(StandalonePlayground, { ...config });
1529
+ return /* @__PURE__ */ jsx(StandalonePlayground, { ...config });
910
1530
  }
911
1531
  async function renderReactPlayground(config) {
912
- const app = await createReactPlayground(config);
913
- const root = createRoot(document.getElementById("root"));
914
- root.render(jsx(FluentProvider, { theme: webLightTheme, style: { height: "100vh" }, children: app }));
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
+ );
915
1537
  }
916
1538
  function createStandalonePlaygroundStateStorage() {
917
- const stateStorage = createUrlStateStorage({
918
- content: {
919
- queryParam: "c",
920
- compress: "lz-base64",
921
- },
922
- emitter: {
923
- queryParam: "e",
924
- },
925
- options: {
926
- type: "object",
927
- queryParam: "options",
928
- },
929
- sampleName: {
930
- queryParam: "sample",
931
- },
932
- });
933
- return {
934
- load: stateStorage.load,
935
- resolveSearchParams: stateStorage.resolveSearchParams,
936
- save(data) {
937
- stateStorage.save(data.sampleName ? { sampleName: data.sampleName, options: data.options } : data);
938
- },
939
- };
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
+ };
940
1564
  }
941
1565
 
942
1566
  export { Footer, FooterItem, FooterVersionItem, Playground, StandalonePlayground, createReactPlayground, createStandalonePlaygroundStateStorage, renderReactPlayground, usePlaygroundContext };
943
- //# sourceMappingURL=index.js.map