From f7119040b110649813a5d4658fd5b959c26ebed3 Mon Sep 17 00:00:00 2001 From: bordun Date: Sat, 7 Mar 2020 11:42:41 +0100 Subject: [PATCH] be4 traversing mod --- src/client/editor/context-menu.js | 18 ++-- src/client/editor/index.js | 121 ++++++++++++++---------- src/client/widgets/containers/matrix.js | 4 +- src/scss/ui/contextmenu.scss | 2 +- src/scss/ui/grid.scss | 22 +++++ src/scss/ui/modal.scss | 4 +- src/scss/ui/toolbar.scss | 2 +- src/server/callbacks.js | 12 ++- src/server/electron-window.js | 2 +- 9 files changed, 123 insertions(+), 64 deletions(-) create mode 100644 src/scss/ui/grid.scss diff --git a/src/client/editor/context-menu.js b/src/client/editor/context-menu.js index 16499871..700a1c95 100644 --- a/src/client/editor/context-menu.js +++ b/src/client/editor/context-menu.js @@ -58,12 +58,18 @@ var handleClick = function(event) { if (parent !== widgetManager) { - if (event.target.tagName !== 'LI') actions.push({ - label: icon('project-diagram') + ' ' + locales('editor_show_in_tree'), - action: ()=>{ - editor.widgetTree.showWidget(editor.selectedWidgets[0]) - } - }) + if (event.target.tagName !== 'LI') { + actions.push({ + label: icon('project-diagram') + ' ' + locales('editor_show_in_tree'), + action: ()=>{ + editor.widgetTree.showWidget(editor.selectedWidgets[0]) + } + }) + actions.push({ + separator: true + }) + + } actions.push({ label: icon('copy') + ' ' + locales('editor_copy'), diff --git a/src/client/editor/index.js b/src/client/editor/index.js index 8a802b5f..7ef8a624 100644 --- a/src/client/editor/index.js +++ b/src/client/editor/index.js @@ -10,12 +10,13 @@ var {updateWidget, incrementWidget} = require('./data-workers'), UiTree = require('../ui/ui-tree'), UiDragResize = require('../ui/ui-dragresize'), sidepanel = require('../ui/ui-sidepanel'), + ipc = require('../ipc'), html = require('nanohtml'), sessionManager const HISTORY_SIZE = 50 -var Editor = class Editor { +class Editor { constructor() { @@ -88,6 +89,11 @@ var Editor = class Editor { this.clipboard = null this.idClipboard = null + ipc.on('clipboard', (data)=>{ + this.clipboard = data.clipboard + this.idClipboard = data.idClipboard + }) + this.enabled = false this.grid = true @@ -102,8 +108,9 @@ var Editor = class Editor { this.historyState = -1 this.historySession = null - this.mousePosition = {x:0, y:0} + this.mousePosition = {} this.mouveMoveHandler = this.mouseMove.bind(this) + this.mouveLeaveHandler = this.mouseLeave.bind(this) keyboardJS.withContext('editing', ()=>{ @@ -331,7 +338,8 @@ var Editor = class Editor { keyboardJS.setContext('editing') - document.body.addEventListener('mousemove', this.mouveMoveHandler) + this.oscContainer.addEventListener('mousemove', this.mouveMoveHandler) + this.oscContainer.addEventListener('mouseleave', this.mouveLeaveHandler) this.selectarea.enable() @@ -349,7 +357,8 @@ var Editor = class Editor { keyboardJS.setContext('global') - document.body.removeEventListener('mousemove', this.mouveMoveHandler) + this.oscContainer.removeEventListener('mousemove', this.mouveMoveHandler) + this.oscContainer.removeEventListener('mouseleave', this.mouveLeaveHandler) sidepanel.left.disable() sidepanel.right.disable() @@ -444,19 +453,23 @@ var Editor = class Editor { } + mouseLeave(e) { + + this.mousePosition = {} + + } + copyWidget() { if (!this.selectedWidgets.length) return - var data = this.selectedWidgets.map((w)=>w.props) + this.clipboard = deepCopy(this.selectedWidgets.map((w)=>w.props)) + this.idClipboard = this.selectedWidgets[0].getProp('id') - this.clipboard = deepCopy(data) - - if (data.length == 1) { - this.idClipboard = this.selectedWidgets[0].getProp('id') - } else { - this.idClipboard = null - } + ipc.send('clipboard', { + clipboard: this.clipboard, + idClipboard: this.idClipboard + }) } @@ -464,19 +477,13 @@ var Editor = class Editor { if (!this.selectedWidgets.length) return + this.copyWidget() + 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 = [] - this.clipboard = deepCopy(data) - - if (data.length == 1) { - this.idClipboard = this.selectedWidgets[0].getProp('id') - } else { - this.idClipboard = null - } - for (var i of index) { removedIndexes.push(i) parent.props.widgets.splice(i,1) @@ -499,39 +506,53 @@ var Editor = class Editor { this.clipboard[0].type !== 'tab' && this.selectedWidgets[0].childrenType === 'tab' ) return - - var data = this.selectedWidgets.map((w)=>w.props) - var pastedData = deepCopy(this.clipboard), minTop = Infinity, - minLeft = Infinity, - store = this.clipboard[0].type === 'tab' ? 'tabs' : 'widgets' + minLeft = Infinity - 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 - } - if (!isNaN(pastedData[i]).left && pastedData[i].left < minLeft) { - minLeft = pastedData[i].left - } + if (increment) { + pastedData = pastedData.map(x=>incrementWidget(x)) } - for (let i in pastedData) { - if (!isNaN(pastedData[i].left)) pastedData[i].left = pastedData[i].left - minLeft + x - if (!isNaN(pastedData[i].top)) pastedData[i].top = pastedData[i].top - minTop + y + if (x !== undefined) { + + for (let i in pastedData) { + + if (!isNaN(pastedData[i]).top && pastedData[i].top < minTop) { + minTop = pastedData[i].top + } + + if (!isNaN(pastedData[i]).left && pastedData[i].left < minLeft) { + minLeft = pastedData[i].left + } + + } + + for (let i in pastedData) { + + if (!isNaN(pastedData[i].left)) pastedData[i].left = pastedData[i].left - minLeft + x + if (!isNaN(pastedData[i].top)) pastedData[i].top = pastedData[i].top - minTop + y + + } } - data[0][store] = data[0][store] || [] - data[0][store] = data[0][store].concat(pastedData) + + // paste data + + var store = this.clipboard[0].type === 'tab' ? 'tabs' : 'widgets' + + this.selectedWidgets[0].props[store] = this.selectedWidgets[0].props[store] || [] + this.selectedWidgets[0].props[store] = this.selectedWidgets[0].props[store].concat(pastedData) var indexes = {addedIndexes: []} for (let i = 0; i < pastedData.length; i++) { - indexes.addedIndexes.push(data[0][store].length - 1 - i ) + indexes.addedIndexes.push(this.selectedWidgets[0].props[store].length - 1 - i ) } + updateWidget(this.selectedWidgets[0], indexes) + this.pushHistory(indexes) } @@ -547,23 +568,25 @@ var Editor = class Editor { 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 = deepCopy(this.clipboard) - clone.width = pastedData.width - clone.height = pastedData.height - clone.css = pastedData.css + clone.width = pastedData[0].width + clone.height = pastedData[0].height - clone.left = x - clone.top = y + if (x !== undefined) { - data[0].widgets = data[0].widgets || [] - data[0].widgets.push(clone) + clone.left = x + clone.top = y + + } + + this.selectedWidgets[0].props.widgets = this.selectedWidgets[0].props.widgets || [] + this.selectedWidgets[0].props.widgets.push(clone) + + var indexes = {addedIndexes: [this.selectedWidgets[0].props.widgets.length -1]} - var indexes = {addedIndexes: [data[0].widgets.length -1]} updateWidget(this.selectedWidgets[0], indexes) this.pushHistory(indexes) diff --git a/src/client/widgets/containers/matrix.js b/src/client/widgets/containers/matrix.js index 1a2b2fec..b95fced3 100644 --- a/src/client/widgets/containers/matrix.js +++ b/src/client/widgets/containers/matrix.js @@ -3,9 +3,7 @@ var Panel = require('./panel'), StaticProperties = require('../mixins/static_properties'), parser = require('../../parser'), {deepCopy} = require('../../utils'), - html = require('nanohtml'), - {enableTraversingGestures, disableTraversingGestures} = require('../../events/drag') - + html = require('nanohtml') class Matrix extends StaticProperties(Panel, {scroll: false}) { diff --git a/src/scss/ui/contextmenu.scss b/src/scss/ui/contextmenu.scss index f09c6ad9..a63b8471 100644 --- a/src/scss/ui/contextmenu.scss +++ b/src/scss/ui/contextmenu.scss @@ -6,7 +6,7 @@ $line-height: 30rem; --alpha-fill: 0.75; position:fixed; - z-index: 999999999; + z-index: 9999999; background: var(--color-context-menu); box-shadow: 0 0 0 0.5rem rgba(0, 0, 0, 0.15) inset; text-transform: none; diff --git a/src/scss/ui/grid.scss b/src/scss/ui/grid.scss new file mode 100644 index 00000000..112a4bc4 --- /dev/null +++ b/src/scss/ui/grid.scss @@ -0,0 +1,22 @@ +.editor-enabled { + &:not(.no-grid) { + .root-container, + .tab-container, + .modal-container, + .panel-container { + > inner { + background-image: linear-gradient(to bottom, var(--color-grid) 1rem, transparent 1rem), + linear-gradient(to right, var(--color-grid) 1rem, transparent 1rem); + --size: calc(var(--grid-width) * 1rem); + background-size: var(--size) var(--size); + background-attachment: local; + background-position: 0rem 0; + } + } + } + + .widget:not(.not-editable) { + pointer-events: initial!important; + } + +} diff --git a/src/scss/ui/modal.scss b/src/scss/ui/modal.scss index 9c3d50da..31d1fc43 100644 --- a/src/scss/ui/modal.scss +++ b/src/scss/ui/modal.scss @@ -15,8 +15,8 @@ $padding: 8rem; left:0; right:0; bottom:0; - background: white; - opacity: .03; + background: black; + opacity: .3; pointer-events: none; // animation: popup-backdrop-fade-in .25s forwards; diff --git a/src/scss/ui/toolbar.scss b/src/scss/ui/toolbar.scss index d7e9f58f..ffd2a01a 100644 --- a/src/scss/ui/toolbar.scss +++ b/src/scss/ui/toolbar.scss @@ -8,7 +8,7 @@ osc-toolbar { max-width:var(--size); min-width:var(--size); text-align: center; - z-index: 999999999; + z-index: 99999999; cursor: pointer; &:after { transition: text-shadow .1s, color .1s; diff --git a/src/server/callbacks.js b/src/server/callbacks.js index 7bd48757..acd0e976 100644 --- a/src/server/callbacks.js +++ b/src/server/callbacks.js @@ -7,7 +7,8 @@ var path = require('path'), theme = require('./theme') var widgetHashTable = {}, - sessionBackups = {} + sessionBackups = {}, + clipboard = {clipboard: null, idClipboard: null} module.exports = { @@ -16,7 +17,9 @@ module.exports = { ipc.send('connected') var recentSessions = settings.read('recentSessions') + ipc.send('sessionList', recentSessions, clientId) + ipc.send('clipboard', clipboard, clientId) if (settings.read('readOnly')) { ipc.send('readOnly') @@ -458,6 +461,13 @@ module.exports = { }) + }, + + clipboard: function(data, clientId) { + + clipboard = data + ipc.send('clipboard', data, null, clientId) + } } diff --git a/src/server/electron-window.js b/src/server/electron-window.js index 06d0beea..def080d0 100644 --- a/src/server/electron-window.js +++ b/src/server/electron-window.js @@ -79,7 +79,7 @@ module.exports = function(options={}) { window.reload() }) - shortcut.register(window,'F11',function(){ + if (options.fullscreen) shortcut.register(window,'F11',function(){ window.setFullScreen(!window.isFullScreen()) })