Skip to content

Commit

Permalink
Merge pull request #338 from laradumps/improve-json-viewer
Browse files Browse the repository at this point in the history
Improve JSON Viewer
  • Loading branch information
luanfreitasdev authored Nov 6, 2024
2 parents aaea962 + 7c28ed8 commit 63b4e57
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 8 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "laradumps",
"version": "3.4.0",
"version": "3.4.1",
"private": false,
"description": "LaraDumps a friendly app designed to boost your PHP coding and debugging experience. https://github.com/laradumps/app",
"author": "Luan Freitas <[email protected]>",
Expand Down
46 changes: 39 additions & 7 deletions src/renderer/components/DumpJson.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script setup lang="ts">
import VueJsonPretty from "vue-json-pretty";
import { computed, defineProps, onMounted } from "vue";
import { computed, defineProps } from "vue";
import { Payload } from "@/types/Payload";
const props = defineProps<{
Expand All @@ -14,21 +14,53 @@ const value = computed(() => {
return JSON.parse(props.payload.json?.string ?? "");
});
</script>
<style>
.vjs-tree-node:hover {
background-color: transparent !important;
function countNodes(obj: any): number {
if (typeof obj !== 'object' || obj === null) return 0;
let count = 0;
const stack = [obj];
while (stack.length) {
const node = stack.pop();
if (typeof node === 'object' && node !== null) {
count++;
for (const key in node) {
if (Object.prototype.hasOwnProperty.call(node, key)) {
stack.push(node[key]);
}
}
}
}
return count;
}
</style>
const shouldCollapse = computed(() => countNodes(value.value) >= 4);
</script>

<template>
<div class="text-base-content">
<VueJsonPretty
:data="value"
:show-icon="true"
:show-lenght="true"
:show-line="false"
:data="value"
:show-line-number="true"
:item-height="28"
v-bind:collapsed-node-length="shouldCollapse ? 4 : undefined"
:show-double-quotes="false"
/>
</div>
</template>
<style>
.vjs-tree-node:hover {
background-color: transparent !important;
}
.vjs-node-index {
@apply text-base-content/40
}
.vjs-carets {
@apply text-base-content/70 top-[6px] cursor-pointer right-[2px] absolute
}
</style>

0 comments on commit 63b4e57

Please sign in to comment.