diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1adebb9..f6a0c5a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -8,7 +8,7 @@ jobs: services: postgres: - image: postgres:13 + image: postgres:16 env: POSTGRES_USER: 'postgres' POSTGRES_HOST_AUTH_METHOD: 'trust' @@ -17,7 +17,7 @@ jobs: options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 3 mariadb: - image: mariadb:10 + image: mariadb:10.11 env: MYSQL_USER: 'root' MYSQL_ALLOW_EMPTY_PASSWORD: "true" @@ -31,7 +31,7 @@ jobs: fail-fast: false matrix: php: ['8.2', '8.3'] - moodle-branch: ['main', 'MOODLE_404_STABLE'] + moodle-branch: ['main', 'MOODLE_405_STABLE', 'MOODLE_404_STABLE'] database: [pgsql, mariadb] steps: @@ -85,6 +85,7 @@ jobs: run: moodle-plugin-ci savepoints - name: Mustache Lint + continue-on-error: true if: ${{ !cancelled() }} run: moodle-plugin-ci mustache diff --git a/amd/build/commands.min.js.map b/amd/build/commands.min.js.map index 4cfe500..30f461f 100644 --- a/amd/build/commands.min.js.map +++ b/amd/build/commands.min.js.map @@ -1 +1 @@ -{"version":3,"file":"commands.min.js","sources":["../src/commands.js"],"sourcesContent":["// This file is part of Moodle - https://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see .\n\n/**\n * Commands helper for the Moodle tiny_ai plugin.\n *\n * @module tiny_ai/commands\n * @copyright 2024, ISB Bayern\n * @author Dr. Peter Mayer\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nimport {getButtonImage} from 'editor_tiny/utils';\nimport {\n component,\n toolbarButtonName,\n selectionbarButtonName,\n icon,\n selectionbarSource,\n toolbarSource,\n menubarSource\n} from 'tiny_ai/common';\nimport * as Utils from 'tiny_ai/utils';\nimport {prefetchStrings} from 'core/prefetch';\nimport {getString} from 'core/str';\n\n/**\n * Get the setup function for the buttons.\n *\n * This is performed in an async function which ultimately returns the registration function as the\n * Tiny.AddOnManager.Add() function does not support async functions.\n *\n * @returns {function} The registration function to call within the Plugin.add function.\n */\nexport const getSetup = async() => {\n prefetchStrings('tiny_ai', ['toolbarbuttontitle', 'selectionbarbuttontitle']);\n const [\n buttonImage,\n toolbarButtonTitle,\n selectionbarButtonTitle\n ] = await Promise.all([\n getButtonImage('icon', component),\n getString('toolbarbuttontitle', 'tiny_ai'),\n getString('selectionbarbuttontitle', 'tiny_ai')\n ]);\n\n\n return (editor) => {\n // Register the Moodle SVG as an icon suitable for use as a TinyMCE toolbar button.\n editor.ui.registry.addIcon(icon, buttonImage.html);\n\n const uniqid = Math.random().toString(16).slice(2);\n Utils.init(uniqid, editor);\n\n // Register the AI Toolbar Button.\n editor.ui.registry.addButton(toolbarButtonName, {\n icon,\n tooltip: toolbarButtonTitle,\n onAction: () => {\n Utils.getEditorUtils(uniqid).displayDialogue(toolbarSource);\n }\n });\n\n // Register the menu item.\n editor.ui.registry.addMenuItem(toolbarButtonName, {\n icon,\n text: toolbarButtonTitle,\n onAction: () => {\n Utils.getEditorUtils(uniqid).displayDialogue(menubarSource);\n }\n });\n\n editor.ui.registry.addButton(selectionbarButtonName, {\n icon,\n tooltip: selectionbarButtonTitle,\n onAction: () => {\n Utils.getEditorUtils(uniqid).displayDialogue(selectionbarSource);\n }\n });\n\n // editor.on('init', () => onInit(editor));\n // editor.on('BeforeGetContent', format => onBeforeGetContent(format));\n // editor.on('submit', () => onSubmit());\n\n };\n};\n"],"names":["async","buttonImage","toolbarButtonTitle","selectionbarButtonTitle","Promise","all","component","editor","ui","registry","addIcon","icon","html","uniqid","Math","random","toString","slice","Utils","init","addButton","toolbarButtonName","tooltip","onAction","getEditorUtils","displayDialogue","toolbarSource","addMenuItem","text","menubarSource","selectionbarButtonName","selectionbarSource"],"mappings":";;;;;;;;+BA8CwBA,wCACJ,UAAW,CAAC,qBAAsB,kCAE9CC,YACAC,mBACAC,+BACMC,QAAQC,IAAI,EAClB,yBAAe,OAAQC,oBACvB,kBAAU,qBAAsB,YAChC,kBAAU,0BAA2B,oBAIjCC,SAEJA,OAAOC,GAAGC,SAASC,QAAQC,aAAMV,YAAYW,YAEvCC,OAASC,KAAKC,SAASC,SAAS,IAAIC,MAAM,GAChDC,MAAMC,KAAKN,OAAQN,QAGnBA,OAAOC,GAAGC,SAASW,UAAUC,0BAAmB,CAC5CV,KAAAA,aACAW,QAASpB,mBACTqB,SAAU,KACNL,MAAMM,eAAeX,QAAQY,gBAAgBC,0BAKrDnB,OAAOC,GAAGC,SAASkB,YAAYN,0BAAmB,CAC9CV,KAAAA,aACAiB,KAAM1B,mBACNqB,SAAU,KACNL,MAAMM,eAAeX,QAAQY,gBAAgBI,0BAIrDtB,OAAOC,GAAGC,SAASW,UAAUU,+BAAwB,CACjDnB,KAAAA,aACAW,QAASnB,wBACToB,SAAU,KACNL,MAAMM,eAAeX,QAAQY,gBAAgBM"} \ No newline at end of file +{"version":3,"file":"commands.min.js","sources":["../src/commands.js"],"sourcesContent":["// This file is part of Moodle - https://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see .\n\n/**\n * Commands helper for the Moodle tiny_ai plugin.\n *\n * @module tiny_ai/commands\n * @copyright 2024, ISB Bayern\n * @author Dr. Peter Mayer\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nimport {getButtonImage} from 'editor_tiny/utils';\nimport {\n component,\n toolbarButtonName,\n selectionbarButtonName,\n icon,\n selectionbarSource,\n toolbarSource,\n menubarSource\n} from 'tiny_ai/common';\nimport * as Utils from 'tiny_ai/utils';\nimport {prefetchStrings} from 'core/prefetch';\nimport {getString} from 'core/str';\n\n/**\n * Get the setup function for the buttons.\n *\n * This is performed in an async function which ultimately returns the registration function as the\n * Tiny.AddOnManager.Add() function does not support async functions.\n *\n * @returns {function} The registration function to call within the Plugin.add function.\n */\nexport const getSetup = async() => {\n prefetchStrings('tiny_ai', ['toolbarbuttontitle', 'selectionbarbuttontitle']);\n const [\n buttonImage,\n toolbarButtonTitle,\n selectionbarButtonTitle\n ] = await Promise.all([\n getButtonImage('icon', component),\n getString('toolbarbuttontitle', 'tiny_ai'),\n getString('selectionbarbuttontitle', 'tiny_ai')\n ]);\n\n\n return (editor) => {\n // Register the Moodle SVG as an icon suitable for use as a TinyMCE toolbar button.\n editor.ui.registry.addIcon(icon, buttonImage.html);\n\n const uniqid = Math.random().toString(16).slice(2);\n Utils.init(uniqid, editor);\n\n // Register the AI Toolbar Button.\n editor.ui.registry.addButton(toolbarButtonName, {\n icon,\n tooltip: toolbarButtonTitle,\n onAction: () => {\n Utils.getEditorUtils(uniqid).displayDialogue(toolbarSource);\n }\n });\n\n // Register the menu item.\n editor.ui.registry.addMenuItem(toolbarButtonName, {\n icon,\n text: toolbarButtonTitle,\n onAction: () => {\n Utils.getEditorUtils(uniqid).displayDialogue(menubarSource);\n }\n });\n\n editor.ui.registry.addButton(selectionbarButtonName, {\n icon,\n tooltip: selectionbarButtonTitle,\n onAction: () => {\n Utils.getEditorUtils(uniqid).displayDialogue(selectionbarSource);\n }\n });\n };\n};\n"],"names":["async","buttonImage","toolbarButtonTitle","selectionbarButtonTitle","Promise","all","component","editor","ui","registry","addIcon","icon","html","uniqid","Math","random","toString","slice","Utils","init","addButton","toolbarButtonName","tooltip","onAction","getEditorUtils","displayDialogue","toolbarSource","addMenuItem","text","menubarSource","selectionbarButtonName","selectionbarSource"],"mappings":";;;;;;;;+BA8CwBA,wCACJ,UAAW,CAAC,qBAAsB,kCAE9CC,YACAC,mBACAC,+BACMC,QAAQC,IAAI,EAClB,yBAAe,OAAQC,oBACvB,kBAAU,qBAAsB,YAChC,kBAAU,0BAA2B,oBAIjCC,SAEJA,OAAOC,GAAGC,SAASC,QAAQC,aAAMV,YAAYW,YAEvCC,OAASC,KAAKC,SAASC,SAAS,IAAIC,MAAM,GAChDC,MAAMC,KAAKN,OAAQN,QAGnBA,OAAOC,GAAGC,SAASW,UAAUC,0BAAmB,CAC5CV,KAAAA,aACAW,QAASpB,mBACTqB,SAAU,KACNL,MAAMM,eAAeX,QAAQY,gBAAgBC,0BAKrDnB,OAAOC,GAAGC,SAASkB,YAAYN,0BAAmB,CAC9CV,KAAAA,aACAiB,KAAM1B,mBACNqB,SAAU,KACNL,MAAMM,eAAeX,QAAQY,gBAAgBI,0BAIrDtB,OAAOC,GAAGC,SAASW,UAAUU,+BAAwB,CACjDnB,KAAAA,aACAW,QAASnB,wBACToB,SAAU,KACNL,MAAMM,eAAeX,QAAQY,gBAAgBM"} \ No newline at end of file diff --git a/amd/build/configuration.min.js.map b/amd/build/configuration.min.js.map index c3cbd3a..8bdb7fa 100644 --- a/amd/build/configuration.min.js.map +++ b/amd/build/configuration.min.js.map @@ -1 +1 @@ -{"version":3,"file":"configuration.min.js","sources":["../src/configuration.js"],"sourcesContent":["// This file is part of Moodle - https://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see .\n\n/**\n * Tiny tiny_ai for Moodle.\n *\n * @module tiny_ai/configuration\n * @copyright 2024, ISB Bayern\n * @author Dr. Peter Mayer\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nimport {\n toolbarButtonName,\n selectionbarButtonName\n} from 'tiny_ai/common';\n\nimport {\n addMenubarItem,\n addToolbarButtons,\n addQuickbarsToolbarItem\n} from 'editor_tiny/utils';\n\nconst getToolbarConfiguration = (instanceConfig) => {\n let toolbar = instanceConfig.toolbar;\n\n toolbar = addToolbarButtons(toolbar, 'formatting', [\n toolbarButtonName,\n ]);\n\n return toolbar;\n};\n\nconst getMenuConfiguration = (instanceConfig) => {\n let menu = instanceConfig.menu;\n menu = addMenubarItem(menu, 'tools', [\n toolbarButtonName,\n ].join(' '));\n return menu;\n};\n\nconst getSelectionToolbarConfiguration = (instanceConfig) => {\n let toolbar = instanceConfig.quickbars_selection_toolbar;\n // The following is a dirty workaround until MDL-82724 has been integrated.\n if (toolbar === false) {\n toolbar = undefined;\n }\n toolbar = addQuickbarsToolbarItem(toolbar, '|', selectionbarButtonName);\n return toolbar;\n};\n\nexport const configure = (instanceConfig) => {\n return {\n toolbar: getToolbarConfiguration(instanceConfig),\n menu: getMenuConfiguration(instanceConfig),\n quickbars_selection_toolbar: getSelectionToolbarConfiguration(instanceConfig)\n };\n};\n"],"names":["getToolbarConfiguration","instanceConfig","toolbar","toolbarButtonName","getMenuConfiguration","menu","join","getSelectionToolbarConfiguration","quickbars_selection_toolbar","undefined","selectionbarButtonName"],"mappings":";;;;;;;;;MAmCMA,wBAA2BC,qBACzBC,QAAUD,eAAeC,eAE7BA,SAAU,4BAAkBA,QAAS,aAAc,CAC/CC,4BAGGD,SAGLE,qBAAwBH,qBACtBI,KAAOJ,eAAeI,YAC1BA,MAAO,yBAAeA,KAAM,QAAS,CACjCF,2BACFG,KAAK,MACAD,MAGLE,iCAAoCN,qBAClCC,QAAUD,eAAeO,mCAEb,IAAZN,UACAA,aAAUO,GAEdP,SAAU,kCAAwBA,QAAS,IAAKQ,gCACzCR,4BAGeD,iBACf,CACHC,QAASF,wBAAwBC,gBACjCI,KAAMD,qBAAqBH,gBAC3BO,4BAA6BD,iCAAiCN"} \ No newline at end of file +{"version":3,"file":"configuration.min.js","sources":["../src/configuration.js"],"sourcesContent":["// This file is part of Moodle - https://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see .\n\n/**\n * Tiny tiny_ai for Moodle.\n *\n * @module tiny_ai/configuration\n * @copyright 2024, ISB Bayern\n * @author Dr. Peter Mayer\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nimport {\n toolbarButtonName,\n selectionbarButtonName\n} from 'tiny_ai/common';\n\nimport {\n addMenubarItem,\n addToolbarButtons,\n addQuickbarsToolbarItem\n} from 'editor_tiny/utils';\n\nconst getToolbarConfiguration = (instanceConfig) => {\n let toolbar = instanceConfig.toolbar;\n\n toolbar = addToolbarButtons(toolbar, 'formatting', [\n toolbarButtonName,\n ]);\n\n return toolbar;\n};\n\nconst getMenuConfiguration = (instanceConfig) => {\n let menu = instanceConfig.menu;\n menu = addMenubarItem(menu, 'tools', [\n toolbarButtonName,\n ].join(' '));\n return menu;\n};\n\nconst getSelectionToolbarConfiguration = (instanceConfig) => {\n let toolbar = instanceConfig.quickbars_selection_toolbar;\n // The following is a dirty workaround until MDL-82724 has been integrated.\n if (toolbar === false) {\n toolbar = undefined;\n }\n toolbar = addQuickbarsToolbarItem(toolbar, '|', selectionbarButtonName);\n return toolbar;\n};\n\nexport const configure = (instanceConfig) => {\n return {\n toolbar: getToolbarConfiguration(instanceConfig),\n menu: getMenuConfiguration(instanceConfig),\n // eslint-disable-next-line camelcase\n quickbars_selection_toolbar: getSelectionToolbarConfiguration(instanceConfig)\n };\n};\n"],"names":["getToolbarConfiguration","instanceConfig","toolbar","toolbarButtonName","getMenuConfiguration","menu","join","getSelectionToolbarConfiguration","quickbars_selection_toolbar","undefined","selectionbarButtonName"],"mappings":";;;;;;;;;MAmCMA,wBAA2BC,qBACzBC,QAAUD,eAAeC,eAE7BA,SAAU,4BAAkBA,QAAS,aAAc,CAC/CC,4BAGGD,SAGLE,qBAAwBH,qBACtBI,KAAOJ,eAAeI,YAC1BA,MAAO,yBAAeA,KAAM,QAAS,CACjCF,2BACFG,KAAK,MACAD,MAGLE,iCAAoCN,qBAClCC,QAAUD,eAAeO,mCAEb,IAAZN,UACAA,aAAUO,GAEdP,SAAU,kCAAwBA,QAAS,IAAKQ,gCACzCR,4BAGeD,iBACf,CACHC,QAASF,wBAAwBC,gBACjCI,KAAMD,qBAAqBH,gBAE3BO,4BAA6BD,iCAAiCN"} \ No newline at end of file diff --git a/amd/build/controllers/optimize.min.js.map b/amd/build/controllers/optimize.min.js.map index 223f522..39aaa91 100644 --- a/amd/build/controllers/optimize.min.js.map +++ b/amd/build/controllers/optimize.min.js.map @@ -1 +1 @@ -{"version":3,"file":"optimize.min.js","sources":["../../src/controllers/optimize.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/optimize\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';\n\nexport default class extends BaseController {\n\n async init() {\n const backButton = this.footer.querySelector('[data-action=\"back\"]');\n const generateButton = this.footer.querySelector('[data-action=\"generate\"]');\n\n if (backButton) {\n backButton.addEventListener('click', async() => {\n await this.renderer.renderSuggestion();\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","backButton","this","footer","querySelector","generateButton","addEventListener","async","renderer","renderSuggestion","generateAiAnswer"],"mappings":";;;;;;;;gKA0B6BA,iCAGfC,WAAaC,KAAKC,OAAOC,cAAc,wBACvCC,eAAiBH,KAAKC,OAAOC,cAAc,4BAE7CH,YACAA,WAAWK,iBAAiB,SAASC,gBAC3BL,KAAKM,SAASC,sBAIxBJ,gBACAA,eAAeC,iBAAiB,SAASC,UAEtB,aADML,KAAKQ,0BAIpBR,KAAKM,SAASC"} \ No newline at end of file +{"version":3,"file":"optimize.min.js","sources":["../../src/controllers/optimize.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/optimize\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';\n\nexport default class extends BaseController {\n\n async init() {\n const backButton = this.footer.querySelector('[data-action=\"back\"]');\n const generateButton = this.footer.querySelector('[data-action=\"generate\"]');\n\n if (backButton) {\n backButton.addEventListener('click', async() => {\n await this.renderer.renderSuggestion();\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","backButton","this","footer","querySelector","generateButton","addEventListener","async","renderer","renderSuggestion","generateAiAnswer"],"mappings":";;;;;;;;gKA0B6BA,iCAGfC,WAAaC,KAAKC,OAAOC,cAAc,wBACvCC,eAAiBH,KAAKC,OAAOC,cAAc,4BAE7CH,YACAA,WAAWK,iBAAiB,SAASC,gBAC3BL,KAAKM,SAASC,sBAIxBJ,gBACAA,eAAeC,iBAAiB,SAASC,UAEtB,aADML,KAAKQ,0BAIpBR,KAAKM,SAASC"} \ 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 1e98767..ccbea78 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/preferences\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', async (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,wBACvC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8B,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 +{"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/preferences\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', async(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,iBAAiBk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GlDF,gBACA9B,WAAWkC,UAAUJ,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,gBAAgBC,MAAAA,aAClEf,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.map b/amd/build/controllers/start.min.js.map index 465c87e..14145d8 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 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 +{"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,kB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d/build/datahandler/basedata.min.js b/amd/build/datahandler/basedata.min.js index 70a5c43..21f0500 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","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","imagefromeditor","imagetotext_baseprompt","imagetotext_headline","imagetotext_insertimage","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_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.imagefromeditor,strings.imagetotext_baseprompt,strings.imagetotext_headline,strings.imagetotext_insertimage,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_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})})); +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","imagefromeditor","imagetotext_baseprompt","imagetotext_headline","imagetotext_insertimage","imggen_headline","imggen_placeholder","insertatcaret","insertatcaret_tooltip","insertbelow","insertbelow_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=new Map;_exports.init=async()=>{(0,_prefetch.prefetchStrings)("tiny_ai",stringKeys);const stringRequest=stringKeys.map((key=>({key:key,component:"tiny_ai"}))),fetchedStrings=await(0,_str.getStrings)(stringRequest);for(let i=0;istrings.get(string);_exports.getTinyAiString=getTinyAiString;_exports.getBackAndGenerateButtonContext=()=>({footerButtons:[{hasText:!0,buttonText:getTinyAiString("back"),iconLeft:!0,iconRight:!1,primary:!1,secondary:!1,tertiary:!0,iconname:"arrow-left",iconstyle:"solid",action:"back",tooltip:getTinyAiString("backbutton_tooltip")},{hasText:!0,buttonText:getTinyAiString("generate"),iconLeft:!0,iconRight:!1,primary:!0,secondary:!1,tertiary:!1,iconname:"sparkle",customicon:!0,action:"generate",tooltip:getTinyAiString("generatebutton_tooltip")}]});_exports.getReplaceButtonsContext=mode=>({footerIconButtons:[{action:"delete",iconname:"trash",tooltip:getTinyAiString("deletebutton_tooltip")},{action:"regenerate",iconname:"arrows-rotate",tooltip:getTinyAiString("regeneratebutton_tooltip")}],footerButtons:[{action:"insertbelow",hasText:!0,buttonText:getTinyAiString("insertbelow"),iconLeft:!0,iconRight:!1,secondary:!0,iconname:"text-insert-last",customicon:!0,tooltip:getTinyAiString("insertbelow_tooltip")},{action:mode===_constants.constants.modalModes.selection?"replace":"insertatcaret",hasText:!0,buttonText:mode===_constants.constants.modalModes.selection?getTinyAiString("replaceselection"):getTinyAiString("insertatcaret"),iconLeft:!0,iconRight:!1,primary:!0,iconname:"check",iconstyle:"solid",tooltip:mode===_constants.constants.modalModes.selection?getTinyAiString("replaceselection_tooltip"):getTinyAiString("insertatcaret_tooltip")}]});_exports.getInputContext=()=>({input:[{iconname:"sparkle",customicon:!0,button:[{customicon:!1,iconname:"arrow-right",iconstyle:"solid",iconLeft:!1,iconRight:!0,tooltip:getTinyAiString("freepromptbutton_tooltip")}]}]});_exports.getShowPromptButtonContext=()=>({hasText:!0,buttonText:getTinyAiString("showprompt"),iconLeft:!0,iconRight:!1,tertiary:!0,iconname:"eye",iconstyle:"solid",action:"showprompt",textareatype:"prompt",collapsed:!0,tooltip:getTinyAiString("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 0878222..295e96e 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 '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 'imagefromeditor',\n 'imagetotext_baseprompt',\n 'imagetotext_headline',\n 'imagetotext_insertimage',\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_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.imagefromeditor,\n strings.imagetotext_baseprompt,\n strings.imagetotext_headline,\n strings.imagetotext_insertimage,\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_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","imagefromeditor","imagetotext_baseprompt","imagetotext_headline","imagetotext_insertimage","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_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,yBACA,uBACA,0BACA,kBACA,qBACA,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,QAAQ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,EACTC,YAAahF,QAAQU,KACrBuE,WAAW,EACXC,YAAY,EACZC,SAAS,EACTC,WAAW,EACXC,UAAU,EACVC,SAAU,aACVC,UAAW,QACXC,OAAQ,OACRC,QAASzF,QAAQW,oBAErB,CACIoE,SAAS,EACTC,YAAahF,QAAQ4B,SACrBqD,WAAW,EACXC,YAAY,EACZC,SAAS,EACTC,WAAW,EACXC,UAAU,EACVC,SAAU,UACVI,YAAY,EACZF,OAAQ,WACRC,QAASzF,QAAQ6B,6DAMQ8D,OAE7B,CACJC,mBACI,CACI,CACIJ,OAAQ,SACRF,SAAU,QACVG,QAASzF,QAAQa,sBAErB,CACI2E,OAAQ,aACRF,SAAU,gBACVG,QAASzF,QAAQgD,2BAG7B8B,eACI,CACI,CACIU,OAAQ,cACRT,SAAS,EACTC,YAAahF,QAAQuC,YACrB0C,WAAW,EACXC,YAAY,EACZE,WAAW,EACXE,SAAU,mBACVI,YAAY,EACZD,QAASzF,QAAQ6F,qBAErB,CACIL,OAAQG,OAASG,qBAAUC,WAAWC,UAAY,UAAY,gBAC9DjB,SAAS,EACTC,YAAaW,OAASG,qBAAUC,WAAWC,UAAYhG,QAAQiD,iBAAmBjD,QAAQqC,cAC1F4C,WAAW,EACXC,YAAY,EACZC,SAAS,EACTG,SAAU,QACVC,UAAW,QACXE,QAASE,OAASG,qBAAUC,WAAWC,UACjChG,QAAQiG,yBAA2BjG,QAAQkG,mDAMtC,KACpB,CACHC,MAAO,CACH,CACIb,SAAU,UACVI,YAAY,EACZU,OAAQ,CACJ,CACIV,YAAY,EACZJ,SAAU,cACVC,UAAW,QACXN,WAAW,EACXC,YAAY,EACZO,QAASzF,QAAQyB,mEAQC,KAC/B,CACHsD,SAAS,EACTC,YAAahF,QAAQsD,WACrB2B,WAAW,EACXC,YAAY,EACZG,UAAU,EACVC,SAAU,MACVC,UAAW,QACXC,OAAQ,aACRa,aAAc,SACdC,WAAW,EACXb,QAASzF,QAAQuD"} \ 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 'imagefromeditor',\n 'imagetotext_baseprompt',\n 'imagetotext_headline',\n 'imagetotext_insertimage',\n 'imggen_headline',\n 'imggen_placeholder',\n 'insertatcaret',\n 'insertatcaret_tooltip',\n 'insertbelow',\n 'insertbelow_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 = new Map();\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 const fetchedStrings = await getStrings(stringRequest);\n for (let i = 0; i < stringKeys.length; i++) {\n strings.set(stringKeys[i], fetchedStrings[i]);\n }\n};\n\nexport const getTinyAiString = (string) => {\n return strings.get(string);\n};\n\nexport const getBackAndGenerateButtonContext = () => {\n return {\n footerButtons: [\n {\n hasText: true,\n buttonText: getTinyAiString('back'),\n iconLeft: true,\n iconRight: false,\n primary: false,\n secondary: false,\n tertiary: true,\n iconname: 'arrow-left',\n iconstyle: 'solid',\n action: 'back',\n tooltip: getTinyAiString('backbutton_tooltip')\n },\n {\n hasText: true,\n buttonText: getTinyAiString('generate'),\n iconLeft: true,\n iconRight: false,\n primary: true,\n secondary: false,\n tertiary: false,\n iconname: 'sparkle',\n customicon: true,\n action: 'generate',\n tooltip: getTinyAiString('generatebutton_tooltip')\n }\n ]\n };\n};\n\nexport const getReplaceButtonsContext = (mode) => {\n\n return {\n footerIconButtons:\n [\n {\n action: 'delete',\n iconname: 'trash',\n tooltip: getTinyAiString('deletebutton_tooltip')\n },\n {\n action: 'regenerate',\n iconname: 'arrows-rotate',\n tooltip: getTinyAiString('regeneratebutton_tooltip')\n }\n ],\n footerButtons:\n [\n {\n action: 'insertbelow',\n hasText: true,\n buttonText: getTinyAiString('insertbelow'),\n iconLeft: true,\n iconRight: false,\n secondary: true,\n iconname: 'text-insert-last',\n customicon: true,\n tooltip: getTinyAiString('insertbelow_tooltip')\n },\n {\n action: mode === constants.modalModes.selection ? 'replace' : 'insertatcaret',\n hasText: true,\n buttonText: mode === constants.modalModes.selection\n ? getTinyAiString('replaceselection') : getTinyAiString('insertatcaret'),\n iconLeft: true,\n iconRight: false,\n primary: true,\n iconname: 'check',\n iconstyle: 'solid',\n tooltip: mode === constants.modalModes.selection\n ? getTinyAiString('replaceselection_tooltip') : getTinyAiString('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 iconLeft: false,\n iconRight: true,\n tooltip: getTinyAiString('freepromptbutton_tooltip')\n }\n ]\n }\n ],\n };\n};\n\nexport const getShowPromptButtonContext = () => {\n return {\n hasText: true,\n buttonText: getTinyAiString('showprompt'),\n iconLeft: true,\n iconRight: false,\n tertiary: true,\n iconname: 'eye',\n iconstyle: 'solid',\n action: 'showprompt',\n textareatype: 'prompt',\n collapsed: true,\n tooltip: getTinyAiString('showpromptbutton_tooltip')\n };\n};\n"],"names":["stringKeys","strings","Map","async","stringRequest","map","key","component","fetchedStrings","i","length","set","getTinyAiString","string","get","footerButtons","hasText","buttonText","iconLeft","iconRight","primary","secondary","tertiary","iconname","iconstyle","action","tooltip","customicon","mode","footerIconButtons","constants","modalModes","selection","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,W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C9DhB,SAAS,EACTC,WAAYW,OAASE,qBAAUC,WAAWC,UACpCpB,gBAAgB,oBAAsBA,gBAAgB,iBAC5DM,UAAU,EACVC,WAAW,EACXC,SAAS,EACTG,SAAU,QACVC,UAAW,QACXE,QAASE,OAASE,qBAAUC,WAAWC,UACjCpB,gBAAgB,4BAA8BA,gBAAgB,sDAMzD,KACpB,CACHqB,MAAO,CACH,CACIV,SAAU,UACVI,YAAY,EACZO,OAAQ,CACJ,CACIP,YAAY,EACZJ,SAAU,cACVC,UAAW,QACXN,UAAU,EACVC,WAAW,EACXO,QAASd,gBAAgB,sEAQP,KAC/B,CACHI,SAAS,EACTC,WAAYL,gBAAgB,cAC5BM,UAAU,EACVC,WAAW,EACXG,UAAU,EACVC,SAAU,MACVC,UAAW,QACXC,OAAQ,aACRU,aAAc,SACdC,WAAW,EACXV,QAASd,gBAAgB"} \ No newline at end of file diff --git a/amd/build/datahandler/imggen.min.js b/amd/build/datahandler/imggen.min.js index 3fd6659..1f57138 100644 --- a/amd/build/datahandler/imggen.min.js +++ b/amd/build/datahandler/imggen.min.js @@ -6,6 +6,6 @@ define("tiny_ai/datahandler/imggen",["exports","local_ai_manager/config","./base * @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=(obj=_base)&&obj.__esModule?obj:{default:obj};class _default extends _base.default{constructor(){super(...arguments),_defineProperty(this,"imggenOptions",null),_defineProperty(this,"size",null)}async getSizesOptions(){return await this.loadImggenOptions(),this.imggenOptions.sizes}setSize(size){this.size=size}getOptions(){if(null===this.size)return{};const options={};return this.size&&(options.sizes=[this.size]),options}async loadImggenOptions(){if(null===this.imggenOptions){const fetchedOptions=await AiConfig.getPurposeOptions("imggen");this.imggenOptions=JSON.parse(fetchedOptions.options)}}async getTemplateContext(){const context={modal_headline:BasedataHandler.getTinyAiString("imggen_headline"),showIcon:!0,tool:"imggen",textareatype:"prompt",placeholder:BasedataHandler.getTinyAiString("imggen_placeholder")},modalDropdowns=[],sizesOptions=await this.getSizesOptions();if(null!==sizesOptions&&Object.keys(sizesOptions).length>0){const sizesDropdownContext={preference:"sizes"};sizesDropdownContext.dropdown_default=sizesOptions[0].displayname,sizesDropdownContext.dropdown_default_value=sizesOptions[0].key,sizesDropdownContext.dropdown_description=BasedataHandler.getTinyAiString("size");const sizesDropdownOptions=[];sizesOptions.forEach((option=>{sizesDropdownOptions.push({optionValue:option.key,optionLabel:option.displayname})})),sizesDropdownContext.dropdown_options=sizesDropdownOptions,modalDropdowns.push(sizesDropdownContext)}return modalDropdowns.forEach((dropdownContext=>{dropdownContext.dropup=!0})),Object.assign(context,{modal_dropdowns:modalDropdowns}),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=(obj=_base)&&obj.__esModule?obj:{default:obj};class _default extends _base.default{constructor(){super(...arguments),_defineProperty(this,"imggenOptions",null),_defineProperty(this,"size",null)}async getSizesOptions(){return await this.loadImggenOptions(),this.imggenOptions.sizes}setSize(size){this.size=size}getOptions(){if(null===this.size)return{};const options={};return this.size&&(options.sizes=[this.size]),options}async loadImggenOptions(){if(null===this.imggenOptions){const fetchedOptions=await AiConfig.getPurposeOptions("imggen");this.imggenOptions=JSON.parse(fetchedOptions.options)}}async getTemplateContext(){const context={modalHeadline:BasedataHandler.getTinyAiString("imggen_headline"),showIcon:!0,tool:"imggen",textareatype:"prompt",placeholder:BasedataHandler.getTinyAiString("imggen_placeholder")},modalDropdowns=[],sizesOptions=await this.getSizesOptions();if(null!==sizesOptions&&Object.keys(sizesOptions).length>0){const sizesDropdownContext={preference:"sizes"};sizesDropdownContext.dropdownDefault=sizesOptions[0].displayname,sizesDropdownContext.dropdownDefaultValue=sizesOptions[0].key,sizesDropdownContext.dropdownDescription=BasedataHandler.getTinyAiString("size");const sizesDropdownOptions=[];sizesOptions.forEach((option=>{sizesDropdownOptions.push({optionValue:option.key,optionLabel:option.displayname})})),sizesDropdownContext.dropdownOptions=sizesDropdownOptions,modalDropdowns.push(sizesDropdownContext)}return modalDropdowns.forEach((dropdownContext=>{dropdownContext.dropup=!0})),Object.assign(context,{modalDropdowns:modalDropdowns}),Object.assign(context,BasedataHandler.getBackAndGenerateButtonContext()),context}}return _exports.default=_default,_exports.default})); //# sourceMappingURL=imggen.min.js.map \ No newline at end of file diff --git a/amd/build/datahandler/imggen.min.js.map b/amd/build/datahandler/imggen.min.js.map index 090eeb3..07fdf35 100644 --- a/amd/build/datahandler/imggen.min.js.map +++ b/amd/build/datahandler/imggen.min.js.map @@ -1 +1 @@ -{"version":3,"file":"imggen.min.js","sources":["../../src/datahandler/imggen.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 \"./basedata\";\nimport BaseHandler from 'tiny_ai/datahandler/base';\n\n/**\n * Tiny AI data manager.\n *\n * @module tiny_ai/datahandler/imggen\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 imggenOptions = null;\n\n size = null;\n\n async getSizesOptions() {\n await this.loadImggenOptions();\n return this.imggenOptions.sizes;\n }\n\n setSize(size) {\n this.size = size;\n }\n\n getOptions() {\n if (this.size === null) {\n return {};\n }\n const options = {};\n if (this.size) {\n options['sizes'] = [this.size];\n }\n return options;\n }\n\n async loadImggenOptions() {\n if (this.imggenOptions === null) {\n const fetchedOptions = await AiConfig.getPurposeOptions('imggen');\n this.imggenOptions = JSON.parse(fetchedOptions.options);\n }\n }\n\n async getTemplateContext() {\n const context = {\n modal_headline: BasedataHandler.getTinyAiString('imggen_headline'),\n showIcon: true,\n tool: 'imggen',\n textareatype: 'prompt',\n placeholder: BasedataHandler.getTinyAiString('imggen_placeholder'),\n };\n\n const modalDropdowns = [];\n\n const sizesOptions = await this.getSizesOptions();\n if (sizesOptions !== null && Object.keys(sizesOptions).length > 0) {\n const sizesDropdownContext = {};\n sizesDropdownContext.preference = 'sizes';\n sizesDropdownContext.dropdown_default = sizesOptions[0]['displayname'];\n sizesDropdownContext.dropdown_default_value = sizesOptions[0]['key'];\n sizesDropdownContext.dropdown_description = BasedataHandler.getTinyAiString('size');\n const sizesDropdownOptions = [];\n sizesOptions.forEach(option => {\n sizesDropdownOptions.push({\n optionValue: option.key,\n optionLabel: option.displayname,\n });\n });\n sizesDropdownContext.dropdown_options = sizesDropdownOptions;\n modalDropdowns.push(sizesDropdownContext);\n }\n // In the imggen view the dropdowns are at the bottom, so we need to make the dropdowns dropup instead of dropdown.\n // We only have one here of course, but in case we will have more options, we use a forEach.\n modalDropdowns.forEach(dropdownContext => {\n dropdownContext.dropup = true;\n });\n\n Object.assign(context, {\n modal_dropdowns: modalDropdowns\n });\n Object.assign(context, BasedataHandler.getBackAndGenerateButtonContext());\n return context;\n }\n}\n"],"names":["BaseHandler","this","loadImggenOptions","imggenOptions","sizes","setSize","size","getOptions","options","fetchedOptions","AiConfig","getPurposeOptions","JSON","parse","context","modal_headline","BasedataHandler","getTinyAiString","showIcon","tool","textareatype","placeholder","modalDropdowns","sizesOptions","getSizesOptions","Object","keys","length","sizesDropdownContext","dropdown_default","dropdown_default_value","dropdown_description","sizesDropdownOptions","forEach","option","push","optionValue","key","optionLabel","displayname","dropdown_options","dropdownContext","dropup","assign","modal_dropdowns","getBackAndGenerateButtonContext"],"mappings":";;;;;;;;oQA4B6BA,qFAET,kCAET,2CAGGC,KAAKC,oBACJD,KAAKE,cAAcC,MAG9BC,QAAQC,WACCA,KAAOA,KAGhBC,gBACsB,OAAdN,KAAKK,WACE,SAELE,QAAU,UACZP,KAAKK,OACLE,QAAO,MAAY,CAACP,KAAKK,OAEtBE,qCAIoB,OAAvBP,KAAKE,cAAwB,OACvBM,qBAAuBC,SAASC,kBAAkB,eACnDR,cAAgBS,KAAKC,MAAMJ,eAAeD,2CAK7CM,QAAU,CACZC,eAAgBC,gBAAgBC,gBAAgB,mBAChDC,UAAU,EACVC,KAAM,SACNC,aAAc,SACdC,YAAaL,gBAAgBC,gBAAgB,uBAG3CK,eAAiB,GAEjBC,mBAAqBtB,KAAKuB,qBACX,OAAjBD,cAAyBE,OAAOC,KAAKH,cAAcI,OAAS,EAAG,OACzDC,qBAAuB,CAC7BA,WAAkC,SAClCA,qBAAqBC,iBAAmBN,aAAa,GAAb,YACxCK,qBAAqBE,uBAAyBP,aAAa,GAAb,IAC9CK,qBAAqBG,qBAAuBf,gBAAgBC,gBAAgB,cACtEe,qBAAuB,GAC7BT,aAAaU,SAAQC,SACjBF,qBAAqBG,KAAK,CACtBC,YAAaF,OAAOG,IACpBC,YAAaJ,OAAOK,iBAG5BX,qBAAqBY,iBAAmBR,qBACxCV,eAAea,KAAKP,6BAIxBN,eAAeW,SAAQQ,kBACnBA,gBAAgBC,QAAS,KAG7BjB,OAAOkB,OAAO7B,QAAS,CACnB8B,gBAAiBtB,iBAErBG,OAAOkB,OAAO7B,QAASE,gBAAgB6B,mCAChC/B"} \ No newline at end of file +{"version":3,"file":"imggen.min.js","sources":["../../src/datahandler/imggen.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 \"./basedata\";\nimport BaseHandler from 'tiny_ai/datahandler/base';\n\n/**\n * Tiny AI data manager.\n *\n * @module tiny_ai/datahandler/imggen\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 imggenOptions = null;\n\n size = null;\n\n async getSizesOptions() {\n await this.loadImggenOptions();\n return this.imggenOptions.sizes;\n }\n\n setSize(size) {\n this.size = size;\n }\n\n getOptions() {\n if (this.size === null) {\n return {};\n }\n const options = {};\n if (this.size) {\n options.sizes = [this.size];\n }\n return options;\n }\n\n async loadImggenOptions() {\n if (this.imggenOptions === null) {\n const fetchedOptions = await AiConfig.getPurposeOptions('imggen');\n this.imggenOptions = JSON.parse(fetchedOptions.options);\n }\n }\n\n async getTemplateContext() {\n const context = {\n modalHeadline: BasedataHandler.getTinyAiString('imggen_headline'),\n showIcon: true,\n tool: 'imggen',\n textareatype: 'prompt',\n placeholder: BasedataHandler.getTinyAiString('imggen_placeholder'),\n };\n\n const modalDropdowns = [];\n\n const sizesOptions = await this.getSizesOptions();\n if (sizesOptions !== null && Object.keys(sizesOptions).length > 0) {\n const sizesDropdownContext = {};\n sizesDropdownContext.preference = 'sizes';\n sizesDropdownContext.dropdownDefault = sizesOptions[0].displayname;\n sizesDropdownContext.dropdownDefaultValue = sizesOptions[0].key;\n sizesDropdownContext.dropdownDescription = BasedataHandler.getTinyAiString('size');\n const sizesDropdownOptions = [];\n sizesOptions.forEach(option => {\n sizesDropdownOptions.push({\n optionValue: option.key,\n optionLabel: option.displayname,\n });\n });\n sizesDropdownContext.dropdownOptions = sizesDropdownOptions;\n modalDropdowns.push(sizesDropdownContext);\n }\n // In the imggen view the dropdowns are at the bottom, so we need to make the dropdowns dropup instead of dropdown.\n // We only have one here of course, but in case we will have more options, we use a forEach.\n modalDropdowns.forEach(dropdownContext => {\n dropdownContext.dropup = true;\n });\n\n Object.assign(context, {\n modalDropdowns: modalDropdowns\n });\n Object.assign(context, BasedataHandler.getBackAndGenerateButtonContext());\n return context;\n }\n}\n"],"names":["BaseHandler","this","loadImggenOptions","imggenOptions","sizes","setSize","size","getOptions","options","fetchedOptions","AiConfig","getPurposeOptions","JSON","parse","context","modalHeadline","BasedataHandler","getTinyAiString","showIcon","tool","textareatype","placeholder","modalDropdowns","sizesOptions","getSizesOptions","Object","keys","length","sizesDropdownContext","dropdownDefault","displayname","dropdownDefaultValue","key","dropdownDescription","sizesDropdownOptions","forEach","option","push","optionValue","optionLabel","dropdownOptions","dropdownContext","dropup","assign","getBackAndGenerateButtonContext"],"mappings":";;;;;;;;oQA4B6BA,qFAET,kCAET,2CAGGC,KAAKC,oBACJD,KAAKE,cAAcC,MAG9BC,QAAQC,WACCA,KAAOA,KAGhBC,gBACsB,OAAdN,KAAKK,WACE,SAELE,QAAU,UACZP,KAAKK,OACLE,QAAQJ,MAAQ,CAACH,KAAKK,OAEnBE,qCAIoB,OAAvBP,KAAKE,cAAwB,OACvBM,qBAAuBC,SAASC,kBAAkB,eACnDR,cAAgBS,KAAKC,MAAMJ,eAAeD,2CAK7CM,QAAU,CACZC,cAAeC,gBAAgBC,gBAAgB,mBAC/CC,UAAU,EACVC,KAAM,SACNC,aAAc,SACdC,YAAaL,gBAAgBC,gBAAgB,uBAG3CK,eAAiB,GAEjBC,mBAAqBtB,KAAKuB,qBACX,OAAjBD,cAAyBE,OAAOC,KAAKH,cAAcI,OAAS,EAAG,OACzDC,qBAAuB,CAC7BA,WAAkC,SAClCA,qBAAqBC,gBAAkBN,aAAa,GAAGO,YACvDF,qBAAqBG,qBAAuBR,aAAa,GAAGS,IAC5DJ,qBAAqBK,oBAAsBjB,gBAAgBC,gBAAgB,cACrEiB,qBAAuB,GAC7BX,aAAaY,SAAQC,SACjBF,qBAAqBG,KAAK,CACtBC,YAAaF,OAAOJ,IACpBO,YAAaH,OAAON,iBAG5BF,qBAAqBY,gBAAkBN,qBACvCZ,eAAee,KAAKT,6BAIxBN,eAAea,SAAQM,kBACnBA,gBAAgBC,QAAS,KAG7BjB,OAAOkB,OAAO7B,QAAS,CACnBQ,eAAgBA,iBAEpBG,OAAOkB,OAAO7B,QAASE,gBAAgB4B,mCAChC9B"} \ No newline at end of file diff --git a/amd/build/datahandler/itt.min.js b/amd/build/datahandler/itt.min.js index 3e117b9..7b83180 100644 --- a/amd/build/datahandler/itt.min.js +++ b/amd/build/datahandler/itt.min.js @@ -7,6 +7,6 @@ define("tiny_ai/datahandler/itt",["exports","local_ai_manager/config","tiny_ai/d * @author Philipp Memmel * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class _default extends _base.default{constructor(){super(...arguments),function(obj,key,value){key in obj?Object.defineProperty(obj,key,{value:value,enumerable:!0,configurable:!0,writable:!0}):obj[key]=value}(this,"ittOptions",null)}async loadIttOptions(){if(null===this.ittOptions){const fetchedOptions=await AiConfig.getPurposeOptions("itt");this.ittOptions=JSON.parse(fetchedOptions.options)}}async getAllowedMimetypes(){return await this.loadIttOptions(),this.ittOptions.allowedmimetypes}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})); +class _default extends _base.default{constructor(){super(...arguments),function(obj,key,value){key in obj?Object.defineProperty(obj,key,{value:value,enumerable:!0,configurable:!0,writable:!0}):obj[key]=value}(this,"ittOptions",null)}async loadIttOptions(){if(null===this.ittOptions){const fetchedOptions=await AiConfig.getPurposeOptions("itt");this.ittOptions=JSON.parse(fetchedOptions.options)}}async getAllowedMimetypes(){return await this.loadIttOptions(),this.ittOptions.allowedmimetypes}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={modalHeadline: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 3a45fdc..c2b2387 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 {getDatamanager} from 'tiny_ai/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 ittOptions = null;\n\n async loadIttOptions() {\n if (this.ittOptions === null) {\n const fetchedOptions = await AiConfig.getPurposeOptions('itt');\n this.ittOptions = JSON.parse(fetchedOptions.options);\n }\n }\n\n async getAllowedMimetypes() {\n await this.loadIttOptions();\n return this.ittOptions.allowedmimetypes;\n }\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","this","ittOptions","fetchedOptions","AiConfig","getPurposeOptions","JSON","parse","options","loadIttOptions","allowedmimetypes","getOptions","datamanager","uniqid","image","getCurrentFile","getPrompt","tool","BasedataHandler","getTinyAiString","context","modal_headline","showIcon","textareatype","placeholder","insertimagedescription","Object","assign","getShowPromptButtonContext","getBackAndGenerateButtonContext"],"mappings":";;;;;;;;;uBA6B6BA,4MAEZ,gCAGe,OAApBC,KAAKC,WAAqB,OACpBC,qBAAuBC,SAASC,kBAAkB,YACnDH,WAAaI,KAAKC,MAAMJ,eAAeK,mDAK1CP,KAAKQ,iBACJR,KAAKC,WAAWQ,iBAG3BC,mBACUH,QAAU,GACVI,aAAc,yBAAeX,KAAKY,eACxCL,QAAQM,MAAQF,YAAYG,iBACrBP,QAQXQ,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 +{"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 {getDatamanager} from 'tiny_ai/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 ittOptions = null;\n\n async loadIttOptions() {\n if (this.ittOptions === null) {\n const fetchedOptions = await AiConfig.getPurposeOptions('itt');\n this.ittOptions = JSON.parse(fetchedOptions.options);\n }\n }\n\n async getAllowedMimetypes() {\n await this.loadIttOptions();\n return this.ittOptions.allowedmimetypes;\n }\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 modalHeadline: 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","this","ittOptions","fetchedOptions","AiConfig","getPurposeOptions","JSON","parse","options","loadIttOptions","allowedmimetypes","getOptions","datamanager","uniqid","image","getCurrentFile","getPrompt","tool","BasedataHandler","getTinyAiString","context","modalHeadline","showIcon","textareatype","placeholder","insertimagedescription","Object","assign","getShowPromptButtonContext","getBackAndGenerateButtonContext"],"mappings":";;;;;;;;;uBA6B6BA,4MAEZ,gCAGe,OAApBC,KAAKC,WAAqB,OACpBC,qBAAuBC,SAASC,kBAAkB,YACnDH,WAAaI,KAAKC,MAAMJ,eAAeK,mDAK1CP,KAAKQ,iBACJR,KAAKC,WAAWQ,iBAG3BC,mBACUH,QAAU,GACVI,aAAc,yBAAeX,KAAKY,eACxCL,QAAQM,MAAQF,YAAYG,iBACrBP,QAQXQ,UAAUC,aACCC,gBAAgBC,gBAAgBF,KAAO,wCAQzBA,YACfG,QAAU,CACZC,cAAeH,gBAAgBC,gBAAgBF,KAAO,aACtDK,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/optimize.min.js b/amd/build/datahandler/optimize.min.js index 67f1d91..6f468cd 100644 --- a/amd/build/datahandler/optimize.min.js +++ b/amd/build/datahandler/optimize.min.js @@ -7,6 +7,6 @@ define("tiny_ai/datahandler/optimize",["exports","tiny_ai/datahandler/basedata", * @author Philipp Memmel * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class _default extends _base.default{constructor(){super(...arguments),function(obj,key,value){key in obj?Object.defineProperty(obj,key,{value:value,enumerable:!0,configurable:!0,writable:!0}):obj[key]=value}(this,"getTemplateContext",(()=>{const context={modal_headline:BasedataHandler.getTinyAiString("reworkprompt"),showIcon:!0,textareatype:"prompt"};return Object.assign(context,BasedataHandler.getBackAndGenerateButtonContext()),context}))}}return _exports.default=_default,_exports.default})); +class _default extends _base.default{constructor(){super(...arguments),function(obj,key,value){key in obj?Object.defineProperty(obj,key,{value:value,enumerable:!0,configurable:!0,writable:!0}):obj[key]=value}(this,"getTemplateContext",(()=>{const context={modalHeadline:BasedataHandler.getTinyAiString("reworkprompt"),showIcon:!0,textareatype:"prompt"};return Object.assign(context,BasedataHandler.getBackAndGenerateButtonContext()),context}))}}return _exports.default=_default,_exports.default})); //# sourceMappingURL=optimize.min.js.map \ No newline at end of file diff --git a/amd/build/datahandler/optimize.min.js.map b/amd/build/datahandler/optimize.min.js.map index 6f6b9a0..602c346 100644 --- a/amd/build/datahandler/optimize.min.js.map +++ b/amd/build/datahandler/optimize.min.js.map @@ -1 +1 @@ -{"version":3,"file":"optimize.min.js","sources":["../../src/datahandler/optimize.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 BasedataHandler from 'tiny_ai/datahandler/basedata';\nimport BaseHandler from 'tiny_ai/datahandler/base';\n\n/**\n * Tiny AI data handler for optimize prompt page.\n *\n * @module tiny_ai/datahandler/optimize\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 getTemplateContext = () => {\n const context = {\n modal_headline: BasedataHandler.getTinyAiString('reworkprompt'),\n showIcon: true,\n textareatype: 'prompt'\n };\n Object.assign(context, BasedataHandler.getBackAndGenerateButtonContext());\n return context;\n };\n}\n\n\n"],"names":["BaseHandler","context","modal_headline","BasedataHandler","getTinyAiString","showIcon","textareatype","Object","assign","getBackAndGenerateButtonContext"],"mappings":";;;;;;;;;uBA2B6BA,qNAEJ,WACXC,QAAU,CACZC,eAAgBC,gBAAgBC,gBAAgB,gBAChDC,UAAU,EACVC,aAAc,iBAElBC,OAAOC,OAAOP,QAASE,gBAAgBM,mCAChCR"} \ No newline at end of file +{"version":3,"file":"optimize.min.js","sources":["../../src/datahandler/optimize.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 BasedataHandler from 'tiny_ai/datahandler/basedata';\nimport BaseHandler from 'tiny_ai/datahandler/base';\n\n/**\n * Tiny AI data handler for optimize prompt page.\n *\n * @module tiny_ai/datahandler/optimize\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 getTemplateContext = () => {\n const context = {\n modalHeadline: BasedataHandler.getTinyAiString('reworkprompt'),\n showIcon: true,\n textareatype: 'prompt'\n };\n Object.assign(context, BasedataHandler.getBackAndGenerateButtonContext());\n return context;\n };\n}\n\n\n"],"names":["BaseHandler","context","modalHeadline","BasedataHandler","getTinyAiString","showIcon","textareatype","Object","assign","getBackAndGenerateButtonContext"],"mappings":";;;;;;;;;uBA2B6BA,qNAEJ,WACXC,QAAU,CACZC,cAAeC,gBAAgBC,gBAAgB,gBAC/CC,UAAU,EACVC,aAAc,iBAElBC,OAAOC,OAAOP,QAASE,gBAAgBM,mCAChCR"} \ No newline at end of file diff --git a/amd/build/datahandler/start.min.js b/amd/build/datahandler/start.min.js index fb7b5d7..b2372db 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"].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})); + */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",new Map)}async init(){this.aiConfig=await(0,_config2.getAiConfig)();const stringRequest=this.stringKeys.map((key=>({key:key,component:"local_ai_manager"}))),fetchedStrings=await(0,_str.getStrings)(stringRequest);for(let i=0;ipurpose.purpose===toolPurpose))[0]}isTinyAiDisabled(){return this.aiConfig.tenantenabled?this.aiConfig.userconfirmed?this.aiConfig.userlocked?this.strings.get("error_userlocked"):"":this.strings.get("combinedusernotconfirmederror"):this.strings.get("error_tenantdisabled")}isToolDisabled(tool,mode){if(this.isTinyAiDisabled())return this.isTinyAiDisabled();const purposeInfo=this.getPurposeConfig(tool);return purposeInfo.isconfigured?purposeInfo.limitreached?this.strings.get("error_limitreached"):mode===_constants.constants.modalModes.selection?["audiogen","imggen"].includes(tool)?this.strings.get("error_unavailable_noselection"):"":mode===_constants.constants.modalModes.general&&["summarize","translate","describe","tts"].includes(tool)?this.strings.get("error_unavailable_selection"):"":this.strings.get("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,modalHeadline:BasedataHandler.getTinyAiString("mainselection_heading"),action:"loadfreeprompt",modalButtons: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 8f1e13a..ce940c7 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']\n .includes(tool) ? this.strings.error_unavailable_noselection : '';\n } else if (mode === constants.modalModes.general) {\n return ['summarize', 'translate', 'describe', 'tts']\n .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,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AgB,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 +{"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 = new Map();\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 const fetchedStrings = await getStrings(stringRequest);\n for (let i = 0; i < this.stringKeys.length; i++) {\n this.strings.set(this.stringKeys[i], fetchedStrings[i]);\n }\n const tinyNotAvailableString = await getString('error_tiny_ai_notavailable', 'tiny_ai');\n this.strings.set('error_editor_notavailable', tinyNotAvailableString);\n const confirmLink = document.createElement('a');\n confirmLink.href = `${config.wwwroot}/local/ai_manager/confirm_ai_usage.php`;\n confirmLink.innerText = this.strings.get('error_pleaseconfirm');\n confirmLink.target = '_blank';\n this.strings.set('combinedusernotconfirmederror', this.strings.get('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.get('error_tenantdisabled');\n }\n if (!this.aiConfig.userconfirmed) {\n return this.strings.get('combinedusernotconfirmederror');\n }\n if (this.aiConfig.userlocked) {\n return this.strings.get('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.get('error_purposenotconfigured');\n }\n if (purposeInfo.limitreached) {\n return this.strings.get('error_limitreached');\n }\n\n if (mode === constants.modalModes.selection) {\n return ['audiogen', 'imggen']\n .includes(tool) ? this.strings.get('error_unavailable_noselection') : '';\n } else if (mode === constants.modalModes.general) {\n return ['summarize', 'translate', 'describe', 'tts']\n .includes(tool) ? this.strings.get('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 modalHeadline: BasedataHandler.getTinyAiString('mainselection_heading'),\n action: 'loadfreeprompt',\n modalButtons: toolButtons,\n freeprompthidden: true\n };\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\n if (this.isToolDisabled('freeprompt', mode)) {\n templateContext.input[0].disabled = true;\n }\n return templateContext;\n }\n}\n"],"names":["BaseHandler","Map","aiConfig","stringRequest","this","stringKeys","map","key","component","fetchedStrings","i","length","strings","set","tinyNotAvailableString","confirmLink","document","createElement","href","config","wwwroot","innerText","get","target","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","tooltip","action","iconstyle","sort","a","b","templateContext","showIcon","modalHeadline","modalButtons","freeprompthidden","Object","assign","getInputContext","input","hasError","errorMessage"],"mappings":";;;;;;;;gQAiC6BA,kFAEZ,CACT,qBACA,sBACA,6BACA,uBACA,gCACA,8BACA,mBACA,2DAGO,qCACD,IAAIC,uBAGLC,eAAiB,gCAGhBC,cAAgBC,KAAKC,WAAWC,KAAIC,MAC/B,CAACA,IAAAA,IAAKC,UAAW,uBAGtBC,qBAAuB,mBAAWN,mBACnC,IAAIO,EAAI,EAAGA,EAAIN,KAAKC,WAAWM,OAAQD,SACnCE,QAAQC,IAAIT,KAAKC,WAAWK,GAAID,eAAeC,UAElDI,6BAA+B,kBAAU,6BAA8B,gBACxEF,QAAQC,IAAI,4BAA6BC,8BACxCC,YAAcC,SAASC,cAAc,KAC3CF,YAAYG,eAAUC,OAAOC,kDAC7BL,YAAYM,UAAYjB,KAAKQ,QAAQU,IAAI,u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G,KAAK,CACbC,SAAU,SACV7B,KAAM8B,gBAAgBC,gBAAgB,mBACtCO,UAAW,QACXJ,SAAU,QACVC,SAAUzD,KAAKkC,eAAe,SAAUC,MAAM5B,OAAS,EACvDmD,SAAS,wBAAc1D,KAAKkC,eAAe,SAAUC,OACrDwB,OAAQ,eAGX3D,KAAK2C,aAAa,gBACnBI,YAAYG,KAAK,CACbC,SAAU,cACV7B,KAAM8B,gBAAgBC,gBAAgB,wBACtCO,UAAW,QACXJ,SAAU,aACVC,SAAUzD,KAAKkC,eAAe,cAAeC,MAAM5B,OAAS,EAC5DmD,SAAS,wBAAc1D,KAAKkC,eAAe,cAAeC,OAC1DwB,OAAQ,oBAGX3D,KAAK2C,aAAa,gBACnBI,YAAYG,KAAK,CACbC,SAAU,cACV7B,KAAM8B,gBAAgBC,gBAAgB,wBACtCO,UAAW,QACXJ,SAAU,YACVC,SAAUzD,KAAKkC,eAAe,cAAeC,MAAM5B,OAAS,EAC5DmD,SAAS,wBAAc1D,KAAKkC,eAAe,cAAeC,OAC1DwB,OAAQ,oBAKhBZ,YAAYc,MAAK,CAACC,EAAGC,IACbD,EAAEL,WAAaM,EAAEN,SACV,EACAM,EAAEN,WAAaK,EAAEL,UAChB,EAED,UAITO,gBAAkB,CACpBC,UAAU,EACVC,cAAed,gBAAgBC,gBAAgB,yBAC/CM,OAAQ,iBACRQ,aAAcpB,YACdqB,kBAAkB,UAGtBC,OAAOC,OAAON,gBAAiBZ,gBAAgBmB,mBAC3CvE,KAAK8B,qBACLkC,gBAAgBQ,MAAM,GAAGf,UAAW,EACpCO,gBAAgBQ,MAAM,GAAGC,UAAW,EACpCT,gBAAgBQ,MAAM,GAAGE,aAAe1E,KAAK8B,oBAG7C9B,KAAKkC,eAAe,aAAcC,QAClC6B,gBAAgBQ,MAAM,GAAGf,UAAW,GAEjCO"} \ No newline at end of file diff --git a/amd/build/datahandler/summarize.min.js b/amd/build/datahandler/summarize.min.js index e861aaf..e6a1f08 100644 --- a/amd/build/datahandler/summarize.min.js +++ b/amd/build/datahandler/summarize.min.js @@ -6,6 +6,6 @@ define("tiny_ai/datahandler/summarize",["exports","tiny_ai/datahandler/basedata" * @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),_base=(obj=_base)&&obj.__esModule?obj:{default:obj};class _default extends _base.default{constructor(){super(...arguments),_defineProperty(this,"currentTool",null),_defineProperty(this,"languageType",null),_defineProperty(this,"maxWordCount",0)}getLanguageTypeOptions(){return{nospeciallanguage:BasedataHandler.getTinyAiString("keeplanguagetype"),simplelanguage:BasedataHandler.getTinyAiString("simplelanguage"),technicallanguage:BasedataHandler.getTinyAiString("technicallanguage")}}getMaxWordCountOptions(){return{0:BasedataHandler.getTinyAiString("nomaxwordcount"),10:"10",20:"20",50:"50",100:"100",200:"200",300:"300"}}setMaxWordCount(maxWordCount){this.maxWordCount=maxWordCount}setLanguageType(languageType){this.languageType=languageType}async getPrompt(selectionText){let prompt="";return"summarize"===this.currentTool?prompt+=BasedataHandler.getTinyAiString("summarize_baseprompt"):"describe"===this.currentTool&&(prompt+=BasedataHandler.getTinyAiString("describe_baseprompt")),0===parseInt(this.maxWordCount)&&"nospeciallanguage"===this.languageType?prompt+": "+selectionText:(prompt+=". ",0!==parseInt(this.maxWordCount)&&(prompt+=" ",prompt+=await(0,_str.getString)("maxwordcount_prompt","tiny_ai",this.maxWordCount),prompt+="."),"nospeciallanguage"!==this.languageType&&(prompt+=" ",prompt+=await(0,_str.getString)("languagetype_prompt","tiny_ai",this.getLanguageTypeOptions()[this.languageType]),prompt+="."),prompt+="\n",prompt+=BasedataHandler.getTinyAiString("texttouse")+": "+selectionText,prompt)}setTool(currentTool){this.currentTool=currentTool}getTemplateContext(tool){const context={modal_headline:BasedataHandler.getTinyAiString(tool+"_headline"),showIcon:!0,tool:tool};Object.assign(context,BasedataHandler.getShowPromptButtonContext()),Object.assign(context,BasedataHandler.getBackAndGenerateButtonContext());const maxWordCountDropdownContext={preference:"maxWordCount"};maxWordCountDropdownContext.dropdown_default=Object.values(this.getMaxWordCountOptions())[0],maxWordCountDropdownContext.dropdown_default_value=Object.keys(this.getMaxWordCountOptions())[0],maxWordCountDropdownContext.dropdown_description="MAXIMALE WORTANZAHL";const maxWordCountDropdownOptions=[];for(const[key,value]of Object.entries(this.getMaxWordCountOptions()))maxWordCountDropdownOptions.push({optionValue:key,optionLabel:value});delete maxWordCountDropdownOptions[Object.keys(this.getLanguageTypeOptions())[0]],maxWordCountDropdownContext.dropdown_options=maxWordCountDropdownOptions;const languageTypeDropdownContext={preference:"languageType"};languageTypeDropdownContext.dropdown_default=Object.values(this.getLanguageTypeOptions())[0],languageTypeDropdownContext.dropdown_default_value=Object.keys(this.getLanguageTypeOptions())[0],languageTypeDropdownContext.dropdown_description="ART DER SPRACHE";const languageTypeDropdownOptions=[];for(const[key,value]of Object.entries(this.getLanguageTypeOptions()))languageTypeDropdownOptions.push({optionValue:key,optionLabel:value});return delete languageTypeDropdownOptions[Object.keys(this.getLanguageTypeOptions)[0]],languageTypeDropdownContext.dropdown_options=languageTypeDropdownOptions,Object.assign(context,{modal_dropdowns:[maxWordCountDropdownContext,languageTypeDropdownContext]}),context}}return _exports.default=_default,_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),_base=(obj=_base)&&obj.__esModule?obj:{default:obj};class _default extends _base.default{constructor(){super(...arguments),_defineProperty(this,"currentTool",null),_defineProperty(this,"languageType",null),_defineProperty(this,"maxWordCount",0)}getLanguageTypeOptions(){return{nospeciallanguage:BasedataHandler.getTinyAiString("keeplanguagetype"),simplelanguage:BasedataHandler.getTinyAiString("simplelanguage"),technicallanguage:BasedataHandler.getTinyAiString("technicallanguage")}}getMaxWordCountOptions(){return{0:BasedataHandler.getTinyAiString("nomaxwordcount"),10:"10",20:"20",50:"50",100:"100",200:"200",300:"300"}}setMaxWordCount(maxWordCount){this.maxWordCount=maxWordCount}setLanguageType(languageType){this.languageType=languageType}async getPrompt(selectionText){let prompt="";return"summarize"===this.currentTool?prompt+=BasedataHandler.getTinyAiString("summarize_baseprompt"):"describe"===this.currentTool&&(prompt+=BasedataHandler.getTinyAiString("describe_baseprompt")),0===parseInt(this.maxWordCount)&&"nospeciallanguage"===this.languageType?prompt+": "+selectionText:(prompt+=". ",0!==parseInt(this.maxWordCount)&&(prompt+=" ",prompt+=await(0,_str.getString)("maxwordcount_prompt","tiny_ai",this.maxWordCount),prompt+="."),"nospeciallanguage"!==this.languageType&&(prompt+=" ",prompt+=await(0,_str.getString)("languagetype_prompt","tiny_ai",this.getLanguageTypeOptions()[this.languageType]),prompt+="."),prompt+="\n",prompt+=BasedataHandler.getTinyAiString("texttouse")+": "+selectionText,prompt)}setTool(currentTool){this.currentTool=currentTool}getTemplateContext(tool){const context={modalHeadline:BasedataHandler.getTinyAiString(tool+"_headline"),showIcon:!0,tool:tool};Object.assign(context,BasedataHandler.getShowPromptButtonContext()),Object.assign(context,BasedataHandler.getBackAndGenerateButtonContext());const maxWordCountDropdownContext={preference:"maxWordCount"};maxWordCountDropdownContext.dropdownDefault=Object.values(this.getMaxWordCountOptions())[0],maxWordCountDropdownContext.dropdownDefaultValue=Object.keys(this.getMaxWordCountOptions())[0],maxWordCountDropdownContext.dropdownDescription="MAXIMALE WORTANZAHL";const maxWordCountDropdownOptions=[];for(const[key,value]of Object.entries(this.getMaxWordCountOptions()))maxWordCountDropdownOptions.push({optionValue:key,optionLabel:value});delete maxWordCountDropdownOptions[Object.keys(this.getLanguageTypeOptions())[0]],maxWordCountDropdownContext.dropdownOptions=maxWordCountDropdownOptions;const languageTypeDropdownContext={preference:"languageType"};languageTypeDropdownContext.dropdownDefault=Object.values(this.getLanguageTypeOptions())[0],languageTypeDropdownContext.dropdownDefaultValue=Object.keys(this.getLanguageTypeOptions())[0],languageTypeDropdownContext.dropdownDescription="ART DER SPRACHE";const languageTypeDropdownOptions=[];for(const[key,value]of Object.entries(this.getLanguageTypeOptions()))languageTypeDropdownOptions.push({optionValue:key,optionLabel:value});return delete languageTypeDropdownOptions[Object.keys(this.getLanguageTypeOptions)[0]],languageTypeDropdownContext.dropdownOptions=languageTypeDropdownOptions,Object.assign(context,{modalDropdowns:[maxWordCountDropdownContext,languageTypeDropdownContext]}),context}}return _exports.default=_default,_exports.default})); //# sourceMappingURL=summarize.min.js.map \ No newline at end of file diff --git a/amd/build/datahandler/summarize.min.js.map b/amd/build/datahandler/summarize.min.js.map index f853fa5..aa94b89 100644 --- a/amd/build/datahandler/summarize.min.js.map +++ b/amd/build/datahandler/summarize.min.js.map @@ -1 +1 @@ -{"version":3,"file":"summarize.min.js","sources":["../../src/datahandler/summarize.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 BasedataHandler from 'tiny_ai/datahandler/basedata';\nimport BaseHandler from 'tiny_ai/datahandler/base';\nimport {getString} from 'core/str';\n\n/**\n * Tiny AI data manager.\n *\n * @module tiny_ai/datahandler/summarize\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 currentTool = null;\n\n getLanguageTypeOptions() {\n return {\n nospeciallanguage: BasedataHandler.getTinyAiString('keeplanguagetype'),\n simplelanguage: BasedataHandler.getTinyAiString('simplelanguage'),\n technicallanguage: BasedataHandler.getTinyAiString('technicallanguage'),\n };\n }\n\n getMaxWordCountOptions() {\n return {\n 0: BasedataHandler.getTinyAiString('nomaxwordcount'),\n 10: '10',\n 20: '20',\n 50: '50',\n 100: '100',\n 200: '200',\n 300: '300'\n };\n }\n\n languageType = null;\n maxWordCount = 0;\n\n setMaxWordCount(maxWordCount) {\n this.maxWordCount = maxWordCount;\n }\n\n setLanguageType(languageType) {\n this.languageType = languageType;\n }\n\n async getPrompt(selectionText) {\n let prompt = '';\n if (this.currentTool === 'summarize') {\n prompt += BasedataHandler.getTinyAiString('summarize_baseprompt');\n } else if (this.currentTool === 'describe') {\n prompt += BasedataHandler.getTinyAiString('describe_baseprompt');\n }\n if (parseInt(this.maxWordCount) === 0 && this.languageType === 'nospeciallanguage') {\n return prompt + ': ' + selectionText;\n } else {\n prompt += '. ';\n if (parseInt(this.maxWordCount) !== 0) {\n prompt += ' ';\n prompt += await getString('maxwordcount_prompt', 'tiny_ai', this.maxWordCount);\n prompt += '.';\n }\n if (this.languageType !== 'nospeciallanguage') {\n prompt += ' ';\n prompt += await getString('languagetype_prompt', 'tiny_ai', this.getLanguageTypeOptions()[this.languageType]);\n prompt += '.';\n }\n prompt += '\\n';\n prompt += BasedataHandler.getTinyAiString('texttouse') + ': ' + selectionText;\n return prompt;\n }\n }\n\n setTool(currentTool) {\n this.currentTool = currentTool;\n }\n\n /**\n * Return the template context.\n *\n * @param {string} tool the tool to generate the context for, can be 'summarize' or 'describe'\n */\n getTemplateContext(tool) {\n const\n context = {\n modal_headline: BasedataHandler.getTinyAiString(tool + '_headline'),\n showIcon: true,\n tool: tool,\n };\n Object\n .assign(context, BasedataHandler\n\n .getShowPromptButtonContext()\n )\n ;\n Object\n .assign(context, BasedataHandler\n\n .getBackAndGenerateButtonContext()\n )\n ;\n\n const maxWordCountDropdownContext = {};\n maxWordCountDropdownContext.preference = 'maxWordCount';\n maxWordCountDropdownContext.dropdown_default = Object.values(this.getMaxWordCountOptions())[0];\n maxWordCountDropdownContext.dropdown_default_value = Object.keys(this.getMaxWordCountOptions())[0];\n maxWordCountDropdownContext.dropdown_description = 'MAXIMALE WORTANZAHL';\n const maxWordCountDropdownOptions = [];\n\n for (const [key, value] of Object.entries(this.getMaxWordCountOptions())) {\n maxWordCountDropdownOptions.push({\n optionValue: key,\n optionLabel: value,\n });\n }\n\n delete maxWordCountDropdownOptions[Object.keys(this.getLanguageTypeOptions())[0]];\n maxWordCountDropdownContext.dropdown_options = maxWordCountDropdownOptions;\n\n const languageTypeDropdownContext = {};\n languageTypeDropdownContext.preference = 'languageType';\n languageTypeDropdownContext.dropdown_default = Object.values(this.getLanguageTypeOptions())[0];\n languageTypeDropdownContext.dropdown_default_value = Object.keys(this.getLanguageTypeOptions())[0];\n languageTypeDropdownContext.dropdown_description = 'ART DER SPRACHE';\n const languageTypeDropdownOptions = [];\n for (const [key, value] of Object.entries(this.getLanguageTypeOptions())) {\n languageTypeDropdownOptions.push({\n optionValue: key,\n optionLabel: value,\n });\n }\n delete languageTypeDropdownOptions[Object.keys(this.getLanguageTypeOptions)[0]];\n languageTypeDropdownContext.dropdown_options = languageTypeDropdownOptions;\n\n\n Object.assign(context, {\n modal_dropdowns: [\n maxWordCountDropdownContext,\n languageTypeDropdownContext,\n ]\n });\n\n return context;\n }\n}\n"],"names":["BaseHandler","getLanguageTypeOptions","nospeciallanguage","BasedataHandler","getTinyAiString","simplelanguage","technicallanguage","getMaxWordCountOptions","setMaxWordCount","maxWordCount","setLanguageType","languageType","selectionText","prompt","this","currentTool","parseInt","setTool","getTemplateContext","tool","context","modal_headline","showIcon","Object","assign","getShowPromptButtonContext","getBackAndGenerateButtonContext","maxWordCountDropdownContext","dropdown_default","values","dropdown_default_value","keys","dropdown_description","maxWordCountDropdownOptions","key","value","entries","push","optionValue","optionLabel","dropdown_options","languageTypeDropdownContext","languageTypeDropdownOptions","modal_dropdowns"],"mappings":";;;;;;;;80BA4B6BA,mFAEX,0CAsBC,0CACA,GArBfC,+BACW,CACHC,kBAAmBC,gBAAgBC,gBAAgB,oBACnDC,eAAgBF,gBAAgBC,gBAAgB,kBAChDE,kBAAmBH,gBAAgBC,gBAAgB,sBAI3DG,+BACW,GACAJ,gBAAgBC,gBAAgB,qBAC/B,QACA,QACA,SACC,UACA,UACA,OAObI,gBAAgBC,mBACPA,aAAeA,aAGxBC,gBAAgBC,mBACPA,aAAeA,6BAGRC,mBACRC,OAAS,SACY,cAArBC,KAAKC,YACLF,QAAUV,gBAAgBC,gBAAgB,wBACd,aAArBU,KAAKC,cACZF,QAAUV,gBAAgBC,gBAAgB,wBAEV,IAAhCY,SAASF,KAAKL,eAA6C,sBAAtBK,KAAKH,aACnCE,OAAS,KAAOD,eAEvBC,QAAU,KAC0B,IAAhCG,SAASF,KAAKL,gBACdI,QAAU,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AAOJ,QAAS,CACnBuB,gBAAiB,CACbhB,4BACAc,+BAIDrB"} \ No newline at end of file +{"version":3,"file":"summarize.min.js","sources":["../../src/datahandler/summarize.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 BasedataHandler from 'tiny_ai/datahandler/basedata';\nimport BaseHandler from 'tiny_ai/datahandler/base';\nimport {getString} from 'core/str';\n\n/**\n * Tiny AI data manager.\n *\n * @module tiny_ai/datahandler/summarize\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 currentTool = null;\n\n getLanguageTypeOptions() {\n return {\n nospeciallanguage: BasedataHandler.getTinyAiString('keeplanguagetype'),\n simplelanguage: BasedataHandler.getTinyAiString('simplelanguage'),\n technicallanguage: BasedataHandler.getTinyAiString('technicallanguage'),\n };\n }\n\n getMaxWordCountOptions() {\n return {\n '0': BasedataHandler.getTinyAiString('nomaxwordcount'),\n '10': '10',\n '20': '20',\n '50': '50',\n '100': '100',\n '200': '200',\n '300': '300'\n };\n }\n\n languageType = null;\n maxWordCount = 0;\n\n setMaxWordCount(maxWordCount) {\n this.maxWordCount = maxWordCount;\n }\n\n setLanguageType(languageType) {\n this.languageType = languageType;\n }\n\n async getPrompt(selectionText) {\n let prompt = '';\n if (this.currentTool === 'summarize') {\n prompt += BasedataHandler.getTinyAiString('summarize_baseprompt');\n } else if (this.currentTool === 'describe') {\n prompt += BasedataHandler.getTinyAiString('describe_baseprompt');\n }\n if (parseInt(this.maxWordCount) === 0 && this.languageType === 'nospeciallanguage') {\n return prompt + ': ' + selectionText;\n } else {\n prompt += '. ';\n if (parseInt(this.maxWordCount) !== 0) {\n prompt += ' ';\n prompt += await getString('maxwordcount_prompt', 'tiny_ai', this.maxWordCount);\n prompt += '.';\n }\n if (this.languageType !== 'nospeciallanguage') {\n prompt += ' ';\n prompt += await getString('languagetype_prompt', 'tiny_ai', this.getLanguageTypeOptions()[this.languageType]);\n prompt += '.';\n }\n prompt += '\\n';\n prompt += BasedataHandler.getTinyAiString('texttouse') + ': ' + selectionText;\n return prompt;\n }\n }\n\n setTool(currentTool) {\n this.currentTool = currentTool;\n }\n\n /**\n * Return the template context.\n *\n * @param {string} tool the tool to generate the context for, can be 'summarize' or 'describe'\n */\n getTemplateContext(tool) {\n const\n context = {\n modalHeadline: BasedataHandler.getTinyAiString(tool + '_headline'),\n showIcon: true,\n tool: tool,\n };\n Object\n .assign(context, BasedataHandler\n\n .getShowPromptButtonContext()\n )\n ;\n Object\n .assign(context, BasedataHandler\n\n .getBackAndGenerateButtonContext()\n )\n ;\n\n const maxWordCountDropdownContext = {};\n maxWordCountDropdownContext.preference = 'maxWordCount';\n maxWordCountDropdownContext.dropdownDefault = Object.values(this.getMaxWordCountOptions())[0];\n maxWordCountDropdownContext.dropdownDefaultValue = Object.keys(this.getMaxWordCountOptions())[0];\n maxWordCountDropdownContext.dropdownDescription = 'MAXIMALE WORTANZAHL';\n const maxWordCountDropdownOptions = [];\n\n for (const [key, value] of Object.entries(this.getMaxWordCountOptions())) {\n maxWordCountDropdownOptions.push({\n optionValue: key,\n optionLabel: value,\n });\n }\n\n delete maxWordCountDropdownOptions[Object.keys(this.getLanguageTypeOptions())[0]];\n maxWordCountDropdownContext.dropdownOptions = maxWordCountDropdownOptions;\n\n const languageTypeDropdownContext = {};\n languageTypeDropdownContext.preference = 'languageType';\n languageTypeDropdownContext.dropdownDefault = Object.values(this.getLanguageTypeOptions())[0];\n languageTypeDropdownContext.dropdownDefaultValue = Object.keys(this.getLanguageTypeOptions())[0];\n languageTypeDropdownContext.dropdownDescription = 'ART DER SPRACHE';\n const languageTypeDropdownOptions = [];\n for (const [key, value] of Object.entries(this.getLanguageTypeOptions())) {\n languageTypeDropdownOptions.push({\n optionValue: key,\n optionLabel: value,\n });\n }\n delete languageTypeDropdownOptions[Object.keys(this.getLanguageTypeOptions)[0]];\n languageTypeDropdownContext.dropdownOptions = languageTypeDropdownOptions;\n\n\n Object.assign(context, {\n modalDropdowns: [\n maxWordCountDropdownContext,\n languageTypeDropdownContext,\n ]\n });\n\n return context;\n }\n}\n"],"names":["BaseHandler","getLanguageTypeOptions","nospeciallanguage","BasedataHandler","getTinyAiString","simplelanguage","technicallanguage","getMaxWordCountOptions","setMaxWordCount","maxWordCount","setLanguageType","languageType","selectionText","prompt","this","currentTool","parseInt","setTool","getTemplateContext","tool","context","modalHeadline","showIcon","Object","assign","getShowPromptButtonContext","getBackAndGenerateButtonContext","maxWordCountDropdownContext","dropdownDefault","values","dropdownDefaultValue","keys","dropdownDescription","maxWordCountDropdownOptions","key","value","entries","push","optionValue","optionLabel","dropdownOptions","languageTypeDropdownContext","languageTypeDropdownOptions","modalDropdowns"],"mappings":";;;;;;;;80BA4B6BA,mFAEX,0CAsBC,0CACA,GArBfC,+BACW,CACHC,kBAAmBC,gBAAgBC,gBAAgB,oBACnDC,eAAgBF,gBAAgBC,gBAAgB,kBAChDE,kBAAmBH,gBAAgBC,gBAAgB,sBAI3DG,+BACW,GACEJ,gBAAgBC,gBAAgB,qBAC/B,QACA,QACA,SACC,UACA,UACA,OAOfI,gBAAgBC,mBACPA,aAAeA,aAGxBC,gBAAgBC,mBACPA,aAAeA,6BAGRC,mBACRC,OAAS,SACY,cAArBC,KAAKC,YACLF,QAAUV,gBAAgBC,gBAAgB,wBACd,aAArBU,KAAKC,cACZF,QAAUV,gBAAgBC,gBAAgB,wBAEV,IAAhCY,SAASF,KAAKL,eAA6C,sBAAtBK,KAAKH,aAC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,KAAKjB,KAAKb,wBAAwB,IAC5EwC,4BAA4BD,gBAAkBE,4BAG9CnB,OAAOC,OAAOJ,QAAS,CACnBuB,eAAgB,CACZhB,4BACAc,+BAIDrB"} \ No newline at end of file diff --git a/amd/build/datahandler/translate.min.js b/amd/build/datahandler/translate.min.js index 2581c8e..eaff7db 100644 --- a/amd/build/datahandler/translate.min.js +++ b/amd/build/datahandler/translate.min.js @@ -6,6 +6,6 @@ define("tiny_ai/datahandler/translate",["exports","tiny_ai/datahandler/basedata" * @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),_base=_interopRequireDefault(_base),_config=_interopRequireDefault(_config);class _default extends _base.default{constructor(uniqid){super(uniqid),_defineProperty(this,"targetLanguageCodes",["de","fr","it","es","cs","zh","ru","uk","el","la","tr","ro","pl","bg","ar","sq","bs","sr","hr","ku","fa","ps","sk","hu"]),_defineProperty(this,"targetLanguageOptions",[]),_defineProperty(this,"targetLanguage",null),this.initTargetLanguages()}setTargetLanguage(targetLanguage){this.targetLanguage=targetLanguage}async getPrompt(selectionText){const selectedLanguageEntry=this.targetLanguageOptions.filter((languageEntry=>languageEntry.key===this.targetLanguage))[0];let prompt=await(0,_str.getString)("translate_baseprompt","tiny_ai",selectedLanguageEntry.value);return prompt+=": "+selectionText,prompt}getTemplateContext(){const translateHandler=(0,_utils.getTranslateHandler)(this.uniqid),context={modal_headline:BasedataHandler.getTinyAiString("translate_headline"),showIcon:!0,tool:"translate"},targetLanguageDropdownContext={preference:"targetLanguage"};targetLanguageDropdownContext.dropdown_default=translateHandler.targetLanguageOptions[0].value,targetLanguageDropdownContext.dropdown_default_value=translateHandler.targetLanguageOptions[0].key,targetLanguageDropdownContext.dropdown_description=BasedataHandler.getTinyAiString("targetlanguage");const targetLanguageDropdownOptions=[];return translateHandler.targetLanguageOptions.forEach((languageEntry=>{targetLanguageDropdownOptions.push({optionValue:languageEntry.key,optionLabel:languageEntry.value})})),targetLanguageDropdownContext.dropdown_options=targetLanguageDropdownOptions,Object.assign(context,{modal_dropdowns:[targetLanguageDropdownContext]}),Object.assign(context,BasedataHandler.getShowPromptButtonContext()),Object.assign(context,BasedataHandler.getBackAndGenerateButtonContext()),context}initTargetLanguages(){const currentUserLanguage=_config.default.language.substring(0,2),languageNameInCurrentUserLanguage=new Intl.DisplayNames([currentUserLanguage],{type:"language"}),firstLanguages=[{key:"en",value:languageNameInCurrentUserLanguage.of("en")}];if("en"!==currentUserLanguage&&this.targetLanguageCodes.includes(currentUserLanguage)){firstLanguages.push({key:currentUserLanguage,value:languageNameInCurrentUserLanguage.of(currentUserLanguage)});const index=this.targetLanguageCodes.indexOf(currentUserLanguage);this.targetLanguageCodes.splice(index,1)}this.targetLanguageCodes.forEach((languageCode=>{this.targetLanguageOptions[languageCode]=languageNameInCurrentUserLanguage.of(languageCode)}));const sortedLanguages=Object.entries(this.targetLanguageOptions).sort(((a,b)=>a[1].localeCompare(b[1]))).map((_ref=>{let[key,value]=_ref;return{key:key,value:value}}));this.targetLanguageOptions=[...firstLanguages,...sortedLanguages]}}return _exports.default=_default,_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),_base=_interopRequireDefault(_base),_config=_interopRequireDefault(_config);class _default extends _base.default{constructor(uniqid){super(uniqid),_defineProperty(this,"targetLanguageCodes",["de","fr","it","es","cs","zh","ru","uk","el","la","tr","ro","pl","bg","ar","sq","bs","sr","hr","ku","fa","ps","sk","hu"]),_defineProperty(this,"targetLanguageOptions",[]),_defineProperty(this,"targetLanguage",null),this.initTargetLanguages()}setTargetLanguage(targetLanguage){this.targetLanguage=targetLanguage}async getPrompt(selectionText){const selectedLanguageEntry=this.targetLanguageOptions.filter((languageEntry=>languageEntry.key===this.targetLanguage))[0];let prompt=await(0,_str.getString)("translate_baseprompt","tiny_ai",selectedLanguageEntry.value);return prompt+=": "+selectionText,prompt}getTemplateContext(){const translateHandler=(0,_utils.getTranslateHandler)(this.uniqid),context={modalHeadline:BasedataHandler.getTinyAiString("translate_headline"),showIcon:!0,tool:"translate"},targetLanguageDropdownContext={preference:"targetLanguage"};targetLanguageDropdownContext.dropdownDefault=translateHandler.targetLanguageOptions[0].value,targetLanguageDropdownContext.dropdownDefaultValue=translateHandler.targetLanguageOptions[0].key,targetLanguageDropdownContext.dropdownDescription=BasedataHandler.getTinyAiString("targetlanguage");const targetLanguageDropdownOptions=[];return translateHandler.targetLanguageOptions.forEach((languageEntry=>{targetLanguageDropdownOptions.push({optionValue:languageEntry.key,optionLabel:languageEntry.value})})),targetLanguageDropdownContext.dropdownOptions=targetLanguageDropdownOptions,Object.assign(context,{modalDropdowns:[targetLanguageDropdownContext]}),Object.assign(context,BasedataHandler.getShowPromptButtonContext()),Object.assign(context,BasedataHandler.getBackAndGenerateButtonContext()),context}initTargetLanguages(){const currentUserLanguage=_config.default.language.substring(0,2),languageNameInCurrentUserLanguage=new Intl.DisplayNames([currentUserLanguage],{type:"language"}),firstLanguages=[{key:"en",value:languageNameInCurrentUserLanguage.of("en")}];if("en"!==currentUserLanguage&&this.targetLanguageCodes.includes(currentUserLanguage)){firstLanguages.push({key:currentUserLanguage,value:languageNameInCurrentUserLanguage.of(currentUserLanguage)});const index=this.targetLanguageCodes.indexOf(currentUserLanguage);this.targetLanguageCodes.splice(index,1)}this.targetLanguageCodes.forEach((languageCode=>{this.targetLanguageOptions[languageCode]=languageNameInCurrentUserLanguage.of(languageCode)}));const sortedLanguages=Object.entries(this.targetLanguageOptions).sort(((a,b)=>a[1].localeCompare(b[1]))).map((_ref=>{let[key,value]=_ref;return{key:key,value:value}}));this.targetLanguageOptions=[...firstLanguages,...sortedLanguages]}}return _exports.default=_default,_exports.default})); //# sourceMappingURL=translate.min.js.map \ No newline at end of file diff --git a/amd/build/datahandler/translate.min.js.map b/amd/build/datahandler/translate.min.js.map index 72aa3bc..499bbf2 100644 --- a/amd/build/datahandler/translate.min.js.map +++ b/amd/build/datahandler/translate.min.js.map @@ -1 +1 @@ -{"version":3,"file":"translate.min.js","sources":["../../src/datahandler/translate.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 BasedataHandler from 'tiny_ai/datahandler/basedata';\nimport BaseHandler from 'tiny_ai/datahandler/base';\nimport {getTranslateHandler} from 'tiny_ai/utils';\nimport Config from 'core/config';\nimport {getString} from 'core/str';\n\n/**\n * Tiny AI data manager.\n *\n * @module tiny_ai/datahandler/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\nexport default class extends BaseHandler {\n\n // English will always be added to the front of the list. All other languages can be defined here.\n // The user's current language will be shown right after English, if it is contained in this list.\n targetLanguageCodes = [\n 'de', 'fr', 'it', 'es', 'cs', 'zh', 'ru', 'uk', 'el', 'la', 'tr', 'ro', 'pl', 'bg', 'ar', 'sq',\n 'bs', 'sr', 'hr', 'ku', 'fa', 'ps', 'sk', 'hu'\n ];\n targetLanguageOptions = [];\n targetLanguage = null;\n\n constructor(uniqid) {\n super(uniqid);\n this.initTargetLanguages();\n }\n\n setTargetLanguage(targetLanguage) {\n this.targetLanguage = targetLanguage;\n }\n\n async getPrompt(selectionText) {\n const selectedLanguageEntry =\n this.targetLanguageOptions.filter(languageEntry => languageEntry.key === this.targetLanguage)[0];\n let prompt = await getString('translate_baseprompt', 'tiny_ai', selectedLanguageEntry.value);\n prompt += ': ' + selectionText;\n return prompt;\n }\n\n getTemplateContext() {\n const translateHandler = getTranslateHandler(this.uniqid);\n const context = {\n modal_headline: BasedataHandler.getTinyAiString('translate_headline'),\n showIcon: true,\n tool: 'translate',\n };\n const targetLanguageDropdownContext = {};\n targetLanguageDropdownContext.preference = 'targetLanguage';\n targetLanguageDropdownContext.dropdown_default = translateHandler.targetLanguageOptions[0].value;\n targetLanguageDropdownContext.dropdown_default_value = translateHandler.targetLanguageOptions[0].key;\n targetLanguageDropdownContext.dropdown_description = BasedataHandler.getTinyAiString('targetlanguage');\n const targetLanguageDropdownOptions = [];\n translateHandler.targetLanguageOptions.forEach(languageEntry => {\n targetLanguageDropdownOptions.push({\n optionValue: languageEntry.key,\n optionLabel: languageEntry.value,\n });\n });\n targetLanguageDropdownContext.dropdown_options = targetLanguageDropdownOptions;\n\n Object.assign(context, {\n modal_dropdowns: [\n targetLanguageDropdownContext,\n ]\n });\n Object.assign(context, BasedataHandler.getShowPromptButtonContext());\n Object.assign(context, BasedataHandler.getBackAndGenerateButtonContext());\n return context;\n }\n\n initTargetLanguages() {\n // Ensure to only have a two-character lang string for the user's current language.\n // In case of extended language packs like for example \"de_du\" the attribute Config.language contains \"de_du\", for example.\n const currentUserLanguage = Config.language.substring(0, 2);\n const languageNameInCurrentUserLanguage = new Intl.DisplayNames([currentUserLanguage], {type: 'language'});\n const firstLanguages = [\n {\n key: 'en',\n value: languageNameInCurrentUserLanguage.of('en')\n }\n ];\n if (currentUserLanguage !== 'en' && this.targetLanguageCodes.includes(currentUserLanguage)) {\n firstLanguages.push(\n {\n key: currentUserLanguage,\n value: languageNameInCurrentUserLanguage.of(currentUserLanguage)\n }\n );\n // Remove current user's language from the list.\n const index = this.targetLanguageCodes.indexOf(currentUserLanguage);\n this.targetLanguageCodes.splice(index, 1);\n }\n this.targetLanguageCodes.forEach(languageCode => {\n this.targetLanguageOptions[languageCode] = languageNameInCurrentUserLanguage.of(languageCode);\n });\n\n const sortedLanguages = Object\n .entries(this.targetLanguageOptions)\n .sort((a, b) => a[1].localeCompare(b[1]))\n .map(([key, value]) => ({'key': key, 'value': value}));\n this.targetLanguageOptions = [...firstLanguages, ...sortedLanguages];\n }\n}\n"],"names":["BaseHandler","constructor","uniqid","initTargetLanguages","setTargetLanguage","targetLanguage","selectionText","selectedLanguageEntry","this","targetLanguageOptions","filter","languageEntry","key","prompt","value","getTemplateContext","translateHandler","context","modal_headline","BasedataHandler","getTinyAiString","showIcon","tool","targetLanguageDropdownContext","dropdown_default","dropdown_default_value","dropdown_description","targetLanguageDropdownOptions","forEach","push","optionValue","optionLabel","dropdown_options","Object","assign","modal_dropdowns","getShowPromptButtonContext","getBackAndGenerateButtonContext","currentUserLanguage","Config","language","substring","languageNameInCurrentUserLanguage","Intl","DisplayNames","type","firstLanguages","of","targetLanguageCodes","includes","index","indexOf","splice","languageCode","sortedLanguages","entries","sort","a","b","localeCompare","map","_ref"],"mappings":";;;;;;;;s2BA8B6BA,cAWzBC,YAAYC,cACFA,mDARY,CAClB,KAAM,KAAM,KAAM,KAAM,KAAM,KAAM,KAAM,KAAM,KAAM,KAAM,KAAM,KAAM,KAAM,KAAM,KAAM,KAC1F,KAAM,KAAM,KAAM,KAAM,KAAM,KAAM,KAAM,oDAEtB,0CACP,WAIRC,sBAGTC,kBAAkBC,qBACTA,eAAiBA,+BAGVC,qBACNC,sBACFC,KAAKC,sBAAsBC,QAAOC,eAAiBA,cAAcC,MAAQJ,KAAKH,iBAAgB,OAC9FQ,aAAe,kBAAU,uBAAwB,UAAWN,sBAAsBO,cACtFD,QAAU,KAAOP,cACVO,OAGXE,2BACUC,kBAAmB,8BAAoBR,KAAKN,QAC5Ce,QAAU,CACZC,eAAgBC,gBAAgBC,gBAAgB,sBAChDC,UAAU,EACVC,KAAM,aAEJC,8BAAgC,CACtCA,WAA2C,kBAC3CA,8BAA8BC,iBAAmBR,iBAAiBP,sBAAsB,GAAGK,MAC3FS,8BAA8BE,uBAAyBT,iBAAiBP,sBAAsB,GAAGG,IACjGW,8BAA8BG,qBAAuBP,gBAAgBC,gBAAgB,wBAC/EO,8BAAgC,UACtCX,iBAAiBP,sBAAsBmB,SAAQjB,gBAC3CgB,8BAA8BE,KAAK,CAC/BC,YAAanB,cAAcC,IAC3BmB,YAAapB,cAAcG,WAGnCS,8BAA8BS,iBAAmBL,8BAEjDM,OAAOC,OAAOjB,QAAS,CACnBkB,gBAAiB,CACbZ,iCAGRU,OAAOC,OAAOjB,QAASE,gBAAgBiB,8BACvCH,OAAOC,OAAOjB,QAASE,gBAAgBkB,mCAChCpB,QAGXd,4BAGUmC,oBAAsBC,gBAAOC,SAASC,UAAU,EAAG,GACnDC,kCAAoC,IAAIC,KAAKC,aAAa,CAACN,qBAAsB,CAACO,KAAM,aACxFC,eAAiB,CACnB,CACIlC,IAAK,KACLE,MAAO4B,kCAAkCK,GAAG,WAGxB,OAAxBT,qBAAgC9B,KAAKwC,oBAAoBC,SAASX,qBAAsB,CACxFQ,eAAejB,KACX,CACIjB,IAAK0B,oBACLxB,MAAO4B,kCAAkCK,GAAGT,6BAI9CY,MAAQ1C,KAAKwC,oBAAoBG,QAAQb,0BAC1CU,oBAAoBI,OAAOF,MAAO,QAEtCF,oBAAoBpB,SAAQyB,oBACxB5C,sBAAsB4C,cAAgBX,kCAAkCK,GAAGM,uBAG9EC,gBAAkBrB,OACnBsB,QAAQ/C,KAAKC,uBACb+C,MAAK,CAACC,EAAGC,IAAMD,EAAE,GAAGE,cAAcD,EAAE,MACpCE,KAAIC,WAAEjD,IAAKE,kBAAY,KAAQF,UAAcE,eAC7CL,sBAAwB,IAAIqC,kBAAmBQ"} \ No newline at end of file +{"version":3,"file":"translate.min.js","sources":["../../src/datahandler/translate.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 BasedataHandler from 'tiny_ai/datahandler/basedata';\nimport BaseHandler from 'tiny_ai/datahandler/base';\nimport {getTranslateHandler} from 'tiny_ai/utils';\nimport Config from 'core/config';\nimport {getString} from 'core/str';\n\n/**\n * Tiny AI data manager.\n *\n * @module tiny_ai/datahandler/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\nexport default class extends BaseHandler {\n\n // English will always be added to the front of the list. All other languages can be defined here.\n // The user's current language will be shown right after English, if it is contained in this list.\n targetLanguageCodes = [\n 'de', 'fr', 'it', 'es', 'cs', 'zh', 'ru', 'uk', 'el', 'la', 'tr', 'ro', 'pl', 'bg', 'ar', 'sq',\n 'bs', 'sr', 'hr', 'ku', 'fa', 'ps', 'sk', 'hu'\n ];\n targetLanguageOptions = [];\n targetLanguage = null;\n\n constructor(uniqid) {\n super(uniqid);\n this.initTargetLanguages();\n }\n\n setTargetLanguage(targetLanguage) {\n this.targetLanguage = targetLanguage;\n }\n\n async getPrompt(selectionText) {\n const selectedLanguageEntry =\n this.targetLanguageOptions.filter(languageEntry => languageEntry.key === this.targetLanguage)[0];\n let prompt = await getString('translate_baseprompt', 'tiny_ai', selectedLanguageEntry.value);\n prompt += ': ' + selectionText;\n return prompt;\n }\n\n getTemplateContext() {\n const translateHandler = getTranslateHandler(this.uniqid);\n const context = {\n modalHeadline: BasedataHandler.getTinyAiString('translate_headline'),\n showIcon: true,\n tool: 'translate',\n };\n const targetLanguageDropdownContext = {};\n targetLanguageDropdownContext.preference = 'targetLanguage';\n targetLanguageDropdownContext.dropdownDefault = translateHandler.targetLanguageOptions[0].value;\n targetLanguageDropdownContext.dropdownDefaultValue = translateHandler.targetLanguageOptions[0].key;\n targetLanguageDropdownContext.dropdownDescription = BasedataHandler.getTinyAiString('targetlanguage');\n const targetLanguageDropdownOptions = [];\n translateHandler.targetLanguageOptions.forEach(languageEntry => {\n targetLanguageDropdownOptions.push({\n optionValue: languageEntry.key,\n optionLabel: languageEntry.value,\n });\n });\n targetLanguageDropdownContext.dropdownOptions = targetLanguageDropdownOptions;\n\n Object.assign(context, {\n modalDropdowns: [\n targetLanguageDropdownContext,\n ]\n });\n Object.assign(context, BasedataHandler.getShowPromptButtonContext());\n Object.assign(context, BasedataHandler.getBackAndGenerateButtonContext());\n return context;\n }\n\n initTargetLanguages() {\n // Ensure to only have a two-character lang string for the user's current language.\n // In case of extended language packs like for example \"de_du\" the attribute Config.language contains \"de_du\", for example.\n const currentUserLanguage = Config.language.substring(0, 2);\n const languageNameInCurrentUserLanguage = new Intl.DisplayNames([currentUserLanguage], {type: 'language'});\n const firstLanguages = [\n {\n key: 'en',\n value: languageNameInCurrentUserLanguage.of('en')\n }\n ];\n if (currentUserLanguage !== 'en' && this.targetLanguageCodes.includes(currentUserLanguage)) {\n firstLanguages.push(\n {\n key: currentUserLanguage,\n value: languageNameInCurrentUserLanguage.of(currentUserLanguage)\n }\n );\n // Remove current user's language from the list.\n const index = this.targetLanguageCodes.indexOf(currentUserLanguage);\n this.targetLanguageCodes.splice(index, 1);\n }\n this.targetLanguageCodes.forEach(languageCode => {\n this.targetLanguageOptions[languageCode] = languageNameInCurrentUserLanguage.of(languageCode);\n });\n\n const sortedLanguages = Object\n .entries(this.targetLanguageOptions)\n .sort((a, b) => a[1].localeCompare(b[1]))\n .map(([key, value]) => ({'key': key, 'value': value}));\n this.targetLanguageOptions = [...firstLanguages, ...sortedLanguages];\n }\n}\n"],"names":["BaseHandler","constructor","uniqid","initTargetLanguages","setTargetLanguage","targetLanguage","selectionText","selectedLanguageEntry","this","targetLanguageOptions","filter","languageEntry","key","prompt","value","getTemplateContext","translateHandler","context","modalHeadline","BasedataHandler","getTinyAiString","showIcon","tool","targetLanguageDropdownContext","dropdownDefault","dropdownDefaultValue","dropdownDescription","targetLanguageDropdownOptions","forEach","push","optionValue","optionLabel","dropdownOptions","Object","assign","modalDropdowns","getShowPromptButtonContext","getBackAndGenerateButtonContext","currentUserLanguage","Config","language","substring","languageNameInCurrentUserLanguage","Intl","DisplayNames","type","firstLanguages","of","targetLanguageCodes","includes","index","indexOf","splice","languageCode","sortedLanguages","entries","sort","a","b","localeCompare","map","_ref"],"mappings":";;;;;;;;s2BA8B6BA,cAWzBC,YAAYC,cACFA,mDARY,CAClB,KAAM,KAAM,KAAM,KAAM,KAAM,KAAM,KAAM,KAAM,KAAM,KAAM,KAAM,KAAM,KAAM,KAAM,KAAM,KAC1F,KAAM,KAAM,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EtCF,oBAAoBpB,SAAQyB,oBACxB5C,sBAAsB4C,cAAgBX,kCAAkCK,GAAGM,uBAG9EC,gBAAkBrB,OACnBsB,QAAQ/C,KAAKC,uBACb+C,MAAK,CAACC,EAAGC,IAAMD,EAAE,GAAGE,cAAcD,EAAE,MACpCE,KAAIC,WAAEjD,IAAKE,kBAAY,KAAQF,UAAcE,eAC7CL,sBAAwB,IAAIqC,kBAAmBQ"} \ No newline at end of file diff --git a/amd/build/datahandler/tts.min.js b/amd/build/datahandler/tts.min.js index 1e1fe60..fc585bc 100644 --- a/amd/build/datahandler/tts.min.js +++ b/amd/build/datahandler/tts.min.js @@ -6,6 +6,6 @@ define("tiny_ai/datahandler/tts",["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{constructor(){super(...arguments),_defineProperty(this,"ttsOptions",null),_defineProperty(this,"targetLanguage",null),_defineProperty(this,"voice",null),_defineProperty(this,"gender",null)}async getTargetLanguageOptions(){return await this.loadTtsOptions(),this.ttsOptions.languages}async getVoiceOptions(){return await this.loadTtsOptions(),this.ttsOptions.voices}async getGenderOptions(){return await this.loadTtsOptions(),this.ttsOptions.gender}setTargetLanguage(targetLanguage){this.targetLanguage=targetLanguage}setVoice(voice){this.voice=voice}setGender(gender){this.gender=gender}getOptions(){if(null===this.targetLanguage&&null===this.voice&&null===this.gender)return{};const options={};return this.targetLanguage&&(options.languages=[this.targetLanguage]),this.voice&&(options.voices=[this.voice]),this.gender&&(options.gender=[this.gender]),options}getPrompt(currentTool,selectionText){return"tts"===currentTool?selectionText:""}async loadTtsOptions(){if(null===this.ttsOptions){const fetchedOptions=await AiConfig.getPurposeOptions("tts");this.ttsOptions=JSON.parse(fetchedOptions.options)}}async getTemplateContext(tool){const context={modal_headline:BasedataHandler.getTinyAiString(tool+"_headline"),showIcon:!0,tool:tool},modalDropdowns=[],targetLanguageOptions=await this.getTargetLanguageOptions();if(null!==targetLanguageOptions&&Object.keys(targetLanguageOptions).length>0){const targetLanguageDropdownContext={preference:"targetLanguage"};let indexOfLanguageOption=0;targetLanguageOptions.map((entry=>entry.key.startsWith(_config2.default.language))).length>0&&(indexOfLanguageOption=targetLanguageOptions.findIndex((value=>value.key.startsWith(_config2.default.language)))),targetLanguageDropdownContext.dropdown_default=targetLanguageOptions[indexOfLanguageOption].displayname,targetLanguageDropdownContext.dropdown_default_value=targetLanguageOptions[indexOfLanguageOption].key,targetLanguageDropdownContext.dropdown_description=BasedataHandler.getTinyAiString("targetlanguage");const targetLanguageDropdownOptions=[];targetLanguageOptions.forEach((option=>{targetLanguageDropdownOptions.push({optionValue:option.key,optionLabel:option.displayname})})),targetLanguageDropdownContext.dropdown_options=targetLanguageDropdownOptions,modalDropdowns.push(targetLanguageDropdownContext)}const voiceOptions=await this.getVoiceOptions();if(null!==voiceOptions&&Object.keys(voiceOptions).length>0){const voiceDropdownContext={preference:"voice"};voiceDropdownContext.dropdown_default=voiceOptions[0].displayname,voiceDropdownContext.dropdown_default_value=voiceOptions[0].key,voiceDropdownContext.dropdown_description=BasedataHandler.getTinyAiString("voice");const voiceDropdownOptions=[];voiceOptions.forEach((option=>{voiceDropdownOptions.push({optionValue:option.key,optionLabel:option.displayname})})),voiceDropdownContext.dropdown_options=voiceDropdownOptions,modalDropdowns.push(voiceDropdownContext)}const genderOptions=await this.getGenderOptions();if(null!==genderOptions&&Object.keys(genderOptions).length>0){const genderDropdownContext={preference:"gender"};genderDropdownContext.dropdown_default=genderOptions[0].displayname,genderDropdownContext.dropdown_default_value=genderOptions[0].key,genderDropdownContext.dropdown_description=BasedataHandler.getTinyAiString("gender");const genderDropdownOptions=[];genderOptions.forEach((option=>{genderDropdownOptions.push({optionValue:option.key,optionLabel:option.displayname})})),genderDropdownContext.dropdown_options=genderDropdownOptions,modalDropdowns.push(genderDropdownContext)}return"audiogen"===tool&&modalDropdowns.forEach((dropdownContext=>{dropdownContext.dropup=!0})),Object.assign(context,{modal_dropdowns:modalDropdowns}),Object.assign(context,BasedataHandler.getShowPromptButtonContext()),"audiogen"===tool&&(context.collapsed=!1,context.placeholder=BasedataHandler.getTinyAiString("audiogen_placeholder")),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{constructor(){super(...arguments),_defineProperty(this,"ttsOptions",null),_defineProperty(this,"targetLanguage",null),_defineProperty(this,"voice",null),_defineProperty(this,"gender",null)}async getTargetLanguageOptions(){return await this.loadTtsOptions(),this.ttsOptions.languages}async getVoiceOptions(){return await this.loadTtsOptions(),this.ttsOptions.voices}async getGenderOptions(){return await this.loadTtsOptions(),this.ttsOptions.gender}setTargetLanguage(targetLanguage){this.targetLanguage=targetLanguage}setVoice(voice){this.voice=voice}setGender(gender){this.gender=gender}getOptions(){if(null===this.targetLanguage&&null===this.voice&&null===this.gender)return{};const options={};return this.targetLanguage&&(options.languages=[this.targetLanguage]),this.voice&&(options.voices=[this.voice]),this.gender&&(options.gender=[this.gender]),options}getPrompt(currentTool,selectionText){return"tts"===currentTool?selectionText:""}async loadTtsOptions(){if(null===this.ttsOptions){const fetchedOptions=await AiConfig.getPurposeOptions("tts");this.ttsOptions=JSON.parse(fetchedOptions.options)}}async getTemplateContext(tool){const context={modalHeadline:BasedataHandler.getTinyAiString(tool+"_headline"),showIcon:!0,tool:tool},modalDropdowns=[],targetLanguageOptions=await this.getTargetLanguageOptions();if(null!==targetLanguageOptions&&Object.keys(targetLanguageOptions).length>0){const targetLanguageDropdownContext={preference:"targetLanguage"};let indexOfLanguageOption=0;targetLanguageOptions.map((entry=>entry.key.startsWith(_config2.default.language))).length>0&&(indexOfLanguageOption=targetLanguageOptions.findIndex((value=>value.key.startsWith(_config2.default.language)))),targetLanguageDropdownContext.dropdownDefault=targetLanguageOptions[indexOfLanguageOption].displayname,targetLanguageDropdownContext.dropdownDefaultValue=targetLanguageOptions[indexOfLanguageOption].key,targetLanguageDropdownContext.dropdownDescription=BasedataHandler.getTinyAiString("targetlanguage");const targetLanguageDropdownOptions=[];targetLanguageOptions.forEach((option=>{targetLanguageDropdownOptions.push({optionValue:option.key,optionLabel:option.displayname})})),targetLanguageDropdownContext.dropdownOptions=targetLanguageDropdownOptions,modalDropdowns.push(targetLanguageDropdownContext)}const voiceOptions=await this.getVoiceOptions();if(null!==voiceOptions&&Object.keys(voiceOptions).length>0){const voiceDropdownContext={preference:"voice"};voiceDropdownContext.dropdownDefault=voiceOptions[0].displayname,voiceDropdownContext.dropdownDefaultValue=voiceOptions[0].key,voiceDropdownContext.dropdownDescription=BasedataHandler.getTinyAiString("voice");const voiceDropdownOptions=[];voiceOptions.forEach((option=>{voiceDropdownOptions.push({optionValue:option.key,optionLabel:option.displayname})})),voiceDropdownContext.dropdownOptions=voiceDropdownOptions,modalDropdowns.push(voiceDropdownContext)}const genderOptions=await this.getGenderOptions();if(null!==genderOptions&&Object.keys(genderOptions).length>0){const genderDropdownContext={preference:"gender"};genderDropdownContext.dropdownDefault=genderOptions[0].displayname,genderDropdownContext.dropdownDefaultValue=genderOptions[0].key,genderDropdownContext.dropdownDescription=BasedataHandler.getTinyAiString("gender");const genderDropdownOptions=[];genderOptions.forEach((option=>{genderDropdownOptions.push({optionValue:option.key,optionLabel:option.displayname})})),genderDropdownContext.dropdownOptions=genderDropdownOptions,modalDropdowns.push(genderDropdownContext)}return"audiogen"===tool&&modalDropdowns.forEach((dropdownContext=>{dropdownContext.dropup=!0})),Object.assign(context,{modalDropdowns:modalDropdowns}),Object.assign(context,BasedataHandler.getShowPromptButtonContext()),"audiogen"===tool&&(context.collapsed=!1,context.placeholder=BasedataHandler.getTinyAiString("audiogen_placeholder")),Object.assign(context,BasedataHandler.getBackAndGenerateButtonContext()),context}}return _exports.default=_default,_exports.default})); //# sourceMappingURL=tts.min.js.map \ No newline at end of file diff --git a/amd/build/datahandler/tts.min.js.map b/amd/build/datahandler/tts.min.js.map index 26a24c4..478596c 100644 --- a/amd/build/datahandler/tts.min.js.map +++ b/amd/build/datahandler/tts.min.js.map @@ -1 +1 @@ -{"version":3,"file":"tts.min.js","sources":["../../src/datahandler/tts.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';\n\n/**\n * Tiny AI data manager.\n *\n * @module tiny_ai/datahandler/tts\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 ttsOptions = null;\n\n targetLanguage = null;\n voice = null;\n gender = null;\n\n async getTargetLanguageOptions() {\n await this.loadTtsOptions();\n return this.ttsOptions.languages;\n }\n\n async getVoiceOptions() {\n await this.loadTtsOptions();\n return this.ttsOptions.voices;\n }\n\n async getGenderOptions() {\n await this.loadTtsOptions();\n return this.ttsOptions.gender;\n }\n\n setTargetLanguage(targetLanguage) {\n this.targetLanguage = targetLanguage;\n }\n\n setVoice(voice) {\n this.voice = voice;\n }\n\n setGender(gender) {\n this.gender = gender;\n }\n\n getOptions() {\n if (this.targetLanguage === null && this.voice === null && this.gender === null) {\n return {};\n }\n const options = {};\n if (this.targetLanguage) {\n options['languages'] = [this.targetLanguage];\n }\n if (this.voice) {\n options['voices'] = [this.voice];\n }\n if (this.gender) {\n options['gender'] = [this.gender];\n }\n return options;\n }\n\n getPrompt(currentTool, selectionText) {\n // This handler handles both 'tts' and 'audiogen' tool types which basically are pretty much the same,\n // but not exactly.\n return currentTool === 'tts' ? selectionText : '';\n }\n\n async loadTtsOptions() {\n if (this.ttsOptions === null) {\n const fetchedOptions = await AiConfig.getPurposeOptions('tts');\n this.ttsOptions = JSON.parse(fetchedOptions.options);\n }\n }\n\n /**\n * Get the rendering context.\n *\n * @param {string} tool the tool to generate the context for, can be 'tts' and 'audiogen'\n */\n async getTemplateContext(tool) {\n const context = {\n modal_headline: BasedataHandler.getTinyAiString(tool + '_headline'),\n showIcon: true,\n tool: tool,\n };\n\n const modalDropdowns = [];\n\n const targetLanguageOptions = await this.getTargetLanguageOptions();\n if (targetLanguageOptions !== null && Object.keys(targetLanguageOptions).length > 0) {\n const targetLanguageDropdownContext = {};\n targetLanguageDropdownContext.preference = 'targetLanguage';\n let indexOfLanguageOption = 0;\n const matchingEntry = targetLanguageOptions.map(entry => entry['key'].startsWith(Config.language));\n\n if (matchingEntry.length > 0) {\n // Language keys are of the form de-DE, so we check, if current user's language starts with same language code.\n indexOfLanguageOption = targetLanguageOptions.findIndex(value => value['key'].startsWith(Config.language));\n }\n targetLanguageDropdownContext.dropdown_default = targetLanguageOptions[indexOfLanguageOption]['displayname'];\n targetLanguageDropdownContext.dropdown_default_value = targetLanguageOptions[indexOfLanguageOption]['key'];\n targetLanguageDropdownContext.dropdown_description = BasedataHandler.getTinyAiString('targetlanguage');\n const targetLanguageDropdownOptions = [];\n targetLanguageOptions.forEach(option => {\n targetLanguageDropdownOptions.push({\n optionValue: option.key,\n optionLabel: option.displayname,\n });\n });\n targetLanguageDropdownContext.dropdown_options = targetLanguageDropdownOptions;\n modalDropdowns.push(targetLanguageDropdownContext);\n }\n\n const voiceOptions = await this.getVoiceOptions();\n if (voiceOptions !== null && Object.keys(voiceOptions).length > 0) {\n const voiceDropdownContext = {};\n voiceDropdownContext.preference = 'voice';\n voiceDropdownContext.dropdown_default = voiceOptions[0]['displayname'];\n voiceDropdownContext.dropdown_default_value = voiceOptions[0]['key'];\n voiceDropdownContext.dropdown_description = BasedataHandler.getTinyAiString('voice');\n const voiceDropdownOptions = [];\n voiceOptions.forEach(option => {\n voiceDropdownOptions.push({\n optionValue: option.key,\n optionLabel: option.displayname,\n });\n });\n voiceDropdownContext.dropdown_options = voiceDropdownOptions;\n modalDropdowns.push(voiceDropdownContext);\n }\n\n const genderOptions = await this.getGenderOptions();\n if (genderOptions !== null && Object.keys(genderOptions).length > 0) {\n const genderDropdownContext = {};\n genderDropdownContext.preference = 'gender';\n genderDropdownContext.dropdown_default = genderOptions[0]['displayname'];\n genderDropdownContext.dropdown_default_value = genderOptions[0]['key'];\n genderDropdownContext.dropdown_description = BasedataHandler.getTinyAiString('gender');\n const genderDropdownOptions = [];\n genderOptions.forEach(option => {\n genderDropdownOptions.push({\n optionValue: option.key,\n optionLabel: option.displayname,\n });\n });\n genderDropdownContext.dropdown_options = genderDropdownOptions;\n modalDropdowns.push(genderDropdownContext);\n }\n if (tool === 'audiogen') {\n // In the audiogen view the dropdowns are at the bottom, so we need to make the dropdowns dropup instead of dropdown.\n modalDropdowns.forEach(dropdownContext => {\n dropdownContext.dropup = true;\n });\n }\n\n Object.assign(context, {\n modal_dropdowns: modalDropdowns\n });\n\n Object.assign(context, BasedataHandler.getShowPromptButtonContext());\n\n if (tool === 'audiogen') {\n // Overwrite some prompt textarea specific attributes.\n context.collapsed = false;\n context.placeholder = BasedataHandler.getTinyAiString('audiogen_placeholder');\n }\n Object.assign(context, BasedataHandler.getBackAndGenerateButtonContext());\n return context;\n }\n}\n"],"names":["BaseHandler","this","loadTtsOptions","ttsOptions","languages","voices","gender","setTargetLanguage","targetLanguage","setVoice","voice","setGender","getOptions","options","getPrompt","currentTool","selectionText","fetchedOptions","AiConfig","getPurposeOptions","JSON","parse","tool","context","modal_headline","BasedataHandler","getTinyAiString","showIcon","modalDropdowns","targetLanguageOptions","getTargetLanguageOptions","Object","keys","length","targetLanguageDropdownContext","indexOfLanguageOption","map","entry","startsWith","Config","language","findIndex","value","dropdown_default","dropdown_default_value","dropdown_description","targetLanguageDropdownOptions","forEach","option","push","optionValue","key","optionLabel","displayname","dropdown_options","voiceOptions","getVoiceOptions","voiceDropdownContext","voiceDropdownOptions","genderOptions","getGenderOptions","genderDropdownContext","genderDropdownOptions","dropdownContext","dropup","assign","modal_dropdowns","getShowPromptButtonContext","collapsed","placeholder","getBackAndGenerateButtonContext"],"mappings":";;;;;;;;8RA6B6BA,kFAEZ,4CAEI,mCACT,oCACC,oDAGCC,KAAKC,iBACJD,KAAKE,WAAWC,+CAIjBH,KAAKC,iBACJD,KAAKE,WAAWE,6CAIjBJ,KAAKC,iBACJD,KAAKE,WAAWG,OAG3BC,kBAAkBC,qBACTA,eAAiBA,eAG1BC,SAASC,YACAA,MAAQA,MAGjBC,UAAUL,aACDA,OAASA,OAGlBM,gBACgC,OAAxBX,KAAKO,gBAA0C,OAAfP,KAAKS,OAAkC,OAAhBT,KAAKK,aACrD,SAELO,QAAU,UACZZ,KAAKO,iBACLK,QAAO,UAAgB,CAACZ,KAAKO,iBAE7BP,KAAKS,QACLG,QAAO,OAAa,CAACZ,KAAKS,QAE1BT,KAAKK,SACLO,QAAO,OAAa,CAACZ,KAAKK,SAEvBO,QAGXC,UAAUC,YAAaC,qBAGI,QAAhBD,YAAwBC,cAAgB,6BAIvB,OAApBf,KAAKE,WAAqB,OACpBc,qBAAuBC,SAASC,kBAAkB,YACnDhB,WAAaiB,KAAKC,MAAMJ,eAAeJ,mCAS3BS,YACfC,QAAU,CACZC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Ad,YACzCE,sBAAsBjB,uBAAyBe,cAAc,GAAd,IAC/CE,sBAAsBhB,qBAAuBpB,gBAAgBC,gBAAgB,gBACvEoC,sBAAwB,GAC9BH,cAAcZ,SAAQC,SAClBc,sBAAsBb,KAAK,CACvBC,YAAaF,OAAOG,IACpBC,YAAaJ,OAAOK,iBAG5BQ,sBAAsBP,iBAAmBQ,sBACzClC,eAAeqB,KAAKY,6BAEX,aAATvC,MAEAM,eAAemB,SAAQgB,kBACnBA,gBAAgBC,QAAS,KAIjCjC,OAAOkC,OAAO1C,QAAS,CACnB2C,gBAAiBtC,iBAGrBG,OAAOkC,OAAO1C,QAASE,gBAAgB0C,8BAE1B,aAAT7C,OAEAC,QAAQ6C,WAAY,EACpB7C,QAAQ8C,YAAc5C,gBAAgBC,gBAAgB,yBAE1DK,OAAOkC,OAAO1C,QAASE,gBAAgB6C,mCAChC/C"} \ No newline at end of file +{"version":3,"file":"tts.min.js","sources":["../../src/datahandler/tts.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';\n\n/**\n * Tiny AI data manager.\n *\n * @module tiny_ai/datahandler/tts\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 ttsOptions = null;\n\n targetLanguage = null;\n voice = null;\n gender = null;\n\n async getTargetLanguageOptions() {\n await this.loadTtsOptions();\n return this.ttsOptions.languages;\n }\n\n async getVoiceOptions() {\n await this.loadTtsOptions();\n return this.ttsOptions.voices;\n }\n\n async getGenderOptions() {\n await this.loadTtsOptions();\n return this.ttsOptions.gender;\n }\n\n setTargetLanguage(targetLanguage) {\n this.targetLanguage = targetLanguage;\n }\n\n setVoice(voice) {\n this.voice = voice;\n }\n\n setGender(gender) {\n this.gender = gender;\n }\n\n getOptions() {\n if (this.targetLanguage === null && this.voice === null && this.gender === null) {\n return {};\n }\n const options = {};\n if (this.targetLanguage) {\n options.languages = [this.targetLanguage];\n }\n if (this.voice) {\n options.voices = [this.voice];\n }\n if (this.gender) {\n options.gender = [this.gender];\n }\n return options;\n }\n\n getPrompt(currentTool, selectionText) {\n // This handler handles both 'tts' and 'audiogen' tool types which basically are pretty much the same,\n // but not exactly.\n return currentTool === 'tts' ? selectionText : '';\n }\n\n async loadTtsOptions() {\n if (this.ttsOptions === null) {\n const fetchedOptions = await AiConfig.getPurposeOptions('tts');\n this.ttsOptions = JSON.parse(fetchedOptions.options);\n }\n }\n\n /**\n * Get the rendering context.\n *\n * @param {string} tool the tool to generate the context for, can be 'tts' and 'audiogen'\n */\n async getTemplateContext(tool) {\n const context = {\n modalHeadline: BasedataHandler.getTinyAiString(tool + '_headline'),\n showIcon: true,\n tool: tool,\n };\n\n const modalDropdowns = [];\n\n const targetLanguageOptions = await this.getTargetLanguageOptions();\n if (targetLanguageOptions !== null && Object.keys(targetLanguageOptions).length > 0) {\n const targetLanguageDropdownContext = {};\n targetLanguageDropdownContext.preference = 'targetLanguage';\n let indexOfLanguageOption = 0;\n const matchingEntry = targetLanguageOptions.map(entry => entry.key.startsWith(Config.language));\n\n if (matchingEntry.length > 0) {\n // Language keys are of the form de-DE, so we check, if current user's language starts with same language code.\n indexOfLanguageOption = targetLanguageOptions.findIndex(value => value.key.startsWith(Config.language));\n }\n targetLanguageDropdownContext.dropdownDefault = targetLanguageOptions[indexOfLanguageOption].displayname;\n targetLanguageDropdownContext.dropdownDefaultValue = targetLanguageOptions[indexOfLanguageOption].key;\n targetLanguageDropdownContext.dropdownDescription = BasedataHandler.getTinyAiString('targetlanguage');\n const targetLanguageDropdownOptions = [];\n targetLanguageOptions.forEach(option => {\n targetLanguageDropdownOptions.push({\n optionValue: option.key,\n optionLabel: option.displayname,\n });\n });\n targetLanguageDropdownContext.dropdownOptions = targetLanguageDropdownOptions;\n modalDropdowns.push(targetLanguageDropdownContext);\n }\n\n const voiceOptions = await this.getVoiceOptions();\n if (voiceOptions !== null && Object.keys(voiceOptions).length > 0) {\n const voiceDropdownContext = {};\n voiceDropdownContext.preference = 'voice';\n voiceDropdownContext.dropdownDefault = voiceOptions[0].displayname;\n voiceDropdownContext.dropdownDefaultValue = voiceOptions[0].key;\n voiceDropdownContext.dropdownDescription = BasedataHandler.getTinyAiString('voice');\n const voiceDropdownOptions = [];\n voiceOptions.forEach(option => {\n voiceDropdownOptions.push({\n optionValue: option.key,\n optionLabel: option.displayname,\n });\n });\n voiceDropdownContext.dropdownOptions = voiceDropdownOptions;\n modalDropdowns.push(voiceDropdownContext);\n }\n\n const genderOptions = await this.getGenderOptions();\n if (genderOptions !== null && Object.keys(genderOptions).length > 0) {\n const genderDropdownContext = {};\n genderDropdownContext.preference = 'gender';\n genderDropdownContext.dropdownDefault = genderOptions[0].displayname;\n genderDropdownContext.dropdownDefaultValue = genderOptions[0].key;\n genderDropdownContext.dropdownDescription = BasedataHandler.getTinyAiString('gender');\n const genderDropdownOptions = [];\n genderOptions.forEach(option => {\n genderDropdownOptions.push({\n optionValue: option.key,\n optionLabel: option.displayname,\n });\n });\n genderDropdownContext.dropdownOptions = genderDropdownOptions;\n modalDropdowns.push(genderDropdownContext);\n }\n if (tool === 'audiogen') {\n // In the audiogen view the dropdowns are at the bottom, so we need to make the dropdowns dropup instead of dropdown.\n modalDropdowns.forEach(dropdownContext => {\n dropdownContext.dropup = true;\n });\n }\n\n Object.assign(context, {\n modalDropdowns: modalDropdowns\n });\n\n Object.assign(context, BasedataHandler.getShowPromptButtonContext());\n\n if (tool === 'audiogen') {\n // Overwrite some prompt textarea specific attributes.\n context.collapsed = false;\n context.placeholder = BasedataHandler.getTinyAiString('audiogen_placeholder');\n }\n Object.assign(context, BasedataHandler.getBackAndGenerateButtonContext());\n return context;\n }\n}\n"],"names":["BaseHandler","this","loadTtsOptions","ttsOptions","languages","voices","gender","setTargetLanguage","targetLanguage","setVoice","voice","setGender","getOptions","options","getPrompt","currentTool","selectionText","fetchedOptions","AiConfig","getPurposeOptions","JSON","parse","tool","context","modalHeadline","BasedataHandler","getTinyAiString","showIcon","modalDropdowns","targetLanguageOptions","getTargetLanguageOptions","Object","keys","length","targetLanguageDropdownContext","indexOfLanguageOption","map","entry","key","startsWith","Config","language","findIndex","value","dropdownDefault","displayname","dropdownDefaultValue","dropdownDescription","targetLanguageDropdownOptions","forEach","option","push","optionValue","optionLabel","dropdownOptions","voiceOptions","getVoiceOptions","voiceDropdownContext","voiceDropdownOptions","genderOptions","getGenderOptions","genderDropdownContext","genderDropdownOptions","dropdownContext","dropup","assign","getShowPromptButtonContext","collapsed","placeholder","getBackAndGenerateButtonContext"],"mappings":";;;;;;;;8RA6B6BA,kFAEZ,4CAEI,mCACT,oCACC,oDAGCC,KAAKC,iBACJD,KAAKE,WAAWC,+CAIjBH,KAAKC,iBACJD,KAAKE,WAAWE,6CAIjBJ,KAAKC,iBACJD,KAAKE,WAAWG,OAG3BC,kBAAkBC,qBACTA,eAAiBA,eAG1BC,SAASC,YACAA,MAAQA,MAGjBC,UAAUL,aACDA,OAASA,OAGlBM,gBACgC,OAAxBX,KAAKO,gBAA0C,OAAfP,KAAKS,OAAkC,OAAhBT,KAAKK,aACrD,SAELO,QAAU,UACZZ,KAAKO,iBACLK,QAAQT,UAAY,CAACH,KAAKO,iBAE1BP,KAAKS,QACLG,QAAQR,OAAS,CAACJ,KAAKS,QAEvBT,KAAKK,SACLO,QAAQP,OAAS,CAAC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BY,qBAAqBH,gBAAkBI,qBACvC9B,eAAeuB,KAAKM,4BAGlBE,oBAAsB1D,KAAK2D,sBACX,OAAlBD,eAA0B5B,OAAOC,KAAK2B,eAAe1B,OAAS,EAAG,OAC3D4B,sBAAwB,CAC9BA,WAAmC,UACnCA,sBAAsBjB,gBAAkBe,cAAc,GAAGd,YACzDgB,sBAAsBf,qBAAuBa,cAAc,GAAGrB,IAC9DuB,sBAAsBd,oBAAsBtB,gBAAgBC,gBAAgB,gBACtEoC,sBAAwB,GAC9BH,cAAcV,SAAQC,SAClBY,sBAAsBX,KAAK,CACvBC,YAAaF,OAAOZ,IACpBe,YAAaH,OAAOL,iBAG5BgB,sBAAsBP,gBAAkBQ,sBACxClC,eAAeuB,KAAKU,6BAEX,aAATvC,MAEAM,eAAeqB,SAAQc,kBACnBA,gBAAgBC,QAAS,KAIjCjC,OAAOkC,OAAO1C,QAAS,CACnBK,eAAgBA,iBAGpBG,OAAOkC,OAAO1C,QAASE,gBAAgByC,8BAE1B,aAAT5C,OAEAC,QAAQ4C,WAAY,EACpB5C,QAAQ6C,YAAc3C,gBAAgBC,gBAAgB,yBAE1DK,OAAOkC,OAAO1C,QAASE,gBAAgB4C,mCAChC9C"} \ No newline at end of file diff --git a/amd/build/renderer.min.js b/amd/build/renderer.min.js index b99d2ac..7390923 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("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","itt"])}async insertUserQuotaBox(){document.querySelector('[data-rendertarget="usageinfo"]')&&await(0,_userquota.renderUserQuota)('[data-rendertarget="usageinfo"]',["singleprompt","translate","tts","imggen","itt"])}},_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.modalHeadline=BasedataHandler.getTinyAiString("aigenerating"),await this.renderModalContent("moodle-modal-body-loading","moodle-modal-footer-empty",templateContext)}async renderSuggestion(){const templateContext={};templateContext.modalHeadline=BasedataHandler.getTinyAiString("aisuggestion"),templateContext.resultText=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={modalHeadline:"",centeredHeadline:BasedataHandler.getTinyAiString("dismisssuggestion"),showIcon:!1,buttons:[{hasText:!0,buttonText:BasedataHandler.getTinyAiString("cancel"),iconLeft:!1,iconRight:!1,primary:!1,secondary:!0,tertiary:!1,action:"canceldismiss"},{hasText:!0,buttonText:BasedataHandler.getTinyAiString("dismiss"),iconLeft:!1,iconRight:!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("modalHeadline")&&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","itt"])}async insertUserQuotaBox(){document.querySelector('[data-rendertarget="usageinfo"]')&&await(0,_userquota.renderUserQuota)('[data-rendertarget="usageinfo"]',["singleprompt","translate","tts","imggen","itt"])}},_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 12eda8a..33ca5c0 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('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', 'itt']);\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', 'itt']);\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,KAAK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ASuC,cADY,0CAEf,8BAFe,kCAEmB,CAAC,eAAgB,YAAa,MAAO,SAAU"} \ No newline at end of file +{"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('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.modalHeadline = 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.modalHeadline = 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.resultText = 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 modalHeadline: '',\n centeredHeadline: BasedataHandler.getTinyAiString('dismisssuggestion'),\n showIcon: false,\n buttons: [\n {\n hasText: true,\n buttonText: BasedataHandler.getTinyAiString('cancel'),\n iconLeft: false,\n iconRight: false,\n primary: false,\n secondary: true,\n tertiary: false,\n action: 'canceldismiss'\n },\n {\n hasText: true,\n buttonText: BasedataHandler.getTinyAiString('dismiss'),\n iconLeft: false,\n iconRight: 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('modalHeadline')) {\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', 'itt']);\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', 'itt']);\n }\n }\n}\n"],"names":["constructor","uniqid","datamanager","editorUtils","reset","templateContext","this","getTemplateContext","renderModalContent","modalHeadline","BasedataHandler","getTinyAiString","resultText","renderAiResultForEditor","Object","assign","getReplaceButtonsContext","getMode","centeredHeadline","showIcon","buttons","hasText","buttonText","iconLeft","iconRight","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,cAAgBC,gBAAgBC,gBAAgB,sBAC1DL,KAAKE,mBAAm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C,aAAeC,QAAQC,IAAI,CAC7BC,mBAAUC,iBAAiB,+CAAgDlD,iBAC3EiD,mBAAUC,iBAAiB,sBAAwBb,sBAAuBrC,iBAC1EiD,mBAAUC,iBAAiB,sBAAwBZ,wBAAyBtC,mBAE5EA,gBAAgBmD,eAAe,kBAE/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,SAAU,mCAMnDxC,SAASuC,cADY,0CAEf,8BAFe,kCAEmB,CAAC,eAAgB,YAAa,MAAO,SAAU"} \ No newline at end of file diff --git a/amd/build/utils.min.js b/amd/build/utils.min.js index 893e7be..7696b7e 100644 --- a/amd/build/utils.min.js +++ b/amd/build/utils.min.js @@ -6,6 +6,6 @@ define("tiny_ai/utils",["exports","core/modal_events","tiny_ai/renderer","tiny_a * @copyright 2024, ISB Bayern * @author Dr. Peter Mayer * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.stripHtmlTags=_exports.init=_exports.getTtsHandler=_exports.getTranslateHandler=_exports.getSummarizeHandler=_exports.getStartHandler=_exports.getRenderer=_exports.getOptimizeHandler=_exports.getIttHandler=_exports.getImggenHandler=_exports.getEditorUtils=_exports.getDatamanager=_exports.getCurrentModalUniqId=_exports.getAiAnswer=_exports.errorAlert=void 0,_modal_events=_interopRequireDefault(_modal_events),_renderer=_interopRequireDefault(_renderer),_datamanager=_interopRequireDefault(_datamanager),_imggen=_interopRequireDefault(_imggen),_optimize=_interopRequireDefault(_optimize),_start=_interopRequireDefault(_start),_summarize=_interopRequireDefault(_summarize),_translate=_interopRequireDefault(_translate),_tts=_interopRequireDefault(_tts),_itt=_interopRequireDefault(_itt),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),_jquery=_interopRequireDefault(_jquery),_log=_interopRequireDefault(_log),_editor_utils=_interopRequireDefault(_editor_utils);const objectStore={};_exports.init=async(uniqid,editor)=>{objectStore.hasOwnProperty(uniqid)||(objectStore[uniqid]={},objectStore[uniqid].editorUtils=new _editor_utils.default(uniqid,editor),objectStore[uniqid].datamanager=new _datamanager.default(uniqid),await BasedataHandler.init(),objectStore[uniqid].imggenhandler=new _imggen.default(uniqid),objectStore[uniqid].optimizehandler=new _optimize.default(uniqid),objectStore[uniqid].starthandler=new _start.default(uniqid),await objectStore[uniqid].starthandler.init(),objectStore[uniqid].summarizehandler=new _summarize.default(uniqid),objectStore[uniqid].translatehandler=new _translate.default(uniqid),objectStore[uniqid].ttshandler=new _tts.default(uniqid),objectStore[uniqid].itthandler=new _itt.default(uniqid),objectStore[uniqid].renderer=new _renderer.default(uniqid))};_exports.getAiAnswer=async function(prompt,purpose){let options=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},result=null;try{result=await(0,_make_request.makeRequest)(purpose,prompt,options)}catch(exception){return void await(0,_notification.exception)(exception)}if(200!==result.code){const alertTitle=await(0,_str.getString)("errorwithcode","tiny_ai",result.code),parsedResult=JSON.parse(result.result);return parsedResult.debuginfo&&_log.default.error(parsedResult.debuginfo),await errorAlert(parsedResult.message,alertTitle),null}return result.result};const errorAlert=async function(message){let title=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;null===title&&(title=BasedataHandler.getTinyAiString("generalerror"));const alertModal=await(0,_notification.alert)(title,message);alertModal.getRoot().on(_modal_events.default.hidden,(()=>{document.querySelectorAll("button[data-action]").forEach((button=>{(0,_jquery.default)(button).tooltip("hide")}))}))};_exports.errorAlert=errorAlert;_exports.stripHtmlTags=textWithTags=>{const span=document.createElement("span");return span.innerHTML=textWithTags,span.textContent};_exports.getEditorUtils=uniqid=>objectStore[uniqid].editorUtils;_exports.getRenderer=uniqid=>objectStore[uniqid].renderer;_exports.getDatamanager=uniqid=>objectStore[uniqid].datamanager;_exports.getImggenHandler=uniqid=>objectStore[uniqid].imggenhandler;_exports.getOptimizeHandler=uniqid=>objectStore[uniqid].optimizehandler;_exports.getStartHandler=uniqid=>objectStore[uniqid].starthandler;_exports.getSummarizeHandler=uniqid=>objectStore[uniqid].summarizehandler;_exports.getTranslateHandler=uniqid=>objectStore[uniqid].translatehandler;_exports.getTtsHandler=uniqid=>objectStore[uniqid].ttshandler;_exports.getIttHandler=uniqid=>objectStore[uniqid].itthandler;_exports.getCurrentModalUniqId=element=>element.closest("[data-tiny_instance_uniqid]").dataset.tiny_instance_uniqid})); + */Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.stripHtmlTags=_exports.init=_exports.getTtsHandler=_exports.getTranslateHandler=_exports.getSummarizeHandler=_exports.getStartHandler=_exports.getRenderer=_exports.getOptimizeHandler=_exports.getIttHandler=_exports.getImggenHandler=_exports.getEditorUtils=_exports.getDatamanager=_exports.getCurrentModalUniqId=_exports.getAiAnswer=_exports.errorAlert=void 0,_modal_events=_interopRequireDefault(_modal_events),_renderer=_interopRequireDefault(_renderer),_datamanager=_interopRequireDefault(_datamanager),_imggen=_interopRequireDefault(_imggen),_optimize=_interopRequireDefault(_optimize),_start=_interopRequireDefault(_start),_summarize=_interopRequireDefault(_summarize),_translate=_interopRequireDefault(_translate),_tts=_interopRequireDefault(_tts),_itt=_interopRequireDefault(_itt),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),_jquery=_interopRequireDefault(_jquery),_log=_interopRequireDefault(_log),_editor_utils=_interopRequireDefault(_editor_utils);const objectStore={};_exports.init=async(uniqid,editor)=>{objectStore.hasOwnProperty(uniqid)||(objectStore[uniqid]={},objectStore[uniqid].editorUtils=new _editor_utils.default(uniqid,editor),objectStore[uniqid].datamanager=new _datamanager.default(uniqid),await BasedataHandler.init(),objectStore[uniqid].imggenhandler=new _imggen.default(uniqid),objectStore[uniqid].optimizehandler=new _optimize.default(uniqid),objectStore[uniqid].starthandler=new _start.default(uniqid),await objectStore[uniqid].starthandler.init(),objectStore[uniqid].summarizehandler=new _summarize.default(uniqid),objectStore[uniqid].translatehandler=new _translate.default(uniqid),objectStore[uniqid].ttshandler=new _tts.default(uniqid),objectStore[uniqid].itthandler=new _itt.default(uniqid),objectStore[uniqid].renderer=new _renderer.default(uniqid))};_exports.getAiAnswer=async function(prompt,purpose){let options=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},result=null;try{result=await(0,_make_request.makeRequest)(purpose,prompt,options)}catch(exception){return await(0,_notification.exception)(exception),null}if(200!==result.code){const alertTitle=await(0,_str.getString)("errorwithcode","tiny_ai",result.code),parsedResult=JSON.parse(result.result);return parsedResult.debuginfo&&_log.default.error(parsedResult.debuginfo),await errorAlert(parsedResult.message,alertTitle),null}return result.result};const errorAlert=async function(message){let title=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;null===title&&(title=BasedataHandler.getTinyAiString("generalerror"));const alertModal=await(0,_notification.alert)(title,message);alertModal.getRoot().on(_modal_events.default.hidden,(()=>{document.querySelectorAll("button[data-action]").forEach((button=>{(0,_jquery.default)(button).tooltip("hide")}))}))};_exports.errorAlert=errorAlert;_exports.stripHtmlTags=textWithTags=>{const span=document.createElement("span");return span.innerHTML=textWithTags,span.textContent};_exports.getEditorUtils=uniqid=>objectStore[uniqid].editorUtils;_exports.getRenderer=uniqid=>objectStore[uniqid].renderer;_exports.getDatamanager=uniqid=>objectStore[uniqid].datamanager;_exports.getImggenHandler=uniqid=>objectStore[uniqid].imggenhandler;_exports.getOptimizeHandler=uniqid=>objectStore[uniqid].optimizehandler;_exports.getStartHandler=uniqid=>objectStore[uniqid].starthandler;_exports.getSummarizeHandler=uniqid=>objectStore[uniqid].summarizehandler;_exports.getTranslateHandler=uniqid=>objectStore[uniqid].translatehandler;_exports.getTtsHandler=uniqid=>objectStore[uniqid].ttshandler;_exports.getIttHandler=uniqid=>objectStore[uniqid].itthandler;_exports.getCurrentModalUniqId=element=>element.closest("[data-tiny_instance_uniqid]").dataset.tiny_instance_uniqid})); //# sourceMappingURL=utils.min.js.map \ No newline at end of file diff --git a/amd/build/utils.min.js.map b/amd/build/utils.min.js.map index 8dbbfdc..c5ae9d0 100644 --- a/amd/build/utils.min.js.map +++ b/amd/build/utils.min.js.map @@ -1 +1 @@ -{"version":3,"file":"utils.min.js","sources":["../src/utils.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/utils\n * @copyright 2024, ISB Bayern\n * @author Dr. Peter Mayer\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nimport ModalEvents from 'core/modal_events';\nimport Renderer from 'tiny_ai/renderer';\nimport DataManager from 'tiny_ai/datamanager';\nimport ImggenHandler from 'tiny_ai/datahandler/imggen';\nimport OptimizeHandler from 'tiny_ai/datahandler/optimize';\nimport StartHandler from 'tiny_ai/datahandler/start';\nimport SummarizeHandler from 'tiny_ai/datahandler/summarize';\nimport TranslateHandler from 'tiny_ai/datahandler/translate';\nimport TtsHandler from 'tiny_ai/datahandler/tts';\nimport IttHandler from 'tiny_ai/datahandler/itt';\nimport {alert as Alert, exception as displayException} from 'core/notification';\nimport {getString} from 'core/str';\nimport {makeRequest} from 'local_ai_manager/make_request';\nimport * as BasedataHandler from 'tiny_ai/datahandler/basedata';\nimport $ from 'jquery';\nimport Log from 'core/log';\nimport EditorUtils from 'tiny_ai/editor_utils';\n\nconst objectStore = {};\n\nexport const init = async (uniqid, editor) => {\n if (!objectStore.hasOwnProperty(uniqid)) {\n objectStore[uniqid] = {};\n // The order in which these objects are being created is actually pretty important, because Renderer\n // object depends on DataManager object.\n objectStore[uniqid].editorUtils = new EditorUtils(uniqid, editor);\n objectStore[uniqid].datamanager = new DataManager(uniqid);\n await BasedataHandler.init();\n objectStore[uniqid].imggenhandler = new ImggenHandler(uniqid);\n objectStore[uniqid].optimizehandler = new OptimizeHandler(uniqid);\n objectStore[uniqid].starthandler = new StartHandler(uniqid);\n await objectStore[uniqid].starthandler.init();\n objectStore[uniqid].summarizehandler = new SummarizeHandler(uniqid);\n objectStore[uniqid].translatehandler = new TranslateHandler(uniqid);\n objectStore[uniqid].ttshandler = new TtsHandler(uniqid);\n objectStore[uniqid].itthandler = new IttHandler(uniqid);\n objectStore[uniqid].renderer = new Renderer(uniqid);\n }\n};\n\nexport const getAiAnswer = async (prompt, purpose, options = {}) => {\n let result = null;\n try {\n result = await makeRequest(purpose, prompt, options);\n } catch (exception) {\n await displayException(exception);\n return;\n }\n if (result.code !== 200) {\n const alertTitle = await getString('errorwithcode', 'tiny_ai', result.code);\n const parsedResult = JSON.parse(result.result);\n if (parsedResult.debuginfo) {\n Log.error(parsedResult.debuginfo);\n }\n await errorAlert(parsedResult.message, alertTitle);\n return null;\n }\n return result.result;\n};\n\nexport const errorAlert = async (message, title = null) => {\n if (title === null) {\n title = BasedataHandler.getTinyAiString('generalerror');\n }\n const alertModal = await Alert(title, message);\n alertModal.getRoot().on(ModalEvents.hidden, () => {\n document.querySelectorAll('button[data-action]').forEach(button => {\n $(button).tooltip('hide');\n });\n });\n};\n\nexport const stripHtmlTags = (textWithTags) => {\n // Place selected content into a temporary span and extract the plain text from it to strip HTML tags.\n const span = document.createElement('span');\n span.innerHTML = textWithTags;\n return span.textContent;\n};\n\nexport const getEditorUtils = (uniqid) => {\n return objectStore[uniqid].editorUtils;\n};\n\nexport const getRenderer = (uniqid) => {\n return objectStore[uniqid].renderer;\n};\n\nexport const getDatamanager = (uniqid) => {\n return objectStore[uniqid].datamanager;\n};\n\nexport const getImggenHandler = (uniqid) => {\n return objectStore[uniqid].imggenhandler;\n};\n\nexport const getOptimizeHandler = (uniqid) => {\n return objectStore[uniqid].optimizehandler;\n};\n\nexport const getStartHandler = (uniqid) => {\n return objectStore[uniqid].starthandler;\n};\n\nexport const getSummarizeHandler = (uniqid) => {\n return objectStore[uniqid].summarizehandler;\n};\n\nexport const getTranslateHandler = (uniqid) => {\n return objectStore[uniqid].translatehandler;\n};\n\nexport const getTtsHandler = (uniqid) => {\n return objectStore[uniqid].ttshandler;\n};\n\nexport const getIttHandler = (uniqid) => {\n return objectStore[uniqid].itthandler;\n};\n\nexport const getCurrentModalUniqId = (element) => {\n return element.closest('[data-tiny_instance_uniqid]').dataset.tiny_instance_uniqid;\n};\n"],"names":["objectStore","async","uniqid","editor","hasOwnProperty","editorUtils","EditorUtils","datamanager","DataManager","BasedataHandler","init","imggenhandler","ImggenHandler","optimizehandler","OptimizeHandler","starthandler","StartHandler","summarizehandler","SummarizeHandler","translatehandler","TranslateHandler","ttshandler","TtsHandler","itthandler","IttHandler","renderer","Renderer","prompt","purpose","options","result","exception","code","alertTitle","parsedResult","JSON","parse","debuginfo","error","errorAlert","message","title","getTinyAiString","alertModal","getRoot","on","ModalEvents","hidden","document","querySelectorAll","forEach","button","tooltip","textWithTags","span","createElement","innerHTML","textContent","element","closest","dataset","tiny_instance_uniqid"],"mappings":";;;;;;;;2oDA0CMA,YAAc,iBAEAC,MAAOC,OAAQC,UAC1BH,YAAYI,eAAeF,UAC5BF,YAAYE,QAAU,GAGtBF,YAAYE,QAAQG,YAAc,IAAIC,sBAAYJ,OAAQC,QAC1DH,YAAYE,QAAQK,YAAc,IAAIC,qBAAYN,cAC5CO,gBAAgBC,OACtBV,YAAYE,QAAQS,cAAgB,IAAIC,gBAAcV,QACtDF,YAAYE,QAAQW,gBAAkB,IAAIC,kBAAgBZ,QAC1DF,YAAYE,QAAQa,aAAe,IAAIC,eAAad,cAC9CF,YAAYE,QAAQa,aAAaL,OACvCV,YAAYE,QAAQe,iBAAmB,IAAIC,mBAAiBhB,QAC5DF,YAAYE,QAAQiB,iBAAmB,IAAIC,mBAAiBlB,QAC5DF,YAAYE,QAAQmB,WAAa,IAAIC,aAAWpB,QAChDF,YAAYE,QAAQqB,WAAa,IAAIC,aAAWtB,QAChDF,YAAYE,QAAQuB,SAAW,IAAIC,kBAASxB,+BAIzBD,eAAO0B,OAAQC,aAASC,+DAAU,GACrDC,OAAS,SAETA,aAAe,6BAAYF,QAASD,OAAQE,SAC9C,MAAOE,6BACC,2BAAiBA,cAGP,MAAhBD,OAAOE,KAAc,OACfC,iBAAmB,kBAAU,gBAAiB,UAAWH,OAAOE,MAChEE,aAAeC,KAAKC,MAAMN,OAAOA,eACnCI,aAAaG,wBACTC,MAAMJ,aAAaG,iBAErBE,WAAWL,aAAaM,QAASP,YAChC,YAEJH,OAAOA,cAGLS,WAAatC,eAAOuC,aAASC,6DAAQ,KAChC,OAAVA,QACAA,MAAQhC,gBAAgBiC,gBAAgB,uBAEtCC,iBAAmB,uBAAMF,MAAOD,SACtCG,WAAWC,UAAUC,GAAGC,sBAAYC,QAAQ,KACxCC,SAASC,iBAAiB,uBAAuBC,SAAQC,6BACnDA,QAAQC,QAAQ,qEAKAC,qBAEpBC,KAAON,SAASO,cAAc,eACpCD,KAAKE,UAAYH,aACVC,KAAKG,qCAGevD,QACpBF,YAAYE,QAAQG,iCAGHH,QACjBF,YAAYE,QAAQuB,iCAGAvB,QACpBF,YAAYE,QAAQK,sCAGEL,QACtBF,YAAYE,QAAQS,0CAGIT,QACxBF,YAAYE,QAAQW,yCAGCX,QACrBF,YAAYE,QAAQa,0CAGKb,QACzBF,YAAYE,QAAQe,8CAGKf,QACzBF,YAAYE,QAAQiB,wCAGDjB,QACnBF,YAAYE,QAAQmB,kCAGDnB,QACnBF,YAAYE,QAAQqB,0CAGOmC,SAC3BA,QAAQC,QAAQ,+BAA+BC,QAAQC"} \ No newline at end of file +{"version":3,"file":"utils.min.js","sources":["../src/utils.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/utils\n * @copyright 2024, ISB Bayern\n * @author Dr. Peter Mayer\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nimport ModalEvents from 'core/modal_events';\nimport Renderer from 'tiny_ai/renderer';\nimport DataManager from 'tiny_ai/datamanager';\nimport ImggenHandler from 'tiny_ai/datahandler/imggen';\nimport OptimizeHandler from 'tiny_ai/datahandler/optimize';\nimport StartHandler from 'tiny_ai/datahandler/start';\nimport SummarizeHandler from 'tiny_ai/datahandler/summarize';\nimport TranslateHandler from 'tiny_ai/datahandler/translate';\nimport TtsHandler from 'tiny_ai/datahandler/tts';\nimport IttHandler from 'tiny_ai/datahandler/itt';\nimport {alert as moodleAlert, exception as displayException} from 'core/notification';\nimport {getString} from 'core/str';\nimport {makeRequest} from 'local_ai_manager/make_request';\nimport * as BasedataHandler from 'tiny_ai/datahandler/basedata';\nimport $ from 'jquery';\nimport Log from 'core/log';\nimport EditorUtils from 'tiny_ai/editor_utils';\n\nconst objectStore = {};\n\nexport const init = async(uniqid, editor) => {\n if (!objectStore.hasOwnProperty(uniqid)) {\n objectStore[uniqid] = {};\n // The order in which these objects are being created is actually pretty important, because Renderer\n // object depends on DataManager object.\n objectStore[uniqid].editorUtils = new EditorUtils(uniqid, editor);\n objectStore[uniqid].datamanager = new DataManager(uniqid);\n await BasedataHandler.init();\n objectStore[uniqid].imggenhandler = new ImggenHandler(uniqid);\n objectStore[uniqid].optimizehandler = new OptimizeHandler(uniqid);\n objectStore[uniqid].starthandler = new StartHandler(uniqid);\n await objectStore[uniqid].starthandler.init();\n objectStore[uniqid].summarizehandler = new SummarizeHandler(uniqid);\n objectStore[uniqid].translatehandler = new TranslateHandler(uniqid);\n objectStore[uniqid].ttshandler = new TtsHandler(uniqid);\n objectStore[uniqid].itthandler = new IttHandler(uniqid);\n objectStore[uniqid].renderer = new Renderer(uniqid);\n }\n};\n\nexport const getAiAnswer = async(prompt, purpose, options = {}) => {\n let result = null;\n try {\n result = await makeRequest(purpose, prompt, options);\n } catch (exception) {\n await displayException(exception);\n return null;\n }\n if (result.code !== 200) {\n const alertTitle = await getString('errorwithcode', 'tiny_ai', result.code);\n const parsedResult = JSON.parse(result.result);\n if (parsedResult.debuginfo) {\n Log.error(parsedResult.debuginfo);\n }\n await errorAlert(parsedResult.message, alertTitle);\n return null;\n }\n return result.result;\n};\n\nexport const errorAlert = async(message, title = null) => {\n if (title === null) {\n title = BasedataHandler.getTinyAiString('generalerror');\n }\n const alertModal = await moodleAlert(title, message);\n alertModal.getRoot().on(ModalEvents.hidden, () => {\n document.querySelectorAll('button[data-action]').forEach(button => {\n $(button).tooltip('hide');\n });\n });\n};\n\nexport const stripHtmlTags = (textWithTags) => {\n // Place selected content into a temporary span and extract the plain text from it to strip HTML tags.\n const span = document.createElement('span');\n span.innerHTML = textWithTags;\n return span.textContent;\n};\n\nexport const getEditorUtils = (uniqid) => {\n return objectStore[uniqid].editorUtils;\n};\n\nexport const getRenderer = (uniqid) => {\n return objectStore[uniqid].renderer;\n};\n\nexport const getDatamanager = (uniqid) => {\n return objectStore[uniqid].datamanager;\n};\n\nexport const getImggenHandler = (uniqid) => {\n return objectStore[uniqid].imggenhandler;\n};\n\nexport const getOptimizeHandler = (uniqid) => {\n return objectStore[uniqid].optimizehandler;\n};\n\nexport const getStartHandler = (uniqid) => {\n return objectStore[uniqid].starthandler;\n};\n\nexport const getSummarizeHandler = (uniqid) => {\n return objectStore[uniqid].summarizehandler;\n};\n\nexport const getTranslateHandler = (uniqid) => {\n return objectStore[uniqid].translatehandler;\n};\n\nexport const getTtsHandler = (uniqid) => {\n return objectStore[uniqid].ttshandler;\n};\n\nexport const getIttHandler = (uniqid) => {\n return objectStore[uniqid].itthandler;\n};\n\nexport const getCurrentModalUniqId = (element) => {\n return element.closest('[data-tiny_instance_uniqid]').dataset.tiny_instance_uniqid;\n};\n"],"names":["objectStore","async","uniqid","editor","hasOwnProperty","editorUtils","EditorUtils","datamanager","DataManager","BasedataHandler","init","imggenhandler","ImggenHandler","optimizehandler","OptimizeHandler","starthandler","StartHandler","summarizehandler","SummarizeHandler","translatehandler","TranslateHandler","ttshandler","TtsHandler","itthandler","IttHandler","renderer","Renderer","prompt","purpose","options","result","exception","code","alertTitle","parsedResult","JSON","parse","debuginfo","error","errorAlert","message","title","getTinyAiString","alertModal","getRoot","on","ModalEvents","hidden","document","querySelectorAll","forEach","button","tooltip","textWithTags","span","createElement","innerHTML","textContent","element","closest","dataset","tiny_instance_uniqid"],"mappings":";;;;;;;;2oDA0CMA,YAAc,iBAEAC,MAAMC,OAAQC,UACzBH,YAAYI,eAAeF,UAC5BF,YAAYE,QAAU,GAGtBF,YAAYE,QAAQG,YAAc,IAAIC,sBAAYJ,OAAQC,QAC1DH,YAAYE,QAAQK,YAAc,IAAIC,qBAAYN,cAC5CO,gBAAgBC,OACtBV,YAAYE,QAAQS,cAAgB,IAAIC,gBAAcV,QACtDF,YAAYE,QAAQW,gBAAkB,IAAIC,kBAAgBZ,QAC1DF,YAAYE,QAAQa,aAAe,IAAIC,eAAad,cAC9CF,YAAYE,QAAQa,aAAaL,OACvCV,YAAYE,QAAQe,iBAAmB,IAAIC,mBAAiBhB,QAC5DF,YAAYE,QAAQiB,iBAAmB,IAAIC,mBAAiBlB,QAC5DF,YAAYE,QAAQmB,WAAa,IAAIC,aAAWpB,QAChDF,YAAYE,QAAQqB,WAAa,IAAIC,aAAWtB,QAChDF,YAAYE,QAAQuB,SAAW,IAAIC,kBAASxB,+BAIzBD,eAAM0B,OAAQC,aAASC,+DAAU,GACpDC,OAAS,SAETA,aAAe,6BAAYF,QAASD,OAAQE,SAC9C,MAAOE,wBACC,2BAAiBA,WAChB,QAES,MAAhBD,OAAOE,KAAc,OACfC,iBAAmB,kBAAU,gBAAiB,UAAWH,OAAOE,MAChEE,aAAeC,KAAKC,MAAMN,OAAOA,eACnCI,aAAaG,wBACTC,MAAMJ,aAAaG,iBAErBE,WAAWL,aAAaM,QAASP,YAChC,YAEJH,OAAOA,cAGLS,WAAatC,eAAMuC,aAASC,6DAAQ,KAC/B,OAAVA,QACAA,MAAQhC,gBAAgBiC,gBAAgB,uBAEtCC,iBAAmB,uBAAYF,MAAOD,SAC5CG,WAAWC,UAAUC,GAAGC,sBAAYC,QAAQ,KACxCC,SAASC,iBAAiB,uBAAuBC,SAAQC,6BACnDA,QAAQC,QAAQ,qEAKAC,qBAEpBC,KAAON,SAASO,cAAc,eACpCD,KAAKE,UAAYH,aACVC,KAAKG,qCAGevD,QACpBF,YAAYE,QAAQG,iCAGHH,QACjBF,YAAYE,QAAQuB,iCAGAvB,QACpBF,YAAYE,QAAQK,sCAGEL,QACtBF,YAAYE,QAAQS,0CAGIT,QACxBF,YAAYE,QAAQW,yCAGCX,QACrBF,YAAYE,QAAQa,0CAGKb,QACzBF,YAAYE,QAAQe,8CAGKf,QACzBF,YAAYE,QAAQiB,wCAGDjB,QACnBF,YAAYE,QAAQmB,kCAGDnB,QACnBF,YAAYE,QAAQqB,0CAGOmC,SAC3BA,QAAQC,QAAQ,+BAA+BC,QAAQC"} \ No newline at end of file diff --git a/amd/src/commands.js b/amd/src/commands.js index 2896c5c..8cd3efa 100644 --- a/amd/src/commands.js +++ b/amd/src/commands.js @@ -89,10 +89,5 @@ export const getSetup = async() => { Utils.getEditorUtils(uniqid).displayDialogue(selectionbarSource); } }); - - // editor.on('init', () => onInit(editor)); - // editor.on('BeforeGetContent', format => onBeforeGetContent(format)); - // editor.on('submit', () => onSubmit()); - }; }; diff --git a/amd/src/configuration.js b/amd/src/configuration.js index 181faad..255d567 100644 --- a/amd/src/configuration.js +++ b/amd/src/configuration.js @@ -65,6 +65,7 @@ export const configure = (instanceConfig) => { return { toolbar: getToolbarConfiguration(instanceConfig), menu: getMenuConfiguration(instanceConfig), + // eslint-disable-next-line camelcase quickbars_selection_toolbar: getSelectionToolbarConfiguration(instanceConfig) }; }; diff --git a/amd/src/controllers/optimize.js b/amd/src/controllers/optimize.js index 56887ac..b177c8d 100644 --- a/amd/src/controllers/optimize.js +++ b/amd/src/controllers/optimize.js @@ -37,7 +37,7 @@ export default class extends BaseController { } if (generateButton) { - generateButton.addEventListener('click', async () => { + generateButton.addEventListener('click', async() => { const result = await this.generateAiAnswer(); if (result === null) { return; diff --git a/amd/src/controllers/preferences.js b/amd/src/controllers/preferences.js index 9a4569b..279bf56 100644 --- a/amd/src/controllers/preferences.js +++ b/amd/src/controllers/preferences.js @@ -52,12 +52,12 @@ export default class extends BaseController { 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) => { + 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) => { + languageTypeElement.addEventListener('dropdownSelectionUpdated', async(event) => { summarizeHandler.setLanguageType(event.detail.newValue); const currentPrompt = await summarizeHandler.getPrompt(this.datamanager.getSelectionText()); this.datamanager.setCurrentPrompt(currentPrompt); @@ -69,7 +69,7 @@ export default class extends BaseController { 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) => { + targetLanguageElement.addEventListener('dropdownSelectionUpdated', async(event) => { translateHandler.setTargetLanguage(event.detail.newValue); const currentPromptTranslate = await translateHandler.getPrompt(this.datamanager.getSelectionText()); this.datamanager.setCurrentPrompt(currentPromptTranslate); @@ -125,7 +125,7 @@ export default class extends BaseController { case 'imagetotext': { const fileUploadArea = this.baseElement.querySelector('[data-preference="fileupload"]'); if (fileUploadArea) { - this.datamanager.getEventEmitterElement().addEventListener('fileUploaded', async (event) => { + this.datamanager.getEventEmitterElement().addEventListener('fileUploaded', async(event) => { this.datamanager.setCurrentFile(event.detail.newFile); this.datamanager.setCurrentOptions(ittHandler.getOptions()); }); @@ -137,13 +137,13 @@ export default class extends BaseController { } if (backButton) { - backButton.addEventListener('click', async () => { + backButton.addEventListener('click', async() => { await this.renderer.renderStart(constants.modalModes.selection); }); } if (generateButton) { - generateButton.addEventListener('click', async () => { + generateButton.addEventListener('click', async() => { const result = await this.generateAiAnswer(); if (result === null) { return; diff --git a/amd/src/controllers/start.js b/amd/src/controllers/start.js index 22819e1..9f5efc7 100644 --- a/amd/src/controllers/start.js +++ b/amd/src/controllers/start.js @@ -48,7 +48,7 @@ export default class extends BaseController { const startHandler = getStartHandler(this.uniqid); if (!(await startHandler.isTinyAiDisabled())) { - if(window.matchMedia("(pointer: coarse)").matches) { + if (window.matchMedia("(pointer: coarse)").matches) { // If we have a touch device, we need to manually trigger the tooltips by touching the cards. document.querySelectorAll('.tiny_ai-card-button.disabled').forEach(button => { button.parentElement.addEventListener( @@ -109,7 +109,7 @@ export default class extends BaseController { } if (freePromptButton) { if (!freePromptButton.classList.contains('disabled')) { - freePromptButton.addEventListener('click', async () => { + freePromptButton.addEventListener('click', async() => { this.datamanager.setCurrentTool('freeprompt'); this.datamanager.setCurrentPrompt(this.baseElement.querySelector('[data-type="freepromptinput"]').value); const result = await this.generateAiAnswer(); diff --git a/amd/src/datahandler/basedata.js b/amd/src/datahandler/basedata.js index 3923a04..fbf28b0 100644 --- a/amd/src/datahandler/basedata.js +++ b/amd/src/datahandler/basedata.js @@ -59,9 +59,9 @@ const stringKeys = [ 'imggen_headline', 'imggen_placeholder', 'insertatcaret', - 'insertatcaretbutton_tooltip', + 'insertatcaret_tooltip', 'insertbelow', - 'insertbelowbutton_tooltip', + 'insertbelow_tooltip', 'keeplanguagetype', 'languagetype', 'languagetype_prompt', @@ -100,9 +100,7 @@ const stringKeys = [ 'voice' ]; -let strings = {}; - - +let strings = new Map(); export const init = async() => { prefetchStrings('tiny_ai', stringKeys); @@ -112,113 +110,44 @@ export const init = async() => { // We now get the strings. They are already prefetched, so this is not a performance feature. // We just use this to avoid having to code asynchronously all the time just for retrieving the // strings by using getString which returns a promise. - [ - 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.imagefromeditor, - strings.imagetotext_baseprompt, - strings.imagetotext_headline, - strings.imagetotext_insertimage, - 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_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 getStrings(stringRequest); + const fetchedStrings = await getStrings(stringRequest); + for (let i = 0; i < stringKeys.length; i++) { + strings.set(stringKeys[i], fetchedStrings[i]); + } }; export const getTinyAiString = (string) => { - return strings[string]; + return strings.get(string); }; export const getBackAndGenerateButtonContext = () => { return { - footer_buttons: [ + footerButtons: [ { hasText: true, - button_text: strings.back, - icon_left: true, - icon_right: false, + buttonText: getTinyAiString('back'), + iconLeft: true, + iconRight: false, primary: false, secondary: false, tertiary: true, iconname: 'arrow-left', iconstyle: 'solid', action: 'back', - tooltip: strings.backbutton_tooltip + tooltip: getTinyAiString('backbutton_tooltip') }, { hasText: true, - button_text: strings.generate, - icon_left: true, - icon_right: false, + buttonText: getTinyAiString('generate'), + iconLeft: true, + iconRight: false, primary: true, secondary: false, tertiary: false, iconname: 'sparkle', customicon: true, action: 'generate', - tooltip: strings.generatebutton_tooltip + tooltip: getTinyAiString('generatebutton_tooltip') } ] }; @@ -226,44 +155,45 @@ export const getBackAndGenerateButtonContext = () => { export const getReplaceButtonsContext = (mode) => { - return { - footer_iconbuttons: + return { + footerIconButtons: [ { action: 'delete', iconname: 'trash', - tooltip: strings.deletebutton_tooltip + tooltip: getTinyAiString('deletebutton_tooltip') }, { action: 'regenerate', iconname: 'arrows-rotate', - tooltip: strings.regeneratebutton_tooltip + tooltip: getTinyAiString('regeneratebutton_tooltip') } ], - footer_buttons: + footerButtons: [ { action: 'insertbelow', hasText: true, - button_text: strings.insertbelow, - icon_left: true, - icon_right: false, + buttonText: getTinyAiString('insertbelow'), + iconLeft: true, + iconRight: false, secondary: true, iconname: 'text-insert-last', customicon: true, - tooltip: strings.insertbelow_tooltip + tooltip: getTinyAiString('insertbelow_tooltip') }, { action: mode === constants.modalModes.selection ? 'replace' : 'insertatcaret', hasText: true, - button_text: mode === constants.modalModes.selection ? strings.replaceselection : strings.insertatcaret, - icon_left: true, - icon_right: false, + buttonText: mode === constants.modalModes.selection + ? getTinyAiString('replaceselection') : getTinyAiString('insertatcaret'), + iconLeft: true, + iconRight: false, primary: true, iconname: 'check', iconstyle: 'solid', tooltip: mode === constants.modalModes.selection - ? strings.replaceselection_tooltip : strings.insertatcaret_tooltip + ? getTinyAiString('replaceselection_tooltip') : getTinyAiString('insertatcaret_tooltip') } ], }; @@ -280,9 +210,9 @@ export const getInputContext = () => { customicon: false, iconname: 'arrow-right', iconstyle: 'solid', - icon_left: false, - icon_right: true, - tooltip: strings.freepromptbutton_tooltip + iconLeft: false, + iconRight: true, + tooltip: getTinyAiString('freepromptbutton_tooltip') } ] } @@ -293,15 +223,15 @@ export const getInputContext = () => { export const getShowPromptButtonContext = () => { return { hasText: true, - button_text: strings.showprompt, - icon_left: true, - icon_right: false, + buttonText: getTinyAiString('showprompt'), + iconLeft: true, + iconRight: false, tertiary: true, iconname: 'eye', iconstyle: 'solid', action: 'showprompt', textareatype: 'prompt', collapsed: true, - tooltip: strings.showpromptbutton_tooltip + tooltip: getTinyAiString('showpromptbutton_tooltip') }; }; diff --git a/amd/src/datahandler/imggen.js b/amd/src/datahandler/imggen.js index 110d2c2..baee412 100644 --- a/amd/src/datahandler/imggen.js +++ b/amd/src/datahandler/imggen.js @@ -47,7 +47,7 @@ export default class extends BaseHandler { } const options = {}; if (this.size) { - options['sizes'] = [this.size]; + options.sizes = [this.size]; } return options; } @@ -61,7 +61,7 @@ export default class extends BaseHandler { async getTemplateContext() { const context = { - modal_headline: BasedataHandler.getTinyAiString('imggen_headline'), + modalHeadline: BasedataHandler.getTinyAiString('imggen_headline'), showIcon: true, tool: 'imggen', textareatype: 'prompt', @@ -74,9 +74,9 @@ export default class extends BaseHandler { if (sizesOptions !== null && Object.keys(sizesOptions).length > 0) { const sizesDropdownContext = {}; sizesDropdownContext.preference = 'sizes'; - sizesDropdownContext.dropdown_default = sizesOptions[0]['displayname']; - sizesDropdownContext.dropdown_default_value = sizesOptions[0]['key']; - sizesDropdownContext.dropdown_description = BasedataHandler.getTinyAiString('size'); + sizesDropdownContext.dropdownDefault = sizesOptions[0].displayname; + sizesDropdownContext.dropdownDefaultValue = sizesOptions[0].key; + sizesDropdownContext.dropdownDescription = BasedataHandler.getTinyAiString('size'); const sizesDropdownOptions = []; sizesOptions.forEach(option => { sizesDropdownOptions.push({ @@ -84,7 +84,7 @@ export default class extends BaseHandler { optionLabel: option.displayname, }); }); - sizesDropdownContext.dropdown_options = sizesDropdownOptions; + sizesDropdownContext.dropdownOptions = sizesDropdownOptions; modalDropdowns.push(sizesDropdownContext); } // In the imggen view the dropdowns are at the bottom, so we need to make the dropdowns dropup instead of dropdown. @@ -94,7 +94,7 @@ export default class extends BaseHandler { }); Object.assign(context, { - modal_dropdowns: modalDropdowns + modalDropdowns: modalDropdowns }); Object.assign(context, BasedataHandler.getBackAndGenerateButtonContext()); return context; diff --git a/amd/src/datahandler/itt.js b/amd/src/datahandler/itt.js index 570fff8..dd62a9d 100644 --- a/amd/src/datahandler/itt.js +++ b/amd/src/datahandler/itt.js @@ -66,7 +66,7 @@ export default class extends BaseHandler { */ async getTemplateContext(tool) { const context = { - modal_headline: BasedataHandler.getTinyAiString(tool + '_headline'), + modalHeadline: BasedataHandler.getTinyAiString(tool + '_headline'), showIcon: true, tool: tool, textareatype: 'prompt', diff --git a/amd/src/datahandler/optimize.js b/amd/src/datahandler/optimize.js index b16c357..1caf63d 100644 --- a/amd/src/datahandler/optimize.js +++ b/amd/src/datahandler/optimize.js @@ -29,7 +29,7 @@ export default class extends BaseHandler { getTemplateContext = () => { const context = { - modal_headline: BasedataHandler.getTinyAiString('reworkprompt'), + modalHeadline: BasedataHandler.getTinyAiString('reworkprompt'), showIcon: true, textareatype: 'prompt' }; diff --git a/amd/src/datahandler/start.js b/amd/src/datahandler/start.js index fd361b4..5a4f0ee 100644 --- a/amd/src/datahandler/start.js +++ b/amd/src/datahandler/start.js @@ -45,7 +45,7 @@ export default class extends BaseHandler { ]; aiConfig = null; - strings = {}; + strings = new Map(); async init() { this.aiConfig = await getAiConfig(); @@ -55,22 +55,17 @@ export default class extends BaseHandler { return {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 getStrings(stringRequest); - this.strings.error_editor_notavailable = await getString('error_tiny_ai_notavailable', 'tiny_ai'); + const fetchedStrings = await getStrings(stringRequest); + for (let i = 0; i < this.stringKeys.length; i++) { + this.strings.set(this.stringKeys[i], fetchedStrings[i]); + } + const tinyNotAvailableString = await getString('error_tiny_ai_notavailable', 'tiny_ai'); + this.strings.set('error_editor_notavailable', tinyNotAvailableString); const confirmLink = document.createElement('a'); confirmLink.href = `${config.wwwroot}/local/ai_manager/confirm_ai_usage.php`; - confirmLink.innerText = this.strings.error_pleaseconfirm; + confirmLink.innerText = this.strings.get('error_pleaseconfirm'); confirmLink.target = '_blank'; - this.strings.combinedusernotconfirmederror = this.strings.error_usernotconfirmed + ' ' + confirmLink.outerHTML; + this.strings.set('combinedusernotconfirmederror', this.strings.get('error_usernotconfirmed') + ' ' + confirmLink.outerHTML); } getPurposeConfig(tool) { @@ -78,18 +73,18 @@ export default class extends BaseHandler { throw new Error('Coding error: init function was not called before accessing this.getPurposeConfig!'); } const toolPurpose = constants.toolPurposeMapping[tool]; - return this.aiConfig.purposes.filter(purpose => purpose['purpose'] === toolPurpose)[0]; + return this.aiConfig.purposes.filter(purpose => purpose.purpose === toolPurpose)[0]; } isTinyAiDisabled() { if (!this.aiConfig.tenantenabled) { - return this.strings.error_tenantdisabled; + return this.strings.get('error_tenantdisabled'); } if (!this.aiConfig.userconfirmed) { - return this.strings.combinedusernotconfirmederror; + return this.strings.get('combinedusernotconfirmederror'); } if (this.aiConfig.userlocked) { - return this.strings.error_userlocked; + return this.strings.get('error_userlocked'); } return ''; } @@ -100,18 +95,18 @@ export default class extends BaseHandler { } const purposeInfo = this.getPurposeConfig(tool); if (!purposeInfo.isconfigured) { - return this.strings.error_purposenotconfigured; + return this.strings.get('error_purposenotconfigured'); } if (purposeInfo.limitreached) { - return this.strings.error_limitreached; + return this.strings.get('error_limitreached'); } if (mode === constants.modalModes.selection) { return ['audiogen', 'imggen'] - .includes(tool) ? this.strings.error_unavailable_noselection : ''; + .includes(tool) ? this.strings.get('error_unavailable_noselection') : ''; } else if (mode === constants.modalModes.general) { return ['summarize', 'translate', 'describe', 'tts'] - .includes(tool) ? this.strings.error_unavailable_selection : ''; + .includes(tool) ? this.strings.get('error_unavailable_selection') : ''; } return ''; } @@ -246,17 +241,19 @@ export default class extends BaseHandler { const templateContext = { showIcon: true, - modal_headline: BasedataHandler.getTinyAiString('mainselection_heading'), + modalHeadline: BasedataHandler.getTinyAiString('mainselection_heading'), action: 'loadfreeprompt', - modal_buttons: toolButtons, + modalButtons: toolButtons, freeprompthidden: true }; + Object.assign(templateContext, BasedataHandler.getInputContext()); if (this.isTinyAiDisabled()) { templateContext.input[0].disabled = true; templateContext.input[0].hasError = true; templateContext.input[0].errorMessage = this.isTinyAiDisabled(); } + if (this.isToolDisabled('freeprompt', mode)) { templateContext.input[0].disabled = true; } diff --git a/amd/src/datahandler/summarize.js b/amd/src/datahandler/summarize.js index 17051af..71754dc 100644 --- a/amd/src/datahandler/summarize.js +++ b/amd/src/datahandler/summarize.js @@ -40,13 +40,13 @@ export default class extends BaseHandler { getMaxWordCountOptions() { return { - 0: BasedataHandler.getTinyAiString('nomaxwordcount'), - 10: '10', - 20: '20', - 50: '50', - 100: '100', - 200: '200', - 300: '300' + '0': BasedataHandler.getTinyAiString('nomaxwordcount'), + '10': '10', + '20': '20', + '50': '50', + '100': '100', + '200': '200', + '300': '300' }; } @@ -100,7 +100,7 @@ export default class extends BaseHandler { getTemplateContext(tool) { const context = { - modal_headline: BasedataHandler.getTinyAiString(tool + '_headline'), + modalHeadline: BasedataHandler.getTinyAiString(tool + '_headline'), showIcon: true, tool: tool, }; @@ -119,9 +119,9 @@ export default class extends BaseHandler { const maxWordCountDropdownContext = {}; maxWordCountDropdownContext.preference = 'maxWordCount'; - maxWordCountDropdownContext.dropdown_default = Object.values(this.getMaxWordCountOptions())[0]; - maxWordCountDropdownContext.dropdown_default_value = Object.keys(this.getMaxWordCountOptions())[0]; - maxWordCountDropdownContext.dropdown_description = 'MAXIMALE WORTANZAHL'; + maxWordCountDropdownContext.dropdownDefault = Object.values(this.getMaxWordCountOptions())[0]; + maxWordCountDropdownContext.dropdownDefaultValue = Object.keys(this.getMaxWordCountOptions())[0]; + maxWordCountDropdownContext.dropdownDescription = 'MAXIMALE WORTANZAHL'; const maxWordCountDropdownOptions = []; for (const [key, value] of Object.entries(this.getMaxWordCountOptions())) { @@ -132,13 +132,13 @@ export default class extends BaseHandler { } delete maxWordCountDropdownOptions[Object.keys(this.getLanguageTypeOptions())[0]]; - maxWordCountDropdownContext.dropdown_options = maxWordCountDropdownOptions; + maxWordCountDropdownContext.dropdownOptions = maxWordCountDropdownOptions; const languageTypeDropdownContext = {}; languageTypeDropdownContext.preference = 'languageType'; - languageTypeDropdownContext.dropdown_default = Object.values(this.getLanguageTypeOptions())[0]; - languageTypeDropdownContext.dropdown_default_value = Object.keys(this.getLanguageTypeOptions())[0]; - languageTypeDropdownContext.dropdown_description = 'ART DER SPRACHE'; + languageTypeDropdownContext.dropdownDefault = Object.values(this.getLanguageTypeOptions())[0]; + languageTypeDropdownContext.dropdownDefaultValue = Object.keys(this.getLanguageTypeOptions())[0]; + languageTypeDropdownContext.dropdownDescription = 'ART DER SPRACHE'; const languageTypeDropdownOptions = []; for (const [key, value] of Object.entries(this.getLanguageTypeOptions())) { languageTypeDropdownOptions.push({ @@ -147,11 +147,11 @@ export default class extends BaseHandler { }); } delete languageTypeDropdownOptions[Object.keys(this.getLanguageTypeOptions)[0]]; - languageTypeDropdownContext.dropdown_options = languageTypeDropdownOptions; + languageTypeDropdownContext.dropdownOptions = languageTypeDropdownOptions; Object.assign(context, { - modal_dropdowns: [ + modalDropdowns: [ maxWordCountDropdownContext, languageTypeDropdownContext, ] diff --git a/amd/src/datahandler/translate.js b/amd/src/datahandler/translate.js index a47db0c..fa240a2 100644 --- a/amd/src/datahandler/translate.js +++ b/amd/src/datahandler/translate.js @@ -59,15 +59,15 @@ export default class extends BaseHandler { getTemplateContext() { const translateHandler = getTranslateHandler(this.uniqid); const context = { - modal_headline: BasedataHandler.getTinyAiString('translate_headline'), + modalHeadline: BasedataHandler.getTinyAiString('translate_headline'), showIcon: true, tool: 'translate', }; const targetLanguageDropdownContext = {}; targetLanguageDropdownContext.preference = 'targetLanguage'; - targetLanguageDropdownContext.dropdown_default = translateHandler.targetLanguageOptions[0].value; - targetLanguageDropdownContext.dropdown_default_value = translateHandler.targetLanguageOptions[0].key; - targetLanguageDropdownContext.dropdown_description = BasedataHandler.getTinyAiString('targetlanguage'); + targetLanguageDropdownContext.dropdownDefault = translateHandler.targetLanguageOptions[0].value; + targetLanguageDropdownContext.dropdownDefaultValue = translateHandler.targetLanguageOptions[0].key; + targetLanguageDropdownContext.dropdownDescription = BasedataHandler.getTinyAiString('targetlanguage'); const targetLanguageDropdownOptions = []; translateHandler.targetLanguageOptions.forEach(languageEntry => { targetLanguageDropdownOptions.push({ @@ -75,10 +75,10 @@ export default class extends BaseHandler { optionLabel: languageEntry.value, }); }); - targetLanguageDropdownContext.dropdown_options = targetLanguageDropdownOptions; + targetLanguageDropdownContext.dropdownOptions = targetLanguageDropdownOptions; Object.assign(context, { - modal_dropdowns: [ + modalDropdowns: [ targetLanguageDropdownContext, ] }); diff --git a/amd/src/datahandler/tts.js b/amd/src/datahandler/tts.js index dee23f8..a287ade 100644 --- a/amd/src/datahandler/tts.js +++ b/amd/src/datahandler/tts.js @@ -68,13 +68,13 @@ export default class extends BaseHandler { } const options = {}; if (this.targetLanguage) { - options['languages'] = [this.targetLanguage]; + options.languages = [this.targetLanguage]; } if (this.voice) { - options['voices'] = [this.voice]; + options.voices = [this.voice]; } if (this.gender) { - options['gender'] = [this.gender]; + options.gender = [this.gender]; } return options; } @@ -99,7 +99,7 @@ export default class extends BaseHandler { */ async getTemplateContext(tool) { const context = { - modal_headline: BasedataHandler.getTinyAiString(tool + '_headline'), + modalHeadline: BasedataHandler.getTinyAiString(tool + '_headline'), showIcon: true, tool: tool, }; @@ -111,15 +111,15 @@ export default class extends BaseHandler { const targetLanguageDropdownContext = {}; targetLanguageDropdownContext.preference = 'targetLanguage'; let indexOfLanguageOption = 0; - const matchingEntry = targetLanguageOptions.map(entry => entry['key'].startsWith(Config.language)); + const matchingEntry = targetLanguageOptions.map(entry => entry.key.startsWith(Config.language)); if (matchingEntry.length > 0) { // Language keys are of the form de-DE, so we check, if current user's language starts with same language code. - indexOfLanguageOption = targetLanguageOptions.findIndex(value => value['key'].startsWith(Config.language)); + indexOfLanguageOption = targetLanguageOptions.findIndex(value => value.key.startsWith(Config.language)); } - targetLanguageDropdownContext.dropdown_default = targetLanguageOptions[indexOfLanguageOption]['displayname']; - targetLanguageDropdownContext.dropdown_default_value = targetLanguageOptions[indexOfLanguageOption]['key']; - targetLanguageDropdownContext.dropdown_description = BasedataHandler.getTinyAiString('targetlanguage'); + targetLanguageDropdownContext.dropdownDefault = targetLanguageOptions[indexOfLanguageOption].displayname; + targetLanguageDropdownContext.dropdownDefaultValue = targetLanguageOptions[indexOfLanguageOption].key; + targetLanguageDropdownContext.dropdownDescription = BasedataHandler.getTinyAiString('targetlanguage'); const targetLanguageDropdownOptions = []; targetLanguageOptions.forEach(option => { targetLanguageDropdownOptions.push({ @@ -127,7 +127,7 @@ export default class extends BaseHandler { optionLabel: option.displayname, }); }); - targetLanguageDropdownContext.dropdown_options = targetLanguageDropdownOptions; + targetLanguageDropdownContext.dropdownOptions = targetLanguageDropdownOptions; modalDropdowns.push(targetLanguageDropdownContext); } @@ -135,9 +135,9 @@ export default class extends BaseHandler { if (voiceOptions !== null && Object.keys(voiceOptions).length > 0) { const voiceDropdownContext = {}; voiceDropdownContext.preference = 'voice'; - voiceDropdownContext.dropdown_default = voiceOptions[0]['displayname']; - voiceDropdownContext.dropdown_default_value = voiceOptions[0]['key']; - voiceDropdownContext.dropdown_description = BasedataHandler.getTinyAiString('voice'); + voiceDropdownContext.dropdownDefault = voiceOptions[0].displayname; + voiceDropdownContext.dropdownDefaultValue = voiceOptions[0].key; + voiceDropdownContext.dropdownDescription = BasedataHandler.getTinyAiString('voice'); const voiceDropdownOptions = []; voiceOptions.forEach(option => { voiceDropdownOptions.push({ @@ -145,7 +145,7 @@ export default class extends BaseHandler { optionLabel: option.displayname, }); }); - voiceDropdownContext.dropdown_options = voiceDropdownOptions; + voiceDropdownContext.dropdownOptions = voiceDropdownOptions; modalDropdowns.push(voiceDropdownContext); } @@ -153,9 +153,9 @@ export default class extends BaseHandler { if (genderOptions !== null && Object.keys(genderOptions).length > 0) { const genderDropdownContext = {}; genderDropdownContext.preference = 'gender'; - genderDropdownContext.dropdown_default = genderOptions[0]['displayname']; - genderDropdownContext.dropdown_default_value = genderOptions[0]['key']; - genderDropdownContext.dropdown_description = BasedataHandler.getTinyAiString('gender'); + genderDropdownContext.dropdownDefault = genderOptions[0].displayname; + genderDropdownContext.dropdownDefaultValue = genderOptions[0].key; + genderDropdownContext.dropdownDescription = BasedataHandler.getTinyAiString('gender'); const genderDropdownOptions = []; genderOptions.forEach(option => { genderDropdownOptions.push({ @@ -163,7 +163,7 @@ export default class extends BaseHandler { optionLabel: option.displayname, }); }); - genderDropdownContext.dropdown_options = genderDropdownOptions; + genderDropdownContext.dropdownOptions = genderDropdownOptions; modalDropdowns.push(genderDropdownContext); } if (tool === 'audiogen') { @@ -174,7 +174,7 @@ export default class extends BaseHandler { } Object.assign(context, { - modal_dropdowns: modalDropdowns + modalDropdowns: modalDropdowns }); Object.assign(context, BasedataHandler.getShowPromptButtonContext()); diff --git a/amd/src/renderer.js b/amd/src/renderer.js index a80135a..5b6a4e5 100644 --- a/amd/src/renderer.js +++ b/amd/src/renderer.js @@ -102,17 +102,17 @@ export default class { async renderLoading() { const templateContext = {}; - templateContext.modal_headline = BasedataHandler.getTinyAiString('aigenerating'); + templateContext.modalHeadline = 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.modalHeadline = BasedataHandler.getTinyAiString('aisuggestion'); // TODO Eventually do not use the same rendering in the suggestion like in the course, or just leave it because we // consider it beautiful - templateContext.result_text = this.renderAiResultForEditor(); + templateContext.resultText = this.renderAiResultForEditor(); Object.assign(templateContext, BasedataHandler.getReplaceButtonsContext(this.editorUtils.getMode())); await this.renderModalContent('moodle-modal-body-suggestion', 'moodle-modal-footer-replace', templateContext); @@ -126,15 +126,15 @@ export default class { async renderDismiss() { const templateContext = { - modal_headline: '', - centered_headline: BasedataHandler.getTinyAiString('dismisssuggestion'), + modalHeadline: '', + centeredHeadline: BasedataHandler.getTinyAiString('dismisssuggestion'), showIcon: false, buttons: [ { hasText: true, - button_text: BasedataHandler.getTinyAiString('cancel'), - icon_left: false, - icon_right: false, + buttonText: BasedataHandler.getTinyAiString('cancel'), + iconLeft: false, + iconRight: false, primary: false, secondary: true, tertiary: false, @@ -142,9 +142,9 @@ export default class { }, { hasText: true, - button_text: BasedataHandler.getTinyAiString('dismiss'), - icon_left: false, - icon_right: false, + buttonText: BasedataHandler.getTinyAiString('dismiss'), + iconLeft: false, + iconRight: false, primary: true, secondary: false, tertiary: false, @@ -202,7 +202,7 @@ export default class { Templates.renderForPromise('tiny_ai/components/' + bodyComponentTemplate, templateContext), Templates.renderForPromise('tiny_ai/components/' + footerComponentTemplate, templateContext) ]); - if (templateContext.hasOwnProperty('modal_headline')) { + if (templateContext.hasOwnProperty('modalHeadline')) { // If there is no headline specified, we keep the old one. modal.setTitle(result[0].html); } diff --git a/amd/src/utils.js b/amd/src/utils.js index 7358d0c..9a91363 100644 --- a/amd/src/utils.js +++ b/amd/src/utils.js @@ -32,7 +32,7 @@ import SummarizeHandler from 'tiny_ai/datahandler/summarize'; import TranslateHandler from 'tiny_ai/datahandler/translate'; import TtsHandler from 'tiny_ai/datahandler/tts'; import IttHandler from 'tiny_ai/datahandler/itt'; -import {alert as Alert, exception as displayException} from 'core/notification'; +import {alert as moodleAlert, exception as displayException} from 'core/notification'; import {getString} from 'core/str'; import {makeRequest} from 'local_ai_manager/make_request'; import * as BasedataHandler from 'tiny_ai/datahandler/basedata'; @@ -42,7 +42,7 @@ import EditorUtils from 'tiny_ai/editor_utils'; const objectStore = {}; -export const init = async (uniqid, editor) => { +export const init = async(uniqid, editor) => { if (!objectStore.hasOwnProperty(uniqid)) { objectStore[uniqid] = {}; // The order in which these objects are being created is actually pretty important, because Renderer @@ -62,13 +62,13 @@ export const init = async (uniqid, editor) => { } }; -export const getAiAnswer = async (prompt, purpose, options = {}) => { +export const getAiAnswer = async(prompt, purpose, options = {}) => { let result = null; try { result = await makeRequest(purpose, prompt, options); } catch (exception) { await displayException(exception); - return; + return null; } if (result.code !== 200) { const alertTitle = await getString('errorwithcode', 'tiny_ai', result.code); @@ -82,11 +82,11 @@ export const getAiAnswer = async (prompt, purpose, options = {}) => { return result.result; }; -export const errorAlert = async (message, title = null) => { +export const errorAlert = async(message, title = null) => { if (title === null) { title = BasedataHandler.getTinyAiString('generalerror'); } - const alertModal = await Alert(title, message); + const alertModal = await moodleAlert(title, message); alertModal.getRoot().on(ModalEvents.hidden, () => { document.querySelectorAll('button[data-action]').forEach(button => { $(button).tooltip('hide'); diff --git a/classes/plugininfo.php b/classes/plugininfo.php index 7471e6d..5e5e456 100644 --- a/classes/plugininfo.php +++ b/classes/plugininfo.php @@ -35,8 +35,17 @@ use local_ai_manager\local\tenant; use local_ai_manager\local\userinfo; +/** + * Tiny plugin info class. + * + * @package tiny_ai + * @copyright 2024 ISB Bayern + * @author Philipp Memmel + * @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ class plugininfo extends plugin implements plugin_with_configuration, plugin_with_buttons, plugin_with_menuitems { + #[\Override] public static function is_enabled( context $context, array $options, @@ -56,18 +65,21 @@ public static function is_enabled( } + #[\Override] public static function get_available_buttons(): array { return [ 'tiny_ai/plugin', ]; } + #[\Override] public static function get_available_menuitems(): array { return [ 'tiny_ai/plugin', ]; } + #[\Override] public static function get_plugin_configuration_for_context( context $context, array $options, diff --git a/classes/privacy/provider.php b/classes/privacy/provider.php index e7cb1c1..096842c 100644 --- a/classes/privacy/provider.php +++ b/classes/privacy/provider.php @@ -19,6 +19,7 @@ /** * Privacy provider for tiny_ai implementing null_provider. * + * @package tiny_ai * @copyright 2024 ISB Bayern * @author Philipp Memmel * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later diff --git a/lang/de/tiny_ai.php b/lang/de/tiny_ai.php index 375db89..712fd7d 100644 --- a/lang/de/tiny_ai.php +++ b/lang/de/tiny_ai.php @@ -27,22 +27,21 @@ defined('MOODLE_INTERNAL') || die(); $string['additional_prompt'] = 'Zusätzlicher Prompt'; +$string['ai:view'] = 'Die AI-Schaltfläche anzeigen'; $string['aigenerating'] = 'KI generiert...'; $string['aisuggestion'] = 'KI-Vorschlag'; -$string['ai:view'] = 'Die AI-Schaltfläche anzeigen'; $string['audiogen_headline'] = 'Audio aus Text generieren'; $string['audiogen_placeholder'] = 'Text eingeben oder einfügen, der in Audio umgewandelt werden soll'; $string['back'] = 'Zurück'; $string['backbutton_tooltip'] = 'Zurück zur vorherigen Seite'; $string['cancel'] = 'Abbrechen'; $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'] = 'Bildbeschreibung'; +$string['describe_headline'] = 'Ausführliche Beschreibung des markierten Texts'; $string['describeimg_baseprompt'] = 'Beschreibe, was auf dem Bild zu sehen ist'; +$string['describeimg_headline'] = 'Bildbeschreibung'; $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'; @@ -50,8 +49,9 @@ $string['error_tiny_ai_notavailable'] = 'Die KI-Funktionen stehen Ihnen nicht zur Verfügung.'; $string['error_unsupportedfiletype_text'] = 'Der Dateityp wird nicht unterstützt. unterstützte Typen sind: {$a}'; $string['error_unsupportedwrongfiletype_title'] = 'Nicht unterstützter Dateityp'; -$string['freepromptbutton_tooltip'] = 'Generiere KI-Antwort'; +$string['errorwithcode'] = 'Ein Fehler ist aufgetreten, Fehlercode: {$a}'; $string['freeprompt_placeholder'] = 'Geben Sie der KI eine beliebige Anweisung zur Textgenerierung...'; +$string['freepromptbutton_tooltip'] = 'Generiere KI-Antwort'; $string['gender'] = 'Geschlecht'; $string['generalerror'] = 'Ein Fehler ist aufgetreten'; $string['generate'] = 'Jetzt generieren'; @@ -59,8 +59,8 @@ $string['generating'] = 'Die KI-Antwort wird generiert...'; $string['hideprompt'] = 'Prompt ausblenden'; $string['imagefromeditor'] = 'Bild aus Editor'; -$string['imagetotext_headline'] = 'Texterkennung'; $string['imagetotext_baseprompt'] = 'Gib den Text auf dem Bild zurück'; +$string['imagetotext_headline'] = 'Texterkennung'; $string['imagetotext_insertimage'] = 'Ziehen Sie eine Datei per Drag&Drop in diesen Bereich oder fügen Sie sie aus der Zwischenablage ein'; $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"'; @@ -91,8 +91,8 @@ $string['showpromptbutton_tooltip'] = 'Prompt anzeigen/ausblenden'; $string['simplelanguage'] = 'Einfache Sprache'; $string['size'] = 'Größe'; -$string['summarize_headline'] = 'Zusammenfassen des markierten Texts'; $string['summarize_baseprompt'] = 'Fasse den folgenden Text zusammen'; +$string['summarize_headline'] = 'Zusammenfassen des markierten Texts'; $string['targetlanguage'] = 'Ausgabesprache'; $string['technicallanguage'] = 'Fachsprache'; $string['texttouse'] = 'Der Text lautet'; @@ -101,15 +101,15 @@ $string['toolname_describe'] = 'Ausführliche Beschreibung'; $string['toolname_describe_extension'] = 'des markierten Textes'; $string['toolname_describeimg'] = 'Bildbeschreibung'; -$string['toolname_imggen'] = 'Bildgenerierung'; $string['toolname_imagetotext'] = 'Texterkennung'; +$string['toolname_imggen'] = 'Bildgenerierung'; $string['toolname_summarize'] = 'Zusammenfassen'; $string['toolname_summarize_extension'] = 'des markierten Textes'; $string['toolname_translate'] = 'Übersetzen'; $string['toolname_translate_extension'] = 'des markierten Textes'; $string['toolname_tts'] = 'Audio erstellen'; $string['toolname_tts_extension'] = 'aus dem markierten Text'; -$string['translate_headline'] = 'Übersetzen des markierten Texts'; $string['translate_baseprompt'] = 'Übersetze den folgenden Text in die Sprache {$a} und gib dabei ausschließlich den übersetzten Text aus'; +$string['translate_headline'] = 'Übersetzen des markierten Texts'; $string['tts_headline'] = 'Audio aus markiertem Text generieren'; $string['voice'] = 'Stimme'; diff --git a/lang/en/tiny_ai.php b/lang/en/tiny_ai.php index c06d9a1..bc30fc2 100644 --- a/lang/en/tiny_ai.php +++ b/lang/en/tiny_ai.php @@ -27,22 +27,21 @@ defined('MOODLE_INTERNAL') || die(); $string['additional_prompt'] = 'Additional Propmt'; +$string['ai:view'] = 'View the AI button'; $string['aigenerating'] = 'AI is generating...'; $string['aisuggestion'] = 'AI suggestion'; -$string['ai:view'] = 'View the AI button'; $string['audiogen_headline'] = 'Generate audio from text'; $string['audiogen_placeholder'] = 'Type or insert text which should be converted into audio'; $string['back'] = 'Back'; $string['backbutton_tooltip'] = 'Back to the previous page'; $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 description'; +$string['describe_headline'] = 'Detailed description of the selected text'; $string['describeimg_baseprompt'] = 'Describe what is being shown on the image'; +$string['describeimg_headline'] = 'Image description'; $string['dismiss'] = 'Dismiss'; $string['dismisssuggestion'] = 'Do you want to dismiss the AI suggestion?'; -$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'; @@ -50,8 +49,9 @@ $string['error_tiny_ai_notavailable'] = 'The AI features are not availeble for you.'; $string['error_unsupportedfiletype_text'] = 'This file type is not supported. Supported types are: {$a}'; $string['error_unsupportedfiletype_title'] = 'Not supported filetype'; -$string['freepromptbutton_tooltip'] = 'Generate AI answer'; +$string['errorwithcode'] = 'An error occured with error code {$a}'; $string['freeprompt_placeholder'] = 'Give the AI any order for generating text...'; +$string['freepromptbutton_tooltip'] = 'Generate AI answer'; $string['gender'] = 'Gender'; $string['generalerror'] = 'Ein Fehler ist aufgetreten'; $string['generate'] = 'Generate now'; @@ -59,8 +59,8 @@ $string['generating'] = 'The AI answer is being generated...'; $string['hideprompt'] = 'Hide prompt'; $string['imagefromeditor'] = 'Image from editor'; -$string['imagetotext_headline'] = 'Text recognition'; $string['imagetotext_baseprompt'] = 'Parse the text in the image'; +$string['imagetotext_headline'] = 'Text recognition'; $string['imagetotext_insertimage'] = 'Drag&Drop a file into this area or paste a file from clipboard'; $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"'; @@ -91,8 +91,8 @@ $string['showpromptbutton_tooltip'] = 'Show or hide prompt'; $string['simplelanguage'] = 'Simple language'; $string['size'] = 'Size'; -$string['summarize_headline'] = 'Summarize the selected text'; $string['summarize_baseprompt'] = 'Summarize the following text'; +$string['summarize_headline'] = 'Summarize the selected text'; $string['targetlanguage'] = 'Target language'; $string['technicallanguage'] = 'Technical language'; $string['texttouse'] = 'The text reads'; @@ -101,15 +101,15 @@ $string['toolname_describe'] = 'Detailed description'; $string['toolname_describe_extension'] = 'of the selected text'; $string['toolname_describeimg'] = 'Image description'; -$string['toolname_imggen'] = 'Image generation'; $string['toolname_imagetotext'] = 'Text recognition'; +$string['toolname_imggen'] = 'Image generation'; $string['toolname_summarize'] = 'Summarize'; $string['toolname_summarize_extension'] = 'the selected text'; $string['toolname_translate'] = 'Translate'; $string['toolname_translate_extension'] = 'the selected text'; $string['toolname_tts'] = 'Create audio'; $string['toolname_tts_extension'] = 'from the selected text'; -$string['translate_headline'] = 'Translate the selected text'; $string['translate_baseprompt'] = 'Translate the following text to the language {$a} and only return the translated text'; +$string['translate_headline'] = 'Translate the selected text'; $string['tts_headline'] = 'Generate audio from selected text'; $string['voice'] = 'Voice'; diff --git a/scss/partials/ai-info-box.scss b/scss/partials/ai-info-box.scss deleted file mode 100644 index af25bfa..0000000 --- a/scss/partials/ai-info-box.scss +++ /dev/null @@ -1,23 +0,0 @@ -.tiny_ai-alert { - display: flex; - align-items: center; - padding: 10px 15px; - background-color: $feedback-warning-100; - border-radius: 4px; - color: $neutral-grey-500; - font-family: "Atkinson Hyperlegible"; - font-size: 18px; - font-style: normal; - font-weight: 400; - line-height: 26px; - - .tiny_ai-icon { - font-size: 24px; - margin-right: 10px; - color: $neutral-grey-500; - } - - .tiny_ai-alert-text { - color: $neutral-grey-500; - } -} diff --git a/styles.css b/styles.css index 77bae61..9e1edf4 100644 --- a/styles.css +++ b/styles.css @@ -604,28 +604,6 @@ max-height: 100%; } -.tiny_ai-alert { - display: flex; - align-items: center; - padding: 10px 15px; - background-color: #FFF8E0; - border-radius: 4px; - color: #00091E; - font-family: "Atkinson Hyperlegible"; - font-size: 18px; - font-style: normal; - font-weight: 400; - line-height: 26px; -} -.tiny_ai-alert .tiny_ai-icon { - font-size: 24px; - margin-right: 10px; - color: #00091E; -} -.tiny_ai-alert .tiny_ai-alert-text { - color: #00091E; -} - .tiny_ai-icon-button { display: flex; justify-content: center; diff --git a/styles.scss b/styles.scss index 7f4e4d8..cec73b5 100644 --- a/styles.scss +++ b/styles.scss @@ -8,7 +8,6 @@ @import 'scss/partials/ai-button.scss'; @import 'scss/partials/ai-dropdown.scss'; @import 'scss/partials/ai-dropzone.scss'; -@import 'scss/partials/ai-info-box.scss'; @import 'scss/partials/ai-icon-button.scss'; @import 'scss/partials/ai-result-text.scss'; @import 'scss/partials/ai-textarea.scss'; diff --git a/templates/components/ai-audio-player.mustache b/templates/components/ai-audio-player.mustache index d34263a..584f95d 100644 --- a/templates/components/ai-audio-player.mustache +++ b/templates/components/ai-audio-player.mustache @@ -1,3 +1,36 @@ +{{! +This file is part of Moodle - http://moodle.org/ + +Moodle is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +Moodle is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with Moodle. If not, see +. +}} +{{! +@template tiny_ai/components/ai-audio-player + +Modal to select ai actions within the Tiny Editor. + +Classes required for JS: +* none + +Data attributes required for JS: +* none + +Context variables required for this template: + +Example context (json): +{} +}} {{audio_description}}
diff --git a/templates/components/ai-button.mustache b/templates/components/ai-button.mustache index 094c922..bed56d3 100644 --- a/templates/components/ai-button.mustache +++ b/templates/components/ai-button.mustache @@ -1,16 +1,49 @@ +{{! +This file is part of Moodle - http://moodle.org/ + +Moodle is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +Moodle is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with Moodle. If not, see +. +}} +{{! +@template tiny_ai/components/ai-button + +Modal to select ai actions within the Tiny Editor. + +Classes required for JS: +* none + +Data attributes required for JS: +* none + +Context variables required for this template: + +Example context (json): +{} +}} diff --git a/templates/components/ai-card-button.mustache b/templates/components/ai-card-button.mustache index 0ce6104..9a32a7e 100644 --- a/templates/components/ai-card-button.mustache +++ b/templates/components/ai-card-button.mustache @@ -1,3 +1,36 @@ +{{! +This file is part of Moodle - http://moodle.org/ + +Moodle is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +Moodle is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with Moodle. If not, see +. +}} +{{! +@template tiny_ai/components/ai-card-button + +Modal to select ai actions within the Tiny Editor. + +Classes required for JS: +* none + +Data attributes required for JS: +* none + +Context variables required for this template: + +Example context (json): +{} +}}
{{> tiny_ai/components/ai-icon}} diff --git a/templates/components/ai-dropdown.mustache b/templates/components/ai-dropdown.mustache index 9222bb4..c73fa39 100644 --- a/templates/components/ai-dropdown.mustache +++ b/templates/components/ai-dropdown.mustache @@ -1,14 +1,47 @@ -{{dropdown_description}} +{{! +This file is part of Moodle - http://moodle.org/ + +Moodle is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +Moodle is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with Moodle. If not, see +. +}} +{{! +@template tiny_ai/components/ai-dropdown + +Modal to select ai actions within the Tiny Editor. + +Classes required for JS: +* none + +Data attributes required for JS: +* none + +Context variables required for this template: + +Example context (json): +{} +}} +{{dropdownDescription}} {{#js}} diff --git a/templates/components/ai-file-list-entry.mustache b/templates/components/ai-file-list-entry.mustache index 3bd4862..56d11b6 100644 --- a/templates/components/ai-file-list-entry.mustache +++ b/templates/components/ai-file-list-entry.mustache @@ -1,3 +1,36 @@ +{{! +This file is part of Moodle - http://moodle.org/ + +Moodle is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +Moodle is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with Moodle. If not, see +. +}} +{{! +@template tiny_ai/components/ai-file-list-entry + +Modal to select ai actions within the Tiny Editor. + +Classes required for JS: +* none + +Data attributes required for JS: +* none + +Context variables required for this template: + +Example context (json): +{} +}}
{{filename}}
{{#isImage}} diff --git a/templates/components/ai-icon-button.mustache b/templates/components/ai-icon-button.mustache index bf370b9..b606bd0 100644 --- a/templates/components/ai-icon-button.mustache +++ b/templates/components/ai-icon-button.mustache @@ -1,3 +1,36 @@ +{{! +This file is part of Moodle - http://moodle.org/ + +Moodle is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +Moodle is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with Moodle. If not, see +. +}} +{{! +@template tiny_ai/components/ai-icon-button + +Modal to select ai actions within the Tiny Editor. + +Classes required for JS: +* none + +Data attributes required for JS: +* none + +Context variables required for this template: + +Example context (json): +{} +}} diff --git a/templates/components/ai-icon.mustache b/templates/components/ai-icon.mustache index 90c5974..68c3fdd 100644 --- a/templates/components/ai-icon.mustache +++ b/templates/components/ai-icon.mustache @@ -1,3 +1,36 @@ +{{! +This file is part of Moodle - http://moodle.org/ + +Moodle is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +Moodle is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with Moodle. If not, see +. +}} +{{! +@template tiny_ai/components/ai-icon + +Modal to select ai actions within the Tiny Editor. + +Classes required for JS: +* none + +Data attributes required for JS: +* none + +Context variables required for this template: + +Example context (json): +{} +}} {{#customicon}} {{/customicon}} diff --git a/templates/components/ai-info-box.mustache b/templates/components/ai-info-box.mustache deleted file mode 100644 index e6f5915..0000000 --- a/templates/components/ai-info-box.mustache +++ /dev/null @@ -1,6 +0,0 @@ -
- - - Es sind nicht alle Funktionen verfügbar. Text- und Audiogenerierung wurden noch nicht aktiviert. Wenden Sie sich an Ihren Schul-Admin. - -
diff --git a/templates/components/ai-info-text.mustache b/templates/components/ai-info-text.mustache index 659ce0d..6e00f45 100644 --- a/templates/components/ai-info-text.mustache +++ b/templates/components/ai-info-text.mustache @@ -1,2 +1,35 @@ +{{! +This file is part of Moodle - http://moodle.org/ + +Moodle is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +Moodle is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with Moodle. If not, see +. +}} +{{! +@template tiny_ai/components/ai-info-text + +Modal to select ai actions within the Tiny Editor. + +Classes required for JS: +* none + +Data attributes required for JS: +* none + +Context variables required for this template: + +Example context (json): +{} +}}
diff --git a/templates/components/ai-info-warning.mustache b/templates/components/ai-info-warning.mustache index 606f307..f07c0f1 100644 --- a/templates/components/ai-info-warning.mustache +++ b/templates/components/ai-info-warning.mustache @@ -1 +1,34 @@ +{{! +This file is part of Moodle - http://moodle.org/ + +Moodle is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +Moodle is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with Moodle. If not, see +. +}} +{{! +@template tiny_ai/components/ai-info-warning + +Modal to select ai actions within the Tiny Editor. + +Classes required for JS: +* none + +Data attributes required for JS: +* none + +Context variables required for this template: + +Example context (json): +{} +}}
diff --git a/templates/components/ai-input.mustache b/templates/components/ai-input.mustache index 1d54d95..2d25c07 100644 --- a/templates/components/ai-input.mustache +++ b/templates/components/ai-input.mustache @@ -1,3 +1,36 @@ +{{! +This file is part of Moodle - http://moodle.org/ + +Moodle is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +Moodle is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with Moodle. If not, see +. +}} +{{! +@template tiny_ai/components/ai-input + +Modal to select ai actions within the Tiny Editor. + +Classes required for JS: +* none + +Data attributes required for JS: +* none + +Context variables required for this template: + +Example context (json): +{} +}}
{{> tiny_ai/components/ai-icon }} diff --git a/templates/components/ai-modal.mustache b/templates/components/ai-modal.mustache deleted file mode 100644 index 21b396c..0000000 --- a/templates/components/ai-modal.mustache +++ /dev/null @@ -1,26 +0,0 @@ - diff --git a/templates/components/ai-result-text.mustache b/templates/components/ai-result-text.mustache index 473b493..82396e6 100644 --- a/templates/components/ai-result-text.mustache +++ b/templates/components/ai-result-text.mustache @@ -1,3 +1,36 @@ +{{! +This file is part of Moodle - http://moodle.org/ + +Moodle is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +Moodle is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with Moodle. If not, see +. +}} +{{! +@template tiny_ai/components/ai-result-text + +Modal to select ai actions within the Tiny Editor. + +Classes required for JS: +* none + +Data attributes required for JS: +* none + +Context variables required for this template: + +Example context (json): +{} +}}
-

{{{result_text}}}

+

{{{resultText}}}

diff --git a/templates/components/ai-textarea.mustache b/templates/components/ai-textarea.mustache index 7589b57..d69f1bd 100644 --- a/templates/components/ai-textarea.mustache +++ b/templates/components/ai-textarea.mustache @@ -1,2 +1,35 @@ - diff --git a/templates/components/ai-tooltip.mustache b/templates/components/ai-tooltip.mustache index 33d641d..cfa08c3 100644 --- a/templates/components/ai-tooltip.mustache +++ b/templates/components/ai-tooltip.mustache @@ -1,3 +1,36 @@ +{{! +This file is part of Moodle - http://moodle.org/ + +Moodle is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +Moodle is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with Moodle. If not, see +. +}} +{{! +@template tiny_ai/components/ai-tooltip + +Modal to select ai actions within the Tiny Editor. + +Classes required for JS: +* none + +Data attributes required for JS: +* none + +Context variables required for this template: + +Example context (json): +{} +}} \ No newline at end of file diff --git a/templates/components/moodle-modal-body-dismiss.mustache b/templates/components/moodle-modal-body-dismiss.mustache index 9550fae..0a72cc2 100644 --- a/templates/components/moodle-modal-body-dismiss.mustache +++ b/templates/components/moodle-modal-body-dismiss.mustache @@ -1,7 +1,40 @@ +{{! +This file is part of Moodle - http://moodle.org/ + +Moodle is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +Moodle is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with Moodle. If not, see +. +}} +{{! +@template tiny_ai/components/moodle-modal-body-dismiss + +Modal to select ai actions within the Tiny Editor. + +Classes required for JS: +* none + +Data attributes required for JS: +* none + +Context variables required for this template: + +Example context (json): +{} +}}
{{> tiny_ai/components/ai-icon}} -
{{centered_headline}}
+
{{centeredHeadline}}
{{#buttons}} diff --git a/templates/components/moodle-modal-body-itt.mustache b/templates/components/moodle-modal-body-itt.mustache index 608b293..8c31016 100644 --- a/templates/components/moodle-modal-body-itt.mustache +++ b/templates/components/moodle-modal-body-itt.mustache @@ -1,3 +1,36 @@ +{{! +This file is part of Moodle - http://moodle.org/ + +Moodle is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +Moodle is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with Moodle. If not, see +. +}} +{{! +@template tiny_ai/components/moodle-modal-body-itt + +Modal to select ai actions within the Tiny Editor. + +Classes required for JS: +* none + +Data attributes required for JS: +* none + +Context variables required for this template: + +Example context (json): +{} +}}
diff --git a/templates/components/moodle-modal-body-loading.mustache b/templates/components/moodle-modal-body-loading.mustache index b02f84b..5e7ec88 100644 --- a/templates/components/moodle-modal-body-loading.mustache +++ b/templates/components/moodle-modal-body-loading.mustache @@ -1,3 +1,36 @@ +{{! +This file is part of Moodle - http://moodle.org/ + +Moodle is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +Moodle is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with Moodle. If not, see +. +}} +{{! +@template tiny_ai/components/moodle-modal-body-loading + +Modal to select ai actions within the Tiny Editor. + +Classes required for JS: +* none + +Data attributes required for JS: +* none + +Context variables required for this template: + +Example context (json): +{} +}}
{{> core/loading }} {{#str}}generating, tiny_ai{{/str}}
diff --git a/templates/components/moodle-modal-body-mediageneration.mustache b/templates/components/moodle-modal-body-mediageneration.mustache index f3dd991..202abb8 100644 --- a/templates/components/moodle-modal-body-mediageneration.mustache +++ b/templates/components/moodle-modal-body-mediageneration.mustache @@ -1,11 +1,44 @@ +{{! +This file is part of Moodle - http://moodle.org/ + +Moodle is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +Moodle is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with Moodle. If not, see +. +}} +{{! +@template tiny_ai/components/moodle-modal-body-mediageneration + +Modal to select ai actions within the Tiny Editor. + +Classes required for JS: +* none + +Data attributes required for JS: +* none + +Context variables required for this template: + +Example context (json): +{} +}}
{{> tiny_ai/components/ai-textarea}}
- {{#modal_dropdowns}} + {{#modalDropdowns}}
{{> tiny_ai/components/ai-dropdown}}
- {{/modal_dropdowns}} + {{/modalDropdowns}}
{{#js}} diff --git a/templates/components/moodle-modal-body-optimize.mustache b/templates/components/moodle-modal-body-optimize.mustache index 6fde300..62d46f9 100644 --- a/templates/components/moodle-modal-body-optimize.mustache +++ b/templates/components/moodle-modal-body-optimize.mustache @@ -1,3 +1,36 @@ +{{! +This file is part of Moodle - http://moodle.org/ + +Moodle is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +Moodle is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with Moodle. If not, see +. +}} +{{! +@template tiny_ai/components/moodle-modal-body-optimize + +Modal to select ai actions within the Tiny Editor. + +Classes required for JS: +* none + +Data attributes required for JS: +* none + +Context variables required for this template: + +Example context (json): +{} +}}
{{> tiny_ai/components/ai-textarea }}
diff --git a/templates/components/moodle-modal-body-preferences.mustache b/templates/components/moodle-modal-body-preferences.mustache index fcb8633..f99a60e 100644 --- a/templates/components/moodle-modal-body-preferences.mustache +++ b/templates/components/moodle-modal-body-preferences.mustache @@ -1,10 +1,43 @@ +{{! +This file is part of Moodle - http://moodle.org/ + +Moodle is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +Moodle is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with Moodle. If not, see +. +}} +{{! +@template tiny_ai/components/moodle-modal-body-preferences + +Modal to select ai actions within the Tiny Editor. + +Classes required for JS: +* none + +Data attributes required for JS: +* none + +Context variables required for this template: + +Example context (json): +{} +}}
- {{#modal_dropdowns}} + {{#modalDropdowns}}
{{> tiny_ai/components/ai-dropdown}}
- {{/modal_dropdowns}} + {{/modalDropdowns}}
diff --git a/templates/components/moodle-modal-body-start.mustache b/templates/components/moodle-modal-body-start.mustache index ba3ca81..1de385c 100644 --- a/templates/components/moodle-modal-body-start.mustache +++ b/templates/components/moodle-modal-body-start.mustache @@ -1,14 +1,47 @@ +{{! +This file is part of Moodle - http://moodle.org/ + +Moodle is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +Moodle is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with Moodle. If not, see +. +}} +{{! +@template tiny_ai/components/moodle-modal-body-start + +Modal to select ai actions within the Tiny Editor. + +Classes required for JS: +* none + +Data attributes required for JS: +* none + +Context variables required for this template: + +Example context (json): +{} +}}
{{> tiny_ai/components/ai-info-text}} {{#input}} {{> tiny_ai/components/ai-input}} {{/input}}
- {{#modal_buttons}} + {{#modalButtons}}
{{> tiny_ai/components/ai-card-button}}
- {{/modal_buttons}} + {{/modalButtons}}
{{#js}} diff --git a/templates/components/moodle-modal-body-suggestion.mustache b/templates/components/moodle-modal-body-suggestion.mustache index a56a13c..b6fd183 100644 --- a/templates/components/moodle-modal-body-suggestion.mustache +++ b/templates/components/moodle-modal-body-suggestion.mustache @@ -1,3 +1,36 @@ +{{! +This file is part of Moodle - http://moodle.org/ + +Moodle is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +Moodle is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with Moodle. If not, see +. +}} +{{! +@template tiny_ai/components/moodle-modal-body-suggestion + +Modal to select ai actions within the Tiny Editor. + +Classes required for JS: +* none + +Data attributes required for JS: +* none + +Context variables required for this template: + +Example context (json): +{} +}}
{{> tiny_ai/components/ai-result-text}} {{> tiny_ai/components/ai-info-warning}} diff --git a/templates/components/moodle-modal-body-textarea.mustache b/templates/components/moodle-modal-body-textarea.mustache index a093471..a342f12 100644 --- a/templates/components/moodle-modal-body-textarea.mustache +++ b/templates/components/moodle-modal-body-textarea.mustache @@ -1 +1,34 @@ +{{! +This file is part of Moodle - http://moodle.org/ + +Moodle is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +Moodle is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with Moodle. If not, see +. +}} +{{! +@template tiny_ai/components/moodle-modal-body-textarea + +Modal to select ai actions within the Tiny Editor. + +Classes required for JS: +* none + +Data attributes required for JS: +* none + +Context variables required for this template: + +Example context (json): +{} +}} {{> tiny_ai/components/ai-textarea}} diff --git a/templates/components/moodle-modal-footer-empty.mustache b/templates/components/moodle-modal-footer-empty.mustache index 7c89b54..5d3a23a 100644 --- a/templates/components/moodle-modal-footer-empty.mustache +++ b/templates/components/moodle-modal-footer-empty.mustache @@ -1 +1,34 @@ +{{! +This file is part of Moodle - http://moodle.org/ + +Moodle is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +Moodle is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with Moodle. If not, see +. +}} +{{! +@template tiny_ai/components/moodle-modal-footer-empty + +Modal to select ai actions within the Tiny Editor. + +Classes required for JS: +* none + +Data attributes required for JS: +* none + +Context variables required for this template: + +Example context (json): +{} +}}
diff --git a/templates/components/moodle-modal-footer-generate.mustache b/templates/components/moodle-modal-footer-generate.mustache index 43aa15a..274eebe 100644 --- a/templates/components/moodle-modal-footer-generate.mustache +++ b/templates/components/moodle-modal-footer-generate.mustache @@ -1,6 +1,39 @@ +{{! +This file is part of Moodle - http://moodle.org/ + +Moodle is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +Moodle is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with Moodle. If not, see +. +}} +{{! +@template tiny_ai/components/moodle-modal-footer-generate + +Modal to select ai actions within the Tiny Editor. + +Classes required for JS: +* none + +Data attributes required for JS: +* none + +Context variables required for this template: + +Example context (json): +{} +}} {{> tiny_ai/components/moodle-modal-footer-info}} diff --git a/templates/components/moodle-modal-footer-info.mustache b/templates/components/moodle-modal-footer-info.mustache index 1a3588d..7e3aedc 100644 --- a/templates/components/moodle-modal-footer-info.mustache +++ b/templates/components/moodle-modal-footer-info.mustache @@ -1 +1,34 @@ +{{! +This file is part of Moodle - http://moodle.org/ + +Moodle is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +Moodle is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with Moodle. If not, see +. +}} +{{! +@template tiny_ai/components/moodle-modal-footer-info + +Modal to select ai actions within the Tiny Editor. + +Classes required for JS: +* none + +Data attributes required for JS: +* none + +Context variables required for this template: + +Example context (json): +{} +}}

diff --git a/templates/components/moodle-modal-footer-replace.mustache b/templates/components/moodle-modal-footer-replace.mustache index a8dfc39..b2c68fb 100644 --- a/templates/components/moodle-modal-footer-replace.mustache +++ b/templates/components/moodle-modal-footer-replace.mustache @@ -1,13 +1,46 @@ +{{! +This file is part of Moodle - http://moodle.org/ + +Moodle is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +Moodle is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with Moodle. If not, see +. +}} +{{! +@template tiny_ai/components/moodle-modal-footer-replace + +Modal to select ai actions within the Tiny Editor. + +Classes required for JS: +* none + +Data attributes required for JS: +* none + +Context variables required for this template: + +Example context (json): +{} +}} {{> tiny_ai/components/moodle-modal-footer-info}} diff --git a/templates/components/moodle-modal-header-title.mustache b/templates/components/moodle-modal-header-title.mustache index 1f7c211..5738aa0 100644 --- a/templates/components/moodle-modal-header-title.mustache +++ b/templates/components/moodle-modal-header-title.mustache @@ -1,4 +1,37 @@ +{{! +This file is part of Moodle - http://moodle.org/ + +Moodle is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +Moodle is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with Moodle. If not, see +. +}} +{{! +@template tiny_ai/components/moodle-modal-header-title + +Modal to select ai actions within the Tiny Editor. + +Classes required for JS: +* none + +Data attributes required for JS: +* none + +Context variables required for this template: + +Example context (json): +{} +}} {{#showIcon}} {{/showIcon}} -{{modal_headline}} +{{modalHeadline}} diff --git a/templates/components/moodle-modal-header.mustache b/templates/components/moodle-modal-header.mustache index 8bff7cc..319abdc 100644 --- a/templates/components/moodle-modal-header.mustache +++ b/templates/components/moodle-modal-header.mustache @@ -1,3 +1,36 @@ +{{! +This file is part of Moodle - http://moodle.org/ + +Moodle is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +Moodle is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with Moodle. If not, see +. +}} +{{! +@template tiny_ai/components/moodle-modal-header + +Modal to select ai actions within the Tiny Editor. + +Classes required for JS: +* none + +Data attributes required for JS: +* none + +Context variables required for this template: + +Example context (json): +{} +}}