|
| 1 | +<script lang="ts"> |
| 2 | +import Modal from './Modal.svelte' |
| 3 | +import { stringifyJson } from './stringifyJson' |
| 4 | +import type { JSONQueryError } from './types' |
| 5 | +
|
| 6 | +interface Props { |
| 7 | + error: JSONQueryError |
| 8 | + onClose: () => void |
| 9 | +} |
| 10 | +
|
| 11 | +const { error, onClose }: Props = $props() |
| 12 | +
|
| 13 | +let errorIndex = $state(error.jsonquery.length - 1) |
| 14 | +const current = $derived(error.jsonquery[errorIndex]) |
| 15 | +
|
| 16 | +function close() { |
| 17 | + onClose() |
| 18 | +} |
| 19 | +
|
| 20 | +function prev() { |
| 21 | + if (errorIndex > 0) { |
| 22 | + errorIndex-- |
| 23 | + } |
| 24 | +} |
| 25 | +
|
| 26 | +function next() { |
| 27 | + if (errorIndex < error?.jsonquery?.length - 1) { |
| 28 | + errorIndex++ |
| 29 | + } |
| 30 | +} |
| 31 | +</script> |
| 32 | + |
| 33 | +<Modal title="Debugger" onClose={close}> |
| 34 | + <div class="dialog-contents"> |
| 35 | + <div class="error-message">{String(error)}</div> |
| 36 | + <div class="stack-toggles"> |
| 37 | + Stack: <button type="button" onclick={prev}>Previous</button> |
| 38 | + <span>{errorIndex + 1}/{error.jsonquery.length}</span> |
| 39 | + <button type="button" onclick={next}>Next</button> |
| 40 | + </div> |
| 41 | + <div class="debug-columns"> |
| 42 | + <div class="debug-column"> |
| 43 | + <label class="debug-label" for="error-data">Input</label> |
| 44 | + <textarea class="debug-content" readonly>{stringifyJson(current.data)}</textarea> |
| 45 | + </div> |
| 46 | + <div class="debug-column"> |
| 47 | + <label class="debug-label" for="error-query">Query</label> |
| 48 | + <textarea class="debug-content" readonly>{stringifyJson(current.query)}</textarea> |
| 49 | + </div> |
| 50 | + </div> |
| 51 | + </div> |
| 52 | +</Modal> |
| 53 | + |
| 54 | +<style> |
| 55 | + .dialog-contents { |
| 56 | + flex: 1; |
| 57 | + display: flex; |
| 58 | + flex-direction: column; |
| 59 | + gap: var(--padding); |
| 60 | + padding: calc(2 * var(--padding)); |
| 61 | + background: var(--background-color-gray); |
| 62 | + } |
| 63 | +
|
| 64 | + .error-message { |
| 65 | + color: var(--error-color); |
| 66 | + } |
| 67 | +
|
| 68 | + .debug-columns { |
| 69 | + flex: 1; |
| 70 | + display: flex; |
| 71 | + flex-wrap: wrap; |
| 72 | + gap: 20px; |
| 73 | + min-height: 0; |
| 74 | +
|
| 75 | + .debug-column { |
| 76 | + flex: 1; |
| 77 | + display: flex; |
| 78 | + flex-direction: column; |
| 79 | + gap: 10px; |
| 80 | + min-height: 0; |
| 81 | +
|
| 82 | + .debug-label { |
| 83 | + font-weight: bold; |
| 84 | + } |
| 85 | +
|
| 86 | + label { |
| 87 | + margin: 0; |
| 88 | + } |
| 89 | +
|
| 90 | + textarea { |
| 91 | + flex: 1; |
| 92 | + min-height: 200px; |
| 93 | + min-width: 300px; |
| 94 | + resize: none; |
| 95 | + border: var(--input-border); |
| 96 | + padding: 5px; |
| 97 | + border-radius: var(--border-radius); |
| 98 | + box-sizing: border-box; |
| 99 | + } |
| 100 | + } |
| 101 | + } |
| 102 | +</style> |
0 commit comments