feat(ui): show toast after copying jsontree node
This commit is contained in:
@@ -33,6 +33,7 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { browser } from '$app/environment';
|
import { browser } from '$app/environment';
|
||||||
import JsonViewer from './JsonViewer.svelte';
|
import JsonViewer from './JsonViewer.svelte';
|
||||||
|
import { toast } from './toast.svelte';
|
||||||
|
|
||||||
let {
|
let {
|
||||||
value,
|
value,
|
||||||
@@ -70,6 +71,11 @@
|
|||||||
let prevJson = '';
|
let prevJson = '';
|
||||||
let flashTimeout: ReturnType<typeof setTimeout> | null = null;
|
let flashTimeout: ReturnType<typeof setTimeout> | null = null;
|
||||||
|
|
||||||
|
function copyValue() {
|
||||||
|
navigator.clipboard.writeText(JSON.stringify(key ? { [key]: value } : value, null, 2));
|
||||||
|
toast('Value copied to clipboard', 'success');
|
||||||
|
}
|
||||||
|
|
||||||
$effect(() => {
|
$effect(() => {
|
||||||
const json = JSON.stringify(value);
|
const json = JSON.stringify(value);
|
||||||
if (prevJson && json !== prevJson) {
|
if (prevJson && json !== prevJson) {
|
||||||
@@ -92,7 +98,7 @@
|
|||||||
<button
|
<button
|
||||||
class="text-text hover:bg-layer-3 cursor-pointer"
|
class="text-text hover:bg-layer-3 cursor-pointer"
|
||||||
title="Copy value"
|
title="Copy value"
|
||||||
onclick={() => navigator.clipboard.writeText(JSON.stringify({ [key]: value }, null, 2))}
|
onclick={() => copyValue()}
|
||||||
>
|
>
|
||||||
{key}
|
{key}
|
||||||
</button><span class="text-text/40">: </span>
|
</button><span class="text-text/40">: </span>
|
||||||
|
|||||||
Reference in New Issue
Block a user