|
2 | 2 | import {createEditor} from "./editor.js";
|
3 | 3 | import {onMount} from "svelte";
|
4 | 4 |
|
5 |
| - let editor; |
| 5 | + let editor, editorMount; |
6 | 6 | onMount(() => {
|
7 | 7 | const resultMatch = window.location.pathname.match(/^\/r\/([0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12})$/i);
|
8 | 8 | if (resultMatch !== null) {
|
9 |
| - fetchResult(resultMatch[1]); |
| 9 | + fetchResult(resultMatch[1]) |
| 10 | + .then(() => { |
| 11 | + editor.dispatch({changes: { |
| 12 | + from: 0, |
| 13 | + to: editor.state.doc.length, |
| 14 | + insert: data.code |
| 15 | + }}) |
| 16 | + }) |
10 | 17 | }
|
11 |
| - createEditor(editor, data.code, update => data.code = update) |
| 18 | + editor = createEditor(editorMount, data.code, update => data.code = update) |
12 | 19 | })
|
13 | 20 |
|
14 | 21 | const apiUrl = 'https://gkyhj54sul.execute-api.us-east-1.amazonaws.com/prod';
|
|
161 | 168 | <h1 class="text-3xl">Playground</h1>
|
162 | 169 | <p class="mb-4 md:px-0 pt-4 px-4">Try out PHPStan with phpstan-drupal and all of its features here in the editor. <a href="https://phpstan.org/" class="hover:no-underline underline">Learn more about PHPStan »</a></p>
|
163 | 170 | <form class="space-y-4" on:submit={analyse}>
|
164 |
| - <div bind:this={editor}></div> |
| 171 | + <div bind:this={editorMount}></div> |
165 | 172 | {#if !editor}
|
166 | 173 | <textarea bind:value={data.code} rows="10" name="code" class="block w-full rounded-md border-0 py-1.5 text-gray-900 shadow-sm ring-1 ring-inset ring-gray-300 placeholder:text-gray-400 focus:ring-2 focus:ring-inset focus:ring-light-navy-blue sm:text-sm sm:leading-6"></textarea>
|
167 | 174 | {/if}
|
|
197 | 204 | </select>
|
198 | 205 | <button disabled={processing} class="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded" type="submit">Analyse</button>
|
199 | 206 | <div class="flex-grow"></div>
|
200 |
| - <button on:click={share} type="button" data-bind="click: share" class="bg-gray-100 border border-gray-300 flex-grow font-medium h-10 hover:bg-gray-200 inline-flex items-center justify-center leading-4 md:flex-grow-0 md:mx-0 md:w-32 mx-4 px-2.5 py-3 rounded-lg text-md w-auto"> |
| 207 | + <button on:click={share} type="button" class="bg-gray-100 border border-gray-300 flex-grow font-medium h-10 hover:bg-gray-200 inline-flex items-center justify-center leading-4 md:flex-grow-0 md:mx-0 md:w-32 mx-4 px-2.5 py-3 rounded-lg text-md w-auto"> |
201 | 208 | <svg fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" viewBox="0 0 24 24" class="h-6 w-6"><path d="M8.684 13.342C8.886 12.938 9 12.482 9 12c0-.482-.114-.938-.316-1.342m0 2.684a3 3 0 110-2.684m0 2.684l6.632 3.316m-6.632-6l6.632-3.316m0 0a3 3 0 105.367-2.684 3 3 0 00-5.367 2.684zm0 9.316a3 3 0 105.368 2.684 3 3 0 00-5.368-2.684z"></path></svg>
|
202 |
| - <span class="ml-2" data-bind="text: shareText">Share</span> |
| 209 | + <span class="ml-2">Share</span> |
203 | 210 | </button>
|
204 | 211 | </div>
|
205 | 212 | </form>
|
|
0 commit comments