From c30ee233169adb707199fe047852ca4a20f9db9e Mon Sep 17 00:00:00 2001 From: Mikko Haiku Date: Wed, 9 Oct 2024 12:34:31 +0300 Subject: [PATCH 1/2] wip --- classes/plugininfo.php | 5 +++- lang/en/tiny_fontfamily.php | 3 +++ lang/fi/tiny_fontfamily.php | 3 +++ settings.php | 50 +++++++++++++++++++++++++++++++++++++ 4 files changed, 60 insertions(+), 1 deletion(-) create mode 100644 settings.php diff --git a/classes/plugininfo.php b/classes/plugininfo.php index df8ffb7..cf67840 100644 --- a/classes/plugininfo.php +++ b/classes/plugininfo.php @@ -69,6 +69,9 @@ public static function get_plugin_configuration_for_context( array $fpoptions, ?\editor_tiny\editor $editor = null ): array { - return []; + $config = []; + $config['fonts'] = explode("\r\n", get_config('tiny_fontfamily', 'fonts')); + return $config; + } } diff --git a/lang/en/tiny_fontfamily.php b/lang/en/tiny_fontfamily.php index 45cf6c6..d64d6b6 100644 --- a/lang/en/tiny_fontfamily.php +++ b/lang/en/tiny_fontfamily.php @@ -29,3 +29,6 @@ $string['menuitem_fontfamily'] = 'Font family'; $string['pluginname'] = 'Font family plugin'; $string['privacy:metadata'] = 'Font family plugin does not store any personal data'; +$string['fonts'] = "Font families"; +$string['settings'] = "Settings"; +$string['fonts_desc'] = "List of available font families separated by a new line."; diff --git a/lang/fi/tiny_fontfamily.php b/lang/fi/tiny_fontfamily.php index dd202ea..e36bcdd 100644 --- a/lang/fi/tiny_fontfamily.php +++ b/lang/fi/tiny_fontfamily.php @@ -29,3 +29,6 @@ $string['menuitem_fontfamily'] = 'Kirjasinperhe'; $string['pluginname'] = 'Kirjasinperhe-lisäosa'; $string['privacy:metadata'] = 'Kirjasinperhe-lisäosa ei tallentaa henkilötietoja.'; +$string['fonts'] = "Kirjasinperheet"; +$string['settings'] = "Asetukset"; +$string['fonts_desc'] = "Lista käytettävissä olevista kirjasinperheistä rivinvaihdolla eroteltuna."; diff --git a/settings.php b/settings.php new file mode 100644 index 0000000..1cec517 --- /dev/null +++ b/settings.php @@ -0,0 +1,50 @@ +. + +/** + * Settings that allow configuring various tiny Font Family plugin features. + * + * @package tiny_fontfamily + * @copyright 2024 Mikko Haiku add('editortiny', new admin_category($plugin, new lang_string('pluginname', $plugin))); + +$settings = new admin_settingpage('tiny_fontfamily_settings', new lang_string('settings', $plugin)); +if ($ADMIN->fulltree) { + + $defaults = [ + 'Arial', + 'Verdana', + 'Tahoma', + 'Trebuchet MS', + 'Times New Roman', + 'Georgia', + 'Garamond', + 'Courier New', + 'Brush Script MT' + ]; + + $settings->add( + new admin_setting_configtextarea($plugin . '/fonts', + new lang_string('fonts', $plugin), + new lang_string('fonts_desc', $plugin), + implode("\r\n", $defaults), PARAM_TEXT, 80, 10)); +} From cf60bc142a429ded93c300fdd9fcc15c3b7d7468 Mon Sep 17 00:00:00 2001 From: Mikko Haiku Date: Wed, 9 Oct 2024 13:50:06 +0300 Subject: [PATCH 2/2] Add setting to edit fonts --- amd/build/commands.min.js | 10 +++--- amd/build/commands.min.js.map | 2 +- amd/build/common.min.js | 8 ++--- amd/build/common.min.js.map | 2 +- amd/build/configuration.min.js | 6 ++-- amd/build/configuration.min.js.map | 2 +- amd/build/functions.min.js | 13 ++++++++ amd/build/functions.min.js.map | 1 + amd/build/options.min.js | 11 +++++++ amd/build/options.min.js.map | 1 + amd/build/plugin.min.js | 10 +++--- amd/build/plugin.min.js.map | 2 +- amd/src/commands.js | 31 +++++++++---------- amd/src/common.js | 6 ++-- amd/src/configuration.js | 9 ++---- amd/src/options.js | 49 ++++++++++++++++++++++++++++++ amd/src/plugin.js | 11 +++++-- classes/plugininfo.php | 1 - version.php | 4 +-- 19 files changed, 127 insertions(+), 52 deletions(-) create mode 100644 amd/build/functions.min.js create mode 100644 amd/build/functions.min.js.map create mode 100644 amd/build/options.min.js create mode 100644 amd/build/options.min.js.map create mode 100644 amd/src/options.js diff --git a/amd/build/commands.min.js b/amd/build/commands.min.js index c1f78a1..b8f1630 100644 --- a/amd/build/commands.min.js +++ b/amd/build/commands.min.js @@ -1,11 +1,11 @@ -define("tiny_fontfamily/commands",["exports","editor_tiny/utils","core/str","./common"],(function(_exports,_utils,_str,_common){Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.getSetup=void 0; +define("tiny_fontfamily/commands",["exports","./options","editor_tiny/utils","core/str","./common"],(function(_exports,_options,_utils,_str,_common){Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.getSetup=void 0; /** - * Commands helper for the Moodle tiny_fontfamily plugin. + * tiny_fontfamily for Moodle. * - * @module plugintype_pluginname/commands - * @copyright 2023 Mikko Haiku + * @module tiny_fontfamily + * @copyright 2024 Mikko Haiku * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -const handleAction=(editor,fontfamily)=>{editor.selection.dom.setAttrib(editor.selection.getNode(),"style","font-family: "+fontfamily)};_exports.getSetup=async()=>{const[fontfamilyButtonNameTitle,fontfamilyMenuItemNameTitle,buttonImage]=await Promise.all([(0,_str.get_string)("button_fontfamily",_common.component),(0,_str.get_string)("menuitem_fontfamily",_common.component),(0,_utils.getButtonImage)("icon",_common.component)]);return editor=>{editor.ui.registry.addIcon(_common.icon,buttonImage.html),editor.ui.registry.addButton(_common.fontfamilyButtonName,{icon:_common.icon,tooltip:fontfamilyButtonNameTitle,onAction:()=>handleAction(editor)}),editor.ui.registry.addMenuItem(_common.fontfamilyMenuItemName,{icon:_common.icon,text:fontfamilyMenuItemNameTitle,onAction:()=>handleAction(editor)});function handlefontfamily(editor,family){return()=>handleAction(editor,family)}const submenuItems=[{family:"Arial",label:"Arial"},{family:"Verdana",label:"Verdana"},{family:"Tahoma",label:"Tahoma"},{family:"Trebuchet MS",label:"Trebuchet MS"},{family:"Times New Roman",label:"Times New Roman"},{family:"Georgia",label:"Georgia"},{family:"Garamond",label:"Garamond"},{family:"Courier New",label:"Courier New"},{family:"Brush Script MT",label:"Brush Script MT"}].map((_ref=>{let{family:family,label:label}=_ref;return{type:"menuitem",text:label,onAction:handlefontfamily(editor,family)}}));editor.ui.registry.addNestedMenuItem(_common.fontfamilyMenuItemName,{icon:_common.icon,text:fontfamilyMenuItemNameTitle,getSubmenuItems:()=>submenuItems})}}})); +const handleAction=(editor,fontfamily)=>{editor.selection.dom.setAttrib(editor.selection.getNode(),"style","font-family: "+fontfamily)};_exports.getSetup=async()=>{const[fontfamilyButtonNameTitle,fontfamilyMenuItemNameTitle,buttonImage]=await Promise.all([(0,_str.get_string)("button_fontfamily",_common.component),(0,_str.get_string)("menuitem_fontfamily",_common.component),(0,_utils.getButtonImage)("icon",_common.component)]);return editor=>{const fontList=(0,_options.getFontList)(editor);if(fontList.length<2)return;editor.ui.registry.addIcon(_common.icon,buttonImage.html),editor.ui.registry.addButton(_common.fontfamilyButtonName,{icon:_common.icon,tooltip:fontfamilyButtonNameTitle,onAction:()=>handleAction(editor)}),editor.ui.registry.addMenuItem(_common.fontfamilyMenuItemName,{icon:_common.icon,text:fontfamilyMenuItemNameTitle,onAction:()=>handleAction(editor)});function handlefontfamily(editor,family){return()=>handleAction(editor,family)}const submenuItems=fontList.map((font=>({family:font,label:font}))).map((_ref=>{let{family:family,label:label}=_ref;return{type:"menuitem",text:label,onAction:handlefontfamily(editor,family)}}));editor.ui.registry.addNestedMenuItem(_common.fontfamilyMenuItemName,{icon:_common.icon,text:fontfamilyMenuItemNameTitle,getSubmenuItems:()=>submenuItems})}}})); //# sourceMappingURL=commands.min.js.map \ No newline at end of file diff --git a/amd/build/commands.min.js.map b/amd/build/commands.min.js.map index f1f457c..781390d 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_fontfamily plugin.\n *\n * @module plugintype_pluginname/commands\n * @copyright 2023 Mikko Haiku \n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nimport {getButtonImage} from 'editor_tiny/utils';\nimport {get_string as getString} from 'core/str';\nimport {\n component,\n fontfamilyButtonName,\n fontfamilyMenuItemName,\n icon,\n} from './common';\n\n/**\n * Handle the action for your plugin.\n * @param {TinyMCE.editor} editor The tinyMCE editor instance.\n * @param {integer} fontfamily Font family in integer.\n */\nconst handleAction = (editor, fontfamily) => {\n editor.selection.dom.setAttrib(editor.selection.getNode(), \"style\", \"font-family: \" + fontfamily);\n};\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 const [\n fontfamilyButtonNameTitle,\n fontfamilyMenuItemNameTitle,\n buttonImage,\n ] = await Promise.all([\n getString('button_fontfamily', component),\n getString('menuitem_fontfamily', component),\n getButtonImage('icon', component),\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 // Register the fontfamily Toolbar Button.\n editor.ui.registry.addButton(fontfamilyButtonName, {\n icon,\n tooltip: fontfamilyButtonNameTitle,\n onAction: () => handleAction(editor),\n });\n\n // Add the fontfamily Menu Item.\n // This allows it to be added to a standard menu, or a context menu.\n editor.ui.registry.addMenuItem(fontfamilyMenuItemName, {\n icon,\n text: fontfamilyMenuItemNameTitle,\n onAction: () => handleAction(editor),\n });\n\n // Define the font familys and their corresponding text labels\n const fontfamilys = [\n { family: \"Arial\", label: \"Arial\" },\n { family: \"Verdana\", label: \"Verdana\" },\n { family: \"Tahoma\", label: \"Tahoma\" },\n { family: \"Trebuchet MS\", label: \"Trebuchet MS\" },\n { family: \"Times New Roman\", label: \"Times New Roman\" },\n { family: \"Georgia\", label: \"Georgia\" },\n { family: \"Garamond\", label: \"Garamond\" },\n { family: \"Courier New\", label: \"Courier New\" },\n { family: \"Brush Script MT\", label: \"Brush Script MT\" },\n ];\n\n /**\n * Handle the font family menu item action.\n *\n * @param {Editor} editor - The editor instance.\n * @param {number} family - The font family to set.\n * @returns {Function} - The action handler function.\n */\n function handlefontfamily(editor, family) {\n return () => handleAction(editor, family);\n }\n\n // Create an array of submenu items using a map function\n const submenuItems = fontfamilys.map(({family, label}) => ({\n type: 'menuitem',\n text: label,\n onAction: handlefontfamily(editor, family),\n }));\n\n // Add the nested menu item to the editor UI\n editor.ui.registry.addNestedMenuItem(fontfamilyMenuItemName, {\n icon,\n text: fontfamilyMenuItemNameTitle,\n getSubmenuItems: () => submenuItems,\n });\n\n };\n};\n"],"names":["handleAction","editor","fontfamily","selection","dom","setAttrib","getNode","async","fontfamilyButtonNameTitle","fontfamilyMenuItemNameTitle","buttonImage","Promise","all","component","ui","registry","addIcon","icon","html","addButton","fontfamilyButtonName","tooltip","onAction","addMenuItem","fontfamilyMenuItemName","text","handlefontfamily","family","submenuItems","label","map","_ref","type","addNestedMenuItem","getSubmenuItems"],"mappings":";;;;;;;;MAqCMA,aAAe,CAACC,OAAQC,cAC1BD,OAAOE,UAAUC,IAAIC,UAAUJ,OAAOE,UAAUG,UAAW,QAAS,gBAAkBJ,+BAWlEK,gBAEhBC,0BACAC,4BACAC,mBACMC,QAAQC,IAAI,EAClB,mBAAU,oBAAqBC,oBAC/B,mBAAU,sBAAuBA,oBACjC,yBAAe,OAAQA,4BAGnBZ,SAEJA,OAAOa,GAAGC,SAASC,QAAQC,aAAMP,YAAYQ,MAG7CjB,OAAOa,GAAGC,SAASI,UAAUC,6BAAsB,CAC/CH,KAAAA,aACAI,QAASb,0BACTc,SAAU,IAAMtB,aAAaC,UAKjCA,OAAOa,GAAGC,SAASQ,YAAYC,+BAAwB,CACnDP,KAAAA,aACAQ,KAAMhB,4BACNa,SAAU,IAAMtB,aAAaC,mBAuBxByB,iBAAiBzB,OAAQ0B,cACvB,IAAM3B,aAAaC,OAAQ0B,cAIhCC,aAxBc,CAChB,CAAED,OAAQ,QAASE,MAAO,SAC1B,CAAEF,OAAQ,UAAWE,MAAO,WAC5B,CAAEF,OAAQ,SAAUE,MAAO,UAC3B,CAAEF,OAAQ,eAAgBE,MAAO,gBACjC,CAAEF,OAAQ,kBAAmBE,MAAO,mBACpC,CAAEF,OAAQ,UAAWE,MAAO,WAC5B,CAAEF,OAAQ,WAAYE,MAAO,YAC7B,CAAEF,OAAQ,cAAeE,MAAO,eAChC,CAAEF,OAAQ,kBAAmBE,MAAO,oBAePC,KAAIC,WAACJ,OAACA,OAADE,MAASA,kBAAY,CACvDG,KAAM,WACNP,KAAMI,MACNP,SAAUI,iBAAiBzB,OAAQ0B,YAIvC1B,OAAOa,GAAGC,SAASkB,kBAAkBT,+BAAwB,CACzDP,KAAAA,aACAQ,KAAMhB,4BACNyB,gBAAiB,IAAMN"} \ 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 * tiny_fontfamily for Moodle.\n *\n * @module tiny_fontfamily\n * @copyright 2024 Mikko Haiku \n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nimport {getFontList} from './options';\nimport {getButtonImage} from 'editor_tiny/utils';\nimport {get_string as getString} from 'core/str';\nimport {\n component,\n fontfamilyButtonName,\n fontfamilyMenuItemName,\n icon,\n} from './common';\n\n/**\n * Handle the action for your plugin.\n * @param {TinyMCE.editor} editor The tinyMCE editor instance.\n * @param {integer} fontfamily Font family in integer.\n */\nconst handleAction = (editor, fontfamily) => {\n editor.selection.dom.setAttrib(editor.selection.getNode(), \"style\", \"font-family: \" + fontfamily);\n};\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 const [\n fontfamilyButtonNameTitle,\n fontfamilyMenuItemNameTitle,\n buttonImage,\n ] = await Promise.all([\n getString('button_fontfamily', component),\n getString('menuitem_fontfamily', component),\n getButtonImage('icon', component),\n ]);\n\n return (editor) => {\n\n const fontList = getFontList(editor);\n\n // If there is only one font available, we don't need the plugin.\n if (fontList.length < 2) {\n return;\n }\n\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 // Register the fontfamily Toolbar Button.\n editor.ui.registry.addButton(fontfamilyButtonName, {\n icon,\n tooltip: fontfamilyButtonNameTitle,\n onAction: () => handleAction(editor),\n });\n\n // Add the fontfamily Menu Item.\n // This allows it to be added to a standard menu, or a context menu.\n editor.ui.registry.addMenuItem(fontfamilyMenuItemName, {\n icon,\n text: fontfamilyMenuItemNameTitle,\n onAction: () => handleAction(editor),\n });\n\n // Define the font families and their corresponding text labels\n const fontfamilies = fontList.map(font => ({ family: font, label: font }));\n\n /**\n * Handle the font family menu item action.\n *\n * @param {Editor} editor - The editor instance.\n * @param {number} family - The font family to set.\n * @returns {Function} - The action handler function.\n */\n function handlefontfamily(editor, family) {\n return () => handleAction(editor, family);\n }\n\n // Create an array of submenu items using a map function\n const submenuItems = fontfamilies.map(({family, label}) => ({\n type: 'menuitem',\n text: label,\n onAction: handlefontfamily(editor, family),\n }));\n\n // Add the nested menu item to the editor UI\n editor.ui.registry.addNestedMenuItem(fontfamilyMenuItemName, {\n icon,\n text: fontfamilyMenuItemNameTitle,\n getSubmenuItems: () => submenuItems,\n });\n\n };\n};\n"],"names":["handleAction","editor","fontfamily","selection","dom","setAttrib","getNode","async","fontfamilyButtonNameTitle","fontfamilyMenuItemNameTitle","buttonImage","Promise","all","component","fontList","length","ui","registry","addIcon","icon","html","addButton","fontfamilyButtonName","tooltip","onAction","addMenuItem","fontfamilyMenuItemName","text","handlefontfamily","family","submenuItems","map","font","label","_ref","type","addNestedMenuItem","getSubmenuItems"],"mappings":";;;;;;;;MAsCMA,aAAe,CAACC,OAAQC,cAC1BD,OAAOE,UAAUC,IAAIC,UAAUJ,OAAOE,UAAUG,UAAW,QAAS,gBAAkBJ,+BAWlEK,gBAEhBC,0BACAC,4BACAC,mBACMC,QAAQC,IAAI,EAClB,mBAAU,oBAAqBC,oBAC/B,mBAAU,sBAAuBA,oBACjC,yBAAe,OAAQA,4BAGnBZ,eAEEa,UAAW,wBAAYb,WAGzBa,SAASC,OAAS,SAKtBd,OAAOe,GAAGC,SAASC,QAAQC,aAAMT,YAAYU,MAG7CnB,OAAOe,GAAGC,SAASI,UAAUC,6BAAsB,CAC/CH,KAAAA,aACAI,QAASf,0BACTgB,SAAU,IAAMxB,aAAaC,UAKjCA,OAAOe,GAAGC,SAASQ,YAAYC,+BAAwB,CACnDP,KAAAA,aACAQ,KAAMlB,4BACNe,SAAU,IAAMxB,aAAaC,mBAaxB2B,iBAAiB3B,OAAQ4B,cACvB,IAAM7B,aAAaC,OAAQ4B,cAIhCC,aAdehB,SAASiB,KAAIC,QAAWH,OAAQG,KAAMC,MAAOD,SAchCD,KAAIG,WAACL,OAACA,OAADI,MAASA,kBAAY,CACxDE,KAAM,WACNR,KAAMM,MACNT,SAAUI,iBAAiB3B,OAAQ4B,YAIvC5B,OAAOe,GAAGC,SAASmB,kBAAkBV,+BAAwB,CACzDP,KAAAA,aACAQ,KAAMlB,4BACN4B,gBAAiB,IAAMP"} \ No newline at end of file diff --git a/amd/build/common.min.js b/amd/build/common.min.js index 84ad229..1d4bac8 100644 --- a/amd/build/common.min.js +++ b/amd/build/common.min.js @@ -1,11 +1,11 @@ define("tiny_fontfamily/common",["exports"],(function(_exports){Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.default=void 0; /** - * Common values helper for the Moodle tiny_fontfamily plugin. + * tiny_fontfamily for Moodle. * - * @module plugintype_pluginname/common - * @copyright 2023 Mikko Haiku + * @module tiny_fontfamily + * @copyright 2024 Mikko Haiku * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -const component="tiny_fontfamily";var _default={component:component,pluginName:"".concat(component,"/plugin"),icon:component,fontfamilyButtonName:"".concat(component,"_fontfamily"),fontfamilyMenuItemName:"".concat(component,"_fontfamily")};return _exports.default=_default,_exports.default})); +const component="tiny_fontfamily";var _default={component:component,pluginName:`${component}/plugin`,icon:component,fontfamilyButtonName:`${component}_fontfamily`,fontfamilyMenuItemName:`${component}_fontfamily`};return _exports.default=_default,_exports.default})); //# sourceMappingURL=common.min.js.map \ No newline at end of file diff --git a/amd/build/common.min.js.map b/amd/build/common.min.js.map index b7668fe..9a53195 100644 --- a/amd/build/common.min.js.map +++ b/amd/build/common.min.js.map @@ -1 +1 @@ -{"version":3,"file":"common.min.js","sources":["../src/common.js"],"sourcesContent":["// This file is part of Moodle - https://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see .\n\n/**\n * Common values helper for the Moodle tiny_fontfamily plugin.\n *\n * @module plugintype_pluginname/common\n * @copyright 2023 Mikko Haiku \n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nconst component = 'tiny_fontfamily';\n\nexport default {\n component,\n pluginName: `${component}/plugin`,\n icon: component,\n fontfamilyButtonName: `${component}_fontfamily`,\n fontfamilyMenuItemName: `${component}_fontfamily`,\n};\n"],"names":["component","pluginName","icon","fontfamilyButtonName","fontfamilyMenuItemName"],"mappings":";;;;;;;;MAuBMA,UAAY,+BAEH,CACXA,UAAAA,UACAC,qBAAeD,qBACfE,KAAMF,UACNG,+BAAyBH,yBACzBI,iCAA2BJ"} \ No newline at end of file +{"version":3,"file":"common.min.js","sources":["../src/common.js"],"sourcesContent":["// This file is part of Moodle - https://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see .\n\n/**\n * tiny_fontfamily for Moodle.\n *\n * @module tiny_fontfamily\n * @copyright 2024 Mikko Haiku \n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nconst component = 'tiny_fontfamily';\n\nexport default {\n component,\n pluginName: `${component}/plugin`,\n icon: component,\n fontfamilyButtonName: `${component}_fontfamily`,\n fontfamilyMenuItemName: `${component}_fontfamily`,\n};\n"],"names":["component","pluginName","icon","fontfamilyButtonName","fontfamilyMenuItemName"],"mappings":";;;;;;;;MAuBMA,UAAY,+BAEH,CACXA,UAAAA,UACAC,WAAa,GAAED,mBACfE,KAAMF,UACNG,qBAAuB,GAAEH,uBACzBI,uBAAyB,GAAEJ"} \ No newline at end of file diff --git a/amd/build/configuration.min.js b/amd/build/configuration.min.js index f5ed1c3..4b1cc27 100644 --- a/amd/build/configuration.min.js +++ b/amd/build/configuration.min.js @@ -1,9 +1,9 @@ define("tiny_fontfamily/configuration",["exports","./common","editor_tiny/utils"],(function(_exports,_common,_utils){Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.configure=void 0; /** - * Tiny tiny_fontfamily for Moodle. + * tiny_fontfamily for Moodle. * - * @module plugintype_pluginname/plugin - * @copyright 2023 Mikko Haiku + * @module tiny_fontfamily + * @copyright 2024 Mikko Haiku * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ const getToolbarConfiguration=instanceConfig=>instanceConfig.toolbar,getMenuConfiguration=instanceConfig=>{let menu=instanceConfig.menu;return menu=(0,_utils.addMenubarItem)(menu,"format",[_common.fontfamilyMenuItemName].join(" ")),menu};_exports.configure=instanceConfig=>({toolbar:getToolbarConfiguration(instanceConfig),menu:getMenuConfiguration(instanceConfig)})})); diff --git a/amd/build/configuration.min.js.map b/amd/build/configuration.min.js.map index 35cec31..73aed48 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":["/* eslint-disable no-undef */\n// 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_fontfamily for Moodle.\n *\n * @module plugintype_pluginname/plugin\n * @copyright 2023 Mikko Haiku \n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nimport {\n fontfamilyButtonName,\n fontfamilyMenuItemName,\n} from './common';\n\nimport {\n addMenubarItem,\n addToolbarButtons,\n} from 'editor_tiny/utils';\n\nconst getToolbarConfiguration = (instanceConfig) => {\n let toolbar = instanceConfig.toolbar;\n return toolbar;\n};\n\nconst getMenuConfiguration = (instanceConfig) => {\n let menu = instanceConfig.menu;\n menu = addMenubarItem(menu, 'format', [\n fontfamilyMenuItemName,\n ].join(' '));\n\n return menu;\n};\n\nexport const configure = (instanceConfig) => {\n return {\n toolbar: getToolbarConfiguration(instanceConfig),\n menu: getMenuConfiguration(instanceConfig),\n };\n};\n"],"names":["getToolbarConfiguration","instanceConfig","toolbar","getMenuConfiguration","menu","fontfamilyMenuItemName","join"],"mappings":";;;;;;;;MAkCMA,wBAA2BC,gBACfA,eAAeC,QAI3BC,qBAAwBF,qBACtBG,KAAOH,eAAeG,YAC1BA,MAAO,yBAAeA,KAAM,SAAU,CAClCC,gCACFC,KAAK,MAEAF,yBAGeH,iBACf,CACHC,QAASF,wBAAwBC,gBACjCG,KAAMD,qBAAqBF"} \ 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_fontfamily for Moodle.\n *\n * @module tiny_fontfamily\n * @copyright 2024 Mikko Haiku \n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nimport {\n fontfamilyMenuItemName,\n} from './common';\n\nimport {\n addMenubarItem,\n} from 'editor_tiny/utils';\n\nconst getToolbarConfiguration = (instanceConfig) => {\n let toolbar = instanceConfig.toolbar;\n return toolbar;\n};\n\nconst getMenuConfiguration = (instanceConfig) => {\n let menu = instanceConfig.menu;\n menu = addMenubarItem(menu, 'format', [\n fontfamilyMenuItemName,\n ].join(' '));\n\n return menu;\n};\n\nexport const configure = (instanceConfig) => {\n return {\n toolbar: getToolbarConfiguration(instanceConfig),\n menu: getMenuConfiguration(instanceConfig),\n };\n};\n"],"names":["getToolbarConfiguration","instanceConfig","toolbar","getMenuConfiguration","menu","fontfamilyMenuItemName","join"],"mappings":";;;;;;;;MA+BMA,wBAA2BC,gBACfA,eAAeC,QAI3BC,qBAAwBF,qBACtBG,KAAOH,eAAeG,YAC1BA,MAAO,yBAAeA,KAAM,SAAU,CAClCC,gCACFC,KAAK,MAEAF,yBAGeH,iBACf,CACHC,QAASF,wBAAwBC,gBACjCG,KAAMD,qBAAqBF"} \ No newline at end of file diff --git a/amd/build/functions.min.js b/amd/build/functions.min.js new file mode 100644 index 0000000..d3409ef --- /dev/null +++ b/amd/build/functions.min.js @@ -0,0 +1,13 @@ +define("tiny_fontfamily/functions",["exports"],(function(_exports){Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.typeOf=_exports.isType$1=_exports.isArrayOf=_exports.isArray=_exports.hasProto=void 0; +/** + * Helper functions that come from the theme.js of the TinyMCE and that are + * heavily used by the colorswat.js. + * + * @module tiny_fontcolor + * @copyright 2023 Luca Bösch + * @copyright 2023 Stephan Robotta + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +const hasProto=(v,constructor,predicate)=>{return!!predicate(v,constructor.prototype)||(null===(_v$constructor=v.constructor)||void 0===_v$constructor?void 0:_v$constructor.name)===constructor.name;var _v$constructor};_exports.hasProto=hasProto;const typeOf=x=>{const t=typeof x;return null===x?"null":"object"===t&&Array.isArray(x)?"array":"object"===t&&hasProto(x,String,((o,proto)=>proto.isPrototypeOf(o)))?"string":t};_exports.typeOf=typeOf;const isType$1=type=>value=>typeOf(value)===type;_exports.isType$1=isType$1;const isArray=isType$1("array");_exports.isArray=isArray;_exports.isArrayOf=(value,pred)=>{if(isArray(value)){for(let i=0,len=value.length;i.\n\n/**\n * Helper functions that come from the theme.js of the TinyMCE and that are\n * heavily used by the colorswat.js.\n *\n * @module tiny_fontcolor\n * @copyright 2023 Luca Bösch \n * @copyright 2023 Stephan Robotta \n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nexport const hasProto = (v, constructor, predicate) => {\n if (predicate(v, constructor.prototype)) {\n return true;\n } else {\n return v.constructor?.name === constructor.name;\n }\n};\nexport const typeOf = x => {\n const t = typeof x;\n if (x === null) {\n return 'null';\n } else if (t === 'object' && Array.isArray(x)) {\n return 'array';\n } else if (t === 'object' && hasProto(x, String, (o, proto) => proto.isPrototypeOf(o))) {\n return 'string';\n } else {\n return t;\n }\n};\nexport const isType$1 = type => value => typeOf(value) === type;\nexport const isArray = isType$1('array');\nexport const isArrayOf = (value, pred) => {\n if (isArray(value)) {\n for (let i = 0, len = value.length; i < len; ++i) {\n if (!pred(value[i])) {\n return false;\n }\n }\n return true;\n }\n return false;\n};"],"names":["hasProto","v","constructor","predicate","prototype","name","typeOf","x","t","Array","isArray","String","o","proto","isPrototypeOf","isType$1","type","value","pred","i","len","length"],"mappings":";;;;;;;;;;MAyBaA,SAAW,CAACC,EAAGC,YAAaC,qBACnCA,UAAUF,EAAGC,YAAYE,oCAGpBH,EAAEC,4DAAaG,QAASH,YAAYG,0DAGlCC,OAASC,UACdC,SAAWD,SACP,OAANA,EACK,OACQ,WAANC,GAAkBC,MAAMC,QAAQH,GAClC,QACQ,WAANC,GAAkBR,SAASO,EAAGI,QAAQ,CAACC,EAAGC,QAAUA,MAAMC,cAAcF,KAC1E,SAEAJ,gCAGEO,SAAWC,MAAQC,OAASX,OAAOW,SAAWD,sCAC9CN,QAAUK,SAAS,qDACP,CAACE,MAAOC,WAC3BR,QAAQO,OAAQ,KACb,IAAIE,EAAI,EAAGC,IAAMH,MAAMI,OAAQF,EAAIC,MAAOD,MACxCD,KAAKD,MAAME,WACP,SAGJ,SAEF"} \ No newline at end of file diff --git a/amd/build/options.min.js b/amd/build/options.min.js new file mode 100644 index 0000000..67796a9 --- /dev/null +++ b/amd/build/options.min.js @@ -0,0 +1,11 @@ +define("tiny_fontfamily/options",["exports","editor_tiny/options","./common"],(function(_exports,_options,_common){Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.register=_exports.getFontList=void 0; +/** + * tiny_fontfamily for Moodle. + * + * @module tiny_fontfamily + * @copyright 2024 Mikko Haiku + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +const fonts=(0,_options.getPluginOptionName)(_common.pluginName,"fonts");_exports.register=editor=>{editor.options.register(fonts,{processor:"Array",default:[]})};_exports.getFontList=editor=>editor.options.get(fonts)})); + +//# sourceMappingURL=options.min.js.map \ No newline at end of file diff --git a/amd/build/options.min.js.map b/amd/build/options.min.js.map new file mode 100644 index 0000000..c1e8d69 --- /dev/null +++ b/amd/build/options.min.js.map @@ -0,0 +1 @@ +{"version":3,"file":"options.min.js","sources":["../src/options.js"],"sourcesContent":["// This file is part of Moodle - https://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see .\n\n/**\n * tiny_fontfamily for Moodle.\n *\n * @module tiny_fontfamily\n * @copyright 2024 Mikko Haiku \n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nimport {getPluginOptionName} from 'editor_tiny/options';\nimport {pluginName} from './common';\n\nconst fonts = getPluginOptionName(pluginName, 'fonts');\n\n/**\n * Register the options for the Tiny Equation plugin.\n *\n * @param {TinyMCE} editor\n */\nexport const register = (editor) => {\n\n editor.options.register(fonts, {\n processor: 'Array',\n \"default\": [],\n });\n\n};\n\n/**\n * Get the list of fonts.\n *\n * @param {TinyMCE.editor} editor\n * @returns {Array} Array.\n */\nexport const getFontList = (editor) => editor.options.get(fonts);\n"],"names":["fonts","pluginName","editor","options","register","processor","get"],"mappings":";;;;;;;;MA0BMA,OAAQ,gCAAoBC,mBAAY,2BAOrBC,SAErBA,OAAOC,QAAQC,SAASJ,MAAO,CAC3BK,UAAW,gBACA,2BAWSH,QAAWA,OAAOC,QAAQG,IAAIN"} \ No newline at end of file diff --git a/amd/build/plugin.min.js b/amd/build/plugin.min.js index 752b03a..551fdc9 100644 --- a/amd/build/plugin.min.js +++ b/amd/build/plugin.min.js @@ -1,10 +1,10 @@ -define("tiny_fontfamily/plugin",["exports","editor_tiny/loader","editor_tiny/utils","./common","./commands","./configuration"],(function(_exports,_loader,_utils,_common,_commands,Configuration){function _getRequireWildcardCache(nodeInterop){if("function"!=typeof WeakMap)return null;var cacheBabelInterop=new WeakMap,cacheNodeInterop=new WeakMap;return(_getRequireWildcardCache=function(nodeInterop){return nodeInterop?cacheNodeInterop:cacheBabelInterop})(nodeInterop)}Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.default=void 0,Configuration=function(obj,nodeInterop){if(!nodeInterop&&obj&&obj.__esModule)return obj;if(null===obj||"object"!=typeof obj&&"function"!=typeof obj)return{default:obj};var cache=_getRequireWildcardCache(nodeInterop);if(cache&&cache.has(obj))return cache.get(obj);var newObj={},hasPropertyDescriptor=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var key in obj)if("default"!==key&&Object.prototype.hasOwnProperty.call(obj,key)){var desc=hasPropertyDescriptor?Object.getOwnPropertyDescriptor(obj,key):null;desc&&(desc.get||desc.set)?Object.defineProperty(newObj,key,desc):newObj[key]=obj[key]}newObj.default=obj,cache&&cache.set(obj,newObj);return newObj} +define("tiny_fontfamily/plugin",["exports","editor_tiny/loader","editor_tiny/utils","./common","./commands","./configuration","./options"],(function(_exports,_loader,_utils,_common,_commands,Configuration,_options){function _getRequireWildcardCache(nodeInterop){if("function"!=typeof WeakMap)return null;var cacheBabelInterop=new WeakMap,cacheNodeInterop=new WeakMap;return(_getRequireWildcardCache=function(nodeInterop){return nodeInterop?cacheNodeInterop:cacheBabelInterop})(nodeInterop)}Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.default=void 0,Configuration=function(obj,nodeInterop){if(!nodeInterop&&obj&&obj.__esModule)return obj;if(null===obj||"object"!=typeof obj&&"function"!=typeof obj)return{default:obj};var cache=_getRequireWildcardCache(nodeInterop);if(cache&&cache.has(obj))return cache.get(obj);var newObj={},hasPropertyDescriptor=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var key in obj)if("default"!==key&&Object.prototype.hasOwnProperty.call(obj,key)){var desc=hasPropertyDescriptor?Object.getOwnPropertyDescriptor(obj,key):null;desc&&(desc.get||desc.set)?Object.defineProperty(newObj,key,desc):newObj[key]=obj[key]}newObj.default=obj,cache&&cache.set(obj,newObj);return newObj} /** - * Tiny tiny_fontfamily for Moodle. + * tiny_fontfamily for Moodle. * - * @module plugintype_pluginname/plugin - * @copyright 2023 Mikko Haiku + * @module tiny_fontfamily + * @copyright 2024 Mikko Haiku * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */(Configuration);var _default=new Promise((async resolve=>{const[tinyMCE,pluginMetadata,setupCommands]=await Promise.all([(0,_loader.getTinyMCE)(),(0,_utils.getPluginMetadata)(_common.component,_common.pluginName),(0,_commands.getSetup)()]);tinyMCE.PluginManager.add(_common.pluginName,(editor=>(setupCommands(editor),pluginMetadata))),resolve([_common.pluginName,Configuration])}));return _exports.default=_default,_exports.default})); + */(Configuration);var _default=new Promise((async resolve=>{const[tinyMCE,pluginMetadata,setupCommands]=await Promise.all([(0,_loader.getTinyMCE)(),(0,_utils.getPluginMetadata)(_common.component,_common.pluginName),(0,_commands.getSetup)()]);tinyMCE.PluginManager.add(_common.pluginName,(editor=>((0,_options.register)(editor),setupCommands(editor),pluginMetadata))),resolve([_common.pluginName,Configuration])}));return _exports.default=_default,_exports.default})); //# sourceMappingURL=plugin.min.js.map \ No newline at end of file diff --git a/amd/build/plugin.min.js.map b/amd/build/plugin.min.js.map index 291f441..a30afec 100644 --- a/amd/build/plugin.min.js.map +++ b/amd/build/plugin.min.js.map @@ -1 +1 @@ -{"version":3,"file":"plugin.min.js","sources":["../src/plugin.js"],"sourcesContent":["// This file is part of Moodle - https://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see .\n\n/**\n * Tiny tiny_fontfamily for Moodle.\n *\n * @module plugintype_pluginname/plugin\n * @copyright 2023 Mikko Haiku \n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nimport {getTinyMCE} from 'editor_tiny/loader';\nimport {getPluginMetadata} from 'editor_tiny/utils';\n\nimport {component, pluginName} from './common';\nimport {getSetup as getCommandSetup} from './commands';\nimport * as Configuration from './configuration';\n\n// Setup the tiny_fontfamily Plugin.\nexport default new Promise(async(resolve) => {\n // Note: The PluginManager.add function does not support asynchronous configuration.\n // Perform any asynchronous configuration here, and then call the PluginManager.add function.\n const [\n tinyMCE,\n pluginMetadata,\n setupCommands,\n ] = await Promise.all([\n getTinyMCE(),\n getPluginMetadata(component, pluginName),\n getCommandSetup(),\n ]);\n\n // Reminder: Any asynchronous code must be run before this point.\n tinyMCE.PluginManager.add(pluginName, (editor) => {\n // Setup any commands such as buttons, menu items, and so on.\n setupCommands(editor);\n\n // Return the pluginMetadata object. This is used by TinyMCE to display a help link for your plugin.\n return pluginMetadata;\n });\n\n resolve([pluginName, Configuration]);\n});\n"],"names":["Promise","async","tinyMCE","pluginMetadata","setupCommands","all","component","pluginName","PluginManager","add","editor","resolve","Configuration"],"mappings":";;;;;;;kCA+Be,IAAIA,SAAQC,MAAAA,gBAInBC,QACAC,eACAC,qBACMJ,QAAQK,IAAI,EAClB,yBACA,4BAAkBC,kBAAWC,qBAC7B,0BAIJL,QAAQM,cAAcC,IAAIF,oBAAaG,SAEnCN,cAAcM,QAGPP,kBAGXQ,QAAQ,CAACJ,mBAAYK"} \ No newline at end of file +{"version":3,"file":"plugin.min.js","sources":["../src/plugin.js"],"sourcesContent":["// This file is part of Moodle - https://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see .\n\n/**\n * tiny_fontfamily for Moodle.\n *\n * @module tiny_fontfamily\n * @copyright 2024 Mikko Haiku \n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nimport {getTinyMCE} from 'editor_tiny/loader';\nimport {getPluginMetadata} from 'editor_tiny/utils';\n\nimport {component, pluginName} from './common';\nimport {getSetup as getCommandSetup} from './commands';\nimport * as Configuration from './configuration';\nimport {register as registerOptions} from './options';\n\n// Setup the tiny_fontfamily Plugin.\n// eslint-disable-next-line no-async-promise-executor\nexport default new Promise(async(resolve) => {\n // Note: The PluginManager.add function does not support asynchronous configuration.\n // Perform any asynchronous configuration here, and then call the PluginManager.add function.\n const [\n tinyMCE,\n pluginMetadata,\n setupCommands,\n ] = await Promise.all([\n getTinyMCE(),\n getPluginMetadata(component, pluginName),\n getCommandSetup(),\n ]);\n\n // Reminder: Any asynchronous code must be run before this point.\n tinyMCE.PluginManager.add(pluginName, (editor) => {\n\n registerOptions(editor);\n\n // Setup any commands such as buttons, menu items, and so on.\n setupCommands(editor);\n\n // Return the pluginMetadata object. This is used by TinyMCE to display a help link for your plugin.\n return pluginMetadata;\n });\n\n resolve([pluginName, Configuration]);\n});\n"],"names":["Promise","async","tinyMCE","pluginMetadata","setupCommands","all","component","pluginName","PluginManager","add","editor","resolve","Configuration"],"mappings":";;;;;;;kCAiCe,IAAIA,SAAQC,MAAAA,gBAInBC,QACAC,eACAC,qBACMJ,QAAQK,IAAI,EAClB,yBACA,4BAAkBC,kBAAWC,qBAC7B,0BAIJL,QAAQM,cAAcC,IAAIF,oBAAaG,+BAEnBA,QAGhBN,cAAcM,QAGPP,kBAGXQ,QAAQ,CAACJ,mBAAYK"} \ No newline at end of file diff --git a/amd/src/commands.js b/amd/src/commands.js index 84f2529..f5d5a8f 100644 --- a/amd/src/commands.js +++ b/amd/src/commands.js @@ -14,13 +14,14 @@ // along with Moodle. If not, see . /** - * Commands helper for the Moodle tiny_fontfamily plugin. + * tiny_fontfamily for Moodle. * - * @module plugintype_pluginname/commands - * @copyright 2023 Mikko Haiku + * @module tiny_fontfamily + * @copyright 2024 Mikko Haiku * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ +import {getFontList} from './options'; import {getButtonImage} from 'editor_tiny/utils'; import {get_string as getString} from 'core/str'; import { @@ -59,6 +60,14 @@ export const getSetup = async() => { ]); return (editor) => { + + const fontList = getFontList(editor); + + // If there is only one font available, we don't need the plugin. + if (fontList.length < 2) { + return; + } + // Register the Moodle SVG as an icon suitable for use as a TinyMCE toolbar button. editor.ui.registry.addIcon(icon, buttonImage.html); @@ -77,18 +86,8 @@ export const getSetup = async() => { onAction: () => handleAction(editor), }); - // Define the font familys and their corresponding text labels - const fontfamilys = [ - { family: "Arial", label: "Arial" }, - { family: "Verdana", label: "Verdana" }, - { family: "Tahoma", label: "Tahoma" }, - { family: "Trebuchet MS", label: "Trebuchet MS" }, - { family: "Times New Roman", label: "Times New Roman" }, - { family: "Georgia", label: "Georgia" }, - { family: "Garamond", label: "Garamond" }, - { family: "Courier New", label: "Courier New" }, - { family: "Brush Script MT", label: "Brush Script MT" }, - ]; + // Define the font families and their corresponding text labels + const fontfamilies = fontList.map(font => ({ family: font, label: font })); /** * Handle the font family menu item action. @@ -102,7 +101,7 @@ export const getSetup = async() => { } // Create an array of submenu items using a map function - const submenuItems = fontfamilys.map(({family, label}) => ({ + const submenuItems = fontfamilies.map(({family, label}) => ({ type: 'menuitem', text: label, onAction: handlefontfamily(editor, family), diff --git a/amd/src/common.js b/amd/src/common.js index 689874a..1c745ea 100644 --- a/amd/src/common.js +++ b/amd/src/common.js @@ -14,10 +14,10 @@ // along with Moodle. If not, see . /** - * Common values helper for the Moodle tiny_fontfamily plugin. + * tiny_fontfamily for Moodle. * - * @module plugintype_pluginname/common - * @copyright 2023 Mikko Haiku + * @module tiny_fontfamily + * @copyright 2024 Mikko Haiku * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ diff --git a/amd/src/configuration.js b/amd/src/configuration.js index 79b4029..b34d463 100644 --- a/amd/src/configuration.js +++ b/amd/src/configuration.js @@ -1,4 +1,3 @@ -/* eslint-disable no-undef */ // This file is part of Moodle - https://moodle.org/ // // Moodle is free software: you can redistribute it and/or modify @@ -15,21 +14,19 @@ // along with Moodle. If not, see . /** - * Tiny tiny_fontfamily for Moodle. + * tiny_fontfamily for Moodle. * - * @module plugintype_pluginname/plugin - * @copyright 2023 Mikko Haiku + * @module tiny_fontfamily + * @copyright 2024 Mikko Haiku * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ import { - fontfamilyButtonName, fontfamilyMenuItemName, } from './common'; import { addMenubarItem, - addToolbarButtons, } from 'editor_tiny/utils'; const getToolbarConfiguration = (instanceConfig) => { diff --git a/amd/src/options.js b/amd/src/options.js new file mode 100644 index 0000000..e9ce5de --- /dev/null +++ b/amd/src/options.js @@ -0,0 +1,49 @@ +// This file is part of Moodle - https://moodle.org/ +// +// Moodle is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Moodle is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Moodle. If not, see . + +/** + * tiny_fontfamily for Moodle. + * + * @module tiny_fontfamily + * @copyright 2024 Mikko Haiku + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +import {getPluginOptionName} from 'editor_tiny/options'; +import {pluginName} from './common'; + +const fonts = getPluginOptionName(pluginName, 'fonts'); + +/** + * Register the options for the Tiny Equation plugin. + * + * @param {TinyMCE} editor + */ +export const register = (editor) => { + + editor.options.register(fonts, { + processor: 'Array', + "default": [], + }); + +}; + +/** + * Get the list of fonts. + * + * @param {TinyMCE.editor} editor + * @returns {Array} Array. + */ +export const getFontList = (editor) => editor.options.get(fonts); diff --git a/amd/src/plugin.js b/amd/src/plugin.js index 5ad5975..42cba95 100644 --- a/amd/src/plugin.js +++ b/amd/src/plugin.js @@ -14,10 +14,10 @@ // along with Moodle. If not, see . /** - * Tiny tiny_fontfamily for Moodle. + * tiny_fontfamily for Moodle. * - * @module plugintype_pluginname/plugin - * @copyright 2023 Mikko Haiku + * @module tiny_fontfamily + * @copyright 2024 Mikko Haiku * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ @@ -27,8 +27,10 @@ import {getPluginMetadata} from 'editor_tiny/utils'; import {component, pluginName} from './common'; import {getSetup as getCommandSetup} from './commands'; import * as Configuration from './configuration'; +import {register as registerOptions} from './options'; // Setup the tiny_fontfamily Plugin. +// eslint-disable-next-line no-async-promise-executor export default new Promise(async(resolve) => { // Note: The PluginManager.add function does not support asynchronous configuration. // Perform any asynchronous configuration here, and then call the PluginManager.add function. @@ -44,6 +46,9 @@ export default new Promise(async(resolve) => { // Reminder: Any asynchronous code must be run before this point. tinyMCE.PluginManager.add(pluginName, (editor) => { + + registerOptions(editor); + // Setup any commands such as buttons, menu items, and so on. setupCommands(editor); diff --git a/classes/plugininfo.php b/classes/plugininfo.php index cf67840..555e0ab 100644 --- a/classes/plugininfo.php +++ b/classes/plugininfo.php @@ -72,6 +72,5 @@ public static function get_plugin_configuration_for_context( $config = []; $config['fonts'] = explode("\r\n", get_config('tiny_fontfamily', 'fonts')); return $config; - } } diff --git a/version.php b/version.php index a210545..ba9fc74 100644 --- a/version.php +++ b/version.php @@ -25,7 +25,7 @@ defined('MOODLE_INTERNAL') || die(); $plugin->component = 'tiny_fontfamily'; -$plugin->release = '1.0.0'; +$plugin->release = '1.0.1'; $plugin->maturity = MATURITY_STABLE; $plugin->requires = 2022112800; -$plugin->version = 2024083000; +$plugin->version = 2024100900;