diff --git a/amd/build/commands.min.js b/amd/build/commands.min.js new file mode 100644 index 0000000..3556a12 --- /dev/null +++ b/amd/build/commands.min.js @@ -0,0 +1,11 @@ +define("tiny_chemdraw/commands",["exports","editor_tiny/utils","core/str","./common","./ui","core/notification"],(function(_exports,_utils,_str,_common,_ui,_notification){Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.getSetup=void 0; +/** + * Commands helper for the Moodle tiny_chemdraw plugin. + * + * @module plugintype_pluginname/commands + * @copyright 2024 Aniket Kumar + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +const handleAction=async editor=>{new _ui.ChemEmbed(editor).init();const insertButton=document.getElementById("insertButton");insertButton?insertButton.addEventListener("click",_ui.insert):_notification.notify.addNotification({type:"error",message:"Insert button not found in the DOM."})};_exports.getSetup=async()=>{try{const buttonName=await(0,_str.get_string)("buttonName",_common.component),buttonImage=await(0,_utils.getButtonImage)("icon",_common.component);return editor=>{editor.ui.registry.addIcon(_common.icon,buttonImage.html),editor.ui.registry.addButton(buttonName,{icon:_common.icon,tooltip:buttonName,onAction:()=>handleAction(editor)}),editor.ui.registry.addMenuItem(buttonName,{icon:_common.icon,text:buttonName,onAction:()=>handleAction(editor)})}}catch(error){return _notification.notify.addNotification({type:"error",message:"Error setting up the tiny_chemdraw plugin: "+error.message}),null}}})); + +//# sourceMappingURL=commands.min.js.map \ No newline at end of file diff --git a/amd/build/commands.min.js.map b/amd/build/commands.min.js.map new file mode 100644 index 0000000..0a9e7bd --- /dev/null +++ b/amd/build/commands.min.js.map @@ -0,0 +1 @@ +{"version":3,"file":"commands.min.js","sources":["../src/commands.js"],"sourcesContent":["// This file is part of Moodle - https://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see .\n\n/**\n * Commands helper for the Moodle tiny_chemdraw plugin.\n *\n * @module plugintype_pluginname/commands\n * @copyright 2024 Aniket Kumar \n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nimport {getButtonImage} from \"editor_tiny/utils\";\nimport {get_string as getString} from \"core/str\";\nimport {component, icon} from \"./common\";\nimport {ChemEmbed, insert} from \"./ui\";\nimport {notify} from 'core/notification';\n\nconst handleAction = async(editor) => {\n const chemImage = new ChemEmbed(editor);\n chemImage.init();\n\n const insertButton = document.getElementById('insertButton');\n\n if (insertButton) {\n insertButton.addEventListener('click', insert);\n } else {\n notify.addNotification({\n type: 'error',\n message: 'Insert button not found in the DOM.'\n });\n }\n\n};\n\nexport const getSetup = async() => {\n try {\n const buttonName = await getString(\"buttonName\", component);\n const buttonImage = await getButtonImage(\"icon\", component);\n\n return (editor) => {\n editor.ui.registry.addIcon(icon, buttonImage.html);\n\n editor.ui.registry.addButton(buttonName, {\n icon,\n tooltip: buttonName,\n onAction: () => handleAction(editor),\n });\n\n editor.ui.registry.addMenuItem(buttonName, {\n icon,\n text: buttonName,\n onAction: () => handleAction(editor),\n });\n };\n\n } catch (error) {\n notify.addNotification({\n type: 'error',\n message: 'Error setting up the tiny_chemdraw plugin: ' + error.message\n });\n return null;\n }\n};\n"],"names":["handleAction","async","ChemEmbed","editor","init","insertButton","document","getElementById","addEventListener","insert","addNotification","type","message","buttonName","component","buttonImage","ui","registry","addIcon","icon","html","addButton","tooltip","onAction","addMenuItem","text","error"],"mappings":";;;;;;;;MA6BMA,aAAeC,MAAAA,SACD,IAAIC,cAAUC,QACtBC,aAEJC,aAAeC,SAASC,eAAe,gBAEzCF,aACFA,aAAaG,iBAAiB,QAASC,iCAEhCC,gBAAgB,CACrBC,KAAM,QACNC,QAAS,2DAMSX,oBAEdY,iBAAmB,mBAAU,aAAcC,mBAC3CC,kBAAoB,yBAAe,OAAQD,0BAEzCX,SACNA,OAAOa,GAAGC,SAASC,QAAQC,aAAMJ,YAAYK,MAE7CjB,OAAOa,GAAGC,SAASI,UAAUR,WAAY,CACvCM,KAAAA,aACAG,QAAST,WACTU,SAAU,IAAMvB,aAAaG,UAG/BA,OAAOa,GAAGC,SAASO,YAAYX,WAAY,CACzCM,KAAAA,aACAM,KAAMZ,WACNU,SAAU,IAAMvB,aAAaG,WAIjC,MAAOuB,mCACAhB,gBAAgB,CACrBC,KAAM,QACNC,QAAS,8CAAgDc,MAAMd,UAE1D"} \ No newline at end of file diff --git a/amd/build/common.min.js b/amd/build/common.min.js new file mode 100644 index 0000000..b8405cc --- /dev/null +++ b/amd/build/common.min.js @@ -0,0 +1,3 @@ +define("tiny_chemdraw/common",["exports"],(function(_exports){Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.default=void 0;var _default={component:"tiny_chemdraw",pluginName:"tiny_chemdraw/plugin",icon:"tiny_chemdraw",buttonName:"ChemDraw"};return _exports.default=_default,_exports.default})); + +//# sourceMappingURL=common.min.js.map \ No newline at end of file diff --git a/amd/build/common.min.js.map b/amd/build/common.min.js.map new file mode 100644 index 0000000..1b41041 --- /dev/null +++ b/amd/build/common.min.js.map @@ -0,0 +1 @@ +{"version":3,"file":"common.min.js","sources":["../src/common.js"],"sourcesContent":["// This file is part of Moodle - https://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see .\n\n/**\n * Common values helper for the Moodle tiny_chemdraw plugin.\n *\n * @module plugintype_pluginname/common\n * @copyright 2024 Aniket Kumar \n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nconst component = 'tiny_chemdraw';\n\nexport default {\n component,\n pluginName: `${component}/plugin`,\n icon: component,\n buttonName: `ChemDraw`\n\n};\n"],"names":["component","pluginName","icon","buttonName"],"mappings":"2JAyBe,CACXA,UAHc,gBAIdC,WAAa,uBACbC,KALc,gBAMdC,WAAa"} \ No newline at end of file diff --git a/amd/build/configuration.min.js b/amd/build/configuration.min.js new file mode 100644 index 0000000..2f2e26a --- /dev/null +++ b/amd/build/configuration.min.js @@ -0,0 +1,11 @@ +define("tiny_chemdraw/configuration",["exports","./common","editor_tiny/utils"],(function(_exports,_common,_utils){Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.configure=void 0; +/** + * Tiny tiny_chemdraw for Moodle. + * + * @module plugintype_pluginname/plugin + * @copyright 2024 Aniket Kumar + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +const getToolbarConfiguration=instanceConfig=>{let toolbar=instanceConfig.toolbar;return toolbar=(0,_utils.addToolbarButtons)(toolbar,"content",[_common.startMolDrawButtonName]),toolbar},getMenuConfiguration=instanceConfig=>{let menu=instanceConfig.menu;return menu=(0,_utils.addMenubarItem)(menu,"file",[_common.startMolDrawMenuItemName].join(" ")),menu};_exports.configure=instanceConfig=>({toolbar:getToolbarConfiguration(instanceConfig),menu:getMenuConfiguration(instanceConfig)})})); + +//# sourceMappingURL=configuration.min.js.map \ No newline at end of file diff --git a/amd/build/configuration.min.js.map b/amd/build/configuration.min.js.map new file mode 100644 index 0000000..19e0ad1 --- /dev/null +++ b/amd/build/configuration.min.js.map @@ -0,0 +1 @@ +{"version":3,"file":"configuration.min.js","sources":["../src/configuration.js"],"sourcesContent":["// This file is part of Moodle - https://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see .\n\n/**\n * Tiny tiny_chemdraw for Moodle.\n *\n * @module plugintype_pluginname/plugin\n * @copyright 2024 Aniket Kumar \n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nimport {\n startMolDrawButtonName,\n startMolDrawMenuItemName,\n} from './common';\n\nimport {\n addMenubarItem,\n addToolbarButtons,\n} from 'editor_tiny/utils';\n\nconst getToolbarConfiguration = (instanceConfig) => {\n let toolbar = instanceConfig.toolbar;\n toolbar = addToolbarButtons(toolbar, 'content', [\n startMolDrawButtonName,\n ]);\n\n return toolbar;\n};\n\nconst getMenuConfiguration = (instanceConfig) => {\n let menu = instanceConfig.menu;\n menu = addMenubarItem(menu, 'file', [\n startMolDrawMenuItemName,\n ].join(' '));\n\n return menu;\n};\n\nexport const configure = (instanceConfig) => {\n return {\n toolbar: getToolbarConfiguration(instanceConfig),\n menu: getMenuConfiguration(instanceConfig),\n };\n};\n"],"names":["getToolbarConfiguration","instanceConfig","toolbar","startMolDrawButtonName","getMenuConfiguration","menu","startMolDrawMenuItemName","join"],"mappings":";;;;;;;;MAiCMA,wBAA2BC,qBACzBC,QAAUD,eAAeC,eAC7BA,SAAU,4BAAkBA,QAAS,UAAW,CAC5CC,iCAGGD,SAGLE,qBAAwBH,qBACtBI,KAAOJ,eAAeI,YAC1BA,MAAO,yBAAeA,KAAM,OAAQ,CAChCC,kCACFC,KAAK,MAEAF,yBAGeJ,iBACf,CACHC,QAASF,wBAAwBC,gBACjCI,KAAMD,qBAAqBH"} \ No newline at end of file diff --git a/amd/build/options.min.js b/amd/build/options.min.js new file mode 100644 index 0000000..ba8d22e --- /dev/null +++ b/amd/build/options.min.js @@ -0,0 +1,11 @@ +define("tiny_chemdraw/options",["exports","editor_tiny/options","./common"],(function(_exports,_options,_common){Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.register=_exports.isPluginVisible=void 0; +/** + * Common values helper for the Moodle tiny_chemdraw plugin. + * + * @module plugintype_pluginname/common + * @copyright 2024 Aniket Kumar + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +const showPlugin=(0,_options.getPluginOptionName)(_common.pluginName,"showplugin");_exports.register=editor=>{(0,editor.options.register)(showPlugin,{processor:"boolean",default:!0})};_exports.isPluginVisible=editor=>editor.options.get(showPlugin)})); + +//# sourceMappingURL=options.min.js.map \ No newline at end of file diff --git a/amd/build/options.min.js.map b/amd/build/options.min.js.map new file mode 100644 index 0000000..1d44998 --- /dev/null +++ b/amd/build/options.min.js.map @@ -0,0 +1 @@ +{"version":3,"file":"options.min.js","sources":["../src/options.js"],"sourcesContent":["// This file is part of Moodle - https://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see .\n\n/**\n * Common values helper for the Moodle tiny_chemdraw plugin.\n *\n * @module plugintype_pluginname/common\n * @copyright 2024 Aniket Kumar \n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nimport {\n getPluginOptionName\n}\nfrom 'editor_tiny/options';\nimport {\n pluginName\n}\nfrom './common';\n\n// Helper variables for the option names.\nconst showPlugin = getPluginOptionName(pluginName, 'showplugin');\n\n/**\n * Options registration function.\n *\n * @param {tinyMCE} editor\n */\nexport const register = (editor) => {\n const registerOption = editor.options.register;\n\n registerOption(showPlugin, {\n processor: 'boolean',\n \"default\": true,\n });\n};\n\n/**\n * Fetch the myFirstProperty value for this editor instance.\n *\n * @param {tinyMCE} editor The editor instance to fetch the value for\n * @returns {object} The value of the myFirstProperty option\n */\nexport const isPluginVisible = (editor) => editor.options.get(showPlugin);"],"names":["showPlugin","pluginName","editor","registerOption","options","register","processor","get"],"mappings":";;;;;;;;MAiCMA,YAAa,gCAAoBC,mBAAY,gCAO1BC,UAGrBC,EAFuBD,OAAOE,QAAQC,UAEvBL,WAAY,CACvBM,UAAW,mBACA,8BAUaJ,QAAWA,OAAOE,QAAQG,IAAIP"} \ No newline at end of file diff --git a/amd/build/plugin.min.js b/amd/build/plugin.min.js new file mode 100644 index 0000000..aaed879 --- /dev/null +++ b/amd/build/plugin.min.js @@ -0,0 +1,10 @@ +define("tiny_chemdraw/plugin",["exports","editor_tiny/loader","editor_tiny/utils","./common","./options","./commands","./configuration"],(function(_exports,_loader,_utils,_common,_options,_commands,Configuration){function _getRequireWildcardCache(nodeInterop){if("function"!=typeof WeakMap)return null;var cacheBabelInterop=new WeakMap,cacheNodeInterop=new WeakMap;return(_getRequireWildcardCache=function(nodeInterop){return nodeInterop?cacheNodeInterop:cacheBabelInterop})(nodeInterop)}Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.default=void 0,Configuration=function(obj,nodeInterop){if(!nodeInterop&&obj&&obj.__esModule)return obj;if(null===obj||"object"!=typeof obj&&"function"!=typeof obj)return{default:obj};var cache=_getRequireWildcardCache(nodeInterop);if(cache&&cache.has(obj))return cache.get(obj);var newObj={},hasPropertyDescriptor=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var key in obj)if("default"!==key&&Object.prototype.hasOwnProperty.call(obj,key)){var desc=hasPropertyDescriptor?Object.getOwnPropertyDescriptor(obj,key):null;desc&&(desc.get||desc.set)?Object.defineProperty(newObj,key,desc):newObj[key]=obj[key]}newObj.default=obj,cache&&cache.set(obj,newObj);return newObj} +/** + * Tiny tiny_chemdraw for Moodle. + * + * @module plugintype_pluginname/plugin + * @copyright 2024 Aniket Kumar + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */(Configuration);var _default=new Promise((resolve=>{const[tinyMCE,pluginMetadata,setupCommands]=Promise.all([(0,_loader.getTinyMCE)(),(0,_utils.getPluginMetadata)(_common.component,_common.pluginName),(0,_commands.getSetup)()]);tinyMCE.PluginManager.add(_common.pluginName,(editor=>((0,_options.register)(editor),setupCommands(editor),pluginMetadata))),resolve([_common.pluginName,Configuration])}));return _exports.default=_default,_exports.default})); + +//# sourceMappingURL=plugin.min.js.map \ No newline at end of file diff --git a/amd/build/plugin.min.js.map b/amd/build/plugin.min.js.map new file mode 100644 index 0000000..d098e39 --- /dev/null +++ b/amd/build/plugin.min.js.map @@ -0,0 +1 @@ +{"version":3,"file":"plugin.min.js","sources":["../src/plugin.js"],"sourcesContent":["// This file is part of Moodle - https://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see .\n\n/**\n * Tiny tiny_chemdraw for Moodle.\n *\n * @module plugintype_pluginname/plugin\n * @copyright 2024 Aniket Kumar \n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nimport {getTinyMCE} from 'editor_tiny/loader';\nimport {getPluginMetadata} from 'editor_tiny/utils';\nimport {component, pluginName} from './common';\nimport {register as registerOptions} from './options';\nimport {getSetup as getCommandSetup} from './commands';\nimport * as Configuration from './configuration';\n\n// Setup the tiny_moldraw Plugin.\nexport default new Promise((resolve) => {\n const [tinyMCE, pluginMetadata, setupCommands] = Promise.all([\n getTinyMCE(),\n getPluginMetadata(component, pluginName),\n getCommandSetup(),\n ]);\n\n tinyMCE.PluginManager.add(pluginName, (editor) => {\n // Register any options that your plugin has\n registerOptions(editor);\n\n // Setup any commands such as buttons, menu items, and so on.\n setupCommands(editor);\n\n // Return the pluginMetadata object. This is used by TinyMCE to display a help link for your plugin.\n return pluginMetadata;\n });\n\n resolve([pluginName, Configuration]);\n });"],"names":["Promise","resolve","tinyMCE","pluginMetadata","setupCommands","all","component","pluginName","PluginManager","add","editor","Configuration"],"mappings":";;;;;;;kCA+Be,IAAIA,SAASC,gBACjBC,QAASC,eAAgBC,eAAiBJ,QAAQK,IAAI,EAC3D,yBACA,4BAAkBC,kBAAWC,qBAC7B,0BAGFL,QAAQM,cAAcC,IAAIF,oBAAaG,+BAErBA,QAGhBN,cAAcM,QAGPP,kBAGTF,QAAQ,CAACM,mBAAYI"} \ No newline at end of file diff --git a/amd/build/ui.min.js b/amd/build/ui.min.js new file mode 100644 index 0000000..33e2582 --- /dev/null +++ b/amd/build/ui.min.js @@ -0,0 +1,10 @@ +define("tiny_chemdraw/ui",["exports","core/str","core/templates","core/modal","core/config","core/notification"],(function(_exports,_str,_templates,_modal,_config,_notification){function _interopRequireDefault(obj){return obj&&obj.__esModule?obj:{default:obj}} +/** + * Commands helper for the Moodle tiny_chemdraw plugin. + * + * @module plugintype_pluginname/ui + * @copyright 2024 Aniket Kumar + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.insert=_exports.ChemEmbed=void 0,_templates=_interopRequireDefault(_templates),_modal=_interopRequireDefault(_modal),_config=_interopRequireDefault(_config);_exports.ChemEmbed=class{editor=null;constructor(editor){this.editor=editor}loadResource=async(url,type)=>new Promise(((resolve,reject)=>{const element="script"===type?document.createElement("script"):document.createElement("link");element.onload=resolve,element.onerror=()=>reject(new Error(`Failed to load ${type}: ${url}`)),"stylesheet"===type?(element.rel="stylesheet",element.href=url):"script"===type&&(element.src=url),document["script"===type?"body":"head"].appendChild(element)}));initializeChemDoodle=()=>{try{ChemDoodle.ELEMENT.H.jmolColor="black",ChemDoodle.ELEMENT.S.jmolColor="#B9A130";const sketcher=new ChemDoodle.SketcherCanvas("sketcher",600,350,{useServices:!1,requireStartingAtom:!1});sketcher.styles.atoms_displayTerminalCarbonLabels_2D=!0,sketcher.styles.atoms_useJMOLColors=!0,sketcher.styles.bonds_clearOverlaps_2D=!0,sketcher.styles.shapes_color="#c10000",sketcher.repaint();const sketcherViewer=new ChemDoodle.ViewerCanvas("sketcher-viewer-atto",100,100);sketcherViewer.emptyMessage="No data loaded",sketcherViewer.styles.atoms_displayTerminalCarbonLabels_2D=!0,sketcherViewer.styles.atoms_useJMOLColors=!0,sketcherViewer.styles.bonds_clearOverlaps_2D=!0,sketcher.oldFunc=sketcher.checksOnAction,sketcher.checksOnAction=function(force){this.oldFunc(force);let mols=sketcher.molecules,forms=sketcher.shapes;sketcherViewer.loadContent(mols,forms),sketcher.center();for(let i=0,ii=this.molecules.length;i{try{const modal=await _modal.default.create({title:(0,_str.get_string)("sketchtitle"),show:!0,removeOnClose:!0});_templates.default.renderForPromise("tiny_chemdraw/chemTemplate",{}).then((async _ref=>{let{html:html,js:js}=_ref;_templates.default.appendNodeContents(modal.getBody(),html,js);const resources=[`${_config.default.wwwroot}/lib/editor/tiny/plugins/chemdraw/ChemDoodle/install/ChemDoodleWeb.css`,`${_config.default.wwwroot}/lib/editor/tiny/plugins/chemdraw/ChemDoodle/install/uis/jquery-ui-1.11.4.css`,`${_config.default.wwwroot}/lib/editor/tiny/plugins/chemdraw/ChemDoodle/install/ChemDoodleWeb.js`,`${_config.default.wwwroot}/lib/editor/tiny/plugins/chemdraw/ChemDoodle/install/uis/ChemDoodleWeb-uis.js`,`${_config.default.wwwroot}/lib/editor/tiny/plugins/chemdraw/chem/chem.css`],types=["stylesheet","stylesheet","script","script","stylesheet"];for(let i=0;i{if(window.parent.tinyMCE&&window.parent.tinyMCE.activeEditor){let mol=sketcherViewer.getMolecule(),src=ChemDoodle.io.png.string(sketcherViewer),molFile=ChemDoodle.writeMOL(mol);var content='';window.parent.tinyMCE.activeEditor.execCommand("mceInsertContent",0,content),window.parent.tinyMCE.activeEditor.execCommand("mceInsertContent",0,"\x3c!--"+molFile+"--\x3e"),window.parent.document.querySelector(".modal").querySelector(".close").click()}console.log("button Click")}})); + +//# sourceMappingURL=ui.min.js.map \ No newline at end of file diff --git a/amd/build/ui.min.js.map b/amd/build/ui.min.js.map new file mode 100644 index 0000000..c67b780 --- /dev/null +++ b/amd/build/ui.min.js.map @@ -0,0 +1 @@ +{"version":3,"file":"ui.min.js","sources":["../src/ui.js"],"sourcesContent":["// This file is part of Moodle - https://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see .\n\n/**\n * Commands helper for the Moodle tiny_chemdraw plugin.\n *\n * @module plugintype_pluginname/ui\n * @copyright 2024 Aniket Kumar \n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nimport {get_string as getString} from 'core/str';\nimport Templates from 'core/templates';\nimport Modal from 'core/modal';\nimport Config from 'core/config';\nimport {exception as displayException} from 'core/notification';\n\n\nexport const ChemEmbed = class {\n editor = null;\n constructor(editor) {\n this.editor = editor;\n }\n\n loadResource = async(url, type) => {\n return new Promise((resolve, reject) => {\n const element = (type === \"script\") ? document.createElement(\"script\") : document.createElement(\"link\");\n element.onload = resolve;\n element.onerror = () => reject(new Error(`Failed to load ${type}: ${url}`));\n if (type === \"stylesheet\") {\n element.rel = 'stylesheet';\n element.href = url;\n } else if (type === \"script\") {\n element.src = url;}\n document[type === \"script\" ? 'body' : 'head'].appendChild(element);\n });\n };\n\n initializeChemDoodle = () => {\n try {\n ChemDoodle.ELEMENT[\"H\"].jmolColor = \"black\";\n ChemDoodle.ELEMENT[\"S\"].jmolColor = \"#B9A130\";\n\n // Main ketcher initialization\n const sketcher = new ChemDoodle.SketcherCanvas(\"sketcher\", 600, 350, {\n useServices: false,\n requireStartingAtom: false,\n });\n // Additional initialization for ChemDoodle goes here...\n sketcher.styles.atoms_displayTerminalCarbonLabels_2D = true;\n sketcher.styles.atoms_useJMOLColors = true;\n sketcher.styles.bonds_clearOverlaps_2D = true;\n sketcher.styles.shapes_color = \"#c10000\";\n sketcher.repaint();\n // Preview ketcher initialization\n const sketcherViewer = new ChemDoodle.ViewerCanvas(\"sketcher-viewer-atto\", 100, 100);\n sketcherViewer.emptyMessage = \"No data loaded\";\n sketcherViewer.styles.atoms_displayTerminalCarbonLabels_2D = true;\n sketcherViewer.styles.atoms_useJMOLColors = true;\n sketcherViewer.styles.bonds_clearOverlaps_2D = true;\n sketcher.oldFunc = sketcher.checksOnAction;\n sketcher.checksOnAction = function (force) {\n this.oldFunc(force);\n let mols = sketcher.molecules;\n let forms = sketcher.shapes;\n sketcherViewer.loadContent(mols, forms);\n sketcher.center();\n for (let i = 0, ii = this.molecules.length; i < ii; i++) {\n this.molecules[i].check();\n }\n };\n } catch (error) {\n console.error(\"Error:\", error.message);\n }\n };\n\n init = async() => {\n try {\n const modal = await Modal.create({\n title: getString('sketchtitle'),\n show: true,\n removeOnClose: true,\n });\n Templates.renderForPromise('tiny_chemdraw/chemTemplate', {})\n .then(async ({ html, js }) => {\n Templates.appendNodeContents(modal.getBody(), html, js);\n const resources = [\n `${Config.wwwroot}/lib/editor/tiny/plugins/chemdraw/ChemDoodle/install/ChemDoodleWeb.css`,\n `${Config.wwwroot}/lib/editor/tiny/plugins/chemdraw/ChemDoodle/install/uis/jquery-ui-1.11.4.css`,\n `${Config.wwwroot}/lib/editor/tiny/plugins/chemdraw/ChemDoodle/install/ChemDoodleWeb.js`,\n `${Config.wwwroot}/lib/editor/tiny/plugins/chemdraw/ChemDoodle/install/uis/ChemDoodleWeb-uis.js`,\n `${Config.wwwroot}/lib/editor/tiny/plugins/chemdraw/chem/chem.css`\n ];\n\n const types = [\"stylesheet\", \"stylesheet\", \"script\", \"script\", \"stylesheet\"];\n\n for (let i = 0; i < resources.length; i++) {\n await loadResource(resources[i], types[i]);\n }\n\n // Add this line to fix the model width.\n window.parent.document.querySelector(\".modal-dialog\").style.maxWidth = '850px';\n\n // Load and run ChemDoodle functionality\n loadAndRunChemDoodle();\n }) \n } catch (error) {\n displayException(error);\n }\n };\n}\n\nexport const insert = () => {\n if (window.parent.tinyMCE && window.parent.tinyMCE.activeEditor) {\n let mol = sketcherViewer.getMolecule();\n let src = ChemDoodle.io.png.string(sketcherViewer);\n let molFile = ChemDoodle.writeMOL(mol);\n let width = document.getElementById('width_input_molstructure').valueAsNumber;\n let height = document.getElementById('height_input_molstructure').valueAsNumber;\n var content =\n '';\n\n window.parent.tinyMCE.activeEditor.execCommand(\n \"mceInsertContent\",\n 0,\n content\n );\n window.parent.tinyMCE.activeEditor.execCommand(\n \"mceInsertContent\",\n 0,\n \"\"\n );\n var modal = window.parent.document.querySelector('.modal');\n var closeButton = modal.querySelector('.close');\n closeButton.click();\n }\n console.log(\"button Click\");\n};"],"names":["editor","constructor","loadResource","async","url","type","Promise","resolve","reject","element","document","createElement","onload","onerror","Error","rel","href","src","appendChild","initializeChemDoodle","ChemDoodle","ELEMENT","jmolColor","sketcher","SketcherCanvas","useServices","requireStartingAtom","styles","atoms_displayTerminalCarbonLabels_2D","atoms_useJMOLColors","bonds_clearOverlaps_2D","shapes_color","repaint","sketcherViewer","ViewerCanvas","emptyMessage","oldFunc","checksOnAction","force","mols","molecules","forms","shapes","loadContent","center","i","ii","this","length","check","error","console","message","init","modal","Modal","create","title","show","removeOnClose","renderForPromise","then","html","js","appendNodeContents","getBody","resources","Config","wwwroot","types","window","parent","querySelector","style","maxWidth","loadAndRunChemDoodle","tinyMCE","activeEditor","mol","getMolecule","io","png","string","molFile","writeMOL","content","getElementById","valueAsNumber","execCommand","click","log"],"mappings":";;;;;;;sPA8ByB,MACvBA,OAAS,KACTC,YAAYD,aACLA,OAASA,OAGhBE,aAAeC,MAAMC,IAAKC,OACjB,IAAIC,SAAQ,CAACC,QAASC,gBACrBC,QAAoB,WAATJ,KAAqBK,SAASC,cAAc,UAAYD,SAASC,cAAc,QAChGF,QAAQG,OAASL,QACjBE,QAAQI,QAAU,IAAML,OAAO,IAAIM,MAAO,kBAAiBT,SAASD,QACvD,eAATC,MACFI,QAAQM,IAAM,aACdN,QAAQO,KAAOZ,KACG,WAATC,OACTI,QAAQQ,IAAMb,KAChBM,SAAkB,WAATL,KAAoB,OAAS,QAAQa,YAAYT,YAI9DU,qBAAuB,SAEnBC,WAAWC,QAAX,EAAwBC,UAAY,QACpCF,WAAWC,QAAX,EAAwBC,UAAY,gBAG9BC,SAAW,IAAIH,WAAWI,eAAe,WAAY,IAAK,IAAK,CACnEC,aAAa,EACbC,qBAAqB,IAGvBH,SAASI,OAAOC,sCAAuC,EACvDL,SAASI,OAAOE,qBAAsB,EACtCN,SAASI,OAAOG,wBAAyB,EACzCP,SAASI,OAAOI,aAAe,UAC/BR,SAASS,gBAEHC,eAAiB,IAAIb,WAAWc,aAAa,uBAAwB,IAAK,KAChFD,eAAeE,aAAe,iBAC9BF,eAAeN,OAAOC,sCAAuC,EAC7DK,eAAeN,OAAOE,qBAAsB,EAC5CI,eAAeN,OAAOG,wBAAyB,EAC/CP,SAASa,QAAUb,SAASc,eAC5Bd,SAASc,eAAiB,SAAUC,YAC7BF,QAAQE,WACTC,KAAOhB,SAASiB,UAChBC,MAAQlB,SAASmB,OACrBT,eAAeU,YAAYJ,KAAME,OACjClB,SAASqB,aACJ,IAAIC,EAAI,EAAGC,GAAKC,KAAKP,UAAUQ,OAAQH,EAAIC,GAAID,SAC7CL,UAAUK,GAAGI,SAGtB,MAAOC,OACPC,QAAQD,MAAM,SAAUA,MAAME,WAIlCC,KAAOlD,oBAEGmD,YAAcC,eAAMC,OAAO,CAC/BC,OAAO,mBAAU,eACjBC,MAAM,EACNC,eAAe,uBAEPC,iBAAiB,6BAA8B,IACtDC,MAAK1D,MAAAA,WAAO2D,KAAEA,KAAFC,GAAQA,4BACTC,mBAAmBV,MAAMW,UAAWH,KAAMC,UAC9CG,UAAY,CACf,GAAEC,gBAAOC,gFACT,GAAED,gBAAOC,uFACT,GAAED,gBAAOC,+EACT,GAAED,gBAAOC,uFACT,GAAED,gBAAOC,0DAGNC,MAAQ,CAAC,aAAc,aAAc,SAAU,SAAU,kBAE1D,IAAIxB,EAAI,EAAGA,EAAIqB,UAAUlB,OAAQH,UAC9B3C,aAAagE,UAAUrB,GAAIwB,MAAMxB,IAIzCyB,OAAOC,OAAO7D,SAAS8D,cAAc,iBAAiBC,MAAMC,SAAW,QAGvEC,0BAEJ,MAAOzB,mCACUA,0BAKD,QAChBoB,OAAOC,OAAOK,SAAWN,OAAOC,OAAOK,QAAQC,aAAc,KAC3DC,IAAM7C,eAAe8C,cACrB9D,IAAMG,WAAW4D,GAAGC,IAAIC,OAAOjD,gBAC/BkD,QAAU/D,WAAWgE,SAASN,SAG9BO,QACF,aACApE,IACA,YALUP,SAAS4E,eAAe,4BAA4BC,cAO9D,eANW7E,SAAS4E,eAAe,6BAA6BC,cAQhE,OAEFjB,OAAOC,OAAOK,QAAQC,aAAaW,YACjC,mBACA,EACAH,SAEFf,OAAOC,OAAOK,QAAQC,aAAaW,YACjC,mBACA,EACA,UAASL,QAAU,UAETb,OAAOC,OAAO7D,SAAS8D,cAAc,UACzBA,cAAc,UAC1BiB,QAEdtC,QAAQuC,IAAI"} \ No newline at end of file diff --git a/amd/src/commands.js b/amd/src/commands.js index f7ddeb7..afb21c7 100644 --- a/amd/src/commands.js +++ b/amd/src/commands.js @@ -7,11 +7,11 @@ // // Moodle is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License -// along with Moodle. If not, see . +// along with Moodle. If not, see . /** * Commands helper for the Moodle tiny_chemdraw plugin. @@ -23,49 +23,53 @@ import {getButtonImage} from "editor_tiny/utils"; import {get_string as getString} from "core/str"; -import {handleAction} from "./ui"; -import {component, startMolDrawButtonName, startMolDrawMenuItemName, icon} from "./common"; +import {component, icon} from "./common"; +import {ChemEmbed, insert} from "./ui"; +import {notify} from 'core/notification'; -/** - * Handle the action for your plugin. - * @param {TinyMCE.editor} editor The tinyMCE editor instance. - */ -// handle Action funciton.. +const handleAction = async(editor) => { + const chemImage = new ChemEmbed(editor); + chemImage.init(); + const insertButton = document.getElementById('insertButton'); + + if (insertButton) { + insertButton.addEventListener('click', insert); + } else { + notify.addNotification({ + type: 'error', + message: 'Insert button not found in the DOM.' + }); + } + +}; -/** - * Get the setup function for the buttons. - * - * This is performed in an async function which ultimately returns the registration function as the - * Tiny.AddOnManager.Add() function does not support async functions. - * - * @returns {function} The registration function to call within the Plugin.add function. - */ export const getSetup = async() => { - try { - const [startMolDrawButtonNameTitle, startMolDrawMenuItemNameTitle, buttonImage] = await Promise.all([ - getString("button_startMolDraw", component), - getString("menuitem_startMolDraw", component), - getButtonImage("icon", component), - ]); - - return (editor) => { - editor.ui.registry.addIcon(icon, buttonImage.html); - - editor.ui.registry.addButton(startMolDrawButtonName, { - icon, - tooltip: startMolDrawButtonNameTitle, - onAction: () => handleAction(editor), - }); - - editor.ui.registry.addMenuItem(startMolDrawMenuItemName, { - icon, - text: startMolDrawMenuItemNameTitle, - onAction: () => handleAction(editor), - }); - }; - } catch (error) { - // eslint-disable-next-line no-alert - alert("Error setting up plugin:", error); - } - }; + try { + const buttonName = await getString("buttonName", component); + const buttonImage = await getButtonImage("icon", component); + + return (editor) => { + editor.ui.registry.addIcon(icon, buttonImage.html); + + editor.ui.registry.addButton(buttonName, { + icon, + tooltip: buttonName, + onAction: () => handleAction(editor), + }); + + editor.ui.registry.addMenuItem(buttonName, { + icon, + text: buttonName, + onAction: () => handleAction(editor), + }); + }; + + } catch (error) { + notify.addNotification({ + type: 'error', + message: 'Error setting up the tiny_chemdraw plugin: ' + error.message + }); + return null; + } +}; diff --git a/amd/src/common.js b/amd/src/common.js index a4742cd..667383c 100644 --- a/amd/src/common.js +++ b/amd/src/common.js @@ -21,12 +21,12 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -const component = 'tiny_moldraw'; +const component = 'tiny_chemdraw'; export default { component, pluginName: `${component}/plugin`, icon: component, - startMolDrawButtonName: `${component}_startMolDraw`, - startMolDrawMenuItemName: `${component}_startMolDraw`, + buttonName: `ChemDraw` + }; diff --git a/amd/src/options.js b/amd/src/options.js new file mode 100644 index 0000000..198706a --- /dev/null +++ b/amd/src/options.js @@ -0,0 +1,56 @@ +// This file is part of Moodle - https://moodle.org/ +// +// Moodle is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Moodle is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Moodle. If not, see . + +/** + * Common values helper for the Moodle tiny_chemdraw plugin. + * + * @module plugintype_pluginname/common + * @copyright 2024 Aniket Kumar + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +import { + getPluginOptionName +} +from 'editor_tiny/options'; +import { + pluginName +} +from './common'; + +// Helper variables for the option names. +const showPlugin = getPluginOptionName(pluginName, 'showplugin'); + +/** + * Options registration function. + * + * @param {tinyMCE} editor + */ +export const register = (editor) => { + const registerOption = editor.options.register; + + registerOption(showPlugin, { + processor: 'boolean', + "default": true, + }); +}; + +/** + * Fetch the myFirstProperty value for this editor instance. + * + * @param {tinyMCE} editor The editor instance to fetch the value for + * @returns {object} The value of the myFirstProperty option + */ +export const isPluginVisible = (editor) => editor.options.get(showPlugin); \ No newline at end of file diff --git a/amd/src/plugin.js b/amd/src/plugin.js index bc3c56d..31f31db 100644 --- a/amd/src/plugin.js +++ b/amd/src/plugin.js @@ -21,33 +21,31 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -import { getTinyMCE } from 'editor_tiny/loader'; -import { getPluginMetadata } from 'editor_tiny/utils'; - -import { component, pluginName } from './common'; -import { register as registerOptions } from './options'; -import { getSetup as getCommandSetup } from './commands'; +import {getTinyMCE} from 'editor_tiny/loader'; +import {getPluginMetadata} from 'editor_tiny/utils'; +import {component, pluginName} from './common'; +import {register as registerOptions} from './options'; +import {getSetup as getCommandSetup} from './commands'; import * as Configuration from './configuration'; // Setup the tiny_moldraw Plugin. export default new Promise((resolve) => { - Promise.all([ - getTinyMCE(), - getPluginMetadata(component, pluginName), - getCommandSetup(), - ]).then(([tinyMCE, pluginMetadata, setupCommands]) => { - // Register the plugin with TinyMCE - tinyMCE.PluginManager.add(pluginName, (editor) => { - // Register any options that your plugin has - registerOptions(editor); + const [tinyMCE, pluginMetadata, setupCommands] = Promise.all([ + getTinyMCE(), + getPluginMetadata(component, pluginName), + getCommandSetup(), + ]); - // Setup any commands such as buttons, menu items, and so on. - setupCommands(editor); + tinyMCE.PluginManager.add(pluginName, (editor) => { + // Register any options that your plugin has + registerOptions(editor); - // Return the pluginMetadata object. This is used by TinyMCE to display a help link for your plugin. - return pluginMetadata; - }); + // Setup any commands such as buttons, menu items, and so on. + setupCommands(editor); - resolve([pluginName, Configuration]); + // Return the pluginMetadata object. This is used by TinyMCE to display a help link for your plugin. + return pluginMetadata; }); -}); \ No newline at end of file + + resolve([pluginName, Configuration]); + }); \ No newline at end of file diff --git a/amd/src/ui.js b/amd/src/ui.js index f14a6b9..422e442 100644 --- a/amd/src/ui.js +++ b/amd/src/ui.js @@ -1,160 +1,156 @@ -import Modal from "core/modal"; -import Templates from "core/templates"; - -class MyModal extends Modal { - static TYPE = "tiny_moldraw/moldraw"; - static TEMPLATE = "tiny_moldraw/moldraw"; - configure(modalConfig) { - // Show this modal on instantiation. - modalConfig.show = true; - // Remove from the DOM on close. - modalConfig.removeOnClose = true; - } -} - -export const handleAction = async () => { - await MyModal.create(); -}; - -/** - * @param {*} url - * @param { }type - */ -async function loadResource(url, type) { - return new Promise((resolve, reject) => { - if (type === "script") { - var script = document.createElement("script"); - script.type = "text/javascript"; - script.onload = resolve; - script.onerror = reject; - script.src = url; - document.getElementsByTagName("body")[0].appendChild(script); - } else if (type === "stylesheet") { - var link = document.createElement("link"); - link.rel = "stylesheet"; - link.type = "text/css"; - link.onload = resolve; - link.onerror = reject; - link.href = url; - document.getElementsByTagName("head")[0].appendChild(link); - } else { - reject(new Error("Invalid resource type")); - } - }); -} - -/** - * - */ -async function loadAndRunAnotherFunction() { - try { - await loadResource("../../ChemDoodle/install/ChemDoodleWeb.css", "stylesheet"); - await loadResource("../../ChemDoodle/install/uis/jquery-ui-1.11.4.css", "stylesheet"); - await loadResource("../../ChemDoodle/install/ChemDoodleWeb.js", "script"); - await loadResource("../../ChemDoodle/install/uis/ChemDoodleWeb-uis.js", "script"); - await loadResource("../../chem/chem.css", "stylesheet"); - - // All resources are loaded, now you can execute your code - // For example, you can run the provided script here - - ChemDoodle.ELEMENT["H"].jmolColor = "black"; - ChemDoodle.ELEMENT["S"].jmolColor = "#B9A130"; - // Main ketcher. - const sketcher = new ChemDoodle.SketcherCanvas("sketcher", 600, 350, { - useServices: false, - requireStartingAtom: false, - }); - // We init the ketcher with an empty molecule object. - sketcher.styles.atoms_displayTerminalCarbonLabels_2D = true; - sketcher.styles.atoms_useJMOLColors = true; - sketcher.styles.bonds_clearOverlaps_2D = true; - sketcher.styles.shapes_color = "#c10000"; - sketcher.repaint(); - - // Preview ketcher. - const sketcherViewer = new ChemDoodle.ViewerCanvas( - "sketcher-viewer-atto", - 100, - 100 - ); - sketcherViewer.styles.atoms_displayTerminalCarbonLabels_2D = true; - sketcherViewer.styles.atoms_useJMOLColors = true; - sketcherViewer.styles.bonds_clearOverlaps_2D = true; - - sketcherViewer.emptyMessage = "No data loaded"; - sketcher.oldFunc = sketcher.checksOnAction; - - /* Refactor the function, in order for the preview ketcher to be a copy of the main ketcher, - updated at every modification of the main ketcher. */ - sketcher.checksOnAction = function (force) { - this.oldFunc(force); - let mols = sketcher.molecules; - let forms = sketcher.shapes; - sketcherViewer.loadContent(mols, forms); - sketcher.center(); - for (let i = 0, ii = this.molecules.length; i < ii; i++) { - this.molecules[i].check(); - } - } - - // eslint - disable - next - line no - console - console.log("All resources loaded successfully."); - } catch { - console.log("error"); - } -} -// Call the function to load all resources and run the provided script - - - -function function_resize() { - let input_width = document.getElementById('width_input_molstructure').valueAsNumber; - let input_height = document.getElementById('height_input_molstructure').valueAsNumber; - let width; - let height; - - if (input_width > 0) { - width = input_width; - } else { - width = 100; - } - if (input_height > 0) { - height = input_height; - } else { - height = 100; - } - sketcherViewer.resize(width, height); -} - -function insert() { - if (window.parent.tinyMCE && window.parent.tinyMCE.activeEditor) { - let mol = sketcherViewer.getMolecule(); - let src = ChemDoodle.io.png.string(sketcherViewer); - let molFile = ChemDoodle.writeMOL(mol); - let width = document.getElementById('width_input_molstructure').valueAsNumber; - let height = document.getElementById('height_input_molstructure').valueAsNumber; - var content = - ''; - - window.parent.tinyMCE.activeEditor.execCommand( - "mceInsertContent", - 0, - content - ); - window.parent.tinyMCE.activeEditor.execCommand( - "mceInsertContent", - 0, - "" - ); - var modal = window.parent.document.querySelector('.modal'); - var closeButton = modal.querySelector('.close'); - closeButton.click(); - } - console.log("button Click") -} +// This file is part of Moodle - https://moodle.org/ +// +// Moodle is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Moodle is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Moodle. If not, see . + +/** + * Commands helper for the Moodle tiny_chemdraw plugin. + * + * @module plugintype_pluginname/ui + * @copyright 2024 Aniket Kumar + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +import {get_string as getString} from 'core/str'; +import Templates from 'core/templates'; +import Modal from 'core/modal'; +import Config from 'core/config'; +import {exception as displayException} from 'core/notification'; + + +export const ChemEmbed = class { + editor = null; + constructor(editor) { + this.editor = editor; + } + + loadResource = async(url, type) => { + return new Promise((resolve, reject) => { + const element = (type === "script") ? document.createElement("script") : document.createElement("link"); + element.onload = resolve; + element.onerror = () => reject(new Error(`Failed to load ${type}: ${url}`)); + if (type === "stylesheet") { + element.rel = 'stylesheet'; + element.href = url; + } else if (type === "script") { + element.src = url;} + document[type === "script" ? 'body' : 'head'].appendChild(element); + }); + }; + + initializeChemDoodle = () => { + try { + ChemDoodle.ELEMENT["H"].jmolColor = "black"; + ChemDoodle.ELEMENT["S"].jmolColor = "#B9A130"; + + // Main ketcher initialization + const sketcher = new ChemDoodle.SketcherCanvas("sketcher", 600, 350, { + useServices: false, + requireStartingAtom: false, + }); + // Additional initialization for ChemDoodle goes here... + sketcher.styles.atoms_displayTerminalCarbonLabels_2D = true; + sketcher.styles.atoms_useJMOLColors = true; + sketcher.styles.bonds_clearOverlaps_2D = true; + sketcher.styles.shapes_color = "#c10000"; + sketcher.repaint(); + // Preview ketcher initialization + const sketcherViewer = new ChemDoodle.ViewerCanvas("sketcher-viewer-atto", 100, 100); + sketcherViewer.emptyMessage = "No data loaded"; + sketcherViewer.styles.atoms_displayTerminalCarbonLabels_2D = true; + sketcherViewer.styles.atoms_useJMOLColors = true; + sketcherViewer.styles.bonds_clearOverlaps_2D = true; + sketcher.oldFunc = sketcher.checksOnAction; + sketcher.checksOnAction = function (force) { + this.oldFunc(force); + let mols = sketcher.molecules; + let forms = sketcher.shapes; + sketcherViewer.loadContent(mols, forms); + sketcher.center(); + for (let i = 0, ii = this.molecules.length; i < ii; i++) { + this.molecules[i].check(); + } + }; + } catch (error) { + console.error("Error:", error.message); + } + }; + + init = async() => { + try { + const modal = await Modal.create({ + title: getString('sketchtitle'), + show: true, + removeOnClose: true, + }); + Templates.renderForPromise('tiny_chemdraw/chemTemplate', {}) + .then(async ({ html, js }) => { + Templates.appendNodeContents(modal.getBody(), html, js); + const resources = [ + `${Config.wwwroot}/lib/editor/tiny/plugins/chemdraw/ChemDoodle/install/ChemDoodleWeb.css`, + `${Config.wwwroot}/lib/editor/tiny/plugins/chemdraw/ChemDoodle/install/uis/jquery-ui-1.11.4.css`, + `${Config.wwwroot}/lib/editor/tiny/plugins/chemdraw/ChemDoodle/install/ChemDoodleWeb.js`, + `${Config.wwwroot}/lib/editor/tiny/plugins/chemdraw/ChemDoodle/install/uis/ChemDoodleWeb-uis.js`, + `${Config.wwwroot}/lib/editor/tiny/plugins/chemdraw/chem/chem.css` + ]; + + const types = ["stylesheet", "stylesheet", "script", "script", "stylesheet"]; + + for (let i = 0; i < resources.length; i++) { + await loadResource(resources[i], types[i]); + } + + // Add this line to fix the model width. + window.parent.document.querySelector(".modal-dialog").style.maxWidth = '850px'; + + // Load and run ChemDoodle functionality + await loadAndRunChemDoodle(); + }) + } catch (error) { + displayException(error); + } + }; +} + +export const insert = () => { + if (window.parent.tinyMCE && window.parent.tinyMCE.activeEditor) { + let mol = sketcherViewer.getMolecule(); + let src = ChemDoodle.io.png.string(sketcherViewer); + let molFile = ChemDoodle.writeMOL(mol); + let width = document.getElementById('width_input_molstructure').valueAsNumber; + let height = document.getElementById('height_input_molstructure').valueAsNumber; + var content = + ''; + + window.parent.tinyMCE.activeEditor.execCommand( + "mceInsertContent", + 0, + content + ); + window.parent.tinyMCE.activeEditor.execCommand( + "mceInsertContent", + 0, + "" + ); + var modal = window.parent.document.querySelector('.modal'); + var closeButton = modal.querySelector('.close'); + closeButton.click(); + } + console.log("button Click"); +}; \ No newline at end of file diff --git a/chem/test.js b/chem/test.js new file mode 100644 index 0000000..a969078 --- /dev/null +++ b/chem/test.js @@ -0,0 +1,52 @@ +// This file is part of Moodle - https://moodle.org/ +// +// Moodle is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Moodle is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Moodle. If not, see . + +/** + * Tiny tiny_keteditor for Moodle. + * + * @module tiny_keteditor/plugin + * @copyright 2024 Venkatesan Rangarajan + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +import { getTinyMCE } from "editor_tiny/loader"; +import { getPluginMetadata } from "editor_tiny/utils"; + +import { component, pluginName } from "./common"; +import { register as registerOptions } from "./options"; +import { getSetup as getCommandSetup } from "./commands"; +import * as Configuration from "./configuration"; + +// Setup the tiny_ketcher Plugin. +export default new Promise((resolve) => { + const [tinyMCE, pluginMetadata, setupCommands] = Promise.all([ + getTinyMCE(), + getPluginMetadata(component, pluginName), + getCommandSetup(), + ]); + + tinyMCE.PluginManager.add(pluginName, (editor) => { + // Register any options that your plugin has + registerOptions(editor); + + // Setup any commands such as buttons, menu items, and so on. + setupCommands(editor); + + // Return the pluginMetadata object. This is used by TinyMCE to display a help link for your plugin. + return pluginMetadata; + }); + + resolve([pluginName, Configuration]); +}); diff --git a/lang/en/tiny_chemdraw.php b/lang/en/tiny_chemdraw.php index 0c6899b..88b35bd 100644 --- a/lang/en/tiny_chemdraw.php +++ b/lang/en/tiny_chemdraw.php @@ -25,8 +25,7 @@ defined('MOODLE_INTERNAL') || die(); -$string['pluginname'] = 'Chemical Structure Drawing Tool'; -$string['button_startMolDraw'] = 'Start MOL Draw'; -$string['menuitem_startMolDraw'] = 'Start MOL Draw'; +$string['pluginName'] = 'chemdraw'; +$string['buttonName'] = 'ChemDoodle'; $string['privacy:metadata'] = 'Chemical Structure Editor does not store any personal data'; -$string['sketchtitle'] = 'Chemical Structure Editor'; +$string['sketchTitle'] = 'ChemDoodle Editor'; diff --git a/templates/chemTemplate.mustache b/templates/chemTemplate.mustache new file mode 100644 index 0000000..aa0a2ae --- /dev/null +++ b/templates/chemTemplate.mustache @@ -0,0 +1,43 @@ +{{! + This file is part of Moodle - http://moodle.org/ + + Moodle is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Moodle is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Moodle. If not, see . +}} +{{! + @template tiny_moldraw/chemdoodle_iframe + + Insert ketcher window for chemical structure drawing. + + Example context (json): + { + + } +}} + +
+ +
+

+
+ +
+ +
+ +
+ +
+
+ + diff --git a/templates/moldraw.mustache b/templates/moldraw.mustache deleted file mode 100644 index 93bbaeb..0000000 --- a/templates/moldraw.mustache +++ /dev/null @@ -1,65 +0,0 @@ -{{! - This file is part of Moodle - http://moodle.org/ - - Moodle is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - Moodle is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with Moodle. If not, see . -}} -{{! - @template tiny_moldraw/chemdoodle_iframe - - Insert ketcher window for chemical structure drawing. - - Example context (json): - { - - } -}} - -{{< core/modal }} - {{$title}}{{#str}} sketchtitle {{/str}}{{/title}} - {{$body}} -
- -
-

-
- -
-
- - -

-
- -
- - -

-
-
- -
-

-
- -
- -
- -
- {{/body}} - {{$footer}} - - - {{/footer}} -{{/ core/modal }}