diff --git a/arrows.sketchplugin/Contents/Sketch/autoUpdate.js b/arrows.sketchplugin/Contents/Sketch/autoUpdate.js index fb4e336..86c9c96 100644 --- a/arrows.sketchplugin/Contents/Sketch/autoUpdate.js +++ b/arrows.sketchplugin/Contents/Sketch/autoUpdate.js @@ -1,1134 +1,49 @@ -var that = this; -function __skpm_run (key, context) { - that.context = context; - -var exports = -/******/ (function(modules) { // webpackBootstrap -/******/ // The module cache -/******/ var installedModules = {}; -/******/ -/******/ // The require function -/******/ function __webpack_require__(moduleId) { -/******/ -/******/ // Check if module is in cache -/******/ if(installedModules[moduleId]) { -/******/ return installedModules[moduleId].exports; -/******/ } -/******/ // Create a new module (and put it into the cache) -/******/ var module = installedModules[moduleId] = { -/******/ i: moduleId, -/******/ l: false, -/******/ exports: {} -/******/ }; -/******/ -/******/ // Execute the module function -/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); -/******/ -/******/ // Flag the module as loaded -/******/ module.l = true; -/******/ -/******/ // Return the exports of the module -/******/ return module.exports; -/******/ } -/******/ -/******/ -/******/ // expose the modules object (__webpack_modules__) -/******/ __webpack_require__.m = modules; -/******/ -/******/ // expose the module cache -/******/ __webpack_require__.c = installedModules; -/******/ -/******/ // define getter function for harmony exports -/******/ __webpack_require__.d = function(exports, name, getter) { -/******/ if(!__webpack_require__.o(exports, name)) { -/******/ Object.defineProperty(exports, name, { enumerable: true, get: getter }); -/******/ } -/******/ }; -/******/ -/******/ // define __esModule on exports -/******/ __webpack_require__.r = function(exports) { -/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { -/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); -/******/ } -/******/ Object.defineProperty(exports, '__esModule', { value: true }); -/******/ }; -/******/ -/******/ // create a fake namespace object -/******/ // mode & 1: value is a module id, require it -/******/ // mode & 2: merge all properties of value into the ns -/******/ // mode & 4: return value when already ns object -/******/ // mode & 8|1: behave like require -/******/ __webpack_require__.t = function(value, mode) { -/******/ if(mode & 1) value = __webpack_require__(value); -/******/ if(mode & 8) return value; -/******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value; -/******/ var ns = Object.create(null); -/******/ __webpack_require__.r(ns); -/******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value }); -/******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key)); -/******/ return ns; -/******/ }; -/******/ -/******/ // getDefaultExport function for compatibility with non-harmony modules -/******/ __webpack_require__.n = function(module) { -/******/ var getter = module && module.__esModule ? -/******/ function getDefault() { return module['default']; } : -/******/ function getModuleExports() { return module; }; -/******/ __webpack_require__.d(getter, 'a', getter); -/******/ return getter; -/******/ }; -/******/ -/******/ // Object.prototype.hasOwnProperty.call -/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); }; -/******/ -/******/ // __webpack_public_path__ -/******/ __webpack_require__.p = ""; -/******/ -/******/ -/******/ // Load entry module and return exports -/******/ return __webpack_require__(__webpack_require__.s = "./src/autoUpdate.js"); -/******/ }) -/************************************************************************/ -/******/ ({ - -/***/ "./src/autoUpdate.js": +var that=this;function __skpm_run(e,t){that.context=t;var r=function(e){var t={};function r(o){if(t[o])return t[o].exports;var n=t[o]={i:o,l:!1,exports:{}};return e[o].call(n.exports,n,n.exports,r),n.l=!0,n.exports}return r.m=e,r.c=t,r.d=function(e,t,o){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:o})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var o=Object.create(null);if(r.r(o),Object.defineProperty(o,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var n in e)r.d(o,n,function(t){return e[t]}.bind(null,n));return o},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s="./src/autoUpdate.js")}({"./src/autoUpdate.js": /*!***************************!*\ !*** ./src/autoUpdate.js ***! \***************************/ -/*! exports provided: autoUpdateSelectedArrows */ -/***/ (function(module, __webpack_exports__, __webpack_require__) { - -"use strict"; -__webpack_require__.r(__webpack_exports__); -/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "autoUpdateSelectedArrows", function() { return autoUpdateSelectedArrows; }); -/* harmony import */ var sketch__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! sketch */ "sketch"); -/* harmony import */ var sketch__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(sketch__WEBPACK_IMPORTED_MODULE_0__); -/* harmony import */ var _utilities_lines_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./utilities/lines.js */ "./src/utilities/lines.js"); -/* harmony import */ var _createArrow_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./createArrow.js */ "./src/createArrow.js"); -/* harmony import */ var _utilities_data_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./utilities/data.js */ "./src/utilities/data.js"); - - -var UI = __webpack_require__(/*! sketch/ui */ "sketch/ui"); - -var pluginKey = "flowArrows"; - - - - -var Settings = __webpack_require__(/*! sketch/settings */ "sketch/settings"); - -function autoUpdateSelectedArrows(context) { - if (Settings.settingForKey("autoDraw") != false) { - var document = sketch__WEBPACK_IMPORTED_MODULE_0___default.a.fromNative(context.actionContext.document); - var action = context.actionContext; - var docData = action.document.documentData(); - var connectionsData = Object(_utilities_data_js__WEBPACK_IMPORTED_MODULE_3__["getConnectionsData"])(docData); - var movedLayers = Array.from(context.actionContext.layers).map(function (layer) { - return sketch__WEBPACK_IMPORTED_MODULE_0___default.a.fromNative(layer); - }); - var firstObjectID = String(movedLayers[0].id); - var connectionIndex = []; - connectionIndex = getIndex(connectionsData, firstObjectID); - - if (connectionIndex.length > 0) { - for (var x = 0; x < connectionIndex.length; x++) { - Object(_utilities_lines_js__WEBPACK_IMPORTED_MODULE_1__["deleteLine"])(connectionsData[connectionIndex[x]].line, document); - var connection = Object(_createArrow_js__WEBPACK_IMPORTED_MODULE_2__["createArrow"])(connectionsData[connectionIndex[x]].firstObject, connectionsData[connectionIndex[x]].secondObject, connectionsData[connectionIndex[x]].style, connectionsData[connectionIndex[x]].type, connectionsData[connectionIndex[x]].direction, connectionsData[connectionIndex[x]].condition, connectionsData[connectionIndex[x]].isCondition, document, docData); - connectionsData.push(connection); - } - - connectionsData = Object(_utilities_data_js__WEBPACK_IMPORTED_MODULE_3__["deleteConnectionFromData"])(connectionIndex, connectionsData); - } - - context.command.setValue_forKey_onLayer_forPluginIdentifier(connectionsData, "arrowConnections", docData, pluginKey); - } -} - -function getIndex(connectionsData, firstObjectID) { - var connectionIndex = []; - - if (connectionsData.length > 0) { - for (var y = 0; y < connectionsData.length; y++) { - if (firstObjectID == connectionsData[y].firstObject || firstObjectID == connectionsData[y].secondObject) { - connectionIndex.push(y); - } - } - } - - return connectionIndex; -} - -/***/ }), - -/***/ "./src/createArrow.js": +/*! exports provided: autoUpdateSelectedArrows */function(e,t,r){"use strict";r.r(t),r.d(t,"autoUpdateSelectedArrows",function(){return l});var o=r(/*! sketch */"sketch"),n=r.n(o),i=r(/*! ./utilities/lines.js */"./src/utilities/lines.js"),a=r(/*! ./createArrow.js */"./src/createArrow.js"),s=r(/*! ./utilities/data.js */"./src/utilities/data.js"),c=(r(/*! sketch/ui */"sketch/ui"),"flowArrows"),u=r(/*! sketch/settings */"sketch/settings");function l(e){if(0!=u.settingForKey("autoDraw")){var t,r=n.a.fromNative(e.actionContext.document),o=e.actionContext.document.documentData(),l=Object(s.getConnectionsData)(o),d=Array.from(e.actionContext.layers).map(function(e){return n.a.fromNative(e)});if((t=function(e,t){var r=[];if(e.length>0)for(var o=0;o0){for(var f=0;f firstObjectMidX) { - // Right Half - if (secondObjectMidY > firstObjectMidY) { - // Bottom quarter - direction = diffX > diffY ? "Down" : "Right"; - } else { - // Top quarter - direction = absDiffX > absDiffY ? "Right" : "Up"; - } - } else { - // Left Half - if (secondObjectMidY > firstObjectMidY) { - // Bottom quarter - direction = absDiffX > absDiffY ? "Left" : "Down"; - } else { - // Top quarter - direction = diffX > diffY ? "Left" : "Up"; - } - } - - return direction; -} - -function updateSpacing(sourceObjectID, childObjectID, direction, document) { - var sourceObject = document.getLayerWithID(sourceObjectID); - var childObject = document.getLayerWithID(childObjectID); - - if (Settings.settingForKey("arrowSpacing") && Settings.settingForKey("arrowSpacing") != 0) { - var currentSpacing = Settings.settingForKey("arrowSpacing"); - - if (direction == "Right") { - childObject.frame.x = sourceObject.frame.x + sourceObject.frame.width + currentSpacing; - } - - if (direction == "Down") { - childObject.frame.y = sourceObject.frame.y + sourceObject.frame.height + currentSpacing; - } - - if (direction == "Left") { - childObject.frame.x = sourceObject.frame.x - childObject.frame.width - currentSpacing; - } - - if (direction == "Up") { - childObject.frame.y = sourceObject.frame.y - childObject.frame.height - currentSpacing; - } - } -} - -function autoAlignLayer(sourceObjectID, childObjectID, direction, document) { - var sourceObject = document.getLayerWithID(sourceObjectID); - var childObject = document.getLayerWithID(childObjectID); - var sourceMidY, childMidY, sourceMidX, childMidX, diff; - - if (Settings.settingForKey("autoAlign")) { - if (Settings.settingForKey("autoAlign") == true) { - // If user turned on Auto-Align settings - if (direction == "Right" || direction == "Left") { - sourceMidY = sourceObject.frame.y + sourceObject.frame.height / 2; - childMidY = childObject.frame.y + childObject.frame.height / 2; - diff = sourceMidY - childMidY; - - if (diff > -6 && diff < 6) { - childObject.frame.y = childObject.frame.y + diff; - } - } - - if (direction == "Down" || direction == "Up") { - sourceMidX = sourceObject.frame.x + sourceObject.frame.width / 2; - childMidX = childObject.frame.x + childObject.frame.width / 2; - diff = sourceMidX - childMidX; - - if (diff > -6 && diff < 6) { - childObject.frame.x = childObject.frame.x + diff; - } - } - } - } -} - -/***/ }), - -/***/ "./src/draw.js": +/*! exports provided: createArrow */function(e,t,r){"use strict";r.r(t),r.d(t,"createArrow",function(){return i});r(/*! sketch */"sketch");var o=r(/*! ./draw.js */"./src/draw.js"),n=r(/*! sketch/settings */"sketch/settings");function i(e,t,r,i,a,s,c,u,l){var d="Auto"==a?function(e,t,r){var o,n=r.getLayerWithID(e),i=r.getLayerWithID(t),a=n.frame.x+n.frame.width/2,s=n.frame.y+n.frame.height/2,c=i.frame.x+i.frame.width/2,u=i.frame.y+i.frame.height/2,l=a-c,d=s-u,f=Math.abs(l),y=Math.abs(d);o=c>a?u>s?l>d?"Down":"Right":f>y?"Right":"Up":u>s?f>y?"Left":"Down":l>d?"Left":"Up";return o}(e,t,u):a;!function(e,t,r,o){var i=o.getLayerWithID(e),a=o.getLayerWithID(t);if(n.settingForKey("arrowSpacing")&&0!=n.settingForKey("arrowSpacing")){var s=n.settingForKey("arrowSpacing");"Right"==r&&(a.frame.x=i.frame.x+i.frame.width+s),"Down"==r&&(a.frame.y=i.frame.y+i.frame.height+s),"Left"==r&&(a.frame.x=i.frame.x-a.frame.width-s),"Up"==r&&(a.frame.y=i.frame.y-a.frame.height-s)}}(e,t,d,u),function(e,t,r,o){var i,a,s,c,u,l=o.getLayerWithID(e),d=o.getLayerWithID(t);n.settingForKey("autoAlign")&&1==n.settingForKey("autoAlign")&&("Right"!=r&&"Left"!=r||(i=l.frame.y+l.frame.height/2,a=d.frame.y+d.frame.height/2,(u=i-a)>-6&&u<6&&(d.frame.y=d.frame.y+u)),"Down"!=r&&"Up"!=r||(s=l.frame.x+l.frame.width/2,c=d.frame.x+d.frame.width/2,(u=s-c)>-6&&u<6&&(d.frame.x=d.frame.x+u)))}(e,t,d,u);var f=Object(o.drawConnection)(e,t,r,i,d,s,c,u,l);return{firstObject:e,secondObject:t,style:f.style,condition:f.conditionID,isCondition:c,type:f.type,direction:d,line:f.line.objectID()}}},"./src/draw.js": /*!*********************!*\ !*** ./src/draw.js ***! \*********************/ -/*! exports provided: drawConnection */ -/***/ (function(module, __webpack_exports__, __webpack_require__) { - -"use strict"; -__webpack_require__.r(__webpack_exports__); -/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "drawConnection", function() { return drawConnection; }); -/* harmony import */ var sketch__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! sketch */ "sketch"); -/* harmony import */ var sketch__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(sketch__WEBPACK_IMPORTED_MODULE_0__); -/* harmony import */ var _utilities_styling_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./utilities/styling.js */ "./src/utilities/styling.js"); -/* harmony import */ var _utilities_conditions_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./utilities/conditions.js */ "./src/utilities/conditions.js"); -/* harmony import */ var _utilities_groups_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./utilities/groups.js */ "./src/utilities/groups.js"); - - - - - -var Settings = __webpack_require__(/*! sketch/settings */ "sketch/settings"); - -var UI = __webpack_require__(/*! sketch/ui */ "sketch/ui"); // let document = sketch.fromNative(context.document); -// let docData = context.document.documentData(); -// let currentParentGroup = docData.currentPage().currentArtboard() || docData.currentPage(); -// Main Function - - -function drawConnection(firstObjectID, secondObjectID, style, type, localDirection, conditionID, isCondition, document, docData) { - // Refactored - // Process of creating new connection - var currentParentGroup = docData.currentPage().currentArtboard() || docData.currentPage(); - var firstObject = document.getLayerWithID(firstObjectID); - var secondObject = document.getLayerWithID(secondObjectID); - var connectionPos = getConnectionPos(firstObject, secondObject, localDirection, currentParentGroup); - var connection = { - line: [], - conditionID: [], - type: [], - style: [] // Type - - }; - connection.type = type == null ? Settings.settingForKey("arrowType") : type; - - if (connection.type == "Angled" || connection.type == null) { - connection.line = drawAngledLine(connectionPos.firstLayerPosX, connectionPos.firstLayerPosY, connectionPos.middlePosX, connectionPos.middlePosY, connectionPos.secondLayerPosX, connectionPos.secondLayerPosY, localDirection); - } - - if (connection.type == "Straight") { - connection.line = drawStraightLine(connectionPos.firstLayerPosX, connectionPos.firstLayerPosY, connectionPos.secondLayerPosX, connectionPos.secondLayerPosY, localDirection); - } - - if (connection.type == "Curved") { - connection.line = drawCurvedLine(connectionPos.firstLayerPosX, connectionPos.firstLayerPosY, connectionPos.secondLayerPosX, connectionPos.secondLayerPosY, localDirection); - } // Condition - - - if (isCondition == true) { - if (document.getLayerWithID(conditionID)) { - connection.conditionID = Object(_utilities_conditions_js__WEBPACK_IMPORTED_MODULE_2__["updateCondition"])(conditionID, connectionPos.middlePosX, connectionPos.middlePosY, document, docData); - } else { - connection.conditionID = Object(_utilities_conditions_js__WEBPACK_IMPORTED_MODULE_2__["addCondition"])("#con", connectionPos.middlePosX, connectionPos.middlePosY, document, docData); - } - } else { - connection.conditionID = null; - } // Style - - - connection.style = Object(_utilities_styling_js__WEBPACK_IMPORTED_MODULE_1__["styleLine"])(connection.line, style, docData); // Add to group - - Object(_utilities_groups_js__WEBPACK_IMPORTED_MODULE_3__["addToArrowsGroup"])(connection.line, currentParentGroup); - return connection; -} // Positions - -function getConnectionPos(firstObject, secondObject, direction, currentParentGroup) { - // Refactored - var firstObjectAbsPos = firstObject.frame.changeBasis({ - from: firstObject.parent, - to: currentParentGroup - }); - var secondObjectAbsPos = secondObject.frame.changeBasis({ - from: secondObject.parent, - to: currentParentGroup - }); - var currentGroup = Object(_utilities_groups_js__WEBPACK_IMPORTED_MODULE_3__["checkForGroup"])("Arrows", currentParentGroup); - var diffX, diffY; - - if (currentGroup) { - diffX = currentGroup.frame().x(); - diffY = currentGroup.frame().y(); - } else { - diffX = 0; - diffY = 0; - } - - var connectionPos = { - firstLayerPosX: null, - firstLayerPosY: null, - secondLayerPosX: null, - secondLayerPosY: null, - middlePosX: null, - middlePosY: null // Getting all the positions - - }; - - if (direction == "Up") { - // First Layer Position Start Point Position - connectionPos.firstLayerPosX = firstObjectAbsPos.x + firstObjectAbsPos.width / 2 - diffX; - connectionPos.firstLayerPosY = firstObjectAbsPos.y - diffY; // Second Layer Position End Point Position - - connectionPos.secondLayerPosX = secondObjectAbsPos.x + secondObjectAbsPos.width / 2 - diffX; - connectionPos.secondLayerPosY = secondObjectAbsPos.y + secondObjectAbsPos.height - diffY; // Middle Points - - connectionPos.middlePosX = (connectionPos.firstLayerPosX + connectionPos.secondLayerPosX) / 2; - connectionPos.middlePosY = (connectionPos.firstLayerPosY + connectionPos.secondLayerPosY) / 2; - } - - if (direction == "Right") { - // First Layer Position Start Point Position - connectionPos.firstLayerPosX = firstObjectAbsPos.x + firstObjectAbsPos.width - diffX; - connectionPos.firstLayerPosY = firstObjectAbsPos.y + firstObjectAbsPos.height / 2 - diffY; // Second Layer Position End Point Position - - connectionPos.secondLayerPosX = secondObjectAbsPos.x - diffX; - connectionPos.secondLayerPosY = secondObjectAbsPos.y + secondObjectAbsPos.height / 2 - diffY; // Middle Points - - connectionPos.middlePosX = (connectionPos.firstLayerPosX + connectionPos.secondLayerPosX) / 2; - connectionPos.middlePosY = (connectionPos.firstLayerPosY + connectionPos.secondLayerPosY) / 2; - } - - if (direction == "Down") { - // First Layer Position Start Point Position - connectionPos.firstLayerPosX = firstObjectAbsPos.x + firstObjectAbsPos.width / 2 - diffX; - connectionPos.firstLayerPosY = firstObjectAbsPos.y + firstObjectAbsPos.height - diffY; // Second Layer Position End Point Position - - connectionPos.secondLayerPosX = secondObjectAbsPos.x + secondObjectAbsPos.width / 2 - diffX; - connectionPos.secondLayerPosY = secondObjectAbsPos.y - diffY; // Middle Points - - connectionPos.middlePosX = (connectionPos.firstLayerPosX + connectionPos.secondLayerPosX) / 2; - connectionPos.middlePosY = (connectionPos.firstLayerPosY + connectionPos.secondLayerPosY) / 2; - } - - if (direction == "Left") { - // First Layer Position Start Point Position - connectionPos.firstLayerPosX = firstObjectAbsPos.x - diffX; - connectionPos.firstLayerPosY = firstObjectAbsPos.y + firstObjectAbsPos.height / 2 - diffY; // Second Layer Position End Point Position - - connectionPos.secondLayerPosX = secondObjectAbsPos.x + secondObjectAbsPos.width - diffX; - connectionPos.secondLayerPosY = secondObjectAbsPos.y + secondObjectAbsPos.height / 2 - diffY; // Middle Points - - connectionPos.middlePosX = (connectionPos.firstLayerPosX + connectionPos.secondLayerPosX) / 2; - connectionPos.middlePosY = (connectionPos.firstLayerPosY + connectionPos.secondLayerPosY) / 2; - } - - return connectionPos; -} // Drawing Types - - -function drawAngledLine(firstLayerPosX, firstLayerPosY, middlePosX, middlePosY, secondLayerPosX, secondLayerPosY, direction) { - // Refactored - var path = NSBezierPath.bezierPath(); - - if (direction == "Up") { - // Connecting points - path.moveToPoint(NSMakePoint(firstLayerPosX, firstLayerPosY)); - path.lineToPoint(NSMakePoint(firstLayerPosX, middlePosY)); - path.lineToPoint(NSMakePoint(secondLayerPosX, middlePosY)); - path.lineToPoint(NSMakePoint(secondLayerPosX, secondLayerPosY)); - } - - if (direction == "Right") { - // Connecting points - path.moveToPoint(NSMakePoint(firstLayerPosX, firstLayerPosY)); - path.lineToPoint(NSMakePoint(middlePosX, firstLayerPosY)); - path.lineToPoint(NSMakePoint(middlePosX, secondLayerPosY)); - path.lineToPoint(NSMakePoint(secondLayerPosX, secondLayerPosY)); - } - - if (direction == "Down") { - // Connecting points - path.moveToPoint(NSMakePoint(firstLayerPosX, firstLayerPosY)); - path.lineToPoint(NSMakePoint(firstLayerPosX, middlePosY)); - path.lineToPoint(NSMakePoint(secondLayerPosX, middlePosY)); - path.lineToPoint(NSMakePoint(secondLayerPosX, secondLayerPosY)); - } - - if (direction == "Left") { - // Connecting points - path.moveToPoint(NSMakePoint(firstLayerPosX, firstLayerPosY)); - path.lineToPoint(NSMakePoint(middlePosX, firstLayerPosY)); - path.lineToPoint(NSMakePoint(middlePosX, secondLayerPosY)); - path.lineToPoint(NSMakePoint(secondLayerPosX, secondLayerPosY)); - } - - var line = MSShapeGroup.layerWithPath(MSPath.pathWithBezierPath(path)); - var points = line.layers().firstObject().points(); - points[1].cornerRadius = 20; - points[2].cornerRadius = 20; - line.setName("Angled Arrow"); - return line; -} - -function drawStraightLine(firstLayerPosX, firstLayerPosY, secondLayerPosX, secondLayerPosY, direction) { - // Refactored - var path = NSBezierPath.bezierPath(); - - if (direction == "Up") { - path.moveToPoint(NSMakePoint(firstLayerPosX, firstLayerPosY)); - path.lineToPoint(NSMakePoint(secondLayerPosX, secondLayerPosY)); - } - - if (direction == "Right") { - path.moveToPoint(NSMakePoint(firstLayerPosX, firstLayerPosY)); - path.lineToPoint(NSMakePoint(secondLayerPosX, secondLayerPosY)); - } - - if (direction == "Down") { - path.moveToPoint(NSMakePoint(firstLayerPosX, firstLayerPosY)); - path.lineToPoint(NSMakePoint(secondLayerPosX, secondLayerPosY)); - } - - if (direction == "Left") { - path.moveToPoint(NSMakePoint(firstLayerPosX, firstLayerPosY)); - path.lineToPoint(NSMakePoint(secondLayerPosX, secondLayerPosY)); - } - - var line = MSShapeGroup.layerWithPath(MSPath.pathWithBezierPath(path)); - line.setName("Straight Arrow"); - return line; -} - -function drawCurvedLine(firstLayerPosX, firstLayerPosY, secondLayerPosX, secondLayerPosY, direction) { - // Refactored - var path = NSBezierPath.bezierPath(); - var line; - - if (direction == "Up") { - // Connecting points - path.moveToPoint(NSMakePoint(firstLayerPosX, firstLayerPosY)); - path.lineToPoint(NSMakePoint(secondLayerPosX, secondLayerPosY)); // Painting the line - - line = MSShapeGroup.layerWithPath(MSPath.pathWithBezierPath(path)); - var points = line.layers().firstObject().points(); - points[0].curveMode = 4; - points[1].curveMode = 4; - points[0].hasCurveFrom = true; - points[1].hasCurveTo = true; - - if (firstLayerPosX < secondLayerPosX) { - points[0].curveFrom = { - x: 0, - y: 0.5 - }; - points[0].curveTo = { - x: -0.5, - y: 1 - }; - points[1].curveFrom = { - x: 1, - y: 1 - }; - points[1].curveTo = { - x: 1, - y: 0.5 - }; - } else { - points[0].curveFrom = { - x: 1, - y: 0.5 - }; - points[0].curveTo = { - x: -0.5, - y: 1 - }; - points[1].curveFrom = { - x: 1, - y: 1 - }; - points[1].curveTo = { - x: 0, - y: 0.5 - }; - } - } - - if (direction == "Right") { - // Connecting points - path.moveToPoint(NSMakePoint(firstLayerPosX, firstLayerPosY)); - path.lineToPoint(NSMakePoint(secondLayerPosX, secondLayerPosY)); // Painting the line - - line = MSShapeGroup.layerWithPath(MSPath.pathWithBezierPath(path)); - - var _points = line.layers().firstObject().points(); - - _points[0].curveMode = 4; - _points[1].curveMode = 4; - _points[0].hasCurveFrom = true; - _points[1].hasCurveTo = true; - - if (firstLayerPosY < secondLayerPosY) { - _points[0].curveFrom = { - x: 0.5, - y: 0 - }; - _points[0].curveTo = { - x: -0.5, - y: 1 - }; - _points[1].curveFrom = { - x: 1, - y: 1 - }; - _points[1].curveTo = { - x: 0.5, - y: 1 - }; - } else { - _points[0].curveFrom = { - x: 0.5, - y: 1 - }; - _points[0].curveTo = { - x: -0.5, - y: 1 - }; - _points[1].curveFrom = { - x: 1, - y: 1 - }; - _points[1].curveTo = { - x: 0.5, - y: 0 - }; - } - } - - if (direction == "Down") { - // Connecting points - path.moveToPoint(NSMakePoint(firstLayerPosX, firstLayerPosY)); - path.lineToPoint(NSMakePoint(secondLayerPosX, secondLayerPosY)); // Painting the line - - line = MSShapeGroup.layerWithPath(MSPath.pathWithBezierPath(path)); - - var _points2 = line.layers().firstObject().points(); - - _points2[0].curveMode = 4; - _points2[1].curveMode = 4; - _points2[0].hasCurveFrom = true; - _points2[1].hasCurveTo = true; - - if (firstLayerPosX < secondLayerPosX) { - _points2[0].curveFrom = { - x: 0, - y: 0.5 - }; - _points2[0].curveTo = { - x: -0.5, - y: 1 - }; - _points2[1].curveFrom = { - x: 1, - y: 1 - }; - _points2[1].curveTo = { - x: 1, - y: 0.5 - }; - } else { - _points2[0].curveFrom = { - x: 1, - y: 0.5 - }; - _points2[0].curveTo = { - x: -0.5, - y: 1 - }; - _points2[1].curveFrom = { - x: 1, - y: 1 - }; - _points2[1].curveTo = { - x: 0, - y: 0.5 - }; - } - } - - if (direction == "Left") { - // Connecting points - path.moveToPoint(NSMakePoint(firstLayerPosX, firstLayerPosY)); - path.lineToPoint(NSMakePoint(secondLayerPosX, secondLayerPosY)); // Painting the line - - line = MSShapeGroup.layerWithPath(MSPath.pathWithBezierPath(path)); - - var _points3 = line.layers().firstObject().points(); - - _points3[0].curveMode = 4; - _points3[1].curveMode = 4; - _points3[0].hasCurveFrom = true; - _points3[1].hasCurveTo = true; - - if (firstLayerPosY < secondLayerPosY) { - _points3[0].curveFrom = { - x: 0.5, - y: 0 - }; - _points3[0].curveTo = { - x: -0.5, - y: 1 - }; - _points3[1].curveFrom = { - x: 1, - y: 1 - }; - _points3[1].curveTo = { - x: 0.5, - y: 1 - }; - } else { - _points3[0].curveFrom = { - x: 0.5, - y: 1 - }; - _points3[0].curveTo = { - x: -0.5, - y: 1 - }; - _points3[1].curveFrom = { - x: 1, - y: 1 - }; - _points3[1].curveTo = { - x: 0.5, - y: 0 - }; - } - } // Providing Settings for the arrow - - - line.setName("Curved Arrow"); - return line; -} - -/***/ }), - -/***/ "./src/utilities/conditions.js": +/*! exports provided: drawConnection */function(e,t,r){"use strict";r.r(t),r.d(t,"drawConnection",function(){return s});r(/*! sketch */"sketch");var o=r(/*! ./utilities/styling.js */"./src/utilities/styling.js"),n=r(/*! ./utilities/conditions.js */"./src/utilities/conditions.js"),i=r(/*! ./utilities/groups.js */"./src/utilities/groups.js"),a=r(/*! sketch/settings */"sketch/settings");r(/*! sketch/ui */"sketch/ui");function s(e,t,r,s,c,u,l,d,f){var y=f.currentPage().currentArtboard()||f.currentPage(),h=function(e,t,r,o){var n,a,s=e.frame.changeBasis({from:e.parent,to:o}),c=t.frame.changeBasis({from:t.parent,to:o}),u=Object(i.checkForGroup)("Arrows",o);u?(n=u.frame().x(),a=u.frame().y()):(n=0,a=0);var l={firstLayerPosX:null,firstLayerPosY:null,secondLayerPosX:null,secondLayerPosY:null,middlePosX:null,middlePosY:null};"Up"==r&&(l.firstLayerPosX=s.x+s.width/2-n,l.firstLayerPosY=s.y-a,l.secondLayerPosX=c.x+c.width/2-n,l.secondLayerPosY=c.y+c.height-a,l.middlePosX=(l.firstLayerPosX+l.secondLayerPosX)/2,l.middlePosY=(l.firstLayerPosY+l.secondLayerPosY)/2);"Right"==r&&(l.firstLayerPosX=s.x+s.width-n,l.firstLayerPosY=s.y+s.height/2-a,l.secondLayerPosX=c.x-n,l.secondLayerPosY=c.y+c.height/2-a,l.middlePosX=(l.firstLayerPosX+l.secondLayerPosX)/2,l.middlePosY=(l.firstLayerPosY+l.secondLayerPosY)/2);"Down"==r&&(l.firstLayerPosX=s.x+s.width/2-n,l.firstLayerPosY=s.y+s.height-a,l.secondLayerPosX=c.x+c.width/2-n,l.secondLayerPosY=c.y-a,l.middlePosX=(l.firstLayerPosX+l.secondLayerPosX)/2,l.middlePosY=(l.firstLayerPosY+l.secondLayerPosY)/2);"Left"==r&&(l.firstLayerPosX=s.x-n,l.firstLayerPosY=s.y+s.height/2-a,l.secondLayerPosX=c.x+c.width-n,l.secondLayerPosY=c.y+c.height/2-a,l.middlePosX=(l.firstLayerPosX+l.secondLayerPosX)/2,l.middlePosY=(l.firstLayerPosY+l.secondLayerPosY)/2);return l}(d.getLayerWithID(e),d.getLayerWithID(t),c,y),m={line:[],conditionID:[],type:[],style:[]};return m.type=null==s?a.settingForKey("arrowType"):s,"Angled"!=m.type&&null!=m.type||(m.line=function(e,t,r,o,n,i,a){var s=NSBezierPath.bezierPath();"Up"==a&&(s.moveToPoint(NSMakePoint(e,t)),s.lineToPoint(NSMakePoint(e,o)),s.lineToPoint(NSMakePoint(n,o)),s.lineToPoint(NSMakePoint(n,i)));"Right"==a&&(s.moveToPoint(NSMakePoint(e,t)),s.lineToPoint(NSMakePoint(r,t)),s.lineToPoint(NSMakePoint(r,i)),s.lineToPoint(NSMakePoint(n,i)));"Down"==a&&(s.moveToPoint(NSMakePoint(e,t)),s.lineToPoint(NSMakePoint(e,o)),s.lineToPoint(NSMakePoint(n,o)),s.lineToPoint(NSMakePoint(n,i)));"Left"==a&&(s.moveToPoint(NSMakePoint(e,t)),s.lineToPoint(NSMakePoint(r,t)),s.lineToPoint(NSMakePoint(r,i)),s.lineToPoint(NSMakePoint(n,i)));var c=MSShapeGroup.layerWithPath(MSPath.pathWithBezierPath(s)),u=c.layers().firstObject().points();return u[1].cornerRadius=20,u[2].cornerRadius=20,c.setName("Angled Arrow"),c}(h.firstLayerPosX,h.firstLayerPosY,h.middlePosX,h.middlePosY,h.secondLayerPosX,h.secondLayerPosY,c)),"Straight"==m.type&&(m.line=function(e,t,r,o,n){var i=NSBezierPath.bezierPath();"Up"==n&&(i.moveToPoint(NSMakePoint(e,t)),i.lineToPoint(NSMakePoint(r,o)));"Right"==n&&(i.moveToPoint(NSMakePoint(e,t)),i.lineToPoint(NSMakePoint(r,o)));"Down"==n&&(i.moveToPoint(NSMakePoint(e,t)),i.lineToPoint(NSMakePoint(r,o)));"Left"==n&&(i.moveToPoint(NSMakePoint(e,t)),i.lineToPoint(NSMakePoint(r,o)));var a=MSShapeGroup.layerWithPath(MSPath.pathWithBezierPath(i));return a.setName("Straight Arrow"),a}(h.firstLayerPosX,h.firstLayerPosY,h.secondLayerPosX,h.secondLayerPosY,c)),"Curved"==m.type&&(m.line=function(e,t,r,o,n){var i,a=NSBezierPath.bezierPath();if("Up"==n){a.moveToPoint(NSMakePoint(e,t)),a.lineToPoint(NSMakePoint(r,o));var s=(i=MSShapeGroup.layerWithPath(MSPath.pathWithBezierPath(a))).layers().firstObject().points();s[0].curveMode=4,s[1].curveMode=4,s[0].hasCurveFrom=!0,s[1].hasCurveTo=!0,e Connection Arrows -> Get Free Library. Conditions are taken from the library based on their names. Make sure to name symbol as "#condition" so it will be added here'); - } else { - var symbolMaster = libraryObject.import(); - symbol = symbolMaster.createNewInstance(); - symbol = Object(_groups_js__WEBPACK_IMPORTED_MODULE_1__["addToConditionGroup"])(symbol, x, y, currentParentGroup); - } - - return symbol; -} -function updateCondition(conditionID, x, y, document, docData) { - var currentParentGroup = docData.currentPage().currentArtboard() || docData.currentPage(); - var condition = document.getLayerWithID(conditionID); - var conGroup = Object(_groups_js__WEBPACK_IMPORTED_MODULE_1__["checkForGroup"])("Conditions", currentParentGroup); - var arGroup = Object(_groups_js__WEBPACK_IMPORTED_MODULE_1__["checkForGroup"])("Arrows", currentParentGroup); - var arGroupX = arGroup != null ? arGroup.frame().x() : 0; - var arGroupY = arGroup != null ? arGroup.frame().y() : 0; - - if (conGroup) { - condition.frame.x = x - condition.frame.width / 2 - (conGroup.frame().x() - arGroupX); - condition.frame.y = y - condition.frame.height / 2 - (conGroup.frame().y() - arGroupY); - conGroup.fixGeometryWithOptions(1); - } else { - condition.frame.x = x - condition.frame.width / 2; - condition.frame.y = y - condition.frame.height / 2; - } - - return condition.id; -} -function deleteCondition(conditionID, document) { - var conditionObject = document.getLayerWithID(conditionID); - var selectedGroup; - - if (conditionObject) { - selectedGroup = conditionObject.parent; - conditionObject.remove(); - - if (selectedGroup.layers.length == 0) { - selectedGroup.remove(); - } - } -} - -/***/ }), - -/***/ "./src/utilities/data.js": +/*! exports provided: addCondition, updateCondition, deleteCondition */function(e,t,r){"use strict";r.r(t),r.d(t,"addCondition",function(){return s}),r.d(t,"updateCondition",function(){return c}),r.d(t,"deleteCondition",function(){return u});var o=r(/*! sketch */"sketch"),n=r.n(o),i=r(/*! ./groups.js */"./src/utilities/groups.js"),a=(r(/*! sketch/settings */"sketch/settings"),r(/*! sketch/ui */"sketch/ui"));function s(e,t,r,o,s){for(var c,u,l,d=n.a.getLibraries(),f=s.currentPage().currentArtboard()||s.currentPage(),y=0;y Connection Arrows -> Get Free Library. Conditions are taken from the library based on their names. Make sure to name symbol as "#condition" so it will be added here')):(l=c.import().createNewInstance(),l=Object(i.addToConditionGroup)(l,t,r,f));return l}function c(e,t,r,o,n){var a=n.currentPage().currentArtboard()||n.currentPage(),s=o.getLayerWithID(e),c=Object(i.checkForGroup)("Conditions",a),u=Object(i.checkForGroup)("Arrows",a),l=null!=u?u.frame().x():0,d=null!=u?u.frame().y():0;return c?(s.frame.x=t-s.frame.width/2-(c.frame().x()-l),s.frame.y=r-s.frame.height/2-(c.frame().y()-d),c.fixGeometryWithOptions(1)):(s.frame.x=t-s.frame.width/2,s.frame.y=r-s.frame.height/2),s.id}function u(e,t){var r,o=t.getLayerWithID(e);o&&(r=o.parent,o.remove(),0==r.layers.length&&r.remove())}},"./src/utilities/data.js": /*!*******************************!*\ !*** ./src/utilities/data.js ***! \*******************************/ -/*! exports provided: getConnectionsData, deleteConnectionFromData */ -/***/ (function(module, __webpack_exports__, __webpack_require__) { - -"use strict"; -__webpack_require__.r(__webpack_exports__); -/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "getConnectionsData", function() { return getConnectionsData; }); -/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "deleteConnectionFromData", function() { return deleteConnectionFromData; }); -/* harmony import */ var sketch__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! sketch */ "sketch"); -/* harmony import */ var sketch__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(sketch__WEBPACK_IMPORTED_MODULE_0__); - - -var UI = __webpack_require__(/*! sketch/ui */ "sketch/ui"); - -var Settings = __webpack_require__(/*! sketch/settings */ "sketch/settings"); - -var pluginKey = "flowArrows"; -function getConnectionsData(docData) { - var pluginData = context.command.valueForKey_onLayer_forPluginIdentifier("arrowConnections", docData, pluginKey); - var dataArray = []; - - if (pluginData) { - for (var i = 0; i < pluginData.length; i++) { - dataArray.push(pluginData[i]); - } - } - - return dataArray; -} -function deleteConnectionFromData(connectionIndexArray, data) { - if (data) { - for (var i = connectionIndexArray.length - 1; i >= 0; i--) { - data.splice(connectionIndexArray[i], 1); - } - } - - return data; -} - -/***/ }), - -/***/ "./src/utilities/groups.js": +/*! exports provided: getConnectionsData, deleteConnectionFromData */function(e,r,o){"use strict";o.r(r),o.d(r,"getConnectionsData",function(){return i}),o.d(r,"deleteConnectionFromData",function(){return a});o(/*! sketch */"sketch"),o(/*! sketch/ui */"sketch/ui"),o(/*! sketch/settings */"sketch/settings");var n="flowArrows";function i(e){var r=t.command.valueForKey_onLayer_forPluginIdentifier("arrowConnections",e,n),o=[];if(r)for(var i=0;i=0;r--)t.splice(e[r],1);return t}},"./src/utilities/groups.js": /*!*********************************!*\ !*** ./src/utilities/groups.js ***! \*********************************/ -/*! exports provided: checkForGroup, addToArrowsGroup, addToConditionGroup */ -/***/ (function(module, __webpack_exports__, __webpack_require__) { - -"use strict"; -__webpack_require__.r(__webpack_exports__); -/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "checkForGroup", function() { return checkForGroup; }); -/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "addToArrowsGroup", function() { return addToArrowsGroup; }); -/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "addToConditionGroup", function() { return addToConditionGroup; }); -/* harmony import */ var sketch__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! sketch */ "sketch"); -/* harmony import */ var sketch__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(sketch__WEBPACK_IMPORTED_MODULE_0__); - - -var Settings = __webpack_require__(/*! sketch/settings */ "sketch/settings"); - -var UI = __webpack_require__(/*! sketch/ui */ "sketch/ui"); // let document = sketch.fromNative(context.document); -// let docData = context.document.documentData(); -// let currentParentGroup = docData.currentPage().currentArtboard() || docData.currentPage(); - - -function checkForGroup(groupName, currentParentGroup) { - // refactored - var currentGroup = null; // Checking all the groups that we have - - for (var i = 0; i < currentParentGroup.layers().count(); i++) { - if (currentParentGroup.layers()[i].name() == groupName) { - currentGroup = currentParentGroup.layers()[i]; - } - } - - return currentGroup; -} -function addToArrowsGroup(line, currentParentGroup) { - var currentGroup = checkForGroup("Arrows", currentParentGroup); - - if (currentGroup) { - currentGroup.addLayers([line]); - currentGroup.fixGeometryWithOptions(1); - } else { - var Group = __webpack_require__(/*! sketch/dom */ "sketch/dom").Group; - - var group = new Group({ - parent: currentParentGroup, - name: 'Arrows', - locked: true, - layers: [line] - }); - group.moveToBack(); - group.adjustToFit(); - } -} -function addToConditionGroup(condition, x, y, currentParentGroup) { - var conGroup = checkForGroup("Conditions", currentParentGroup); - var arGroup = checkForGroup("Arrows", currentParentGroup); - var arGroupX = arGroup != null ? arGroup.frame().x() : 0; - var arGroupY = arGroup != null ? arGroup.frame().y() : 0; - - if (conGroup) { - condition.frame.x = x - condition.frame.width / 2 - (conGroup.frame().x() - arGroupX); - condition.frame.y = y - condition.frame.height / 2 - (conGroup.frame().y() - arGroupY); - condition.parent = conGroup; - conGroup.fixGeometryWithOptions(1); - } else { - condition.frame.x = x - condition.frame.width / 2 + arGroupX; - condition.frame.y = y - condition.frame.height / 2 + arGroupY; - - var Group = __webpack_require__(/*! sketch/dom */ "sketch/dom").Group; - - var group = new Group({ - parent: currentParentGroup, - name: "Conditions", - layers: [condition] - }); - group.moveToBack(); - group.adjustToFit(); - } - - return condition.id; -} - -/***/ }), - -/***/ "./src/utilities/lines.js": +/*! exports provided: checkForGroup, addToArrowsGroup, addToConditionGroup */function(e,t,r){"use strict";r.r(t),r.d(t,"checkForGroup",function(){return o}),r.d(t,"addToArrowsGroup",function(){return n}),r.d(t,"addToConditionGroup",function(){return i});r(/*! sketch */"sketch"),r(/*! sketch/settings */"sketch/settings"),r(/*! sketch/ui */"sketch/ui");function o(e,t){for(var r=null,o=0;o firstObjectMidX) { - // Right Half - if (secondObjectMidY > firstObjectMidY) { - // Bottom quarter - direction = diffX > diffY ? "Down" : "Right"; - } else { - // Top quarter - direction = absDiffX > absDiffY ? "Right" : "Up"; - } - } else { - // Left Half - if (secondObjectMidY > firstObjectMidY) { - // Bottom quarter - direction = absDiffX > absDiffY ? "Left" : "Down"; - } else { - // Top quarter - direction = diffX > diffY ? "Left" : "Up"; - } - } - - return direction; -} - -function updateSpacing(sourceObjectID, childObjectID, direction, document) { - var sourceObject = document.getLayerWithID(sourceObjectID); - var childObject = document.getLayerWithID(childObjectID); - - if (Settings.settingForKey("arrowSpacing") && Settings.settingForKey("arrowSpacing") != 0) { - var currentSpacing = Settings.settingForKey("arrowSpacing"); - - if (direction == "Right") { - childObject.frame.x = sourceObject.frame.x + sourceObject.frame.width + currentSpacing; - } - - if (direction == "Down") { - childObject.frame.y = sourceObject.frame.y + sourceObject.frame.height + currentSpacing; - } - - if (direction == "Left") { - childObject.frame.x = sourceObject.frame.x - childObject.frame.width - currentSpacing; - } - - if (direction == "Up") { - childObject.frame.y = sourceObject.frame.y - childObject.frame.height - currentSpacing; - } - } -} - -function autoAlignLayer(sourceObjectID, childObjectID, direction, document) { - var sourceObject = document.getLayerWithID(sourceObjectID); - var childObject = document.getLayerWithID(childObjectID); - var sourceMidY, childMidY, sourceMidX, childMidX, diff; - - if (Settings.settingForKey("autoAlign")) { - if (Settings.settingForKey("autoAlign") == true) { - // If user turned on Auto-Align settings - if (direction == "Right" || direction == "Left") { - sourceMidY = sourceObject.frame.y + sourceObject.frame.height / 2; - childMidY = childObject.frame.y + childObject.frame.height / 2; - diff = sourceMidY - childMidY; - - if (diff > -6 && diff < 6) { - childObject.frame.y = childObject.frame.y + diff; - } - } - - if (direction == "Down" || direction == "Up") { - sourceMidX = sourceObject.frame.x + sourceObject.frame.width / 2; - childMidX = childObject.frame.x + childObject.frame.width / 2; - diff = sourceMidX - childMidX; - - if (diff > -6 && diff < 6) { - childObject.frame.x = childObject.frame.x + diff; - } - } - } - } -} - -/***/ }), - -/***/ "./src/draw.js": +/*! exports provided: createArrow */function(e,t,r){"use strict";r.r(t),r.d(t,"createArrow",function(){return i});r(/*! sketch */"sketch");var o=r(/*! ./draw.js */"./src/draw.js"),n=r(/*! sketch/settings */"sketch/settings");function i(e,t,r,i,a,s,c,u,d){var l="Auto"==a?function(e,t,r){var o,n=r.getLayerWithID(e),i=r.getLayerWithID(t),a=n.frame.x+n.frame.width/2,s=n.frame.y+n.frame.height/2,c=i.frame.x+i.frame.width/2,u=i.frame.y+i.frame.height/2,d=a-c,l=s-u,f=Math.abs(d),h=Math.abs(l);o=c>a?u>s?d>l?"Down":"Right":f>h?"Right":"Up":u>s?f>h?"Left":"Down":d>l?"Left":"Up";return o}(e,t,u):a;!function(e,t,r,o){var i=o.getLayerWithID(e),a=o.getLayerWithID(t);if(n.settingForKey("arrowSpacing")&&0!=n.settingForKey("arrowSpacing")){var s=n.settingForKey("arrowSpacing");"Right"==r&&(a.frame.x=i.frame.x+i.frame.width+s),"Down"==r&&(a.frame.y=i.frame.y+i.frame.height+s),"Left"==r&&(a.frame.x=i.frame.x-a.frame.width-s),"Up"==r&&(a.frame.y=i.frame.y-a.frame.height-s)}}(e,t,l,u),function(e,t,r,o){var i,a,s,c,u,d=o.getLayerWithID(e),l=o.getLayerWithID(t);n.settingForKey("autoAlign")&&1==n.settingForKey("autoAlign")&&("Right"!=r&&"Left"!=r||(i=d.frame.y+d.frame.height/2,a=l.frame.y+l.frame.height/2,(u=i-a)>-6&&u<6&&(l.frame.y=l.frame.y+u)),"Down"!=r&&"Up"!=r||(s=d.frame.x+d.frame.width/2,c=l.frame.x+l.frame.width/2,(u=s-c)>-6&&u<6&&(l.frame.x=l.frame.x+u)))}(e,t,l,u);var f=Object(o.drawConnection)(e,t,r,i,l,s,c,u,d);return{firstObject:e,secondObject:t,style:f.style,condition:f.conditionID,isCondition:c,type:f.type,direction:l,line:f.line.objectID()}}},"./src/draw.js": /*!*********************!*\ !*** ./src/draw.js ***! \*********************/ -/*! exports provided: drawConnection */ -/***/ (function(module, __webpack_exports__, __webpack_require__) { - -"use strict"; -__webpack_require__.r(__webpack_exports__); -/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "drawConnection", function() { return drawConnection; }); -/* harmony import */ var sketch__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! sketch */ "sketch"); -/* harmony import */ var sketch__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(sketch__WEBPACK_IMPORTED_MODULE_0__); -/* harmony import */ var _utilities_styling_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./utilities/styling.js */ "./src/utilities/styling.js"); -/* harmony import */ var _utilities_conditions_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./utilities/conditions.js */ "./src/utilities/conditions.js"); -/* harmony import */ var _utilities_groups_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./utilities/groups.js */ "./src/utilities/groups.js"); - - - - - -var Settings = __webpack_require__(/*! sketch/settings */ "sketch/settings"); - -var UI = __webpack_require__(/*! sketch/ui */ "sketch/ui"); // let document = sketch.fromNative(context.document); -// let docData = context.document.documentData(); -// let currentParentGroup = docData.currentPage().currentArtboard() || docData.currentPage(); -// Main Function - - -function drawConnection(firstObjectID, secondObjectID, style, type, localDirection, conditionID, isCondition, document, docData) { - // Refactored - // Process of creating new connection - var currentParentGroup = docData.currentPage().currentArtboard() || docData.currentPage(); - var firstObject = document.getLayerWithID(firstObjectID); - var secondObject = document.getLayerWithID(secondObjectID); - var connectionPos = getConnectionPos(firstObject, secondObject, localDirection, currentParentGroup); - var connection = { - line: [], - conditionID: [], - type: [], - style: [] // Type - - }; - connection.type = type == null ? Settings.settingForKey("arrowType") : type; - - if (connection.type == "Angled" || connection.type == null) { - connection.line = drawAngledLine(connectionPos.firstLayerPosX, connectionPos.firstLayerPosY, connectionPos.middlePosX, connectionPos.middlePosY, connectionPos.secondLayerPosX, connectionPos.secondLayerPosY, localDirection); - } - - if (connection.type == "Straight") { - connection.line = drawStraightLine(connectionPos.firstLayerPosX, connectionPos.firstLayerPosY, connectionPos.secondLayerPosX, connectionPos.secondLayerPosY, localDirection); - } - - if (connection.type == "Curved") { - connection.line = drawCurvedLine(connectionPos.firstLayerPosX, connectionPos.firstLayerPosY, connectionPos.secondLayerPosX, connectionPos.secondLayerPosY, localDirection); - } // Condition - - - if (isCondition == true) { - if (document.getLayerWithID(conditionID)) { - connection.conditionID = Object(_utilities_conditions_js__WEBPACK_IMPORTED_MODULE_2__["updateCondition"])(conditionID, connectionPos.middlePosX, connectionPos.middlePosY, document, docData); - } else { - connection.conditionID = Object(_utilities_conditions_js__WEBPACK_IMPORTED_MODULE_2__["addCondition"])("#con", connectionPos.middlePosX, connectionPos.middlePosY, document, docData); - } - } else { - connection.conditionID = null; - } // Style - - - connection.style = Object(_utilities_styling_js__WEBPACK_IMPORTED_MODULE_1__["styleLine"])(connection.line, style, docData); // Add to group - - Object(_utilities_groups_js__WEBPACK_IMPORTED_MODULE_3__["addToArrowsGroup"])(connection.line, currentParentGroup); - return connection; -} // Positions - -function getConnectionPos(firstObject, secondObject, direction, currentParentGroup) { - // Refactored - var firstObjectAbsPos = firstObject.frame.changeBasis({ - from: firstObject.parent, - to: currentParentGroup - }); - var secondObjectAbsPos = secondObject.frame.changeBasis({ - from: secondObject.parent, - to: currentParentGroup - }); - var currentGroup = Object(_utilities_groups_js__WEBPACK_IMPORTED_MODULE_3__["checkForGroup"])("Arrows", currentParentGroup); - var diffX, diffY; - - if (currentGroup) { - diffX = currentGroup.frame().x(); - diffY = currentGroup.frame().y(); - } else { - diffX = 0; - diffY = 0; - } - - var connectionPos = { - firstLayerPosX: null, - firstLayerPosY: null, - secondLayerPosX: null, - secondLayerPosY: null, - middlePosX: null, - middlePosY: null // Getting all the positions - - }; - - if (direction == "Up") { - // First Layer Position Start Point Position - connectionPos.firstLayerPosX = firstObjectAbsPos.x + firstObjectAbsPos.width / 2 - diffX; - connectionPos.firstLayerPosY = firstObjectAbsPos.y - diffY; // Second Layer Position End Point Position - - connectionPos.secondLayerPosX = secondObjectAbsPos.x + secondObjectAbsPos.width / 2 - diffX; - connectionPos.secondLayerPosY = secondObjectAbsPos.y + secondObjectAbsPos.height - diffY; // Middle Points - - connectionPos.middlePosX = (connectionPos.firstLayerPosX + connectionPos.secondLayerPosX) / 2; - connectionPos.middlePosY = (connectionPos.firstLayerPosY + connectionPos.secondLayerPosY) / 2; - } - - if (direction == "Right") { - // First Layer Position Start Point Position - connectionPos.firstLayerPosX = firstObjectAbsPos.x + firstObjectAbsPos.width - diffX; - connectionPos.firstLayerPosY = firstObjectAbsPos.y + firstObjectAbsPos.height / 2 - diffY; // Second Layer Position End Point Position - - connectionPos.secondLayerPosX = secondObjectAbsPos.x - diffX; - connectionPos.secondLayerPosY = secondObjectAbsPos.y + secondObjectAbsPos.height / 2 - diffY; // Middle Points - - connectionPos.middlePosX = (connectionPos.firstLayerPosX + connectionPos.secondLayerPosX) / 2; - connectionPos.middlePosY = (connectionPos.firstLayerPosY + connectionPos.secondLayerPosY) / 2; - } - - if (direction == "Down") { - // First Layer Position Start Point Position - connectionPos.firstLayerPosX = firstObjectAbsPos.x + firstObjectAbsPos.width / 2 - diffX; - connectionPos.firstLayerPosY = firstObjectAbsPos.y + firstObjectAbsPos.height - diffY; // Second Layer Position End Point Position - - connectionPos.secondLayerPosX = secondObjectAbsPos.x + secondObjectAbsPos.width / 2 - diffX; - connectionPos.secondLayerPosY = secondObjectAbsPos.y - diffY; // Middle Points - - connectionPos.middlePosX = (connectionPos.firstLayerPosX + connectionPos.secondLayerPosX) / 2; - connectionPos.middlePosY = (connectionPos.firstLayerPosY + connectionPos.secondLayerPosY) / 2; - } - - if (direction == "Left") { - // First Layer Position Start Point Position - connectionPos.firstLayerPosX = firstObjectAbsPos.x - diffX; - connectionPos.firstLayerPosY = firstObjectAbsPos.y + firstObjectAbsPos.height / 2 - diffY; // Second Layer Position End Point Position - - connectionPos.secondLayerPosX = secondObjectAbsPos.x + secondObjectAbsPos.width - diffX; - connectionPos.secondLayerPosY = secondObjectAbsPos.y + secondObjectAbsPos.height / 2 - diffY; // Middle Points - - connectionPos.middlePosX = (connectionPos.firstLayerPosX + connectionPos.secondLayerPosX) / 2; - connectionPos.middlePosY = (connectionPos.firstLayerPosY + connectionPos.secondLayerPosY) / 2; - } - - return connectionPos; -} // Drawing Types - - -function drawAngledLine(firstLayerPosX, firstLayerPosY, middlePosX, middlePosY, secondLayerPosX, secondLayerPosY, direction) { - // Refactored - var path = NSBezierPath.bezierPath(); - - if (direction == "Up") { - // Connecting points - path.moveToPoint(NSMakePoint(firstLayerPosX, firstLayerPosY)); - path.lineToPoint(NSMakePoint(firstLayerPosX, middlePosY)); - path.lineToPoint(NSMakePoint(secondLayerPosX, middlePosY)); - path.lineToPoint(NSMakePoint(secondLayerPosX, secondLayerPosY)); - } - - if (direction == "Right") { - // Connecting points - path.moveToPoint(NSMakePoint(firstLayerPosX, firstLayerPosY)); - path.lineToPoint(NSMakePoint(middlePosX, firstLayerPosY)); - path.lineToPoint(NSMakePoint(middlePosX, secondLayerPosY)); - path.lineToPoint(NSMakePoint(secondLayerPosX, secondLayerPosY)); - } - - if (direction == "Down") { - // Connecting points - path.moveToPoint(NSMakePoint(firstLayerPosX, firstLayerPosY)); - path.lineToPoint(NSMakePoint(firstLayerPosX, middlePosY)); - path.lineToPoint(NSMakePoint(secondLayerPosX, middlePosY)); - path.lineToPoint(NSMakePoint(secondLayerPosX, secondLayerPosY)); - } - - if (direction == "Left") { - // Connecting points - path.moveToPoint(NSMakePoint(firstLayerPosX, firstLayerPosY)); - path.lineToPoint(NSMakePoint(middlePosX, firstLayerPosY)); - path.lineToPoint(NSMakePoint(middlePosX, secondLayerPosY)); - path.lineToPoint(NSMakePoint(secondLayerPosX, secondLayerPosY)); - } - - var line = MSShapeGroup.layerWithPath(MSPath.pathWithBezierPath(path)); - var points = line.layers().firstObject().points(); - points[1].cornerRadius = 20; - points[2].cornerRadius = 20; - line.setName("Angled Arrow"); - return line; -} - -function drawStraightLine(firstLayerPosX, firstLayerPosY, secondLayerPosX, secondLayerPosY, direction) { - // Refactored - var path = NSBezierPath.bezierPath(); - - if (direction == "Up") { - path.moveToPoint(NSMakePoint(firstLayerPosX, firstLayerPosY)); - path.lineToPoint(NSMakePoint(secondLayerPosX, secondLayerPosY)); - } - - if (direction == "Right") { - path.moveToPoint(NSMakePoint(firstLayerPosX, firstLayerPosY)); - path.lineToPoint(NSMakePoint(secondLayerPosX, secondLayerPosY)); - } - - if (direction == "Down") { - path.moveToPoint(NSMakePoint(firstLayerPosX, firstLayerPosY)); - path.lineToPoint(NSMakePoint(secondLayerPosX, secondLayerPosY)); - } - - if (direction == "Left") { - path.moveToPoint(NSMakePoint(firstLayerPosX, firstLayerPosY)); - path.lineToPoint(NSMakePoint(secondLayerPosX, secondLayerPosY)); - } - - var line = MSShapeGroup.layerWithPath(MSPath.pathWithBezierPath(path)); - line.setName("Straight Arrow"); - return line; -} - -function drawCurvedLine(firstLayerPosX, firstLayerPosY, secondLayerPosX, secondLayerPosY, direction) { - // Refactored - var path = NSBezierPath.bezierPath(); - var line; - - if (direction == "Up") { - // Connecting points - path.moveToPoint(NSMakePoint(firstLayerPosX, firstLayerPosY)); - path.lineToPoint(NSMakePoint(secondLayerPosX, secondLayerPosY)); // Painting the line - - line = MSShapeGroup.layerWithPath(MSPath.pathWithBezierPath(path)); - var points = line.layers().firstObject().points(); - points[0].curveMode = 4; - points[1].curveMode = 4; - points[0].hasCurveFrom = true; - points[1].hasCurveTo = true; - - if (firstLayerPosX < secondLayerPosX) { - points[0].curveFrom = { - x: 0, - y: 0.5 - }; - points[0].curveTo = { - x: -0.5, - y: 1 - }; - points[1].curveFrom = { - x: 1, - y: 1 - }; - points[1].curveTo = { - x: 1, - y: 0.5 - }; - } else { - points[0].curveFrom = { - x: 1, - y: 0.5 - }; - points[0].curveTo = { - x: -0.5, - y: 1 - }; - points[1].curveFrom = { - x: 1, - y: 1 - }; - points[1].curveTo = { - x: 0, - y: 0.5 - }; - } - } - - if (direction == "Right") { - // Connecting points - path.moveToPoint(NSMakePoint(firstLayerPosX, firstLayerPosY)); - path.lineToPoint(NSMakePoint(secondLayerPosX, secondLayerPosY)); // Painting the line - - line = MSShapeGroup.layerWithPath(MSPath.pathWithBezierPath(path)); - - var _points = line.layers().firstObject().points(); - - _points[0].curveMode = 4; - _points[1].curveMode = 4; - _points[0].hasCurveFrom = true; - _points[1].hasCurveTo = true; - - if (firstLayerPosY < secondLayerPosY) { - _points[0].curveFrom = { - x: 0.5, - y: 0 - }; - _points[0].curveTo = { - x: -0.5, - y: 1 - }; - _points[1].curveFrom = { - x: 1, - y: 1 - }; - _points[1].curveTo = { - x: 0.5, - y: 1 - }; - } else { - _points[0].curveFrom = { - x: 0.5, - y: 1 - }; - _points[0].curveTo = { - x: -0.5, - y: 1 - }; - _points[1].curveFrom = { - x: 1, - y: 1 - }; - _points[1].curveTo = { - x: 0.5, - y: 0 - }; - } - } - - if (direction == "Down") { - // Connecting points - path.moveToPoint(NSMakePoint(firstLayerPosX, firstLayerPosY)); - path.lineToPoint(NSMakePoint(secondLayerPosX, secondLayerPosY)); // Painting the line - - line = MSShapeGroup.layerWithPath(MSPath.pathWithBezierPath(path)); - - var _points2 = line.layers().firstObject().points(); - - _points2[0].curveMode = 4; - _points2[1].curveMode = 4; - _points2[0].hasCurveFrom = true; - _points2[1].hasCurveTo = true; - - if (firstLayerPosX < secondLayerPosX) { - _points2[0].curveFrom = { - x: 0, - y: 0.5 - }; - _points2[0].curveTo = { - x: -0.5, - y: 1 - }; - _points2[1].curveFrom = { - x: 1, - y: 1 - }; - _points2[1].curveTo = { - x: 1, - y: 0.5 - }; - } else { - _points2[0].curveFrom = { - x: 1, - y: 0.5 - }; - _points2[0].curveTo = { - x: -0.5, - y: 1 - }; - _points2[1].curveFrom = { - x: 1, - y: 1 - }; - _points2[1].curveTo = { - x: 0, - y: 0.5 - }; - } - } - - if (direction == "Left") { - // Connecting points - path.moveToPoint(NSMakePoint(firstLayerPosX, firstLayerPosY)); - path.lineToPoint(NSMakePoint(secondLayerPosX, secondLayerPosY)); // Painting the line - - line = MSShapeGroup.layerWithPath(MSPath.pathWithBezierPath(path)); - - var _points3 = line.layers().firstObject().points(); - - _points3[0].curveMode = 4; - _points3[1].curveMode = 4; - _points3[0].hasCurveFrom = true; - _points3[1].hasCurveTo = true; - - if (firstLayerPosY < secondLayerPosY) { - _points3[0].curveFrom = { - x: 0.5, - y: 0 - }; - _points3[0].curveTo = { - x: -0.5, - y: 1 - }; - _points3[1].curveFrom = { - x: 1, - y: 1 - }; - _points3[1].curveTo = { - x: 0.5, - y: 1 - }; - } else { - _points3[0].curveFrom = { - x: 0.5, - y: 1 - }; - _points3[0].curveTo = { - x: -0.5, - y: 1 - }; - _points3[1].curveFrom = { - x: 1, - y: 1 - }; - _points3[1].curveTo = { - x: 0.5, - y: 0 - }; - } - } // Providing Settings for the arrow - - - line.setName("Curved Arrow"); - return line; -} - -/***/ }), - -/***/ "./src/script.js": +/*! exports provided: drawConnection */function(e,t,r){"use strict";r.r(t),r.d(t,"drawConnection",function(){return s});r(/*! sketch */"sketch");var o=r(/*! ./utilities/styling.js */"./src/utilities/styling.js"),n=r(/*! ./utilities/conditions.js */"./src/utilities/conditions.js"),i=r(/*! ./utilities/groups.js */"./src/utilities/groups.js"),a=r(/*! sketch/settings */"sketch/settings");r(/*! sketch/ui */"sketch/ui");function s(e,t,r,s,c,u,d,l,f){var h=f.currentPage().currentArtboard()||f.currentPage(),y=function(e,t,r,o){var n,a,s=e.frame.changeBasis({from:e.parent,to:o}),c=t.frame.changeBasis({from:t.parent,to:o}),u=Object(i.checkForGroup)("Arrows",o);u?(n=u.frame().x(),a=u.frame().y()):(n=0,a=0);var d={firstLayerPosX:null,firstLayerPosY:null,secondLayerPosX:null,secondLayerPosY:null,middlePosX:null,middlePosY:null};"Up"==r&&(d.firstLayerPosX=s.x+s.width/2-n,d.firstLayerPosY=s.y-a,d.secondLayerPosX=c.x+c.width/2-n,d.secondLayerPosY=c.y+c.height-a,d.middlePosX=(d.firstLayerPosX+d.secondLayerPosX)/2,d.middlePosY=(d.firstLayerPosY+d.secondLayerPosY)/2);"Right"==r&&(d.firstLayerPosX=s.x+s.width-n,d.firstLayerPosY=s.y+s.height/2-a,d.secondLayerPosX=c.x-n,d.secondLayerPosY=c.y+c.height/2-a,d.middlePosX=(d.firstLayerPosX+d.secondLayerPosX)/2,d.middlePosY=(d.firstLayerPosY+d.secondLayerPosY)/2);"Down"==r&&(d.firstLayerPosX=s.x+s.width/2-n,d.firstLayerPosY=s.y+s.height-a,d.secondLayerPosX=c.x+c.width/2-n,d.secondLayerPosY=c.y-a,d.middlePosX=(d.firstLayerPosX+d.secondLayerPosX)/2,d.middlePosY=(d.firstLayerPosY+d.secondLayerPosY)/2);"Left"==r&&(d.firstLayerPosX=s.x-n,d.firstLayerPosY=s.y+s.height/2-a,d.secondLayerPosX=c.x+c.width-n,d.secondLayerPosY=c.y+c.height/2-a,d.middlePosX=(d.firstLayerPosX+d.secondLayerPosX)/2,d.middlePosY=(d.firstLayerPosY+d.secondLayerPosY)/2);return d}(l.getLayerWithID(e),l.getLayerWithID(t),c,h),m={line:[],conditionID:[],type:[],style:[]};return m.type=null==s?a.settingForKey("arrowType"):s,"Angled"!=m.type&&null!=m.type||(m.line=function(e,t,r,o,n,i,a){var s=NSBezierPath.bezierPath();"Up"==a&&(s.moveToPoint(NSMakePoint(e,t)),s.lineToPoint(NSMakePoint(e,o)),s.lineToPoint(NSMakePoint(n,o)),s.lineToPoint(NSMakePoint(n,i)));"Right"==a&&(s.moveToPoint(NSMakePoint(e,t)),s.lineToPoint(NSMakePoint(r,t)),s.lineToPoint(NSMakePoint(r,i)),s.lineToPoint(NSMakePoint(n,i)));"Down"==a&&(s.moveToPoint(NSMakePoint(e,t)),s.lineToPoint(NSMakePoint(e,o)),s.lineToPoint(NSMakePoint(n,o)),s.lineToPoint(NSMakePoint(n,i)));"Left"==a&&(s.moveToPoint(NSMakePoint(e,t)),s.lineToPoint(NSMakePoint(r,t)),s.lineToPoint(NSMakePoint(r,i)),s.lineToPoint(NSMakePoint(n,i)));var c=MSShapeGroup.layerWithPath(MSPath.pathWithBezierPath(s)),u=c.layers().firstObject().points();return u[1].cornerRadius=20,u[2].cornerRadius=20,c.setName("Angled Arrow"),c}(y.firstLayerPosX,y.firstLayerPosY,y.middlePosX,y.middlePosY,y.secondLayerPosX,y.secondLayerPosY,c)),"Straight"==m.type&&(m.line=function(e,t,r,o,n){var i=NSBezierPath.bezierPath();"Up"==n&&(i.moveToPoint(NSMakePoint(e,t)),i.lineToPoint(NSMakePoint(r,o)));"Right"==n&&(i.moveToPoint(NSMakePoint(e,t)),i.lineToPoint(NSMakePoint(r,o)));"Down"==n&&(i.moveToPoint(NSMakePoint(e,t)),i.lineToPoint(NSMakePoint(r,o)));"Left"==n&&(i.moveToPoint(NSMakePoint(e,t)),i.lineToPoint(NSMakePoint(r,o)));var a=MSShapeGroup.layerWithPath(MSPath.pathWithBezierPath(i));return a.setName("Straight Arrow"),a}(y.firstLayerPosX,y.firstLayerPosY,y.secondLayerPosX,y.secondLayerPosY,c)),"Curved"==m.type&&(m.line=function(e,t,r,o,n){var i,a=NSBezierPath.bezierPath();if("Up"==n){a.moveToPoint(NSMakePoint(e,t)),a.lineToPoint(NSMakePoint(r,o));var s=(i=MSShapeGroup.layerWithPath(MSPath.pathWithBezierPath(a))).layers().firstObject().points();s[0].curveMode=4,s[1].curveMode=4,s[0].hasCurveFrom=!0,s[1].hasCurveTo=!0,e 1 && selection[0].class() != "MSArtboardGroup") { - var sourceObjectID = Object(_utilities_getSourceObject_js__WEBPACK_IMPORTED_MODULE_3__["getSourceObjectFromSelection"])(selection, direction); - var connectionIndex = []; - - for (var g = 0; g < selection.count(); g++) { - if (selection[g].objectID() != sourceObjectID) { - var firstObjectID = String(sourceObjectID); - var secondObjectID = String(selection[g].objectID()); - var _create = true; - var index = void 0; - - if (connectionsData.length > 0) { - for (var y = 0; y < connectionsData.length; y++) { - if ((firstObjectID == connectionsData[y].firstObject || firstObjectID == connectionsData[y].secondObject) && (secondObjectID == connectionsData[y].firstObject || secondObjectID == connectionsData[y].secondObject)) { - // We have this connection and need to update - _create = false; - index = y; - connectionIndex.push(y); - } - } - } - - if (_create) { - // Create - var connection = Object(_createArrow_js__WEBPACK_IMPORTED_MODULE_1__["createArrow"])(firstObjectID, secondObjectID, null, null, direction, null, isCondition, document, docData); - connectionsData.push(connection); - sketch__WEBPACK_IMPORTED_MODULE_0___default.a.UI.message("New connection is created 🚀"); - } else { - // Update - Object(_utilities_lines_js__WEBPACK_IMPORTED_MODULE_5__["deleteLine"])(connectionsData[index].line, document); - - if (!isCondition) { - Object(_utilities_conditions_js__WEBPACK_IMPORTED_MODULE_6__["deleteCondition"])(connectionsData[index].condition, document); - } - - var _connection = Object(_createArrow_js__WEBPACK_IMPORTED_MODULE_1__["createArrow"])(firstObjectID, secondObjectID, null, null, direction, connectionsData[index].condition, isCondition, document, docData); - - connectionsData.push(_connection); - sketch__WEBPACK_IMPORTED_MODULE_0___default.a.UI.message("Current connection is updated 🤘"); - } - } - } - - if (connectionIndex.length > 0) { - // Update data if there was changes - connectionsData = Object(_utilities_data_js__WEBPACK_IMPORTED_MODULE_4__["deleteConnectionFromData"])(connectionIndex, connectionsData); - } - - context.command.setValue_forKey_onLayer_forPluginIdentifier(connectionsData, "arrowConnections", docData, pluginKey); - } else { - // When user didn't select anything - sketch__WEBPACK_IMPORTED_MODULE_0___default.a.UI.message("Please select more than two layers. Artboards are coming soon 🥳"); - } -} // -// Plugin Incoming Commands - Update and Delete -// - - -function updateSelectedArrows(context) { - update(context, 1, true); -} -function updateArtboardArrows(context) { - update(context, 2, true); -} -function updateAllArrows(context) { - update(context, 3, true); -} -function deleteSelectedArrows(context) { - update(context, 1, false); -} -function deleteArtboardArrows(context) { - update(context, 2, false); -} -function deleteAllArrows(context) { - update(context, 3, false); -} -function update(context, level, isUpdate) { - // 1 - selection level - // 2 - artboard level - // 3 - document level - var newConnectionsData = []; - var selection = context.selection; - var firstObjectArtboard; - var secondObjectArtboard; - - if (connectionsData.length > 0) { - if (level == 3) { - if (isUpdate) { - newConnectionsData = Object(_updateArrow_js__WEBPACK_IMPORTED_MODULE_2__["updateArrow"])(connectionsData[i].firstObject, connectionsData[i].secondObject, connectionsData[i].style, connectionsData[i].type, connectionsData[i].direction, connectionsData[i].line, connectionsData[i].condition, i); - sketch__WEBPACK_IMPORTED_MODULE_0___default.a.UI.message("All arrows are updated"); - } else { - for (var _i = 0; _i < connectionsData.length; _i++) { - Object(_utilities_lines_js__WEBPACK_IMPORTED_MODULE_5__["deleteLine"])(connectionsData[_i].line, document); - Object(_utilities_conditions_js__WEBPACK_IMPORTED_MODULE_6__["deleteCondition"])(connectionsData[_i].condition, document); - newConnectionsData = null; - } - } - } - - if (level == 2) { - if (isUpdate) {// Need to update - } else { - for (var _i2 = 0; _i2 < connectionsData.length; _i2++) { - if (selection[0].class() == "MSArtboardGroup") { - firstObjectArtboard = document.getLayerWithID(connectionsData[_i2].firstObject); - firstObjectArtboard = firstObjectArtboard.sketchObject.parentArtboard().objectID(); - - if (firstObjectArtboard == selection[0].objectID()) { - Object(_utilities_lines_js__WEBPACK_IMPORTED_MODULE_5__["deleteLine"])(connectionsData[_i2].line, document); - Object(_utilities_conditions_js__WEBPACK_IMPORTED_MODULE_6__["deleteCondition"])(connectionsData[_i2].condition, document); - } else { - newConnectionsData.push(connectionsData[_i2]); - } - } else { - sketch__WEBPACK_IMPORTED_MODULE_0___default.a.UI.message("Please select an artboard"); - } - } - } - } - - if (level == 1) { - if (isUpdate) {// updateArrow(connectionsData[i].firstObject, connectionsData[i].secondObject, connectionsData[i].style, connectionsData[i].type, connectionsData[i].direction, connectionsData[i].line, connectionsData[i].condition, i); - // sketch.UI.message("All arrows are updated"); - } else { - for (var _i3 = 0; _i3 < connectionsData.length; _i3++) { - if (selection[0].objectID() == connectionsData[_i3].firstObject) { - log("here"); - Object(_utilities_lines_js__WEBPACK_IMPORTED_MODULE_5__["deleteLine"])(connectionsData[_i3].line, document); - Object(_utilities_conditions_js__WEBPACK_IMPORTED_MODULE_6__["deleteCondition"])(connectionsData[_i3].condition, document); - } else { - newConnectionsData.push(connectionsData[_i3]); - } - } - - newConnectionsData = null; - sketch__WEBPACK_IMPORTED_MODULE_0___default.a.UI.message("All arrows are deleted"); - } - } - - sketch__WEBPACK_IMPORTED_MODULE_0___default.a.UI.message("All arrows are updated 🚀"); // let connection = createArrow(sourceObjectID, selection[g].objectID(), null, null, direction, null, isCondition, document, docData); - // connectionsData.push(connection); - - context.command.setValue_forKey_onLayer_forPluginIdentifier(newConnectionsData, "arrowConnections", docData, pluginKey); - } else { - sketch__WEBPACK_IMPORTED_MODULE_0___default.a.UI.message("There is no arrows"); - } -} // const track = require("sketch-module-google-analytics") -// track("UA-138226597-1", "event", { -// ec: "command", -// ea: "create", -// ev: "my-command" -// }); - -/***/ }), - -/***/ "./src/updateArrow.js": +/*! exports provided: createAutoArrow, createRightArrow, createDownArrow, createLeftArrow, createUpArrow, createRightArrowWithCondition, createDownArrowWithCondition, createLeftArrowWithCondition, createUpArrowWithCondition, updateSelectedArrows, updateArtboardArrows, updateAllArrows, deleteSelectedArrows, deleteArtboardArrows, deleteAllArrows, update */function(e,r,o){"use strict";o.r(r),o.d(r,"createAutoArrow",function(){return p}),o.d(r,"createRightArrow",function(){return g}),o.d(r,"createDownArrow",function(){return v}),o.d(r,"createLeftArrow",function(){return w}),o.d(r,"createUpArrow",function(){return b}),o.d(r,"createRightArrowWithCondition",function(){return A}),o.d(r,"createDownArrowWithCondition",function(){return L}),o.d(r,"createLeftArrowWithCondition",function(){return k}),o.d(r,"createUpArrowWithCondition",function(){return S}),o.d(r,"updateSelectedArrows",function(){return x}),o.d(r,"updateArtboardArrows",function(){return _}),o.d(r,"updateAllArrows",function(){return T}),o.d(r,"deleteSelectedArrows",function(){return M}),o.d(r,"deleteArtboardArrows",function(){return D}),o.d(r,"deleteAllArrows",function(){return O}),o.d(r,"update",function(){return C});var n=o(/*! sketch */"sketch"),a=o.n(n),s=o(/*! ./createArrow.js */"./src/createArrow.js"),c=o(/*! ./updateArrow.js */"./src/updateArrow.js"),u=o(/*! ./utilities/getSourceObject.js */"./src/utilities/getSourceObject.js"),d=o(/*! ./utilities/data.js */"./src/utilities/data.js"),l=o(/*! ./utilities/lines.js */"./src/utilities/lines.js"),f=o(/*! ./utilities/conditions.js */"./src/utilities/conditions.js"),h=(o(/*! sketch/ui */"sketch/ui"),o(/*! sketch/settings */"sketch/settings"),"flowArrows"),y=a.a.fromNative(t.document),m=t.document.documentData(),P=Object(d.getConnectionsData)(m);function p(e){j(e,"Auto",!1)}function g(e){j(e,"Right",!1)}function v(e){j(e,"Down",!1)}function w(e){j(e,"Left",!1)}function b(e){j(e,"Up",!1)}function A(e){j(e,"Right",!0)}function L(e){j(e,"Down",!0)}function k(e){j(e,"Left",!0)}function S(e){j(e,"Up",!0)}function j(e,t,r){var o=e.selection;if(o.count()>1&&"MSArtboardGroup"!=o[0].class()){for(var n=Object(u.getSourceObjectFromSelection)(o,t),i=[],c=0;c0)for(var b=0;b0&&(P=Object(d.deleteConnectionFromData)(i,P)),e.command.setValue_forKey_onLayer_forPluginIdentifier(P,"arrowConnections",m,h)}else a.a.UI.message("Please select more than two layers. Artboards are coming soon 🥳")}function x(e){C(e,1,!0)}function _(e){C(e,2,!0)}function T(e){C(e,3,!0)}function M(e){C(e,1,!1)}function D(e){C(e,2,!1)}function O(e){C(e,3,!1)}function C(e,t,r){var o=[],n=e.selection;if(P.length>0){if(3==t)if(r)o=Object(c.updateArrow)(P[i].firstObject,P[i].secondObject,P[i].style,P[i].type,P[i].direction,P[i].line,P[i].condition,i),a.a.UI.message("All arrows are updated");else for(var s=0;s Connection Arrows -> Get Free Library. Conditions are taken from the library based on their names. Make sure to name symbol as "#condition" so it will be added here'); - } else { - var symbolMaster = libraryObject.import(); - symbol = symbolMaster.createNewInstance(); - symbol = Object(_groups_js__WEBPACK_IMPORTED_MODULE_1__["addToConditionGroup"])(symbol, x, y, currentParentGroup); - } - - return symbol; -} -function updateCondition(conditionID, x, y, document, docData) { - var currentParentGroup = docData.currentPage().currentArtboard() || docData.currentPage(); - var condition = document.getLayerWithID(conditionID); - var conGroup = Object(_groups_js__WEBPACK_IMPORTED_MODULE_1__["checkForGroup"])("Conditions", currentParentGroup); - var arGroup = Object(_groups_js__WEBPACK_IMPORTED_MODULE_1__["checkForGroup"])("Arrows", currentParentGroup); - var arGroupX = arGroup != null ? arGroup.frame().x() : 0; - var arGroupY = arGroup != null ? arGroup.frame().y() : 0; - - if (conGroup) { - condition.frame.x = x - condition.frame.width / 2 - (conGroup.frame().x() - arGroupX); - condition.frame.y = y - condition.frame.height / 2 - (conGroup.frame().y() - arGroupY); - conGroup.fixGeometryWithOptions(1); - } else { - condition.frame.x = x - condition.frame.width / 2; - condition.frame.y = y - condition.frame.height / 2; - } - - return condition.id; -} -function deleteCondition(conditionID, document) { - var conditionObject = document.getLayerWithID(conditionID); - var selectedGroup; - - if (conditionObject) { - selectedGroup = conditionObject.parent; - conditionObject.remove(); - - if (selectedGroup.layers.length == 0) { - selectedGroup.remove(); - } - } -} - -/***/ }), - -/***/ "./src/utilities/data.js": +/*! exports provided: addCondition, updateCondition, deleteCondition */function(e,t,r){"use strict";r.r(t),r.d(t,"addCondition",function(){return s}),r.d(t,"updateCondition",function(){return c}),r.d(t,"deleteCondition",function(){return u});var o=r(/*! sketch */"sketch"),n=r.n(o),i=r(/*! ./groups.js */"./src/utilities/groups.js"),a=(r(/*! sketch/settings */"sketch/settings"),r(/*! sketch/ui */"sketch/ui"));function s(e,t,r,o,s){for(var c,u,d,l=n.a.getLibraries(),f=s.currentPage().currentArtboard()||s.currentPage(),h=0;h Connection Arrows -> Get Free Library. Conditions are taken from the library based on their names. Make sure to name symbol as "#condition" so it will be added here')):(d=c.import().createNewInstance(),d=Object(i.addToConditionGroup)(d,t,r,f));return d}function c(e,t,r,o,n){var a=n.currentPage().currentArtboard()||n.currentPage(),s=o.getLayerWithID(e),c=Object(i.checkForGroup)("Conditions",a),u=Object(i.checkForGroup)("Arrows",a),d=null!=u?u.frame().x():0,l=null!=u?u.frame().y():0;return c?(s.frame.x=t-s.frame.width/2-(c.frame().x()-d),s.frame.y=r-s.frame.height/2-(c.frame().y()-l),c.fixGeometryWithOptions(1)):(s.frame.x=t-s.frame.width/2,s.frame.y=r-s.frame.height/2),s.id}function u(e,t){var r,o=t.getLayerWithID(e);o&&(r=o.parent,o.remove(),0==r.layers.length&&r.remove())}},"./src/utilities/data.js": /*!*******************************!*\ !*** ./src/utilities/data.js ***! \*******************************/ -/*! exports provided: getConnectionsData, deleteConnectionFromData */ -/***/ (function(module, __webpack_exports__, __webpack_require__) { - -"use strict"; -__webpack_require__.r(__webpack_exports__); -/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "getConnectionsData", function() { return getConnectionsData; }); -/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "deleteConnectionFromData", function() { return deleteConnectionFromData; }); -/* harmony import */ var sketch__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! sketch */ "sketch"); -/* harmony import */ var sketch__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(sketch__WEBPACK_IMPORTED_MODULE_0__); - - -var UI = __webpack_require__(/*! sketch/ui */ "sketch/ui"); - -var Settings = __webpack_require__(/*! sketch/settings */ "sketch/settings"); - -var pluginKey = "flowArrows"; -function getConnectionsData(docData) { - var pluginData = context.command.valueForKey_onLayer_forPluginIdentifier("arrowConnections", docData, pluginKey); - var dataArray = []; - - if (pluginData) { - for (var i = 0; i < pluginData.length; i++) { - dataArray.push(pluginData[i]); - } - } - - return dataArray; -} -function deleteConnectionFromData(connectionIndexArray, data) { - if (data) { - for (var i = connectionIndexArray.length - 1; i >= 0; i--) { - data.splice(connectionIndexArray[i], 1); - } - } - - return data; -} - -/***/ }), - -/***/ "./src/utilities/getSourceObject.js": +/*! exports provided: getConnectionsData, deleteConnectionFromData */function(e,r,o){"use strict";o.r(r),o.d(r,"getConnectionsData",function(){return i}),o.d(r,"deleteConnectionFromData",function(){return a});o(/*! sketch */"sketch"),o(/*! sketch/ui */"sketch/ui"),o(/*! sketch/settings */"sketch/settings");var n="flowArrows";function i(e){var r=t.command.valueForKey_onLayer_forPluginIdentifier("arrowConnections",e,n),o=[];if(r)for(var i=0;i=0;r--)t.splice(e[r],1);return t}},"./src/utilities/getSourceObject.js": /*!******************************************!*\ !*** ./src/utilities/getSourceObject.js ***! \******************************************/ -/*! exports provided: getSourceObjectFromSelection */ -/***/ (function(module, __webpack_exports__, __webpack_require__) { - -"use strict"; -__webpack_require__.r(__webpack_exports__); -/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "getSourceObjectFromSelection", function() { return getSourceObjectFromSelection; }); -/* harmony import */ var sketch__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! sketch */ "sketch"); -/* harmony import */ var sketch__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(sketch__WEBPACK_IMPORTED_MODULE_0__); - -var document = sketch__WEBPACK_IMPORTED_MODULE_0___default.a.fromNative(context.document); -var docData = context.document.documentData(); -var currentParentGroup = docData.currentPage().currentArtboard() || docData.currentPage(); -function getSourceObjectFromSelection(selection, direction) { - var sourceObjectID = selection.firstObject().objectID(); - - if (direction != "Auto") { - for (var g = 0; g < selection.count(); g++) { - sourceObjectID = defineSourceObject(sourceObjectID, selection[g].objectID(), direction); - } - } - - return sourceObjectID; -} - -function defineSourceObject(firstObjectID, secondObjectID, direction) { - var firstObject = document.getLayerWithID(firstObjectID); - var secondObject = document.getLayerWithID(secondObjectID); - var firstObjectAbsPos = firstObject.frame.changeBasis({ - from: firstObject.parent, - to: currentParentGroup - }); - var secondObjectAbsPos = secondObject.frame.changeBasis({ - from: secondObject.parent, - to: currentParentGroup - }); - var sourceObjectID; - - if (direction == "Right") { - if (firstObjectAbsPos.x <= secondObjectAbsPos.x) { - // We need to get the doc position - sourceObjectID = firstObject.id; - } else { - sourceObjectID = secondObject.id; - } - } - - if (direction == "Down") { - if (firstObject.y <= secondObjectAbsPos.y) { - sourceObjectID = firstObject.id; - } else { - sourceObjectID = secondObject.id; - } - } - - if (direction == "Left") { - if (firstObjectAbsPos.x <= secondObjectAbsPos.x) { - sourceObjectID = secondObject.id; - } else { - sourceObjectID = firstObject.id; - } - } - - if (direction == "Up") { - if (firstObjectAbsPos.y <= secondObjectAbsPos.y) { - sourceObjectID = secondObject.id; - } else { - sourceObjectID = firstObject.id; - } - } - - return sourceObjectID; -} - -/***/ }), - -/***/ "./src/utilities/groups.js": +/*! exports provided: getSourceObjectFromSelection */function(e,r,o){"use strict";o.r(r),o.d(r,"getSourceObjectFromSelection",function(){return c});var n=o(/*! sketch */"sketch"),i=o.n(n).a.fromNative(t.document),a=t.document.documentData(),s=a.currentPage().currentArtboard()||a.currentPage();function c(e,t){var r=e.firstObject().objectID();if("Auto"!=t)for(var o=0;o