allow copying tabs too
This commit is contained in:
parent
49ac867c63
commit
07b67f10d2
7 changed files with 75 additions and 48 deletions
|
|
@ -1,5 +1,6 @@
|
|||
var {updateWidget} = require('./data-workers'),
|
||||
{categories} = require('../widgets/'),
|
||||
Panel = require('../widgets/containers/panel'),
|
||||
widgetManager = require('../managers/widgets'),
|
||||
{icon} = require('../ui/utils'),
|
||||
editor = require('./'),
|
||||
|
|
@ -48,16 +49,14 @@ var handleClick = function(event) {
|
|||
|
||||
var index = editor.selectedWidgets.map((w)=>DOM.index(w.container)).sort((a,b)=>{return b-a}),
|
||||
data = editor.selectedWidgets.map((w)=>w.props),
|
||||
type = editor.selectedWidgets[0].props.type == 'tab' ? 'tab' : 'widget',
|
||||
parent = editor.selectedWidgets[0].parent,
|
||||
widget = editor.selectedWidgets[0],
|
||||
parent = widget.parent,
|
||||
actions = []
|
||||
|
||||
// case !root
|
||||
|
||||
var clickX = Math.round((eventData.offsetX + eventData.target.scrollLeft) / (GRIDWIDTH * PXSCALE)) * GRIDWIDTH,
|
||||
clickY = Math.round((eventData.offsetY + eventData.target.scrollTop) / (GRIDWIDTH * PXSCALE)) * GRIDWIDTH
|
||||
|
||||
if (type === 'widget' && parent !== widgetManager) {
|
||||
if (parent !== widgetManager) {
|
||||
|
||||
if (event.target.tagName !== 'LI') actions.push({
|
||||
label: icon('project-diagram') + ' ' + locales('editor_show_in_tree'),
|
||||
|
|
@ -78,38 +77,48 @@ var handleClick = function(event) {
|
|||
|
||||
}
|
||||
|
||||
|
||||
if (data.length == 1 && (!data[0].tabs || !data[0].tabs.length) && (data[0].widgets)) {
|
||||
if (widget.childrenType !== undefined) {
|
||||
|
||||
if (editor.clipboard !== null) {
|
||||
|
||||
var pasteActions = []
|
||||
var pasteActions = [],
|
||||
canPaste = true
|
||||
|
||||
pasteActions.push({
|
||||
label: icon('paste') + ' ' + locales('editor_paste'),
|
||||
action: ()=>{
|
||||
editor.pasteWidget(clickX, clickY)
|
||||
}
|
||||
})
|
||||
pasteActions.push({
|
||||
label: icon('plus-square') + ' ' + locales('editor_pasteindent'),
|
||||
action: ()=>{
|
||||
editor.pasteWidget(clickX, clickY, true)
|
||||
}
|
||||
})
|
||||
if (
|
||||
editor.clipboard[0].type === 'tab' && widget.childrenType === 'widget' ||
|
||||
editor.clipboard[0].type !== 'tab' && widget.childrenType === 'tab'
|
||||
) canPaste = false
|
||||
|
||||
if (canPaste) {
|
||||
|
||||
if (editor.idClipboard && widgetManager.getWidgetById(editor.idClipboard).length) {
|
||||
pasteActions.push({
|
||||
label: icon('clone') + ' ' + locales('editor_clone'),
|
||||
label: icon('paste') + ' ' + locales('editor_paste'),
|
||||
action: ()=>{
|
||||
editor.pasteWidgetAsClone(clickX, clickY)
|
||||
editor.pasteWidget(clickX, clickY)
|
||||
}
|
||||
})
|
||||
pasteActions.push({
|
||||
label: icon('plus-square') + ' ' + locales('editor_pasteindent'),
|
||||
action: ()=>{
|
||||
editor.pasteWidget(clickX, clickY, true)
|
||||
}
|
||||
})
|
||||
|
||||
if (editor.idClipboard && widgetManager.getWidgetById(editor.idClipboard).length && editor.clipboard[0].type !== 'tab') {
|
||||
pasteActions.push({
|
||||
label: icon('clone') + ' ' + locales('editor_clone'),
|
||||
action: ()=>{
|
||||
editor.pasteWidgetAsClone(clickX, clickY)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
actions.push({
|
||||
label: icon('paste') + ' ' + locales('editor_paste'),
|
||||
action: pasteActions
|
||||
action: pasteActions,
|
||||
class: canPaste ? '' : 'disabled'
|
||||
})
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,7 +9,6 @@ var {updateWidget, incrementWidget} = require('./data-workers'),
|
|||
UiInspector = require('../ui/ui-inspector'),
|
||||
UiTree = require('../ui/ui-tree'),
|
||||
UiDragResize = require('../ui/ui-dragresize'),
|
||||
Panel = require('../widgets/containers/panel'),
|
||||
sidepanel = require('../ui/ui-sidepanel'),
|
||||
html = require('nanohtml'),
|
||||
sessionManager
|
||||
|
|
@ -449,18 +448,14 @@ var Editor = class Editor {
|
|||
|
||||
if (!this.selectedWidgets.length) return
|
||||
|
||||
var data = this.selectedWidgets.map((w)=>w.props),
|
||||
type = this.selectedWidgets[0].props.type == 'tab' ? 'tab' : 'widget'
|
||||
var data = this.selectedWidgets.map((w)=>w.props)
|
||||
|
||||
|
||||
if (type !== 'widget') return
|
||||
|
||||
this.clipboard = JSON.stringify(data)
|
||||
this.clipboard = deepCopy(data)
|
||||
|
||||
if (data.length == 1) {
|
||||
this.idClipboard = this.selectedWidgets[0].getProp('id')
|
||||
} else {
|
||||
this.idClipboard =null
|
||||
this.idClipboard = null
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -469,20 +464,17 @@ var Editor = class Editor {
|
|||
|
||||
if (!this.selectedWidgets.length) return
|
||||
|
||||
var type = this.selectedWidgets[0].props.type == 'tab' ? 'tab' : 'widget',
|
||||
parent = this.selectedWidgets[0].parent,
|
||||
var parent = this.selectedWidgets[0].parent,
|
||||
index = this.selectedWidgets.map(w => parent.children.indexOf(w)).sort((a,b)=>{return b-a}),
|
||||
data = this.selectedWidgets.map((w)=>w.props),
|
||||
removedIndexes = []
|
||||
|
||||
if (type !== 'widget') return
|
||||
|
||||
this.clipboard = JSON.stringify(data)
|
||||
this.clipboard = deepCopy(data)
|
||||
|
||||
if (data.length == 1) {
|
||||
this.idClipboard = this.selectedWidgets[0].getProp('id')
|
||||
} else {
|
||||
this.idClipboard =null
|
||||
this.idClipboard = null
|
||||
}
|
||||
|
||||
for (var i of index) {
|
||||
|
|
@ -501,13 +493,19 @@ var Editor = class Editor {
|
|||
pasteWidget(x, y, increment) {
|
||||
|
||||
if (!this.selectedWidgets.length || this.clipboard === null) return
|
||||
if (!(this.selectedWidgets[0] instanceof Panel)) return
|
||||
if (
|
||||
this.selectedWidgets[0].childrenType === undefined ||
|
||||
this.clipboard[0].type === 'tab' && this.selectedWidgets[0].childrenType === 'widget' ||
|
||||
this.clipboard[0].type !== 'tab' && this.selectedWidgets[0].childrenType === 'tab'
|
||||
) return
|
||||
|
||||
|
||||
var data = this.selectedWidgets.map((w)=>w.props)
|
||||
|
||||
var pastedData = JSON.parse(this.clipboard),
|
||||
var pastedData = deepCopy(this.clipboard),
|
||||
minTop = Infinity,
|
||||
minLeft = Infinity
|
||||
minLeft = Infinity,
|
||||
store = this.clipboard[0].type === 'tab' ? 'tabs' : 'widgets'
|
||||
|
||||
for (let i in pastedData) {
|
||||
if (increment) pastedData[i] = incrementWidget(pastedData[i])
|
||||
|
|
@ -526,12 +524,12 @@ var Editor = class Editor {
|
|||
|
||||
}
|
||||
|
||||
data[0].widgets = data[0].widgets || []
|
||||
data[0].widgets = data[0].widgets.concat(pastedData)
|
||||
data[0][store] = data[0][store] || []
|
||||
data[0][store] = data[0][store].concat(pastedData)
|
||||
|
||||
var indexes = {addedIndexes: []}
|
||||
for (let i = 0; i < pastedData.length; i++) {
|
||||
indexes.addedIndexes.push(data[0].widgets.length - 1 - i )
|
||||
indexes.addedIndexes.push(data[0][store].length - 1 - i )
|
||||
}
|
||||
updateWidget(this.selectedWidgets[0], indexes)
|
||||
this.pushHistory(indexes)
|
||||
|
|
@ -540,17 +538,22 @@ var Editor = class Editor {
|
|||
|
||||
pasteWidgetAsClone(x, y) {
|
||||
|
||||
if (!this.selectedWidgets.length) return
|
||||
if (!this.selectedWidgets.length || this.clipboard === null) return
|
||||
if (!this.idClipboard || !widgetManager.getWidgetById(this.idClipboard).length) return
|
||||
|
||||
if (this.clipboard === null || !(this.idClipboard && widgetManager.getWidgetById(this.idClipboard).length)) return
|
||||
if (
|
||||
this.selectedWidgets[0].childrenType === undefined ||
|
||||
this.clipboard[0].type === 'tab' ||
|
||||
this.clipboard[0].type !== 'tab' && this.selectedWidgets[0].childrenType === 'tab'
|
||||
) return
|
||||
|
||||
var data = this.selectedWidgets.map((w)=>w.props)
|
||||
|
||||
var clone = {type: 'clone', widgetId: this.idClipboard},
|
||||
pastedData = JSON.parse(this.clipboard)
|
||||
pastedData = deepCopy(this.clipboard)
|
||||
|
||||
clone.width = pastedData.width
|
||||
clone.height = pastedData.width
|
||||
clone.height = pastedData.height
|
||||
clone.css = pastedData.css
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -140,6 +140,11 @@ class ContextMenu extends UiWidget {
|
|||
|
||||
this.container.parentNode.removeChild(this.container)
|
||||
|
||||
// remove position fix
|
||||
this.container.style.bottom = ''
|
||||
this.container.style.right = ''
|
||||
this.container.style.marginRight = ''
|
||||
|
||||
}
|
||||
|
||||
document.removeEventListener('fast-click', this.clickHandler, true)
|
||||
|
|
|
|||
|
|
@ -126,6 +126,7 @@ class UiTree extends UiWidget {
|
|||
while (parent !== this.list) {
|
||||
if (parent.classList.contains('container')) {
|
||||
parent.classList.add('expanded')
|
||||
this.expanded[parent.getAttribute('data-id')] = true
|
||||
}
|
||||
parent = parent.parentNode
|
||||
}
|
||||
|
|
|
|||
|
|
@ -42,6 +42,8 @@ class Matrix extends StaticProperties(Panel, {scroll: false}) {
|
|||
|
||||
super(options)
|
||||
|
||||
this.childrenType = undefined
|
||||
|
||||
this.value = []
|
||||
|
||||
this.on('change',(e)=>{
|
||||
|
|
|
|||
|
|
@ -114,6 +114,7 @@ class Modal extends Panel {
|
|||
this.popupContent.style.setProperty('--widget-padding', this.getProp('padding') != 'auto' ? parseFloat(this.getProp('padding')) + 'rem' : '')
|
||||
|
||||
|
||||
this.childrenType = 'widget'
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -49,6 +49,8 @@ class Panel extends Container() {
|
|||
|
||||
super({...options, html: html`<inner></inner>`})
|
||||
|
||||
this.childrenType = ''
|
||||
|
||||
this.container.classList.toggle('no-scroll', !this.getProp('scroll'))
|
||||
this.container.classList.add('layout-' + this.getProp('layout'))
|
||||
|
||||
|
|
@ -84,6 +86,8 @@ class Panel extends Container() {
|
|||
|
||||
if (this.getProp('tabs') && this.getProp('tabs').length) {
|
||||
|
||||
this.childrenType = 'tab'
|
||||
|
||||
this.value = -1
|
||||
|
||||
this.navigation = this.widget.appendChild(html`<div class="navigation ${this.getProp('verticalTabs') ? 'vertical' : ''}"></div>`)
|
||||
|
|
@ -125,6 +129,8 @@ class Panel extends Container() {
|
|||
|
||||
} else if (this.getProp('widgets') && this.getProp('widgets').length) {
|
||||
|
||||
this.childrenType = 'widget'
|
||||
|
||||
this.children = options.children || new Array(this.getProp('widgets').length)
|
||||
for (let i = 0; i < this.children.length; i++) {
|
||||
if (this.children[i]) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue