Rename selection areas to before, on, after
This commit is contained in:
parent
0f24a9204f
commit
f33342b54b
|
@ -91,7 +91,7 @@ export default class JSONNode extends PureComponent {
|
||||||
const nodeStart = h('div', {
|
const nodeStart = h('div', {
|
||||||
key: 'node',
|
key: 'node',
|
||||||
onKeyDown: this.handleKeyDown,
|
onKeyDown: this.handleKeyDown,
|
||||||
'data-selection-area': 'contents',
|
'data-selection-area': 'on',
|
||||||
className: 'jsoneditor-node jsoneditor-object'
|
className: 'jsoneditor-node jsoneditor-object'
|
||||||
}, [
|
}, [
|
||||||
this.renderExpandButton(),
|
this.renderExpandButton(),
|
||||||
|
@ -124,7 +124,7 @@ export default class JSONNode extends PureComponent {
|
||||||
|
|
||||||
childs = h('div', {
|
childs = h('div', {
|
||||||
key: 'childs',
|
key: 'childs',
|
||||||
'data-selection-area': 'left',
|
'data-selection-area': 'before',
|
||||||
className: 'jsoneditor-list'
|
className: 'jsoneditor-list'
|
||||||
}, propsChilds)
|
}, propsChilds)
|
||||||
}
|
}
|
||||||
|
@ -133,7 +133,7 @@ export default class JSONNode extends PureComponent {
|
||||||
key: 'childs',
|
key: 'childs',
|
||||||
className: 'jsoneditor-list',
|
className: 'jsoneditor-list',
|
||||||
'data-area': 'emptyBefore', // TODO: remove
|
'data-area': 'emptyBefore', // TODO: remove
|
||||||
'data-selection-area': 'left'
|
'data-selection-area': 'before'
|
||||||
},
|
},
|
||||||
this.renderEmpty('(empty object)')
|
this.renderEmpty('(empty object)')
|
||||||
)
|
)
|
||||||
|
@ -144,17 +144,17 @@ export default class JSONNode extends PureComponent {
|
||||||
? h('div', {
|
? h('div', {
|
||||||
key: 'node-end',
|
key: 'node-end',
|
||||||
className: 'jsoneditor-node-end',
|
className: 'jsoneditor-node-end',
|
||||||
'data-selection-area': 'right',
|
'data-selection-area': 'after',
|
||||||
'data-area': 'empty', // TODO: remove
|
'data-area': 'empty', // TODO: remove
|
||||||
}, [
|
}, [
|
||||||
this.renderDelimiter('}', 'jsoneditor-delimiter-end', 'left')
|
this.renderDelimiter('}', 'jsoneditor-delimiter-end', 'before')
|
||||||
])
|
])
|
||||||
: null
|
: null
|
||||||
|
|
||||||
return h('div', {
|
return h('div', {
|
||||||
'data-path': compileJSONPointer(this.state.path),
|
'data-path': compileJSONPointer(this.state.path),
|
||||||
'data-area': 'empty', // TODO: remove
|
'data-area': 'empty', // TODO: remove
|
||||||
'data-selection-area': 'right',
|
'data-selection-area': 'after',
|
||||||
className: this.getContainerClassName(this.props.eson[SELECTION], this.state.hover),
|
className: this.getContainerClassName(this.props.eson[SELECTION], this.state.hover),
|
||||||
// onMouseOver: this.handleMouseOver,
|
// onMouseOver: this.handleMouseOver,
|
||||||
// onMouseLeave: this.handleMouseLeave
|
// onMouseLeave: this.handleMouseLeave
|
||||||
|
@ -167,7 +167,7 @@ export default class JSONNode extends PureComponent {
|
||||||
const nodeStart = h('div', {
|
const nodeStart = h('div', {
|
||||||
key: 'node',
|
key: 'node',
|
||||||
onKeyDown: this.handleKeyDown,
|
onKeyDown: this.handleKeyDown,
|
||||||
'data-selection-area': 'contents',
|
'data-selection-area': 'on',
|
||||||
className: 'jsoneditor-node jsoneditor-array'
|
className: 'jsoneditor-node jsoneditor-array'
|
||||||
}, [
|
}, [
|
||||||
this.renderExpandButton(),
|
this.renderExpandButton(),
|
||||||
|
@ -199,7 +199,7 @@ export default class JSONNode extends PureComponent {
|
||||||
|
|
||||||
childs = h('div', {
|
childs = h('div', {
|
||||||
key: 'childs',
|
key: 'childs',
|
||||||
'data-selection-area': 'left',
|
'data-selection-area': 'before',
|
||||||
className: 'jsoneditor-list'
|
className: 'jsoneditor-list'
|
||||||
}, items)
|
}, items)
|
||||||
}
|
}
|
||||||
|
@ -207,7 +207,7 @@ export default class JSONNode extends PureComponent {
|
||||||
childs = h('div', {
|
childs = h('div', {
|
||||||
key: 'childs',
|
key: 'childs',
|
||||||
className: 'jsoneditor-list',
|
className: 'jsoneditor-list',
|
||||||
'data-selection-area': 'left',
|
'data-selection-area': 'before',
|
||||||
'data-area': 'emptyBefore' // TODO: remove data-area
|
'data-area': 'emptyBefore' // TODO: remove data-area
|
||||||
},
|
},
|
||||||
this.renderEmpty('(empty array)')
|
this.renderEmpty('(empty array)')
|
||||||
|
@ -217,14 +217,14 @@ export default class JSONNode extends PureComponent {
|
||||||
|
|
||||||
const nodeEnd = this.props.eson[EXPANDED]
|
const nodeEnd = this.props.eson[EXPANDED]
|
||||||
? h('div', {key: 'node-end', className: 'jsoneditor-node-end', 'data-area': 'empty'}, [ // TODO: remove data-area
|
? h('div', {key: 'node-end', className: 'jsoneditor-node-end', 'data-area': 'empty'}, [ // TODO: remove data-area
|
||||||
this.renderDelimiter(']', 'jsoneditor-delimiter-end', 'left')
|
this.renderDelimiter(']', 'jsoneditor-delimiter-end', 'before')
|
||||||
])
|
])
|
||||||
: null
|
: null
|
||||||
|
|
||||||
return h('div', {
|
return h('div', {
|
||||||
'data-path': compileJSONPointer(this.state.path),
|
'data-path': compileJSONPointer(this.state.path),
|
||||||
'data-area': 'empty', // TODO: remove data-area
|
'data-area': 'empty', // TODO: remove data-area
|
||||||
'data-selection-area': 'right',
|
'data-selection-area': 'after',
|
||||||
className: this.getContainerClassName(this.props.eson[SELECTION], this.state.hover),
|
className: this.getContainerClassName(this.props.eson[SELECTION], this.state.hover),
|
||||||
// onMouseOver: this.handleMouseOver,
|
// onMouseOver: this.handleMouseOver,
|
||||||
// onMouseLeave: this.handleMouseLeave
|
// onMouseLeave: this.handleMouseLeave
|
||||||
|
@ -235,7 +235,7 @@ export default class JSONNode extends PureComponent {
|
||||||
const node = h('div', {
|
const node = h('div', {
|
||||||
key: 'node',
|
key: 'node',
|
||||||
onKeyDown: this.handleKeyDown,
|
onKeyDown: this.handleKeyDown,
|
||||||
'data-selection-area': 'contents',
|
'data-selection-area': 'on',
|
||||||
className: 'jsoneditor-node'
|
className: 'jsoneditor-node'
|
||||||
}, [
|
}, [
|
||||||
this.renderPlaceholder(),
|
this.renderPlaceholder(),
|
||||||
|
@ -250,7 +250,7 @@ export default class JSONNode extends PureComponent {
|
||||||
return h('div', {
|
return h('div', {
|
||||||
'data-path': compileJSONPointer(this.state.path),
|
'data-path': compileJSONPointer(this.state.path),
|
||||||
'data-area': 'empty', // TODO: remove
|
'data-area': 'empty', // TODO: remove
|
||||||
'data-selection-area': 'right',
|
'data-selection-area': 'after',
|
||||||
className: this.getContainerClassName(this.props.eson[SELECTION], this.state.hover),
|
className: this.getContainerClassName(this.props.eson[SELECTION], this.state.hover),
|
||||||
// onMouseOver: this.handleMouseOver,
|
// onMouseOver: this.handleMouseOver,
|
||||||
// onMouseLeave: this.handleMouseLeave
|
// onMouseLeave: this.handleMouseLeave
|
||||||
|
@ -266,11 +266,11 @@ export default class JSONNode extends PureComponent {
|
||||||
return h('div', {
|
return h('div', {
|
||||||
'data-path': compileJSONPointer(this.state.path) + '/-',
|
'data-path': compileJSONPointer(this.state.path) + '/-',
|
||||||
'data-area': 'empty', // TODO: remove
|
'data-area': 'empty', // TODO: remove
|
||||||
'data-selection-area': 'right',
|
'data-selection-area': 'after',
|
||||||
className: 'jsoneditor-node-container'
|
className: 'jsoneditor-node-container'
|
||||||
}, h('div', {
|
}, h('div', {
|
||||||
className: 'jsoneditor-node',
|
className: 'jsoneditor-node',
|
||||||
'data-selection-area': 'contents',
|
'data-selection-area': 'on',
|
||||||
onKeyDown: this.handleKeyDownAppend
|
onKeyDown: this.handleKeyDownAppend
|
||||||
}, [
|
}, [
|
||||||
this.renderPlaceholder(),
|
this.renderPlaceholder(),
|
||||||
|
@ -282,7 +282,7 @@ export default class JSONNode extends PureComponent {
|
||||||
return h('div', {
|
return h('div', {
|
||||||
key: 'placeholder',
|
key: 'placeholder',
|
||||||
// 'data-area': dataArea, // TODO: remove
|
// 'data-area': dataArea, // TODO: remove
|
||||||
'data-selection-area': 'left',
|
'data-selection-area': 'before',
|
||||||
className: 'jsoneditor-button-placeholder'
|
className: 'jsoneditor-button-placeholder'
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -555,7 +555,7 @@ export default class JSONNode extends PureComponent {
|
||||||
|
|
||||||
return h('div', {key: 'expand', className: 'jsoneditor-button-container'},
|
return h('div', {key: 'expand', className: 'jsoneditor-button-container'},
|
||||||
h('button', {
|
h('button', {
|
||||||
'data-selection-area': 'left',
|
'data-selection-area': 'before',
|
||||||
className: className,
|
className: className,
|
||||||
onClick: this.handleExpand,
|
onClick: this.handleExpand,
|
||||||
title:
|
title:
|
||||||
|
|
|
@ -876,7 +876,7 @@ export default class TreeMode extends PureComponent {
|
||||||
const areaParent = findParentWithAttribute(element, 'data-selection-area')
|
const areaParent = findParentWithAttribute(element, 'data-selection-area')
|
||||||
const area = areaParent ? areaParent.getAttribute('data-selection-area') : undefined
|
const area = areaParent ? areaParent.getAttribute('data-selection-area') : undefined
|
||||||
|
|
||||||
const base = (area === 'left')
|
const base = (area === 'before')
|
||||||
? document.elementFromPoint(element.getBoundingClientRect().right - 1, y)
|
? document.elementFromPoint(element.getBoundingClientRect().right - 1, y)
|
||||||
: element
|
: element
|
||||||
|
|
||||||
|
@ -901,11 +901,11 @@ export default class TreeMode extends PureComponent {
|
||||||
|
|
||||||
if (isEqual(startChildPath, sharedPath) || isEqual(endChildPath, sharedPath)) {
|
if (isEqual(startChildPath, sharedPath) || isEqual(endChildPath, sharedPath)) {
|
||||||
// one element
|
// one element
|
||||||
if (start.area === 'right' && end.area === 'right' && start.path === end.path) {
|
if (start.area === 'after' && end.area === 'after' && start.path === end.path) {
|
||||||
return { type: 'after', after: compileJSONPointer(sharedPath) }
|
return { type: 'after', after: compileJSONPointer(sharedPath) }
|
||||||
}
|
}
|
||||||
|
|
||||||
if (start.path !== end.path || start.area !== end.area || start.area === 'contents' || end.area === 'contents') {
|
if (start.path !== end.path || start.area !== end.area || start.area === 'on' || end.area === 'on') {
|
||||||
return { type: 'multi', multi: [ compileJSONPointer(sharedPath) ] }
|
return { type: 'multi', multi: [ compileJSONPointer(sharedPath) ] }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -921,8 +921,8 @@ export default class TreeMode extends PureComponent {
|
||||||
|
|
||||||
const first = startIndex < endIndex ? start : end
|
const first = startIndex < endIndex ? start : end
|
||||||
const last = startIndex < endIndex ? end : start
|
const last = startIndex < endIndex ? end : start
|
||||||
const includeFirst = first.area !== 'right' || parseJSONPointer(first.path).length > sharedPath.length + 1
|
const includeFirst = first.area !== 'after' || parseJSONPointer(first.path).length > sharedPath.length + 1
|
||||||
const includeLast = last.area !== 'left' || parseJSONPointer(last.path).length > sharedPath.length + 1
|
const includeLast = last.area !== 'before' || parseJSONPointer(last.path).length > sharedPath.length + 1
|
||||||
|
|
||||||
const firstIndex = Math.min(startIndex, endIndex) + (includeFirst ? 0 : 1)
|
const firstIndex = Math.min(startIndex, endIndex) + (includeFirst ? 0 : 1)
|
||||||
const lastIndex = Math.max(startIndex, endIndex) + (includeLast ? 1 : 0)
|
const lastIndex = Math.max(startIndex, endIndex) + (includeLast ? 1 : 0)
|
||||||
|
|
|
@ -39,7 +39,7 @@
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @typedef {{
|
* @typedef {{
|
||||||
* area: 'left' | 'contents' | 'after',
|
* area: 'before' | 'on' | 'after' | 'inside',
|
||||||
* path: string
|
* path: string
|
||||||
* }} SelectionPointer
|
* }} SelectionPointer
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in New Issue