Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
ec2d785
Start moving the playground into v2
orta Dec 26, 2019
2b9b853
Make a working playground and sandbox
orta Dec 26, 2019
e3be9cd
Bootstrap
orta Dec 26, 2019
271f332
fixes some urls
orta Dec 26, 2019
d599d0a
Sidebars and plugins for the playground
orta Dec 26, 2019
142d004
Adds some useful helpers to the sandbox
orta Dec 27, 2019
a8c72b6
Vendor the tsworker types
orta Dec 27, 2019
81f3875
Adds the sidebar for playground, and gets some of the infra running f…
orta Dec 29, 2019
10d3765
Docs
orta Dec 29, 2019
370c54d
Fix playground and add json to the watcher to trigger builds
orta Dec 29, 2019
9bed4f7
Some CI faff
orta Dec 29, 2019
d5421dc
Adds some nav and infra
orta Dec 29, 2019
e79dd88
More work on the playground
orta Dec 30, 2019
c000ec9
Make tests green
orta Dec 31, 2019
4627aa3
Add a one-liner to every compiler flag
orta Dec 31, 2019
3e121f1
Add a bootstrap command
orta Dec 31, 2019
f6a8740
Playground work
orta Dec 31, 2019
c937c93
Get green
orta Dec 31, 2019
67984e8
Show examples
orta Jan 2, 2020
e7f3afc
Adds caching to the ATA
orta Jan 2, 2020
b33592f
Hook up more buttons on the playground
orta Jan 2, 2020
f82cfc5
Set up i8n for playground samples
orta Jan 2, 2020
c6c26e6
Create the exaples dir
orta Jan 2, 2020
0c0daf5
Grab examples
orta Jan 2, 2020
d0851b0
Make the default height the size of the window
orta Jan 2, 2020
5e66299
Merge branch 'v2' of https://github.com/microsoft/TypeScript-website …
orta Jan 2, 2020
63fdbf9
Bring back clicking on links
orta Jan 2, 2020
259a9e3
Add/remove the examples
orta Jan 2, 2020
b0bb817
Migrate from pirate to leet, adds initial work for showing compiler c…
orta Jan 3, 2020
3a6c116
Compiler options
orta Jan 4, 2020
aaa832b
Adds compiler settings to the new playground
orta Jan 4, 2020
b6a116e
Add some dropdowns
orta Jan 5, 2020
ca89abb
Handle updating the compiler flags
orta Jan 6, 2020
0792608
Test fixes
orta Jan 6, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Docs
  • Loading branch information
orta committed Dec 29, 2019
commit 10d37651f6c2a6a470be6d94655c619a5f68593e
19 changes: 9 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ yarn bootstrap
code .
```

Working on this repo is done by running `yarn start` - this starts up the website on port `8000` and creates a
builder worker for every package in the repo, so if you make a change outside of the site it will compile and lint etc.

# Website Packages

## TypeScriptLang-Org
Expand All @@ -20,18 +23,14 @@ The main website for TypeScript, a Gatsby website which is statically deployed.
yarn start
```

## Playground

A React component for the TypeScript playground base component. Not the one available on
the site, but one you can use in other websites for showing off your APIs.
## Sandbox

You can work on the playground by running:
The editor aspect of the TypeScript Playground REPL, useable for all sites which want to show a monaco editor
with TypeScript or JavaScript code.

```sh
yarn playground
```
## Playground

Then opening: http://localhost:1234 - which is the below package.
The JS code as an AMD module for the playground which is loaded at runtime in the Playground website.

# Doc Packages

Expand All @@ -54,7 +53,7 @@ yarn workspace tsconfig-reference run test
# or to just run the linter without a build
yarn workspace tsconfig-reference run lint

