9541058d983883682dbee8ff11652de3.json
13.4 KB
{"ast":null,"code":"import snippet from 'tui-code-snippet';\nimport Colorpicker from './tools/colorpicker';\nimport Submenu from './submenuBase';\nimport templateHtml from './template/submenu/icon';\nimport { isSupportFileApi, assignmentForDestroy } from '../util';\nimport { defaultIconPath } from '../consts';\n/**\r\n * Icon ui class\r\n * @class\r\n * @ignore\r\n */\n\nclass Icon extends Submenu {\n constructor(subMenuElement, {\n locale,\n makeSvgIcon,\n menuBarPosition,\n usageStatistics\n }) {\n super(subMenuElement, {\n locale,\n name: 'icon',\n makeSvgIcon,\n menuBarPosition,\n templateHtml,\n usageStatistics\n });\n this.iconType = null;\n this._iconMap = {};\n this._els = {\n registrIconButton: this.selector('.tie-icon-image-file'),\n addIconButton: this.selector('.tie-icon-add-button'),\n iconColorpicker: new Colorpicker(this.selector('.tie-icon-color'), '#ffbb3b', this.toggleDirection, this.usageStatistics)\n };\n }\n /**\r\n * Destroys the instance.\r\n */\n\n\n destroy() {\n this._removeEvent();\n\n this._els.iconColorpicker.destroy();\n\n assignmentForDestroy(this);\n }\n /**\r\n * Add event for icon\r\n * @param {Object} actions - actions for icon\r\n * @param {Function} actions.registCustomIcon - register icon\r\n * @param {Function} actions.addIcon - add icon\r\n * @param {Function} actions.changeColor - change icon color\r\n */\n\n\n addEvent(actions) {\n const registerIcon = this._registerIconHandler.bind(this);\n\n const addIcon = this._addIconHandler.bind(this);\n\n this.eventHandler = {\n registerIcon,\n addIcon\n };\n this.actions = actions;\n\n this._els.iconColorpicker.on('change', this._changeColorHandler.bind(this));\n\n this._els.registrIconButton.addEventListener('change', registerIcon);\n\n this._els.addIconButton.addEventListener('click', addIcon);\n }\n /**\r\n * Remove event\r\n * @private\r\n */\n\n\n _removeEvent() {\n this._els.iconColorpicker.off();\n\n this._els.registrIconButton.removeEventListener('change', this.eventHandler.registerIcon);\n\n this._els.addIconButton.removeEventListener('click', this.eventHandler.addIcon);\n }\n /**\r\n * Clear icon type\r\n */\n\n\n clearIconType() {\n this._els.addIconButton.classList.remove(this.iconType);\n\n this.iconType = null;\n }\n /**\r\n * Register default icon\r\n */\n\n\n registDefaultIcon() {\n snippet.forEach(defaultIconPath, (path, type) => {\n this.actions.registDefalutIcons(type, path);\n });\n }\n /**\r\n * Set icon picker color\r\n * @param {string} iconColor - rgb color string\r\n */\n\n\n setIconPickerColor(iconColor) {\n this._els.iconColorpicker.color = iconColor;\n }\n /**\r\n * Returns the menu to its default state.\r\n */\n\n\n changeStandbyMode() {\n this.clearIconType();\n this.actions.cancelAddIcon();\n }\n /**\r\n * Change icon color\r\n * @param {string} color - color for change\r\n * @private\r\n */\n\n\n _changeColorHandler(color) {\n color = color || 'transparent';\n this.actions.changeColor(color);\n }\n /**\r\n * Change icon color\r\n * @param {object} event - add button event object\r\n * @private\r\n */\n\n\n _addIconHandler(event) {\n const button = event.target.closest('.tui-image-editor-button');\n\n if (button) {\n const iconType = button.getAttribute('data-icontype');\n const iconColor = this._els.iconColorpicker.color;\n this.actions.discardSelection();\n this.actions.changeSelectableAll(false);\n\n this._els.addIconButton.classList.remove(this.iconType);\n\n this._els.addIconButton.classList.add(iconType);\n\n if (this.iconType === iconType) {\n this.changeStandbyMode();\n } else {\n this.actions.addIcon(iconType, iconColor);\n this.iconType = iconType;\n }\n }\n }\n /**\r\n * register icon\r\n * @param {object} event - file change event object\r\n * @private\r\n */\n\n\n _registerIconHandler(event) {\n let imgUrl;\n\n if (!isSupportFileApi) {\n alert('This browser does not support file-api');\n }\n\n const [file] = event.target.files;\n\n if (file) {\n imgUrl = URL.createObjectURL(file);\n this.actions.registCustomIcon(imgUrl, file);\n }\n }\n\n}\n\nexport default Icon;","map":{"version":3,"sources":["C:/Users/kkwan_000/Desktop/git/2017110269/minsung/src/js/ui/icon.js"],"names":["snippet","Colorpicker","Submenu","templateHtml","isSupportFileApi","assignmentForDestroy","defaultIconPath","Icon","constructor","subMenuElement","locale","makeSvgIcon","menuBarPosition","usageStatistics","name","iconType","_iconMap","_els","registrIconButton","selector","addIconButton","iconColorpicker","toggleDirection","destroy","_removeEvent","addEvent","actions","registerIcon","_registerIconHandler","bind","addIcon","_addIconHandler","eventHandler","on","_changeColorHandler","addEventListener","off","removeEventListener","clearIconType","classList","remove","registDefaultIcon","forEach","path","type","registDefalutIcons","setIconPickerColor","iconColor","color","changeStandbyMode","cancelAddIcon","changeColor","event","button","target","closest","getAttribute","discardSelection","changeSelectableAll","add","imgUrl","alert","file","files","URL","createObjectURL","registCustomIcon"],"mappings":"AAAA,OAAOA,OAAP,MAAoB,kBAApB;AACA,OAAOC,WAAP,MAAwB,qBAAxB;AACA,OAAOC,OAAP,MAAoB,eAApB;AACA,OAAOC,YAAP,MAAyB,yBAAzB;AACA,SAASC,gBAAT,EAA2BC,oBAA3B,QAAuD,SAAvD;AACA,SAASC,eAAT,QAAgC,WAAhC;AAEA;AACA;AACA;AACA;AACA;;AACA,MAAMC,IAAN,SAAmBL,OAAnB,CAA2B;AACzBM,EAAAA,WAAW,CAACC,cAAD,EAAiB;AAAEC,IAAAA,MAAF;AAAUC,IAAAA,WAAV;AAAuBC,IAAAA,eAAvB;AAAwCC,IAAAA;AAAxC,GAAjB,EAA4E;AACrF,UAAMJ,cAAN,EAAsB;AACpBC,MAAAA,MADoB;AAEpBI,MAAAA,IAAI,EAAE,MAFc;AAGpBH,MAAAA,WAHoB;AAIpBC,MAAAA,eAJoB;AAKpBT,MAAAA,YALoB;AAMpBU,MAAAA;AANoB,KAAtB;AASA,SAAKE,QAAL,GAAgB,IAAhB;AACA,SAAKC,QAAL,GAAgB,EAAhB;AAEA,SAAKC,IAAL,GAAY;AACVC,MAAAA,iBAAiB,EAAE,KAAKC,QAAL,CAAc,sBAAd,CADT;AAEVC,MAAAA,aAAa,EAAE,KAAKD,QAAL,CAAc,sBAAd,CAFL;AAGVE,MAAAA,eAAe,EAAE,IAAIpB,WAAJ,CACf,KAAKkB,QAAL,CAAc,iBAAd,CADe,EAEf,SAFe,EAGf,KAAKG,eAHU,EAIf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AsC5C,QAAtC;;AAEA,UAAI,KAAKA,QAAL,KAAkBA,QAAtB,EAAgC;AAC9B,aAAKkC,iBAAL;AACD,OAFD,MAEO;AACL,aAAKvB,OAAL,CAAaI,OAAb,CAAqBf,QAArB,EAA+BgC,SAA/B;AACA,aAAKhC,QAAL,GAAgBA,QAAhB;AACD;AACF;AACF;AAED;AACF;AACA;AACA;AACA;;;AACEa,EAAAA,oBAAoB,CAACwB,KAAD,EAAQ;AAC1B,QAAIQ,MAAJ;;AAEA,QAAI,CAACxD,gBAAL,EAAuB;AACrByD,MAAAA,KAAK,CAAC,wCAAD,CAAL;AACD;;AAED,UAAM,CAACC,IAAD,IAASV,KAAK,CAACE,MAAN,CAAaS,KAA5B;;AAEA,QAAID,IAAJ,EAAU;AACRF,MAAAA,MAAM,GAAGI,GAAG,CAACC,eAAJ,CAAoBH,IAApB,CAAT;AACA,WAAKpC,OAAL,CAAawC,gBAAb,CAA8BN,MAA9B,EAAsCE,IAAtC;AACD;AACF;;AA1JwB;;AA6J3B,eAAevD,IAAf","sourcesContent":["import snippet from 'tui-code-snippet';\r\nimport Colorpicker from './tools/colorpicker';\r\nimport Submenu from './submenuBase';\r\nimport templateHtml from './template/submenu/icon';\r\nimport { isSupportFileApi, assignmentForDestroy } from '../util';\r\nimport { defaultIconPath } from '../consts';\r\n\r\n/**\r\n * Icon ui class\r\n * @class\r\n * @ignore\r\n */\r\nclass Icon extends Submenu {\r\n constructor(subMenuElement, { locale, makeSvgIcon, menuBarPosition, usageStatistics }) {\r\n super(subMenuElement, {\r\n locale,\r\n name: 'icon',\r\n makeSvgIcon,\r\n menuBarPosition,\r\n templateHtml,\r\n usageStatistics,\r\n });\r\n\r\n this.iconType = null;\r\n this._iconMap = {};\r\n\r\n this._els = {\r\n registrIconButton: this.selector('.tie-icon-image-file'),\r\n addIconButton: this.selector('.tie-icon-add-button'),\r\n iconColorpicker: new Colorpicker(\r\n this.selector('.tie-icon-color'),\r\n '#ffbb3b',\r\n this.toggleDirection,\r\n this.usageStatistics\r\n ),\r\n };\r\n }\r\n\r\n /**\r\n * Destroys the instance.\r\n */\r\n destroy() {\r\n this._removeEvent();\r\n this._els.iconColorpicker.destroy();\r\n\r\n assignmentForDestroy(this);\r\n }\r\n\r\n /**\r\n * Add event for icon\r\n * @param {Object} actions - actions for icon\r\n * @param {Function} actions.registCustomIcon - register icon\r\n * @param {Function} actions.addIcon - add icon\r\n * @param {Function} actions.changeColor - change icon color\r\n */\r\n addEvent(actions) {\r\n const registerIcon = this._registerIconHandler.bind(this);\r\n const addIcon = this._addIconHandler.bind(this);\r\n\r\n this.eventHandler = {\r\n registerIcon,\r\n addIcon,\r\n };\r\n\r\n this.actions = actions;\r\n this._els.iconColorpicker.on('change', this._changeColorHandler.bind(this));\r\n this._els.registrIconButton.addEventListener('change', registerIcon);\r\n this._els.addIconButton.addEventListener('click', addIcon);\r\n }\r\n\r\n /**\r\n * Remove event\r\n * @private\r\n */\r\n _removeEvent() {\r\n this._els.iconColorpicker.off();\r\n this._els.registrIconButton.removeEventListener('change', this.eventHandler.registerIcon);\r\n this._els.addIconButton.removeEventListener('click', this.eventHandler.addIcon);\r\n }\r\n\r\n /**\r\n * Clear icon type\r\n */\r\n clearIconType() {\r\n this._els.addIconButton.classList.remove(this.iconType);\r\n this.iconType = null;\r\n }\r\n\r\n /**\r\n * Register default icon\r\n */\r\n registDefaultIcon() {\r\n snippet.forEach(defaultIconPath, (path, type) => {\r\n this.actions.registDefalutIcons(type, path);\r\n });\r\n }\r\n\r\n /**\r\n * Set icon picker color\r\n * @param {string} iconColor - rgb color string\r\n */\r\n setIconPickerColor(iconColor) {\r\n this._els.iconColorpicker.color = iconColor;\r\n }\r\n\r\n /**\r\n * Returns the menu to its default state.\r\n */\r\n changeStandbyMode() {\r\n this.clearIconType();\r\n this.actions.cancelAddIcon();\r\n }\r\n\r\n /**\r\n * Change icon color\r\n * @param {string} color - color for change\r\n * @private\r\n */\r\n _changeColorHandler(color) {\r\n color = color || 'transparent';\r\n this.actions.changeColor(color);\r\n }\r\n\r\n /**\r\n * Change icon color\r\n * @param {object} event - add button event object\r\n * @private\r\n */\r\n _addIconHandler(event) {\r\n const button = event.target.closest('.tui-image-editor-button');\r\n\r\n if (button) {\r\n const iconType = button.getAttribute('data-icontype');\r\n const iconColor = this._els.iconColorpicker.color;\r\n this.actions.discardSelection();\r\n this.actions.changeSelectableAll(false);\r\n this._els.addIconButton.classList.remove(this.iconType);\r\n this._els.addIconButton.classList.add(iconType);\r\n\r\n if (this.iconType === iconType) {\r\n this.changeStandbyMode();\r\n } else {\r\n this.actions.addIcon(iconType, iconColor);\r\n this.iconType = iconType;\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * register icon\r\n * @param {object} event - file change event object\r\n * @private\r\n */\r\n _registerIconHandler(event) {\r\n let imgUrl;\r\n\r\n if (!isSupportFileApi) {\r\n alert('This browser does not support file-api');\r\n }\r\n\r\n const [file] = event.target.files;\r\n\r\n if (file) {\r\n imgUrl = URL.createObjectURL(file);\r\n this.actions.registCustomIcon(imgUrl, file);\r\n }\r\n }\r\n}\r\n\r\nexport default Icon;\r\n"]},"metadata":{},"sourceType":"module"}