From b99d4b4d5d58fe7a1a03c9fad8443a84a1350a92 Mon Sep 17 00:00:00 2001 From: Jos de Jong Date: Mon, 27 Jul 2020 09:42:15 +0200 Subject: [PATCH] Reorganize files in folders /components and /logic --- src/{ => components}/JSONEditor.scss | 2 +- src/{ => components}/JSONEditor.svelte | 41 ++-- src/{ => components}/JSONNode.scss | 2 +- src/{ => components}/JSONNode.svelte | 20 +- src/{ => components}/Menu.scss | 2 +- src/{ => components}/Menu.svelte | 2 +- src/{ => components}/SearchBox.scss | 2 +- src/{ => components}/SearchBox.svelte | 6 +- src/logic/documentState.js | 210 ++++++++++++++++++ .../documentState.test.js} | 23 +- src/{ => logic}/history.js | 0 src/{ => logic}/operations.js | 6 +- src/{utils => logic}/search.js | 4 +- src/{ => logic}/selection.js | 8 +- src/{ => logic}/selection.test.js | 4 +- src/main.js | 2 +- src/utils/stateUtils.js | 104 --------- src/utils/updateProps.js | 111 --------- src/utils/updateProps.test.js | 21 -- 19 files changed, 279 insertions(+), 291 deletions(-) rename src/{ => components}/JSONEditor.scss (95%) rename src/{ => components}/JSONEditor.svelte (90%) rename src/{ => components}/JSONNode.scss (99%) rename src/{ => components}/JSONNode.svelte (96%) rename src/{ => components}/Menu.scss (97%) rename src/{ => components}/Menu.svelte (98%) rename src/{ => components}/SearchBox.scss (97%) rename src/{ => components}/SearchBox.svelte (93%) create mode 100644 src/logic/documentState.js rename src/{utils/stateUtils.test.js => logic/documentState.test.js} (64%) rename src/{ => logic}/history.js (100%) rename src/{ => logic}/operations.js (97%) rename src/{utils => logic}/search.js (97%) rename src/{ => logic}/selection.js (92%) rename src/{ => logic}/selection.test.js (93%) delete mode 100644 src/utils/stateUtils.js delete mode 100644 src/utils/updateProps.js delete mode 100644 src/utils/updateProps.test.js diff --git a/src/JSONEditor.scss b/src/components/JSONEditor.scss similarity index 95% rename from src/JSONEditor.scss rename to src/components/JSONEditor.scss index e37db82..90c1b9e 100644 --- a/src/JSONEditor.scss +++ b/src/components/JSONEditor.scss @@ -1,4 +1,4 @@ -@import './styles.scss'; +@import '../styles.scss'; .jsoneditor { border: 1px solid $theme-color; diff --git a/src/JSONEditor.svelte b/src/components/JSONEditor.svelte similarity index 90% rename from src/JSONEditor.svelte rename to src/components/JSONEditor.svelte index 9c22294..304af46 100644 --- a/src/JSONEditor.svelte +++ b/src/components/JSONEditor.svelte @@ -6,34 +6,33 @@ insertBefore, removeAll, replace - } from './operations.js' + } from '../logic/operations.js' import { STATE_EXPANDED, STATE_LIMIT, SCROLL_DURATION, STATE_PROPS - } from './constants.js' - import { createHistory } from './history.js' + } from '../constants.js' + import { createHistory } from '../logic/history.js' import JSONNode from './JSONNode.svelte' import { createPathsMap, createSelectionFromOperations, expandSelection - } from './selection.js' - import { isContentEditableDiv } from './utils/domUtils.js' + } from '../logic/selection.js' + import { isContentEditableDiv } from '../utils/domUtils.js' import { getIn, setIn, updateIn - } from './utils/immutabilityHelpers.js' - import { compileJSONPointer, parseJSONPointer } from './utils/jsonPointer.js' - import { keyComboFromEvent } from './utils/keyBindings.js' - import { search, searchNext, searchPrevious } from './utils/search.js' - import { immutableJSONPatch } from './utils/immutableJSONPatch' + } from '../utils/immutabilityHelpers.js' + import { compileJSONPointer, parseJSONPointer } from '../utils/jsonPointer.js' + import { keyComboFromEvent } from '../utils/keyBindings.js' + import { search, searchNext, searchPrevious } from '../logic/search.js' + import { immutableJSONPatch } from '../utils/immutableJSONPatch' import { initial, last, cloneDeep } from 'lodash-es' - import jump from './assets/jump.js/src/jump.js' - import { expandPath, stateUtils } from './utils/stateUtils.js' - import { getNextKeys, patchProps } from './utils/updateProps.js' + import jump from '../assets/jump.js/src/jump.js' + import { expandPath, syncState, getNextKeys, patchProps } from '../logic/documentState.js' import Menu from './Menu.svelte' let divContents @@ -49,7 +48,7 @@ $: hasSelectionContents = selection != null && selection.paths != null $: hasClipboardContents = clipboard != null && selection != null - $: state = stateUtils(doc, state, [], (path) => path.length < 1) + $: state = syncState(doc, state, [], (path) => path.length < 1) let showSearch = false let searchText = '' @@ -63,11 +62,11 @@ let historyState = history.getState() export function expand (callback = () => true) { - state = stateUtils(doc, state, [], callback, true) + state = syncState(doc, state, [], callback, true) } export function collapse (callback = () => false) { - state = stateUtils(doc, state, [], callback, true) + state = syncState(doc, state, [], callback, true) } export function get() { @@ -168,7 +167,7 @@ const parentPath = initial(selection.beforePath) const beforeKey = last(selection.beforePath) const props = getIn(state, parentPath.concat(STATE_PROPS)) - const nextKeys = getNextKeys(props, parentPath, beforeKey, true) + const nextKeys = getNextKeys(props, beforeKey, true) const operations = insertBefore(doc, selection.beforePath, clipboard, nextKeys) const newSelection = createSelectionFromOperations(operations) @@ -183,7 +182,7 @@ const parentPath = initial(lastPath) const beforeKey = last(lastPath) const props = getIn(state, parentPath.concat(STATE_PROPS)) - const nextKeys = getNextKeys(props, parentPath, beforeKey, true) + const nextKeys = getNextKeys(props, beforeKey, true) const operations = replace(doc, selection.paths, clipboard, nextKeys) const newSelection = createSelectionFromOperations(operations) @@ -200,7 +199,7 @@ const parentPath = initial(lastPath) const beforeKey = last(lastPath) const props = getIn(state, parentPath.concat(STATE_PROPS)) - const nextKeys = getNextKeys(props, parentPath, beforeKey, false) + const nextKeys = getNextKeys(props, beforeKey, false) const operations = duplicate(doc, selection.paths, nextKeys) const newSelection = createSelectionFromOperations(operations) @@ -318,7 +317,7 @@ function handleExpand (path, expanded, recursive = false) { if (recursive) { state = updateIn(state, path, (childState) => { - return stateUtils(getIn(doc, path), childState, [], () => expanded, true) + return syncState(getIn(doc, path), childState, [], () => expanded, true) }) } else { state = setIn(state, path.concat(STATE_EXPANDED), expanded, true) @@ -471,4 +470,4 @@ - + diff --git a/src/JSONNode.scss b/src/components/JSONNode.scss similarity index 99% rename from src/JSONNode.scss rename to src/components/JSONNode.scss index 51896f8..acfaf70 100644 --- a/src/JSONNode.scss +++ b/src/components/JSONNode.scss @@ -1,4 +1,4 @@ -@import './styles.scss'; +@import '../styles.scss'; .json-node { position: relative; diff --git a/src/JSONNode.svelte b/src/components/JSONNode.svelte similarity index 96% rename from src/JSONNode.svelte rename to src/components/JSONNode.svelte index 804b427..85eff22 100644 --- a/src/JSONNode.svelte +++ b/src/components/JSONNode.svelte @@ -1,6 +1,6 @@