b4bf7f08ce3c90c7ad0f066fc93d4514.json 8.01 KB
{"ast":null,"code":"/**\r\n * @author NHN Ent. FE Development Team <dl_javascript@nhn.com>\r\n * @fileoverview change a shape\r\n */\nimport snippet from 'tui-code-snippet';\nimport { Promise } from '../util';\nimport commandFactory from '../factory/command';\nimport { componentNames, rejectMessages, commandNames } from '../consts';\nconst {\n  SHAPE\n} = componentNames;\n/**\r\n * Chched data for undo\r\n * @type {Object}\r\n */\n\nlet chchedUndoDataForSilent = null;\n/**\r\n * Make undoData\r\n * @param {object} options - shape options\r\n * @param {Component} targetObj - shape component\r\n * @returns {object} - undo data\r\n */\n\nfunction makeUndoData(options, targetObj) {\n  const undoData = {\n    object: targetObj,\n    options: {}\n  };\n  snippet.forEachOwnProperties(options, (value, key) => {\n    undoData.options[key] = targetObj[key];\n  });\n  return undoData;\n}\n\nconst command = {\n  name: commandNames.CHANGE_SHAPE,\n\n  /**\r\n   * Change a shape\r\n   * @param {Graphics} graphics - Graphics instance\r\n   * @param {number} id - object id\r\n   * @param {Object} options - Shape options\r\n   *      @param {string} [options.fill] - Shape foreground color (ex: '#fff', 'transparent')\r\n   *      @param {string} [options.stroke] - Shape outline color\r\n   *      @param {number} [options.strokeWidth] - Shape outline width\r\n   *      @param {number} [options.width] - Width value (When type option is 'rect', this options can use)\r\n   *      @param {number} [options.height] - Height value (When type option is 'rect', this options can use)\r\n   *      @param {number} [options.rx] - Radius x value (When type option is 'circle', this options can use)\r\n   *      @param {number} [options.ry] - Radius y value (When type option is 'circle', this options can use)\r\n   *      @param {number} [options.left] - Shape x position\r\n   *      @param {number} [options.top] - Shape y position\r\n   *      @param {number} [options.isRegular] - Whether resizing shape has 1:1 ratio or not\r\n   * @param {boolean} isSilent - is silent execution or not\r\n   * @returns {Promise}\r\n   */\n  execute(graphics, id, options, isSilent) {\n    const shapeComp = graphics.getComponent(SHAPE);\n    const targetObj = graphics.getObject(id);\n\n    if (!targetObj) {\n      return Promise.reject(rejectMessages.noObject);\n    }\n\n    if (!this.isRedo) {\n      const undoData = makeUndoData(options, targetObj);\n      chchedUndoDataForSilent = this.setUndoData(undoData, chchedUndoDataForSilent, isSilent);\n    }\n\n    return shapeComp.change(targetObj, options);\n  },\n\n  /**\r\n   * @param {Graphics} graphics - Graphics instance\r\n   * @returns {Promise}\r\n   */\n  undo(graphics) {\n    const shapeComp = graphics.getComponent(SHAPE);\n    const {\n      object: shape,\n      options\n    } = this.undoData;\n    return shapeComp.change(shape, options);\n  }\n\n};\ncommandFactory.register(command);\nexport default command;","map":{"version":3,"sources":["C:/Users/kkwan_000/Desktop/git/2017110269/minsung/src/js/command/changeShape.js"],"names":["snippet","Promise","commandFactory","componentNames","rejectMessages","commandNames","SHAPE","chchedUndoDataForSilent","makeUndoData","options","targetObj","undoData","object","forEachOwnProperties","value","key","command","name","CHANGE_SHAPE","execute","graphics","id","isSilent","shapeComp","getComponent","getObject","reject","noObject","isRedo","setUndoData","change","undo","shape","register"],"mappings":"AAAA;AACA;AACA;AACA;AACA,OAAOA,OAAP,MAAoB,kBAApB;AACA,SAASC,OAAT,QAAwB,SAAxB;AACA,OAAOC,cAAP,MAA2B,oBAA3B;AACA,SAASC,cAAT,EAAyBC,cAAzB,EAAyCC,YAAzC,QAA6D,WAA7D;AAEA,MAAM;AAAEC,EAAAA;AAAF,IAAYH,cAAlB;AAEA;AACA;AACA;AACA;;AACA,IAAII,uBAAuB,GAAG,IAA9B;AAEA;AACA;AACA;AACA;AACA;AACA;;AACA,SAASC,YAAT,CAAsBC,OAAtB,EAA+BC,SAA/B,EAA0C;AACxC,QAAMC,QAAQ,GAAG;AACfC,IAAAA,MAAM,EAAEF,SADO;AAEfD,IAAAA,OAAO,EAAE;AAFM,GAAjB;AAKAT,EAAAA,OAAO,CAACa,oBAAR,CAA6BJ,OAA7B,EAAsC,CAACK,KAAD,EAAQC,GAAR,KAAgB;AACpDJ,IAAAA,QAAQ,CAACF,OAAT,CAAiBM,GAAjB,IAAwBL,SAAS,CAACK,GAAD,C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_javascript@nhn.com>\r\n * @fileoverview change a shape\r\n */\r\nimport snippet from 'tui-code-snippet';\r\nimport { Promise } from '../util';\r\nimport commandFactory from '../factory/command';\r\nimport { componentNames, rejectMessages, commandNames } from '../consts';\r\n\r\nconst { SHAPE } = componentNames;\r\n\r\n/**\r\n * Chched data for undo\r\n * @type {Object}\r\n */\r\nlet chchedUndoDataForSilent = null;\r\n\r\n/**\r\n * Make undoData\r\n * @param {object} options - shape options\r\n * @param {Component} targetObj - shape component\r\n * @returns {object} - undo data\r\n */\r\nfunction makeUndoData(options, targetObj) {\r\n  const undoData = {\r\n    object: targetObj,\r\n    options: {},\r\n  };\r\n\r\n  snippet.forEachOwnProperties(options, (value, key) => {\r\n    undoData.options[key] = targetObj[key];\r\n  });\r\n\r\n  return undoData;\r\n}\r\n\r\nconst command = {\r\n  name: commandNames.CHANGE_SHAPE,\r\n\r\n  /**\r\n   * Change a shape\r\n   * @param {Graphics} graphics - Graphics instance\r\n   * @param {number} id - object id\r\n   * @param {Object} options - Shape options\r\n   *      @param {string} [options.fill] - Shape foreground color (ex: '#fff', 'transparent')\r\n   *      @param {string} [options.stroke] - Shape outline color\r\n   *      @param {number} [options.strokeWidth] - Shape outline width\r\n   *      @param {number} [options.width] - Width value (When type option is 'rect', this options can use)\r\n   *      @param {number} [options.height] - Height value (When type option is 'rect', this options can use)\r\n   *      @param {number} [options.rx] - Radius x value (When type option is 'circle', this options can use)\r\n   *      @param {number} [options.ry] - Radius y value (When type option is 'circle', this options can use)\r\n   *      @param {number} [options.left] - Shape x position\r\n   *      @param {number} [options.top] - Shape y position\r\n   *      @param {number} [options.isRegular] - Whether resizing shape has 1:1 ratio or not\r\n   * @param {boolean} isSilent - is silent execution or not\r\n   * @returns {Promise}\r\n   */\r\n  execute(graphics, id, options, isSilent) {\r\n    const shapeComp = graphics.getComponent(SHAPE);\r\n    const targetObj = graphics.getObject(id);\r\n\r\n    if (!targetObj) {\r\n      return Promise.reject(rejectMessages.noObject);\r\n    }\r\n\r\n    if (!this.isRedo) {\r\n      const undoData = makeUndoData(options, targetObj);\r\n\r\n      chchedUndoDataForSilent = this.setUndoData(undoData, chchedUndoDataForSilent, isSilent);\r\n    }\r\n\r\n    return shapeComp.change(targetObj, options);\r\n  },\r\n  /**\r\n   * @param {Graphics} graphics - Graphics instance\r\n   * @returns {Promise}\r\n   */\r\n  undo(graphics) {\r\n    const shapeComp = graphics.getComponent(SHAPE);\r\n    const { object: shape, options } = this.undoData;\r\n\r\n    return shapeComp.change(shape, options);\r\n  },\r\n};\r\n\r\ncommandFactory.register(command);\r\n\r\nexport default command;\r\n"]},"metadata":{},"sourceType":"module"}