Skip to content

Commit 62e490b

Browse files
author
nboichev
committed
The panel is now draggable.
1 parent e82cf3c commit 62e490b

7 files changed

Lines changed: 322 additions & 52 deletions

File tree

extension/PixelParallel.js

Lines changed: 179 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -470,31 +470,6 @@ function mergeDeep(target, source) {
470470

471471
/***/ },
472472
/* 3 */
473-
/***/ function(module, exports) {
474-
475-
var g;
476-
477-
// This works in non-strict mode
478-
g = (function() { return this; })();
479-
480-
try {
481-
// This works if eval is allowed (see CSP)
482-
g = g || Function("return this")() || (1,eval)("this");
483-
} catch(e) {
484-
// This works if the window reference is available
485-
if(typeof window === "object")
486-
g = window;
487-
}
488-
489-
// g can still be undefined, but nothing to do about it...
490-
// We return undefined, instead of nothing here, so it's
491-
// easier to handle this case. if(!global) { ...}
492-
493-
module.exports = g;
494-
495-
496-
/***/ },
497-
/* 4 */
498473
/***/ function(module, exports, __webpack_require__) {
499474

500475
"use strict";
@@ -525,19 +500,25 @@ function draggableElement(element, settings) {
525500
top: 0
526501
};
527502

528-
var mouseUpHandler = function mouseUpHandler() {
503+
var mouseUpHandler = function mouseUpHandler(event) {
529504
elementDraggable = false;
530505
document.removeEventListener('mouseup', mouseUpHandler);
531506
document.removeEventListener('mousemove', mouseMoveHandler);
532507

533508
if ('onDragEnd' in settings) {
534-
settings.onDragEnd(elementMargin);
509+
settings.onDragEnd(elementMargin, event);
535510
};
536511
};
537512

538513
var mouseMoveHandler = function mouseMoveHandler(event) {
539514
if (elementDraggable) {
540515

516+
if ('onDragMove' in settings) {
517+
settings.onDragMove(event);
518+
519+
return;
520+
};
521+
541522
if (settings.y) {
542523
elementMargin.top = event.pageY - startPosition.top + elementInitialMargin.top;
543524
element.style.marginTop = elementMargin.top + 'px';
@@ -554,6 +535,10 @@ function draggableElement(element, settings) {
554535
event.preventDefault();
555536
elementDraggable = true;
556537

538+
if ('onDragStart' in settings) {
539+
settings.onDragStart(event);
540+
};
541+
557542
if (settings.y) {
558543
startPosition.top = event.pageY;
559544
elementMargin.top = parseInt(element.style.marginTop || 0);
@@ -573,6 +558,31 @@ function draggableElement(element, settings) {
573558
element.addEventListener('mousedown', mouseDownHandler);
574559
}
575560

561+
/***/ },
562+
/* 4 */
563+
/***/ function(module, exports) {
564+
565+
var g;
566+
567+
// This works in non-strict mode
568+
g = (function() { return this; })();
569+
570+
try {
571+
// This works if eval is allowed (see CSP)
572+
g = g || Function("return this")() || (1,eval)("this");
573+
} catch(e) {
574+
// This works if the window reference is available
575+
if(typeof window === "object")
576+
g = window;
577+
}
578+
579+
// g can still be undefined, but nothing to do about it...
580+
// We return undefined, instead of nothing here, so it's
581+
// easier to handle this case. if(!global) { ...}
582+
583+
module.exports = g;
584+
585+
576586
/***/ },
577587
/* 5 */
578588
/***/ function(module, exports, __webpack_require__) {
@@ -648,7 +658,7 @@ function immediate(task) {
648658
}
649659
}
650660

651-
/* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(3)))
661+
/* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(4)))
652662

653663
/***/ },
654664
/* 6 */
@@ -9002,7 +9012,7 @@ Vue$3.compile = compileToFunctions;
90029012

90039013
module.exports = Vue$3;
90049014

9005-
/* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(3)))
9015+
/* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(4)))
90069016

90079017
/***/ },
90089018
/* 8 */
@@ -9104,6 +9114,16 @@ var mousetrap = {
91049114
difference: false,
91059115
lock: false,
91069116
enabled: true
9117+
},
9118+
position: {
9119+
x: {
9120+
name: 'right',
9121+
value: .5
9122+
},
9123+
y: {
9124+
name: 'bottom',
9125+
value: 1
9126+
}
91079127
}
91089128
},
91099129
image: {
@@ -9225,18 +9245,15 @@ var mousetrap = {
92259245
var instance = __WEBPACK_IMPORTED_MODULE_0_mousetrap___default()(element || window);
92269246

92279247
if (mousetrap.main) {
9228-
console.log('reset');
92299248
mousetrap.main.reset();
92309249
}
92319250

92329251
if (mousetrap.panel) {
9233-
console.log('reset');
92349252
mousetrap.panel.reset();
92359253
}
92369254

92379255
setTimeout(function () {
92389256
Object.keys(bindings).forEach(function (key) {
9239-
console.log(key);
92409257
var keyString = bindings[key].base ? 'ctrl+alt+' + bindings[key].key : bindings[key].key;
92419258
var keyStringWithShift = bindings[key].base ? 'ctrl+alt+shift+' + bindings[key].key : 'shift+' + bindings[key].key;
92429259

@@ -9643,7 +9660,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
96439660
/***/ function(module, exports, __webpack_require__) {
96449661

96459662
"use strict";
9646-
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__directives_draggable_js__ = __webpack_require__(4);
9663+
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__directives_draggable_js__ = __webpack_require__(3);
96479664
Object.defineProperty(exports, "__esModule", { value: true });
96489665
//
96499666
//
@@ -9718,7 +9735,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
97189735
/***/ function(module, exports, __webpack_require__) {
97199736

97209737
"use strict";
9721-
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__directives_draggable_js__ = __webpack_require__(4);
9738+
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__directives_draggable_js__ = __webpack_require__(3);
97229739
Object.defineProperty(exports, "__esModule", { value: true });
97239740
//
97249741
//
@@ -9767,6 +9784,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
97679784
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_6__Droparea_vue___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_6__Droparea_vue__);
97689785
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_7__PasteBox_vue__ = __webpack_require__(49);
97699786
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_7__PasteBox_vue___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_7__PasteBox_vue__);
9787+
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_8__directives_draggable_js__ = __webpack_require__(3);
97709788
Object.defineProperty(exports, "__esModule", { value: true });
97719789
//
97729790
//
@@ -9921,6 +9939,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
99219939
//
99229940
//
99239941
//
9942+
//
9943+
//
9944+
//
9945+
99249946

99259947

99269948

@@ -9931,6 +9953,25 @@ Object.defineProperty(exports, "__esModule", { value: true });
99319953

99329954

99339955

9956+
var dragPositions = {
9957+
start: {
9958+
x: 0,
9959+
y: 0
9960+
},
9961+
element: {
9962+
x: 0,
9963+
y: 0
9964+
},
9965+
last: {
9966+
x: 0,
9967+
y: 0
9968+
},
9969+
max: {
9970+
x: 0,
9971+
y: 0
9972+
}
9973+
};
9974+
99349975
/* harmony default export */ exports["default"] = {
99359976
name: 'panel',
99369977

@@ -9940,7 +9981,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
99409981
return {
99419982
contentElement: null,
99429983
styleElement: null,
9943-
isolatorElement: null
9984+
isolatorElement: null,
9985+
dragging: false
99449986
};
99459987
},
99469988
mounted: function mounted() {
@@ -9964,6 +10006,74 @@ Object.defineProperty(exports, "__esModule", { value: true });
996410006

996510007

996610008
methods: {
10009+
handleDragEnd: function handleDragEnd(newPosition, event) {
10010+
var elementBoundingRect = this.$el.getBoundingClientRect();
10011+
var windowSize = {
10012+
x: window.innerWidth,
10013+
y: window.innerHeight
10014+
};
10015+
10016+
var propNameX = null;
10017+
var propNameY = null;
10018+
var propValX = 0;
10019+
var propValY = 0;
10020+
10021+
if (dragPositions.last.x < windowSize.x / 2) {
10022+
propNameX = 'left';
10023+
10024+
propValX = dragPositions.last.x / window.innerWidth * 100;
10025+
} else {
10026+
propNameX = 'right';
10027+
10028+
this.$el.style.left = 'auto';
10029+
propValX = (windowSize.x - dragPositions.last.x - elementBoundingRect.width) / window.innerWidth * 100;
10030+
}
10031+
10032+
if (dragPositions.last.y < windowSize.y / 2) {
10033+
propNameY = 'top';
10034+
10035+
propValY = dragPositions.last.y / window.innerHeight * 100;
10036+
} else {
10037+
propNameY = 'bottom';
10038+
10039+
this.$el.style.top = 'auto';
10040+
propValY = (windowSize.y - dragPositions.last.y - elementBoundingRect.height) / window.innerHeight * 100;
10041+
}
10042+
10043+
this.$el.style.transform = 'none';
10044+
this.$el.style[propNameX] = propValX + '%';
10045+
this.$el.style[propNameY] = propValY + '%';
10046+
10047+
this.config.position.x.name = propNameX;
10048+
this.config.position.x.value = propValX;
10049+
this.config.position.y.name = propNameY;
10050+
this.config.position.y.value = propValY;
10051+
10052+
this.dragging = false;
10053+
},
10054+
handleDragMove: function handleDragMove(event) {
10055+
dragPositions.last.x = Math.min(dragPositions.max.x, Math.max(0, dragPositions.element.x + event.screenX - dragPositions.start.x));
10056+
dragPositions.last.y = Math.min(dragPositions.max.y, Math.max(0, dragPositions.element.y + event.screenY - dragPositions.start.y));
10057+
10058+
this.$el.style.transform = 'translate(' + dragPositions.last.x + 'px, ' + dragPositions.last.y + 'px)';
10059+
},
10060+
handleDragStart: function handleDragStart(event) {
10061+
var elementBoundingRect = this.$el.getBoundingClientRect();
10062+
dragPositions.start.x = event.screenX;
10063+
dragPositions.start.y = event.screenY;
10064+
dragPositions.element.x = elementBoundingRect.left;
10065+
dragPositions.element.y = elementBoundingRect.top;
10066+
dragPositions.max.x = window.innerWidth - elementBoundingRect.width;
10067+
dragPositions.max.y = window.innerHeight - elementBoundingRect.height;
10068+
10069+
this.$el.style.left = '0px';
10070+
this.$el.style.top = '0px';
10071+
this.$el.style.transform = 'translate(' + dragPositions.element.x + 'px, ' + dragPositions.element.y + 'px)';
10072+
this.$el.style.right = 'auto';
10073+
this.$el.style.bottom = 'auto';
10074+
10075+
this.dragging = true;
10076+
},
996710077
setCurrentPane: function setCurrentPane(paneKey) {
996810078
this.config.currentPane = paneKey;
996910079
},
@@ -9988,7 +10098,20 @@ Object.defineProperty(exports, "__esModule", { value: true });
998810098
this.$children[0].setIsolatorDoc(this.isolatorElement.contentDocument);
998910099
}
999010100
},
10101+
computed: {
10102+
panelInlineStyles: function panelInlineStyles() {
10103+
var styleObject = {};
999110104

10105+
styleObject[this.config.position.x.name] = this.config.position.x.value + '%';
10106+
styleObject[this.config.position.y.name] = this.config.position.y.value + '%';
10107+
styleObject.opacity = 1;
10108+
10109+
return styleObject;
10110+
}
10111+
},
10112+
directives: {
10113+
draggable: __WEBPACK_IMPORTED_MODULE_8__directives_draggable_js__["a" /* default */]
10114+
},
999210115
components: {
999310116
Toggle: __WEBPACK_IMPORTED_MODULE_3__Toggle_vue___default.a,
999410117
Number: __WEBPACK_IMPORTED_MODULE_4__Number_vue___default.a,
@@ -10315,7 +10438,7 @@ exports = module.exports = __webpack_require__(0)();
1031510438

1031610439

1031710440
// module
10318-
exports.push([module.i, ".pixelParallel-panel[data-v-208daeb5]{position:fixed;right:10px;bottom:10px;z-index:2147483647;width:375px;height:265px;transform:translate(0);background:#fff;transition:.2s ease-out}.pixelParallel-panel-inner[data-v-208daeb5]{position:relative;overflow:hidden;height:100%;border:1px solid #dddedf;box-shadow:0 2px 10px rgba(0,0,0,.1);box-sizing:border-box}.pixelParallel-panel-isolator[data-v-208daeb5]{border:0;width:100%;height:100%;overflow:hidden;position:relative}.pixelParallel-panel-minimized[data-v-208daeb5]{width:112px;height:50px;transition:.2s ease-out .15s}@media (max-width:395px){.pixelParallel-panel[data-v-208daeb5]{right:0;bottom:0;width:320px}.pixelParallel-panel-minimized[data-v-208daeb5]{width:112px}}", ""]);
10441+
exports.push([module.i, ".pixelParallel-panel[data-v-208daeb5]{position:fixed;right:10px;bottom:10px;z-index:2147483647;width:375px;height:265px;transform:translate(0);background:#fff;transition:width .2s ease-out,height .2s ease-out;will-change:top,left,width,height,transform;opacity:0}.pixelParallel-panel-inner[data-v-208daeb5]{position:relative;overflow:hidden;height:100%;border:1px solid #dddedf;box-shadow:0 2px 10px rgba(0,0,0,.1);box-sizing:border-box}.pixelParallel-panel-handle[data-v-208daeb5]{position:absolute;top:-10px;right:-10px;z-index:3;width:20px;height:20px;background:red;transform:rotate(45deg);background:linear-gradient(0deg,transparent,transparent 50%,#ccc 0,#ccc);background-size:100% 2px;cursor:move}.pixelParallel-panel-isolator[data-v-208daeb5]{border:0;width:100%;height:100%;overflow:hidden;position:relative}.pixelParallel-panel-dragging .pixelParallel-panel-inner[data-v-208daeb5]{pointer-events:none}.pixelParallel-panel-minimized[data-v-208daeb5]{width:112px;height:50px;transition:width .2s ease-out .15s,height .2s ease-out .15s}@media (max-width:395px){.pixelParallel-panel[data-v-208daeb5]{right:0;bottom:0;width:320px}.pixelParallel-panel-minimized[data-v-208daeb5]{width:112px}}", ""]);
1031910442

1032010443
// exports
1032110444

@@ -23299,7 +23422,7 @@ PouchDB.plugin(IDBPouch)
2329923422
// aggressive bundle.
2330023423

2330123424
module.exports = PouchDB;
23302-
/* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(3)))
23425+
/* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(4)))
2330323426

2330423427
/***/ },
2330523428
/* 37 */
@@ -25037,12 +25160,28 @@ module.exports={render:function (){var _vm=this;var _h=_vm.$createElement;var _c
2503725160

2503825161
module.exports={render:function (){var _vm=this;var _h=_vm.$createElement;var _c=_vm._c;
2503925162
return _c('div', {
25163+
directives: [{
25164+
name: "draggable",
25165+
rawName: "v-draggable",
25166+
value: ({
25167+
x: true,
25168+
y: true,
25169+
onDragEnd: _vm.handleDragEnd,
25170+
onDragMove: _vm.handleDragMove,
25171+
onDragStart: _vm.handleDragStart
25172+
}),
25173+
expression: "{x: true, y: true, onDragEnd: handleDragEnd, onDragMove: handleDragMove, onDragStart: handleDragStart}"
25174+
}],
2504025175
class: ['pixelParallel-panel', {
25041-
'pixelParallel-panel-minimized': _vm.config.minimized
25042-
}]
25176+
'pixelParallel-panel-minimized': _vm.config.minimized,
25177+
'pixelParallel-panel-dragging': this.dragging
25178+
}],
25179+
style: (_vm.panelInlineStyles)
2504325180
}, [_c('div', {
2504425181
staticClass: "pixelParallel-panel-inner"
25045-
}, [_c('iframe', {
25182+
}, [_c('div', {
25183+
staticClass: "pixelParallel-panel-handle"
25184+
}), _vm._v(" "), _c('iframe', {
2504625185
staticClass: "pixelParallel-panel-isolator",
2504725186
attrs: {
2504825187
"frameborder": "0"

extension/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"manifest_version": 2,
33
"name": "PixelParallel",
4-
"version": "1.0.6",
4+
"version": "1.1.0",
55

66
"description": "Frontend development and QA tool for pixel perfect designs.",
77
"icons": {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "pixel-parallel",
3-
"version": "1.0.6",
3+
"version": "1.1.0",
44
"description": "Frontend development and QA tool for pixel perfect designs.",
55
"main": "dist/PixelParallel.js",
66
"scripts": {

0 commit comments

Comments
 (0)