diff --git a/src/jsoneditor/components/TreeMode.js b/src/jsoneditor/components/TreeMode.js index 93c3dda..956d3d2 100644 --- a/src/jsoneditor/components/TreeMode.js +++ b/src/jsoneditor/components/TreeMode.js @@ -50,11 +50,16 @@ import { createFindKeyBinding } from '../utils/keyBindings' import { KEY_BINDINGS } from '../constants' import { immutableJSONPatch } from '../immutableJSONPatch' import { - applyErrors, applySelection, contentsFromPaths, + applyErrors, + applySelection, + contentsFromPaths, expand, EXPANDED, - expandPath, immutableESONPatch, - nextSearchResult, pathsFromSelection, previousSearchResult, + expandPath, + immutableESONPatch, + nextSearchResult, + pathsFromSelection, + previousSearchResult, search, syncEson } from '../eson' diff --git a/src/jsoneditor/eson.js b/src/jsoneditor/eson.js index a28f392..80c66e8 100644 --- a/src/jsoneditor/eson.js +++ b/src/jsoneditor/eson.js @@ -93,7 +93,7 @@ export function syncEson(json, eson) { } } else if (jsonType === 'value') { // json is a value - if (sameType) { + if (sameType && eson[VALUE] === json) { return eson } else { diff --git a/src/jsoneditor/eson.test.js b/src/jsoneditor/eson.test.js index 5b0cdc4..ffd52ff 100644 --- a/src/jsoneditor/eson.test.js +++ b/src/jsoneditor/eson.test.js @@ -16,7 +16,8 @@ import { SELECTED_LAST, SELECTED_START, SELECTION, syncEson, - TYPE + TYPE, + VALUE } from './eson' import { getIn, setIn } from './utils/immutabilityHelpers' import { createAssertEqualEson } from './utils/assertEqualEson' @@ -60,6 +61,36 @@ test('syncEson', () => { expect(nodeState2.obj.a[ID]).toEqual(nodeState1.obj.a[ID]) }) +test('syncEson (replace a value)', () => { + const json1 = { + value: 1 + } + const eson1 = syncEson(json1, undefined) + + expect(eson1.value[ID]).toBeDefined() + expect(eson1.value[TYPE]).toEqual('value') + expect(eson1.value[VALUE]).toEqual(1) + + const json2 = { + value: 2 + } + const eson2 = syncEson(json2, eson1) + + expect(eson2.value[ID]).toBeDefined() + expect(eson2.value[TYPE]).toEqual('value') + expect(eson2.value[VALUE]).toEqual(2) + + // eson1 should be untouched + expect(eson1.value[VALUE]).toEqual(1) + + const json3 = { + value: 2 // samve as json2 + } + const eson3 = syncEson(json3, eson2) + expect(eson3.value).toBe(eson2.value) + expect(eson3).toBe(eson2) +}) + test('expand a single path', () => { const eson = syncEson({ "obj": { diff --git a/src/jsoneditor/types.js b/src/jsoneditor/types.js index 9e009c5..68f4e3d 100644 --- a/src/jsoneditor/types.js +++ b/src/jsoneditor/types.js @@ -11,7 +11,7 @@ * modes: string[]?, * history: boolean?, * indentation: number | string?, - * onChange: function (patch: ESONPatchDocument, revert: ESONPatchDocument)?, + * onChange: function (patch: JSONPatchDocument, revert: JSONPatchDocument)?, * onChangeText: function ()?, * onChangeMode: function (mode: string, prevMode: string)?, * onError: function (err: Error)?, @@ -81,20 +81,6 @@ * }} JSONPatchOptions */ -/** - * @typedef {{ - * op: 'add' | 'remove' | 'replace' | 'copy' | 'move' | 'test', - * path: string, - * from?: string, - * value?: *, - * meta?: ESONPatchOptions - * }} ESONPatchOperation - */ - -/** - * @typedef {ESONPatchOperation[]} ESONPatchDocument - */ - /** * @typedef {{ * patch: JSONPatchDocument, @@ -103,22 +89,6 @@ * }} JSONPatchResult */ -/** - * @typedef {{ - * id: string, - * path: Path, - * type: ESONType, - * before?: string - * props?: string[], - * expanded?: boolean, - * selected?: boolean, - * searchProperty?: SearchResultStatus, - * searchValue?: SearchResultStatus - * }} ESONPatchOptions - * - * // TODO: describe search results and selection - */ - /** * @typedef {Object | Array} ESON */