4148903520d723b7896cf11e168ccbd8.json 7.4 KB
{"ast":null,"code":"/**\r\n * @author NHN Ent. FE Development Team <dl_javascript@nhn.com>\r\n * @fileoverview Change text styles\r\n */\nimport snippet from 'tui-code-snippet';\nimport commandFactory from '../factory/command';\nimport { Promise } from '../util';\nimport { componentNames, rejectMessages, commandNames } from '../consts';\nconst {\n  TEXT\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} styles - text styles\r\n * @param {Component} targetObj - text component\r\n * @returns {object} - undo data\r\n */\n\nfunction makeUndoData(styles, targetObj) {\n  const undoData = {\n    object: targetObj,\n    styles: {}\n  };\n  snippet.forEachOwnProperties(styles, (value, key) => {\n    const undoValue = targetObj[key];\n    undoData.styles[key] = undoValue;\n  });\n  return undoData;\n}\n\nconst command = {\n  name: commandNames.CHANGE_TEXT_STYLE,\n\n  /**\r\n   * Change text styles\r\n   * @param {Graphics} graphics - Graphics instance\r\n   * @param {number} id - object id\r\n   * @param {Object} styles - text styles\r\n   *     @param {string} [styles.fill] Color\r\n   *     @param {string} [styles.fontFamily] Font type for text\r\n   *     @param {number} [styles.fontSize] Size\r\n   *     @param {string} [styles.fontStyle] Type of inclination (normal / italic)\r\n   *     @param {string} [styles.fontWeight] Type of thicker or thinner looking (normal / bold)\r\n   *     @param {string} [styles.textAlign] Type of text align (left / center / right)\r\n   *     @param {string} [styles.textDecoration] Type of line (underline / line-through / overline)\r\n   * @param {boolean} isSilent - is silent execution or not\r\n   * @returns {Promise}\r\n   */\n  execute(graphics, id, styles, isSilent) {\n    const textComp = graphics.getComponent(TEXT);\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(styles, targetObj);\n      chchedUndoDataForSilent = this.setUndoData(undoData, chchedUndoDataForSilent, isSilent);\n    }\n\n    return textComp.setStyle(targetObj, styles);\n  },\n\n  /**\r\n   * @param {Graphics} graphics - Graphics instance\r\n   * @returns {Promise}\r\n   */\n  undo(graphics) {\n    const textComp = graphics.getComponent(TEXT);\n    const {\n      object: textObj,\n      styles\n    } = this.undoData;\n    return textComp.setStyle(textObj, styles);\n  }\n\n};\ncommandFactory.register(command);\nexport default command;","map":{"version":3,"sources":["C:/Users/kkwan_000/Desktop/git/2017110269/minsung/src/js/command/changeTextStyle.js"],"names":["snippet","commandFactory","Promise","componentNames","rejectMessages","commandNames","TEXT","chchedUndoDataForSilent","makeUndoData","styles","targetObj","undoData","object","forEachOwnProperties","value","key","undoValue","command","name","CHANGE_TEXT_STYLE","execute","graphics","id","isSilent","textComp","getComponent","getObject","reject","noObject","isRedo","setUndoData","setStyle","undo","textObj","register"],"mappings":"AAAA;AACA;AACA;AACA;AACA,OAAOA,OAAP,MAAoB,kBAApB;AACA,OAAOC,cAAP,MAA2B,oBAA3B;AACA,SAASC,OAAT,QAAwB,SAAxB;AACA,SAASC,cAAT,EAAyBC,cAAzB,EAAyCC,YAAzC,QAA6D,WAA7D;AAEA,MAAM;AAAEC,EAAAA;AAAF,IAAWH,cAAjB;AAEA;AACA;AACA;AACA;;AACA,IAAII,uBAAuB,GAAG,IAA9B;AAEA;AACA;AACA;AACA;AACA;AACA;;AACA,SAASC,YAAT,CAAsBC,MAAtB,EAA8BC,SAA9B,EAAyC;AACvC,QAAMC,QAAQ,GAAG;AACfC,IAAAA,MAAM,EAAEF,SADO;AAEfD,IAAAA,MAAM,EAAE;AAFO,GAAjB;AAIAT,EAAAA,OAAO,CAACa,oBAAR,CAA6BJ,MAA7B,EAAqC,CAACK,KAAD,EAAQC,GAAR,KAAgB;AACnD,UAAMC,SAAS,GAAGN,SAAS,CAACK,GAAD,CAA3B;AACAJ,IAAAA,QAAQ,CAACF,MAAT,CAAgBM,GAAhB,IAAuBC,SAAvB;AACD,GAHD;AAKA,SAAOL,QAAP;AACD;;AAED,MAAMM,OAAO,GAAG;AACdC,EAAAA,IAAI,EAAEb,YAAY,CAACc,iBADL;;AAGd;AACF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACEC,EAAAA,OAAO,CAACC,QAAD,EAAWC,EAAX,EAAeb,MAAf,EAAuBc,QAAvB,EAAiC;AACtC,UAAMC,QAAQ,GAAGH,QAAQ,CAACI,YAAT,CAAsBnB,IAAtB,CAAjB;AACA,UAAMI,SAAS,GAAGW,QAAQ,CAACK,SAAT,CAAmBJ,EAAnB,CAAlB;;AAEA,QAAI,CAACZ,SAAL,EAAgB;AACd,aAAOR,OAAO,CAACyB,MAAR,CAAevB,cAAc,CAACwB,QAA9B,CAAP;AACD;;AACD,QAAI,CAAC,KAAKC,MAAV,EAAkB;AAChB,YAAMlB,QAAQ,GAAGH,YAAY,CAACC,MAAD,EAASC,SAAT,CAA7B;AAEAH,MAAAA,uBAAuB,GAAG,KAAKuB,WAAL,CAAiBnB,QAAjB,EAA2BJ,uBAA3B,EAAoDgB,QAApD,CAA1B;AACD;;AAED,WAAOC,QAAQ,CAACO,QAAT,CAAkBrB,SAAlB,EAA6BD,MAA7B,CAAP;AACD,GAhCa;;AAiCd;AACF;AACA;AACA;AACEuB,EAAAA,IAAI,CAACX,QAAD,EAAW;AACb,UAAMG,QAAQ,GAAGH,QAAQ,CAACI,YAAT,CAAsBnB,IAAtB,CAAjB;AACA,UAAM;AAAEM,MAAAA,MAAM,EAAEqB,OAAV;AAAmBxB,MAAAA;AAAnB,QAA8B,KAAKE,QAAzC;AAEA,WAAOa,QAAQ,CAACO,QAAT,CAAkBE,OAAlB,EAA2BxB,MAA3B,CAAP;AACD;;AA1Ca,CAAhB;AA6CAR,cAAc,CAACiC,QAAf,CAAwBjB,OAAxB;AAEA,eAAeA,OAAf","sourcesContent":["/**\r\n * @author NHN Ent. FE Development Team <dl_javascript@nhn.com>\r\n * @fileoverview Change text styles\r\n */\r\nimport snippet from 'tui-code-snippet';\r\nimport commandFactory from '../factory/command';\r\nimport { Promise } from '../util';\r\nimport { componentNames, rejectMessages, commandNames } from '../consts';\r\n\r\nconst { TEXT } = 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} styles - text styles\r\n * @param {Component} targetObj - text component\r\n * @returns {object} - undo data\r\n */\r\nfunction makeUndoData(styles, targetObj) {\r\n  const undoData = {\r\n    object: targetObj,\r\n    styles: {},\r\n  };\r\n  snippet.forEachOwnProperties(styles, (value, key) => {\r\n    const undoValue = targetObj[key];\r\n    undoData.styles[key] = undoValue;\r\n  });\r\n\r\n  return undoData;\r\n}\r\n\r\nconst command = {\r\n  name: commandNames.CHANGE_TEXT_STYLE,\r\n\r\n  /**\r\n   * Change text styles\r\n   * @param {Graphics} graphics - Graphics instance\r\n   * @param {number} id - object id\r\n   * @param {Object} styles - text styles\r\n   *     @param {string} [styles.fill] Color\r\n   *     @param {string} [styles.fontFamily] Font type for text\r\n   *     @param {number} [styles.fontSize] Size\r\n   *     @param {string} [styles.fontStyle] Type of inclination (normal / italic)\r\n   *     @param {string} [styles.fontWeight] Type of thicker or thinner looking (normal / bold)\r\n   *     @param {string} [styles.textAlign] Type of text align (left / center / right)\r\n   *     @param {string} [styles.textDecoration] Type of line (underline / line-through / overline)\r\n   * @param {boolean} isSilent - is silent execution or not\r\n   * @returns {Promise}\r\n   */\r\n  execute(graphics, id, styles, isSilent) {\r\n    const textComp = graphics.getComponent(TEXT);\r\n    const targetObj = graphics.getObject(id);\r\n\r\n    if (!targetObj) {\r\n      return Promise.reject(rejectMessages.noObject);\r\n    }\r\n    if (!this.isRedo) {\r\n      const undoData = makeUndoData(styles, targetObj);\r\n\r\n      chchedUndoDataForSilent = this.setUndoData(undoData, chchedUndoDataForSilent, isSilent);\r\n    }\r\n\r\n    return textComp.setStyle(targetObj, styles);\r\n  },\r\n  /**\r\n   * @param {Graphics} graphics - Graphics instance\r\n   * @returns {Promise}\r\n   */\r\n  undo(graphics) {\r\n    const textComp = graphics.getComponent(TEXT);\r\n    const { object: textObj, styles } = this.undoData;\r\n\r\n    return textComp.setStyle(textObj, styles);\r\n  },\r\n};\r\n\r\ncommandFactory.register(command);\r\n\r\nexport default command;\r\n"]},"metadata":{},"sourceType":"module"}