From a4698eee43c8a10c68ca489646c320f66bfb6b10 Mon Sep 17 00:00:00 2001 From: Romein van Buren Date: Thu, 19 Jan 2023 08:57:25 +0100 Subject: [PATCH] Use Webdesq objecttree instead highlight.js --- frontend/package-lock.json | 16 -- frontend/package.json | 3 - frontend/package.json.md5 | 2 +- frontend/src/components/code-example.svelte | 8 +- frontend/src/components/codeviewer.svelte | 74 ------- frontend/src/components/objecttree.svelte | 208 ++++++++++++++++++ frontend/src/components/objectviewer.svelte | 52 +++++ .../connection/collection/find.svelte | 11 +- .../connection/collection/indexes.svelte | 8 +- 9 files changed, 270 insertions(+), 112 deletions(-) delete mode 100644 frontend/src/components/codeviewer.svelte create mode 100644 frontend/src/components/objecttree.svelte create mode 100644 frontend/src/components/objectviewer.svelte diff --git a/frontend/package-lock.json b/frontend/package-lock.json index ce0aa5a..dd2fcc9 100644 --- a/frontend/package-lock.json +++ b/frontend/package-lock.json @@ -7,9 +7,6 @@ "": { "name": "frontend", "version": "0.0.0", - "dependencies": { - "highlight.js": "^11.7.0" - }, "devDependencies": { "@sveltejs/vite-plugin-svelte": "^1.0.1", "eslint": "^8.31.0", @@ -1891,14 +1888,6 @@ "url": "https://github.com/sponsors/ljharb" } }, - "node_modules/highlight.js": { - "version": "11.7.0", - "resolved": "https://registry.npmjs.org/highlight.js/-/highlight.js-11.7.0.tgz", - "integrity": "sha512-1rRqesRFhMO/PRF+G86evnyJkCgaZFOI+Z6kdj15TA18funfoqJXvgPCLSf0SWq3SRfg1j3HlDs8o4s3EGq1oQ==", - "engines": { - "node": ">=12.0.0" - } - }, "node_modules/ignore": { "version": "5.2.4", "resolved": "https://registry.npmjs.org/ignore/-/ignore-5.2.4.tgz", @@ -4534,11 +4523,6 @@ "has-symbols": "^1.0.2" } }, - "highlight.js": { - "version": "11.7.0", - "resolved": "https://registry.npmjs.org/highlight.js/-/highlight.js-11.7.0.tgz", - "integrity": "sha512-1rRqesRFhMO/PRF+G86evnyJkCgaZFOI+Z6kdj15TA18funfoqJXvgPCLSf0SWq3SRfg1j3HlDs8o4s3EGq1oQ==" - }, "ignore": { "version": "5.2.4", "resolved": "https://registry.npmjs.org/ignore/-/ignore-5.2.4.tgz", diff --git a/frontend/package.json b/frontend/package.json index 8e44cb4..6834bc3 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -21,8 +21,5 @@ "nodejs", "svelte3" ] - }, - "dependencies": { - "highlight.js": "^11.7.0" } } diff --git a/frontend/package.json.md5 b/frontend/package.json.md5 index 83aff09..e072450 100755 --- a/frontend/package.json.md5 +++ b/frontend/package.json.md5 @@ -1 +1 @@ -d445254075c563425c5b0fd21e804d4a \ No newline at end of file +e25516ba8abdacf5ab40609a5d48f542 \ No newline at end of file diff --git a/frontend/src/components/code-example.svelte b/frontend/src/components/code-example.svelte index ddd44a9..06eb5ea 100644 --- a/frontend/src/components/code-example.svelte +++ b/frontend/src/components/code-example.svelte @@ -1,18 +1,12 @@ -
modalCode = code}> +
CLI command {code}
- - diff --git a/frontend/src/components/objecttree.svelte b/frontend/src/components/objecttree.svelte new file mode 100644 index 0000000..1d4c889 --- /dev/null +++ b/frontend/src/components/objecttree.svelte @@ -0,0 +1,208 @@ + + +{#if displayOnly} + {#if items.length} + + {#if draggable && isArray} + dragstart(e, kp, data)} draggable="true" class="bracket" on:click={clicked} tabindex="0">{openBracket} + {:else} + {openBracket} + {/if} +
    (readonly ? displayOnly = true : displayOnly = false)} > + {#each items as i, idx} +
  • + {#if !isArray} + {#if draggable} + dragstart(e, kp ? kp + '.' + i : i, data[i])} draggable="true" class="key">{i}: + {:else} + {i}: + {/if} + {/if} + {#if getType(data[i]) === 'object'} + + {:else} + {#if draggable} + dragstart(e, kp ? kp + '.' + i : i, data[i])} draggable="true" class="val {getType(data[i])}">{format(data[i])}{#if idx < items.length - 1},{/if} + {:else} + {format(data[i])}{#if idx < items.length - 1},{/if} + {/if} + {/if} +
  • + {/each} +
+ {closeBracket}{#if !last}, + {/if} +
+ {openBracket}{collapsedSymbol}{closeBracket}{#if !last && collapsed},{/if} + {:else} + {@html isArray ? '[]' : '{}'} + {/if} +{:else} + +{/if} + + diff --git a/frontend/src/components/objectviewer.svelte b/frontend/src/components/objectviewer.svelte new file mode 100644 index 0000000..621a304 --- /dev/null +++ b/frontend/src/components/objectviewer.svelte @@ -0,0 +1,52 @@ + + +{#if data} + +
+
+ +
+
+ +
+
+
+{/if} + + diff --git a/frontend/src/organisms/connection/collection/find.svelte b/frontend/src/organisms/connection/collection/find.svelte index 86039b5..f8ca158 100644 --- a/frontend/src/organisms/connection/collection/find.svelte +++ b/frontend/src/organisms/connection/collection/find.svelte @@ -4,7 +4,7 @@ import { input } from '../../../actions'; import ObjectGrid from '../../../components/objectgrid.svelte'; import Icon from '../../../components/icon.svelte'; - import CodeViewer from '../../../components/codeviewer.svelte'; + import ObjectViewer from '../../../components/objectviewer.svelte'; export let collection; @@ -21,7 +21,7 @@ let submittedForm = {}; let queryField; let activePath = ''; - let json = ''; + let objectViewerData; $: code = `db.${collection.key}.find(${form.query || '{}'}${form.fields && form.fields !== '{}' ? `, ${form.fields}` : ''}).sort(${form.sort})${form.skip ? `.skip(${form.skip})` : ''}${form.limit ? `.limit(${form.limit})` : ''};`; async function submitQuery() { @@ -57,10 +57,7 @@ function openJson(itemId) { const item = result?.results?.find(i => i._id == itemId); - if (!item) { - return; - } - json = JSON.stringify(item, undefined, 2); + objectViewerData = item; } export function performQuery(q) { @@ -133,7 +130,7 @@
- +