widgets: add new clone widget (wip, still some issue detecting original widget's nested edits)
This commit is contained in:
parent
97e8bc12df
commit
ed04519f5b
5 changed files with 139 additions and 4 deletions
|
|
@ -29,7 +29,7 @@ module.exports = function(session,callback) {
|
|||
p.close()
|
||||
$('#lobby').show()
|
||||
createPopup(icon('warning')+' Parsing error', err,true)
|
||||
return
|
||||
throw err
|
||||
}
|
||||
|
||||
stateSet(stateGet(), false)
|
||||
|
|
|
|||
|
|
@ -38,6 +38,7 @@ module.exports.widgets = {
|
|||
strip: require('./widgets/containers/strip'),
|
||||
panel: require('./widgets/containers/panel'),
|
||||
modal: require('./widgets/containers/modal'),
|
||||
clone: require('./widgets/containers/clone'),
|
||||
|
||||
// state switchers
|
||||
switcher: require('./widgets/switchers/switcher'),
|
||||
|
|
@ -48,6 +49,7 @@ module.exports.widgets = {
|
|||
|
||||
// maths
|
||||
formula: require('./widgets/maths/formula')
|
||||
|
||||
}
|
||||
|
||||
module.exports.categories = {
|
||||
|
|
@ -56,7 +58,7 @@ module.exports.categories = {
|
|||
'Pads':['xy','rgb','multixy'],
|
||||
'Matrices':['multifader','multitoggle','multipush', 'keyboard'],
|
||||
'Plots':['plot','eq','visualizer','led', 'rgbled','meter','text'],
|
||||
'Containers':['panel','strip','modal'],
|
||||
'Containers':['panel','strip','modal', 'clone'],
|
||||
'Switchers':['switcher','crossfader'],
|
||||
'Inputs':['input'],
|
||||
'Maths':['formula']
|
||||
|
|
|
|||
|
|
@ -60,13 +60,14 @@ module.exports = class _widgets_base {
|
|||
}
|
||||
}
|
||||
|
||||
$('body').on(`widget-created.${this.hash}`, (e, id)=>{
|
||||
$('body').on(`widget-created.${this.hash}`, (e)=>{
|
||||
var {id} = e
|
||||
if (this.linkedPropsWidgets.indexOf(id) != -1 && id != this.getProp('id')) {
|
||||
this.checkPropsChanged()
|
||||
}
|
||||
})
|
||||
|
||||
$('body').trigger('widget-created', this.getProp('id'))
|
||||
$('body').trigger({type: 'widget-created', id: this.getProp('id'), hash:this.hash})
|
||||
|
||||
// cache precision
|
||||
if (this.props.precision != undefined) {
|
||||
|
|
|
|||
105
src/browser/js/app/widgets/containers/clone.js
Normal file
105
src/browser/js/app/widgets/containers/clone.js
Normal file
|
|
@ -0,0 +1,105 @@
|
|||
var _widgets_base = require('../common/_widgets_base'),
|
||||
{widgetManager} = require('../../managers'),
|
||||
purge = require('../../editor/purge')
|
||||
|
||||
module.exports = class Clone extends _widgets_base {
|
||||
|
||||
static defaults() {
|
||||
|
||||
return {
|
||||
type:'clone',
|
||||
id:'auto',
|
||||
|
||||
_geometry:'geometry',
|
||||
|
||||
left:'auto',
|
||||
top:'auto',
|
||||
width:'auto',
|
||||
height:'auto',
|
||||
|
||||
_style:'style',
|
||||
|
||||
css:'',
|
||||
|
||||
_clone:'clone',
|
||||
|
||||
widgetId:'',
|
||||
|
||||
_children:'children',
|
||||
|
||||
variables:'@{parent.variables}',
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
constructor(options) {
|
||||
|
||||
options.props.label = false
|
||||
|
||||
super({...options, html: '<div class="clone"></div>'})
|
||||
|
||||
this.cloneHash = [0]
|
||||
this.cloneLock = false
|
||||
this.originalHash = false
|
||||
this.createClone()
|
||||
|
||||
$('body').on(`widget-created.${this.hash}`, (e)=>{
|
||||
var {id, hash} = e
|
||||
if ((id == this.getProp('widgetId') && this.cloneHash.indexOf(hash) == -1) ||
|
||||
(widgetManager.widgets[this.originalHash] && widgetManager.widgets[this.originalHash].hashes && widgetManager.widgets[this.originalHash].hashes.indexOf(hash) != -1)
|
||||
) {
|
||||
this.createClone()
|
||||
}
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
createClone() {
|
||||
|
||||
if (this.cloneLock) return
|
||||
|
||||
this.cloneLock = true
|
||||
|
||||
var parsewidgets = require('../../parser').widgets
|
||||
|
||||
this.widget.empty()
|
||||
purge(this.cloneHash)
|
||||
|
||||
var widgets = widgetManager.getWidgetById(this.getProp('widgetId'))
|
||||
|
||||
if (widgets.length) {
|
||||
|
||||
for (var i in widgets) {
|
||||
|
||||
if (this.cloneHash.indexOf(widgets[i].hash) == -1) {
|
||||
|
||||
this.originalHash = widgets[i].hash
|
||||
|
||||
var c = parsewidgets([_widgets_base.deepCopy(widgets[i].props)], this.widget, this)
|
||||
|
||||
this.widget.find('.widget').addClass('not-editable')
|
||||
this.container[0].style.setProperty('--color-border', getComputedStyle(c[0]).getPropertyValue('--color-border'))
|
||||
|
||||
this.hashes = [this.hash]
|
||||
if (c[0].abstract.hashes) {
|
||||
this.hashes = this.hashes.concat(c[0].abstract.hashes)
|
||||
this.cloneHash = c[0].abstract.hashes
|
||||
} else {
|
||||
this.hashes.push(c[0].abstract.hash)
|
||||
this.cloneHash = [c[0].abstract.hash]
|
||||
}
|
||||
|
||||
break
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
this.cloneLock = false
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -260,3 +260,30 @@
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
.clone-container {
|
||||
width: 100rem;
|
||||
height: 100rem;
|
||||
border:0;
|
||||
box-shadow: none;
|
||||
background: transparent;
|
||||
|
||||
.clone {
|
||||
position: relative;
|
||||
height: 100%;
|
||||
width: 100%;
|
||||
> .widget {
|
||||
position: relative!important;
|
||||
left:auto!important;
|
||||
bottom:auto!important;
|
||||
right:auto!important;
|
||||
top: auto!important;
|
||||
width: 100%!important;
|
||||
height: 100%!important;
|
||||
min-height: initial!important;
|
||||
max-height: initial!important;
|
||||
min-width: initial!important;
|
||||
max-width: initial!important;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue