Skip to content

Commit f5c3b25

Browse files
committed
Added collapsible prop to SuperDebug.
Fixes #248
1 parent 716c6a7 commit f5c3b25

File tree

3 files changed

+96
-4
lines changed

3 files changed

+96
-4
lines changed

CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,17 @@ Headlines: Added, Changed, Deprecated, Removed, Fixed, Security
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8-
## [1.5.4] - 2023-08-17
8+
## [1.6.0] - 2023-08-18
99

1010
### Fixed
1111

1212
- Client-side validation wasn't resetted properly, when a component containing a form was destroyed and mounted again.
1313
- Removed debug statement left from 1.5.3
1414

15+
### Added
16+
17+
- [SuperDebug](https://superforms.rocks/super-debug) now has a `collapsible` prop, that will make the component collapsible on a per-route basis.
18+
1519
## [1.5.3] - 2023-08-16
1620

1721
### Fixed

src/lib/client/SuperDebug.svelte

Lines changed: 89 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<script>
2+
import { browser } from '$app/environment';
23
import { page } from '$app/stores';
34
import { readable, get } from 'svelte/store';
45
@@ -99,6 +100,46 @@
99100
*/
100101
export let theme = 'default';
101102
103+
///// Collapse behavior ///////////////////////////////////////////
104+
105+
/**
106+
* Will show a collapse bar at the bottom of the component, that can be used to hide and show the output.
107+
*
108+
* Default is `false`.
109+
*/
110+
export let collapsible = false;
111+
112+
let collapsed = false;
113+
if (browser && collapsible) setCollapse();
114+
115+
/**
116+
* @param {boolean|undefined} status
117+
*/
118+
function setCollapse(status = undefined) {
119+
let data;
120+
const route = $page.route.id ?? '';
121+
try {
122+
data = JSON.parse(sessionStorage.SuperDebug);
123+
if (!('collapsed' in data)) data.collapsed = {};
124+
data.collapsed[route] =
125+
status === undefined ? data.collapsed[route] ?? false : status;
126+
} catch {
127+
data = {
128+
collapsed: {
129+
[route]: false
130+
}
131+
};
132+
}
133+
134+
if (status !== undefined) {
135+
sessionStorage.SuperDebug = JSON.stringify(data);
136+
}
137+
138+
collapsed = data.collapsed[route];
139+
}
140+
141+
///////////////////////////////////////////////////////////////////
142+
102143
/**
103144
* @param {unknown} json
104145
* @returns {string}
@@ -278,6 +319,7 @@
278319
{/if}
279320
<pre
280321
class="super-debug--pre {label === '' ? 'pt-4' : 'pt-0'}"
322+
class:hidden={collapsed}
281323
bind:this={ref}><code class="super-debug--code"
282324
><slot
283325
>{#if assertPromise($debugData, raw, promise)}{#await $debugData}<div
@@ -290,6 +332,24 @@
290332
)}{/await}{:else}{@html syntaxHighlight($debugData)}{/if}</slot
291333
></code
292334
></pre>
335+
{#if collapsible}
336+
<button
337+
on:click={() => setCollapse(!collapsed)}
338+
class="super-debug--collapse"
339+
>
340+
<svg
341+
xmlns="http://www.w3.org/2000/svg"
342+
width="20"
343+
height="20"
344+
viewBox="0 0 24 24"
345+
class:rotated={collapsed}
346+
><path
347+
fill="currentColor"
348+
d="M4.08 11.92L12 4l7.92 7.92l-1.42 1.41l-5.5-5.5V22h-2V7.83l-5.5 5.5l-1.42-1.41M12 4h10V2H2v2h10Z"
349+
/></svg
350+
>
351+
</button>
352+
{/if}
293353
</div>
294354
{/if}
295355
@@ -340,6 +400,15 @@
340400
padding-top: 1em;
341401
}
342402
403+
.hidden {
404+
height: 0;
405+
overflow: hidden;
406+
}
407+
408+
.rotated {
409+
transform: rotate(180deg);
410+
}
411+
343412
.super-debug {
344413
--_sd-bg-color: var(
345414
--sd-bg-color,
@@ -351,6 +420,24 @@
351420
overflow: hidden;
352421
}
353422
423+
.super-debug--collapse {
424+
display: block;
425+
width: 100%;
426+
color: rgba(255, 255, 255, 0.25);
427+
background-color: rgba(255, 255, 255, 0.15);
428+
padding: 5px 0;
429+
display: flex;
430+
justify-content: center;
431+
border-color: transparent;
432+
margin: 0;
433+
padding: 3px 0;
434+
}
435+
436+
.super-debug--collapse:is(:hover) {
437+
color: rgba(255, 255, 255, 0.35);
438+
background-color: rgba(255, 255, 255, 0.25);
439+
}
440+
354441
.super-debug--status {
355442
display: flex;
356443
padding: 1em;
@@ -382,7 +469,8 @@
382469
color: var(--sd-code-default, var(--sd-vscode-code-default, #999));
383470
background-color: var(--_sd-bg-color);
384471
font-size: 1em;
385-
padding: 1em 0 0 1em;
472+
margin-bottom: 0;
473+
padding: 1em 0 1em 1em;
386474
}
387475
388476
.info {

src/routes/super-debug/+page.svelte

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@
103103
<section>
104104
<h4>SuperDebug with label</h4>
105105
<p>Label is useful when using multiple instance of SuperDebug.</p>
106-
<SuperDebug label="Sample User" data={$form} />
106+
<SuperDebug label="Sample User" data={$form} collapsible />
107107
</section>
108108
<section>
109109
<h4>SuperDebug without status</h4>
@@ -167,7 +167,7 @@
167167
<section>
168168
<h4>SuperDebug displaying $page data</h4>
169169
<p>Svelte's <code>$page</code> data in all its glory.</p>
170-
<SuperDebug label="$page data" data={$page} />
170+
<SuperDebug label="$page data" data={$page} collapsible />
171171
</section>
172172

173173
<section>

0 commit comments

Comments
 (0)