diff --git a/.eslintrc.json b/.eslintrc.json index 5a9fe439..08926624 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -27,13 +27,6 @@ "args": "none" } ], - "arrow-spacing": [ - "error", - { - "before": false, - "after": false - } - ], "space-before-function-paren": [ "error", "never" @@ -45,7 +38,8 @@ "SwitchCase": 1, "ObjectExpression": 1, "ArrayExpression": 1, - "MemberExpression": 1 + "MemberExpression": "off", + "ignoredNodes": ["ConditionalExpression"] } ], "linebreak-style": [ diff --git a/src/browser/js/app/editor/data-workers.js b/src/browser/js/app/editor/data-workers.js index a929b957..b9bc3b08 100644 --- a/src/browser/js/app/editor/data-workers.js +++ b/src/browser/js/app/editor/data-workers.js @@ -30,7 +30,7 @@ function updateWidget(widget, options={}) { !propNames.some(n => !widget.constructor.dynamicProps.includes(n)) ) { - var edited = widget.updateProps(options.changedProps, null) || widget + var edited = widget.updateProps(options.changedProps, null) || widget if ( // if prop/osc listeners have changed (@{} / OSC{}) diff --git a/src/browser/js/app/editor/diff.js b/src/browser/js/app/editor/diff.js index 050f279c..8f2902a9 100644 --- a/src/browser/js/app/editor/diff.js +++ b/src/browser/js/app/editor/diff.js @@ -2,12 +2,12 @@ module.exports = { diff: require('jsondiffpatch'), - diffToWidget: function(widget, diff) { + diffToWidget: function(widget, diff) { // traverse a diff patch and the associated widget // to return the first node (widget and sub-patch) with actual changes - var children = diff.tabs ||diff.widgets + var children = diff.tabs || diff.widgets if (children) { var childrenKeys = Object.keys(children), diff --git a/src/browser/js/app/editor/edit-field.js b/src/browser/js/app/editor/edit-field.js index 00ee4cb4..9ccfbed9 100644 --- a/src/browser/js/app/editor/edit-field.js +++ b/src/browser/js/app/editor/edit-field.js @@ -142,8 +142,7 @@ module.exports = function editField(editor, widget, propName, defaultValue){ list.addEventListener('click', (e)=>{ - // e.stopPropagation() - var change + switch (e.target.getAttribute('data-action')) { case 'select': diff --git a/src/browser/js/app/editor/index.js b/src/browser/js/app/editor/index.js index b6752325..800419c0 100644 --- a/src/browser/js/app/editor/index.js +++ b/src/browser/js/app/editor/index.js @@ -138,8 +138,8 @@ var Editor = class Editor { if (!this.selectedWidgets.length) return if (e.target.classList.contains('no-keybinding')) return - var curWidget = this.selectedWidgets[0], - toSelect + var curWidget = this.selectedWidgets[0] + if (curWidget.parent !== widgetManager) { this.select(curWidget.parent.children) } @@ -158,7 +158,7 @@ var Editor = class Editor { } else if (e.key === 'ArrowDown') { - var toSelectList = [...curWidget.children] + let toSelectList = [...curWidget.children] if (toSelectList && toSelectList.length) { toSelectList.sort((a,b) => a.container.offsetLeft>b.container.offsetLeft) @@ -170,8 +170,11 @@ var Editor = class Editor { } else if((e.key == 'ArrowLeft') || (e.key == 'ArrowRight')){ + if (curWidget.parent === widgetManager) return - var toSelectList = [...curWidget.parent.children] + + let toSelectList = [...curWidget.parent.children] + if (toSelectList && toSelectList.length) { toSelectList.sort((a,b) => a.container.offsetLeft > b.container.offsetLeft) var idx = toSelectList.indexOf(curWidget) @@ -575,7 +578,7 @@ var Editor = class Editor { minTop = Infinity, minLeft = Infinity - for (var i in pastedData) { + for (let i in pastedData) { if (increment) pastedData[i] = incrementWidget(pastedData[i]) if (!isNaN(pastedData[i]).top && pastedData[i].top < minTop) { minTop = pastedData[i].top @@ -596,7 +599,7 @@ var Editor = class Editor { data[0].widgets = data[0].widgets.concat(pastedData) var indexes = {addedIndexes: []} - for (var i = 0; i < pastedData.length; i++) { + for (let i = 0; i < pastedData.length; i++) { indexes.addedIndexes.push(data[0].widgets.length - 1 - i ) } updateWidget(this.selectedWidgets[0], indexes) @@ -812,13 +815,13 @@ var Editor = class Editor { updateWidgetFromPatch(patch, indexes) { - var [widget, patch] = diffToWidget(widgetManager.getWidgetById('root')[0], patch[0]), + var [widget, subpatch] = diffToWidget(widgetManager.getWidgetById('root')[0], patch[0]), options = {} if (indexes) { options = {...indexes} } else { - options.changedProps = Object.keys(patch) + options.changedProps = Object.keys(subpatch) options.reuseChildren = false } diff --git a/src/browser/js/app/editor/select-area.js b/src/browser/js/app/editor/select-area.js index dec363da..6b76e8cb 100644 --- a/src/browser/js/app/editor/select-area.js +++ b/src/browser/js/app/editor/select-area.js @@ -7,8 +7,8 @@ class SelectArea { this.curX = 0 this.curY = 0 - this.rectCoords = [0, 0, 0, 0] - this.rectSize = [0, 0] + this.rectCoords = [0, 0, 0, 0] + this.rectSize = [0, 0] this.elements = [] this.rect = DOM.create('
') @@ -44,7 +44,7 @@ class SelectArea { if (!this.down) return this.down = false - if (this.rectSize[0] > 0 && this.rectSize[1] > 0) { + if (this.rectSize[0] > 0 && this.rectSize[1] > 0) { this.callback(this.getElements()) this.rect.classList.add('hidden') } @@ -62,7 +62,7 @@ class SelectArea { w = x1 - x0, h = y1 - y0 - if (w < 1 || h < 1) { + if (w < 1 || h < 1) { this.rect.classList.add('hidden') } else { this.rect.classList.remove('hidden') @@ -95,8 +95,8 @@ class SelectArea { }) // slower implementation... - // for (var x = x0; x <= x1; x += 10) { - // for (var y = y0; y <= y1; y += 10) { + // for (var x = x0; x <= x1; x += 10) { + // for (var y = y0; y <= y1; y += 10) { // var el = document.elementFromPoint(x, y) // if (elements.indexOf(el) < 0) elements.push(el) // } diff --git a/src/browser/js/app/ipc/callbacks.js b/src/browser/js/app/ipc/callbacks.js index 9e280833..00fc6ef6 100644 --- a/src/browser/js/app/ipc/callbacks.js +++ b/src/browser/js/app/ipc/callbacks.js @@ -129,7 +129,7 @@ module.exports = { window.location.search = search - } catch(e) { + } catch(e) { window.location.href = window.location.href diff --git a/src/browser/js/app/parser.js b/src/browser/js/app/parser.js index 3d4f6e7d..600adea5 100644 --- a/src/browser/js/app/parser.js +++ b/src/browser/js/app/parser.js @@ -34,7 +34,7 @@ var Parser = class Parser { reCreateOptions, children, index - } = options + } = options if (!Array.isArray(data)) data = [data] diff --git a/src/browser/js/app/widgets/common/container.js b/src/browser/js/app/widgets/common/container.js index c356d6d8..235909f6 100644 --- a/src/browser/js/app/widgets/common/container.js +++ b/src/browser/js/app/widgets/common/container.js @@ -1,6 +1,4 @@ -var Widget = require('./widget'), - widgetManager = require('../../managers/widgets') - +var Widget = require('./widget') class Container extends Widget { diff --git a/src/browser/js/app/widgets/common/widget.js b/src/browser/js/app/widgets/common/widget.js index 52cf750f..cbff078d 100644 --- a/src/browser/js/app/widgets/common/widget.js +++ b/src/browser/js/app/widgets/common/widget.js @@ -193,7 +193,7 @@ class Widget extends EventEmitter { } - getAllChildren() { + getAllChildren() { var children = [] for (var i = 0; i < this.children.length; i++) { @@ -312,7 +312,7 @@ 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.linkedPropsValue).length) { widgetManager.removeEventContext('widget-created', this.linkedCreatedCallback, {context: this}) widgetManager.removeEventContext('prop-changed', this.linkedPropChangedCallback, {context: this}) @@ -327,7 +327,7 @@ class Widget extends EventEmitter { widgetManager.on('change', this.linkedValueChangedCallback, {context: this}) - } else if (this.linkedPropsValueCallback && !Object.keys(this.linkedPropsValue).length) { + } else if (this.linkedPropsValueCallback && !Object.keys(this.linkedPropsValue).length) { widgetManager.removeEventContext('change', this.linkedValueChangedCallback, {context: this}) @@ -354,7 +354,7 @@ class Widget extends EventEmitter { if (this.nestedLinkedProps[id]) { this.updateLinkedPropsWithNesting(id) } - + if (linkedProps[id]) { this.updateProps(linkedProps[id], widget, options, changedProps) } @@ -380,7 +380,7 @@ class Widget extends EventEmitter { for (var linksStores of [this.linkedPropsValue, this.linkedProps]) { for (let id in linksStores) { - if (linksStores[id].includes(prop)) { + if (linksStores[id].includes(prop)) { linksStores[id].splice(linksStores[id].indexOf(prop), 1) if (!linksStores[id].length) delete linksStores[id] } @@ -671,7 +671,7 @@ class Widget extends EventEmitter { case 'label': this.setContainerStyles(['label']) - if (oldPropValue === false || this.getProp('label') === false) { + if (oldPropValue === false || this.getProp('label') === false) { resize.check(this.container) } return diff --git a/src/browser/js/app/widgets/containers/clone.js b/src/browser/js/app/widgets/containers/clone.js index 16f59d64..a3d75e88 100644 --- a/src/browser/js/app/widgets/containers/clone.js +++ b/src/browser/js/app/widgets/containers/clone.js @@ -75,7 +75,7 @@ class Clone extends Container { if (!this.cloneTarget) return - if (e.widget === this.cloneTarget || this.cloneTarget.contains(e.widget)) { + if (e.widget === this.cloneTarget || this.cloneTarget.contains(e.widget)) { this.updateClone() @@ -90,36 +90,31 @@ class Clone extends Container { // attempt to acquire a cloneTarget if 'widget-created' event has not been catched // (the target might have been created before the clone itself) - const widgets = widgetManager.getWidgetById(this.getProp('widgetId')) + var widgets = widgetManager.getWidgetById(this.getProp('widgetId')) .filter(el=>this.isValidCloneTarget(el)) if (widgets.length === 0) return null if (widgets.length === 1) { return widgets[0] - } + } // when duplicating clones pointing to an object with a static id, // each clone will recreate an object with the same id internally // we try to get the original one if there is more than 2 clone pointing to the same id (avoiding cloning the clone) function isCreatedByAClone(wi){ - const parent = wi.parent + var parent = wi.parent return parent && parent.getProp('type') === 'clone' } var target = widgets[0] - for (const w of widgets) { + for (var w of widgets) { if (!isCreatedByAClone(w)) { target = w break } } - // we may want to remove this warning - // if (isCreatedByAClone(this.cloneTarget)) { - // console.warn('no deduped clone found : ',this.getProp('widgetId')) - // } - return target } @@ -136,12 +131,13 @@ class Clone extends Container { this.cloneLock = true - var data = {...deepCopy(this.cloneTarget.props), ...this.getProp('props')}, - clone = parser.parse({ - data: data, - parentNode: this.widget, - parent: this - }) + var data = {...deepCopy(this.cloneTarget.props), ...this.getProp('props')} + + parser.parse({ + data: data, + parentNode: this.widget, + parent: this + }) this.updateContainer(!init) @@ -201,7 +197,7 @@ class Clone extends Container { var data = {...deepCopy(this.cloneTarget.props), ...this.getProp('props')}, clone = this.children[0] - var delta = diff.diff(clone.props, data) || {}, + var delta = diff.diff(clone.props, data) || {}, [widget, patch] = diffToWidget(clone, delta), changedProps = Object.keys(patch) diff --git a/src/browser/js/app/widgets/containers/panel.js b/src/browser/js/app/widgets/containers/panel.js index ce617193..2508b4b2 100644 --- a/src/browser/js/app/widgets/containers/panel.js +++ b/src/browser/js/app/widgets/containers/panel.js @@ -50,7 +50,7 @@ class Panel extends Container { this.wrapper = this.widget.appendChild(DOM.create('')) - this.children = options.children || new Array(this.getProp('tabs').length) + this.children = options.children || new Array(this.getProp('tabs').length) for (let i = 0; i < this.children.length; i++) { if (this.children[i]) { this.wrapper.appendChild(this.children[i].container) diff --git a/src/browser/js/app/widgets/matrices/matrix.js b/src/browser/js/app/widgets/matrices/matrix.js index 6da98710..7705ac21 100644 --- a/src/browser/js/app/widgets/matrices/matrix.js +++ b/src/browser/js/app/widgets/matrices/matrix.js @@ -1,6 +1,5 @@ var _matrix_base = require('./_matrix_base'), - parser = require('../../parser'), - widgetManager = require('../../managers/widgets') + parser = require('../../parser') class Matrix extends _matrix_base { diff --git a/src/browser/js/app/widgets/matrices/multifader.js b/src/browser/js/app/widgets/matrices/multifader.js index f7461378..31182e4d 100644 --- a/src/browser/js/app/widgets/matrices/multifader.js +++ b/src/browser/js/app/widgets/matrices/multifader.js @@ -1,6 +1,5 @@ var _matrix_base = require('./_matrix_base'), - parser = require('../../parser'), - widgetManager = require('../../managers/widgets') + parser = require('../../parser') module.exports = class Multifader extends _matrix_base { diff --git a/src/browser/js/app/widgets/switchers/_switchers_base.js b/src/browser/js/app/widgets/switchers/_switchers_base.js index 723e0a65..e5563715 100644 --- a/src/browser/js/app/widgets/switchers/_switchers_base.js +++ b/src/browser/js/app/widgets/switchers/_switchers_base.js @@ -45,7 +45,7 @@ module.exports = class _switchers_base extends Widget { for (var i in widgets) { - if (widgets[i].contains(widget) || widgets[i] === widget) return true + if (widgets[i].contains(widget) || widgets[i] === widget) return true }