# or to just one one linter
# or to just one one linter for a single doc
yarn workspace tsconfig-reference run lint resolveJson
```

Expand Down
27 changes: 13 additions & 14 deletions packages/playground/README.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
# TypeScript Sandbox
# TypeScript Playground

The TypeScript Sandbox is the editor part of the TypeScript Playground. It's effectively an opinionated fork of
monaco-typescript with extra extension points so that projects like the TypeScript Playground can exist.
This is the JS tooling which powers the https://www.typescriptlang.org/play/

This project is useful to you if:
It is more or less vanilla DOM-oriented JavaScript with as few dependencies as possible. Originally based on the
work by [Artem Tyurin](https://github.com/agentcooper/typescript-play) but now it's pretty far from that fork.

- You want to improve the TypeScript Playground
- You want to present users of your library with a JS editor which has a typed API (in JS or TS)
## Architecture

## Goals
q
- Support multiple versions of TypeScript (via supporting older builds of monaco-typescript)
- Easy to use when trying to replace code inline on a website
- Support extension points required to build Playground
- High level APIs for things like Automatic Type Acquisition or DTS additions
The playground library sits above the [TypeScript sandbox](../Sandbox), and provides features like:

## Builds
- The code samples support
- The navigation bars, and compiler flags UI
- The sidebar plugin infrastructure for showing JS/DTS/etc
- The export to Code Sandbox/TS AST Viewer/etc features

CJS, ESModules, and UMD module formats are supported.
When deciding where to add a feature to the TypeScript playground, consider if it would be useful to anyone showing
TypeScript in a REPL. If yes, add it to the playground and expose a function for this library to use. For example
Automatic Type Acquisition is a feature which lives in the sandbox and not the playground.
1 change: 1 addition & 0 deletions packages/playground/src/nav/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const createNav = () => {}
59 changes: 55 additions & 4 deletions packages/sandbox/README.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,71 @@
# TypeScript Sandbox

The TypeScript Sandbox is the editor part of the TypeScript Playground. It's effectively an opinionated fork of
The TypeScript Sandbox is the editor part of the TypeScript Playground. It's effectively an opinionated fork of
monaco-typescript with extra extension points so that projects like the TypeScript Playground can exist.

This project is useful to you if:

- You want to improve the TypeScript Playground
- You want to present users of your library with a JS editor which has a typed API (in JS or TS)
- You want to work with monaco at a higher abstraction level

## Goals
q

- Support multiple versions of TypeScript (via supporting older builds of monaco-typescript)
- Easy to use when trying to replace code inline on a website
- Support extension points required to build Playground
- High level APIs for things like Automatic Type Acquisition or DTS additions

## Builds

CJS, ESModules, and UMD module formats are supported.
This library currently ships as an AMD module. This is the same format that vscode/monaco use, and so you can use
the same runtime loader patterns for importing into your web page. It is not a goal to provide ESM builds so people
can run JS packagers over the project. If someone can make that work and have tests which validate it doesn't break,
we'll accept it.

## Installation

```html
<html>
<div id="loader">Loading...</div>
<div id="monaco-editor-embed" />
<script>
// First set up the VSCode loader in a script tag
const getLoaderScript = document.createElement('script');
getLoaderScript.src = "https://typescriptlang.org/v2/js/vs.loader.js";
getLoaderScript.async = true;
getLoaderScript.onload = () => {

// Now the loader is ready, tell require where it can get the version of monaco, and the sandbox
// This version uses the latest version of the sandbox, which is used on the TypeScript website
require.config({
paths: {
vs: "https://tswebinfra.blob.core.windows.net/cdn/3.7.3/monaco/min/vs",
sandbox: 'https://typescriptlang.org/v2/js/sandbox'
},
// This is something you need for monaco to work
ignoreDuplicateModules: ["vs/editor/editor.main"],
});

// Grab a copy of monaco, TypeScript and the sandbox
require(["vs/editor/editor.main", "vs/language/typescript/tsWorker", "sandbox/index"], async (main, ts, sandbox) => {
const initialCode = `import {markdown} from "danger"\n\nmarkdown("OK")`

const isOK = main && ts && sandbox
if (isOK) {
document.getElementById("loader")!.parentNode?.removeChild(document.getElementById("loader")!)
} else {
console.error("Could not get all the dependencies of sandbox set up!")
console.error("main", !!main, "ts", !!ts, "sandbox", !!sandbox)
return
}

// Create a sandbox and embed it into the the div #monaco-editor-embed
const playground = await sandbox.createTypeScriptSandbox({ text: initialCode, compilerOptions: {}, domID: "monaco-editor-embed", useJavaScript: false }, main, ts)
playground.editor.focus()
});
}

document.body.appendChild(getLoaderScript);
</script>
</html>
```
4 changes: 2 additions & 2 deletions packages/typescriptlang-org/src/components/layout/TopNav.scss
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,12 @@ html,
svg {
margin-right: 0.6rem;
margin-left: 1rem;
margin-top: 0.68rem;
margin-top: 0.48rem;
}

span {
position: relative;
top: -0.4rem;
top: -0.5rem;
text-decoration: none;
}
}
Expand Down