Rename `json` to `doc`
This commit is contained in:
parent
596d868cc5
commit
d2b8470e2e
|
@ -49,7 +49,7 @@
|
||||||
<script type="module">
|
<script type="module">
|
||||||
import jsoneditor from './dist/es/jsoneditor.js'
|
import jsoneditor from './dist/es/jsoneditor.js'
|
||||||
|
|
||||||
const json = {
|
const doc = {
|
||||||
'array': [1, 2, 3, {
|
'array': [1, 2, 3, {
|
||||||
name: 'Item ' + 2,
|
name: 'Item ' + 2,
|
||||||
id: String(2),
|
id: String(2),
|
||||||
|
@ -87,8 +87,8 @@
|
||||||
const testEditor = jsoneditor({
|
const testEditor = jsoneditor({
|
||||||
target: document.getElementById('testEditorContainer'),
|
target: document.getElementById('testEditorContainer'),
|
||||||
props: {
|
props: {
|
||||||
json,
|
doc,
|
||||||
onChangeJson: json => console.log('onChangeJson', json)
|
onChangeJson: doc => console.log('onChangeJson', doc)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
window.testEditor = testEditor // expose to window for debugging
|
window.testEditor = testEditor // expose to window for debugging
|
||||||
|
|
|
@ -29,18 +29,18 @@
|
||||||
console.timeEnd('render')
|
console.timeEnd('render')
|
||||||
})
|
})
|
||||||
|
|
||||||
export let json = {} // TODO: rename 'json' to 'document'
|
export let doc = {}
|
||||||
|
let state = undefined
|
||||||
|
|
||||||
export let onChangeJson = () => {}
|
export let onChangeJson = () => {}
|
||||||
|
|
||||||
function expand (path) {
|
function expand (path) {
|
||||||
return path.length < 1
|
return path.length < 1
|
||||||
}
|
}
|
||||||
|
|
||||||
let state
|
|
||||||
|
|
||||||
$: {
|
$: {
|
||||||
console.time('syncState')
|
console.time('syncState')
|
||||||
state = syncState(json, state, [], expand)
|
state = syncState(doc, state, [], expand)
|
||||||
console.timeEnd('syncState')
|
console.timeEnd('syncState')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -55,11 +55,11 @@
|
||||||
let historyState = history.getState()
|
let historyState = history.getState()
|
||||||
|
|
||||||
export function get() {
|
export function get() {
|
||||||
return json
|
return doc
|
||||||
}
|
}
|
||||||
|
|
||||||
export function set(newJson) {
|
export function set(newDocument) {
|
||||||
json = newJson
|
doc = newDocument
|
||||||
state = undefined
|
state = undefined
|
||||||
history.clear()
|
history.clear()
|
||||||
}
|
}
|
||||||
|
@ -67,11 +67,11 @@
|
||||||
export function patch(operations) {
|
export function patch(operations) {
|
||||||
const prevState = state
|
const prevState = state
|
||||||
|
|
||||||
const documentPatchResult = immutableJSONPatch(json, operations)
|
const documentPatchResult = immutableJSONPatch(doc, operations)
|
||||||
const statePatchResult = immutableJSONPatch(state, operations)
|
const statePatchResult = immutableJSONPatch(state, operations)
|
||||||
// TODO: only apply operations to state for relevant operations: move, copy, delete? Figure out
|
// TODO: only apply operations to state for relevant operations: move, copy, delete? Figure out
|
||||||
|
|
||||||
json = documentPatchResult.json
|
doc = documentPatchResult.json
|
||||||
state = statePatchResult.json
|
state = statePatchResult.json
|
||||||
|
|
||||||
// if a property is renamed (move operation), rename it in the object's props
|
// if a property is renamed (move operation), rename it in the object's props
|
||||||
|
@ -104,7 +104,7 @@
|
||||||
})
|
})
|
||||||
|
|
||||||
return {
|
return {
|
||||||
json,
|
doc,
|
||||||
error: documentPatchResult.error,
|
error: documentPatchResult.error,
|
||||||
undo: documentPatchResult.revert,
|
undo: documentPatchResult.revert,
|
||||||
redo: operations
|
redo: operations
|
||||||
|
@ -115,10 +115,10 @@
|
||||||
if (history.getState().canUndo) {
|
if (history.getState().canUndo) {
|
||||||
const item = history.undo()
|
const item = history.undo()
|
||||||
if (item) {
|
if (item) {
|
||||||
json = immutableJSONPatch(json, item.undo).json
|
doc = immutableJSONPatch(doc, item.undo).json
|
||||||
state = item.prevState
|
state = item.prevState
|
||||||
|
|
||||||
console.log('undo', { item, json, state })
|
console.log('undo', { item, doc, state })
|
||||||
|
|
||||||
emitOnChange()
|
emitOnChange()
|
||||||
}
|
}
|
||||||
|
@ -129,18 +129,18 @@
|
||||||
if (history.getState().canRedo) {
|
if (history.getState().canRedo) {
|
||||||
const item = history.redo()
|
const item = history.redo()
|
||||||
if (item) {
|
if (item) {
|
||||||
json = immutableJSONPatch(json, item.redo).json
|
doc = immutableJSONPatch(doc, item.redo).json
|
||||||
state = item.state
|
state = item.state
|
||||||
|
|
||||||
console.log('redo', { item, json, state })
|
console.log('redo', { item, doc, state })
|
||||||
|
|
||||||
emitOnChange()
|
emitOnChange()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function doSearch(json, searchText) {
|
function doSearch(doc, searchText) {
|
||||||
return search(null, json, searchText)
|
return search(null, doc, searchText)
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: refactor the search solution and move it in a separate component
|
// TODO: refactor the search solution and move it in a separate component
|
||||||
|
@ -149,7 +149,7 @@
|
||||||
let activeSearchResultIndex
|
let activeSearchResultIndex
|
||||||
let flatSearchResult
|
let flatSearchResult
|
||||||
let searchResultWithActive
|
let searchResultWithActive
|
||||||
$: searchResult = searchText ? doSearch(json, searchText) : undefined
|
$: searchResult = searchText ? doSearch(doc, searchText) : undefined
|
||||||
$: flatSearchResult = flattenSearch(searchResult)
|
$: flatSearchResult = flattenSearch(searchResult)
|
||||||
|
|
||||||
$: {
|
$: {
|
||||||
|
@ -211,7 +211,7 @@
|
||||||
|
|
||||||
function emitOnChange() {
|
function emitOnChange() {
|
||||||
// TODO: add more logic here to emit onChange, onChangeJson, onChangeText, etc.
|
// TODO: add more logic here to emit onChange, onChangeJson, onChangeText, etc.
|
||||||
onChangeJson(json)
|
onChangeJson(doc)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -357,7 +357,7 @@
|
||||||
</div>
|
</div>
|
||||||
<div class="contents" bind:this={divContents}>
|
<div class="contents" bind:this={divContents}>
|
||||||
<Node
|
<Node
|
||||||
value={json}
|
value={doc}
|
||||||
path={[]}
|
path={[]}
|
||||||
state={state}
|
state={state}
|
||||||
searchResult={searchResultWithActive}
|
searchResult={searchResultWithActive}
|
||||||
|
|
Loading…
Reference in New Issue