Implemented option `history`
This commit is contained in:
parent
9cbb7574c0
commit
b73ff81e19
|
@ -314,6 +314,7 @@ export default class JSONNode extends Component {
|
||||||
: valueType(data.value)
|
: valueType(data.value)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @private */
|
||||||
handleChangeProperty = (event) => {
|
handleChangeProperty = (event) => {
|
||||||
const parentPath = this.props.parent.getPath()
|
const parentPath = this.props.parent.getPath()
|
||||||
const oldProp = this.props.prop
|
const oldProp = this.props.prop
|
||||||
|
@ -324,6 +325,7 @@ export default class JSONNode extends Component {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @private */
|
||||||
handleChangeValue = (event) => {
|
handleChangeValue = (event) => {
|
||||||
const value = this.getValueFromEvent(event)
|
const value = this.getValueFromEvent(event)
|
||||||
|
|
||||||
|
@ -332,18 +334,21 @@ export default class JSONNode extends Component {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @private */
|
||||||
handleClickValue = (event) => {
|
handleClickValue = (event) => {
|
||||||
if (event.ctrlKey && event.button === 0) { // Ctrl+Left click
|
if (event.ctrlKey && event.button === 0) { // Ctrl+Left click
|
||||||
this.openLinkIfUrl(event)
|
this.openLinkIfUrl(event)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @private */
|
||||||
handleKeyDownValue = (event) => {
|
handleKeyDownValue = (event) => {
|
||||||
if (event.ctrlKey && event.which === 13) { // Ctrl+Enter
|
if (event.ctrlKey && event.which === 13) { // Ctrl+Enter
|
||||||
this.openLinkIfUrl(event)
|
this.openLinkIfUrl(event)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @private */
|
||||||
handleExpand = (event) => {
|
handleExpand = (event) => {
|
||||||
const recurse = event.ctrlKey
|
const recurse = event.ctrlKey
|
||||||
const expanded = !this.props.data.expanded
|
const expanded = !this.props.data.expanded
|
||||||
|
@ -351,6 +356,7 @@ export default class JSONNode extends Component {
|
||||||
this.props.events.onExpand(this.getPath(), expanded, recurse)
|
this.props.events.onExpand(this.getPath(), expanded, recurse)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @private */
|
||||||
handleContextMenu = (event) => {
|
handleContextMenu = (event) => {
|
||||||
event.stopPropagation()
|
event.stopPropagation()
|
||||||
|
|
||||||
|
@ -373,6 +379,7 @@ export default class JSONNode extends Component {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @private */
|
||||||
handleAppendContextMenu = (event) => {
|
handleAppendContextMenu = (event) => {
|
||||||
event.stopPropagation()
|
event.stopPropagation()
|
||||||
|
|
||||||
|
@ -397,6 +404,7 @@ export default class JSONNode extends Component {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Singleton function to hide the currently visible context menu if any.
|
* Singleton function to hide the currently visible context menu if any.
|
||||||
|
* @private
|
||||||
*/
|
*/
|
||||||
static hideActionMenu () {
|
static hideActionMenu () {
|
||||||
if (activeContextMenu) {
|
if (activeContextMenu) {
|
||||||
|
@ -411,7 +419,7 @@ export default class JSONNode extends Component {
|
||||||
/**
|
/**
|
||||||
* When this JSONNode holds an URL as value, open this URL in a new browser tab
|
* When this JSONNode holds an URL as value, open this URL in a new browser tab
|
||||||
* @param event
|
* @param event
|
||||||
* @private
|
* @protected
|
||||||
*/
|
*/
|
||||||
openLinkIfUrl (event) {
|
openLinkIfUrl (event) {
|
||||||
const value = this.getValueFromEvent(event)
|
const value = this.getValueFromEvent(event)
|
||||||
|
@ -440,10 +448,6 @@ export default class JSONNode extends Component {
|
||||||
return path
|
return path
|
||||||
}
|
}
|
||||||
|
|
||||||
isFieldEditable () {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the value of the target of an event, and convert it to it's type
|
* Get the value of the target of an event, and convert it to it's type
|
||||||
* @param event
|
* @param event
|
||||||
|
@ -463,7 +467,7 @@ export default class JSONNode extends Component {
|
||||||
* @param event
|
* @param event
|
||||||
* @return {*}
|
* @return {*}
|
||||||
*/
|
*/
|
||||||
// TODO: cleanup
|
// TODO: make redundant and cleanup
|
||||||
static findRootElement (event) {
|
static findRootElement (event) {
|
||||||
function isEditorElement (elem) {
|
function isEditorElement (elem) {
|
||||||
// FIXME: this is a bit tricky. can we use a special attribute or something?
|
// FIXME: this is a bit tricky. can we use a special attribute or something?
|
||||||
|
|
|
@ -84,7 +84,7 @@ export default class TreeMode extends Component {
|
||||||
})
|
})
|
||||||
]
|
]
|
||||||
|
|
||||||
if (this.props.mode !== 'view') {
|
if (this.props.mode !== 'view' && this.props.options.history != false) {
|
||||||
items = items.concat([
|
items = items.concat([
|
||||||
h('div', {class: 'jsoneditor-vertical-menu-separator'}),
|
h('div', {class: 'jsoneditor-vertical-menu-separator'}),
|
||||||
|
|
||||||
|
@ -291,10 +291,13 @@ export default class TreeMode extends Component {
|
||||||
const result = patchData(this.state.data, actions)
|
const result = patchData(this.state.data, actions)
|
||||||
const data = result.data
|
const data = result.data
|
||||||
|
|
||||||
|
if (this.props.options.history != false) {
|
||||||
|
// update data and store history
|
||||||
const historyItem = {
|
const historyItem = {
|
||||||
redo: actions,
|
redo: actions,
|
||||||
undo: result.revert
|
undo: result.revert
|
||||||
}
|
}
|
||||||
|
|
||||||
const history = [historyItem]
|
const history = [historyItem]
|
||||||
.concat(this.state.history.slice(this.state.historyIndex))
|
.concat(this.state.history.slice(this.state.historyIndex))
|
||||||
.slice(0, MAX_HISTORY_ITEMS)
|
.slice(0, MAX_HISTORY_ITEMS)
|
||||||
|
@ -304,6 +307,11 @@ export default class TreeMode extends Component {
|
||||||
history,
|
history,
|
||||||
historyIndex: 0
|
historyIndex: 0
|
||||||
})
|
})
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// update data and don't store history
|
||||||
|
this.setState({ data })
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
patch: actions,
|
patch: actions,
|
||||||
|
|
|
@ -61,7 +61,8 @@
|
||||||
mode: mode,
|
mode: mode,
|
||||||
modes: ['text', 'code', 'tree', 'form', 'view'],
|
modes: ['text', 'code', 'tree', 'form', 'view'],
|
||||||
indentation: 4,
|
indentation: 4,
|
||||||
escapeUnicode: true
|
escapeUnicode: true,
|
||||||
|
history: true
|
||||||
}
|
}
|
||||||
const editor = jsoneditor(container, options)
|
const editor = jsoneditor(container, options)
|
||||||
const json = {
|
const json = {
|
||||||
|
|
Loading…
Reference in New Issue