diff --git a/amd/build/constants.min.js b/amd/build/constants.min.js index 5590268..342ce4b 100644 --- a/amd/build/constants.min.js +++ b/amd/build/constants.min.js @@ -1,3 +1,3 @@ -define("tiny_ai/constants",["exports"],(function(_exports){Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.constants=void 0;_exports.constants={modalModes:{selection:"selection",general:"general"},toolPurposeMapping:{audiogen:"tts",summarize:"singleprompt",translate:"translate",describe:"singleprompt",imggen:"imggen",tts:"tts",freeprompt:"singleprompt",describeimg:"itt"}}})); +define("tiny_ai/constants",["exports"],(function(_exports){Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.constants=void 0;_exports.constants={modalModes:{selection:"selection",general:"general"},toolPurposeMapping:{audiogen:"tts",summarize:"singleprompt",translate:"translate",describe:"singleprompt",imggen:"imggen",tts:"tts",freeprompt:"singleprompt",describeimg:"itt",imagetotext:"itt"}}})); //# sourceMappingURL=constants.min.js.map \ No newline at end of file diff --git a/amd/build/constants.min.js.map b/amd/build/constants.min.js.map index e9dd5f4..2eab48b 100644 --- a/amd/build/constants.min.js.map +++ b/amd/build/constants.min.js.map @@ -1 +1 @@ -{"version":3,"file":"constants.min.js","sources":["../src/constants.js"],"sourcesContent":["// This file is part of Moodle - http://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 AI constants definition.\n *\n * @module tiny_ai/constants\n * @copyright 2024, ISB Bayern\n * @author Philipp Memmel\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\n\nexport const constants = {\n modalModes: {\n selection: 'selection',\n general: 'general'\n },\n toolPurposeMapping: {\n audiogen: 'tts',\n summarize: 'singleprompt',\n translate: 'translate',\n describe: 'singleprompt',\n imggen: 'imggen',\n tts: 'tts',\n freeprompt: 'singleprompt',\n describeimg: 'itt'\n }\n};\n"],"names":["modalModes","selection","general","toolPurposeMapping","audiogen","summarize","translate","describe","imggen","tts","freeprompt","describeimg"],"mappings":"gKAyByB,CACrBA,WAAY,CACRC,UAAW,YACXC,QAAS,WAEbC,mBAAoB,CAChBC,SAAU,MACVC,UAAW,eACXC,UAAW,YACXC,SAAU,eACVC,OAAQ,SACRC,IAAK,MACLC,WAAY,eACZC,YAAa"} \ No newline at end of file +{"version":3,"file":"constants.min.js","sources":["../src/constants.js"],"sourcesContent":["// This file is part of Moodle - http://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 AI constants definition.\n *\n * @module tiny_ai/constants\n * @copyright 2024, ISB Bayern\n * @author Philipp Memmel\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\n\nexport const constants = {\n modalModes: {\n selection: 'selection',\n general: 'general'\n },\n toolPurposeMapping: {\n audiogen: 'tts',\n summarize: 'singleprompt',\n translate: 'translate',\n describe: 'singleprompt',\n imggen: 'imggen',\n tts: 'tts',\n freeprompt: 'singleprompt',\n describeimg: 'itt',\n imagetotext: 'itt'\n }\n};\n"],"names":["modalModes","selection","general","toolPurposeMapping","audiogen","summarize","translate","describe","imggen","tts","freeprompt","describeimg","imagetotext"],"mappings":"gKAyByB,CACrBA,WAAY,CACRC,UAAW,YACXC,QAAS,WAEbC,mBAAoB,CAChBC,SAAU,MACVC,UAAW,eACXC,UAAW,YACXC,SAAU,eACVC,OAAQ,SACRC,IAAK,MACLC,WAAY,eACZC,YAAa,MACbC,YAAa"} \ No newline at end of file diff --git a/amd/build/controllers/base.min.js b/amd/build/controllers/base.min.js index 1b7b69e..b407fc4 100644 --- a/amd/build/controllers/base.min.js +++ b/amd/build/controllers/base.min.js @@ -8,6 +8,6 @@ define("tiny_ai/controllers/base",["exports","core/notification","tiny_ai/dataha * @copyright 2024, ISB Bayern * @author Philipp Memmel * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.default=void 0,BasedataHandler=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}(BasedataHandler);return _exports.default=class{constructor(baseSelector){_defineProperty(this,"uniqid",null),_defineProperty(this,"baseElement",null),_defineProperty(this,"renderer",null),_defineProperty(this,"editorUtils",null),_defineProperty(this,"footer",null),this.baseElement=document.querySelector(baseSelector),this.uniqid=(0,_utils.getCurrentModalUniqId)(this.baseElement),this.renderer=(0,_utils.getRenderer)(this.uniqid),this.editorUtils=(0,_utils.getEditorUtils)(this.uniqid),this.datamanager=(0,_utils.getDatamanager)(this.uniqid),null!==this.baseElement&&(this.footer=this.baseElement.parentElement.parentElement.querySelector('[data-region="footer"]'))}async generateAiAnswer(){if(null===this.datamanager.getCurrentPrompt()||0===this.datamanager.getCurrentPrompt().length)return await(0,_utils.errorAlert)(BasedataHandler.getTinyAiString("error_nopromptgiven")),null;await this.renderer.renderLoading();let result=null;try{result=await(0,_utils.getAiAnswer)(this.datamanager.getCurrentPrompt(),_constants.constants.toolPurposeMapping[this.datamanager.getCurrentTool()],this.datamanager.getCurrentOptions())}catch(exception){await(0,_notification.exception)(exception)}return null===result?(await this.callRendererFunction(),null):(this.datamanager.setCurrentAiResult(result),!0)}async callRendererFunction(){if("freeprompt"===this.datamanager.getCurrentTool())return void await this.renderer.renderStart();const toolNameWithUppercaseLetter=this.datamanager.getCurrentTool().charAt(0).toUpperCase()+this.datamanager.getCurrentTool().slice(1);this.renderer["render"+toolNameWithUppercaseLetter]()}},_exports.default})); + */Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.default=void 0,BasedataHandler=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}(BasedataHandler);return _exports.default=class{constructor(baseSelector){_defineProperty(this,"uniqid",null),_defineProperty(this,"baseElement",null),_defineProperty(this,"renderer",null),_defineProperty(this,"editorUtils",null),_defineProperty(this,"footer",null),this.baseElement=document.querySelector(baseSelector),this.uniqid=(0,_utils.getCurrentModalUniqId)(this.baseElement),this.renderer=(0,_utils.getRenderer)(this.uniqid),this.editorUtils=(0,_utils.getEditorUtils)(this.uniqid),this.datamanager=(0,_utils.getDatamanager)(this.uniqid),null!==this.baseElement&&(this.footer=this.baseElement.parentElement.parentElement.querySelector('[data-region="footer"]'))}async generateAiAnswer(){if(null===this.datamanager.getCurrentPrompt()||0===this.datamanager.getCurrentPrompt().length)return await(0,_utils.errorAlert)(BasedataHandler.getTinyAiString("error_nopromptgiven")),null;if(["describeimg","imagetotext"].includes(this.datamanager.getCurrentTool())&&null===this.datamanager.getCurrentFile())return await(0,_utils.errorAlert)(BasedataHandler.getTinyAiString("error_nofile")),null;await this.renderer.renderLoading();let result=null;try{result=await(0,_utils.getAiAnswer)(this.datamanager.getCurrentPrompt(),_constants.constants.toolPurposeMapping[this.datamanager.getCurrentTool()],this.datamanager.getCurrentOptions())}catch(exception){await(0,_notification.exception)(exception)}return null===result?(await this.callRendererFunction(),null):(this.datamanager.setCurrentAiResult(result),!0)}async callRendererFunction(){if("freeprompt"===this.datamanager.getCurrentTool())return void await this.renderer.renderStart();const toolNameWithUppercaseLetter=this.datamanager.getCurrentTool().charAt(0).toUpperCase()+this.datamanager.getCurrentTool().slice(1);this.renderer["render"+toolNameWithUppercaseLetter]()}},_exports.default})); //# sourceMappingURL=base.min.js.map \ No newline at end of file diff --git a/amd/build/controllers/base.min.js.map b/amd/build/controllers/base.min.js.map index 5ee45b6..d887b2f 100644 --- a/amd/build/controllers/base.min.js.map +++ b/amd/build/controllers/base.min.js.map @@ -1 +1 @@ -{"version":3,"file":"base.min.js","sources":["../../src/controllers/base.js"],"sourcesContent":["// This file is part of Moodle - http://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\nimport {exception as displayException} from 'core/notification';\nimport * as BasedataHandler from 'tiny_ai/datahandler/basedata';\nimport {getRenderer, getDatamanager, getAiAnswer, errorAlert, getCurrentModalUniqId, getEditorUtils} from 'tiny_ai/utils';\nimport {constants} from 'tiny_ai/constants';\n\n/**\n * Base controller class providing some basic functionalities.\n *\n * All tiny_ai controllers should inherit from this class.\n *\n * @module tiny_ai/controllers/base\n * @copyright 2024, ISB Bayern\n * @author Philipp Memmel\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\nexport default class {\n\n uniqid = null;\n baseElement = null;\n renderer = null;\n editorUtils = null;\n footer = null;\n\n constructor(baseSelector) {\n this.baseElement = document.querySelector(baseSelector);\n this.uniqid = getCurrentModalUniqId(this.baseElement);\n this.renderer = getRenderer(this.uniqid);\n this.editorUtils = getEditorUtils(this.uniqid);\n this.datamanager = getDatamanager(this.uniqid);\n\n if (this.baseElement === null) {\n // Sometimes (for example we display an error message before we even finish rendering the modal) we do not have\n // a base element. In this case there is nothing to do, so we avoid console errors by early exiting.\n return;\n }\n this.footer = this.baseElement.parentElement.parentElement.querySelector('[data-region=\"footer\"]');\n }\n\n async generateAiAnswer() {\n if (this.datamanager.getCurrentPrompt() === null || this.datamanager.getCurrentPrompt().length === 0) {\n await errorAlert(BasedataHandler.getTinyAiString('error_nopromptgiven'));\n return null;\n }\n await this.renderer.renderLoading();\n let result = null;\n try {\n result = await getAiAnswer(this.datamanager.getCurrentPrompt(),\n constants.toolPurposeMapping[this.datamanager.getCurrentTool()], this.datamanager.getCurrentOptions());\n } catch (exception) {\n await displayException(exception);\n }\n\n if (result === null) {\n await this.callRendererFunction();\n return null;\n }\n this.datamanager.setCurrentAiResult(result);\n return true;\n }\n\n async callRendererFunction() {\n if (this.datamanager.getCurrentTool() === 'freeprompt') {\n await this.renderer.renderStart();\n return;\n }\n const toolNameWithUppercaseLetter =\n this.datamanager.getCurrentTool().charAt(0).toUpperCase() + this.datamanager.getCurrentTool().slice(1);\n this.renderer['render' + toolNameWithUppercaseLetter]();\n }\n}\n"],"names":["constructor","baseSelector","baseElement","document","querySelector","uniqid","this","renderer","editorUtils","datamanager","footer","parentElement","getCurrentPrompt","length","BasedataHandler","getTinyAiString","renderLoading","result","constants","toolPurposeMapping","getCurrentTool","getCurrentOptions","exception","callRendererFunction","setCurrentAiResult","renderStart","toolNameWithUppercaseLetter","charAt","toUpperCase","slice"],"mappings":";;;;;;;;;;iyBAsCIA,YAAYC,4CANH,yCACK,sCACH,yCACG,oCACL,WAGAC,YAAcC,SAASC,cAAcH,mBACrCI,QAAS,gCAAsBC,KAAKJ,kBACpCK,UAAW,sBAAYD,KAAKD,aAC5BG,aAAc,yBAAeF,KAAKD,aAClCI,aAAc,yBAAeH,KAAKD,QAEd,OAArBC,KAAKJ,mBAKJQ,OAASJ,KAAKJ,YAAYS,cAAcA,cAAcP,cAAc,uDAI7B,OAAxCE,KAAKG,YAAYG,oBAA8E,IAA/CN,KAAKG,YAAYG,mBAAmBC,oBAC9E,qBAAWC,gBAAgBC,gBAAgB,wBAC1C,WAELT,KAAKC,SAASS,oBAChBC,OAAS,SAETA,aAAe,sBAAYX,KAAKG,YAAYG,mBACxCM,qBAAUC,mBAAmBb,KAAKG,YAAYW,kBAAmBd,KAAKG,YAAYY,qBACxF,MAAOC,iBACC,2BAAiBA,kBAGZ,OAAXL,cACMX,KAAKiB,uBACJ,YAENd,YAAYe,mBAAmBP,SAC7B,mCAImC,eAAtCX,KAAKG,YAAYW,mCACXd,KAAKC,SAASkB,oBAGlBC,4BACFpB,KAAKG,YAAYW,iBAAiBO,OAAO,GAAGC,cAAgBtB,KAAKG,YAAYW,iBAAiBS,MAAM,QACnGtB,SAAS,SAAWmB"} \ No newline at end of file +{"version":3,"file":"base.min.js","sources":["../../src/controllers/base.js"],"sourcesContent":["// This file is part of Moodle - http://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\nimport {exception as displayException} from 'core/notification';\nimport * as BasedataHandler from 'tiny_ai/datahandler/basedata';\nimport {getRenderer, getDatamanager, getAiAnswer, errorAlert, getCurrentModalUniqId, getEditorUtils} from 'tiny_ai/utils';\nimport {constants} from 'tiny_ai/constants';\n\n/**\n * Base controller class providing some basic functionalities.\n *\n * All tiny_ai controllers should inherit from this class.\n *\n * @module tiny_ai/controllers/base\n * @copyright 2024, ISB Bayern\n * @author Philipp Memmel\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\nexport default class {\n\n uniqid = null;\n baseElement = null;\n renderer = null;\n editorUtils = null;\n footer = null;\n\n constructor(baseSelector) {\n this.baseElement = document.querySelector(baseSelector);\n this.uniqid = getCurrentModalUniqId(this.baseElement);\n this.renderer = getRenderer(this.uniqid);\n this.editorUtils = getEditorUtils(this.uniqid);\n this.datamanager = getDatamanager(this.uniqid);\n\n if (this.baseElement === null) {\n // Sometimes (for example we display an error message before we even finish rendering the modal) we do not have\n // a base element. In this case there is nothing to do, so we avoid console errors by early exiting.\n return;\n }\n this.footer = this.baseElement.parentElement.parentElement.querySelector('[data-region=\"footer\"]');\n }\n\n async generateAiAnswer() {\n if (this.datamanager.getCurrentPrompt() === null || this.datamanager.getCurrentPrompt().length === 0) {\n await errorAlert(BasedataHandler.getTinyAiString('error_nopromptgiven'));\n return null;\n }\n if (['describeimg', 'imagetotext'].includes(this.datamanager.getCurrentTool())\n && this.datamanager.getCurrentFile() === null) {\n await errorAlert(BasedataHandler.getTinyAiString('error_nofile'));\n return null;\n }\n await this.renderer.renderLoading();\n let result = null;\n try {\n result = await getAiAnswer(this.datamanager.getCurrentPrompt(),\n constants.toolPurposeMapping[this.datamanager.getCurrentTool()], this.datamanager.getCurrentOptions());\n } catch (exception) {\n await displayException(exception);\n }\n\n if (result === null) {\n await this.callRendererFunction();\n return null;\n }\n this.datamanager.setCurrentAiResult(result);\n return true;\n }\n\n async callRendererFunction() {\n if (this.datamanager.getCurrentTool() === 'freeprompt') {\n await this.renderer.renderStart();\n return;\n }\n const toolNameWithUppercaseLetter =\n this.datamanager.getCurrentTool().charAt(0).toUpperCase() + this.datamanager.getCurrentTool().slice(1);\n this.renderer['render' + toolNameWithUppercaseLetter]();\n }\n}\n"],"names":["constructor","baseSelector","baseElement","document","querySelector","uniqid","this","renderer","editorUtils","datamanager","footer","parentElement","getCurrentPrompt","length","BasedataHandler","getTinyAiString","includes","getCurrentTool","getCurrentFile","renderLoading","result","constants","toolPurposeMapping","getCurrentOptions","exception","callRendererFunction","setCurrentAiResult","renderStart","toolNameWithUppercaseLetter","charAt","toUpperCase","slice"],"mappings":";;;;;;;;;;iyBAsCIA,YAAYC,4CANH,yCACK,sCACH,yCACG,oCACL,WAGAC,YAAcC,SAASC,cAAcH,mBACrCI,QAAS,gCAAsBC,KAAKJ,kBACpCK,UAAW,sBAAYD,KAAKD,aAC5BG,aAAc,yBAAeF,KAAKD,aAClCI,aAAc,yBAAeH,KAAKD,QAEd,OAArBC,KAAKJ,mBAKJQ,OAASJ,KAAKJ,YAAYS,cAAcA,cAAcP,cAAc,uDAI7B,OAAxCE,KAAKG,YAAYG,oBAA8E,IAA/CN,KAAKG,YAAYG,mBAAmBC,oBAC9E,qBAAWC,gBAAgBC,gBAAgB,wBAC1C,QAEP,CAAC,cAAe,eAAeC,SAASV,KAAKG,YAAYQ,mBACZ,OAAtCX,KAAKG,YAAYS,8BAClB,qBAAWJ,gBAAgBC,gBAAgB,iBAC1C,WAELT,KAAKC,SAASY,oBAChBC,OAAS,SAETA,aAAe,sBAAYd,KAAKG,YAAYG,mBACxCS,qBAAUC,mBAAmBhB,KAAKG,YAAYQ,kBAAmBX,KAAKG,YAAYc,qBACxF,MAAOC,iBACC,2BAAiBA,kBAGZ,OAAXJ,cACMd,KAAKmB,uBACJ,YAENhB,YAAYiB,mBAAmBN,SAC7B,mCAImC,eAAtCd,KAAKG,YAAYQ,mCACXX,KAAKC,SAASoB,oBAGlBC,4BACFtB,KAAKG,YAAYQ,iBAAiBY,OAAO,GAAGC,cAAgBxB,KAAKG,YAAYQ,iBAAiBc,MAAM,QACnGxB,SAAS,SAAWqB"} \ No newline at end of file diff --git a/amd/build/controllers/file.min.js b/amd/build/controllers/file.min.js new file mode 100644 index 0000000..41a9d95 --- /dev/null +++ b/amd/build/controllers/file.min.js @@ -0,0 +1,3 @@ +define("tiny_ai/controllers/file",["exports","tiny_ai/utils","core/templates","tiny_ai/selectors","tiny_ai/datahandler/basedata"],(function(_exports,_utils,_templates,_selectors,BasedataHandler){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)}function _interopRequireDefault(obj){return obj&&obj.__esModule?obj:{default:obj}}Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.default=void 0,_templates=_interopRequireDefault(_templates),_selectors=_interopRequireDefault(_selectors),BasedataHandler=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}(BasedataHandler);return _exports.default=class{constructor(baseSelector){var obj,key,value;value=null,(key="dropzone")in(obj=this)?Object.defineProperty(obj,key,{value:value,enumerable:!0,configurable:!0,writable:!0}):obj[key]=value,this.baseElement=document.querySelector(baseSelector)}async init(){this.dropzone=this.baseElement.querySelector('[data-type="dropzone"]');const dropzone=this.dropzone;dropzone.contentEditable=!0,dropzone.addEventListener("drop",(async event=>{if(event.preventDefault(),dropzone.classList.remove("tiny_ai_dragover"),dropzone.classList.add("tiny_ai_dropzone_filled"),event.dataTransfer.items){const item=[...event.dataTransfer.items].shift();"file"===item.kind&&await this.handleFile(item.getAsFile())}else await this.handleFile([...event.dataTransfer.files].shift())})),document.querySelector(_selectors.default.modalDialog).addEventListener("paste",(async event=>{event.preventDefault();const clipboardData=event.clipboardData||window.clipboardData;if(console.log(clipboardData),0===clipboardData.files.length)return void await(0,_utils.errorAlert)(BasedataHandler.getTinyAiString("error_nofileinclipboard_text"),BasedataHandler.getTinyAiString("error_nofileinclipboard_title"));dropzone.classList.remove("tiny_ai_dragover"),dropzone.classList.add("tiny_ai_dropzone_filled");const file=clipboardData.files[0];this.handleFile(file)})),dropzone.addEventListener("dragover",(event=>{event.preventDefault(),console.log(event),dropzone.classList.remove("tiny_ai_dropzone_filled"),dropzone.classList.add("tiny_ai_dragover")})),dropzone.addEventListener("dragleave",(event=>{event.preventDefault(),console.log(event),dropzone.classList.remove("tiny_ai_dragover")}))}async handleFile(file){const reader=new FileReader;console.log(file),reader.addEventListener("load",(async()=>{const datamanager=(0,_utils.getDatamanager)((0,_utils.getCurrentModalUniqId)(this.baseElement)),fileUploadedEvent=new CustomEvent("fileUploaded",{detail:{newFile:reader.result}});datamanager.getEventEmitterElement().dispatchEvent(fileUploadedEvent);const fileEntryTemplateContext={icon:"application/pdf"===file.type?"fa-file-pdf":"fa-image",filename:file.name};file.type.startsWith("image")&&(fileEntryTemplateContext.isImage=!0,fileEntryTemplateContext.dataurl=reader.result);const{html:html,js:js}=await _templates.default.renderForPromise("tiny_ai/components/ai-file-list-entry",fileEntryTemplateContext);_templates.default.replaceNodeContents(this.dropzone,html,js)}),!1),reader.readAsDataURL(file)}},_exports.default})); + +//# sourceMappingURL=file.min.js.map \ No newline at end of file diff --git a/amd/build/controllers/file.min.js.map b/amd/build/controllers/file.min.js.map new file mode 100644 index 0000000..d308ef1 --- /dev/null +++ b/amd/build/controllers/file.min.js.map @@ -0,0 +1 @@ +{"version":3,"file":"file.min.js","sources":["../../src/controllers/file.js"],"sourcesContent":["// This file is part of Moodle - http://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 * Controller for handling the show/hide prompt button and the associated textarea.\n *\n * @module tiny_ai/controllers/dnd\n * @copyright 2024, ISB Bayern\n * @author Philipp Memmel\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nimport {getDatamanager, getCurrentModalUniqId} from 'tiny_ai/utils';\nimport Templates from 'core/templates';\nimport SELECTORS from 'tiny_ai/selectors';\nimport {errorAlert} from 'tiny_ai/utils';\nimport * as BasedataHandler from 'tiny_ai/datahandler/basedata';\n\n\nexport default class {\n\n dropzone = null;\n\n constructor(baseSelector) {\n this.baseElement = document.querySelector(baseSelector);\n }\n\n async init() {\n this.dropzone = this.baseElement.querySelector('[data-type=\"dropzone\"]');\n const dropzone = this.dropzone;\n // Setting contentEditable to true makes the browser show a \"paste\" option in the context menu when\n // right-clicking the drop zone.\n dropzone.contentEditable = true;\n\n dropzone.addEventListener('drop', async(event) => {\n event.preventDefault();\n dropzone.classList.remove('tiny_ai_dragover');\n dropzone.classList.add('tiny_ai_dropzone_filled');\n\n if (event.dataTransfer.items) {\n // Use DataTransferItemList interface to access the file(s)\n const item = [...event.dataTransfer.items].shift();\n // If dropped item is no file, reject it.\n if (item.kind === 'file') {\n await this.handleFile(item.getAsFile());\n }\n } else {\n // Use DataTransfer interface to access the file(s)\n await this.handleFile([...event.dataTransfer.files].shift());\n }\n });\n document.querySelector(SELECTORS.modalDialog).addEventListener('paste', async(event) => {\n event.preventDefault();\n const clipboardData = (event.clipboardData || window.clipboardData);\n console.log(clipboardData)\n if (clipboardData.files.length === 0) {\n await errorAlert(BasedataHandler.getTinyAiString('error_nofileinclipboard_text'),\n BasedataHandler.getTinyAiString('error_nofileinclipboard_title'));\n return;\n }\n // There should be no tiny_ai_dragover class, just to be safe.\n dropzone.classList.remove('tiny_ai_dragover');\n dropzone.classList.add('tiny_ai_dropzone_filled');\n const file = clipboardData.files[0];\n this.handleFile(file);\n });\n dropzone.addEventListener('dragover', (event) => {\n event.preventDefault();\n console.log(event)\n dropzone.classList.remove('tiny_ai_dropzone_filled');\n dropzone.classList.add('tiny_ai_dragover');\n });\n dropzone.addEventListener('dragleave', (event) => {\n event.preventDefault();\n console.log(event)\n dropzone.classList.remove('tiny_ai_dragover');\n });\n }\n\n async handleFile(file) {\n const reader = new FileReader();\n console.log(file)\n reader.addEventListener(\n 'load',\n async() => {\n const datamanager = getDatamanager(getCurrentModalUniqId(this.baseElement));\n const fileUploadedEvent = new CustomEvent('fileUploaded', {\n detail: {\n newFile: reader.result\n }\n });\n datamanager.getEventEmitterElement().dispatchEvent(fileUploadedEvent);\n const fileEntryTemplateContext = {\n icon: file.type === 'application/pdf' ? 'fa-file-pdf' : 'fa-image',\n filename: file.name,\n };\n if (file.type.startsWith('image')) {\n fileEntryTemplateContext.isImage = true;\n fileEntryTemplateContext.dataurl = reader.result;\n }\n const {html, js} = await Templates.renderForPromise('tiny_ai/components/ai-file-list-entry',\n fileEntryTemplateContext);\n Templates.replaceNodeContents(this.dropzone, html, js);\n },\n false,\n );\n reader.readAsDataURL(file);\n }\n}\n"],"names":["constructor","baseSelector","baseElement","document","querySelector","dropzone","this","contentEditable","addEventListener","async","event","preventDefault","classList","remove","add","dataTransfer","items","item","shift","kind","handleFile","getAsFile","files","SELECTORS","modalDialog","clipboardData","window","console","log","length","BasedataHandler","getTinyAiString","file","reader","FileReader","datamanager","fileUploadedEvent","CustomEvent","detail","newFile","result","getEventEmitterElement","dispatchEvent","fileEntryTemplateContext","icon","type","filename","name","startsWith","isImage","dataurl","html","js","Templates","renderForPromise","replaceNodeContents","readAsDataURL"],"mappings":"g6CAmCIA,YAAYC,sCAFD,6IAGFC,YAAcC,SAASC,cAAcH,gCAIrCI,SAAWC,KAAKJ,YAAYE,cAAc,gCACzCC,SAAWC,KAAKD,SAGtBA,SAASE,iBAAkB,EAE3BF,SAASG,iBAAiB,QAAQC,MAAAA,WAC9BC,MAAMC,iBACNN,SAASO,UAAUC,OAAO,oBAC1BR,SAASO,UAAUE,IAAI,2BAEnBJ,MAAMK,aAAaC,MAAO,OAEpBC,KAAO,IAAIP,MAAMK,aAAaC,OAAOE,QAEzB,SAAdD,KAAKE,YACCb,KAAKc,WAAWH,KAAKI,wBAIzBf,KAAKc,WAAW,IAAIV,MAAMK,aAAaO,OAAOJ,YAG5Df,SAASC,cAAcmB,mBAAUC,aAAahB,iBAAiB,SAASC,MAAAA,QACpEC,MAAMC,uBACAc,cAAiBf,MAAMe,eAAiBC,OAAOD,iBACrDE,QAAQC,IAAIH,eACuB,IAA/BA,cAAcH,MAAMO,yBACd,qBAAWC,gBAAgBC,gBAAgB,gCAC7CD,gBAAgBC,gBAAgB,kCAIxC1B,SAASO,UAAUC,OAAO,oBAC1BR,SAASO,UAAUE,IAAI,iCACjBkB,KAAOP,cAAcH,MAAM,QAC5BF,WAAWY,SAEpB3B,SAASG,iBAAiB,YAAaE,QACnCA,MAAMC,iBACNgB,QAAQC,IAAIlB,OACZL,SAASO,UAAUC,OAAO,2BAC1BR,SAASO,UAAUE,IAAI,uBAE3BT,SAASG,iBAAiB,aAAcE,QACpCA,MAAMC,iBACNgB,QAAQC,IAAIlB,OACZL,SAASO,UAAUC,OAAO,wCAIjBmB,YACPC,OAAS,IAAIC,WACXP,QAAQC,IAAII,MACpBC,OAAOzB,iBACH,QACAC,gBACU0B,aAAc,0BAAe,gCAAsB7B,KAAKJ,cACxDkC,kBAAoB,IAAIC,YAAY,eAAgB,CACtDC,OAAQ,CACJC,QAASN,OAAOO,UAGxBL,YAAYM,yBAAyBC,cAAcN,yBAC7CO,yBAA2B,CAC7BC,KAAoB,oBAAdZ,KAAKa,KAA6B,cAAgB,WACxDC,SAAUd,KAAKe,MAEff,KAAKa,KAAKG,WAAW,WACrBL,yBAAyBM,SAAU,EACnCN,yBAAyBO,QAAUjB,OAAOO,cAExCW,KAACA,KAADC,GAAOA,UAAYC,mBAAUC,iBAAiB,wCAChDX,6CACMY,oBAAoBjD,KAAKD,SAAU8C,KAAMC,OAEvD,GAEJnB,OAAOuB,cAAcxB"} \ No newline at end of file diff --git a/amd/build/controllers/filednd.min.js b/amd/build/controllers/filednd.min.js deleted file mode 100644 index 490ebf4..0000000 --- a/amd/build/controllers/filednd.min.js +++ /dev/null @@ -1,12 +0,0 @@ -define("tiny_ai/controllers/filednd",["exports","core/str","tiny_ai/utils"],(function(_exports,_str,_utils){Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.default=void 0;return _exports.default= -/** - * Controller for handling the show/hide prompt button and the associated textarea. - * - * @module tiny_ai/controllers/dnd - * @copyright 2024, ISB Bayern - * @author Philipp Memmel - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ -class{constructor(baseSelector){this.baseElement=document.querySelector(baseSelector)}async init(){const dropzone=this.baseElement.querySelector('[data-type="dropzone"]');dropzone.addEventListener("drop",(event=>{if(event.preventDefault(),event.dataTransfer.items){const item=[...event.dataTransfer.items].shift();"file"===item.kind&&this.handleFile(item)}else this.handleFile([...event.dataTransfer.files].shift())})),dropzone.addEventListener("dragover",(event=>{event.preventDefault()}))}handleFile(file){file=file.getAsFile();const reader=new FileReader;reader.addEventListener("load",(()=>{const datamanager=(0,_utils.getDatamanager)((0,_utils.getCurrentModalUniqId)(this.baseElement)),fileUploadedEvent=new CustomEvent("fileUploaded",{detail:{newFile:reader.result}});datamanager.getEventEmitterElement().dispatchEvent(fileUploadedEvent)}),!1),reader.readAsDataURL(file)}},_exports.default})); - -//# sourceMappingURL=filednd.min.js.map \ No newline at end of file diff --git a/amd/build/controllers/filednd.min.js.map b/amd/build/controllers/filednd.min.js.map deleted file mode 100644 index 8f091a3..0000000 --- a/amd/build/controllers/filednd.min.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"filednd.min.js","sources":["../../src/controllers/filednd.js"],"sourcesContent":["// This file is part of Moodle - http://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 * Controller for handling the show/hide prompt button and the associated textarea.\n *\n * @module tiny_ai/controllers/dnd\n * @copyright 2024, ISB Bayern\n * @author Philipp Memmel\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nimport {getStrings} from 'core/str';\nimport {getDatamanager, getCurrentModalUniqId, getIttHandler} from 'tiny_ai/utils';\n\nexport default class {\n\n constructor(baseSelector) {\n this.baseElement = document.querySelector(baseSelector);\n }\n\n async init() {\n const dropzone = this.baseElement.querySelector('[data-type=\"dropzone\"]');\n dropzone.addEventListener('drop', (event) => {\n event.preventDefault();\n if (event.dataTransfer.items) {\n // Use DataTransferItemList interface to access the file(s)\n const item = [...event.dataTransfer.items].shift();\n // If dropped item is no file, reject it.\n if (item.kind === 'file') {\n this.handleFile(item);\n }\n } else {\n // Use DataTransfer interface to access the file(s)\n this.handleFile([...event.dataTransfer.files].shift());\n }\n });\n dropzone.addEventListener('dragover', (event) => {\n event.preventDefault();\n });\n }\n\n handleFile(file) {\n file = file.getAsFile();\n const reader = new FileReader();\n reader.addEventListener(\n 'load',\n () => {\n const datamanager = getDatamanager(getCurrentModalUniqId(this.baseElement));\n const fileUploadedEvent = new CustomEvent('fileUploaded', {\n detail: {\n newFile: reader.result\n }\n });\n datamanager.getEventEmitterElement().dispatchEvent(fileUploadedEvent);\n },\n false,\n );\n reader.readAsDataURL(file);\n }\n}\n"],"names":["constructor","baseSelector","baseElement","document","querySelector","dropzone","this","addEventListener","event","preventDefault","dataTransfer","items","item","shift","kind","handleFile","files","file","getAsFile","reader","FileReader","datamanager","fileUploadedEvent","CustomEvent","detail","newFile","result","getEventEmitterElement","dispatchEvent","readAsDataURL"],"mappings":";;;;;;;;;MA6BIA,YAAYC,mBACHC,YAAcC,SAASC,cAAcH,iCAIpCI,SAAWC,KAAKJ,YAAYE,cAAc,0BAChDC,SAASE,iBAAiB,QAASC,WAC/BA,MAAMC,iBACFD,MAAME,aAAaC,MAAO,OAEpBC,KAAO,IAAIJ,MAAME,aAAaC,OAAOE,QAEzB,SAAdD,KAAKE,WACAC,WAAWH,gBAIfG,WAAW,IAAIP,MAAME,aAAaM,OAAOH,YAGtDR,SAASE,iBAAiB,YAAaC,QACnCA,MAAMC,oBAIdM,WAAWE,MACPA,KAAOA,KAAKC,kBACNC,OAAS,IAAIC,WACnBD,OAAOZ,iBACH,QACA,WACUc,aAAc,0BAAe,gCAAsBf,KAAKJ,cACxDoB,kBAAoB,IAAIC,YAAY,eAAgB,CACtDC,OAAQ,CACJC,QAASN,OAAOO,UAGxBL,YAAYM,yBAAyBC,cAAcN,sBAEvD,GAEJH,OAAOU,cAAcZ"} \ No newline at end of file diff --git a/amd/build/controllers/preferences.min.js b/amd/build/controllers/preferences.min.js index 8875c58..85711c5 100644 --- a/amd/build/controllers/preferences.min.js +++ b/amd/build/controllers/preferences.min.js @@ -6,6 +6,6 @@ define("tiny_ai/controllers/preferences",["exports","tiny_ai/constants","tiny_ai * @copyright 2024, ISB Bayern * @author Philipp Memmel * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.default=void 0,_selectors=_interopRequireDefault(_selectors),_base=_interopRequireDefault(_base);class _default extends _base.default{async init(){const modalFooter=document.querySelector(_selectors.default.modalFooter),backButton=modalFooter.querySelector('[data-action="back"]'),generateButton=modalFooter.querySelector('[data-action="generate"]'),[summarizeHandler,translateHandler,ttsHandler,imggenHandler,ittHandler]=[(0,_utils.getSummarizeHandler)(this.uniqid),(0,_utils.getTranslateHandler)(this.uniqid),(0,_utils.getTtsHandler)(this.uniqid),(0,_utils.getImggenHandler)(this.uniqid),(0,_utils.getIttHandler)(this.uniqid)];switch(this.datamanager.getCurrentTool()){case"summarize":case"describe":{summarizeHandler.setTool(this.datamanager.getCurrentTool());const maxWordCountElement=this.baseElement.querySelector('[data-preference="maxWordCount"]'),languageTypeElement=this.baseElement.querySelector('[data-preference="languageType"]');summarizeHandler.setMaxWordCount(maxWordCountElement.querySelector('[data-dropdown="select"]').dataset.value),summarizeHandler.setLanguageType(languageTypeElement.querySelector('[data-dropdown="select"]').dataset.value);const currentPromptSummarize=await summarizeHandler.getPrompt(this.datamanager.getSelectionText());this.datamanager.setCurrentPrompt(currentPromptSummarize),maxWordCountElement.addEventListener("dropdownSelectionUpdated",(async event=>{summarizeHandler.setMaxWordCount(event.detail.newValue);const currentPrompt=await summarizeHandler.getPrompt(this.datamanager.getSelectionText());this.datamanager.setCurrentPrompt(currentPrompt)})),languageTypeElement.addEventListener("dropdownSelectionUpdated",(async event=>{summarizeHandler.setLanguageType(event.detail.newValue);const currentPrompt=await summarizeHandler.getPrompt(this.datamanager.getSelectionText());this.datamanager.setCurrentPrompt(currentPrompt)}));break}case"translate":{const targetLanguageElement=this.baseElement.querySelector('[data-preference="targetLanguage"]');translateHandler.setTargetLanguage(targetLanguageElement.querySelector('[data-dropdown="select"]').dataset.value);const currentPromptTranslate=await translateHandler.getPrompt(this.datamanager.getSelectionText());this.datamanager.setCurrentPrompt(currentPromptTranslate),targetLanguageElement.addEventListener("dropdownSelectionUpdated",(async event=>{translateHandler.setTargetLanguage(event.detail.newValue);const currentPromptTranslate=await translateHandler.getPrompt(this.datamanager.getSelectionText());this.datamanager.setCurrentPrompt(currentPromptTranslate)}));break}case"tts":case"audiogen":{const ttsTargetLanguageElement=this.baseElement.querySelector('[data-preference="targetLanguage"]'),voiceElement=this.baseElement.querySelector('[data-preference="voice"]'),genderElement=this.baseElement.querySelector('[data-preference="gender"]');ttsTargetLanguageElement&&(ttsHandler.setTargetLanguage(ttsTargetLanguageElement.querySelector('[data-dropdown="select"]').dataset.value),ttsTargetLanguageElement.addEventListener("dropdownSelectionUpdated",(event=>{ttsHandler.setTargetLanguage(event.detail.newValue),this.datamanager.setCurrentOptions(ttsHandler.getOptions())}))),voiceElement&&(ttsHandler.setVoice(voiceElement.querySelector('[data-dropdown="select"]').dataset.value),voiceElement.addEventListener("dropdownSelectionUpdated",(event=>{ttsHandler.setVoice(event.detail.newValue),this.datamanager.setCurrentOptions(ttsHandler.getOptions())}))),genderElement&&(ttsHandler.setGender(genderElement.querySelector('[data-dropdown="select"]').dataset.value),genderElement.addEventListener("dropdownSelectionUpdated",(event=>{ttsHandler.setGender(event.detail.newValue),this.datamanager.setCurrentOptions(ttsHandler.getOptions())}))),this.datamanager.setCurrentPrompt(ttsHandler.getPrompt(this.datamanager.getCurrentTool(),this.datamanager.getSelectionText())),this.datamanager.setCurrentOptions(ttsHandler.getOptions());break}case"imggen":{const sizesElement=this.baseElement.querySelector('[data-preference="sizes"]');sizesElement&&(imggenHandler.setSize(sizesElement.querySelector('[data-dropdown="select"]').dataset.value),sizesElement.addEventListener("dropdownSelectionUpdated",(event=>{imggenHandler.setSize(event.detail.newValue),this.datamanager.setCurrentOptions(imggenHandler.getOptions())}))),this.datamanager.setCurrentPrompt(""),this.datamanager.setCurrentOptions(imggenHandler.getOptions());break}case"describeimg":this.baseElement.querySelector('[data-preference="fileupload"]')&&this.datamanager.getEventEmitterElement().addEventListener("fileUploaded",(event=>{this.datamanager.setCurrentFile(event.detail.newFile),this.datamanager.setCurrentOptions(ittHandler.getOptions())})),this.datamanager.setCurrentPrompt(""),this.datamanager.setCurrentFile(null);break}backButton&&backButton.addEventListener("click",(async()=>{await this.renderer.renderStart(_constants.constants.modalModes.selection)})),generateButton&&generateButton.addEventListener("click",(async()=>{null!==await this.generateAiAnswer()&&await this.renderer.renderSuggestion()}))}}return _exports.default=_default,_exports.default})); + */Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.default=void 0,_selectors=_interopRequireDefault(_selectors),_base=_interopRequireDefault(_base);class _default extends _base.default{async init(){const modalFooter=document.querySelector(_selectors.default.modalFooter),backButton=modalFooter.querySelector('[data-action="back"]'),generateButton=modalFooter.querySelector('[data-action="generate"]'),[summarizeHandler,translateHandler,ttsHandler,imggenHandler,ittHandler]=[(0,_utils.getSummarizeHandler)(this.uniqid),(0,_utils.getTranslateHandler)(this.uniqid),(0,_utils.getTtsHandler)(this.uniqid),(0,_utils.getImggenHandler)(this.uniqid),(0,_utils.getIttHandler)(this.uniqid)];switch(this.datamanager.getCurrentTool()){case"summarize":case"describe":{summarizeHandler.setTool(this.datamanager.getCurrentTool());const maxWordCountElement=this.baseElement.querySelector('[data-preference="maxWordCount"]'),languageTypeElement=this.baseElement.querySelector('[data-preference="languageType"]');summarizeHandler.setMaxWordCount(maxWordCountElement.querySelector('[data-dropdown="select"]').dataset.value),summarizeHandler.setLanguageType(languageTypeElement.querySelector('[data-dropdown="select"]').dataset.value);const currentPromptSummarize=await summarizeHandler.getPrompt(this.datamanager.getSelectionText());this.datamanager.setCurrentPrompt(currentPromptSummarize),maxWordCountElement.addEventListener("dropdownSelectionUpdated",(async event=>{summarizeHandler.setMaxWordCount(event.detail.newValue);const currentPrompt=await summarizeHandler.getPrompt(this.datamanager.getSelectionText());this.datamanager.setCurrentPrompt(currentPrompt)})),languageTypeElement.addEventListener("dropdownSelectionUpdated",(async event=>{summarizeHandler.setLanguageType(event.detail.newValue);const currentPrompt=await summarizeHandler.getPrompt(this.datamanager.getSelectionText());this.datamanager.setCurrentPrompt(currentPrompt)}));break}case"translate":{const targetLanguageElement=this.baseElement.querySelector('[data-preference="targetLanguage"]');translateHandler.setTargetLanguage(targetLanguageElement.querySelector('[data-dropdown="select"]').dataset.value);const currentPromptTranslate=await translateHandler.getPrompt(this.datamanager.getSelectionText());this.datamanager.setCurrentPrompt(currentPromptTranslate),targetLanguageElement.addEventListener("dropdownSelectionUpdated",(async event=>{translateHandler.setTargetLanguage(event.detail.newValue);const currentPromptTranslate=await translateHandler.getPrompt(this.datamanager.getSelectionText());this.datamanager.setCurrentPrompt(currentPromptTranslate)}));break}case"tts":case"audiogen":{const ttsTargetLanguageElement=this.baseElement.querySelector('[data-preference="targetLanguage"]'),voiceElement=this.baseElement.querySelector('[data-preference="voice"]'),genderElement=this.baseElement.querySelector('[data-preference="gender"]');ttsTargetLanguageElement&&(ttsHandler.setTargetLanguage(ttsTargetLanguageElement.querySelector('[data-dropdown="select"]').dataset.value),ttsTargetLanguageElement.addEventListener("dropdownSelectionUpdated",(event=>{ttsHandler.setTargetLanguage(event.detail.newValue),this.datamanager.setCurrentOptions(ttsHandler.getOptions())}))),voiceElement&&(ttsHandler.setVoice(voiceElement.querySelector('[data-dropdown="select"]').dataset.value),voiceElement.addEventListener("dropdownSelectionUpdated",(event=>{ttsHandler.setVoice(event.detail.newValue),this.datamanager.setCurrentOptions(ttsHandler.getOptions())}))),genderElement&&(ttsHandler.setGender(genderElement.querySelector('[data-dropdown="select"]').dataset.value),genderElement.addEventListener("dropdownSelectionUpdated",(event=>{ttsHandler.setGender(event.detail.newValue),this.datamanager.setCurrentOptions(ttsHandler.getOptions())}))),this.datamanager.setCurrentPrompt(ttsHandler.getPrompt(this.datamanager.getCurrentTool(),this.datamanager.getSelectionText())),this.datamanager.setCurrentOptions(ttsHandler.getOptions());break}case"imggen":{const sizesElement=this.baseElement.querySelector('[data-preference="sizes"]');sizesElement&&(imggenHandler.setSize(sizesElement.querySelector('[data-dropdown="select"]').dataset.value),sizesElement.addEventListener("dropdownSelectionUpdated",(event=>{imggenHandler.setSize(event.detail.newValue),this.datamanager.setCurrentOptions(imggenHandler.getOptions())}))),this.datamanager.setCurrentPrompt(""),this.datamanager.setCurrentOptions(imggenHandler.getOptions());break}case"describeimg":case"imagetotext":this.baseElement.querySelector('[data-preference="fileupload"]')&&this.datamanager.getEventEmitterElement().addEventListener("fileUploaded",(event=>{this.datamanager.setCurrentFile(event.detail.newFile),this.datamanager.setCurrentOptions(ittHandler.getOptions())})),this.datamanager.setCurrentPrompt(ittHandler.getPrompt(this.datamanager.getCurrentTool())),this.datamanager.setCurrentFile(null);break}backButton&&backButton.addEventListener("click",(async()=>{await this.renderer.renderStart(_constants.constants.modalModes.selection)})),generateButton&&generateButton.addEventListener("click",(async()=>{null!==await this.generateAiAnswer()&&await this.renderer.renderSuggestion()}))}}return _exports.default=_default,_exports.default})); //# sourceMappingURL=preferences.min.js.map \ No newline at end of file diff --git a/amd/build/controllers/preferences.min.js.map b/amd/build/controllers/preferences.min.js.map index ade545c..4587553 100644 --- a/amd/build/controllers/preferences.min.js.map +++ b/amd/build/controllers/preferences.min.js.map @@ -1 +1 @@ -{"version":3,"file":"preferences.min.js","sources":["../../src/controllers/preferences.js"],"sourcesContent":["// This file is part of Moodle - http://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 * Controller for the main selection.\n *\n * @module tiny_ai/controllers/translate\n * @copyright 2024, ISB Bayern\n * @author Philipp Memmel\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nimport {constants} from 'tiny_ai/constants';\nimport SELECTORS from 'tiny_ai/selectors';\nimport BaseController from 'tiny_ai/controllers/base';\nimport {getSummarizeHandler, getTranslateHandler, getTtsHandler, getImggenHandler, getIttHandler} from 'tiny_ai/utils';\n\nexport default class extends BaseController {\n\n async init() {\n const modalFooter = document.querySelector(SELECTORS.modalFooter);\n const backButton = modalFooter.querySelector('[data-action=\"back\"]');\n const generateButton = modalFooter.querySelector('[data-action=\"generate\"]');\n\n const [summarizeHandler, translateHandler, ttsHandler, imggenHandler, ittHandler] = [\n getSummarizeHandler(this.uniqid),\n getTranslateHandler(this.uniqid),\n getTtsHandler(this.uniqid),\n getImggenHandler(this.uniqid),\n getIttHandler(this.uniqid)\n ];\n\n switch (this.datamanager.getCurrentTool()) {\n case 'summarize':\n case 'describe': {\n summarizeHandler.setTool(this.datamanager.getCurrentTool());\n const maxWordCountElement = this.baseElement.querySelector('[data-preference=\"maxWordCount\"]');\n const languageTypeElement = this.baseElement.querySelector('[data-preference=\"languageType\"]');\n summarizeHandler.setMaxWordCount(maxWordCountElement.querySelector('[data-dropdown=\"select\"]').dataset.value);\n summarizeHandler.setLanguageType(languageTypeElement.querySelector('[data-dropdown=\"select\"]').dataset.value);\n const currentPromptSummarize = await summarizeHandler.getPrompt(this.datamanager.getSelectionText());\n this.datamanager.setCurrentPrompt(currentPromptSummarize);\n maxWordCountElement.addEventListener('dropdownSelectionUpdated', async (event) => {\n summarizeHandler.setMaxWordCount(event.detail.newValue);\n const currentPrompt = await summarizeHandler.getPrompt(this.datamanager.getSelectionText());\n this.datamanager.setCurrentPrompt(currentPrompt);\n });\n languageTypeElement.addEventListener('dropdownSelectionUpdated', async (event) => {\n summarizeHandler.setLanguageType(event.detail.newValue);\n const currentPrompt = await summarizeHandler.getPrompt(this.datamanager.getSelectionText());\n this.datamanager.setCurrentPrompt(currentPrompt);\n });\n break;\n }\n case 'translate': {\n const targetLanguageElement = this.baseElement.querySelector('[data-preference=\"targetLanguage\"]');\n translateHandler.setTargetLanguage(targetLanguageElement.querySelector('[data-dropdown=\"select\"]').dataset.value);\n const currentPromptTranslate = await translateHandler.getPrompt(this.datamanager.getSelectionText());\n this.datamanager.setCurrentPrompt(currentPromptTranslate);\n targetLanguageElement.addEventListener('dropdownSelectionUpdated', async (event) => {\n translateHandler.setTargetLanguage(event.detail.newValue);\n const currentPromptTranslate = await translateHandler.getPrompt(this.datamanager.getSelectionText());\n this.datamanager.setCurrentPrompt(currentPromptTranslate);\n });\n break;\n }\n case 'tts':\n case 'audiogen': {\n const ttsTargetLanguageElement = this.baseElement.querySelector('[data-preference=\"targetLanguage\"]');\n const voiceElement = this.baseElement.querySelector('[data-preference=\"voice\"]');\n const genderElement = this.baseElement.querySelector('[data-preference=\"gender\"]');\n if (ttsTargetLanguageElement) {\n ttsHandler.setTargetLanguage(ttsTargetLanguageElement.querySelector('[data-dropdown=\"select\"]').dataset.value);\n ttsTargetLanguageElement.addEventListener('dropdownSelectionUpdated', event => {\n ttsHandler.setTargetLanguage(event.detail.newValue);\n this.datamanager.setCurrentOptions(ttsHandler.getOptions());\n });\n }\n if (voiceElement) {\n ttsHandler.setVoice(voiceElement.querySelector('[data-dropdown=\"select\"]').dataset.value);\n voiceElement.addEventListener('dropdownSelectionUpdated', event => {\n ttsHandler.setVoice(event.detail.newValue);\n this.datamanager.setCurrentOptions(ttsHandler.getOptions());\n });\n }\n if (genderElement) {\n ttsHandler.setGender(genderElement.querySelector('[data-dropdown=\"select\"]').dataset.value);\n genderElement.addEventListener('dropdownSelectionUpdated', event => {\n ttsHandler.setGender(event.detail.newValue);\n this.datamanager.setCurrentOptions(ttsHandler.getOptions());\n });\n }\n this.datamanager.setCurrentPrompt(ttsHandler.getPrompt(this.datamanager.getCurrentTool(),\n this.datamanager.getSelectionText()));\n this.datamanager.setCurrentOptions(ttsHandler.getOptions());\n break;\n }\n case 'imggen': {\n const sizesElement = this.baseElement.querySelector('[data-preference=\"sizes\"]');\n\n if (sizesElement) {\n imggenHandler.setSize(sizesElement.querySelector('[data-dropdown=\"select\"]').dataset.value);\n sizesElement.addEventListener('dropdownSelectionUpdated', event => {\n imggenHandler.setSize(event.detail.newValue);\n this.datamanager.setCurrentOptions(imggenHandler.getOptions());\n });\n }\n this.datamanager.setCurrentPrompt('');\n this.datamanager.setCurrentOptions(imggenHandler.getOptions());\n break;\n }\n case 'describeimg': {\n const fileUploadArea = this.baseElement.querySelector('[data-preference=\"fileupload\"]');\n if (fileUploadArea) {\n this.datamanager.getEventEmitterElement().addEventListener('fileUploaded', event => {\n this.datamanager.setCurrentFile(event.detail.newFile);\n this.datamanager.setCurrentOptions(ittHandler.getOptions());\n });\n }\n this.datamanager.setCurrentPrompt('');\n this.datamanager.setCurrentFile(null);\n break;\n }\n }\n\n if (backButton) {\n backButton.addEventListener('click', async () => {\n await this.renderer.renderStart(constants.modalModes.selection);\n });\n }\n\n if (generateButton) {\n generateButton.addEventListener('click', async () => {\n const result = await this.generateAiAnswer();\n if (result === null) {\n return;\n }\n await this.renderer.renderSuggestion();\n });\n }\n }\n}\n"],"names":["BaseController","modalFooter","document","querySelector","SELECTORS","backButton","generateButton","summarizeHandler","translateHandler","ttsHandler","imggenHandler","ittHandler","this","uniqid","datamanager","getCurrentTool","setTool","maxWordCountElement","baseElement","languageTypeElement","setMaxWordCount","dataset","value","setLanguageType","currentPromptSummarize","getPrompt","getSelectionText","setCurrentPrompt","addEventListener","async","event","detail","newValue","currentPrompt","targetLanguageElement","setTargetLanguage","currentPromptTranslate","ttsTargetLanguageElement","voiceElement","genderElement","setCurrentOptions","getOptions","setVoice","setGender","sizesElement","setSize","getEventEmitterElement","setCurrentFile","newFile","renderer","renderStart","constants","modalModes","selection","generateAiAnswer","renderSuggestion"],"mappings":";;;;;;;;8LA6B6BA,iCAGfC,YAAcC,SAASC,cAAcC,mBAAUH,aAC/CI,WAAaJ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B7B,WAAW8B,sBAGjD3B,YAAYa,iBAAiB,SAC7Bb,YAAYiC,eAAe,YAKpC1C,YACAA,WAAWuB,iBAAiB,SAASC,gBAC3BjB,KAAKqC,SAASC,YAAYC,qBAAUC,WAAWC,cAIzD/C,gBACAA,eAAesB,iBAAiB,SAASC,UAEtB,aADMjB,KAAK0C,0BAIpB1C,KAAKqC,SAASM"} \ No newline at end of file +{"version":3,"file":"preferences.min.js","sources":["../../src/controllers/preferences.js"],"sourcesContent":["// This file is part of Moodle - http://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 * Controller for the main selection.\n *\n * @module tiny_ai/controllers/translate\n * @copyright 2024, ISB Bayern\n * @author Philipp Memmel\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nimport {constants} from 'tiny_ai/constants';\nimport SELECTORS from 'tiny_ai/selectors';\nimport BaseController from 'tiny_ai/controllers/base';\nimport {getSummarizeHandler, getTranslateHandler, getTtsHandler, getImggenHandler, getIttHandler} from 'tiny_ai/utils';\n\nexport default class extends BaseController {\n\n async init() {\n const modalFooter = document.querySelector(SELECTORS.modalFooter);\n const backButton = modalFooter.querySelector('[data-action=\"back\"]');\n const generateButton = modalFooter.querySelector('[data-action=\"generate\"]');\n\n const [summarizeHandler, translateHandler, ttsHandler, imggenHandler, ittHandler] = [\n getSummarizeHandler(this.uniqid),\n getTranslateHandler(this.uniqid),\n getTtsHandler(this.uniqid),\n getImggenHandler(this.uniqid),\n getIttHandler(this.uniqid)\n ];\n\n switch (this.datamanager.getCurrentTool()) {\n case 'summarize':\n case 'describe': {\n summarizeHandler.setTool(this.datamanager.getCurrentTool());\n const maxWordCountElement = this.baseElement.querySelector('[data-preference=\"maxWordCount\"]');\n const languageTypeElement = this.baseElement.querySelector('[data-preference=\"languageType\"]');\n summarizeHandler.setMaxWordCount(maxWordCountElement.querySelector('[data-dropdown=\"select\"]').dataset.value);\n summarizeHandler.setLanguageType(languageTypeElement.querySelector('[data-dropdown=\"select\"]').dataset.value);\n const currentPromptSummarize = await summarizeHandler.getPrompt(this.datamanager.getSelectionText());\n this.datamanager.setCurrentPrompt(currentPromptSummarize);\n maxWordCountElement.addEventListener('dropdownSelectionUpdated', async (event) => {\n summarizeHandler.setMaxWordCount(event.detail.newValue);\n const currentPrompt = await summarizeHandler.getPrompt(this.datamanager.getSelectionText());\n this.datamanager.setCurrentPrompt(currentPrompt);\n });\n languageTypeElement.addEventListener('dropdownSelectionUpdated', async (event) => {\n summarizeHandler.setLanguageType(event.detail.newValue);\n const currentPrompt = await summarizeHandler.getPrompt(this.datamanager.getSelectionText());\n this.datamanager.setCurrentPrompt(currentPrompt);\n });\n break;\n }\n case 'translate': {\n const targetLanguageElement = this.baseElement.querySelector('[data-preference=\"targetLanguage\"]');\n translateHandler.setTargetLanguage(targetLanguageElement.querySelector('[data-dropdown=\"select\"]').dataset.value);\n const currentPromptTranslate = await translateHandler.getPrompt(this.datamanager.getSelectionText());\n this.datamanager.setCurrentPrompt(currentPromptTranslate);\n targetLanguageElement.addEventListener('dropdownSelectionUpdated', async (event) => {\n translateHandler.setTargetLanguage(event.detail.newValue);\n const currentPromptTranslate = await translateHandler.getPrompt(this.datamanager.getSelectionText());\n this.datamanager.setCurrentPrompt(currentPromptTranslate);\n });\n break;\n }\n case 'tts':\n case 'audiogen': {\n const ttsTargetLanguageElement = this.baseElement.querySelector('[data-preference=\"targetLanguage\"]');\n const voiceElement = this.baseElement.querySelector('[data-preference=\"voice\"]');\n const genderElement = this.baseElement.querySelector('[data-preference=\"gender\"]');\n if (ttsTargetLanguageElement) {\n ttsHandler.setTargetLanguage(ttsTargetLanguageElement.querySelector('[data-dropdown=\"select\"]').dataset.value);\n ttsTargetLanguageElement.addEventListener('dropdownSelectionUpdated', event => {\n ttsHandler.setTargetLanguage(event.detail.newValue);\n this.datamanager.setCurrentOptions(ttsHandler.getOptions());\n });\n }\n if (voiceElement) {\n ttsHandler.setVoice(voiceElement.querySelector('[data-dropdown=\"select\"]').dataset.value);\n voiceElement.addEventListener('dropdownSelectionUpdated', event => {\n ttsHandler.setVoice(event.detail.newValue);\n this.datamanager.setCurrentOptions(ttsHandler.getOptions());\n });\n }\n if (genderElement) {\n ttsHandler.setGender(genderElement.querySelector('[data-dropdown=\"select\"]').dataset.value);\n genderElement.addEventListener('dropdownSelectionUpdated', event => {\n ttsHandler.setGender(event.detail.newValue);\n this.datamanager.setCurrentOptions(ttsHandler.getOptions());\n });\n }\n this.datamanager.setCurrentPrompt(ttsHandler.getPrompt(this.datamanager.getCurrentTool(),\n this.datamanager.getSelectionText()));\n this.datamanager.setCurrentOptions(ttsHandler.getOptions());\n break;\n }\n case 'imggen': {\n const sizesElement = this.baseElement.querySelector('[data-preference=\"sizes\"]');\n\n if (sizesElement) {\n imggenHandler.setSize(sizesElement.querySelector('[data-dropdown=\"select\"]').dataset.value);\n sizesElement.addEventListener('dropdownSelectionUpdated', event => {\n imggenHandler.setSize(event.detail.newValue);\n this.datamanager.setCurrentOptions(imggenHandler.getOptions());\n });\n }\n this.datamanager.setCurrentPrompt('');\n this.datamanager.setCurrentOptions(imggenHandler.getOptions());\n break;\n }\n case 'describeimg':\n case 'imagetotext': {\n const fileUploadArea = this.baseElement.querySelector('[data-preference=\"fileupload\"]');\n if (fileUploadArea) {\n this.datamanager.getEventEmitterElement().addEventListener('fileUploaded', event => {\n this.datamanager.setCurrentFile(event.detail.newFile);\n this.datamanager.setCurrentOptions(ittHandler.getOptions());\n });\n }\n this.datamanager.setCurrentPrompt(ittHandler.getPrompt(this.datamanager.getCurrentTool()));\n this.datamanager.setCurrentFile(null);\n break;\n }\n }\n\n if (backButton) {\n backButton.addEventListener('click', async () => {\n await this.renderer.renderStart(constants.modalModes.selection);\n });\n }\n\n if (generateButton) {\n generateButton.addEventListener('click', async () => {\n const result = await this.generateAiAnswer();\n if (result === null) {\n return;\n }\n await this.renderer.renderSuggestion();\n });\n }\n }\n}\n"],"names":["BaseController","modalFooter","document","querySelector","SELECTORS","backButton","generateButton","summarizeHandler","translateHandler","ttsHandler","imggenHandler","ittHandler","this","uniqid","datamanager","getCurrentTool","setTool","maxWordCountElement","baseElement","languageTypeElement","setMaxWordCount","dataset","value","setLanguageType","currentPromptSummarize","getPrompt","getSelectionText","setCurrentPrompt","addEventListener","async","event","detail","newValue","currentPrompt","targetLanguageElement","setTargetLanguage","currentPromptTranslate","ttsTargetLanguageElement","voiceElement","genderElement","setCurrentOptions","getOptions","setVoice","setGender","sizesElement","setSize","getEventEmitterElement","setCurrentFile","newFile","renderer","renderStart","constants","modalModes","selection","generateAiAnswer","renderSuggestion"],"mappings":";;;;;;;;8LA6B6BA,iCAGfC,YAAcC,SAASC,cAAcC,mBAAUH,aAC/CI,WAAaJ,YAAYE,cAAc,wBACvCG,eAAiBL,YAAYE,cAAc,6BAE1CI,iBAAkBC,iBAAkBC,WAAYC,cAAeC,YAAc,EAChF,8BAAoBC,KAAKC,SACzB,8BAAoBD,KAAKC,SACzB,wBAAcD,KAAKC,SACnB,2BAAiBD,KAAKC,SACtB,wBAAcD,KAAKC,gBAGfD,KAAKE,YAAYC,sBAChB,gBACA,YACDR,iBAAiBS,QAAQJ,KAAKE,YAAYC,wBACpCE,oBAAsBL,KAAKM,YAAYf,cAAc,oCACrDgB,oBAAsBP,KAAKM,YAAYf,cAAc,oCAC3DI,iBAAiBa,gBAAgBH,oBAAoBd,cAAc,4BAA4BkB,QAAQC,OACvGf,iBAAiBgB,gBAAgBJ,oBAAoBhB,cAAc,4BAA4BkB,QAAQC,aACjGE,6BAA+BjB,iBAAiBkB,UAAUb,KAAKE,YAAYY,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AAUJ,cAAcpC,cAAc,4BAA4BkB,QAAQC,OACrFiB,cAAcX,iBAAiB,4BAA4BE,QACvDrB,WAAWkC,UAAUb,MAAMC,OAAOC,eAC7BlB,YAAY0B,kBAAkB/B,WAAWgC,uBAGjD3B,YAAYa,iBAAiBlB,WAAWgB,UAAUb,KAAKE,YAAYC,iBACpEH,KAAKE,YAAYY,0BAChBZ,YAAY0B,kBAAkB/B,WAAWgC,wBAG7C,gBACKG,aAAehC,KAAKM,YAAYf,cAAc,6BAEhDyC,eACAlC,cAAcmC,QAAQD,aAAazC,cAAc,4BAA4BkB,QAAQC,OACrFsB,aAAahB,iBAAiB,4BAA4BE,QACtDpB,cAAcmC,QAAQf,MAAMC,OAAOC,eAC9BlB,YAAY0B,kBAAkB9B,cAAc+B,uBAGpD3B,YAAYa,iBAAiB,SAC7Bb,YAAY0B,kBAAkB9B,cAAc+B,wBAGhD,kBACA,cACsB7B,KAAKM,YAAYf,cAAc,wCAE7CW,YAAYgC,yBAAyBlB,iBAAiB,gBAAgBE,aAClEhB,YAAYiC,eAAejB,MAAMC,OAAOiB,cACxClC,YAAY0B,kBAAkB7B,WAAW8B,sBAGjD3B,YAAYa,iBAAiBhB,WAAWc,UAAUb,KAAKE,YAAYC,wBACnED,YAAYiC,eAAe,YAKpC1C,YACAA,WAAWuB,iBAAiB,SAASC,gBAC3BjB,KAAKqC,SAASC,YAAYC,qBAAUC,WAAWC,cAIzD/C,gBACAA,eAAesB,iBAAiB,SAASC,UAEtB,aADMjB,KAAK0C,0BAIpB1C,KAAKqC,SAASM"} \ No newline at end of file diff --git a/amd/build/controllers/start.min.js b/amd/build/controllers/start.min.js index bcd13c7..0c15593 100644 --- a/amd/build/controllers/start.min.js +++ b/amd/build/controllers/start.min.js @@ -6,6 +6,6 @@ define("tiny_ai/controllers/start",["exports","tiny_ai/controllers/base","tiny_a * @copyright 2024, ISB Bayern * @author Philipp Memmel * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.default=void 0,_base=_interopRequireDefault(_base),_jquery=_interopRequireDefault(_jquery);class _default extends _base.default{async init(){if(!this.baseElement)return;const summarizeButton=this.baseElement.querySelector('[data-action="loadsummarize"]'),translateButton=this.baseElement.querySelector('[data-action="loadtranslate"]'),describeButton=this.baseElement.querySelector('[data-action="loaddescribe"]'),ttsButton=this.baseElement.querySelector('[data-action="loadtts"]'),audiogenButton=this.baseElement.querySelector('[data-action="loadaudiogen"]'),imggenButton=this.baseElement.querySelector('[data-action="loadimggen"]'),freePromptButton=this.baseElement.querySelector('[data-action="loadfreeprompt"]'),describeimgButton=this.baseElement.querySelector('[data-action="loaddescribeimg"]'),startHandler=(0,_utils.getStartHandler)(this.uniqid);await startHandler.isTinyAiDisabled()||window.matchMedia("(pointer: coarse)").matches&&document.querySelectorAll(".tiny_ai-card-button.disabled").forEach((button=>{button.parentElement.addEventListener("click",(async()=>{(0,_jquery.default)(button).tooltip("toggle")}))})),summarizeButton&&summarizeButton.addEventListener("click",(async()=>{this.datamanager.setCurrentTool("summarize"),await this.renderer.renderSummarize()})),translateButton&&translateButton.addEventListener("click",(async()=>{this.datamanager.setCurrentTool("translate"),await this.renderer.renderTranslate()})),describeButton&&describeButton.addEventListener("click",(async()=>{this.datamanager.setCurrentTool("describe"),await this.renderer.renderDescribe()})),ttsButton&&ttsButton.addEventListener("click",(async()=>{this.datamanager.setCurrentTool("tts"),await this.renderer.renderTts()})),audiogenButton&&audiogenButton.addEventListener("click",(async()=>{this.datamanager.setCurrentTool("audiogen"),await this.renderer.renderAudiogen()})),imggenButton&&imggenButton.addEventListener("click",(async()=>{this.datamanager.setCurrentTool("imggen"),await this.renderer.renderImggen()})),describeimgButton&&describeimgButton.addEventListener("click",(async()=>{this.datamanager.setCurrentTool("describeimg"),await this.renderer.renderDescribeimg()})),freePromptButton&&(freePromptButton.classList.contains("disabled")?await startHandler.isTinyAiDisabled()||freePromptButton.addEventListener("click",(async()=>{await(0,_utils.errorAlert)(startHandler.isToolDisabled("freeprompt",this.editorUtils.getMode()))})):freePromptButton.addEventListener("click",(async()=>{this.datamanager.setCurrentTool("freeprompt"),this.datamanager.setCurrentPrompt(this.baseElement.querySelector('[data-type="freepromptinput"]').value);null!==await this.generateAiAnswer()&&await this.renderer.renderSuggestion()})))}}return _exports.default=_default,_exports.default})); + */Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.default=void 0,_base=_interopRequireDefault(_base),_jquery=_interopRequireDefault(_jquery);class _default extends _base.default{async init(){if(!this.baseElement)return;const summarizeButton=this.baseElement.querySelector('[data-action="loadsummarize"]'),translateButton=this.baseElement.querySelector('[data-action="loadtranslate"]'),describeButton=this.baseElement.querySelector('[data-action="loaddescribe"]'),ttsButton=this.baseElement.querySelector('[data-action="loadtts"]'),audiogenButton=this.baseElement.querySelector('[data-action="loadaudiogen"]'),imggenButton=this.baseElement.querySelector('[data-action="loadimggen"]'),freePromptButton=this.baseElement.querySelector('[data-action="loadfreeprompt"]'),describeimgButton=this.baseElement.querySelector('[data-action="loaddescribeimg"]'),imagetotextButton=this.baseElement.querySelector('[data-action="loadimagetotext"]'),startHandler=(0,_utils.getStartHandler)(this.uniqid);await startHandler.isTinyAiDisabled()||window.matchMedia("(pointer: coarse)").matches&&document.querySelectorAll(".tiny_ai-card-button.disabled").forEach((button=>{button.parentElement.addEventListener("click",(async()=>{(0,_jquery.default)(button).tooltip("toggle")}))})),summarizeButton&&summarizeButton.addEventListener("click",(async()=>{this.datamanager.setCurrentTool("summarize"),await this.renderer.renderSummarize()})),translateButton&&translateButton.addEventListener("click",(async()=>{this.datamanager.setCurrentTool("translate"),await this.renderer.renderTranslate()})),describeButton&&describeButton.addEventListener("click",(async()=>{this.datamanager.setCurrentTool("describe"),await this.renderer.renderDescribe()})),ttsButton&&ttsButton.addEventListener("click",(async()=>{this.datamanager.setCurrentTool("tts"),await this.renderer.renderTts()})),audiogenButton&&audiogenButton.addEventListener("click",(async()=>{this.datamanager.setCurrentTool("audiogen"),await this.renderer.renderAudiogen()})),imggenButton&&imggenButton.addEventListener("click",(async()=>{this.datamanager.setCurrentTool("imggen"),await this.renderer.renderImggen()})),describeimgButton&&describeimgButton.addEventListener("click",(async()=>{this.datamanager.setCurrentTool("describeimg"),await this.renderer.renderDescribeimg()})),imagetotextButton&&imagetotextButton.addEventListener("click",(async()=>{this.datamanager.setCurrentTool("imagetotext"),await this.renderer.renderImagetotext()})),freePromptButton&&(freePromptButton.classList.contains("disabled")?await startHandler.isTinyAiDisabled()||freePromptButton.addEventListener("click",(async()=>{await(0,_utils.errorAlert)(startHandler.isToolDisabled("freeprompt",this.editorUtils.getMode()))})):freePromptButton.addEventListener("click",(async()=>{this.datamanager.setCurrentTool("freeprompt"),this.datamanager.setCurrentPrompt(this.baseElement.querySelector('[data-type="freepromptinput"]').value);null!==await this.generateAiAnswer()&&await this.renderer.renderSuggestion()})))}}return _exports.default=_default,_exports.default})); //# sourceMappingURL=start.min.js.map \ No newline at end of file diff --git a/amd/build/controllers/start.min.js.map b/amd/build/controllers/start.min.js.map index f741812..465c87e 100644 --- a/amd/build/controllers/start.min.js.map +++ b/amd/build/controllers/start.min.js.map @@ -1 +1 @@ -{"version":3,"file":"start.min.js","sources":["../../src/controllers/start.js"],"sourcesContent":["// This file is part of Moodle - http://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 * Controller for the main selection.\n *\n * @module tiny_ai/controllers/start\n * @copyright 2024, ISB Bayern\n * @author Philipp Memmel\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nimport BaseController from 'tiny_ai/controllers/base';\nimport {getStartHandler} from 'tiny_ai/utils';\nimport {errorAlert} from 'tiny_ai/utils';\n// We unfortunately need jquery for tooltip handling.\nimport $ from 'jquery';\n\nexport default class extends BaseController {\n\n async init() {\n if (!this.baseElement) {\n // In rare cases (display error messages etc.) we do not have a correct modal, so there is nothing to do here.\n return;\n }\n const summarizeButton = this.baseElement.querySelector('[data-action=\"loadsummarize\"]');\n const translateButton = this.baseElement.querySelector('[data-action=\"loadtranslate\"]');\n const describeButton = this.baseElement.querySelector('[data-action=\"loaddescribe\"]');\n const ttsButton = this.baseElement.querySelector('[data-action=\"loadtts\"]');\n const audiogenButton = this.baseElement.querySelector('[data-action=\"loadaudiogen\"]');\n const imggenButton = this.baseElement.querySelector('[data-action=\"loadimggen\"]');\n const freePromptButton = this.baseElement.querySelector('[data-action=\"loadfreeprompt\"]');\n const describeimgButton = this.baseElement.querySelector('[data-action=\"loaddescribeimg\"]');\n\n const startHandler = getStartHandler(this.uniqid);\n\n if (!(await startHandler.isTinyAiDisabled())) {\n if(window.matchMedia(\"(pointer: coarse)\").matches) {\n // If we have a touch device, we need to manually trigger the tooltips by touching the cards.\n document.querySelectorAll('.tiny_ai-card-button.disabled').forEach(button => {\n button.parentElement.addEventListener(\n 'click', async() => {\n $(button).tooltip('toggle');\n });\n });\n }\n }\n\n if (summarizeButton) {\n summarizeButton.addEventListener('click', async() => {\n this.datamanager.setCurrentTool('summarize');\n await this.renderer.renderSummarize();\n });\n }\n if (translateButton) {\n translateButton.addEventListener('click', async() => {\n this.datamanager.setCurrentTool('translate');\n await this.renderer.renderTranslate();\n });\n }\n if (describeButton) {\n describeButton.addEventListener('click', async() => {\n this.datamanager.setCurrentTool('describe');\n await this.renderer.renderDescribe();\n });\n }\n if (ttsButton) {\n ttsButton.addEventListener('click', async() => {\n this.datamanager.setCurrentTool('tts');\n await this.renderer.renderTts();\n });\n }\n if (audiogenButton) {\n audiogenButton.addEventListener('click', async() => {\n this.datamanager.setCurrentTool('audiogen');\n await this.renderer.renderAudiogen();\n });\n }\n if (imggenButton) {\n imggenButton.addEventListener('click', async() => {\n this.datamanager.setCurrentTool('imggen');\n await this.renderer.renderImggen();\n });\n }\n if (describeimgButton) {\n describeimgButton.addEventListener('click', async() => {\n this.datamanager.setCurrentTool('describeimg');\n await this.renderer.renderDescribeimg();\n });\n }\n if (freePromptButton) {\n if (!freePromptButton.classList.contains('disabled')) {\n freePromptButton.addEventListener('click', async () => {\n this.datamanager.setCurrentTool('freeprompt');\n this.datamanager.setCurrentPrompt(this.baseElement.querySelector('[data-type=\"freepromptinput\"]').value);\n const result = await this.generateAiAnswer();\n if (result === null) {\n return;\n }\n await this.renderer.renderSuggestion();\n });\n } else {\n if (!(await startHandler.isTinyAiDisabled())) {\n freePromptButton.addEventListener('click', async() => {\n await errorAlert(startHandler.isToolDisabled('freeprompt', this.editorUtils.getMode()));\n });\n }\n }\n }\n }\n}\n"],"names":["BaseController","this","baseElement","summarizeButton","querySelector","translateButton","describeButton","ttsButton","audiogenButton","imggenButton","freePromptButton","describeimgButton","startHandler","uniqid","isTinyAiDisabled","window","matchMedia","matches","document","querySelectorAll","forEach","button","parentElement","addEventListener","async","tooltip","datamanager","setCurrentTool","renderer","renderSummarize","renderTranslate","renderDescribe","renderTts","renderAudiogen","renderImggen","renderDescribeimg","classList","contains","isToolDisabled","editorUtils","getMode","setCurrentPrompt","value","generateAiAnswer","renderSuggestion"],"mappings":";;;;;;;;wLA8B6BA,+BAGhBC,KAAKC,yBAIJC,gBAAkBF,KAAKC,YAAYE,cAAc,iCACjDC,gBAAkBJ,KAAKC,YAAYE,cAAc,iCACjDE,eAAiBL,KAAKC,YAAYE,cAAc,gCAChDG,UAAYN,KAAKC,YAAYE,cAAc,2BAC3CI,eAAiBP,KAAKC,YAAYE,cAAc,gCAChDK,aAAeR,KAAKC,YAAYE,cAAc,8BAC9CM,iBAAmBT,KAAKC,YAAYE,cAAc,kCAClDO,kBAAoBV,KAAKC,YAAYE,cAAc,mCAEnDQ,cAAe,0BAAgBX,KAAKY,cAE9BD,aAAaE,oBAClBC,OAAOC,WAAW,qBAAqBC,SAEtCC,SAASC,iBAAiB,iCAAiCC,SAAQC,SAC/DA,OAAOC,cAAcC,iBACjB,SAASC,8BACHH,QAAQI,QAAQ,gBAMlCtB,iBACAA,gBAAgBoB,iBAAiB,SAASC,eACjCE,YAAYC,eAAe,mBAC1B1B,KAAK2B,SAASC,qBAGxBxB,iBACAA,gBAAgBkB,iBAAiB,SAASC,eACjCE,YAAYC,eAAe,mBAC1B1B,KAAK2B,SAASE,qBAGxBxB,gBACAA,eAAeiB,iBAAiB,SAASC,eAChCE,YAAYC,eAAe,kBAC1B1B,KAAK2B,SAASG,oBAGxBxB,WACAA,UAAUgB,iBAAiB,SAASC,eAC3BE,YAAYC,eAAe,aAC1B1B,KAAK2B,SAASI,eAGxBxB,gBACAA,eAAee,iBAAiB,SAASC,eAChCE,YAAYC,eAAe,kBAC1B1B,KAAK2B,SAASK,oBAGxBxB,cACAA,aAAac,iBAAiB,SAASC,eAC9BE,YAAYC,eAAe,gBAC1B1B,KAAK2B,SAASM,kBAGxBvB,mBACAA,kBAAkBY,iBAAiB,SAASC,eACnCE,YAAYC,eAAe,qBAC1B1B,KAAK2B,SAASO,uBAGxBzB,mBACKA,iBAAiB0B,UAAUC,SAAS,kBAWzBzB,aAAaE,oBACrBJ,iBAAiBa,iBAAiB,SAASC,gBACjC,qBAAWZ,aAAa0B,eAAe,aAAcrC,KAAKsC,YAAYC,eAZpF9B,iBAAiBa,iBAAiB,SAASC,eAClCE,YAAYC,eAAe,mBAC3BD,YAAYe,iBAAiBxC,KAAKC,YAAYE,cAAc,iCAAiCsC,OAEnF,aADMzC,KAAK0C,0BAIpB1C,KAAK2B,SAASgB"} \ No newline at end of file +{"version":3,"file":"start.min.js","sources":["../../src/controllers/start.js"],"sourcesContent":["// This file is part of Moodle - http://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 * Controller for the main selection.\n *\n * @module tiny_ai/controllers/start\n * @copyright 2024, ISB Bayern\n * @author Philipp Memmel\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nimport BaseController from 'tiny_ai/controllers/base';\nimport {getStartHandler} from 'tiny_ai/utils';\nimport {errorAlert} from 'tiny_ai/utils';\n// We unfortunately need jquery for tooltip handling.\nimport $ from 'jquery';\n\nexport default class extends BaseController {\n\n async init() {\n if (!this.baseElement) {\n // In rare cases (display error messages etc.) we do not have a correct modal, so there is nothing to do here.\n return;\n }\n const summarizeButton = this.baseElement.querySelector('[data-action=\"loadsummarize\"]');\n const translateButton = this.baseElement.querySelector('[data-action=\"loadtranslate\"]');\n const describeButton = this.baseElement.querySelector('[data-action=\"loaddescribe\"]');\n const ttsButton = this.baseElement.querySelector('[data-action=\"loadtts\"]');\n const audiogenButton = this.baseElement.querySelector('[data-action=\"loadaudiogen\"]');\n const imggenButton = this.baseElement.querySelector('[data-action=\"loadimggen\"]');\n const freePromptButton = this.baseElement.querySelector('[data-action=\"loadfreeprompt\"]');\n const describeimgButton = this.baseElement.querySelector('[data-action=\"loaddescribeimg\"]');\n const imagetotextButton = this.baseElement.querySelector('[data-action=\"loadimagetotext\"]');\n\n const startHandler = getStartHandler(this.uniqid);\n\n if (!(await startHandler.isTinyAiDisabled())) {\n if(window.matchMedia(\"(pointer: coarse)\").matches) {\n // If we have a touch device, we need to manually trigger the tooltips by touching the cards.\n document.querySelectorAll('.tiny_ai-card-button.disabled').forEach(button => {\n button.parentElement.addEventListener(\n 'click', async() => {\n $(button).tooltip('toggle');\n });\n });\n }\n }\n\n if (summarizeButton) {\n summarizeButton.addEventListener('click', async() => {\n this.datamanager.setCurrentTool('summarize');\n await this.renderer.renderSummarize();\n });\n }\n if (translateButton) {\n translateButton.addEventListener('click', async() => {\n this.datamanager.setCurrentTool('translate');\n await this.renderer.renderTranslate();\n });\n }\n if (describeButton) {\n describeButton.addEventListener('click', async() => {\n this.datamanager.setCurrentTool('describe');\n await this.renderer.renderDescribe();\n });\n }\n if (ttsButton) {\n ttsButton.addEventListener('click', async() => {\n this.datamanager.setCurrentTool('tts');\n await this.renderer.renderTts();\n });\n }\n if (audiogenButton) {\n audiogenButton.addEventListener('click', async() => {\n this.datamanager.setCurrentTool('audiogen');\n await this.renderer.renderAudiogen();\n });\n }\n if (imggenButton) {\n imggenButton.addEventListener('click', async() => {\n this.datamanager.setCurrentTool('imggen');\n await this.renderer.renderImggen();\n });\n }\n if (describeimgButton) {\n describeimgButton.addEventListener('click', async() => {\n this.datamanager.setCurrentTool('describeimg');\n await this.renderer.renderDescribeimg();\n });\n }\n if (imagetotextButton) {\n imagetotextButton.addEventListener('click', async() => {\n this.datamanager.setCurrentTool('imagetotext');\n await this.renderer.renderImagetotext();\n });\n }\n if (freePromptButton) {\n if (!freePromptButton.classList.contains('disabled')) {\n freePromptButton.addEventListener('click', async () => {\n this.datamanager.setCurrentTool('freeprompt');\n this.datamanager.setCurrentPrompt(this.baseElement.querySelector('[data-type=\"freepromptinput\"]').value);\n const result = await this.generateAiAnswer();\n if (result === null) {\n return;\n }\n await this.renderer.renderSuggestion();\n });\n } else {\n if (!(await startHandler.isTinyAiDisabled())) {\n freePromptButton.addEventListener('click', async() => {\n await errorAlert(startHandler.isToolDisabled('freeprompt', this.editorUtils.getMode()));\n });\n }\n }\n }\n }\n}\n"],"names":["BaseController","this","baseElement","summarizeButton","querySelector","translateButton","describeButton","ttsButton","audiogenButton","imggenButton","freePromptButton","describeimgButton","imagetotextButton","startHandler","uniqid","isTinyAiDisabled","window","matchMedia","matches","document","querySelectorAll","forEach","button","parentElement","addEventListener","async","tooltip","datamanager","setCurrentTool","renderer","renderSummarize","renderTranslate","renderDescribe","renderTts","renderAudiogen","renderImggen","renderDescribeimg","renderImagetotext","classList","contains","isToolDisabled","editorUtils","getMode","setCurrentPrompt","value","generateAiAnswer","renderSuggestion"],"mappings":";;;;;;;;wLA8B6BA,+BAGhBC,KAAKC,yBAIJC,gBAAkBF,KAAKC,YAAYE,cAAc,iCACjDC,gBAAkBJ,KAAKC,YAAYE,cAAc,iCACjDE,eAAiBL,KAAKC,YAAYE,cAAc,gCAChDG,UAAYN,KAAKC,YAAYE,cAAc,2BAC3CI,eAAiBP,KAAKC,YAAYE,cAAc,gCAChDK,aAAeR,KAAKC,YAAYE,cAAc,8BAC9CM,iBAAmBT,KAAKC,YAAYE,cAAc,kCAClDO,kBAAoBV,KAAKC,YAAYE,cAAc,mCACnDQ,kBAAoBX,KAAKC,YAAYE,cAAc,mCAEnDS,cAAe,0BAAgBZ,KAAKa,cAE9BD,aAAaE,oBAClBC,OAAOC,WAAW,qBAAqBC,SAEtCC,SAASC,iBAAiB,iCAAiCC,SAAQC,SAC/DA,OAAOC,cAAcC,iBACjB,SAASC,8BACHH,QAAQI,QAAQ,gBAMlCvB,iBACAA,gBAAgBqB,iBAAiB,SAASC,eACjCE,YAAYC,eAAe,mBAC1B3B,KAAK4B,SAASC,qBAGxBzB,iBACAA,gBAAgBmB,iBAAiB,SAASC,eACjCE,YAAYC,eAAe,mBAC1B3B,KAAK4B,SAASE,qBAGxBzB,gBACAA,eAAekB,iBAAiB,SAASC,eAChCE,YAAYC,eAAe,kBAC1B3B,KAAK4B,SAASG,oBAGxBzB,WACAA,UAAUiB,iBAAiB,SAASC,eAC3BE,YAAYC,eAAe,aAC1B3B,KAAK4B,SAASI,eAGxBzB,gBACAA,eAAegB,iBAAiB,SAASC,eAChCE,YAAYC,eAAe,kBAC1B3B,KAAK4B,SAASK,oBAGxBzB,cACAA,aAAae,iBAAiB,SAASC,eAC9BE,YAAYC,eAAe,gBAC1B3B,KAAK4B,SAASM,kBAGxBxB,mBACAA,kBAAkBa,iBAAiB,SAASC,eACnCE,YAAYC,eAAe,qBAC1B3B,KAAK4B,SAASO,uBAGxBxB,mBACAA,kBAAkBY,iBAAiB,SAASC,eACnCE,YAAYC,eAAe,qBAC1B3B,KAAK4B,SAASQ,uBAGxB3B,mBACKA,iBAAiB4B,UAAUC,SAAS,kBAWzB1B,aAAaE,oBACrBL,iBAAiBc,iBAAiB,SAASC,gBACjC,qBAAWZ,aAAa2B,eAAe,aAAcvC,KAAKwC,YAAYC,eAZpFhC,iBAAiBc,iBAAiB,SAASC,eAClCE,YAAYC,eAAe,mBAC3BD,YAAYgB,iBAAiB1C,KAAKC,YAAYE,cAAc,iCAAiCwC,OAEnF,aADM3C,KAAK4C,0BAIpB5C,KAAK4B,SAASiB"} \ No newline at end of file diff --git a/amd/build/datahandler/basedata.min.js b/amd/build/datahandler/basedata.min.js index 849b95d..56495b6 100644 --- a/amd/build/datahandler/basedata.min.js +++ b/amd/build/datahandler/basedata.min.js @@ -7,6 +7,6 @@ define("tiny_ai/datahandler/basedata",["exports","core/str","core/prefetch","tin * @author Philipp Memmel * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -const stringKeys=["aigenerating","aisuggestion","audiogen_headline","audiogen_placeholder","back","backbutton_tooltip","cancel","deletebutton_tooltip","describe_baseprompt","describe_headline","dismiss","dismisssuggestion","error_nopromptgiven","freeprompt_placeholder","freepromptbutton_tooltip","gender","generalerror","generate","generatebutton_tooltip","hideprompt","imggen_headline","imggen_placeholder","insertatcaret","insertatcaretbutton_tooltip","insertbelow","insertbelowbutton_tooltip","keeplanguagetype","languagetype","languagetype_prompt","mainselection_heading","maxwordcount","maxwordcount_prompt","nomaxwordcount","regeneratebutton_tooltip","replaceselection","replaceselectionbutton_tooltip","reworkprompt","simplelanguage","size","showprompt","showpromptbutton_tooltip","summarize_baseprompt","summarize_headline","targetlanguage","technicallanguage","texttouse","toolname_audiogen","toolname_describe","toolname_describe_extension","toolname_imggen","toolname_summarize","toolname_summarize_extension","toolname_translate","toolname_translate_extension","toolname_tts","toolname_tts_extension","translate_baseprompt","translate_headline","tts_headline","voice"];let strings={};_exports.init=async()=>{(0,_prefetch.prefetchStrings)("tiny_ai",stringKeys);const stringRequest=stringKeys.map((key=>({key:key,component:"tiny_ai"})));[strings.aigenerating,strings.aisuggestion,strings.audiogen_headline,strings.audiogen_placeholder,strings.back,strings.backbutton_tooltip,strings.cancel,strings.deletebutton_tooltip,strings.describe_baseprompt,strings.describe_headline,strings.dismiss,strings.dismisssuggestion,strings.error_nopromptgiven,strings.freeprompt_placeholder,strings.freepromptbutton_tooltip,strings.gender,strings.generalerror,strings.generate,strings.generatebutton_tooltip,strings.hideprompt,strings.imggen_headline,strings.imggen_placeholder,strings.insertatcaret,strings.insertatcaretbutton_tooltip,strings.insertbelow,strings.insertbelowbutton_tooltip,strings.keeplanguagetype,strings.languagetype,strings.languagetype_prompt,strings.mainselection_heading,strings.maxwordcount,strings.maxwordcount_prompt,strings.nomaxwordcount,strings.regeneratebutton_tooltip,strings.replaceselection,strings.replaceselectionbutton_tooltip,strings.reworkprompt,strings.simplelanguage,strings.size,strings.showprompt,strings.showpromptbutton_tooltip,strings.summarize_baseprompt,strings.summarize_headline,strings.targetlanguage,strings.technicallanguage,strings.texttouse,strings.toolname_audiogen,strings.toolname_describe,strings.toolname_describe_extension,strings.toolname_imggen,strings.toolname_summarize,strings.toolname_summarize_extension,strings.toolname_translate,strings.toolname_translate_extension,strings.toolname_tts,strings.toolname_tts_extension,strings.translate_baseprompt,strings.translate_headline,strings.tts_headline,strings.voice]=await(0,_str.getStrings)(stringRequest)};_exports.getTinyAiString=string=>strings[string];_exports.getBackAndGenerateButtonContext=()=>({footer_buttons:[{hasText:!0,button_text:strings.back,icon_left:!0,icon_right:!1,primary:!1,secondary:!1,tertiary:!0,iconname:"arrow-left",iconstyle:"solid",action:"back",tooltip:strings.backbutton_tooltip},{hasText:!0,button_text:strings.generate,icon_left:!0,icon_right:!1,primary:!0,secondary:!1,tertiary:!1,iconname:"sparkle",customicon:!0,action:"generate",tooltip:strings.generatebutton_tooltip}]});_exports.getReplaceButtonsContext=mode=>({footer_iconbuttons:[{action:"delete",iconname:"trash",tooltip:strings.deletebutton_tooltip},{action:"regenerate",iconname:"arrows-rotate",tooltip:strings.regeneratebutton_tooltip}],footer_buttons:[{action:"insertbelow",hasText:!0,button_text:strings.insertbelow,icon_left:!0,icon_right:!1,secondary:!0,iconname:"text-insert-last",customicon:!0,tooltip:strings.insertbelow_tooltip},{action:mode===_constants.constants.modalModes.selection?"replace":"insertatcaret",hasText:!0,button_text:mode===_constants.constants.modalModes.selection?strings.replaceselection:strings.insertatcaret,icon_left:!0,icon_right:!1,primary:!0,iconname:"check",iconstyle:"solid",tooltip:mode===_constants.constants.modalModes.selection?strings.replaceselection_tooltip:strings.insertatcaret_tooltip}]});_exports.getInputContext=()=>({input:[{iconname:"sparkle",customicon:!0,button:[{customicon:!1,iconname:"arrow-right",iconstyle:"solid",icon_left:!1,icon_right:!0,tooltip:strings.freepromptbutton_tooltip}]}]});_exports.getShowPromptButtonContext=()=>({hasText:!0,button_text:strings.showprompt,icon_left:!0,icon_right:!1,tertiary:!0,iconname:"eye",iconstyle:"solid",action:"showprompt",textareatype:"prompt",collapsed:!0,tooltip:strings.showpromptbutton_tooltip})})); +const stringKeys=["aigenerating","aisuggestion","audiogen_headline","audiogen_placeholder","back","backbutton_tooltip","cancel","deletebutton_tooltip","describeimg_baseprompt","describeimg_headline","describe_baseprompt","describe_headline","dismiss","dismisssuggestion","error_nofile","error_nofileinclipboard_text","error_nofileinclipboard_title","error_nopromptgiven","freeprompt_placeholder","freepromptbutton_tooltip","gender","generalerror","generate","generatebutton_tooltip","hideprompt","imggen_headline","imggen_placeholder","imagetotext_baseprompt","imagetotext_headline","imagetotext_insertimage","insertatcaret","insertatcaretbutton_tooltip","insertbelow","insertbelowbutton_tooltip","keeplanguagetype","languagetype","languagetype_prompt","mainselection_heading","maxwordcount","maxwordcount_prompt","nomaxwordcount","regeneratebutton_tooltip","replaceselection","replaceselectionbutton_tooltip","reworkprompt","simplelanguage","size","showprompt","showpromptbutton_tooltip","summarize_baseprompt","summarize_headline","targetlanguage","technicallanguage","texttouse","toolname_audiogen","toolname_describe","toolname_describeimg","toolname_describe_extension","toolname_imggen","toolname_imagetotext","toolname_summarize","toolname_summarize_extension","toolname_translate","toolname_translate_extension","toolname_tts","toolname_tts_extension","translate_baseprompt","translate_headline","tts_headline","voice"];let strings={};_exports.init=async()=>{(0,_prefetch.prefetchStrings)("tiny_ai",stringKeys);const stringRequest=stringKeys.map((key=>({key:key,component:"tiny_ai"})));[strings.aigenerating,strings.aisuggestion,strings.audiogen_headline,strings.audiogen_placeholder,strings.back,strings.backbutton_tooltip,strings.cancel,strings.deletebutton_tooltip,strings.describeimg_baseprompt,strings.describeimg_headline,strings.describe_baseprompt,strings.describe_headline,strings.dismiss,strings.dismisssuggestion,strings.error_nofile,strings.error_nofileinclipboard_text,strings.error_nofileinclipboard_title,strings.error_nopromptgiven,strings.freeprompt_placeholder,strings.freepromptbutton_tooltip,strings.gender,strings.generalerror,strings.generate,strings.generatebutton_tooltip,strings.hideprompt,strings.imggen_headline,strings.imggen_placeholder,strings.imagetotext_baseprompt,strings.imagetotext_headline,strings.imagetotext_insertimage,strings.insertatcaret,strings.insertatcaretbutton_tooltip,strings.insertbelow,strings.insertbelowbutton_tooltip,strings.keeplanguagetype,strings.languagetype,strings.languagetype_prompt,strings.mainselection_heading,strings.maxwordcount,strings.maxwordcount_prompt,strings.nomaxwordcount,strings.regeneratebutton_tooltip,strings.replaceselection,strings.replaceselectionbutton_tooltip,strings.reworkprompt,strings.simplelanguage,strings.size,strings.showprompt,strings.showpromptbutton_tooltip,strings.summarize_baseprompt,strings.summarize_headline,strings.targetlanguage,strings.technicallanguage,strings.texttouse,strings.toolname_audiogen,strings.toolname_describe,strings.toolname_describeimg,strings.toolname_describe_extension,strings.toolname_imggen,strings.toolname_imagetotext,strings.toolname_summarize,strings.toolname_summarize_extension,strings.toolname_translate,strings.toolname_translate_extension,strings.toolname_tts,strings.toolname_tts_extension,strings.translate_baseprompt,strings.translate_headline,strings.tts_headline,strings.voice]=await(0,_str.getStrings)(stringRequest)};_exports.getTinyAiString=string=>strings[string];_exports.getBackAndGenerateButtonContext=()=>({footer_buttons:[{hasText:!0,button_text:strings.back,icon_left:!0,icon_right:!1,primary:!1,secondary:!1,tertiary:!0,iconname:"arrow-left",iconstyle:"solid",action:"back",tooltip:strings.backbutton_tooltip},{hasText:!0,button_text:strings.generate,icon_left:!0,icon_right:!1,primary:!0,secondary:!1,tertiary:!1,iconname:"sparkle",customicon:!0,action:"generate",tooltip:strings.generatebutton_tooltip}]});_exports.getReplaceButtonsContext=mode=>({footer_iconbuttons:[{action:"delete",iconname:"trash",tooltip:strings.deletebutton_tooltip},{action:"regenerate",iconname:"arrows-rotate",tooltip:strings.regeneratebutton_tooltip}],footer_buttons:[{action:"insertbelow",hasText:!0,button_text:strings.insertbelow,icon_left:!0,icon_right:!1,secondary:!0,iconname:"text-insert-last",customicon:!0,tooltip:strings.insertbelow_tooltip},{action:mode===_constants.constants.modalModes.selection?"replace":"insertatcaret",hasText:!0,button_text:mode===_constants.constants.modalModes.selection?strings.replaceselection:strings.insertatcaret,icon_left:!0,icon_right:!1,primary:!0,iconname:"check",iconstyle:"solid",tooltip:mode===_constants.constants.modalModes.selection?strings.replaceselection_tooltip:strings.insertatcaret_tooltip}]});_exports.getInputContext=()=>({input:[{iconname:"sparkle",customicon:!0,button:[{customicon:!1,iconname:"arrow-right",iconstyle:"solid",icon_left:!1,icon_right:!0,tooltip:strings.freepromptbutton_tooltip}]}]});_exports.getShowPromptButtonContext=()=>({hasText:!0,button_text:strings.showprompt,icon_left:!0,icon_right:!1,tertiary:!0,iconname:"eye",iconstyle:"solid",action:"showprompt",textareatype:"prompt",collapsed:!0,tooltip:strings.showpromptbutton_tooltip})})); //# sourceMappingURL=basedata.min.js.map \ No newline at end of file diff --git a/amd/build/datahandler/basedata.min.js.map b/amd/build/datahandler/basedata.min.js.map index a800db3..e7f1ae4 100644 --- a/amd/build/datahandler/basedata.min.js.map +++ b/amd/build/datahandler/basedata.min.js.map @@ -1 +1 @@ -{"version":3,"file":"basedata.min.js","sources":["../../src/datahandler/basedata.js"],"sourcesContent":["// This file is part of Moodle - http://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\nimport {getStrings} from 'core/str';\nimport {prefetchStrings} from 'core/prefetch';\nimport {constants} from 'tiny_ai/constants';\n\n/**\n * Tiny AI base data provider.\n *\n * @module tiny_ai/datahandler/basedata\n * @copyright 2024, ISB Bayern\n * @author Philipp Memmel\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nconst stringKeys = [\n 'aigenerating',\n 'aisuggestion',\n 'audiogen_headline',\n 'audiogen_placeholder',\n 'back',\n 'backbutton_tooltip',\n 'cancel',\n 'deletebutton_tooltip',\n 'describe_baseprompt',\n 'describe_headline',\n 'dismiss',\n 'dismisssuggestion',\n 'error_nopromptgiven',\n 'freeprompt_placeholder',\n 'freepromptbutton_tooltip',\n 'gender',\n 'generalerror',\n 'generate',\n 'generatebutton_tooltip',\n 'hideprompt',\n 'imggen_headline',\n 'imggen_placeholder',\n 'insertatcaret',\n 'insertatcaretbutton_tooltip',\n 'insertbelow',\n 'insertbelowbutton_tooltip',\n 'keeplanguagetype',\n 'languagetype',\n 'languagetype_prompt',\n 'mainselection_heading',\n 'maxwordcount',\n 'maxwordcount_prompt',\n 'nomaxwordcount',\n 'regeneratebutton_tooltip',\n 'replaceselection',\n 'replaceselectionbutton_tooltip',\n 'reworkprompt',\n 'simplelanguage',\n 'size',\n 'showprompt',\n 'showpromptbutton_tooltip',\n 'summarize_baseprompt',\n 'summarize_headline',\n 'targetlanguage',\n 'technicallanguage',\n 'texttouse',\n 'toolname_audiogen',\n 'toolname_describe',\n 'toolname_describe_extension',\n 'toolname_imggen',\n 'toolname_summarize',\n 'toolname_summarize_extension',\n 'toolname_translate',\n 'toolname_translate_extension',\n 'toolname_tts',\n 'toolname_tts_extension',\n 'translate_baseprompt',\n 'translate_headline',\n 'tts_headline',\n 'voice'\n];\n\nlet strings = {};\n\n\n\nexport const init = async() => {\n prefetchStrings('tiny_ai', stringKeys);\n const stringRequest = stringKeys.map(key => {\n return {key, component: 'tiny_ai'};\n });\n // We now get the strings. They are already prefetched, so this is not a performance feature.\n // We just use this to avoid having to code asynchronously all the time just for retrieving the\n // strings by using getString which returns a promise.\n [\n strings.aigenerating,\n strings.aisuggestion,\n strings.audiogen_headline,\n strings.audiogen_placeholder,\n strings.back,\n strings.backbutton_tooltip,\n strings.cancel,\n strings.deletebutton_tooltip,\n strings.describe_baseprompt,\n strings.describe_headline,\n strings.dismiss,\n strings.dismisssuggestion,\n strings.error_nopromptgiven,\n strings.freeprompt_placeholder,\n strings.freepromptbutton_tooltip,\n strings.gender,\n strings.generalerror,\n strings.generate,\n strings.generatebutton_tooltip,\n strings.hideprompt,\n strings.imggen_headline,\n strings.imggen_placeholder,\n strings.insertatcaret,\n strings.insertatcaretbutton_tooltip,\n strings.insertbelow,\n strings.insertbelowbutton_tooltip,\n strings.keeplanguagetype,\n strings.languagetype,\n strings.languagetype_prompt,\n strings.mainselection_heading,\n strings.maxwordcount,\n strings.maxwordcount_prompt,\n strings.nomaxwordcount,\n strings.regeneratebutton_tooltip,\n strings.replaceselection,\n strings.replaceselectionbutton_tooltip,\n strings.reworkprompt,\n strings.simplelanguage,\n strings.size,\n strings.showprompt,\n strings.showpromptbutton_tooltip,\n strings.summarize_baseprompt,\n strings.summarize_headline,\n strings.targetlanguage,\n strings.technicallanguage,\n strings.texttouse,\n strings.toolname_audiogen,\n strings.toolname_describe,\n strings.toolname_describe_extension,\n strings.toolname_imggen,\n strings.toolname_summarize,\n strings.toolname_summarize_extension,\n strings.toolname_translate,\n strings.toolname_translate_extension,\n strings.toolname_tts,\n strings.toolname_tts_extension,\n strings.translate_baseprompt,\n strings.translate_headline,\n strings.tts_headline,\n strings.voice\n ] = await getStrings(stringRequest);\n};\n\nexport const getTinyAiString = (string) => {\n return strings[string];\n};\n\nexport const getBackAndGenerateButtonContext = () => {\n return {\n footer_buttons: [\n {\n hasText: true,\n button_text: strings.back,\n icon_left: true,\n icon_right: false,\n primary: false,\n secondary: false,\n tertiary: true,\n iconname: 'arrow-left',\n iconstyle: 'solid',\n action: 'back',\n tooltip: strings.backbutton_tooltip\n },\n {\n hasText: true,\n button_text: strings.generate,\n icon_left: true,\n icon_right: false,\n primary: true,\n secondary: false,\n tertiary: false,\n iconname: 'sparkle',\n customicon: true,\n action: 'generate',\n tooltip: strings.generatebutton_tooltip\n }\n ]\n };\n};\n\nexport const getReplaceButtonsContext = (mode) => {\n\n return {\n footer_iconbuttons:\n [\n {\n action: 'delete',\n iconname: 'trash',\n tooltip: strings.deletebutton_tooltip\n },\n {\n action: 'regenerate',\n iconname: 'arrows-rotate',\n tooltip: strings.regeneratebutton_tooltip\n }\n ],\n footer_buttons:\n [\n {\n action: 'insertbelow',\n hasText: true,\n button_text: strings.insertbelow,\n icon_left: true,\n icon_right: false,\n secondary: true,\n iconname: 'text-insert-last',\n customicon: true,\n tooltip: strings.insertbelow_tooltip\n },\n {\n action: mode === constants.modalModes.selection ? 'replace' : 'insertatcaret',\n hasText: true,\n button_text: mode === constants.modalModes.selection ? strings.replaceselection : strings.insertatcaret,\n icon_left: true,\n icon_right: false,\n primary: true,\n iconname: 'check',\n iconstyle: 'solid',\n tooltip: mode === constants.modalModes.selection\n ? strings.replaceselection_tooltip : strings.insertatcaret_tooltip\n }\n ],\n };\n};\n\nexport const getInputContext = () => {\n return {\n input: [\n {\n iconname: 'sparkle',\n customicon: true,\n button: [\n {\n customicon: false,\n iconname: 'arrow-right',\n iconstyle: 'solid',\n icon_left: false,\n icon_right: true,\n tooltip: strings.freepromptbutton_tooltip\n }\n ]\n }\n ],\n };\n};\n\nexport const getShowPromptButtonContext = () => {\n return {\n hasText: true,\n button_text: strings.showprompt,\n icon_left: true,\n icon_right: false,\n tertiary: true,\n iconname: 'eye',\n iconstyle: 'solid',\n action: 'showprompt',\n textareatype: 'prompt',\n collapsed: true,\n tooltip: strings.showpromptbutton_tooltip\n };\n};\n"],"names":["stringKeys","strings","async","stringRequest","map","key","component","aigenerating","aisuggestion","audiogen_headline","audiogen_placeholder","back","backbutton_tooltip","cancel","deletebutton_tooltip","describe_baseprompt","describe_headline","dismiss","dismisssuggestion","error_nopromptgiven","freeprompt_placeholder","freepromptbutton_tooltip","gender","generalerror","generate","generatebutton_tooltip","hideprompt","imggen_headline","imggen_placeholder","insertatcaret","insertatcaretbutton_tooltip","insertbelow","insertbelowbutton_tooltip","keeplanguagetype","languagetype","languagetype_prompt","mainselection_heading","maxwordcount","maxwordcount_prompt","nomaxwordcount","regeneratebutton_tooltip","replaceselection","replaceselectionbutton_tooltip","reworkprompt","simplelanguage","size","showprompt","showpromptbutton_tooltip","summarize_baseprompt","summarize_headline","targetlanguage","technicallanguage","texttouse","toolname_audiogen","toolname_describe","toolname_describe_extension","toolname_imggen","toolname_summarize","toolname_summarize_extension","toolname_translate","toolname_translate_extension","toolname_tts","toolname_tts_extension","translate_baseprompt","translate_headline","tts_headline","voice","string","footer_buttons","hasText","button_text","icon_left","icon_right","primary","secondary","tertiary","iconname","iconstyle","action","tooltip","customicon","mode","footer_iconbuttons","insertbelow_tooltip","constants","modalModes","selection","replaceselection_tooltip","insertatcaret_tooltip","input","button","textareatype","collapsed"],"mappings":";;;;;;;;;MA4BMA,WAAa,CACf,e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AY,EACZJ,SAAU,cACVC,UAAW,QACXN,WAAW,EACXC,YAAY,EACZO,QAAS9E,QAAQoB,mEAQC,KAC/B,CACHgD,SAAS,EACTC,YAAarE,QAAQ6C,WACrByB,WAAW,EACXC,YAAY,EACZG,UAAU,EACVC,SAAU,MACVC,UAAW,QACXC,OAAQ,aACRa,aAAc,SACdC,WAAW,EACXb,QAAS9E,QAAQ8C"} \ No newline at end of file +{"version":3,"file":"basedata.min.js","sources":["../../src/datahandler/basedata.js"],"sourcesContent":["// This file is part of Moodle - http://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\nimport {getStrings} from 'core/str';\nimport {prefetchStrings} from 'core/prefetch';\nimport {constants} from 'tiny_ai/constants';\n\n/**\n * Tiny AI base data provider.\n *\n * @module tiny_ai/datahandler/basedata\n * @copyright 2024, ISB Bayern\n * @author Philipp Memmel\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nconst stringKeys = [\n 'aigenerating',\n 'aisuggestion',\n 'audiogen_headline',\n 'audiogen_placeholder',\n 'back',\n 'backbutton_tooltip',\n 'cancel',\n 'deletebutton_tooltip',\n 'describeimg_baseprompt',\n 'describeimg_headline',\n 'describe_baseprompt',\n 'describe_headline',\n 'dismiss',\n 'dismisssuggestion',\n 'error_nofile',\n 'error_nofileinclipboard_text',\n 'error_nofileinclipboard_title',\n 'error_nopromptgiven',\n 'freeprompt_placeholder',\n 'freepromptbutton_tooltip',\n 'gender',\n 'generalerror',\n 'generate',\n 'generatebutton_tooltip',\n 'hideprompt',\n 'imggen_headline',\n 'imggen_placeholder',\n 'imagetotext_baseprompt',\n 'imagetotext_headline',\n 'imagetotext_insertimage',\n 'insertatcaret',\n 'insertatcaretbutton_tooltip',\n 'insertbelow',\n 'insertbelowbutton_tooltip',\n 'keeplanguagetype',\n 'languagetype',\n 'languagetype_prompt',\n 'mainselection_heading',\n 'maxwordcount',\n 'maxwordcount_prompt',\n 'nomaxwordcount',\n 'regeneratebutton_tooltip',\n 'replaceselection',\n 'replaceselectionbutton_tooltip',\n 'reworkprompt',\n 'simplelanguage',\n 'size',\n 'showprompt',\n 'showpromptbutton_tooltip',\n 'summarize_baseprompt',\n 'summarize_headline',\n 'targetlanguage',\n 'technicallanguage',\n 'texttouse',\n 'toolname_audiogen',\n 'toolname_describe',\n 'toolname_describeimg',\n 'toolname_describe_extension',\n 'toolname_imggen',\n 'toolname_imagetotext',\n 'toolname_summarize',\n 'toolname_summarize_extension',\n 'toolname_translate',\n 'toolname_translate_extension',\n 'toolname_tts',\n 'toolname_tts_extension',\n 'translate_baseprompt',\n 'translate_headline',\n 'tts_headline',\n 'voice'\n];\n\nlet strings = {};\n\n\n\nexport const init = async() => {\n prefetchStrings('tiny_ai', stringKeys);\n const stringRequest = stringKeys.map(key => {\n return {key, component: 'tiny_ai'};\n });\n // We now get the strings. They are already prefetched, so this is not a performance feature.\n // We just use this to avoid having to code asynchronously all the time just for retrieving the\n // strings by using getString which returns a promise.\n [\n strings.aigenerating,\n strings.aisuggestion,\n strings.audiogen_headline,\n strings.audiogen_placeholder,\n strings.back,\n strings.backbutton_tooltip,\n strings.cancel,\n strings.deletebutton_tooltip,\n strings.describeimg_baseprompt,\n strings.describeimg_headline,\n strings.describe_baseprompt,\n strings.describe_headline,\n strings.dismiss,\n strings.dismisssuggestion,\n strings.error_nofile,\n strings.error_nofileinclipboard_text,\n strings.error_nofileinclipboard_title,\n strings.error_nopromptgiven,\n strings.freeprompt_placeholder,\n strings.freepromptbutton_tooltip,\n strings.gender,\n strings.generalerror,\n strings.generate,\n strings.generatebutton_tooltip,\n strings.hideprompt,\n strings.imggen_headline,\n strings.imggen_placeholder,\n strings.imagetotext_baseprompt,\n strings.imagetotext_headline,\n strings.imagetotext_insertimage,\n strings.insertatcaret,\n strings.insertatcaretbutton_tooltip,\n strings.insertbelow,\n strings.insertbelowbutton_tooltip,\n strings.keeplanguagetype,\n strings.languagetype,\n strings.languagetype_prompt,\n strings.mainselection_heading,\n strings.maxwordcount,\n strings.maxwordcount_prompt,\n strings.nomaxwordcount,\n strings.regeneratebutton_tooltip,\n strings.replaceselection,\n strings.replaceselectionbutton_tooltip,\n strings.reworkprompt,\n strings.simplelanguage,\n strings.size,\n strings.showprompt,\n strings.showpromptbutton_tooltip,\n strings.summarize_baseprompt,\n strings.summarize_headline,\n strings.targetlanguage,\n strings.technicallanguage,\n strings.texttouse,\n strings.toolname_audiogen,\n strings.toolname_describe,\n strings.toolname_describeimg,\n strings.toolname_describe_extension,\n strings.toolname_imggen,\n strings.toolname_imagetotext,\n strings.toolname_summarize,\n strings.toolname_summarize_extension,\n strings.toolname_translate,\n strings.toolname_translate_extension,\n strings.toolname_tts,\n strings.toolname_tts_extension,\n strings.translate_baseprompt,\n strings.translate_headline,\n strings.tts_headline,\n strings.voice\n ] = await getStrings(stringRequest);\n};\n\nexport const getTinyAiString = (string) => {\n return strings[string];\n};\n\nexport const getBackAndGenerateButtonContext = () => {\n return {\n footer_buttons: [\n {\n hasText: true,\n button_text: strings.back,\n icon_left: true,\n icon_right: false,\n primary: false,\n secondary: false,\n tertiary: true,\n iconname: 'arrow-left',\n iconstyle: 'solid',\n action: 'back',\n tooltip: strings.backbutton_tooltip\n },\n {\n hasText: true,\n button_text: strings.generate,\n icon_left: true,\n icon_right: false,\n primary: true,\n secondary: false,\n tertiary: false,\n iconname: 'sparkle',\n customicon: true,\n action: 'generate',\n tooltip: strings.generatebutton_tooltip\n }\n ]\n };\n};\n\nexport const getReplaceButtonsContext = (mode) => {\n\n return {\n footer_iconbuttons:\n [\n {\n action: 'delete',\n iconname: 'trash',\n tooltip: strings.deletebutton_tooltip\n },\n {\n action: 'regenerate',\n iconname: 'arrows-rotate',\n tooltip: strings.regeneratebutton_tooltip\n }\n ],\n footer_buttons:\n [\n {\n action: 'insertbelow',\n hasText: true,\n button_text: strings.insertbelow,\n icon_left: true,\n icon_right: false,\n secondary: true,\n iconname: 'text-insert-last',\n customicon: true,\n tooltip: strings.insertbelow_tooltip\n },\n {\n action: mode === constants.modalModes.selection ? 'replace' : 'insertatcaret',\n hasText: true,\n button_text: mode === constants.modalModes.selection ? strings.replaceselection : strings.insertatcaret,\n icon_left: true,\n icon_right: false,\n primary: true,\n iconname: 'check',\n iconstyle: 'solid',\n tooltip: mode === constants.modalModes.selection\n ? strings.replaceselection_tooltip : strings.insertatcaret_tooltip\n }\n ],\n };\n};\n\nexport const getInputContext = () => {\n return {\n input: [\n {\n iconname: 'sparkle',\n customicon: true,\n button: [\n {\n customicon: false,\n iconname: 'arrow-right',\n iconstyle: 'solid',\n icon_left: false,\n icon_right: true,\n tooltip: strings.freepromptbutton_tooltip\n }\n ]\n }\n ],\n };\n};\n\nexport const getShowPromptButtonContext = () => {\n return {\n hasText: true,\n button_text: strings.showprompt,\n icon_left: true,\n icon_right: false,\n tertiary: true,\n iconname: 'eye',\n iconstyle: 'solid',\n action: 'showprompt',\n textareatype: 'prompt',\n collapsed: true,\n tooltip: strings.showpromptbutton_tooltip\n };\n};\n"],"names":["stringKeys","strings","async","stringRequest","map","key","component","aigenerating","aisuggestion","audiogen_headline","audiogen_placeholder","back","backbutton_tooltip","cancel","deletebutton_tooltip","describeimg_baseprompt","describeimg_headline","describe_baseprompt","describe_headline","dismiss","dismisssuggestion","error_nofile","error_nofileinclipboard_text","error_nofileinclipboard_title","error_nopromptgiven","freeprompt_placeholder","freepromptbutton_tooltip","gender","generalerror","generate","generatebutton_tooltip","hideprompt","imggen_headline","imggen_placeholder","imagetotext_baseprompt","imagetotext_headline","imagetotext_insertimage","insertatcaret","insertatcaretbutton_tooltip","insertbelow","insertbelowbutton_tooltip","keeplanguagetype","languagetype","languagetype_prompt","mainselection_heading","maxwordcount","maxwordcount_prompt","nomaxwordcount","regeneratebutton_tooltip","replaceselection","replaceselectionbutton_tooltip","reworkprompt","simplelanguage","size","showprompt","showpromptbutton_tooltip","summarize_baseprompt","summarize_headline","targetlanguage","technicallanguage","texttouse","toolname_audiogen","toolname_describe","toolname_describeimg","toolname_describe_extension","toolname_imggen","toolname_imagetotext","toolname_summarize","toolname_summarize_extension","toolname_translate","toolname_translate_extension","toolname_tts","toolname_tts_extension","translate_baseprompt","translate_headline","tts_headline","voice","string","footer_buttons","hasText","button_text","icon_left","icon_right","primary","secondary","tertiary","iconname","iconstyle","action","tooltip","customicon","mode","footer_iconbuttons","insertbelow_tooltip","constants","modalModes","selection","replaceselection_tooltip","insertatcaret_tooltip","input","button","textareatype","collapsed"],"mappings":";;;;;;;;;MA4BMA,WAAa,CACf,eACA,eACA,oBACA,uBACA,OACA,qBACA,SACA,uBACA,yBACA,uBACA,sBACA,oBACA,UACA,oBACA,eACA,+BACA,gCACA,sBACA,yBACA,2BACA,SACA,eACA,WACA,yBACA,aACA,kBACA,qBACA,yBACA,uBACA,0BACA,gBACA,8BACA,cACA,4BACA,mBACA,eACA,sBACA,wBACA,eACA,sBACA,iBACA,2BACA,mBACA,iCACA,eACA,iBACA,OACA,aACA,2BACA,uBACA,qBACA,iBACA,oBACA,YACA,oBACA,oBACA,uBACA,8BACA,kBACA,uBACA,qBACA,+BACA,qBACA,+BACA,eACA,yBACA,uBACA,qBACA,eACA,aAGAC,QAAU,iBAIMC,wCACA,UAAWF,kBACrBG,cAAgBH,WAAWI,KAAIC,MAC1B,CAACA,IAAAA,IAAKC,UAAW,eAMxBL,QAAQM,aACRN,QAAQO,aACRP,QAAQQ,kBACRR,QAAQS,qBACRT,QAAQU,KACRV,QAAQW,mBACRX,QAAQY,OACRZ,QAAQa,qBACRb,QAAQc,uBACRd,QAAQe,qBACRf,QAAQgB,oBACRhB,QAAQiB,kBACRj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/E,QAAQ4B,SACrBoD,WAAW,EACXC,YAAY,EACZC,SAAS,EACTC,WAAW,EACXC,UAAU,EACVC,SAAU,UACVI,YAAY,EACZF,OAAQ,WACRC,QAASxF,QAAQ6B,6DAMQ6D,OAE7B,CACJC,mBACI,CACI,CACIJ,OAAQ,SACRF,SAAU,QACVG,QAASxF,QAAQa,sBAErB,CACI0E,OAAQ,aACRF,SAAU,gBACVG,QAASxF,QAAQ+C,2BAG7B8B,eACI,CACI,CACIU,OAAQ,cACRT,SAAS,EACTC,YAAa/E,QAAQsC,YACrB0C,WAAW,EACXC,YAAY,EACZE,WAAW,EACXE,SAAU,mBACVI,YAAY,EACZD,QAASxF,QAAQ4F,qBAErB,CACIL,OAAQG,OAASG,qBAAUC,WAAWC,UAAY,UAAY,gBAC9DjB,SAAS,EACTC,YAAaW,OAASG,qBAAUC,WAAWC,UAAY/F,QAAQgD,iBAAmBhD,QAAQoC,cAC1F4C,WAAW,EACXC,YAAY,EACZC,SAAS,EACTG,SAAU,QACVC,UAAW,QACXE,QAASE,OAASG,qBAAUC,WAAWC,UACjC/F,QAAQgG,yBAA2BhG,QAAQiG,mDAMtC,KACpB,CACHC,MAAO,CACH,CACIb,SAAU,UACVI,YAAY,EACZU,OAAQ,CACJ,CACIV,YAAY,EACZJ,SAAU,cACVC,UAAW,QACXN,WAAW,EACXC,YAAY,EACZO,QAASxF,QAAQyB,mEAQC,KAC/B,CACHqD,SAAS,EACTC,YAAa/E,QAAQqD,WACrB2B,WAAW,EACXC,YAAY,EACZG,UAAU,EACVC,SAAU,MACVC,UAAW,QACXC,OAAQ,aACRa,aAAc,SACdC,WAAW,EACXb,QAASxF,QAAQsD"} \ No newline at end of file diff --git a/amd/build/datahandler/itt.min.js b/amd/build/datahandler/itt.min.js index 62fcd66..ea6236d 100644 --- a/amd/build/datahandler/itt.min.js +++ b/amd/build/datahandler/itt.min.js @@ -6,6 +6,6 @@ define("tiny_ai/datahandler/itt",["exports","local_ai_manager/config","tiny_ai/d * @copyright 2024, ISB Bayern * @author Philipp Memmel * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.default=void 0,AiConfig=_interopRequireWildcard(AiConfig),BasedataHandler=_interopRequireWildcard(BasedataHandler),_base=_interopRequireDefault(_base),_config2=_interopRequireDefault(_config2);class _default extends _base.default{getOptions(){const options={},datamanager=(0,_utils.getDatamanager)(this.uniqid);return options.image=datamanager.getCurrentFile(),options}async getTemplateContext(tool){const context={modal_headline:BasedataHandler.getTinyAiString(tool+"_headline"),showIcon:!0,tool:tool,textareatype:"prompt",placeholder:BasedataHandler.getTinyAiString(tool+"_placeholder")};return Object.assign(context,BasedataHandler.getShowPromptButtonContext()),Object.assign(context,BasedataHandler.getBackAndGenerateButtonContext()),context}}return _exports.default=_default,_exports.default})); + */Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.default=void 0,AiConfig=_interopRequireWildcard(AiConfig),BasedataHandler=_interopRequireWildcard(BasedataHandler),_base=_interopRequireDefault(_base),_config2=_interopRequireDefault(_config2);class _default extends _base.default{getOptions(){const options={},datamanager=(0,_utils.getDatamanager)(this.uniqid);return options.image=datamanager.getCurrentFile(),options}getPrompt(tool){return BasedataHandler.getTinyAiString(tool+"_baseprompt")}async getTemplateContext(tool){const context={modal_headline:BasedataHandler.getTinyAiString(tool+"_headline"),showIcon:!0,tool:tool,textareatype:"prompt",placeholder:BasedataHandler.getTinyAiString(tool+"_placeholder"),insertimagedescription:BasedataHandler.getTinyAiString("imagetotext_insertimage")};return Object.assign(context,BasedataHandler.getShowPromptButtonContext()),Object.assign(context,BasedataHandler.getBackAndGenerateButtonContext()),context}}return _exports.default=_default,_exports.default})); //# sourceMappingURL=itt.min.js.map \ No newline at end of file diff --git a/amd/build/datahandler/itt.min.js.map b/amd/build/datahandler/itt.min.js.map index 68e015e..946401c 100644 --- a/amd/build/datahandler/itt.min.js.map +++ b/amd/build/datahandler/itt.min.js.map @@ -1 +1 @@ -{"version":3,"file":"itt.min.js","sources":["../../src/datahandler/itt.js"],"sourcesContent":["// This file is part of Moodle - http://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\nimport * as AiConfig from 'local_ai_manager/config';\nimport * as BasedataHandler from 'tiny_ai/datahandler/basedata';\nimport BaseHandler from 'tiny_ai/datahandler/base';\nimport Config from 'core/config';\nimport {getDatamanager} from \"../utils\";\n\n/**\n * Tiny AI data handler for image to text.\n *\n * @module tiny_ai/datahandler/itt\n * @copyright 2024, ISB Bayern\n * @author Philipp Memmel\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nexport default class extends BaseHandler {\n\n getOptions() {\n const options = {};\n const datamanager = getDatamanager(this.uniqid);\n options.image = datamanager.getCurrentFile();\n return options;\n }\n\n /**\n * Get the rendering context.\n *\n * @param {string} tool the tool to generate the context for, can be 'describeimage' and 'analyzehandwriting'\n */\n async getTemplateContext(tool) {\n const context = {\n modal_headline: BasedataHandler.getTinyAiString(tool + '_headline'),\n showIcon: true,\n tool: tool,\n textareatype: 'prompt',\n placeholder: BasedataHandler.getTinyAiString(tool + '_placeholder'),\n };\n\n Object.assign(context, BasedataHandler.getShowPromptButtonContext());\n\n Object.assign(context, BasedataHandler.getBackAndGenerateButtonContext());\n return context;\n }\n}\n"],"names":["BaseHandler","getOptions","options","datamanager","this","uniqid","image","getCurrentFile","tool","context","modal_headline","BasedataHandler","getTinyAiString","showIcon","textareatype","placeholder","Object","assign","getShowPromptButtonContext","getBackAndGenerateButtonContext"],"mappings":";;;;;;;;8RA8B6BA,cAEzBC,mBACUC,QAAU,GACVC,aAAc,yBAAeC,KAAKC,eACxCH,QAAQI,MAAQH,YAAYI,iBACrBL,iCAQcM,YACfC,QAAU,CACZC,eAAgBC,gBAAgBC,gBAAgBJ,KAAO,aACvDK,UAAU,EACVL,KAAMA,KACNM,aAAc,SACdC,YAAaJ,gBAAgBC,gBAAgBJ,KAAO,wBAGxDQ,OAAOC,OAAOR,QAASE,gBAAgBO,8BAEvCF,OAAOC,OAAOR,QAASE,gBAAgBQ,mCAChCV"} \ No newline at end of file +{"version":3,"file":"itt.min.js","sources":["../../src/datahandler/itt.js"],"sourcesContent":["// This file is part of Moodle - http://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\nimport * as AiConfig from 'local_ai_manager/config';\nimport * as BasedataHandler from 'tiny_ai/datahandler/basedata';\nimport BaseHandler from 'tiny_ai/datahandler/base';\nimport Config from 'core/config';\nimport {getDatamanager} from \"../utils\";\n\n/**\n * Tiny AI data handler for image to text.\n *\n * @module tiny_ai/datahandler/itt\n * @copyright 2024, ISB Bayern\n * @author Philipp Memmel\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nexport default class extends BaseHandler {\n\n getOptions() {\n const options = {};\n const datamanager = getDatamanager(this.uniqid);\n options.image = datamanager.getCurrentFile();\n return options;\n }\n\n /**\n * Get the prompt.\n *\n * @param {string} tool the tool to generate the prompt for, can be 'describeimage' and 'imagetotext'\n */\n getPrompt(tool) {\n return BasedataHandler.getTinyAiString(tool + '_baseprompt');\n }\n\n /**\n * Get the rendering context.\n *\n * @param {string} tool the tool to generate the context for, can be 'describeimage' and 'imagetotext'\n */\n async getTemplateContext(tool) {\n const context = {\n modal_headline: BasedataHandler.getTinyAiString(tool + '_headline'),\n showIcon: true,\n tool: tool,\n textareatype: 'prompt',\n placeholder: BasedataHandler.getTinyAiString(tool + '_placeholder'),\n insertimagedescription: BasedataHandler.getTinyAiString('imagetotext_insertimage')\n };\n\n Object.assign(context, BasedataHandler.getShowPromptButtonContext());\n\n Object.assign(context, BasedataHandler.getBackAndGenerateButtonContext());\n return context;\n }\n}\n"],"names":["BaseHandler","getOptions","options","datamanager","this","uniqid","image","getCurrentFile","getPrompt","tool","BasedataHandler","getTinyAiString","context","modal_headline","showIcon","textareatype","placeholder","insertimagedescription","Object","assign","getShowPromptButtonContext","getBackAndGenerateButtonContext"],"mappings":";;;;;;;;8RA8B6BA,cAEzBC,mBACUC,QAAU,GACVC,aAAc,yBAAeC,KAAKC,eACxCH,QAAQI,MAAQH,YAAYI,iBACrBL,QAQXM,UAAUC,aACCC,gBAAgBC,gBAAgBF,KAAO,wCAQzBA,YACfG,QAAU,CACZC,eAAgBH,gBAAgBC,gBAAgBF,KAAO,aACvDK,UAAU,EACVL,KAAMA,KACNM,aAAc,SACdC,YAAaN,gBAAgBC,gBAAgBF,KAAO,gBACpDQ,uBAAwBP,gBAAgBC,gBAAgB,mCAG5DO,OAAOC,OAAOP,QAASF,gBAAgBU,8BAEvCF,OAAOC,OAAOP,QAASF,gBAAgBW,mCAChCT"} \ No newline at end of file diff --git a/amd/build/datahandler/start.min.js b/amd/build/datahandler/start.min.js index c368c92..7753f2e 100644 --- a/amd/build/datahandler/start.min.js +++ b/amd/build/datahandler/start.min.js @@ -6,6 +6,6 @@ define("tiny_ai/datahandler/start",["exports","core/config","core/str","tiny_ai/ * @copyright 2024, ISB Bayern * @author Philipp Memmel * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.default=void 0,config=_interopRequireWildcard(config),BasedataHandler=_interopRequireWildcard(BasedataHandler),_base=(obj=_base)&&obj.__esModule?obj:{default:obj};class _default extends _base.default{constructor(){super(...arguments),_defineProperty(this,"stringKeys",["error_limitreached","error_pleaseconfirm","error_purposenotconfigured","error_tenantdisabled","error_unavailable_noselection","error_unavailable_selection","error_userlocked","error_usernotconfirmed"]),_defineProperty(this,"aiConfig",null),_defineProperty(this,"strings",{})}async init(){this.aiConfig=await(0,_config2.getAiConfig)();const stringRequest=this.stringKeys.map((key=>({key:key,component:"local_ai_manager"})));[this.strings.error_limitreached,this.strings.error_pleaseconfirm,this.strings.error_purposenotconfigured,this.strings.error_tenantdisabled,this.strings.error_unavailable_noselection,this.strings.error_unavailable_selection,this.strings.error_userlocked,this.strings.error_usernotconfirmed]=await(0,_str.getStrings)(stringRequest),this.strings.error_editor_notavailable=await(0,_str.getString)("error_tiny_ai_notavailable","tiny_ai");const confirmLink=document.createElement("a");confirmLink.href="".concat(config.wwwroot,"/local/ai_manager/confirm_ai_usage.php"),confirmLink.innerText=this.strings.error_pleaseconfirm,confirmLink.target="_blank",this.strings.combinedusernotconfirmederror=this.strings.error_usernotconfirmed+" "+confirmLink.outerHTML}getPurposeConfig(tool){if(null===this.aiConfig)throw new Error("Coding error: init function was not called before accessing this.getPurposeConfig!");const toolPurpose=_constants.constants.toolPurposeMapping[tool];return this.aiConfig.purposes.filter((purpose=>purpose.purpose===toolPurpose))[0]}isTinyAiDisabled(){return this.aiConfig.tenantenabled?this.aiConfig.userconfirmed?this.aiConfig.userlocked?this.strings.error_userlocked:"":this.strings.combinedusernotconfirmederror:this.strings.error_tenantdisabled}isToolDisabled(tool,mode){if(this.isTinyAiDisabled())return this.isTinyAiDisabled();const purposeInfo=this.getPurposeConfig(tool);return purposeInfo.isconfigured?purposeInfo.limitreached?this.strings.error_limitreached:mode===_constants.constants.modalModes.selection?["audiogen","imggen","describeimg"].includes(tool)?this.strings.error_unavailable_noselection:"":mode===_constants.constants.modalModes.general&&["summarize","translate","describe","tts"].includes(tool)?this.strings.error_unavailable_selection:"":this.strings.error_purposenotconfigured}isToolHidden(tool){const purposeInfo=this.getPurposeConfig(tool);if("role_basic"===this.aiConfig.role){if(!this.aiConfig.tenantenabled)return!0;if(!purposeInfo.isconfigured)return!0}return!1}async getTemplateContext(editorUtils){const mode=editorUtils.getMode();let toolButtons=[];"role_basic"===this.aiConfig.role&&this.isTinyAiDisabled()&&(await(0,_utils.errorAlert)(await(0,_str.getString)("error_tiny_ai_notavailable","tiny_ai")+"
"+this.isTinyAiDisabled()),editorUtils.getModal().destroy()),this.isToolHidden("summarize")||toolButtons.push({toolname:"summarize",tool:BasedataHandler.getTinyAiString("toolname_summarize"),description:BasedataHandler.getTinyAiString("toolname_summarize_extension"),customicon:!0,iconname:"shorten",disabled:this.isToolDisabled("summarize",mode).length>0,tooltip:(0,_utils.stripHtmlTags)(this.isToolDisabled("summarize",mode)),action:"loadsummarize"}),this.isToolHidden("translate")||toolButtons.push({toolname:"translate",tool:BasedataHandler.getTinyAiString("toolname_translate"),description:BasedataHandler.getTinyAiString("toolname_translate_extension"),iconname:"language",iconstyle:"solid",disabled:this.isToolDisabled("translate",mode).length>0,tooltip:(0,_utils.stripHtmlTags)(this.isToolDisabled("translate",mode)),action:"loadtranslate"}),this.isToolHidden("describe")||toolButtons.push({toolname:"describe",tool:BasedataHandler.getTinyAiString("toolname_describe"),description:BasedataHandler.getTinyAiString("toolname_describe_extension"),customicon:!0,iconname:"extend",disabled:this.isToolDisabled("describe",mode).length>0,tooltip:(0,_utils.stripHtmlTags)(this.isToolDisabled("describe",mode)),action:"loaddescribe"}),this.isToolHidden("tts")||toolButtons.push({toolname:"tts",tool:BasedataHandler.getTinyAiString("toolname_tts"),description:BasedataHandler.getTinyAiString("toolname_tts_extension"),iconstyle:"solid",iconname:"microphone",disabled:this.isToolDisabled("tts",mode).length>0,tooltip:(0,_utils.stripHtmlTags)(this.isToolDisabled("tts",mode)),action:"loadtts"}),this.isToolHidden("audiogen")||toolButtons.push({toolname:"audiogen",tool:BasedataHandler.getTinyAiString("toolname_audiogen"),iconstyle:"solid",iconname:"microphone",disabled:this.isToolDisabled("audiogen",mode).length>0,tooltip:(0,_utils.stripHtmlTags)(this.isToolDisabled("audiogen",mode)),action:"loadaudiogen"}),this.isToolHidden("imggen")||toolButtons.push({toolname:"imggen",tool:BasedataHandler.getTinyAiString("toolname_imggen"),iconstyle:"solid",iconname:"image",disabled:this.isToolDisabled("imggen",mode).length>0,tooltip:(0,_utils.stripHtmlTags)(this.isToolDisabled("imggen",mode)),action:"loadimggen"}),this.isToolHidden("describeimg")||toolButtons.push({toolname:"describeimg",tool:BasedataHandler.getTinyAiString("toolname_describeimg"),iconstyle:"solid",iconname:"image",disabled:this.isToolDisabled("describeimg",mode).length>0,tooltip:(0,_utils.stripHtmlTags)(this.isToolDisabled("describeimg",mode)),action:"loaddescribeimg"}),toolButtons.sort(((a,b)=>a.disabled&&!b.disabled?1:b.disabled&&!a.disabled?-1:0));const templateContext={showIcon:!0,modal_headline:BasedataHandler.getTinyAiString("mainselection_heading"),action:"loadfreeprompt",modal_buttons:toolButtons,freeprompthidden:!0};return Object.assign(templateContext,BasedataHandler.getInputContext()),this.isTinyAiDisabled()&&(templateContext.input[0].disabled=!0,templateContext.input[0].hasError=!0,templateContext.input[0].errorMessage=this.isTinyAiDisabled()),this.isToolDisabled("freeprompt",mode)&&(templateContext.input[0].disabled=!0),templateContext}}return _exports.default=_default,_exports.default})); + */Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.default=void 0,config=_interopRequireWildcard(config),BasedataHandler=_interopRequireWildcard(BasedataHandler),_base=(obj=_base)&&obj.__esModule?obj:{default:obj};class _default extends _base.default{constructor(){super(...arguments),_defineProperty(this,"stringKeys",["error_limitreached","error_pleaseconfirm","error_purposenotconfigured","error_tenantdisabled","error_unavailable_noselection","error_unavailable_selection","error_userlocked","error_usernotconfirmed"]),_defineProperty(this,"aiConfig",null),_defineProperty(this,"strings",{})}async init(){this.aiConfig=await(0,_config2.getAiConfig)();const stringRequest=this.stringKeys.map((key=>({key:key,component:"local_ai_manager"})));[this.strings.error_limitreached,this.strings.error_pleaseconfirm,this.strings.error_purposenotconfigured,this.strings.error_tenantdisabled,this.strings.error_unavailable_noselection,this.strings.error_unavailable_selection,this.strings.error_userlocked,this.strings.error_usernotconfirmed]=await(0,_str.getStrings)(stringRequest),this.strings.error_editor_notavailable=await(0,_str.getString)("error_tiny_ai_notavailable","tiny_ai");const confirmLink=document.createElement("a");confirmLink.href="".concat(config.wwwroot,"/local/ai_manager/confirm_ai_usage.php"),confirmLink.innerText=this.strings.error_pleaseconfirm,confirmLink.target="_blank",this.strings.combinedusernotconfirmederror=this.strings.error_usernotconfirmed+" "+confirmLink.outerHTML}getPurposeConfig(tool){if(null===this.aiConfig)throw new Error("Coding error: init function was not called before accessing this.getPurposeConfig!");const toolPurpose=_constants.constants.toolPurposeMapping[tool];return this.aiConfig.purposes.filter((purpose=>purpose.purpose===toolPurpose))[0]}isTinyAiDisabled(){return this.aiConfig.tenantenabled?this.aiConfig.userconfirmed?this.aiConfig.userlocked?this.strings.error_userlocked:"":this.strings.combinedusernotconfirmederror:this.strings.error_tenantdisabled}isToolDisabled(tool,mode){if(this.isTinyAiDisabled())return this.isTinyAiDisabled();const purposeInfo=this.getPurposeConfig(tool);return purposeInfo.isconfigured?purposeInfo.limitreached?this.strings.error_limitreached:mode===_constants.constants.modalModes.selection?["audiogen","imggen","describeimg"].includes(tool)?this.strings.error_unavailable_noselection:"":mode===_constants.constants.modalModes.general&&["summarize","translate","describe","tts"].includes(tool)?this.strings.error_unavailable_selection:"":this.strings.error_purposenotconfigured}isToolHidden(tool){const purposeInfo=this.getPurposeConfig(tool);if("role_basic"===this.aiConfig.role){if(!this.aiConfig.tenantenabled)return!0;if(!purposeInfo.isconfigured)return!0}return!1}async getTemplateContext(editorUtils){const mode=editorUtils.getMode();let toolButtons=[];"role_basic"===this.aiConfig.role&&this.isTinyAiDisabled()&&(await(0,_utils.errorAlert)(await(0,_str.getString)("error_tiny_ai_notavailable","tiny_ai")+"
"+this.isTinyAiDisabled()),editorUtils.getModal().destroy()),this.isToolHidden("summarize")||toolButtons.push({toolname:"summarize",tool:BasedataHandler.getTinyAiString("toolname_summarize"),description:BasedataHandler.getTinyAiString("toolname_summarize_extension"),customicon:!0,iconname:"shorten",disabled:this.isToolDisabled("summarize",mode).length>0,tooltip:(0,_utils.stripHtmlTags)(this.isToolDisabled("summarize",mode)),action:"loadsummarize"}),this.isToolHidden("translate")||toolButtons.push({toolname:"translate",tool:BasedataHandler.getTinyAiString("toolname_translate"),description:BasedataHandler.getTinyAiString("toolname_translate_extension"),iconname:"language",iconstyle:"solid",disabled:this.isToolDisabled("translate",mode).length>0,tooltip:(0,_utils.stripHtmlTags)(this.isToolDisabled("translate",mode)),action:"loadtranslate"}),this.isToolHidden("describe")||toolButtons.push({toolname:"describe",tool:BasedataHandler.getTinyAiString("toolname_describe"),description:BasedataHandler.getTinyAiString("toolname_describe_extension"),customicon:!0,iconname:"extend",disabled:this.isToolDisabled("describe",mode).length>0,tooltip:(0,_utils.stripHtmlTags)(this.isToolDisabled("describe",mode)),action:"loaddescribe"}),this.isToolHidden("tts")||toolButtons.push({toolname:"tts",tool:BasedataHandler.getTinyAiString("toolname_tts"),description:BasedataHandler.getTinyAiString("toolname_tts_extension"),iconstyle:"solid",iconname:"microphone",disabled:this.isToolDisabled("tts",mode).length>0,tooltip:(0,_utils.stripHtmlTags)(this.isToolDisabled("tts",mode)),action:"loadtts"}),this.isToolHidden("audiogen")||toolButtons.push({toolname:"audiogen",tool:BasedataHandler.getTinyAiString("toolname_audiogen"),iconstyle:"solid",iconname:"microphone",disabled:this.isToolDisabled("audiogen",mode).length>0,tooltip:(0,_utils.stripHtmlTags)(this.isToolDisabled("audiogen",mode)),action:"loadaudiogen"}),this.isToolHidden("imggen")||toolButtons.push({toolname:"imggen",tool:BasedataHandler.getTinyAiString("toolname_imggen"),iconstyle:"solid",iconname:"image",disabled:this.isToolDisabled("imggen",mode).length>0,tooltip:(0,_utils.stripHtmlTags)(this.isToolDisabled("imggen",mode)),action:"loadimggen"}),this.isToolHidden("describeimg")||toolButtons.push({toolname:"describeimg",tool:BasedataHandler.getTinyAiString("toolname_describeimg"),iconstyle:"solid",iconname:"file-image",disabled:this.isToolDisabled("describeimg",mode).length>0,tooltip:(0,_utils.stripHtmlTags)(this.isToolDisabled("describeimg",mode)),action:"loaddescribeimg"}),this.isToolHidden("imagetotext")||toolButtons.push({toolname:"imagetotext",tool:BasedataHandler.getTinyAiString("toolname_imagetotext"),iconstyle:"solid",iconname:"signature",disabled:this.isToolDisabled("imagetotext",mode).length>0,tooltip:(0,_utils.stripHtmlTags)(this.isToolDisabled("imagetotext",mode)),action:"loadimagetotext"}),toolButtons.sort(((a,b)=>a.disabled&&!b.disabled?1:b.disabled&&!a.disabled?-1:0));const templateContext={showIcon:!0,modal_headline:BasedataHandler.getTinyAiString("mainselection_heading"),action:"loadfreeprompt",modal_buttons:toolButtons,freeprompthidden:!0};return Object.assign(templateContext,BasedataHandler.getInputContext()),this.isTinyAiDisabled()&&(templateContext.input[0].disabled=!0,templateContext.input[0].hasError=!0,templateContext.input[0].errorMessage=this.isTinyAiDisabled()),this.isToolDisabled("freeprompt",mode)&&(templateContext.input[0].disabled=!0),templateContext}}return _exports.default=_default,_exports.default})); //# sourceMappingURL=start.min.js.map \ No newline at end of file diff --git a/amd/build/datahandler/start.min.js.map b/amd/build/datahandler/start.min.js.map index cf0927a..3ae8d71 100644 --- a/amd/build/datahandler/start.min.js.map +++ b/amd/build/datahandler/start.min.js.map @@ -1 +1 @@ -{"version":3,"file":"start.min.js","sources":["../../src/datahandler/start.js"],"sourcesContent":["// This file is part of Moodle - http://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\nimport * as config from 'core/config';\nimport {getString, getStrings} from 'core/str';\nimport {constants} from 'tiny_ai/constants';\nimport * as BasedataHandler from 'tiny_ai/datahandler/basedata';\nimport BaseHandler from 'tiny_ai/datahandler/base';\nimport {getAiConfig} from 'local_ai_manager/config';\nimport {errorAlert, stripHtmlTags} from 'tiny_ai/utils';\n\n\n/**\n * Tiny AI data handler for start page.\n *\n * @module tiny_ai/datahandler/start\n * @copyright 2024, ISB Bayern\n * @author Philipp Memmel\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nexport default class extends BaseHandler {\n\n stringKeys = [\n 'error_limitreached',\n 'error_pleaseconfirm',\n 'error_purposenotconfigured',\n 'error_tenantdisabled',\n 'error_unavailable_noselection',\n 'error_unavailable_selection',\n 'error_userlocked',\n 'error_usernotconfirmed'\n ];\n\n aiConfig = null;\n strings = {};\n\n async init() {\n this.aiConfig = await getAiConfig();\n // It's easier to fetch alle these strings before even if we do not use them\n // instead of making all functions async just because of getString returning a promise.\n const stringRequest = this.stringKeys.map(key => {\n return {key, component: 'local_ai_manager'};\n });\n\n [\n this.strings.error_limitreached,\n this.strings.error_pleaseconfirm,\n this.strings.error_purposenotconfigured,\n this.strings.error_tenantdisabled,\n this.strings.error_unavailable_noselection,\n this.strings.error_unavailable_selection,\n this.strings.error_userlocked,\n this.strings.error_usernotconfirmed\n ] = await getStrings(stringRequest);\n this.strings.error_editor_notavailable = await getString('error_tiny_ai_notavailable', 'tiny_ai');\n const confirmLink = document.createElement('a');\n confirmLink.href = `${config.wwwroot}/local/ai_manager/confirm_ai_usage.php`;\n confirmLink.innerText = this.strings.error_pleaseconfirm;\n confirmLink.target = '_blank';\n this.strings.combinedusernotconfirmederror = this.strings.error_usernotconfirmed + ' ' + confirmLink.outerHTML;\n }\n\n getPurposeConfig(tool) {\n if (this.aiConfig === null) {\n throw new Error('Coding error: init function was not called before accessing this.getPurposeConfig!');\n }\n const toolPurpose = constants.toolPurposeMapping[tool];\n return this.aiConfig.purposes.filter(purpose => purpose['purpose'] === toolPurpose)[0];\n }\n\n isTinyAiDisabled() {\n if (!this.aiConfig.tenantenabled) {\n return this.strings.error_tenantdisabled;\n }\n if (!this.aiConfig.userconfirmed) {\n return this.strings.combinedusernotconfirmederror;\n }\n if (this.aiConfig.userlocked) {\n return this.strings.error_userlocked;\n }\n return '';\n }\n\n isToolDisabled(tool, mode) {\n if (this.isTinyAiDisabled()) {\n return this.isTinyAiDisabled();\n }\n const purposeInfo = this.getPurposeConfig(tool);\n if (!purposeInfo.isconfigured) {\n return this.strings.error_purposenotconfigured;\n }\n if (purposeInfo.limitreached) {\n return this.strings.error_limitreached;\n }\n\n if (mode === constants.modalModes.selection) {\n return ['audiogen', 'imggen', 'describeimg'].includes(tool) ? this.strings.error_unavailable_noselection : '';\n } else if (mode === constants.modalModes.general) {\n return ['summarize', 'translate', 'describe', 'tts'].includes(tool) ? this.strings.error_unavailable_selection : '';\n }\n return '';\n }\n\n isToolHidden(tool) {\n const purposeInfo = this.getPurposeConfig(tool);\n // If the tenant is not allowed the plugin is being disabled completely, so we do not need\n // to check this case here.\n if (this.aiConfig.role === 'role_basic') {\n if (!this.aiConfig.tenantenabled) {\n return true;\n }\n if (!purposeInfo.isconfigured) {\n return true;\n }\n }\n return false;\n }\n\n async getTemplateContext(editorUtils) {\n const mode = editorUtils.getMode();\n let toolButtons = [];\n if (this.aiConfig.role === 'role_basic' && this.isTinyAiDisabled()) {\n await errorAlert(await getString('error_tiny_ai_notavailable', 'tiny_ai') + '
'\n + this.isTinyAiDisabled());\n editorUtils.getModal().destroy();\n }\n\n if (!this.isToolHidden('summarize')) {\n toolButtons.push({\n toolname: 'summarize',\n tool: BasedataHandler.getTinyAiString('toolname_summarize'),\n description: BasedataHandler.getTinyAiString('toolname_summarize_extension'),\n customicon: true,\n iconname: 'shorten',\n disabled: this.isToolDisabled('summarize', mode).length > 0,\n tooltip: stripHtmlTags(this.isToolDisabled('summarize', mode)),\n action: 'loadsummarize'\n });\n }\n if (!this.isToolHidden('translate')) {\n toolButtons.push({\n toolname: 'translate',\n tool: BasedataHandler.getTinyAiString('toolname_translate'),\n description: BasedataHandler.getTinyAiString('toolname_translate_extension'),\n iconname: 'language',\n iconstyle: 'solid',\n disabled: this.isToolDisabled('translate', mode).length > 0,\n tooltip: stripHtmlTags(this.isToolDisabled('translate', mode)),\n action: 'loadtranslate'\n });\n }\n if (!this.isToolHidden('describe')) {\n toolButtons.push({\n toolname: 'describe',\n tool: BasedataHandler.getTinyAiString('toolname_describe'),\n description: BasedataHandler.getTinyAiString('toolname_describe_extension'),\n customicon: true,\n iconname: 'extend',\n disabled: this.isToolDisabled('describe', mode).length > 0,\n tooltip: stripHtmlTags(this.isToolDisabled('describe', mode)),\n action: 'loaddescribe'\n });\n }\n if (!this.isToolHidden('tts')) {\n toolButtons.push({\n toolname: 'tts',\n tool: BasedataHandler.getTinyAiString('toolname_tts'),\n description: BasedataHandler.getTinyAiString('toolname_tts_extension'),\n iconstyle: 'solid',\n iconname: 'microphone',\n disabled: this.isToolDisabled('tts', mode).length > 0,\n tooltip: stripHtmlTags(this.isToolDisabled('tts', mode)),\n action: 'loadtts'\n });\n }\n if (!this.isToolHidden('audiogen')) {\n toolButtons.push({\n toolname: 'audiogen',\n tool: BasedataHandler.getTinyAiString('toolname_audiogen'),\n iconstyle: 'solid',\n iconname: 'microphone',\n disabled: this.isToolDisabled('audiogen', mode).length > 0,\n tooltip: stripHtmlTags(this.isToolDisabled('audiogen', mode)),\n action: 'loadaudiogen'\n });\n }\n if (!this.isToolHidden('imggen')) {\n toolButtons.push({\n toolname: 'imggen',\n tool: BasedataHandler.getTinyAiString('toolname_imggen'),\n iconstyle: 'solid',\n iconname: 'image',\n disabled: this.isToolDisabled('imggen', mode).length > 0,\n tooltip: stripHtmlTags(this.isToolDisabled('imggen', mode)),\n action: 'loadimggen'\n });\n }\n if (!this.isToolHidden('describeimg')) {\n toolButtons.push({\n toolname: 'describeimg',\n tool: BasedataHandler.getTinyAiString('toolname_describeimg'),\n iconstyle: 'solid',\n iconname: 'image',\n disabled: this.isToolDisabled('describeimg', mode).length > 0,\n tooltip: stripHtmlTags(this.isToolDisabled('describeimg', mode)),\n action: 'loaddescribeimg'\n });\n }\n // We sort the not disabled tools to the top while keeping the groups \"disabled tools\" and \"not disabled tools\"\n // in the same order inside the groups.\n toolButtons.sort((a, b) => {\n if (a.disabled && !b.disabled) {\n return 1;\n } else if (b.disabled && !a.disabled) {\n return -1;\n } else {\n return 0;\n }\n });\n\n const templateContext = {\n showIcon: true,\n modal_headline: BasedataHandler.getTinyAiString('mainselection_heading'),\n action: 'loadfreeprompt',\n modal_buttons: toolButtons,\n freeprompthidden: true\n };\n Object.assign(templateContext, BasedataHandler.getInputContext());\n if (this.isTinyAiDisabled()) {\n templateContext.input[0].disabled = true;\n templateContext.input[0].hasError = true;\n templateContext.input[0].errorMessage = this.isTinyAiDisabled();\n }\n if (this.isToolDisabled('freeprompt', mode)) {\n templateContext.input[0].disabled = true;\n }\n return templateContext;\n }\n}\n"],"names":["BaseHandler","aiConfig","stringRequest","this","stringKeys","map","key","component","strings","error_limitreached","error_pleaseconfirm","error_purposenotconfigured","error_tenantdisabled","error_unavailable_noselection","error_unavailable_selection","error_userlocked","error_usernotconfirmed","error_editor_notavailable","confirmLink","document","createElement","href","config","wwwroot","innerText","target","combinedusernotconfirmederror","outerHTML","getPurposeConfig","tool","Error","toolPurpose","constants","toolPurposeMapping","purposes","filter","purpose","isTinyAiDisabled","tenantenabled","userconfirmed","userlocked","isToolDisabled","mode","purposeInfo","isconfigured","limitreached","modalModes","selection","includes","general","isToolHidden","role","editorUtils","getMode","toolButtons","getModal","destroy","push","toolname","BasedataHandler","getTinyAiString","description","customicon","iconname","disabled","length","tooltip","action","iconstyle","sort","a","b","templateContext","showIcon","modal_headline","modal_buttons","fre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ACpCQ,gBAAgBQ,MAAM,GAAGC,UAAW,EACpCT,gBAAgBQ,MAAM,GAAGE,aAAe/E,KAAKkC,oBAE7ClC,KAAKsC,eAAe,aAAcC,QAClC8B,gBAAgBQ,MAAM,GAAGhB,UAAW,GAEjCQ"} \ No newline at end of file +{"version":3,"file":"start.min.js","sources":["../../src/datahandler/start.js"],"sourcesContent":["// This file is part of Moodle - http://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\nimport * as config from 'core/config';\nimport {getString, getStrings} from 'core/str';\nimport {constants} from 'tiny_ai/constants';\nimport * as BasedataHandler from 'tiny_ai/datahandler/basedata';\nimport BaseHandler from 'tiny_ai/datahandler/base';\nimport {getAiConfig} from 'local_ai_manager/config';\nimport {errorAlert, stripHtmlTags} from 'tiny_ai/utils';\n\n\n/**\n * Tiny AI data handler for start page.\n *\n * @module tiny_ai/datahandler/start\n * @copyright 2024, ISB Bayern\n * @author Philipp Memmel\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nexport default class extends BaseHandler {\n\n stringKeys = [\n 'error_limitreached',\n 'error_pleaseconfirm',\n 'error_purposenotconfigured',\n 'error_tenantdisabled',\n 'error_unavailable_noselection',\n 'error_unavailable_selection',\n 'error_userlocked',\n 'error_usernotconfirmed'\n ];\n\n aiConfig = null;\n strings = {};\n\n async init() {\n this.aiConfig = await getAiConfig();\n // It's easier to fetch alle these strings before even if we do not use them\n // instead of making all functions async just because of getString returning a promise.\n const stringRequest = this.stringKeys.map(key => {\n return {key, component: 'local_ai_manager'};\n });\n\n [\n this.strings.error_limitreached,\n this.strings.error_pleaseconfirm,\n this.strings.error_purposenotconfigured,\n this.strings.error_tenantdisabled,\n this.strings.error_unavailable_noselection,\n this.strings.error_unavailable_selection,\n this.strings.error_userlocked,\n this.strings.error_usernotconfirmed\n ] = await getStrings(stringRequest);\n this.strings.error_editor_notavailable = await getString('error_tiny_ai_notavailable', 'tiny_ai');\n const confirmLink = document.createElement('a');\n confirmLink.href = `${config.wwwroot}/local/ai_manager/confirm_ai_usage.php`;\n confirmLink.innerText = this.strings.error_pleaseconfirm;\n confirmLink.target = '_blank';\n this.strings.combinedusernotconfirmederror = this.strings.error_usernotconfirmed + ' ' + confirmLink.outerHTML;\n }\n\n getPurposeConfig(tool) {\n if (this.aiConfig === null) {\n throw new Error('Coding error: init function was not called before accessing this.getPurposeConfig!');\n }\n const toolPurpose = constants.toolPurposeMapping[tool];\n return this.aiConfig.purposes.filter(purpose => purpose['purpose'] === toolPurpose)[0];\n }\n\n isTinyAiDisabled() {\n if (!this.aiConfig.tenantenabled) {\n return this.strings.error_tenantdisabled;\n }\n if (!this.aiConfig.userconfirmed) {\n return this.strings.combinedusernotconfirmederror;\n }\n if (this.aiConfig.userlocked) {\n return this.strings.error_userlocked;\n }\n return '';\n }\n\n isToolDisabled(tool, mode) {\n if (this.isTinyAiDisabled()) {\n return this.isTinyAiDisabled();\n }\n const purposeInfo = this.getPurposeConfig(tool);\n if (!purposeInfo.isconfigured) {\n return this.strings.error_purposenotconfigured;\n }\n if (purposeInfo.limitreached) {\n return this.strings.error_limitreached;\n }\n\n if (mode === constants.modalModes.selection) {\n return ['audiogen', 'imggen', 'describeimg'].includes(tool) ? this.strings.error_unavailable_noselection : '';\n } else if (mode === constants.modalModes.general) {\n return ['summarize', 'translate', 'describe', 'tts'].includes(tool) ? this.strings.error_unavailable_selection : '';\n }\n return '';\n }\n\n isToolHidden(tool) {\n const purposeInfo = this.getPurposeConfig(tool);\n // If the tenant is not allowed the plugin is being disabled completely, so we do not need\n // to check this case here.\n if (this.aiConfig.role === 'role_basic') {\n if (!this.aiConfig.tenantenabled) {\n return true;\n }\n if (!purposeInfo.isconfigured) {\n return true;\n }\n }\n return false;\n }\n\n async getTemplateContext(editorUtils) {\n const mode = editorUtils.getMode();\n let toolButtons = [];\n if (this.aiConfig.role === 'role_basic' && this.isTinyAiDisabled()) {\n await errorAlert(await getString('error_tiny_ai_notavailable', 'tiny_ai') + '
'\n + this.isTinyAiDisabled());\n editorUtils.getModal().destroy();\n }\n\n if (!this.isToolHidden('summarize')) {\n toolButtons.push({\n toolname: 'summarize',\n tool: BasedataHandler.getTinyAiString('toolname_summarize'),\n description: BasedataHandler.getTinyAiString('toolname_summarize_extension'),\n customicon: true,\n iconname: 'shorten',\n disabled: this.isToolDisabled('summarize', mode).length > 0,\n tooltip: stripHtmlTags(this.isToolDisabled('summarize', mode)),\n action: 'loadsummarize'\n });\n }\n if (!this.isToolHidden('translate')) {\n toolButtons.push({\n toolname: 'translate',\n tool: BasedataHandler.getTinyAiString('toolname_translate'),\n description: BasedataHandler.getTinyAiString('toolname_translate_extension'),\n iconname: 'language',\n iconstyle: 'solid',\n disabled: this.isToolDisabled('translate', mode).length > 0,\n tooltip: stripHtmlTags(this.isToolDisabled('translate', mode)),\n action: 'loadtranslate'\n });\n }\n if (!this.isToolHidden('describe')) {\n toolButtons.push({\n toolname: 'describe',\n tool: BasedataHandler.getTinyAiString('toolname_describe'),\n description: BasedataHandler.getTinyAiString('toolname_describe_extension'),\n customicon: true,\n iconname: 'extend',\n disabled: this.isToolDisabled('describe', mode).length > 0,\n tooltip: stripHtmlTags(this.isToolDisabled('describe', mode)),\n action: 'loaddescribe'\n });\n }\n if (!this.isToolHidden('tts')) {\n toolButtons.push({\n toolname: 'tts',\n tool: BasedataHandler.getTinyAiString('toolname_tts'),\n description: BasedataHandler.getTinyAiString('toolname_tts_extension'),\n iconstyle: 'solid',\n iconname: 'microphone',\n disabled: this.isToolDisabled('tts', mode).length > 0,\n tooltip: stripHtmlTags(this.isToolDisabled('tts', mode)),\n action: 'loadtts'\n });\n }\n if (!this.isToolHidden('audiogen')) {\n toolButtons.push({\n toolname: 'audiogen',\n tool: BasedataHandler.getTinyAiString('toolname_audiogen'),\n iconstyle: 'solid',\n iconname: 'microphone',\n disabled: this.isToolDisabled('audiogen', mode).length > 0,\n tooltip: stripHtmlTags(this.isToolDisabled('audiogen', mode)),\n action: 'loadaudiogen'\n });\n }\n if (!this.isToolHidden('imggen')) {\n toolButtons.push({\n toolname: 'imggen',\n tool: BasedataHandler.getTinyAiString('toolname_imggen'),\n iconstyle: 'solid',\n iconname: 'image',\n disabled: this.isToolDisabled('imggen', mode).length > 0,\n tooltip: stripHtmlTags(this.isToolDisabled('imggen', mode)),\n action: 'loadimggen'\n });\n }\n if (!this.isToolHidden('describeimg')) {\n toolButtons.push({\n toolname: 'describeimg',\n tool: BasedataHandler.getTinyAiString('toolname_describeimg'),\n iconstyle: 'solid',\n iconname: 'file-image',\n disabled: this.isToolDisabled('describeimg', mode).length > 0,\n tooltip: stripHtmlTags(this.isToolDisabled('describeimg', mode)),\n action: 'loaddescribeimg'\n });\n }\n if (!this.isToolHidden('imagetotext')) {\n toolButtons.push({\n toolname: 'imagetotext',\n tool: BasedataHandler.getTinyAiString('toolname_imagetotext'),\n iconstyle: 'solid',\n iconname: 'signature',\n disabled: this.isToolDisabled('imagetotext', mode).length > 0,\n tooltip: stripHtmlTags(this.isToolDisabled('imagetotext', mode)),\n action: 'loadimagetotext'\n });\n }\n // We sort the not disabled tools to the top while keeping the groups \"disabled tools\" and \"not disabled tools\"\n // in the same order inside the groups.\n toolButtons.sort((a, b) => {\n if (a.disabled && !b.disabled) {\n return 1;\n } else if (b.disabled && !a.disabled) {\n return -1;\n } else {\n return 0;\n }\n });\n\n const templateContext = {\n showIcon: true,\n modal_headline: BasedataHandler.getTinyAiString('mainselection_heading'),\n action: 'loadfreeprompt',\n modal_buttons: toolButtons,\n freeprompthidden: true\n };\n Object.assign(templateContext, BasedataHandler.getInputContext());\n if (this.isTinyAiDisabled()) {\n templateContext.input[0].disabled = true;\n templateContext.input[0].hasError = true;\n templateContext.input[0].errorMessage = this.isTinyAiDisabled();\n }\n if (this.isToolDisabled('freeprompt', mode)) {\n templateContext.input[0].disabled = true;\n }\n return templateContext;\n }\n}\n"],"names":["BaseHandler","aiConfig","stringRequest","this","stringKeys","map","key","component","strings","error_limitreached","error_pleaseconfirm","error_purposenotconfigured","error_tenantdisabled","error_unavailable_noselection","error_unavailable_selection","error_userlocked","error_usernotconfirmed","error_editor_notavailable","confirmLink","document","createElement","href","config","wwwroot","innerText","target","combinedusernotconfirmederror","outerHTML","getPurposeConfig","tool","Error","toolPurpose","constants","toolPurposeMapping","purposes","filter","purpose","isTinyAiDisabled","tenantenabled","userconfirmed","userlocked","isToolDisabled","mode","purposeInfo","isconfigured","limitreached","modalModes","selection","includes","general","isToolHidden","role","editorUtils","getMode","toolButtons","getModal","destroy","push","toolname","BasedataHandler","getTinyAiString","description","customicon","iconname","disabled","length","tooltip","action","iconstyle","sort","a","b","templateContext","showIcon","modal_headline","modal_buttons","freeprompthidden","Object","assign","getInputContext","input","hasError","errorMessage"],"mappings":";;;;;;;;gQAiC6BA,kFAEZ,CACT,qBACA,sBACA,6BACA,uBACA,gCACA,8BACA,mBACA,2DAGO,qCACD,sBAGDC,eAAiB,gCAGhBC,cAAgBC,KAAKC,WAAWC,KAAIC,MAC/B,CAACA,IAAAA,IAAKC,UAAW,wBAIxBJ,KAAKK,QAAQC,mBACbN,KAAKK,QAAQE,oBACbP,KAAKK,QAAQG,2BACbR,KAAKK,QAAQI,qBACbT,KAAKK,QAAQK,8BACbV,KAAKK,QAAQM,4BACbX,KAAKK,QAAQO,iBACbZ,KAAKK,QAAQQ,8BACP,mBAAWd,oBAChBM,QAAQS,gCAAkC,kBAAU,6BAA8B,iBACjFC,YAAcC,SAASC,cAAc,KAC3CF,YAAYG,eAAUC,OAAOC,kDAC7BL,YAAYM,UAAYrB,KAAKK,QAAQE,oBACrCQ,YAAYO,OA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QACVC,SAAU7D,KAAKsC,eAAe,SAAUC,MAAMuB,OAAS,EACvDC,SAAS,wBAAc/D,KAAKsC,eAAe,SAAUC,OACrDyB,OAAQ,eAGXhE,KAAK+C,aAAa,gBACnBI,YAAYG,KAAK,CACbC,SAAU,cACV7B,KAAM8B,gBAAgBC,gBAAgB,wBACtCQ,UAAW,QACXL,SAAU,aACVC,SAAU7D,KAAKsC,eAAe,cAAeC,MAAMuB,OAAS,EAC5DC,SAAS,wBAAc/D,KAAKsC,eAAe,cAAeC,OAC1DyB,OAAQ,oBAGXhE,KAAK+C,aAAa,gBACnBI,YAAYG,KAAK,CACbC,SAAU,cACV7B,KAAM8B,gBAAgBC,gBAAgB,wBACtCQ,UAAW,QACXL,SAAU,YACVC,SAAU7D,KAAKsC,eAAe,cAAeC,MAAMuB,OAAS,EAC5DC,SAAS,wBAAc/D,KAAKsC,eAAe,cAAeC,OAC1DyB,OAAQ,oBAKhBb,YAAYe,MAAK,CAACC,EAAGC,IACbD,EAAEN,WAAaO,EAAEP,SACV,EACAO,EAAEP,WAAaM,EAAEN,UAChB,EAED,UAITQ,gBAAkB,CACpBC,UAAU,EACVC,eAAgBf,gBAAgBC,gBAAgB,yBAChDO,OAAQ,iBACRQ,cAAerB,YACfsB,kBAAkB,UAEtBC,OAAOC,OAAON,gBAAiBb,gBAAgBoB,mBAC3C5E,KAAKkC,qBACLmC,gBAAgBQ,MAAM,GAAGhB,UAAW,EACpCQ,gBAAgBQ,MAAM,GAAGC,UAAW,EACpCT,gBAAgBQ,MAAM,GAAGE,aAAe/E,KAAKkC,oBAE7ClC,KAAKsC,eAAe,aAAcC,QAClC8B,gBAAgBQ,MAAM,GAAGhB,UAAW,GAEjCQ"} \ No newline at end of file diff --git a/amd/build/renderer.min.js b/amd/build/renderer.min.js index 23ce5a2..14d5c14 100644 --- a/amd/build/renderer.min.js +++ b/amd/build/renderer.min.js @@ -1,3 +1,3 @@ -define("tiny_ai/renderer",["exports","local_ai_manager/infobox","local_ai_manager/userquota","tiny_ai/datahandler/basedata","core/templates","jquery","tiny_ai/utils"],(function(_exports,_infobox,_userquota,BasedataHandler,_templates,_jquery,_utils){function _interopRequireDefault(obj){return obj&&obj.__esModule?obj:{default:obj}}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)}function _defineProperty(obj,key,value){return key in obj?Object.defineProperty(obj,key,{value:value,enumerable:!0,configurable:!0,writable:!0}):obj[key]=value,obj}Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.default=void 0,BasedataHandler=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}(BasedataHandler),_templates=_interopRequireDefault(_templates),_jquery=_interopRequireDefault(_jquery);return _exports.default=class{constructor(uniqid){_defineProperty(this,"uniqid",null),_defineProperty(this,"datamanager",null),_defineProperty(this,"editorUtils",null),this.uniqid=uniqid,this.datamanager=(0,_utils.getDatamanager)(uniqid),this.editorUtils=(0,_utils.getEditorUtils)(uniqid)}async renderStart(){this.datamanager.reset();const templateContext=await(0,_utils.getStartHandler)(this.uniqid).getTemplateContext((0,_utils.getEditorUtils)(this.uniqid));await this.renderModalContent("moodle-modal-body-start","moodle-modal-footer-info",templateContext)}async renderSummarize(){const templateContext=(0,_utils.getSummarizeHandler)(this.uniqid).getTemplateContext("summarize");await this.renderModalContent("moodle-modal-body-preferences","moodle-modal-footer-generate",templateContext)}async renderTranslate(){const templateContext=(0,_utils.getTranslateHandler)(this.uniqid).getTemplateContext();await this.renderModalContent("moodle-modal-body-preferences","moodle-modal-footer-generate",templateContext)}async renderDescribe(){const templateContext=(0,_utils.getSummarizeHandler)(this.uniqid).getTemplateContext("describe");await this.renderModalContent("moodle-modal-body-preferences","moodle-modal-footer-generate",templateContext)}async renderTts(){const templateContext=await(0,_utils.getTtsHandler)(this.uniqid).getTemplateContext("tts");await this.renderModalContent("moodle-modal-body-preferences","moodle-modal-footer-generate",templateContext)}async renderAudiogen(){const templateContext=await(0,_utils.getTtsHandler)(this.uniqid).getTemplateContext("audiogen");await this.renderModalContent("moodle-modal-body-mediageneration","moodle-modal-footer-generate",templateContext)}async renderImggen(){const templateContext=await(0,_utils.getImggenHandler)(this.uniqid).getTemplateContext();await this.renderModalContent("moodle-modal-body-mediageneration","moodle-modal-footer-generate",templateContext)}async renderDescribeimg(){const templateContext=await(0,_utils.getIttHandler)(this.uniqid).getTemplateContext();await this.renderModalContent("moodle-modal-body-itt","moodle-modal-footer-generate",templateContext)}async renderLoading(){const templateContext={};templateContext.modal_headline=BasedataHandler.getTinyAiString("aigenerating"),await this.renderModalContent("moodle-modal-body-loading","moodle-modal-footer-empty",templateContext)}async renderSuggestion(){const templateContext={};templateContext.modal_headline=BasedataHandler.getTinyAiString("aisuggestion"),templateContext.result_text=this.renderAiResultForEditor(),Object.assign(templateContext,BasedataHandler.getReplaceButtonsContext(this.editorUtils.getMode())),await this.renderModalContent("moodle-modal-body-suggestion","moodle-modal-footer-replace",templateContext)}async renderOptimizePrompt(){const templateContext=(0,_utils.getOptimizeHandler)(this.uniqid).getTemplateContext();await this.renderModalContent("moodle-modal-body-optimize","moodle-modal-footer-generate",templateContext)}async renderDismiss(){const templateContext={modal_headline:"",centered_headline:BasedataHandler.getTinyAiString("dismisssuggestion"),showIcon:!1,buttons:[{hasText:!0,button_text:BasedataHandler.getTinyAiString("cancel"),icon_left:!1,icon_right:!1,primary:!1,secondary:!0,tertiary:!1,action:"canceldismiss"},{hasText:!0,button_text:BasedataHandler.getTinyAiString("dismiss"),icon_left:!1,icon_right:!1,primary:!0,secondary:!1,tertiary:!1,action:"dismiss"}]};await this.renderModalContent("moodle-modal-body-dismiss","moodle-modal-footer-empty",templateContext)}renderAiResultForEditor(){let html;switch(this.datamanager.getCurrentTool()){case"tts":case"audiogen":{const audioPlayer=document.createElement("audio");audioPlayer.controls="controls",audioPlayer.src=this.datamanager.getCurrentAiResult(),audioPlayer.type="audio/mpeg",html=audioPlayer.outerHTML;break}case"imggen":{const img=document.createElement("img");img.src=this.datamanager.getCurrentAiResult(),img.classList.add("mw-100"),html=img.outerHTML;break}default:html=this.datamanager.getCurrentAiResult()}return html}async renderModalContent(bodyComponentTemplate,footerComponentTemplate,templateContext){templateContext.tinyinstanceuniqid=this.uniqid;const modal=(0,_utils.getEditorUtils)(this.uniqid).getModal();document.querySelectorAll("button[data-action]").forEach((button=>{(0,_jquery.default)(button).tooltip("hide")}));const result=await Promise.all([_templates.default.renderForPromise("tiny_ai/components/moodle-modal-header-title",templateContext),_templates.default.renderForPromise("tiny_ai/components/"+bodyComponentTemplate,templateContext),_templates.default.renderForPromise("tiny_ai/components/"+footerComponentTemplate,templateContext)]);templateContext.hasOwnProperty("modal_headline")&&modal.setTitle(result[0].html),document.querySelectorAll("button[data-action]").forEach((button=>{(0,_jquery.default)(button).tooltip("hide")})),modal.setBody(result[1].html),modal.setFooter(result[2].html),result.forEach((item=>{_templates.default.runTemplateJS(item.js)})),modal.getRoot().attr("data-tiny_ai_uniqid",this.uniqid),await this.insertInfoBox(),await this.insertUserQuotaBox(),document.querySelectorAll("button[data-action]").forEach((button=>{button.addEventListener("click",(event=>{(0,_jquery.default)(event.target).closest("button[data-action]").tooltip("hide")}))}))}async insertInfoBox(){document.querySelector('[data-rendertarget="infobox"]')&&await(0,_infobox.renderInfoBox)("tiny_ai",(0,_utils.getEditorUtils)(this.uniqid).getUserId(),'[data-rendertarget="infobox"]',["singleprompt","translate","tts","imggen"])}async insertUserQuotaBox(){document.querySelector('[data-rendertarget="usageinfo"]')&&await(0,_userquota.renderUserQuota)('[data-rendertarget="usageinfo"]',["singleprompt","translate","tts","imggen"])}},_exports.default})); +define("tiny_ai/renderer",["exports","local_ai_manager/infobox","local_ai_manager/userquota","tiny_ai/datahandler/basedata","core/templates","jquery","tiny_ai/utils"],(function(_exports,_infobox,_userquota,BasedataHandler,_templates,_jquery,_utils){function _interopRequireDefault(obj){return obj&&obj.__esModule?obj:{default:obj}}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)}function _defineProperty(obj,key,value){return key in obj?Object.defineProperty(obj,key,{value:value,enumerable:!0,configurable:!0,writable:!0}):obj[key]=value,obj}Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.default=void 0,BasedataHandler=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}(BasedataHandler),_templates=_interopRequireDefault(_templates),_jquery=_interopRequireDefault(_jquery);return _exports.default=class{constructor(uniqid){_defineProperty(this,"uniqid",null),_defineProperty(this,"datamanager",null),_defineProperty(this,"editorUtils",null),this.uniqid=uniqid,this.datamanager=(0,_utils.getDatamanager)(uniqid),this.editorUtils=(0,_utils.getEditorUtils)(uniqid)}async renderStart(){this.datamanager.reset();const templateContext=await(0,_utils.getStartHandler)(this.uniqid).getTemplateContext((0,_utils.getEditorUtils)(this.uniqid));await this.renderModalContent("moodle-modal-body-start","moodle-modal-footer-info",templateContext)}async renderSummarize(){const templateContext=(0,_utils.getSummarizeHandler)(this.uniqid).getTemplateContext("summarize");await this.renderModalContent("moodle-modal-body-preferences","moodle-modal-footer-generate",templateContext)}async renderTranslate(){const templateContext=(0,_utils.getTranslateHandler)(this.uniqid).getTemplateContext();await this.renderModalContent("moodle-modal-body-preferences","moodle-modal-footer-generate",templateContext)}async renderDescribe(){const templateContext=(0,_utils.getSummarizeHandler)(this.uniqid).getTemplateContext("describe");await this.renderModalContent("moodle-modal-body-preferences","moodle-modal-footer-generate",templateContext)}async renderTts(){const templateContext=await(0,_utils.getTtsHandler)(this.uniqid).getTemplateContext("tts");await this.renderModalContent("moodle-modal-body-preferences","moodle-modal-footer-generate",templateContext)}async renderAudiogen(){const templateContext=await(0,_utils.getTtsHandler)(this.uniqid).getTemplateContext("audiogen");await this.renderModalContent("moodle-modal-body-mediageneration","moodle-modal-footer-generate",templateContext)}async renderImggen(){const templateContext=await(0,_utils.getImggenHandler)(this.uniqid).getTemplateContext();await this.renderModalContent("moodle-modal-body-mediageneration","moodle-modal-footer-generate",templateContext)}async renderDescribeimg(){const templateContext=await(0,_utils.getIttHandler)(this.uniqid).getTemplateContext("describeimg");await this.renderModalContent("moodle-modal-body-itt","moodle-modal-footer-generate",templateContext)}async renderImagetotext(){const templateContext=await(0,_utils.getIttHandler)(this.uniqid).getTemplateContext("imagetotext");await this.renderModalContent("moodle-modal-body-itt","moodle-modal-footer-generate",templateContext)}async renderLoading(){const templateContext={};templateContext.modal_headline=BasedataHandler.getTinyAiString("aigenerating"),await this.renderModalContent("moodle-modal-body-loading","moodle-modal-footer-empty",templateContext)}async renderSuggestion(){const templateContext={};templateContext.modal_headline=BasedataHandler.getTinyAiString("aisuggestion"),templateContext.result_text=this.renderAiResultForEditor(),Object.assign(templateContext,BasedataHandler.getReplaceButtonsContext(this.editorUtils.getMode())),await this.renderModalContent("moodle-modal-body-suggestion","moodle-modal-footer-replace",templateContext)}async renderOptimizePrompt(){const templateContext=(0,_utils.getOptimizeHandler)(this.uniqid).getTemplateContext();await this.renderModalContent("moodle-modal-body-optimize","moodle-modal-footer-generate",templateContext)}async renderDismiss(){const templateContext={modal_headline:"",centered_headline:BasedataHandler.getTinyAiString("dismisssuggestion"),showIcon:!1,buttons:[{hasText:!0,button_text:BasedataHandler.getTinyAiString("cancel"),icon_left:!1,icon_right:!1,primary:!1,secondary:!0,tertiary:!1,action:"canceldismiss"},{hasText:!0,button_text:BasedataHandler.getTinyAiString("dismiss"),icon_left:!1,icon_right:!1,primary:!0,secondary:!1,tertiary:!1,action:"dismiss"}]};await this.renderModalContent("moodle-modal-body-dismiss","moodle-modal-footer-empty",templateContext)}renderAiResultForEditor(){let html;switch(this.datamanager.getCurrentTool()){case"tts":case"audiogen":{const audioPlayer=document.createElement("audio");audioPlayer.controls="controls",audioPlayer.src=this.datamanager.getCurrentAiResult(),audioPlayer.type="audio/mpeg",html=audioPlayer.outerHTML;break}case"imggen":{const img=document.createElement("img");img.src=this.datamanager.getCurrentAiResult(),img.classList.add("mw-100"),html=img.outerHTML;break}default:html=this.datamanager.getCurrentAiResult()}return html}async renderModalContent(bodyComponentTemplate,footerComponentTemplate,templateContext){templateContext.tinyinstanceuniqid=this.uniqid;const modal=(0,_utils.getEditorUtils)(this.uniqid).getModal();document.querySelectorAll("button[data-action]").forEach((button=>{(0,_jquery.default)(button).tooltip("hide")}));const result=await Promise.all([_templates.default.renderForPromise("tiny_ai/components/moodle-modal-header-title",templateContext),_templates.default.renderForPromise("tiny_ai/components/"+bodyComponentTemplate,templateContext),_templates.default.renderForPromise("tiny_ai/components/"+footerComponentTemplate,templateContext)]);templateContext.hasOwnProperty("modal_headline")&&modal.setTitle(result[0].html),document.querySelectorAll("button[data-action]").forEach((button=>{(0,_jquery.default)(button).tooltip("hide")})),modal.setBody(result[1].html),modal.setFooter(result[2].html),result.forEach((item=>{_templates.default.runTemplateJS(item.js)})),modal.getRoot().attr("data-tiny_ai_uniqid",this.uniqid),await this.insertInfoBox(),await this.insertUserQuotaBox(),document.querySelectorAll("button[data-action]").forEach((button=>{button.addEventListener("click",(event=>{(0,_jquery.default)(event.target).closest("button[data-action]").tooltip("hide")}))}))}async insertInfoBox(){document.querySelector('[data-rendertarget="infobox"]')&&await(0,_infobox.renderInfoBox)("tiny_ai",(0,_utils.getEditorUtils)(this.uniqid).getUserId(),'[data-rendertarget="infobox"]',["singleprompt","translate","tts","imggen"])}async insertUserQuotaBox(){document.querySelector('[data-rendertarget="usageinfo"]')&&await(0,_userquota.renderUserQuota)('[data-rendertarget="usageinfo"]',["singleprompt","translate","tts","imggen"])}},_exports.default})); //# sourceMappingURL=renderer.min.js.map \ No newline at end of file diff --git a/amd/build/renderer.min.js.map b/amd/build/renderer.min.js.map index d75025e..c8e4937 100644 --- a/amd/build/renderer.min.js.map +++ b/amd/build/renderer.min.js.map @@ -1 +1 @@ -{"version":3,"file":"renderer.min.js","sources":["../src/renderer.js"],"sourcesContent":["// This file is part of Moodle - http://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 AI utils library.\n *\n * @module tiny_ai/renderer\n * @copyright 2024, ISB Bayern\n * @author Philipp Memmel\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nimport {renderInfoBox} from 'local_ai_manager/infobox';\nimport {renderUserQuota} from 'local_ai_manager/userquota';\nimport * as BasedataHandler from 'tiny_ai/datahandler/basedata';\nimport Templates from 'core/templates';\nimport $ from 'jquery';\nimport {\n getEditorUtils,\n getDatamanager,\n getImggenHandler,\n getOptimizeHandler,\n getStartHandler,\n getSummarizeHandler,\n getTranslateHandler,\n getTtsHandler,\n getIttHandler\n} from 'tiny_ai/utils';\n\nexport default class {\n\n uniqid = null;\n datamanager = null;\n editorUtils = null;\n\n constructor(uniqid) {\n this.uniqid = uniqid;\n this.datamanager = getDatamanager(uniqid);\n this.editorUtils = getEditorUtils(uniqid);\n }\n\n async renderStart() {\n this.datamanager.reset();\n const templateContext = await getStartHandler(this.uniqid).getTemplateContext(getEditorUtils(this.uniqid));\n await this.renderModalContent('moodle-modal-body-start', 'moodle-modal-footer-info', templateContext);\n }\n\n\n async renderSummarize() {\n const templateContext = getSummarizeHandler(this.uniqid).getTemplateContext('summarize');\n await this.renderModalContent('moodle-modal-body-preferences', 'moodle-modal-footer-generate', templateContext);\n }\n\n\n async renderTranslate() {\n const templateContext = getTranslateHandler(this.uniqid).getTemplateContext();\n await this.renderModalContent('moodle-modal-body-preferences', 'moodle-modal-footer-generate', templateContext);\n }\n\n async renderDescribe() {\n const templateContext = getSummarizeHandler(this.uniqid).getTemplateContext('describe');\n await this.renderModalContent('moodle-modal-body-preferences', 'moodle-modal-footer-generate', templateContext);\n }\n\n async renderTts() {\n const templateContext = await getTtsHandler(this.uniqid).getTemplateContext('tts');\n await this.renderModalContent('moodle-modal-body-preferences', 'moodle-modal-footer-generate', templateContext);\n }\n\n async renderAudiogen() {\n const templateContext = await getTtsHandler(this.uniqid).getTemplateContext('audiogen');\n await this.renderModalContent('moodle-modal-body-mediageneration', 'moodle-modal-footer-generate', templateContext);\n }\n\n\n async renderImggen() {\n const templateContext = await getImggenHandler(this.uniqid).getTemplateContext();\n await this.renderModalContent('moodle-modal-body-mediageneration', 'moodle-modal-footer-generate', templateContext);\n }\n\n async renderDescribeimg() {\n const templateContext = await getIttHandler(this.uniqid).getTemplateContext();\n await this.renderModalContent('moodle-modal-body-itt', 'moodle-modal-footer-generate', templateContext);\n }\n\n async renderLoading() {\n const templateContext = {};\n templateContext.modal_headline = BasedataHandler.getTinyAiString('aigenerating');\n await this.renderModalContent('moodle-modal-body-loading', 'moodle-modal-footer-empty', templateContext);\n }\n\n\n async renderSuggestion() {\n const templateContext = {};\n templateContext.modal_headline = BasedataHandler.getTinyAiString('aisuggestion');\n // TODO Eventually do not use the same rendering in the suggestion like in the course, or just leave it because we\n // consider it beautiful\n templateContext.result_text = this.renderAiResultForEditor();\n\n Object.assign(templateContext, BasedataHandler.getReplaceButtonsContext(this.editorUtils.getMode()));\n await this.renderModalContent('moodle-modal-body-suggestion', 'moodle-modal-footer-replace', templateContext);\n }\n\n async renderOptimizePrompt() {\n const templateContext = getOptimizeHandler(this.uniqid).getTemplateContext();\n await this.renderModalContent('moodle-modal-body-optimize', 'moodle-modal-footer-generate', templateContext);\n }\n\n\n async renderDismiss() {\n const templateContext = {\n modal_headline: '',\n centered_headline: BasedataHandler.getTinyAiString('dismisssuggestion'),\n showIcon: false,\n buttons: [\n {\n hasText: true,\n button_text: BasedataHandler.getTinyAiString('cancel'),\n icon_left: false,\n icon_right: false,\n primary: false,\n secondary: true,\n tertiary: false,\n action: 'canceldismiss'\n },\n {\n hasText: true,\n button_text: BasedataHandler.getTinyAiString('dismiss'),\n icon_left: false,\n icon_right: false,\n primary: true,\n secondary: false,\n tertiary: false,\n action: 'dismiss'\n }\n ]\n };\n await this.renderModalContent('moodle-modal-body-dismiss', 'moodle-modal-footer-empty', templateContext);\n }\n\n\n renderAiResultForEditor() {\n let html;\n switch (this.datamanager.getCurrentTool()) {\n case 'tts':\n case 'audiogen': {\n const audioPlayer = document.createElement('audio');\n audioPlayer.controls = 'controls';\n audioPlayer.src = this.datamanager.getCurrentAiResult();\n audioPlayer.type = 'audio/mpeg';\n html = audioPlayer.outerHTML;\n break;\n }\n case 'imggen': {\n const img = document.createElement('img');\n img.src = this.datamanager.getCurrentAiResult();\n img.classList.add('mw-100');\n html = img.outerHTML;\n break;\n }\n default: {\n html = this.datamanager.getCurrentAiResult();\n }\n }\n return html;\n }\n\n /**\n * Re-renders the content auf the modal once it has been created.\n *\n * @param {string} bodyComponentTemplate the name of the body template to use (without the prefix 'tiny_ai/components/')\n * @param {string} footerComponentTemplate the name of the footer template to use (without the prefix 'tiny_ai/components/')\n * @param {object} templateContext the template context being used for all partial templates\n * @returns {Promise} the async promise\n */\n async renderModalContent(bodyComponentTemplate, footerComponentTemplate, templateContext) {\n templateContext.tinyinstanceuniqid = this.uniqid;\n const modal = getEditorUtils(this.uniqid).getModal();\n // Remove all eventually remaining tooltips before rendering a new view.\n document.querySelectorAll('button[data-action]').forEach(button => {\n $(button).tooltip('hide');\n });\n const result = await Promise.all([\n Templates.renderForPromise('tiny_ai/components/moodle-modal-header-title', templateContext),\n Templates.renderForPromise('tiny_ai/components/' + bodyComponentTemplate, templateContext),\n Templates.renderForPromise('tiny_ai/components/' + footerComponentTemplate, templateContext)\n ]);\n if (templateContext.hasOwnProperty('modal_headline')) {\n // If there is no headline specified, we keep the old one.\n modal.setTitle(result[0].html);\n }\n // Hide all eventually still existing tooltips first, because they show on 'hover' and\n // 'focus'. So we need to remove them before removing the corresponding buttons from the DOM.\n // Boostrap 4 still using jQuery for tooltips, so we need jQuery here.\n document.querySelectorAll('button[data-action]').forEach(button => {\n $(button).tooltip('hide');\n });\n modal.setBody(result[1].html);\n modal.setFooter(result[2].html);\n result.forEach((item) => {\n Templates.runTemplateJS(item.js);\n });\n modal.getRoot().attr('data-tiny_ai_uniqid', this.uniqid);\n await this.insertInfoBox();\n await this.insertUserQuotaBox();\n document.querySelectorAll('button[data-action]').forEach(button => {\n button.addEventListener('click', event => {\n $(event.target).closest('button[data-action]').tooltip('hide');\n });\n });\n }\n\n async insertInfoBox() {\n const infoBoxSelector = '[data-rendertarget=\"infobox\"]';\n if (document.querySelector(infoBoxSelector)) {\n await renderInfoBox('tiny_ai', getEditorUtils(this.uniqid).getUserId(), infoBoxSelector,\n ['singleprompt', 'translate', 'tts', 'imggen']);\n }\n }\n\n async insertUserQuotaBox() {\n const usageBoxSelector = '[data-rendertarget=\"usageinfo\"]';\n if (document.querySelector(usageBoxSelector)) {\n await renderUserQuota(usageBoxSelector, ['singleprompt', 'translate', 'tts', 'imggen']);\n }\n }\n}\n"],"names":["constructor","uniqid","datamanager","editorUtils","reset","templateContext","this","getTemplateContext","renderModalContent","modal_headline","BasedataHandler","getTinyAiString","result_text","renderAiResultForEditor","Object","assign","getReplaceButtonsContext","getMode","centered_headline","showIcon","buttons","hasText","button_text","icon_left","icon_right","primary","secondary","tertiary","action","html","getCurrentTool","audioPlayer","document","createElement","controls","src","getCurrentAiResult","type","outerHTML","img","classList","add","bodyComponentTemplate","footerComponentTemplate","tinyinstanceuniqid","modal","getModal","querySelectorAll","forEach","button","tooltip","result","Promise","all","Templates","renderForPromise","hasOwnProperty","setTitle","setBody","setFooter","item","runTemplateJS","js","getRoot","attr","insertInfoBox","insertUserQuotaBox","addEventListener","event","target","closest","querySelector","getUserId"],"mappings":"onDA+CIA,YAAYC,sCAJH,yCACK,yCACA,WAGLA,OAASA,YACTC,aAAc,yBAAeD,aAC7BE,aAAc,yBAAeF,iCAI7BC,YAAYE,cACXC,sBAAwB,0BAAgBC,KAAKL,QAAQM,oBAAmB,yBAAeD,KAAKL,eAC5FK,KAAKE,mBAAmB,0BAA2B,2BAA4BH,+CAK/EA,iBAAkB,8BAAoBC,KAAKL,QAAQM,mBAAmB,mBACtED,KAAKE,mBAAmB,gCAAiC,+BAAgCH,+CAKzFA,iBAAkB,8BAAoBC,KAAKL,QAAQM,2BACnDD,KAAKE,mBAAmB,gCAAiC,+BAAgCH,8CAIzFA,iBAAkB,8BAAoBC,KAAKL,QAAQM,mBAAmB,kBACtED,KAAKE,mBAAmB,gCAAiC,+BAAgCH,yCAIzFA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":"renderer.min.js","sources":["../src/renderer.js"],"sourcesContent":["// This file is part of Moodle - http://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 AI utils library.\n *\n * @module tiny_ai/renderer\n * @copyright 2024, ISB Bayern\n * @author Philipp Memmel\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nimport {renderInfoBox} from 'local_ai_manager/infobox';\nimport {renderUserQuota} from 'local_ai_manager/userquota';\nimport * as BasedataHandler from 'tiny_ai/datahandler/basedata';\nimport Templates from 'core/templates';\nimport $ from 'jquery';\nimport {\n getEditorUtils,\n getDatamanager,\n getImggenHandler,\n getOptimizeHandler,\n getStartHandler,\n getSummarizeHandler,\n getTranslateHandler,\n getTtsHandler,\n getIttHandler\n} from 'tiny_ai/utils';\n\nexport default class {\n\n uniqid = null;\n datamanager = null;\n editorUtils = null;\n\n constructor(uniqid) {\n this.uniqid = uniqid;\n this.datamanager = getDatamanager(uniqid);\n this.editorUtils = getEditorUtils(uniqid);\n }\n\n async renderStart() {\n this.datamanager.reset();\n const templateContext = await getStartHandler(this.uniqid).getTemplateContext(getEditorUtils(this.uniqid));\n await this.renderModalContent('moodle-modal-body-start', 'moodle-modal-footer-info', templateContext);\n }\n\n\n async renderSummarize() {\n const templateContext = getSummarizeHandler(this.uniqid).getTemplateContext('summarize');\n await this.renderModalContent('moodle-modal-body-preferences', 'moodle-modal-footer-generate', templateContext);\n }\n\n\n async renderTranslate() {\n const templateContext = getTranslateHandler(this.uniqid).getTemplateContext();\n await this.renderModalContent('moodle-modal-body-preferences', 'moodle-modal-footer-generate', templateContext);\n }\n\n async renderDescribe() {\n const templateContext = getSummarizeHandler(this.uniqid).getTemplateContext('describe');\n await this.renderModalContent('moodle-modal-body-preferences', 'moodle-modal-footer-generate', templateContext);\n }\n\n async renderTts() {\n const templateContext = await getTtsHandler(this.uniqid).getTemplateContext('tts');\n await this.renderModalContent('moodle-modal-body-preferences', 'moodle-modal-footer-generate', templateContext);\n }\n\n async renderAudiogen() {\n const templateContext = await getTtsHandler(this.uniqid).getTemplateContext('audiogen');\n await this.renderModalContent('moodle-modal-body-mediageneration', 'moodle-modal-footer-generate', templateContext);\n }\n\n\n async renderImggen() {\n const templateContext = await getImggenHandler(this.uniqid).getTemplateContext();\n await this.renderModalContent('moodle-modal-body-mediageneration', 'moodle-modal-footer-generate', templateContext);\n }\n\n async renderDescribeimg() {\n const templateContext = await getIttHandler(this.uniqid).getTemplateContext('describeimg');\n await this.renderModalContent('moodle-modal-body-itt', 'moodle-modal-footer-generate', templateContext);\n }\n\n async renderImagetotext() {\n const templateContext = await getIttHandler(this.uniqid).getTemplateContext('imagetotext');\n await this.renderModalContent('moodle-modal-body-itt', 'moodle-modal-footer-generate', templateContext);\n }\n\n async renderLoading() {\n const templateContext = {};\n templateContext.modal_headline = BasedataHandler.getTinyAiString('aigenerating');\n await this.renderModalContent('moodle-modal-body-loading', 'moodle-modal-footer-empty', templateContext);\n }\n\n\n async renderSuggestion() {\n const templateContext = {};\n templateContext.modal_headline = BasedataHandler.getTinyAiString('aisuggestion');\n // TODO Eventually do not use the same rendering in the suggestion like in the course, or just leave it because we\n // consider it beautiful\n templateContext.result_text = this.renderAiResultForEditor();\n\n Object.assign(templateContext, BasedataHandler.getReplaceButtonsContext(this.editorUtils.getMode()));\n await this.renderModalContent('moodle-modal-body-suggestion', 'moodle-modal-footer-replace', templateContext);\n }\n\n async renderOptimizePrompt() {\n const templateContext = getOptimizeHandler(this.uniqid).getTemplateContext();\n await this.renderModalContent('moodle-modal-body-optimize', 'moodle-modal-footer-generate', templateContext);\n }\n\n\n async renderDismiss() {\n const templateContext = {\n modal_headline: '',\n centered_headline: BasedataHandler.getTinyAiString('dismisssuggestion'),\n showIcon: false,\n buttons: [\n {\n hasText: true,\n button_text: BasedataHandler.getTinyAiString('cancel'),\n icon_left: false,\n icon_right: false,\n primary: false,\n secondary: true,\n tertiary: false,\n action: 'canceldismiss'\n },\n {\n hasText: true,\n button_text: BasedataHandler.getTinyAiString('dismiss'),\n icon_left: false,\n icon_right: false,\n primary: true,\n secondary: false,\n tertiary: false,\n action: 'dismiss'\n }\n ]\n };\n await this.renderModalContent('moodle-modal-body-dismiss', 'moodle-modal-footer-empty', templateContext);\n }\n\n\n renderAiResultForEditor() {\n let html;\n switch (this.datamanager.getCurrentTool()) {\n case 'tts':\n case 'audiogen': {\n const audioPlayer = document.createElement('audio');\n audioPlayer.controls = 'controls';\n audioPlayer.src = this.datamanager.getCurrentAiResult();\n audioPlayer.type = 'audio/mpeg';\n html = audioPlayer.outerHTML;\n break;\n }\n case 'imggen': {\n const img = document.createElement('img');\n img.src = this.datamanager.getCurrentAiResult();\n img.classList.add('mw-100');\n html = img.outerHTML;\n break;\n }\n default: {\n html = this.datamanager.getCurrentAiResult();\n }\n }\n return html;\n }\n\n /**\n * Re-renders the content auf the modal once it has been created.\n *\n * @param {string} bodyComponentTemplate the name of the body template to use (without the prefix 'tiny_ai/components/')\n * @param {string} footerComponentTemplate the name of the footer template to use (without the prefix 'tiny_ai/components/')\n * @param {object} templateContext the template context being used for all partial templates\n * @returns {Promise} the async promise\n */\n async renderModalContent(bodyComponentTemplate, footerComponentTemplate, templateContext) {\n templateContext.tinyinstanceuniqid = this.uniqid;\n const modal = getEditorUtils(this.uniqid).getModal();\n // Remove all eventually remaining tooltips before rendering a new view.\n document.querySelectorAll('button[data-action]').forEach(button => {\n $(button).tooltip('hide');\n });\n const result = await Promise.all([\n Templates.renderForPromise('tiny_ai/components/moodle-modal-header-title', templateContext),\n Templates.renderForPromise('tiny_ai/components/' + bodyComponentTemplate, templateContext),\n Templates.renderForPromise('tiny_ai/components/' + footerComponentTemplate, templateContext)\n ]);\n if (templateContext.hasOwnProperty('modal_headline')) {\n // If there is no headline specified, we keep the old one.\n modal.setTitle(result[0].html);\n }\n // Hide all eventually still existing tooltips first, because they show on 'hover' and\n // 'focus'. So we need to remove them before removing the corresponding buttons from the DOM.\n // Boostrap 4 still using jQuery for tooltips, so we need jQuery here.\n document.querySelectorAll('button[data-action]').forEach(button => {\n $(button).tooltip('hide');\n });\n modal.setBody(result[1].html);\n modal.setFooter(result[2].html);\n result.forEach((item) => {\n Templates.runTemplateJS(item.js);\n });\n modal.getRoot().attr('data-tiny_ai_uniqid', this.uniqid);\n await this.insertInfoBox();\n await this.insertUserQuotaBox();\n document.querySelectorAll('button[data-action]').forEach(button => {\n button.addEventListener('click', event => {\n $(event.target).closest('button[data-action]').tooltip('hide');\n });\n });\n }\n\n async insertInfoBox() {\n const infoBoxSelector = '[data-rendertarget=\"infobox\"]';\n if (document.querySelector(infoBoxSelector)) {\n await renderInfoBox('tiny_ai', getEditorUtils(this.uniqid).getUserId(), infoBoxSelector,\n ['singleprompt', 'translate', 'tts', 'imggen']);\n }\n }\n\n async insertUserQuotaBox() {\n const usageBoxSelector = '[data-rendertarget=\"usageinfo\"]';\n if (document.querySelector(usageBoxSelector)) {\n await renderUserQuota(usageBoxSelector, ['singleprompt', 'translate', 'tts', 'imggen']);\n }\n }\n}\n"],"names":["constructor","uniqid","datamanager","editorUtils","reset","templateContext","this","getTemplateContext","renderModalContent","modal_headline","BasedataHandler","getTinyAiString","result_text","renderAiResultForEditor","Object","assign","getReplaceButtonsContext","getMode","centered_headline","showIcon","buttons","hasText","button_text","icon_left","icon_right","primary","secondary","tertiary","action","html","getCurrentTool","audioPlayer","document","createElement","controls","src","getCurrentAiResult","type","outerHTML","img","classList","add","bodyComponentTemplate","footerComponentTemplate","tinyinstanceuniqid","modal","getModal","querySelectorAll","forEach","button","tooltip","result","Promise","all","Templates","renderForPromise","hasOwnProperty","setTitle","setBody","setFooter","item","runTemplateJS","js","getRoot","attr","insertInfoBox","insertUserQuotaBox","addEventListener","event","target","closest","querySelector","getUserId"],"mappings":"onDA+CIA,YAAYC,sCAJH,yCACK,yCACA,WAGLA,OAASA,YACTC,aAAc,yBAAeD,aAC7BE,aAAc,yBAAeF,iCAI7BC,YAAYE,cACXC,sBAAwB,0BAAgBC,KAAKL,QAAQM,oBAAmB,yBAAeD,KAAKL,eAC5FK,KAAKE,mBAAmB,0BAA2B,2BAA4BH,+CAK/EA,iBAAkB,8BAAoBC,KAAKL,QAAQM,mBAAmB,mBACtED,KAAKE,mBAAmB,gCAAiC,+BAAgCH,+CAKzFA,iBAAkB,8BAAoBC,KAAKL,QAAQM,2BACnDD,KAAKE,mBAAmB,gCAAiC,+BAAgCH,8CAIzFA,iBAAkB,8BAAoBC,KAAKL,QAAQM,mBAAmB,kBACtED,KAAKE,mBAAmB,gCAAiC,+BAAgCH,yCAIzFA,sBAAwB,wBAAcC,KAAKL,QAAQM,mBAAmB,aACtED,KAAKE,mBAAmB,gCAAiC,+BAAgCH,8CAIzFA,sBAAwB,wBAAcC,KAAKL,QAAQM,mBAAmB,kBACtED,KAAKE,mBAAmB,oCAAqC,+BAAgCH,4CAK7FA,sBAAwB,2BAAiBC,KAAKL,QAAQM,2BACtDD,KAAKE,mBAAmB,oCAAqC,+BAAgCH,iDAI7FA,sBAAwB,wBAAcC,KAAKL,QAAQM,mBAAmB,qBACtED,KAAKE,mBAAmB,wBAAyB,+BAAgCH,iDAIjFA,sBAAwB,wBAAcC,KAAKL,QAAQM,mBAAmB,qBACtED,KAAKE,mBAAmB,wBAAyB,+BAAgCH,6CAIjFA,gBAAkB,GACxBA,gBAAgBI,eAAiBC,gBAAgBC,gBAAgB,sBAC3DL,KAAKE,mBAAmB,4BAA6B,4BAA6BH,gDAKlFA,gBAAkB,GACxBA,gBAAgBI,eAAiBC,gBAAgBC,gBAAgB,gBAGjEN,gBAAgBO,YAAcN,KAAKO,0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EiD,mBAAUC,iBAAiB,sBAAwBZ,wBAAyBtC,mBAE5EA,gBAAgBmD,eAAe,mBAE/BX,MAAMY,SAASN,OAAO,GAAGtB,MAK7BG,SAASe,iBAAiB,uBAAuBC,SAAQC,6BACnDA,QAAQC,QAAQ,WAEtBL,MAAMa,QAAQP,OAAO,GAAGtB,MACxBgB,MAAMc,UAAUR,OAAO,GAAGtB,MAC1BsB,OAAOH,SAASY,0BACFC,cAAcD,KAAKE,OAEjCjB,MAAMkB,UAAUC,KAAK,sBAAuB1D,KAAKL,cAC3CK,KAAK2D,sBACL3D,KAAK4D,qBACXlC,SAASe,iBAAiB,uBAAuBC,SAAQC,SACrDA,OAAOkB,iBAAiB,SAASC,4BAC3BA,MAAMC,QAAQC,QAAQ,uBAAuBpB,QAAQ,oCAO3DlB,SAASuC,cADW,wCAEd,0BAAc,WAAW,yBAAejE,KAAKL,QAAQuE,YAFvC,gCAGhB,CAAC,eAAgB,YAAa,MAAO,sCAMzCxC,SAASuC,cADY,0CAEf,8BAFe,kCAEmB,CAAC,eAAgB,YAAa,MAAO"} \ No newline at end of file diff --git a/amd/src/constants.js b/amd/src/constants.js index 361b43d..8d91b63 100644 --- a/amd/src/constants.js +++ b/amd/src/constants.js @@ -36,6 +36,7 @@ export const constants = { imggen: 'imggen', tts: 'tts', freeprompt: 'singleprompt', - describeimg: 'itt' + describeimg: 'itt', + imagetotext: 'itt' } }; diff --git a/amd/src/controllers/base.js b/amd/src/controllers/base.js index 4dc2ab9..eaa6898 100644 --- a/amd/src/controllers/base.js +++ b/amd/src/controllers/base.js @@ -56,6 +56,11 @@ export default class { await errorAlert(BasedataHandler.getTinyAiString('error_nopromptgiven')); return null; } + if (['describeimg', 'imagetotext'].includes(this.datamanager.getCurrentTool()) + && this.datamanager.getCurrentFile() === null) { + await errorAlert(BasedataHandler.getTinyAiString('error_nofile')); + return null; + } await this.renderer.renderLoading(); let result = null; try { diff --git a/amd/src/controllers/file.js b/amd/src/controllers/file.js new file mode 100644 index 0000000..b05cbdb --- /dev/null +++ b/amd/src/controllers/file.js @@ -0,0 +1,121 @@ +// 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 . + +/** + * Controller for handling the show/hide prompt button and the associated textarea. + * + * @module tiny_ai/controllers/dnd + * @copyright 2024, ISB Bayern + * @author Philipp Memmel + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +import {getDatamanager, getCurrentModalUniqId} from 'tiny_ai/utils'; +import Templates from 'core/templates'; +import SELECTORS from 'tiny_ai/selectors'; +import {errorAlert} from 'tiny_ai/utils'; +import * as BasedataHandler from 'tiny_ai/datahandler/basedata'; + + +export default class { + + dropzone = null; + + constructor(baseSelector) { + this.baseElement = document.querySelector(baseSelector); + } + + async init() { + this.dropzone = this.baseElement.querySelector('[data-type="dropzone"]'); + const dropzone = this.dropzone; + // Setting contentEditable to true makes the browser show a "paste" option in the context menu when + // right-clicking the drop zone. + dropzone.contentEditable = true; + + dropzone.addEventListener('drop', async(event) => { + event.preventDefault(); + dropzone.classList.remove('tiny_ai_dragover'); + dropzone.classList.add('tiny_ai_dropzone_filled'); + + if (event.dataTransfer.items) { + // Use DataTransferItemList interface to access the file(s) + const item = [...event.dataTransfer.items].shift(); + // If dropped item is no file, reject it. + if (item.kind === 'file') { + await this.handleFile(item.getAsFile()); + } + } else { + // Use DataTransfer interface to access the file(s) + await this.handleFile([...event.dataTransfer.files].shift()); + } + }); + document.querySelector(SELECTORS.modalDialog).addEventListener('paste', async(event) => { + event.preventDefault(); + const clipboardData = (event.clipboardData || window.clipboardData); + console.log(clipboardData) + if (clipboardData.files.length === 0) { + await errorAlert(BasedataHandler.getTinyAiString('error_nofileinclipboard_text'), + BasedataHandler.getTinyAiString('error_nofileinclipboard_title')); + return; + } + // There should be no tiny_ai_dragover class, just to be safe. + dropzone.classList.remove('tiny_ai_dragover'); + dropzone.classList.add('tiny_ai_dropzone_filled'); + const file = clipboardData.files[0]; + this.handleFile(file); + }); + dropzone.addEventListener('dragover', (event) => { + event.preventDefault(); + console.log(event) + dropzone.classList.remove('tiny_ai_dropzone_filled'); + dropzone.classList.add('tiny_ai_dragover'); + }); + dropzone.addEventListener('dragleave', (event) => { + event.preventDefault(); + console.log(event) + dropzone.classList.remove('tiny_ai_dragover'); + }); + } + + async handleFile(file) { + const reader = new FileReader(); + console.log(file) + reader.addEventListener( + 'load', + async() => { + const datamanager = getDatamanager(getCurrentModalUniqId(this.baseElement)); + const fileUploadedEvent = new CustomEvent('fileUploaded', { + detail: { + newFile: reader.result + } + }); + datamanager.getEventEmitterElement().dispatchEvent(fileUploadedEvent); + const fileEntryTemplateContext = { + icon: file.type === 'application/pdf' ? 'fa-file-pdf' : 'fa-image', + filename: file.name, + }; + if (file.type.startsWith('image')) { + fileEntryTemplateContext.isImage = true; + fileEntryTemplateContext.dataurl = reader.result; + } + const {html, js} = await Templates.renderForPromise('tiny_ai/components/ai-file-list-entry', + fileEntryTemplateContext); + Templates.replaceNodeContents(this.dropzone, html, js); + }, + false, + ); + reader.readAsDataURL(file); + } +} diff --git a/amd/src/controllers/filednd.js b/amd/src/controllers/filednd.js deleted file mode 100644 index 28b64df..0000000 --- a/amd/src/controllers/filednd.js +++ /dev/null @@ -1,73 +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 . - -/** - * Controller for handling the show/hide prompt button and the associated textarea. - * - * @module tiny_ai/controllers/dnd - * @copyright 2024, ISB Bayern - * @author Philipp Memmel - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - -import {getStrings} from 'core/str'; -import {getDatamanager, getCurrentModalUniqId, getIttHandler} from 'tiny_ai/utils'; - -export default class { - - constructor(baseSelector) { - this.baseElement = document.querySelector(baseSelector); - } - - async init() { - const dropzone = this.baseElement.querySelector('[data-type="dropzone"]'); - dropzone.addEventListener('drop', (event) => { - event.preventDefault(); - if (event.dataTransfer.items) { - // Use DataTransferItemList interface to access the file(s) - const item = [...event.dataTransfer.items].shift(); - // If dropped item is no file, reject it. - if (item.kind === 'file') { - this.handleFile(item); - } - } else { - // Use DataTransfer interface to access the file(s) - this.handleFile([...event.dataTransfer.files].shift()); - } - }); - dropzone.addEventListener('dragover', (event) => { - event.preventDefault(); - }); - } - - handleFile(file) { - file = file.getAsFile(); - const reader = new FileReader(); - reader.addEventListener( - 'load', - () => { - const datamanager = getDatamanager(getCurrentModalUniqId(this.baseElement)); - const fileUploadedEvent = new CustomEvent('fileUploaded', { - detail: { - newFile: reader.result - } - }); - datamanager.getEventEmitterElement().dispatchEvent(fileUploadedEvent); - }, - false, - ); - reader.readAsDataURL(file); - } -} diff --git a/amd/src/controllers/preferences.js b/amd/src/controllers/preferences.js index d1ba332..5f06de4 100644 --- a/amd/src/controllers/preferences.js +++ b/amd/src/controllers/preferences.js @@ -121,7 +121,8 @@ export default class extends BaseController { this.datamanager.setCurrentOptions(imggenHandler.getOptions()); break; } - case 'describeimg': { + case 'describeimg': + case 'imagetotext': { const fileUploadArea = this.baseElement.querySelector('[data-preference="fileupload"]'); if (fileUploadArea) { this.datamanager.getEventEmitterElement().addEventListener('fileUploaded', event => { @@ -129,7 +130,7 @@ export default class extends BaseController { this.datamanager.setCurrentOptions(ittHandler.getOptions()); }); } - this.datamanager.setCurrentPrompt(''); + this.datamanager.setCurrentPrompt(ittHandler.getPrompt(this.datamanager.getCurrentTool())); this.datamanager.setCurrentFile(null); break; } diff --git a/amd/src/controllers/start.js b/amd/src/controllers/start.js index 71f6233..22819e1 100644 --- a/amd/src/controllers/start.js +++ b/amd/src/controllers/start.js @@ -43,6 +43,7 @@ export default class extends BaseController { const imggenButton = this.baseElement.querySelector('[data-action="loadimggen"]'); const freePromptButton = this.baseElement.querySelector('[data-action="loadfreeprompt"]'); const describeimgButton = this.baseElement.querySelector('[data-action="loaddescribeimg"]'); + const imagetotextButton = this.baseElement.querySelector('[data-action="loadimagetotext"]'); const startHandler = getStartHandler(this.uniqid); @@ -100,6 +101,12 @@ export default class extends BaseController { await this.renderer.renderDescribeimg(); }); } + if (imagetotextButton) { + imagetotextButton.addEventListener('click', async() => { + this.datamanager.setCurrentTool('imagetotext'); + await this.renderer.renderImagetotext(); + }); + } if (freePromptButton) { if (!freePromptButton.classList.contains('disabled')) { freePromptButton.addEventListener('click', async () => { diff --git a/amd/src/datahandler/basedata.js b/amd/src/datahandler/basedata.js index d15ba9f..243ba7e 100644 --- a/amd/src/datahandler/basedata.js +++ b/amd/src/datahandler/basedata.js @@ -35,10 +35,15 @@ const stringKeys = [ 'backbutton_tooltip', 'cancel', 'deletebutton_tooltip', + 'describeimg_baseprompt', + 'describeimg_headline', 'describe_baseprompt', 'describe_headline', 'dismiss', 'dismisssuggestion', + 'error_nofile', + 'error_nofileinclipboard_text', + 'error_nofileinclipboard_title', 'error_nopromptgiven', 'freeprompt_placeholder', 'freepromptbutton_tooltip', @@ -49,6 +54,9 @@ const stringKeys = [ 'hideprompt', 'imggen_headline', 'imggen_placeholder', + 'imagetotext_baseprompt', + 'imagetotext_headline', + 'imagetotext_insertimage', 'insertatcaret', 'insertatcaretbutton_tooltip', 'insertbelow', @@ -75,8 +83,10 @@ const stringKeys = [ 'texttouse', 'toolname_audiogen', 'toolname_describe', + 'toolname_describeimg', 'toolname_describe_extension', 'toolname_imggen', + 'toolname_imagetotext', 'toolname_summarize', 'toolname_summarize_extension', 'toolname_translate', @@ -110,10 +120,15 @@ export const init = async() => { strings.backbutton_tooltip, strings.cancel, strings.deletebutton_tooltip, + strings.describeimg_baseprompt, + strings.describeimg_headline, strings.describe_baseprompt, strings.describe_headline, strings.dismiss, strings.dismisssuggestion, + strings.error_nofile, + strings.error_nofileinclipboard_text, + strings.error_nofileinclipboard_title, strings.error_nopromptgiven, strings.freeprompt_placeholder, strings.freepromptbutton_tooltip, @@ -124,6 +139,9 @@ export const init = async() => { strings.hideprompt, strings.imggen_headline, strings.imggen_placeholder, + strings.imagetotext_baseprompt, + strings.imagetotext_headline, + strings.imagetotext_insertimage, strings.insertatcaret, strings.insertatcaretbutton_tooltip, strings.insertbelow, @@ -150,8 +168,10 @@ export const init = async() => { strings.texttouse, strings.toolname_audiogen, strings.toolname_describe, + strings.toolname_describeimg, strings.toolname_describe_extension, strings.toolname_imggen, + strings.toolname_imagetotext, strings.toolname_summarize, strings.toolname_summarize_extension, strings.toolname_translate, diff --git a/amd/src/datahandler/itt.js b/amd/src/datahandler/itt.js index e10d2a8..f05e4cd 100644 --- a/amd/src/datahandler/itt.js +++ b/amd/src/datahandler/itt.js @@ -37,10 +37,19 @@ export default class extends BaseHandler { return options; } + /** + * Get the prompt. + * + * @param {string} tool the tool to generate the prompt for, can be 'describeimage' and 'imagetotext' + */ + getPrompt(tool) { + return BasedataHandler.getTinyAiString(tool + '_baseprompt'); + } + /** * Get the rendering context. * - * @param {string} tool the tool to generate the context for, can be 'describeimage' and 'analyzehandwriting' + * @param {string} tool the tool to generate the context for, can be 'describeimage' and 'imagetotext' */ async getTemplateContext(tool) { const context = { @@ -49,6 +58,7 @@ export default class extends BaseHandler { tool: tool, textareatype: 'prompt', placeholder: BasedataHandler.getTinyAiString(tool + '_placeholder'), + insertimagedescription: BasedataHandler.getTinyAiString('imagetotext_insertimage') }; Object.assign(context, BasedataHandler.getShowPromptButtonContext()); diff --git a/amd/src/datahandler/start.js b/amd/src/datahandler/start.js index ef20514..0e92373 100644 --- a/amd/src/datahandler/start.js +++ b/amd/src/datahandler/start.js @@ -213,12 +213,23 @@ export default class extends BaseHandler { toolname: 'describeimg', tool: BasedataHandler.getTinyAiString('toolname_describeimg'), iconstyle: 'solid', - iconname: 'image', + iconname: 'file-image', disabled: this.isToolDisabled('describeimg', mode).length > 0, tooltip: stripHtmlTags(this.isToolDisabled('describeimg', mode)), action: 'loaddescribeimg' }); } + if (!this.isToolHidden('imagetotext')) { + toolButtons.push({ + toolname: 'imagetotext', + tool: BasedataHandler.getTinyAiString('toolname_imagetotext'), + iconstyle: 'solid', + iconname: 'signature', + disabled: this.isToolDisabled('imagetotext', mode).length > 0, + tooltip: stripHtmlTags(this.isToolDisabled('imagetotext', mode)), + action: 'loadimagetotext' + }); + } // We sort the not disabled tools to the top while keeping the groups "disabled tools" and "not disabled tools" // in the same order inside the groups. toolButtons.sort((a, b) => { diff --git a/amd/src/renderer.js b/amd/src/renderer.js index 61ad645..33fa09b 100644 --- a/amd/src/renderer.js +++ b/amd/src/renderer.js @@ -91,7 +91,12 @@ export default class { } async renderDescribeimg() { - const templateContext = await getIttHandler(this.uniqid).getTemplateContext(); + const templateContext = await getIttHandler(this.uniqid).getTemplateContext('describeimg'); + await this.renderModalContent('moodle-modal-body-itt', 'moodle-modal-footer-generate', templateContext); + } + + async renderImagetotext() { + const templateContext = await getIttHandler(this.uniqid).getTemplateContext('imagetotext'); await this.renderModalContent('moodle-modal-body-itt', 'moodle-modal-footer-generate', templateContext); } diff --git a/lang/de/tiny_ai.php b/lang/de/tiny_ai.php index 7df0ef5..aea4ccd 100644 --- a/lang/de/tiny_ai.php +++ b/lang/de/tiny_ai.php @@ -38,9 +38,14 @@ $string['deletebutton_tooltip'] = 'Aktuelles Ergebnis verwerfen und zurück zur Einstellungsseite'; $string['describe_headline'] = 'Ausführliche Beschreibung des markierten Texts'; $string['describe_baseprompt'] = 'Beschreibe den nachfolgenden Text'; +$string['describeimg_headline'] = 'Bildanalyse'; +$string['describeimg_baseprompt'] = 'Beschreibe, was auf dem Bild zu sehen ist'; $string['dismiss'] = 'Verwerfen'; $string['dismisssuggestion'] = 'Möchten Sie den KI-Vorschlag verwerfen?'; $string['errorwithcode'] = 'Ein Fehler ist aufgetreten, Fehlercode: {$a}'; +$string['error_nofile'] = 'Keine Datei eingefügt. Bitte Datei hinzufügen.'; +$string['error_nofileinclipboard_text'] = 'Die Zwischenablage enthält keine Datei. Bitte eine Datei/einen Screenshot in die Zwischenablage einfügen.'; +$string['error_nofileinclipboard_title'] = 'Keine Datei'; $string['error_nopromptgiven'] = 'Kein Prompt angegeben. Bitte einen Prompt eintippen oder einfügen.'; $string['error_tiny_ai_notavailable'] = 'Die KI-Funktionen stehen Ihnen nicht zur Verfügung.'; $string['freepromptbutton_tooltip'] = 'Generiere KI-Antwort'; @@ -53,6 +58,9 @@ $string['hideprompt'] = 'Prompt ausblenden'; $string['imggen_headline'] = 'Bildgenerierung'; $string['imggen_placeholder'] = 'Beschreibung des Bilds hier eingeben oder einfügen, z. B. "Generiere ein fotorealistisches Bild eines Affen mit einem Bleistift in der Hand und einem Hut auf dem Kopf"'; +$string['imagetotext_headline'] = 'Handschrifterkennung'; +$string['imagetotext_baseprompt'] = 'Gib den Text auf dem Bild zurück'; +$string['imagetotext_insertimage'] = 'Ziehen Sie eine Datei per Drag&Drop in diesen Bereich oder fügen Sie sie aus der Zwischenablage ein'; $string['insertatcaret'] = 'An aktueller Position einfügen'; $string['insertatcaret_tooltip'] = 'Aktuelles Ergebnis an der aktuellen Position des Cursors einfügen'; $string['insertbelow'] = 'Unten einfügen'; @@ -88,7 +96,9 @@ $string['toolname_audiogen'] = 'Audiogenerierung'; $string['toolname_describe'] = 'Ausführliche Beschreibung'; $string['toolname_describe_extension'] = 'des markierten Textes'; +$string['toolname_describeimg'] = 'Bildanalyse'; $string['toolname_imggen'] = 'Bildgenerierung'; +$string['toolname_imagetotext'] = 'Handschrifterkennung'; $string['toolname_summarize'] = 'Zusammenfassen'; $string['toolname_summarize_extension'] = 'des markierten Textes'; $string['toolname_translate'] = 'Übersetzen'; diff --git a/lang/en/tiny_ai.php b/lang/en/tiny_ai.php index d357e99..c1c9e09 100644 --- a/lang/en/tiny_ai.php +++ b/lang/en/tiny_ai.php @@ -37,10 +37,15 @@ $string['cancel'] = 'Cancel'; $string['deletebutton_tooltip'] = 'Dismiss current result and go back to the preferences page'; $string['describe_headline'] = 'Detailed description of the selected text'; +$string['describe_baseprompt'] = 'Describe the following text'; +$string['describeimg_headline'] = 'Image analysis'; +$string['describeimg_baseprompt'] = 'Describe what is being shown on the image'; $string['dismiss'] = 'Dismiss'; $string['dismisssuggestion'] = 'Do you want to dismiss the AI suggestion?'; -$string['describe_baseprompt'] = 'Describe the following text'; $string['errorwithcode'] = 'An error occured with error code {$a}'; +$string['error_nofile'] = 'No file added. Please add a file.'; +$string['error_nofileinclipboard_text'] = 'Clipboard does not contain file data. Please copy a file into the clipboard before pasting.'; +$string['error_nofileinclipboard_title'] = 'No file'; $string['error_nopromptgiven'] = 'No prompt given. Please insert a prompt.'; $string['error_tiny_ai_notavailable'] = 'The AI features are not availeble for you.'; $string['freepromptbutton_tooltip'] = 'Generate AI answer'; @@ -53,6 +58,9 @@ $string['hideprompt'] = 'Hide prompt'; $string['imggen_headline'] = 'Image generation'; $string['imggen_placeholder'] = 'Insert or paste description of the image here, for example "Generate a photorealistic image of a monkey that holds a pen in one hand and wears a hat on the head"'; +$string['imagetotext_headline'] = 'Handwriting recognition'; +$string['imagetotext_baseprompt'] = 'Parse the text in the image'; +$string['imagetotext_insertimage'] = 'Drag&Drop a file into this area or paste a file from clipboard'; $string['insertatcaret'] = 'Insert at current position'; $string['insertatcaret_tooltip'] = 'Insert current result at the cursor\'s current position'; $string['insertbelow'] = 'Insert below'; @@ -88,7 +96,9 @@ $string['toolname_audiogen'] = 'Audio generation'; $string['toolname_describe'] = 'Detailed description'; $string['toolname_describe_extension'] = 'of the selected text'; +$string['toolname_describeimg'] = 'Image analysis'; $string['toolname_imggen'] = 'Image generation'; +$string['toolname_imagetotext'] = 'Handwriting recognition'; $string['toolname_summarize'] = 'Summarize'; $string['toolname_summarize_extension'] = 'the selected text'; $string['toolname_translate'] = 'Translate'; diff --git a/scss/partials/ai-dropzone.scss b/scss/partials/ai-dropzone.scss index ba0adb4..9f9a851 100644 --- a/scss/partials/ai-dropzone.scss +++ b/scss/partials/ai-dropzone.scss @@ -1,3 +1,30 @@ .tiny_ai_dropzone { + flex: 1; + display: flex; + flex-direction: column; + align-items: center; + padding: 20px; + border-width: 2px; + border-radius: 2px; + border-color: #eeeeee; + border-style: dashed; + background-color: #fafafa; + color: #bdbdbd; + outline: none; + transition: border .24s ease-in-out; height: 15rem; } + +.tiny_ai_dragover { + background-color: #63676c; +} + +.tiny_ai_dropzone_filled { + background-color: #ffffff; + color: #000000; +} + +.tiny_ai_dropzone_preview_container { + max-width: 80%; + max-height: 80%; +} diff --git a/styles.css b/styles.css index 96bb27c..9c0cef8 100644 --- a/styles.css +++ b/styles.css @@ -568,9 +568,36 @@ } .tiny_ai_dropzone { + flex: 1; + display: flex; + flex-direction: column; + align-items: center; + padding: 20px; + border-width: 2px; + border-radius: 2px; + border-color: #eeeeee; + border-style: dashed; + background-color: #fafafa; + color: #bdbdbd; + outline: none; + transition: border 0.24s ease-in-out; height: 15rem; } +.tiny_ai_dragover { + background-color: #63676c; +} + +.tiny_ai_dropzone_filled { + background-color: #ffffff; + color: #000000; +} + +.tiny_ai_dropzone_preview_container { + max-width: 80%; + max-height: 80%; +} + .tiny_ai-alert { display: flex; align-items: center; diff --git a/templates/components/ai-file-list-entry.mustache b/templates/components/ai-file-list-entry.mustache new file mode 100644 index 0000000..3bd4862 --- /dev/null +++ b/templates/components/ai-file-list-entry.mustache @@ -0,0 +1,6 @@ +
+
{{filename}}
+ {{#isImage}} +
+ {{/isImage}} +
diff --git a/templates/components/moodle-modal-body-itt.mustache b/templates/components/moodle-modal-body-itt.mustache index 2bc21d3..92968a1 100644 --- a/templates/components/moodle-modal-body-itt.mustache +++ b/templates/components/moodle-modal-body-itt.mustache @@ -1,7 +1,7 @@
-
- +
+ {{insertimagedescription}}
@@ -14,12 +14,12 @@
{{#js}} - require(['tiny_ai/controllers/preferences', 'tiny_ai/controllers/promptedit', 'tiny_ai/controllers/filednd'], function(Controller, PromptEditController, DragAndDropController) { + require(['tiny_ai/controllers/preferences', 'tiny_ai/controllers/promptedit', 'tiny_ai/controllers/file'], function(Controller, PromptEditController, FileController) { const controller = new Controller('#tiny_ai_{{tool}}_{{uniqid}}', '{{tool}}'); Promise.resolve(controller.init()); const promptEditController = new PromptEditController('#tiny_ai_{{tool}}_{{uniqid}}'); Promise.resolve(promptEditController.init()); - const dragAndDropController = new DragAndDropController('#tiny_ai_{{tool}}_{{uniqid}}'); - Promise.resolve(dragAndDropController.init()); + const fileController = new FileController('#tiny_ai_{{tool}}_{{uniqid}}'); + Promise.resolve(fileController.init()); }); {{/js}}