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)
|
||||
}
|
||||
|
||||
/** @private */
|
||||
handleChangeProperty = (event) => {
|
||||
const parentPath = this.props.parent.getPath()
|
||||
const oldProp = this.props.prop
|
||||
|
@ -324,6 +325,7 @@ export default class JSONNode extends Component {
|
|||
}
|
||||
}
|
||||
|
||||
/** @private */
|
||||
handleChangeValue = (event) => {
|
||||
const value = this.getValueFromEvent(event)
|
||||
|
||||
|
@ -332,18 +334,21 @@ export default class JSONNode extends Component {
|
|||
}
|
||||
}
|
||||
|
||||
/** @private */
|
||||
handleClickValue = (event) => {
|
||||
if (event.ctrlKey && event.button === 0) { // Ctrl+Left click
|
||||
this.openLinkIfUrl(event)
|
||||
}
|
||||
}
|
||||
|
||||
/** @private */
|
||||
handleKeyDownValue = (event) => {
|
||||
if (event.ctrlKey && event.which === 13) { // Ctrl+Enter
|
||||
this.openLinkIfUrl(event)
|
||||
}
|
||||
}
|
||||
|
||||
/** @private */
|
||||
handleExpand = (event) => {
|
||||
const recurse = event.ctrlKey
|
||||
const expanded = !this.props.data.expanded
|
||||
|
@ -351,6 +356,7 @@ export default class JSONNode extends Component {
|
|||
this.props.events.onExpand(this.getPath(), expanded, recurse)
|
||||
}
|
||||
|
||||
/** @private */
|
||||
handleContextMenu = (event) => {
|
||||
event.stopPropagation()
|
||||
|
||||
|
@ -373,6 +379,7 @@ export default class JSONNode extends Component {
|
|||
}
|
||||
}
|
||||
|
||||
/** @private */
|
||||
handleAppendContextMenu = (event) => {
|
||||
event.stopPropagation()
|
||||
|
||||
|
@ -397,6 +404,7 @@ export default class JSONNode extends Component {
|
|||
|
||||
/**
|
||||
* Singleton function to hide the currently visible context menu if any.
|
||||
* @private
|
||||
*/
|
||||
static hideActionMenu () {
|
||||
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
|
||||
* @param event
|
||||
* @private
|
||||
* @protected
|
||||
*/
|
||||
openLinkIfUrl (event) {
|
||||
const value = this.getValueFromEvent(event)
|
||||
|
@ -440,10 +448,6 @@ export default class JSONNode extends Component {
|
|||
return path
|
||||
}
|
||||
|
||||
isFieldEditable () {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the value of the target of an event, and convert it to it's type
|
||||
* @param event
|
||||
|
@ -463,7 +467,7 @@ export default class JSONNode extends Component {
|
|||
* @param event
|
||||
* @return {*}
|
||||
*/
|
||||
// TODO: cleanup
|
||||
// TODO: make redundant and cleanup
|
||||
static findRootElement (event) {
|
||||
function isEditorElement (elem) {
|
||||
// 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([
|
||||
h('div', {class: 'jsoneditor-vertical-menu-separator'}),
|
||||
|
||||
|
@ -291,19 +291,27 @@ export default class TreeMode extends Component {
|
|||
const result = patchData(this.state.data, actions)
|
||||
const data = result.data
|
||||
|
||||
const historyItem = {
|
||||
redo: actions,
|
||||
undo: result.revert
|
||||
}
|
||||
const history = [historyItem]
|
||||
.concat(this.state.history.slice(this.state.historyIndex))
|
||||
.slice(0, MAX_HISTORY_ITEMS)
|
||||
if (this.props.options.history != false) {
|
||||
// update data and store history
|
||||
const historyItem = {
|
||||
redo: actions,
|
||||
undo: result.revert
|
||||
}
|
||||
|
||||
this.setState({
|
||||
data,
|
||||
history,
|
||||
historyIndex: 0
|
||||
})
|
||||
const history = [historyItem]
|
||||
.concat(this.state.history.slice(this.state.historyIndex))
|
||||
.slice(0, MAX_HISTORY_ITEMS)
|
||||
|
||||
this.setState({
|
||||
data,
|
||||
history,
|
||||
historyIndex: 0
|
||||
})
|
||||
}
|
||||
else {
|
||||
// update data and don't store history
|
||||
this.setState({ data })
|
||||
}
|
||||
|
||||
return {
|
||||
patch: actions,
|
||||
|
|
|
@ -61,7 +61,8 @@
|
|||
mode: mode,
|
||||
modes: ['text', 'code', 'tree', 'form', 'view'],
|
||||
indentation: 4,
|
||||
escapeUnicode: true
|
||||
escapeUnicode: true,
|
||||
history: true
|
||||
}
|
||||
const editor = jsoneditor(container, options)
|
||||
const json = {
|
||||
|
|
Loading…
Reference in New Issue