From e5ec845d4f65f28add29681f8b766a6a73c9e52c Mon Sep 17 00:00:00 2001 From: josdejong Date: Sun, 31 May 2020 10:54:34 +0200 Subject: [PATCH] Expand array limit when search result is beyond the visible items --- src/JSONEditor.svelte | 34 ++++++++++++++++++++++++++++++---- src/JSONNode.svelte | 13 +++++++------ src/SearchBox.svelte | 3 +-- src/constants.js | 5 ++++- src/utils/search.js | 13 ++++++++++--- 5 files changed, 52 insertions(+), 16 deletions(-) diff --git a/src/JSONEditor.svelte b/src/JSONEditor.svelte index 749b53b..670003d 100644 --- a/src/JSONEditor.svelte +++ b/src/JSONEditor.svelte @@ -1,17 +1,22 @@ @@ -254,6 +253,7 @@ onChangeKey={handleChangeKey} onPatch={onPatch} onExpand={onExpand} + onLimit={onLimit} /> {/each} {#if limited} @@ -307,6 +307,7 @@ onChangeKey={handleChangeKey} onPatch={onPatch} onExpand={onExpand} + onLimit={onLimit} /> {/each} diff --git a/src/SearchBox.svelte b/src/SearchBox.svelte index 9729b72..a1c1d21 100644 --- a/src/SearchBox.svelte +++ b/src/SearchBox.svelte @@ -2,10 +2,9 @@ import { debounce } from 'lodash-es' import Icon from 'svelte-awesome' import { faSearch, faChevronDown, faChevronUp, faTimes } from '@fortawesome/free-solid-svg-icons' + import { DEBOUNCE_DELAY } from './constants.js' import { keyComboFromEvent } from './utils/keyBindings.js' - const DEBOUNCE_DELAY = 300 // milliseconds TODO: make the debounce delay configurable? - export let text = '' let inputText = '' export let resultCount = 0 diff --git a/src/constants.js b/src/constants.js index a6a10ce..27a5b93 100644 --- a/src/constants.js +++ b/src/constants.js @@ -1,6 +1,9 @@ export const EXPANDED_PROPERTY = '$jse:expanded' +export const LIMIT_PROPERTY = '$jse:limit' export const SEARCH_PROPERTY = '$jse:search:property' export const SEARCH_VALUE = '$jse:search:value' -export const SCROLL_DURATION = 300 // ms \ No newline at end of file +export const SCROLL_DURATION = 300 // ms +export const DEBOUNCE_DELAY = 300 +export const DEFAULT_LIMIT = 100 diff --git a/src/utils/search.js b/src/utils/search.js index 30746ce..024072f 100644 --- a/src/utils/search.js +++ b/src/utils/search.js @@ -1,3 +1,4 @@ +import { isNumber } from 'lodash-es' import { SEARCH_PROPERTY, SEARCH_VALUE } from '../constants.js' import { valueType } from './typeUtils.js' @@ -53,7 +54,7 @@ export function flattenSearch (searchResult) { const type = valueType(value) if (type === 'array') { - searchResult.forEach((item, index) => { + value.forEach((item, index) => { _flattenSearch(item, path.concat(index)) }) } else if (type === 'object') { @@ -73,8 +74,14 @@ function createOrAdd(object, key, value) { object[key] = value return object } else { - return { - [key]: value + if (isNumber(key)) { + const array = [] + array[key] = value + return array + } else { + return { + [key]: value + } } } }