From 7da9be3f1504b40ab51dece96426d5fc786c8fb3 Mon Sep 17 00:00:00 2001 From: jean-emmanuel Date: Mon, 5 Mar 2018 23:31:00 +0100 Subject: [PATCH] editor: add wrap in menu (#193) --- CHANGELOG.md | 1 + src/browser/js/app/editor/context-menu.js | 27 +++++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7f9f4f3e..86a3d7f0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ - editor - allow multi widget resizing/dragging - tweaked ctrl+click/right-click selection behaviors + - **new** "Wrap in" context menu ## 0.25.0 diff --git a/src/browser/js/app/editor/context-menu.js b/src/browser/js/app/editor/context-menu.js index caa33711..9a4f7e19 100644 --- a/src/browser/js/app/editor/context-menu.js +++ b/src/browser/js/app/editor/context-menu.js @@ -190,6 +190,33 @@ var handleClick = function(event) { updateWidget(parent) } + actions[' Wrap in'] = {} + for (let c of categories.Containers) { + if (c === 'clone') continue + actions[' Wrap in'][c] = ()=>{ + var wrap = {type: c, widgets:[]} + + wrap.widgets = data + + var minTop = Math.min(...data.map(x => isNaN(x.top) ? x.top == 'auto' ? 0 : Infinity : x.top)) + var minLeft = Math.min(...data.map(x => isNaN(x.left) ? x.left == 'auto' ? 0 : Infinity : x.left)) + + wrap.top = minTop === Infinity ? data[0].top : minTop + wrap.left= minLeft === Infinity ? data[0].left : minLeft + + for (var w of wrap.widgets) { + if (!isNaN(w.top)) w.top = Math.max(w.top - minTop, 0) + if (!isNaN(w.left)) w.left = Math.max(w.left - minLeft, 0) + } + + for (var i of index) { + parent.props.widgets.splice(i,1) + } + parent.props.widgets.push(wrap) + updateWidget(parent) + } + } + }