159a7772a3b7a0bb4d89f0559a1fcc9d.json 6.36 KB
{"ast":null,"code":"/**\r\n * @author NHN Ent. FE Development Team <dl_javascript@nhn.com>\r\n * @fileoverview Add a text object\r\n */\nimport commandFactory from '../factory/command';\nimport { Promise } from '../util';\nimport { componentNames, commandNames, rejectMessages } from '../consts';\nconst {\n  TEXT\n} = componentNames;\nconst command = {\n  name: commandNames.ADD_TEXT,\n\n  /**\r\n   * Add a text object\r\n   * @param {Graphics} graphics - Graphics instance\r\n   * @param {string} text - Initial input text\r\n   * @param {Object} [options] Options for text styles\r\n   *     @param {Object} [options.styles] Initial styles\r\n   *         @param {string} [options.styles.fill] Color\r\n   *         @param {string} [options.styles.fontFamily] Font type for text\r\n   *         @param {number} [options.styles.fontSize] Size\r\n   *         @param {string} [options.styles.fontStyle] Type of inclination (normal / italic)\r\n   *         @param {string} [options.styles.fontWeight] Type of thicker or thinner looking (normal / bold)\r\n   *         @param {string} [options.styles.textAlign] Type of text align (left / center / right)\r\n   *         @param {string} [options.styles.textDecoration] Type of line (underline / line-through / overline)\r\n   *     @param {{x: number, y: number}} [options.position] - Initial position\r\n   * @returns {Promise}\r\n   */\n  execute(graphics, text, options) {\n    const textComp = graphics.getComponent(TEXT);\n\n    if (this.undoData.object) {\n      const undoObject = this.undoData.object;\n      return new Promise((resolve, reject) => {\n        if (!graphics.contains(undoObject)) {\n          graphics.add(undoObject);\n          resolve(undoObject);\n        } else {\n          reject(rejectMessages.redo);\n        }\n      });\n    }\n\n    return textComp.add(text, options).then(objectProps => {\n      const {\n        id\n      } = objectProps;\n      const textObject = graphics.getObject(id);\n      this.undoData.object = textObject;\n      return objectProps;\n    });\n  },\n\n  /**\r\n   * @param {Graphics} graphics - Graphics instance\r\n   * @returns {Promise}\r\n   */\n  undo(graphics) {\n    graphics.remove(this.undoData.object);\n    return Promise.resolve();\n  }\n\n};\ncommandFactory.register(command);\nexport default command;","map":{"version":3,"sources":["C:/Users/kkwan_000/Desktop/git/2017110269/minsung/src/js/command/addText.js"],"names":["commandFactory","Promise","componentNames","commandNames","rejectMessages","TEXT","command","name","ADD_TEXT","execute","graphics","text","options","textComp","getComponent","undoData","object","undoObject","resolve","reject","contains","add","redo","then","objectProps","id","textObject","getObject","undo","remove","register"],"mappings":"AAAA;AACA;AACA;AACA;AACA,OAAOA,cAAP,MAA2B,oBAA3B;AACA,SAASC,OAAT,QAAwB,SAAxB;AACA,SAASC,cAAT,EAAyBC,YAAzB,EAAuCC,cAAvC,QAA6D,WAA7D;AACA,MAAM;AAAEC,EAAAA;AAAF,IAAWH,cAAjB;AAEA,MAAMI,OAAO,GAAG;AACdC,EAAAA,IAAI,EAAEJ,YAAY,CAACK,QADL;;AAGd;AACF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACEC,EAAAA,OAAO,CAACC,QAAD,EAAWC,IAAX,EAAiBC,OAAjB,EAA0B;AAC/B,UAAMC,QAAQ,GAAGH,QAAQ,CAACI,YAAT,CAAsBT,IAAtB,CAAjB;;AAEA,QAAI,KAAKU,QAAL,CAAcC,MAAlB,EAA0B;AACxB,YAAMC,UAAU,GAAG,KAAKF,QAAL,CAAcC,MAAjC;AAEA,aAAO,IAAIf,OAAJ,CAAY,CAACiB,OAAD,EAAUC,MAAV,KAAqB;AACtC,YAAI,CAACT,QAAQ,CAACU,QAAT,CAAkBH,UAAlB,CAAL,EAAoC;AAClCP,UAAAA,QAAQ,CAACW,GAAT,CAAaJ,UAAb;AACAC,UAAAA,OAAO,CAACD,UAAD,CAAP;AACD,SAHD,MAGO;AACLE,UAAAA,MAAM,CAACf,cAAc,CAACkB,IAAhB,CAAN;AACD;AACF,OAPM,CAAP;AAQD;;AAED,WAAOT,QAAQ,CAACQ,GAAT,CAAaV,IAAb,EAAmBC,OAAnB,EAA4BW,IAA5B,CAAkCC,WAAD,IAAiB;AACvD,YAAM;AAAEC,QAAAA;AAAF,UAASD,WAAf;AACA,YAAME,UAAU,GAAGhB,QAAQ,CAACiB,SAAT,CAAmBF,EAAnB,CAAnB;AAEA,WAAKV,QAAL,CAAcC,MAAd,GAAuBU,UAAvB;AAEA,aAAOF,WAAP;AACD,KAPM,CAAP;AAQD,GA3Ca;;AA4Cd;AACF;AACA;AACA;AACEI,EAAAA,IAAI,CAAClB,QAAD,EAAW;AACbA,IAAAA,QAAQ,CAACmB,MAAT,CAAgB,KAAKd,QAAL,CAAcC,MAA9B;AAEA,WAAOf,OAAO,CAACiB,OAAR,EAAP;AACD;;AApDa,CAAhB;AAuDAlB,cAAc,CAAC8B,QAAf,CAAwBxB,OAAxB;AAEA,eAAeA,OAAf","sourcesContent":["/**\r\n * @author NHN Ent. FE Development Team <dl_javascript@nhn.com>\r\n * @fileoverview Add a text object\r\n */\r\nimport commandFactory from '../factory/command';\r\nimport { Promise } from '../util';\r\nimport { componentNames, commandNames, rejectMessages } from '../consts';\r\nconst { TEXT } = componentNames;\r\n\r\nconst command = {\r\n  name: commandNames.ADD_TEXT,\r\n\r\n  /**\r\n   * Add a text object\r\n   * @param {Graphics} graphics - Graphics instance\r\n   * @param {string} text - Initial input text\r\n   * @param {Object} [options] Options for text styles\r\n   *     @param {Object} [options.styles] Initial styles\r\n   *         @param {string} [options.styles.fill] Color\r\n   *         @param {string} [options.styles.fontFamily] Font type for text\r\n   *         @param {number} [options.styles.fontSize] Size\r\n   *         @param {string} [options.styles.fontStyle] Type of inclination (normal / italic)\r\n   *         @param {string} [options.styles.fontWeight] Type of thicker or thinner looking (normal / bold)\r\n   *         @param {string} [options.styles.textAlign] Type of text align (left / center / right)\r\n   *         @param {string} [options.styles.textDecoration] Type of line (underline / line-through / overline)\r\n   *     @param {{x: number, y: number}} [options.position] - Initial position\r\n   * @returns {Promise}\r\n   */\r\n  execute(graphics, text, options) {\r\n    const textComp = graphics.getComponent(TEXT);\r\n\r\n    if (this.undoData.object) {\r\n      const undoObject = this.undoData.object;\r\n\r\n      return new Promise((resolve, reject) => {\r\n        if (!graphics.contains(undoObject)) {\r\n          graphics.add(undoObject);\r\n          resolve(undoObject);\r\n        } else {\r\n          reject(rejectMessages.redo);\r\n        }\r\n      });\r\n    }\r\n\r\n    return textComp.add(text, options).then((objectProps) => {\r\n      const { id } = objectProps;\r\n      const textObject = graphics.getObject(id);\r\n\r\n      this.undoData.object = textObject;\r\n\r\n      return objectProps;\r\n    });\r\n  },\r\n  /**\r\n   * @param {Graphics} graphics - Graphics instance\r\n   * @returns {Promise}\r\n   */\r\n  undo(graphics) {\r\n    graphics.remove(this.undoData.object);\r\n\r\n    return Promise.resolve();\r\n  },\r\n};\r\n\r\ncommandFactory.register(command);\r\n\r\nexport default command;\r\n"]},"metadata":{},"sourceType":"module"}