From e629b404a6abb47c1ab28523276a15f267c2f5a2 Mon Sep 17 00:00:00 2001 From: Jos de Jong Date: Sun, 26 Jul 2020 12:00:14 +0200 Subject: [PATCH] Move Menu into a separate component --- src/JSONEditor.scss | 52 ------------------- src/JSONEditor.svelte | 116 ++++++++--------------------------------- src/Menu.scss | 53 +++++++++++++++++++ src/Menu.svelte | 118 ++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 192 insertions(+), 147 deletions(-) create mode 100644 src/Menu.scss create mode 100644 src/Menu.svelte diff --git a/src/JSONEditor.scss b/src/JSONEditor.scss index e891798..e37db82 100644 --- a/src/JSONEditor.scss +++ b/src/JSONEditor.scss @@ -9,58 +9,6 @@ flex-direction: column; position: relative; - .menu { - font-family: $font-family-menu; - font-size: $font-size; - background: $theme-color; - color: $white; - display: flex; - align-items: center; - position: relative; - - .button { - width: $menu-button-size; - height: $menu-button-size; - border: none; - background: transparent; - color: white; - cursor: pointer; - padding: 0; - - &:hover, - &:focus { - background: rgba(255, 255, 255, 0.3); - } - - &:disabled { - color: rgba(255, 255, 255, 0.5); - background: transparent; - } - } - - .space { - flex: 1; - } - - .separator { - $margin: 3px; - - background: rgba(255, 255, 255, 0.15); - box-sizing: border-box; - width: 1px; - height: $menu-button-size - 2 * $margin; - margin: $margin; - } - - .search-box-container { - position: absolute; - top: 100%; - right: $search-box-offset + 20px; // keep space for scrollbar - margin-top: $search-box-offset; - z-index: 2; - } - } - .hidden-input-label { position: absolute; right: 0; diff --git a/src/JSONEditor.svelte b/src/JSONEditor.svelte index ffb749f..9c22294 100644 --- a/src/JSONEditor.svelte +++ b/src/JSONEditor.svelte @@ -13,9 +13,6 @@ SCROLL_DURATION, STATE_PROPS } from './constants.js' - import SearchBox from './SearchBox.svelte' - import Icon from 'svelte-awesome' - import { faCut, faClone, faCopy, faPaste, faSearch, faUndo, faRedo } from '@fortawesome/free-solid-svg-icons' import { createHistory } from './history.js' import JSONNode from './JSONNode.svelte' import { @@ -37,6 +34,7 @@ import jump from './assets/jump.js/src/jump.js' import { expandPath, stateUtils } from './utils/stateUtils.js' import { getNextKeys, patchProps } from './utils/updateProps.js' + import Menu from './Menu.svelte' let divContents let domHiddenInput @@ -247,27 +245,22 @@ } } - async function changeSearchText (text) { + async function handleSearchText (text) { searchText = text await tick() // await for the search results to be updated focusActiveSearchResult(searchResult && searchResult.activeItem) } - async function nextSearchResult () { + async function handleNextSearchResult () { searchResult = searchNext(searchResult) focusActiveSearchResult(searchResult && searchResult.activeItem) } - function previousSearchResult () { + function handlePreviousSearchResult () { searchResult = searchPrevious(searchResult) focusActiveSearchResult(searchResult && searchResult.activeItem) } - function clearSearchResult () { - showSearch = false - searchText = '' - } - async function focusActiveSearchResult (activeItem) { if (activeItem) { state = expandPath(state, activeItem.path) @@ -316,10 +309,6 @@ // should never be called on the root } - function handleToggleSearch() { - showSearch = !showSearch - } - /** * Toggle expanded state of a node * @param {Path} path @@ -440,88 +429,25 @@
- + onCut={handleCut} + onCopy={handleCopy} + onPaste={handlePaste} + onDuplicate={handleDuplicate} + onUndo={handleUndo} + onRedo={handleRedo} - - -
- - - -
- - - - -
- - {#if showSearch} -
- -
- {/if} -
+ onSearchText={handleSearchText} + onNextSearchResult={handleNextSearchResult} + onPreviousSearchResult={handlePreviousSearchResult} + />