diff --git a/annotations.sketchplugin/Contents/Sketch/create.js b/annotations.sketchplugin/Contents/Sketch/create.js new file mode 100644 index 0000000..5f0cae0 --- /dev/null +++ b/annotations.sketchplugin/Contents/Sketch/create.js @@ -0,0 +1,184 @@ +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/commands/create.js"); +/******/ }) +/************************************************************************/ +/******/ ({ + +/***/ "./src/commands/create.js": +/*!********************************!*\ + !*** ./src/commands/create.js ***! + \********************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony import */ var _modules_createAnnotations__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../modules/createAnnotations */ "./src/modules/createAnnotations.js"); + +/* harmony default export */ __webpack_exports__["default"] = (function () { + Object(_modules_createAnnotations__WEBPACK_IMPORTED_MODULE_0__["default"])(); +}); + +/***/ }), + +/***/ "./src/modules/createAnnotations.js": +/*!******************************************!*\ + !*** ./src/modules/createAnnotations.js ***! + \******************************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +var sketch = __webpack_require__(/*! sketch/dom */ "sketch/dom"); + +var ui = __webpack_require__(/*! sketch/ui */ "sketch/ui"); // Create a group named 'Annotations' from the selected layers + + +/* harmony default export */ __webpack_exports__["default"] = (function () { + var document = sketch.getSelectedDocument(); + var layers = document.selectedLayers.layers; // Display message when no layer is selected + + if (layers.length === 0) { + ui.message("No layers selected."); + return; + } // Find to which parent the group should be attached + + + var parent = layers[0].parent; + + if (!parent) { + parent = sketch.Page.fromNative(layers[0].sketchObject.parentPage()); + } // Create the group + + + var group = new sketch.Group({ + parent: parent, + name: "Annotations", + layers: layers + }); + group.adjustToFit(); + ui.message("New 'Annotations' group created from ".concat(layers.length, " layers.")); +}); + +/***/ }), + +/***/ "sketch/dom": +/*!*****************************!*\ + !*** external "sketch/dom" ***! + \*****************************/ +/*! no static exports found */ +/***/ (function(module, exports) { + +module.exports = require("sketch/dom"); + +/***/ }), + +/***/ "sketch/ui": +/*!****************************!*\ + !*** external "sketch/ui" ***! + \****************************/ +/*! no static exports found */ +/***/ (function(module, exports) { + +module.exports = require("sketch/ui"); + +/***/ }) + +/******/ }); + if (key === 'default' && typeof exports === 'function') { + exports(context); + } else { + exports[key](context); + } +} +that['onRun'] = __skpm_run.bind(this, 'default') + +//# sourceMappingURL=create.js.map \ No newline at end of file diff --git a/annotations.sketchplugin/Contents/Sketch/create.js.map b/annotations.sketchplugin/Contents/Sketch/create.js.map new file mode 100644 index 0000000..0d080b4 --- /dev/null +++ b/annotations.sketchplugin/Contents/Sketch/create.js.map @@ -0,0 +1 @@ +{"version":3,"sources":["webpack://exports/webpack/bootstrap","webpack://exports/./src/commands/create.js","webpack://exports/./src/modules/createAnnotations.js","webpack://exports/external \"sketch/dom\"","webpack://exports/external \"sketch/ui\""],"names":["createAnnotations","sketch","require","ui","document","getSelectedDocument","layers","selectedLayers","length","message","parent","Page","fromNative","sketchObject","parentPage","group","Group","name","adjustToFit"],"mappings":";;;;;;AAAA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;;;AAGA;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,CAAd;AAKAS,OAAK,CAACG,WAAN;AAEAf,IAAE,CAACM,OAAH,gDAAmDH,MAAM,CAACE,MAA1D;AACD,C;;;;;;;;;;;AC7BD,uC;;;;;;;;;;;ACAA,sC","file":"create.js","sourcesContent":[" \t// The module cache\n \tvar installedModules = {};\n\n \t// The require function\n \tfunction __webpack_require__(moduleId) {\n\n \t\t// Check if module is in cache\n \t\tif(installedModules[moduleId]) {\n \t\t\treturn installedModules[moduleId].exports;\n \t\t}\n \t\t// Create a new module (and put it into the cache)\n \t\tvar module = installedModules[moduleId] = {\n \t\t\ti: moduleId,\n \t\t\tl: false,\n \t\t\texports: {}\n \t\t};\n\n \t\t// Execute the module function\n \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n \t\t// Flag the module as loaded\n \t\tmodule.l = true;\n\n \t\t// Return the exports of the module\n \t\treturn module.exports;\n \t}\n\n\n \t// expose the modules object (__webpack_modules__)\n \t__webpack_require__.m = modules;\n\n \t// expose the module cache\n \t__webpack_require__.c = installedModules;\n\n \t// define getter function for harmony exports\n \t__webpack_require__.d = function(exports, name, getter) {\n \t\tif(!__webpack_require__.o(exports, name)) {\n \t\t\tObject.defineProperty(exports, name, { enumerable: true, get: getter });\n \t\t}\n \t};\n\n \t// define __esModule on exports\n \t__webpack_require__.r = function(exports) {\n \t\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n \t\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n \t\t}\n \t\tObject.defineProperty(exports, '__esModule', { value: true });\n \t};\n\n \t// create a fake namespace object\n \t// mode & 1: value is a module id, require it\n \t// mode & 2: merge all properties of value into the ns\n \t// mode & 4: return value when already ns object\n \t// mode & 8|1: behave like require\n \t__webpack_require__.t = function(value, mode) {\n \t\tif(mode & 1) value = __webpack_require__(value);\n \t\tif(mode & 8) return value;\n \t\tif((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;\n \t\tvar ns = Object.create(null);\n \t\t__webpack_require__.r(ns);\n \t\tObject.defineProperty(ns, 'default', { enumerable: true, value: value });\n \t\tif(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));\n \t\treturn ns;\n \t};\n\n \t// getDefaultExport function for compatibility with non-harmony modules\n \t__webpack_require__.n = function(module) {\n \t\tvar getter = module && module.__esModule ?\n \t\t\tfunction getDefault() { return module['default']; } :\n \t\t\tfunction getModuleExports() { return module; };\n \t\t__webpack_require__.d(getter, 'a', getter);\n \t\treturn getter;\n \t};\n\n \t// Object.prototype.hasOwnProperty.call\n \t__webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };\n\n \t// __webpack_public_path__\n \t__webpack_require__.p = \"\";\n\n\n \t// Load entry module and return exports\n \treturn __webpack_require__(__webpack_require__.s = \"./src/commands/create.js\");\n","import createAnnotations from \"../modules/createAnnotations\";\n\nexport default function() {\n createAnnotations();\n}\n","const sketch = require(\"sketch/dom\");\nconst ui = require(\"sketch/ui\");\n\n// Create a group named 'Annotations' from the selected layers\nexport default function() {\n const document = sketch.getSelectedDocument();\n const layers = document.selectedLayers.layers;\n\n // Display message when no layer is selected\n if (layers.length === 0) {\n ui.message(`No layers selected.`);\n return;\n }\n\n // Find to which parent the group should be attached\n let parent = layers[0].parent;\n if (!parent) {\n parent = sketch.Page.fromNative(layers[0].sketchObject.parentPage());\n }\n\n // Create the group\n const group = new sketch.Group({\n parent: parent,\n name: \"Annotations\",\n layers: layers\n });\n group.adjustToFit();\n\n ui.message(`New 'Annotations' group created from ${layers.length} layers.`);\n}\n","module.exports = require(\"sketch/dom\");","module.exports = require(\"sketch/ui\");"],"sourceRoot":""} \ No newline at end of file diff --git a/annotations.sketchplugin/Contents/Sketch/manifest.json b/annotations.sketchplugin/Contents/Sketch/manifest.json index f0569c5..ccb426f 100644 --- a/annotations.sketchplugin/Contents/Sketch/manifest.json +++ b/annotations.sketchplugin/Contents/Sketch/manifest.json @@ -12,13 +12,20 @@ "name": "Show", "identifier": "show", "script": "show.js" + }, + { + "name": "Create 'Annotations' group from selection", + "identifier": "create", + "script": "create.js" } ], "menu": { "title": "Annotations", "items": [ "hide", - "show" + "show", + "-", + "create" ] }, "version": "0.3.0", diff --git a/src/commands/create.js b/src/commands/create.js new file mode 100644 index 0000000..544a24c --- /dev/null +++ b/src/commands/create.js @@ -0,0 +1,5 @@ +import createAnnotations from "../modules/createAnnotations"; + +export default function() { + createAnnotations(); +} diff --git a/src/manifest.json b/src/manifest.json index a074e2b..97700f0 100644 --- a/src/manifest.json +++ b/src/manifest.json @@ -12,13 +12,20 @@ "name": "Show", "identifier": "show", "script": "./commands/show.js" + }, + { + "name": "Create 'Annotations' group from selection", + "identifier": "create", + "script": "./commands/create.js" } ], "menu": { "title": "Annotations", "items": [ "hide", - "show" + "show", + "-", + "create" ] } } \ No newline at end of file diff --git a/src/modules/createAnnotations.js b/src/modules/createAnnotations.js new file mode 100644 index 0000000..4d19d46 --- /dev/null +++ b/src/modules/createAnnotations.js @@ -0,0 +1,30 @@ +const sketch = require("sketch/dom"); +const ui = require("sketch/ui"); + +// Create a group named 'Annotations' from the selected layers +export default function() { + const document = sketch.getSelectedDocument(); + const layers = document.selectedLayers.layers; + + // Display message when no layer is selected + if (layers.length === 0) { + ui.message(`No layers selected.`); + return; + } + + // Find to which parent the group should be attached + let parent = layers[0].parent; + if (!parent) { + parent = sketch.Page.fromNative(layers[0].sketchObject.parentPage()); + } + + // Create the group + const group = new sketch.Group({ + parent: parent, + name: "Annotations", + layers: layers + }); + group.adjustToFit(); + + ui.message(`New 'Annotations' group created from ${layers.length} layers.`); +}