Skip to content

Commit

Permalink
Update script.js
Browse files Browse the repository at this point in the history
  • Loading branch information
EthanThatOneKid committed Apr 2, 2024
1 parent ad3aed1 commit 24b2b2b
Showing 1 changed file with 44 additions and 9 deletions.
53 changes: 44 additions & 9 deletions static/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,20 @@ document.addEventListener("DOMContentLoaded", () => {
});
});

function makeTSConfig(version) {
return {
jsx: "react-jsx",
jsxFactory: "h",
jsxFragmentFactory: "Fragment",
jsxImportSource: `https://esm.sh/jsr/@fartlabs/jsonx@${version}`,
};
}

async function transform(options) {
const transformation = await esbuild.transform(options.code, {
loader: "tsx",
tsconfigRaw: {
compilerOptions: {
jsx: "react-jsx",
jsxFactory: "h",
jsxFragmentFactory: "Fragment",
jsxImportSource:
`https://esm.sh/jsr/@fartlabs/jsonx@${options.version}`,
},
compilerOptions: makeTSConfig(options.version),
},
});

Expand All @@ -28,18 +31,43 @@ async function transform(options) {

let monacoEditor;

function setMonacoTSConfig(version) {
monaco.languages.typescript.javascriptDefaults.setCompilerOptions(
makeTSConfig(version),
);
}

function createEditor(options) {
monaco.editor.defineTheme("jsonx", {
base: "vs-dark",
inherit: true,
// TODO: Figure out how to change fontFamily.
rules: [
{ token: "", foreground: "#ffffff" },
],
colors: {
"editor.foreground": "#ffffff",
},
});

// TODO: Figure out how to set up TypeScript intellisense.
setMonacoTSConfig(options.version);

// TODO: Figure out how to resolve this error.
//
// codicon.ttf:1
// Failed to load resource: the server responded with a status of 500 (Internal Server Error)

monacoEditor = monaco.editor.create(
options.target,
{
theme: "vs-dark",
theme: "jsonx",
fontSize: 18,
model: monaco.editor.createModel(
options.code,
"typescript",
monaco.Uri.parse("inmemory://model/main.tsx"),
),
// TODO: Figure out how to change fontFamily.
// TODO: Figure out how to paste content into the editor.
},
);
Expand Down Expand Up @@ -69,6 +97,9 @@ function createEditor(options) {
isChanged = true;
}
});
elements.version.addEventListener("change", () => {
setMonacoTSConfig(getVersion());
});
}

function sharePlayground() {
Expand Down Expand Up @@ -225,6 +256,10 @@ function getEditorCode() {
return monacoEditor.getModel().getValue();
}

function getVersion() {
return elements.version.value;
}

/**
* elements of the playground.
*/
Expand Down

0 comments on commit 24b2b2b

Please sign in to comment.