diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f33f26a8..9e1f3bfb 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -72,6 +72,19 @@ jobs: npm run build npm run test npm run build:production + npm run bundle + + - name: Check SharedConfig.purs versions + run: | + cd client + cp src/Try/SharedConfig.purs sharedConfig.out + node updateSharedConfigVersions.mjs sharedConfig.out + diff src/Try/SharedConfig.purs sharedConfig.out || { + echo 'PureScript and/or package set versions in "client/src/Try/SharedConfig.purs"' + echo 'do not match the versions extracted from "stack.yaml" and "staging/packages.dhall".' + echo 'Please run "cd client && npm run updateConfigVersions". CI will fail until then.' + exit 1 + } - name: Build client assets if: github.event_name == 'release' diff --git a/.gitignore b/.gitignore index eb1860a6..a7fcc9b6 100644 --- a/.gitignore +++ b/.gitignore @@ -15,3 +15,4 @@ cabal.sandbox.config *.lksh* bundle/ client/public/js/output +client/client.js diff --git a/CHANGELOG.md b/CHANGELOG.md index 36d46714..e73a1d66 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,116 @@ Notable changes to this project are documented in this file. The format is based ## [Unreleased] +Breaking changes: + +New features: + +Bugfixes: + +Other improvements: + +## [v2023-12-22.1](https://github.com/purescript/trypurescript/releases/tag/v2023-12-22.1) + +Other improvements: +- Bump PureScript to `0.15.13` (#306 by @JordanMartinez) +- Update to latest package set (#306 by @JordanMartinez) + +## [v2023-07-18.1](https://github.com/purescript/trypurescript/releases/tag/v2023-07-18.1) + +Other improvements: +- Bump PureScript to `0.15.10` (#310 by @JordanMartinez) +- Update to latest package set (#310 by @JordanMartinez) + +## [v2023-03-06.1](https://github.com/purescript/trypurescript/releases/tag/v2023-03-06.1) + +Other improvements: +- Bump PureScript to `0.15.8` (#305 by @JordanMartinez) +- Update to latest package set (#305 by @JordanMartinez) + +## [v2022-12-12.1](https://github.com/purescript/trypurescript/releases/tag/v2022-12-12.1) + +Other improvements: +- Update main example to note that editor state is persisted in the URL (#300 by @thomashoneyman) +- Update PureScript to `0.15.7` (#302 by @JordanMartinez) +- Update to latest package set (#302 by @JordanMartinez) + +## [v2022-09-10.1](https://github.com/purescript/trypurescript/releases/tag/v2022-09-10.1) + +New features: +- Remove `localStorage` for session storage, persist editor state in URL query param (#299 by @ptrfrncsmrph) + +## [v2022-08-16.1](https://github.com/purescript/trypurescript/releases/tag/v2022-08-16.1) + +Other improvements: +- Update `es-module-shims` to 1.5.12 (#298 by @andys8) + +## [v2022-08-12.1](https://github.com/purescript/trypurescript/releases/tag/v2022-08-12.1) + +Bugfixes: +- Add missing `react-dom/client` shim (#294 by @andys8) +- Fix double `main` invocation (#295 by @JordanMartinez) +- Stop loading hang when using query params to show compiled JS output (#296 by @JordanMartinez) + +Other improvements: +- Update package set to latest `0.15.4` one (#294) by @andys8) + +## [v2022-07-21.1](https://github.com/purescript/trypurescript/releases/tag/v2022-07-21.1) + +Bugfixes: +- Fix `Reference Error: main is not defined` bug: (#288 by @JordanMartinez) +- Fix `Unknown type Effect` bug in examples (#292 by @ptrfrncsmrph) +- Fix NPM dependency shims on Firefox 100+ (#289 by @JordanMartinez) +- Fix import maps for React deps by bumping version to 17.0.2 (#289 by @JordanMartinez) + +Other improvements: +- Update `es-module-shims` to 1.5.9 (#289 by @JordanMartinez) + +## [v2022-07-15.1](https://github.com/purescript/trypurescript/releases/tag/v2022-07-15.1) + +Other improvements: +- Drop requirement that module name be `Main` (#285 by @JordanMartinez) +- Fixes compiler warnings in examples (#286 by @JordanMartinez) +- Support cookbook repo UI recipes by adding element to `frame.html` (#286 by @JordanMartinez) +- Update to latest package set (#287 by @JordanMartinez) + +## [v2022-07-12.1](https://github.com/purescript/trypurescript/releases/tag/v2022-07-12.1) + +Other improvements: +- Update to PureScript 0.15.4 (#281 by @JordanMartinez) + +## [v2022-06-24.1](https://github.com/purescript/trypurescript/releases/tag/v2022-06-24.1) + +Other improvements: +- Update to PureScript 0.15.3 (#281 by @JordanMartinez) +- Update codebase to GHC 9.2.3 (#281 by @JordanMartinez) + +## [v2022-06-18.1](https://github.com/purescript/trypurescript/releases/tag/v2022-06-18.1) + +New features: +- Clearly indicate PureScript and package set version (#280 by @JordanMartinez) + +Bugfixes: +- Stop double `main` invocation by updating `es-module-shims` to 1.5.6 (#279 by @JordanMartinez) + +## [v2022-06-10.2](https://github.com/purescript/trypurescript/releases/tag/v2022-06-10.2) + +Other improvements: +- Update client to 0.15.2; bundle via esbuild (#278 by @JordanMartinez) + +## [v2022-06-10.1](https://github.com/purescript/trypurescript/releases/tag/v2022-06-10.1) + +Bugfixes: +- Fix the URL used for getting module dependencies of `Main` (#277 by @JordanMartinez) +- Update alias to refer to correct location on server (#277 by @JordanMartinez) + +## [v2022-06-08.1](https://github.com/purescript/trypurescript/releases/tag/v2022-06-08.1) + +Breaking changes: +- update compiler to v0.15.2 (#275 by @JordanMartinez) +- Update package set to latest `0.15.2` one (#275 by @JordanMartinez) + +## [v2022-02-25.1](https://github.com/purescript/trypurescript/releases/tag/v2022-02-25.1) + Breaking changes: - Update compiler to v0.14.7 (#271 by @JordanMartinez) diff --git a/README.md b/README.md index 0ffda87b..7e8671d0 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ - PureScript syntax highlighting - Run and print output or show resulting JavaScript - Multiple view modes: code, output or both -- Persistent session +- Shareable code and editor state via URL - Load PureScript code from GitHub Gists or repository files ### Control Features via the Query String @@ -28,6 +28,11 @@ Most of these features can be controlled not only from the toolbar, but also usi - Example: `gist=37c3c97f47a43f20c548` - Notes: the file should be named `Main.purs` with the module name `Main`. +- **Load From URL**: Load compressed PureScript code using the `code` parameter + - Managed by Try PureScript and updated on editor state change to create shareable URLs + - Format: `code=` + - Example: `code=LYewJgrgNgpgBAWQIYEsB2cDuALGAnGIA` will set the editor state to the single line `module Main where` + - **View Mode**: Control the view mode using the `view` parameter - Options are: `code`, `output`, `both` (default) - Example: `view=output` will only display the output @@ -40,11 +45,6 @@ Most of these features can be controlled not only from the toolbar, but also usi - Options are: `true`, `false` (default) - Example: `js=true` will print JavaScript code instead of the program's output -- **Session**: Load code from a session which is stored with [localStorage](https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage) using the `session` parameter - - Usually managed by Try PureScript - - Example: `session=9162f098-070f-4053-60ea-eba47021450d` (Note: will probably not work for you) - - When used with the `gist` or `github` query parameters the code will be loaded from the source file and not the session - ### Which Libraries Are Available? Try PureScript aims to provide a complete, recent package set from . The available libraries are those listed in [`staging/spago.dhall`](./staging/spago.dhall), at the versions in the package set mentioned in [`staging/packages.dhall`](./staging/packages.dhall). @@ -96,15 +96,15 @@ ln -s "$PWD/output" "$PWD/../client/public/js/output" cd client npm install -# Use `build:dev` if you are using a local Try PureScript server, e.g. you -# followed the instructions in step 1. +# Use `serve:dev` if you are using a local Try PureScript server, +# e.g. you followed the instructions in step 1. # -# Use `build:production` if you would like to test the client against the production -# Try PureScript server. -npm run build:(dev|production) +# Use `serve:production` if you would like +# to test the client against the production Try PureScript server. +# Note: the production server may not match the package set you have locally. +npm run serve:(dev|production) -cd public -npx http-server # Try PureScript is now available on localhost:8080 +# Try PureScript is now available on localhost:8080 ``` ### 4. Choosing a Tag diff --git a/RELEASE.md b/RELEASE.md index 8f264c9e..e800d072 100644 --- a/RELEASE.md +++ b/RELEASE.md @@ -5,11 +5,16 @@ After making a new compiler release, do the following to redeploy Try PureScript using the new compiler. 1. Submit a PR with the following changes: - - In `stack.yaml`, update `purescript` (and possibly `purescript-cst`) to use its new version. - - If you are updating the package set, see the next section for instructions. -1. Once the PR is merged, create a new GitHub tagged release using `vYYYY-MM-DD.X` (where `X` is usually `1` or the release attempt) as the version schema. The release will trigger a GitHub Actions build. -2. Wait for the GitHub Actions build to finish (it builds the assets) -3. Run `./deploy/run.sh vX-X-X.1`, replacing `vX-X-X.1` with the version you created. + - In `stack.yaml`, + - update the `resolver` to match the same one used in the PureScript repo + - update `purescript` to use its new version. + - Update the package set (see next section's instructions). + - Update the shared config by running `cd client && npm run updateConfigVersions`. + - Update the changelog to include the next release's date. +2. Once the PR is merged, create a new GitHub tagged release using `vYYYY-MM-DD.X` (where `X` is usually `1` or the release attempt) as the version schema. The release will trigger a GitHub Actions build. +3. Wait for the GitHub Actions build to finish (it builds the assets) +4. Run `./deploy/run.sh vX-X-X.1`, replacing `vX-X-X.1` with the version you created. + - Note: if you're updating the compiler, be sure to push the corresponding tag to [`purescript-metadata`](https://github.com/purescript/purescript-metadata). Otherwise, `spago install` will fail on the server and prevent the server from starting. ## Updating the Package Set @@ -17,7 +22,30 @@ The try.purescript.org server only has a limited amount of memory. If the packag Before deploying an updated package set, someone (your reviewer) should check that the memory required to hold the package set's externs files does not exceed that of the try.purescript.org server. -Update the package set by doing the following: +Update the package set by doing the following. Each step is explained below: + +### Summary + +```sh +pushd staging +spago upgrade-set +cat > spago.dhall << EOF +{ name = "try-purescript-server" +, dependencies = [] : List Text +, packages = ./packages.dhall +, sources = [ "src/**/*.purs" ] +} +EOF +spago ls packages | cut -f 1 -d ' ' | xargs spago install +popd +pushd client +npm run updateConfigVersions +popd +# add any new shims +# update ES Module Shims (if needed) +``` + +### Step-by-Step Explanation 1. Update the `upstream` package set in `staging/packages.dhall`: @@ -30,12 +58,37 @@ Update the package set by doing the following: ```dhall { name = "try-purescript-server" , dependencies = [] : List Text - , ... + , packages = ./packages.dhall + , sources = [ "src/**/*.purs" ] } ``` -3. Install all packages in the package set by running this command: +3. For `staging/spago.dhall`, install all packages in the package set by running this command: ``` $ spago ls packages | cut -f 1 -d ' ' | xargs spago install ``` + +4. Update the `client/src/Try/SharedConfig.purs` file by running this command in `client`: + + ```console + $ npm run updateConfigVersions + ``` + +5. If any packages need NPM dependencies, you can try adding their shims to the import map in `client/public/frame.html` + - Open up the `generator.jspm.io` URL in the comment + - Use the 'Add Dependency' search bar to find the NPM dependency + - If it exists but doesn't exist in that CDN, you can try another one or [open an issue on `jspm/project`](https://github.com/jspm/project#issue-queue-for-the-jspm-cdn) + - Update the version to the one you need once added + - If needed, include other files from that dependency + - Copy and paste the content into the `client/public/frame.html` file + - Ensure `es-module-shims` has version `1.5.9` or greater. + +6. If `es-module-shims` releases a new version, you can calculate its SHA-384 via + + ```console + $ ESM_VERSION=1.5.5 + $ curl -L -o es-module-shims.js "https://ga.jspm.io/npm:es-module-shims@$ESM_VERSION/dist/es-module-shims.js" + $ echo "sha384-$(openssl dgst -sha384 -binary es-module-shims.js | openssl base64 -A)" + $ rm es-module-shims.js + ``` diff --git a/client/config/dev/Try.Config.purs b/client/config/dev/Try.Config.purs index e81be3b2..b3551a5c 100644 --- a/client/config/dev/Try.Config.purs +++ b/client/config/dev/Try.Config.purs @@ -3,7 +3,7 @@ module Try.Config where import Prelude loaderUrl :: String -loaderUrl = "js/output" +loaderUrl = "/js/output" compileUrl :: String compileUrl = "http://localhost:8081" diff --git a/client/examples/ADTs.purs b/client/examples/ADTs.purs index 5bc0dec5..0f5214b5 100644 --- a/client/examples/ADTs.purs +++ b/client/examples/ADTs.purs @@ -2,6 +2,7 @@ module Main where import Prelude +import Effect (Effect) import Effect.Console (logShow) import Data.Map (Map, lookup, singleton) import TryPureScript (render, withConsole) @@ -19,5 +20,6 @@ derive instance ordName :: Ord Name phoneBook :: Map Name String phoneBook = singleton (Name "John" "Smith") "555-555-1234" +main :: Effect Unit main = render =<< withConsole do logShow (lookup (Name "John" "Smith") phoneBook) diff --git a/client/examples/DoNotation.purs b/client/examples/DoNotation.purs index 98bc3141..2a01fc19 100644 --- a/client/examples/DoNotation.purs +++ b/client/examples/DoNotation.purs @@ -2,10 +2,11 @@ module Main where import Prelude import Control.MonadPlus (guard) +import Effect (Effect) import Effect.Console (logShow) import Data.Array ((..)) import Data.Foldable (for_) -import TryPureScript +import TryPureScript (render, withConsole) -- Find Pythagorean triples using an array comprehension. triples :: Int -> Array (Array Int) @@ -16,5 +17,6 @@ triples n = do guard $ x * x + y * y == z * z pure [x, y, z] +main :: Effect Unit main = render =<< withConsole do for_ (triples 20) logShow diff --git a/client/examples/Generic.purs b/client/examples/Generic.purs index 1fea8470..ba7fdd5f 100644 --- a/client/examples/Generic.purs +++ b/client/examples/Generic.purs @@ -1,6 +1,7 @@ module Main where import Prelude +import Effect (Effect) import Effect.Console (logShow) import Data.Generic.Rep (class Generic) import Data.Eq.Generic (genericEq) @@ -45,6 +46,7 @@ instance eqPerson :: Eq Person where instance ordPerson :: Ord Person where compare = genericCompare +main :: Effect Unit main = render =<< withConsole do logShow $ Person { first: "John" diff --git a/client/examples/Loops.purs b/client/examples/Loops.purs index fc0e1290..90ee46e5 100644 --- a/client/examples/Loops.purs +++ b/client/examples/Loops.purs @@ -2,11 +2,13 @@ module Main where import Prelude +import Effect (Effect) import Effect.Console (log) import Data.Array ((..)) import Data.Foldable (for_) import TryPureScript (render, withConsole) +main :: Effect Unit main = render =<< withConsole do for_ (10 .. 1) \n -> log (show n <> "...") log "Lift off!" diff --git a/client/examples/Main.purs b/client/examples/Main.purs index 264976c9..e7f21d5e 100644 --- a/client/examples/Main.purs +++ b/client/examples/Main.purs @@ -14,7 +14,8 @@ main = , h2 (text "Examples") , list (map fromExample examples) , h2 (text "Share Your Code") - , p (text "A PureScript file can be loaded from GitHub from a gist or a repository. To share code using a gist, simply include the gist ID in the URL as follows:") + , p (text "The contents of the text editor are stored in the URL. To share your code you can simply copy the URL.") + , p (text "Additionally, a PureScript file can be loaded from GitHub from a gist or a repository. To share code using a gist, include the gist ID in the URL as follows:") , indent (p (code (text " try.purescript.org?gist="))) , p (fold [ text "The gist should contain PureScript module named " diff --git a/client/examples/Operators.purs b/client/examples/Operators.purs index 23f56351..b5a9919f 100644 --- a/client/examples/Operators.purs +++ b/client/examples/Operators.purs @@ -1,6 +1,7 @@ module Main where import Prelude +import Effect (Effect) import Effect.Console (log) import TryPureScript (render, withConsole) @@ -16,5 +17,6 @@ infixl 5 subdirectory as filepath :: FilePath filepath = "usr" "local" "bin" +main :: Effect Unit main = render =<< withConsole do log filepath diff --git a/client/examples/QuickCheck.purs b/client/examples/QuickCheck.purs index e513109d..72079957 100644 --- a/client/examples/QuickCheck.purs +++ b/client/examples/QuickCheck.purs @@ -2,9 +2,11 @@ module Main where import Prelude import Data.Array (sort) +import Effect (Effect) import Test.QuickCheck (quickCheck, (===)) import TryPureScript (render, withConsole, h1, h2, p, text) +main :: Effect Unit main = do render $ h1 $ text "QuickCheck" render $ p $ text """QuickCheck is a Haskell library which allows us to assert properties diff --git a/client/examples/Records.purs b/client/examples/Records.purs index deba7d99..0425e2a4 100644 --- a/client/examples/Records.purs +++ b/client/examples/Records.purs @@ -1,14 +1,17 @@ module Main where import Prelude +import Effect (Effect) import Effect.Console (log) import TryPureScript (render, withConsole) -- We can write functions which require certain record labels... +showPerson :: forall r. { firstName :: String, lastName :: String | r } -> String showPerson o = o.lastName <> ", " <> o.firstName -- ... but we are free to call those functions with any -- additional arguments, such as "age" here. +main :: Effect Unit main = render =<< withConsole do log $ showPerson { firstName: "John" diff --git a/client/examples/Recursion.purs b/client/examples/Recursion.purs index fd213181..0d511e60 100644 --- a/client/examples/Recursion.purs +++ b/client/examples/Recursion.purs @@ -1,6 +1,7 @@ module Main where import Prelude +import Effect (Effect) import Effect.Console (logShow) import TryPureScript (render, withConsole) @@ -12,6 +13,7 @@ isEven :: Int -> Boolean isEven 0 = true isEven n = isOdd (n - 1) +main :: Effect Unit main = render =<< withConsole do logShow $ isEven 1000 logShow $ isEven 1001 diff --git a/client/examples/TypeClasses.purs b/client/examples/TypeClasses.purs index 5853abf6..b0ca16e8 100644 --- a/client/examples/TypeClasses.purs +++ b/client/examples/TypeClasses.purs @@ -1,6 +1,7 @@ module Main where import Prelude +import Effect (Effect) import Effect.Console (log) import TryPureScript (render, withConsole) @@ -39,6 +40,7 @@ printf = printfWith "" debug :: String -> Int -> String -> String debug uri status msg = printf "[" uri "] " status ": " msg +main :: Effect Unit main = render =<< withConsole do log $ debug "http://www.purescript.org" 200 "OK" log $ debug "http://bad.purescript.org" 404 "Not found" diff --git a/client/package.json b/client/package.json index fc071535..1e937d81 100644 --- a/client/package.json +++ b/client/package.json @@ -5,13 +5,25 @@ "clean": "rimraf output", "test": "spago test --path config/dev/Try.Config.purs", "build": "spago build --path config/dev/Try.Config.purs", - "build:dev": "spago bundle-app --path config/dev/Try.Config.purs --to public/js/index.js", - "build:production": "spago bundle-app --path config/prod/Try.Config.purs --purs-args '--censor-lib --strict' --to public/js/index.js" + "build:dev": "spago bundle-app --path config/dev/Try.Config.purs --to client.js", + "build:production": "spago bundle-app --path config/prod/Try.Config.purs --purs-args '--censor-lib --strict' --to client.js", + "bundle": "esbuild --outfile=public/js/index.js --bundle --minify --platform=browser --format=iife --tree-shaking=true client.js", + "serve": "http-server public/ -o / --cors=\"Access-Control-Allow-Origin: *\" -c-1", + "serve:dev": "npm run build:dev && npm run bundle && npm run serve", + "serve:production": "npm run build:production && npm run bundle && npm run serve", + "updateConfigVersions": "node updateSharedConfigVersions.mjs src/Try/SharedConfig.purs" }, "devDependencies": { - "purescript": "^0.13.6", - "purescript-psa": "^0.7.3", + "esbuild": "^0.14.43", + "http-server": "^14.1.0", + "purescript": "^0.15.2", + "purescript-psa": "^0.8.2", "rimraf": "^2.5.4", - "spago": "^0.14.0" + "spago": "^0.20.9" + }, + "dependencies": { + "ace-builds": "^1.5.0", + "jquery": "^1.12.4", + "lz-string": "^1.4.4" } } diff --git a/client/packages.dhall b/client/packages.dhall index 75331a36..c21f1de2 100644 --- a/client/packages.dhall +++ b/client/packages.dhall @@ -1,22 +1,5 @@ let upstream = - https://github.com/purescript/package-sets/releases/download/psc-0.13.6-20200404/packages.dhall sha256:f239f2e215d0cbd5c203307701748581938f74c4c78f4aeffa32c11c131ef7b6 + https://github.com/purescript/package-sets/releases/download/psc-0.15.4-20220808/packages.dhall + sha256:60eee64b04ca0013fae3e02a69fc3b176105c6baa2f31865c67cd5f881a412fd -let additions = - { ace = - { repo = "https://github.com/purescript-contrib/purescript-ace.git" - , version = "v7.0.0" - , dependencies = - [ "arrays" - , "console" - , "effect" - , "foreign" - , "nullable" - , "prelude" - , "refs" - , "web-html" - , "web-uievents" - ] - } - } - -in upstream // additions +in upstream diff --git a/client/public/css/index.css b/client/public/css/index.css index e6e32b51..acd2322f 100644 --- a/client/public/css/index.css +++ b/client/public/css/index.css @@ -263,10 +263,47 @@ iframe { margin-bottom: 10px; } + +footer { + background-color: #1d222d; + display: flex; + flex-direction: row; + justify-content: center; + gap: 5px; +} + + footer .footer-separator { + color: white; + } + + footer .footer-link { + display: flex; + min-width: 300px; + gap: 2px; + color: white; + } + + footer .footer-link a { + color: white; + } + + footer .footer-link a:visited { + color: white; + } + @media all and (max-width: 720px) { .no-mobile { display: none; } + + footer { + flex-direction: column; + align-items: center; + } + + footer .footer-link { + min-width: initial; + } } @media all and (min-width: 720px) { diff --git a/client/public/frame.html b/client/public/frame.html index ba347939..7a5f8d59 100644 --- a/client/public/frame.html +++ b/client/public/frame.html @@ -5,9 +5,39 @@ + + + + + + + + -
+
+
diff --git a/client/public/index.html b/client/public/index.html index 44a29b24..2cdc56ce 100644 --- a/client/public/index.html +++ b/client/public/index.html @@ -19,67 +19,6 @@ - diff --git a/client/public/js/frame.js b/client/public/js/frame.js index f0d0a6ff..2f277b67 100644 --- a/client/public/js/frame.js +++ b/client/public/js/frame.js @@ -1,42 +1,15 @@ (function() { - function evalSources(sources) { - var modules = {}; - function dirname(str) { - var ix = str.lastIndexOf("/"); - return ix < 0 ? "" : str.slice(0, ix); - } - function resolvePath(a, b) { - if (b[0] === "." && b[1] === "/") { - return dirname(a) + b.slice(1); - } - if (b[0] === "." && b[1] === "." && b[2] === "/") { - return dirname(dirname(a)) + b.slice(2); - } - return b; - } - return function load(name) { - if (modules[name]) { - return modules[name].exports; - } - function require(path) { - return load(resolvePath(name, path)); - } - var module = modules[name] = { exports: {} }; - new Function("module", "exports", "require", sources[name])(module, module.exports, require); - return module.exports; - }; - } - var parent; document.addEventListener("DOMContentLoaded", function() { window.addEventListener("message", function(event) { parent = event.source; parent.postMessage("trypurescript", "*"); - var file = evalSources(event.data)(""); - if (file.main && typeof file.main === "function") { - file.main(); - } + const code = event.data.code; + const scriptEl = document.createElement("script"); + scriptEl.type = "module"; + scriptEl.appendChild(document.createTextNode(code)); + document.body.appendChild(scriptEl); }, { once: true }); }, { once: true }); diff --git a/client/spago.dhall b/client/spago.dhall index d8c65090..44a9bbdf 100644 --- a/client/spago.dhall +++ b/client/spago.dhall @@ -3,14 +3,15 @@ [ "ace" , "aff" , "affjax" + , "affjax-web" , "argonaut-codecs" + , "argonaut-core" , "arrays" , "assert" , "bifunctors" , "console" - , "const" , "control" - , "debug" + , "datetime" , "effect" , "either" , "exceptions" @@ -18,26 +19,25 @@ , "foreign-object" , "functions" , "functors" - , "globals" , "halogen" - , "identity" + , "halogen-subscriptions" , "integers" , "js-timers" - , "math" + , "js-uri" + , "lists" , "maybe" + , "newtype" + , "node-buffer" , "node-fs" - , "ordered-collections" - , "parallel" + , "nullable" + , "partial" , "prelude" - , "profunctor" - , "psci-support" , "random" , "refs" - , "semirings" , "strings" , "transformers" , "tuples" - , "unfoldable" + , "unsafe-coerce" , "web-html" ] , packages = ./packages.dhall diff --git a/client/src/Main.purs b/client/src/Main.purs index 8c3d781c..2ba63761 100644 --- a/client/src/Main.purs +++ b/client/src/Main.purs @@ -9,6 +9,6 @@ import Halogen.VDom.Driver (runUI) import Try.Container as Container main :: Effect Unit -main = launchAff_ do +main = void $ launchAff_ do body <- HA.awaitBody - runUI Container.component unit body + void $ runUI Container.component unit body diff --git a/client/src/Try/API.purs b/client/src/Try/API.purs index afe533c6..4de89e3d 100644 --- a/client/src/Try/API.purs +++ b/client/src/Try/API.purs @@ -14,13 +14,15 @@ module Try.API import Prelude import Affjax (URL, printError) -import Affjax as AX import Affjax.RequestBody as AXRB import Affjax.ResponseFormat as AXRF import Affjax.StatusCode (StatusCode(..)) +import Affjax.Web as AX import Control.Alt ((<|>)) import Control.Monad.Except (ExceptT(..)) -import Data.Argonaut.Decode (class DecodeJson, decodeJson, (.:)) +import Data.Argonaut.Decode (class DecodeJson, JsonDecodeError(..), decodeJson, printJsonDecodeError, (.:)) +import Data.Argonaut.Encode (encodeJson) +import Data.Bifunctor (lmap) import Data.Either (Either(..)) import Data.Maybe (Maybe(..)) import Data.Traversable (traverse) @@ -53,8 +55,8 @@ instance decodeJsonCompileError :: DecodeJson CompileError where map OtherError $ decodeJson contents "CompilerErrors" -> map CompilerErrors $ traverse decodeJson =<< decodeJson contents - _ -> - Left "Tag must be one of: OtherError, CompilerErrors" + j -> + Left $ AtKey "tag" $ UnexpectedValue $ encodeJson $ "- Expected a value of `OtherError` or `CompilerErrors` but got '" <> j <> "'" type Suggestion = { replacement :: String @@ -105,6 +107,6 @@ compile endpoint code = ExceptT $ liftAff $ AX.post AXRF.json (endpoint <> "/com Right { status } | status >= StatusCode 400 -> pure $ Left $ "Received error status code: " <> show status Right { body } -> - pure $ Right $ decodeJson body + pure $ Right $ lmap printJsonDecodeError $ decodeJson body where requestBody = Just $ AXRB.string code diff --git a/client/src/Try/Container.js b/client/src/Try/Container.js index 8c26089e..bc558045 100644 --- a/client/src/Try/Container.js +++ b/client/src/Try/Container.js @@ -1,4 +1,70 @@ -"use strict"; +$.ajaxSetup({ + dataType: "text", +}); -exports.setupIFrame = setupIFrame; -exports.teardownIFrame = teardownIFrame; +export function teardownIFrame() { + var $ctr = $("iframe#output-iframe"); + $ctr.remove() +} + +export function setupIFrame(data, loadCb, failCb) { + var $ctr = $("#column2"); + var $iframe = $( + '