commit
2a988a0194
18 changed files with 141 additions and 130 deletions
|
|
@ -59,7 +59,6 @@
|
|||
"stacktrace-js": "^2.0.0",
|
||||
"through": "^2.3.8",
|
||||
"uglifyify": "5.0.1",
|
||||
"wolfy87-eventemitter": "^5.2.4",
|
||||
"ws": "^6.0.0",
|
||||
"yargs": "12.0.2"
|
||||
},
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ var transforms = [
|
|||
]
|
||||
|
||||
if (prod) {
|
||||
console.warn('\x1b[36m%s\x1b[0m', '=> Building minified client bundle, this may take a while...')
|
||||
console.warn('\033[36m=> Building minified client bundle, this may take a while...\033[0m')
|
||||
transforms.push([transformWrapper(require('uglifyify')), {global: true}])
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -124,7 +124,7 @@ function updateWidget(widget, options={}) {
|
|||
|
||||
newWidget.container.parentNode.replaceChild(newWidget.container, widget.container)
|
||||
|
||||
if (newWidget.getProp('type') === 'tab') newWidget.parent.trigger('tab-created', [{widget: widget}])
|
||||
if (newWidget.getProp('type') === 'tab') newWidget.parent.trigger('tab-created', {widget: widget})
|
||||
if (newWidget.getProp('id') === 'root') DOM.get('.editor-root')[0].setAttribute('data-widget', newWidget.hash)
|
||||
|
||||
|
||||
|
|
@ -136,12 +136,12 @@ function updateWidget(widget, options={}) {
|
|||
if (reuseChildren) {
|
||||
// children don't listen to their parent's 'widget-created' event
|
||||
// so we have to let them know it's been updated
|
||||
widgetManager.trigger('prop-changed', [{
|
||||
widgetManager.trigger('prop-changed', {
|
||||
id: newWidget.getProp('id'),
|
||||
props: [],
|
||||
widget: newWidget,
|
||||
options: {}
|
||||
}])
|
||||
})
|
||||
}
|
||||
|
||||
resize.check(newWidget.container)
|
||||
|
|
|
|||
|
|
@ -20,7 +20,6 @@ function pointerDownHandler(event) {
|
|||
|
||||
if (event.traversing === TRAVERSING_SAMEWIDGET) {
|
||||
event.traversingType = event.target.closest('.drag-event')._drag_widget.getProp('type')
|
||||
console.log(event.traversingType)
|
||||
}
|
||||
|
||||
previousPointers[event.pointerId] = event
|
||||
|
|
@ -48,7 +47,6 @@ function pointerMoveHandler(event) {
|
|||
target && event.traversing === TRAVERSING_SAMEWIDGET
|
||||
&& event.traversingType !== target._drag_widget.getProp('type')
|
||||
) {
|
||||
console.log(event.traversingType, target._drag_widget.getProp('type'))
|
||||
target = null
|
||||
}
|
||||
|
||||
|
|
@ -193,7 +191,7 @@ function touchUpCapture(event) {
|
|||
|
||||
function triggerWidgetEvent(target, name, event) {
|
||||
if (target !== null && target._drag_widget) {
|
||||
target._drag_widget.trigger(name, [event])
|
||||
target._drag_widget.trigger(name, event)
|
||||
} else if (target !== null) {
|
||||
triggerWidgetEvent(target.closest('.drag-event'), name, event)
|
||||
}
|
||||
|
|
@ -215,9 +213,9 @@ module.exports = {
|
|||
setup: function(options) {
|
||||
|
||||
if (
|
||||
this._customBindings['drag'].bindings !== 0 ||
|
||||
this._customBindings['draginit'].bindings !== 0 ||
|
||||
this._customBindings['dragend'].bindings !== 0 ||
|
||||
this._customBindings['drag'] !== 0 ||
|
||||
this._customBindings['draginit'] !== 0 ||
|
||||
this._customBindings['dragend'] !== 0 ||
|
||||
!options
|
||||
) {
|
||||
return
|
||||
|
|
@ -242,9 +240,9 @@ module.exports = {
|
|||
teardown: function(options) {
|
||||
|
||||
if (
|
||||
this._customBindings['drag'].bindings !== 0 ||
|
||||
this._customBindings['draginit'].bindings !== 0 ||
|
||||
this._customBindings['dragend'].bindings !== 0 ||
|
||||
this._customBindings['drag'] !== 0 ||
|
||||
this._customBindings['draginit'] !== 0 ||
|
||||
this._customBindings['dragend'] !== 0 ||
|
||||
!options
|
||||
) {
|
||||
return
|
||||
|
|
|
|||
|
|
@ -1,92 +1,123 @@
|
|||
var WolfyEventEmitter = require('wolfy87-eventemitter'),
|
||||
customEvents = {}
|
||||
var customEvents = {}
|
||||
setTimeout(()=>{
|
||||
customEvents['draginit'] = customEvents['drag'] = customEvents['dragend'] = require('./drag')
|
||||
customEvents['resize'] = require('./resize')
|
||||
})
|
||||
|
||||
customEvents['draginit'] = customEvents['drag'] = customEvents['dragend'] = require('./drag')
|
||||
customEvents['resize'] = require('./resize')
|
||||
// micro optimisation from eventemitter3
|
||||
var has = Object.prototype.hasOwnProperty
|
||||
|
||||
module.exports = class EventEmitter extends WolfyEventEmitter {
|
||||
module.exports = class EventEmitter {
|
||||
|
||||
constructor() {
|
||||
|
||||
super()
|
||||
|
||||
this._customBindings = {}
|
||||
this._contextEvents = {}
|
||||
this._listeners = {}
|
||||
|
||||
for (var evt in customEvents) {
|
||||
this._customBindings[evt] = {
|
||||
bindings: 0
|
||||
}
|
||||
this._customBindings[evt] = 0
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
emitEvent(evt, args) {
|
||||
trigger(evt, data) {
|
||||
|
||||
if (has.call(this._listeners, evt)) {
|
||||
// shallow copy in case a listener gets added/removed while looping
|
||||
var listeners = this._listeners[evt].slice(0)
|
||||
for (var i = 0, len = listeners.length; i !== len; i++) {
|
||||
listeners[i](data)
|
||||
}
|
||||
}
|
||||
|
||||
// Event bubbling
|
||||
|
||||
super.emitEvent(evt, args)
|
||||
|
||||
if (args[0] && !args[0].stopPropagation) {
|
||||
if (this.parent) this.parent.emitEvent(evt, args)
|
||||
if (!data || !data.stopPropagation) {
|
||||
if (this.parent) this.parent.trigger(evt, data)
|
||||
}
|
||||
|
||||
return this
|
||||
|
||||
}
|
||||
|
||||
addListener(evt, listener, options) {
|
||||
on(evt, listener, options) {
|
||||
|
||||
// Custom event setup
|
||||
if (options) {
|
||||
|
||||
if (
|
||||
customEvents.hasOwnProperty(evt) &&
|
||||
typeof customEvents[evt].setup === 'function'
|
||||
) {
|
||||
if (this._customBindings[evt].bindings === 0) {
|
||||
this._customBindings[evt].options = options
|
||||
customEvents[evt].setup.call(this, options)
|
||||
// Custom event setup
|
||||
if (has.call(customEvents, evt)) {
|
||||
this._customBindings[evt]
|
||||
if (this._customBindings[evt] === 0) {
|
||||
listener._options = options
|
||||
customEvents[evt].setup.call(this, options)
|
||||
}
|
||||
this._customBindings[evt]++
|
||||
}
|
||||
this._customBindings[evt].bindings += 1
|
||||
|
||||
// Context storing
|
||||
if (options.context) listener._context = options.context
|
||||
|
||||
}
|
||||
|
||||
if (options && options.context) {
|
||||
var hash = options.context.hash
|
||||
if (!this._contextEvents[hash]) this._contextEvents[hash] = []
|
||||
this._contextEvents[hash].push([evt, listener])
|
||||
}
|
||||
// Add listener
|
||||
if (!has.call(this._listeners, evt)) this._listeners[evt] = []
|
||||
|
||||
super.addListener(evt, listener)
|
||||
var listeners = this._listeners[evt]
|
||||
|
||||
if (listeners.indexOf(listener) === -1) listeners.push(listener)
|
||||
|
||||
return this
|
||||
|
||||
}
|
||||
|
||||
removeListener(evt, listener) {
|
||||
off(evt, listener, context) {
|
||||
|
||||
// Custom event teardown
|
||||
// Remove listener
|
||||
if (evt && has.call(this._listeners, evt)) {
|
||||
|
||||
var listeners = this._listeners[evt]
|
||||
|
||||
if (listener) {
|
||||
|
||||
var index = listeners.indexOf(listener)
|
||||
|
||||
if (index !== -1) {
|
||||
|
||||
if (context && context !== listener._context) return this
|
||||
|
||||
listeners.splice(index, 1)
|
||||
|
||||
// Custom event teardown
|
||||
if (has.call(customEvents, evt)) {
|
||||
|
||||
if (this._customBindings[evt] !== 0) {
|
||||
this._customBindings[evt]--
|
||||
if (this._customBindings[evt] === 0) {
|
||||
customEvents[evt].teardown.call(this, listener._options)
|
||||
delete listener._options
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
for (var i = listeners.length - 1; i !== -1; i--) {
|
||||
|
||||
if (!context || context == listeners[i]._context) {
|
||||
this.off(evt, listeners[i], context)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (
|
||||
customEvents.hasOwnProperty(evt) &&
|
||||
typeof customEvents[evt].teardown === 'function' &&
|
||||
this._customBindings[evt].bindings !== 0
|
||||
) {
|
||||
this._customBindings[evt].bindings -= 1
|
||||
if (this._customBindings[evt].bindings === 0 || !listener) {
|
||||
var options = this._customBindings[evt].options
|
||||
customEvents[evt].teardown.call(this, options)
|
||||
}
|
||||
}
|
||||
|
||||
// Remove all listeners is none specified
|
||||
} else if (!evt) {
|
||||
|
||||
if (listener) {
|
||||
|
||||
super.removeListener(evt, listener)
|
||||
|
||||
} else {
|
||||
|
||||
this.removeEvent(evt)
|
||||
for (var k in this._listeners) {
|
||||
this.off(k, undefined, context)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -94,24 +125,4 @@ module.exports = class EventEmitter extends WolfyEventEmitter {
|
|||
|
||||
}
|
||||
|
||||
removeEventContext(context, evt, listener) {
|
||||
|
||||
var events = this._contextEvents[context.hash]
|
||||
|
||||
if (events) {
|
||||
|
||||
for (var i = 0; i < events.length; i++) {
|
||||
|
||||
if (evt && evt !== events[i][0]) continue
|
||||
if (listener && listener !== events[i][1]) continue
|
||||
|
||||
this.removeListener(events[i][0], events[i][1])
|
||||
}
|
||||
|
||||
if (!this._contextEvents[context.hash].length) delete this._contextEvents[context.hash]
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,12 +25,12 @@ function checkResizes(context, force){
|
|||
}
|
||||
}
|
||||
for (let i = resizedElems.length - 1; i >= 0; i--) {
|
||||
resizedElems[i]._resize_widget.trigger('resize', [{
|
||||
resizedElems[i]._resize_widget.trigger('resize', {
|
||||
width: resizedElems[i].resizedataw,
|
||||
height: resizedElems[i].resizedatah,
|
||||
style:cachedStyles[i],
|
||||
stopPropagation: true
|
||||
}])
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -95,7 +95,7 @@ module.exports = {
|
|||
},
|
||||
|
||||
reload: function(){
|
||||
console.log('reload?')
|
||||
|
||||
var id = Math.random(),
|
||||
search = location.search,
|
||||
query = 'backupId=' + id
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
var EventEmitter = require('wolfy87-eventemitter'),
|
||||
var EventEmitter = require('../events/event-emitter'),
|
||||
uuid = require('nanoid/generate')('0123456789abcdefghijklmnopqrstuvwxyABCDEFGHIJKLMNOPQRSTUVWXYZ', 10)
|
||||
|
||||
var reconnectInterval = 5000,
|
||||
|
|
@ -104,7 +104,7 @@ class Ipc extends EventEmitter {
|
|||
|
||||
if (Array.isArray(packet) && typeof packet[0] == 'string') {
|
||||
|
||||
this.emit(packet[0], packet[1])
|
||||
this.trigger(packet[0], packet[1])
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -68,12 +68,12 @@ var SessionManager = class SessionManager {
|
|||
|
||||
for (var h in widgetManager.widgets) {
|
||||
if (widgetManager.widgets[h].value !== undefined) {
|
||||
widgetManager.trigger('change', [{
|
||||
widgetManager.trigger('change', {
|
||||
widget: widgetManager.widgets[h],
|
||||
id: widgetManager.widgets[h].getProp('id'),
|
||||
linkId: widgetManager.widgets[h].getProp('linkId'),
|
||||
options: {}
|
||||
}])
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ var WidgetManager = class WidgetManager extends EventEmitter {
|
|||
|
||||
this.preArgsSeparator = '||||'
|
||||
|
||||
this.on('change', this.onChange, this)
|
||||
this.on('change', this.onChange.bind(this))
|
||||
|
||||
ipc.on('connect', ()=>{
|
||||
for (var hash in this.widgets) {
|
||||
|
|
@ -175,7 +175,7 @@ var WidgetManager = class WidgetManager extends EventEmitter {
|
|||
hash:hash
|
||||
})
|
||||
|
||||
widget.trigger('widget-removed', [{widget: widget}])
|
||||
widget.trigger('widget-removed', {widget: widget})
|
||||
|
||||
}
|
||||
if (id && this.idRoute[id].indexOf(hash) != -1) this.idRoute[id].splice(this.idRoute[id].indexOf(hash), 1)
|
||||
|
|
@ -234,9 +234,9 @@ var WidgetManager = class WidgetManager extends EventEmitter {
|
|||
|
||||
this.removeWidgets(Object.values(this.widgets))
|
||||
|
||||
this.removeEvent()
|
||||
this.off()
|
||||
|
||||
this.on('change', this.onChange, this)
|
||||
this.on('change', this.onChange.bind(this))
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -49,7 +49,7 @@ var Osc = class Osc extends EventEmitter {
|
|||
}
|
||||
}
|
||||
|
||||
this.trigger(data.address, [data.args])
|
||||
this.trigger(data.address, data.args)
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ module.exports = class OscReceiver {
|
|||
|
||||
if (this.address !== address) {
|
||||
|
||||
if (this.address) osc.removeEventContext(this.parent, this.address, this.bindedCallback)
|
||||
if (this.address) osc.off(this.address, this.bindedCallback, this.parent)
|
||||
|
||||
this.address = address
|
||||
osc.on(this.address, this.bindedCallback, {context: this.parent})
|
||||
|
|
|
|||
|
|
@ -156,8 +156,6 @@ class Widget extends EventEmitter {
|
|||
this.errors.id = 'There can only be one root'
|
||||
}
|
||||
|
||||
this.createLinkedPropsBindings()
|
||||
|
||||
this.disabledProps = []
|
||||
|
||||
// cache precision
|
||||
|
|
@ -209,23 +207,23 @@ class Widget extends EventEmitter {
|
|||
|
||||
created(index) {
|
||||
|
||||
this.trigger('widget-created', [{
|
||||
this.trigger('widget-created', {
|
||||
id: this.getProp('id'),
|
||||
widget: this,
|
||||
options: this.reCreateOptions,
|
||||
index: index
|
||||
}])
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
changed(options) {
|
||||
|
||||
this.trigger('change', [{
|
||||
this.trigger('change', {
|
||||
widget: this,
|
||||
options: options,
|
||||
id: this.getProp('id'),
|
||||
linkId: this.getProp('linkId')
|
||||
}])
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -313,10 +311,10 @@ class Widget extends EventEmitter {
|
|||
widgetManager.on('widget-created', this.linkedCreatedCallback, {context: this})
|
||||
widgetManager.on('prop-changed', this.linkedPropChangedCallback, {context: this})
|
||||
|
||||
} else if (this.linkedCreatedCallback && !Object.keys(this.linkedPropsValue).length) {
|
||||
} else if (this.linkedCreatedCallback && !Object.keys(this.linkedProps).length) {
|
||||
|
||||
widgetManager.removeEventContext('widget-created', this.linkedCreatedCallback, {context: this})
|
||||
widgetManager.removeEventContext('prop-changed', this.linkedPropChangedCallback, {context: this})
|
||||
widgetManager.off('widget-created', this.linkedCreatedCallback)
|
||||
widgetManager.off('prop-changed', this.linkedPropChangedCallback)
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -330,7 +328,7 @@ class Widget extends EventEmitter {
|
|||
|
||||
} else if (this.linkedPropsValueCallback && !Object.keys(this.linkedPropsValue).length) {
|
||||
|
||||
widgetManager.removeEventContext('change', this.linkedValueChangedCallback, {context: this})
|
||||
widgetManager.off('change', this.linkedValueChangedCallback)
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -364,7 +362,7 @@ class Widget extends EventEmitter {
|
|||
|
||||
removeOscReceivers() {
|
||||
|
||||
osc.removeEventContext(this)
|
||||
osc.off(undefined, undefined, this)
|
||||
for (var i in this.oscReceivers) {
|
||||
oscReceiverState[i] = this.oscReceivers[i].value
|
||||
}
|
||||
|
|
@ -650,12 +648,12 @@ class Widget extends EventEmitter {
|
|||
this.onPropChanged(changedProps[i].propName, options, changedProps[i].oldPropValue)
|
||||
}
|
||||
|
||||
widgetManager.trigger('prop-changed', [{
|
||||
widgetManager.trigger('prop-changed', {
|
||||
id: this.getProp('id'),
|
||||
props: changedProps,
|
||||
widget: this,
|
||||
options: options
|
||||
}])
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -841,7 +839,7 @@ class Widget extends EventEmitter {
|
|||
|
||||
onRemove(){
|
||||
|
||||
widgetManager.removeEventContext(this)
|
||||
widgetManager.off(undefined, undefined, this)
|
||||
this.removeOscReceivers()
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -150,7 +150,7 @@ class Clone extends Container {
|
|||
|
||||
if (!this.cloneTarget) return
|
||||
|
||||
this.cloneTarget.removeEventContext(this)
|
||||
this.cloneTarget.off(undefined, undefined, this)
|
||||
|
||||
this.cloneTarget = null
|
||||
|
||||
|
|
|
|||
|
|
@ -115,7 +115,7 @@ module.exports = class MultiXy extends Pad {
|
|||
|
||||
e.stopPropagation = true
|
||||
|
||||
this.pads[id].trigger('draginit', [e])
|
||||
this.pads[id].trigger('draginit', e)
|
||||
|
||||
}, {element: this.wrapper, multitouch: true})
|
||||
|
||||
|
|
@ -123,7 +123,7 @@ module.exports = class MultiXy extends Pad {
|
|||
|
||||
var i = this.touchMap[e.pointerId]
|
||||
|
||||
this.pads[i].trigger('drag', [e])
|
||||
this.pads[i].trigger('drag', e)
|
||||
|
||||
}, {element: this.wrapper[0], multitouch: true})
|
||||
|
||||
|
|
@ -133,7 +133,7 @@ module.exports = class MultiXy extends Pad {
|
|||
|
||||
e.stopPropagation = true
|
||||
|
||||
this.pads[i].trigger('dragend', [e])
|
||||
this.pads[i].trigger('dragend', e)
|
||||
|
||||
delete this.touchMap[e.pointerId]
|
||||
|
||||
|
|
|
|||
|
|
@ -102,21 +102,21 @@ module.exports = class Xy extends Pad {
|
|||
|
||||
this.on('draginit',(e)=>{
|
||||
e.stopPropagation = true
|
||||
this.faders.x.trigger('draginit', [e])
|
||||
this.faders.y.trigger('draginit', [e])
|
||||
this.faders.x.trigger('draginit', e)
|
||||
this.faders.y.trigger('draginit', e)
|
||||
this.dragHandle()
|
||||
}, {element: this.wrapper})
|
||||
|
||||
this.on('drag',(e)=>{
|
||||
this.faders.x.trigger('drag', [e])
|
||||
this.faders.y.trigger('drag', [e])
|
||||
this.faders.x.trigger('drag', e)
|
||||
this.faders.y.trigger('drag', e)
|
||||
this.dragHandle()
|
||||
}, {element: this.wrapper})
|
||||
|
||||
this.on('dragend', (e)=>{
|
||||
e.stopPropagation = true
|
||||
this.faders.x.trigger('dragend', [e])
|
||||
this.faders.y.trigger('dragend', [e])
|
||||
this.faders.x.trigger('dragend', e)
|
||||
this.faders.y.trigger('dragend', e)
|
||||
if (this.getProp('spring')) {
|
||||
this.setValue([this.faders.x.springValue,this.faders.y.springValue],{sync:true,send:true})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -316,7 +316,7 @@ module.exports = class Range extends Widget {
|
|||
if (!id) return
|
||||
|
||||
e.stopPropagation = true
|
||||
this.faders[id].trigger('draginit', [e])
|
||||
this.faders[id].trigger('draginit', e)
|
||||
|
||||
}, {element: this.wrapper, multitouch: true})
|
||||
|
||||
|
|
@ -324,10 +324,10 @@ module.exports = class Range extends Widget {
|
|||
|
||||
var i = this.touchMap[e.pointerId]
|
||||
if (e.shiftKey) {
|
||||
this.faders[0].trigger('drag', [e])
|
||||
this.faders[1].trigger('drag', [e])
|
||||
this.faders[0].trigger('drag', e)
|
||||
this.faders[1].trigger('drag', e)
|
||||
} else {
|
||||
this.faders[i].trigger('drag', [e])
|
||||
this.faders[i].trigger('drag', e)
|
||||
}
|
||||
|
||||
}, {element: this.wrapper, multitouch: true})
|
||||
|
|
@ -336,7 +336,7 @@ module.exports = class Range extends Widget {
|
|||
|
||||
var i = this.touchMap[e.pointerId]
|
||||
e.stopPropagation = true
|
||||
this.faders[i].trigger('dragend', [e])
|
||||
this.faders[i].trigger('dragend', e)
|
||||
delete this.touchMap[e.pointerId]
|
||||
|
||||
}, {element: this.wrapper, multitouch: true})
|
||||
|
|
|
|||
|
|
@ -30,13 +30,18 @@ function std(data){
|
|||
|
||||
if (data.includes('process error')) {
|
||||
console.error(data.toString())
|
||||
console.log('\033[31m\n=> Test errored ✘\n\033[0m')
|
||||
|
||||
end()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// timeout after 5s -> no error
|
||||
setTimeout(end, 5000)
|
||||
setTimeout(()=>{
|
||||
console.log('\033[36m\n=> Test timeout without error ✔\n\033[0m')
|
||||
end()
|
||||
}, 5000)
|
||||
|
||||
function end(fail){
|
||||
process.kill(-proc.pid)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue