AutorÃa | Ultima modificación | Ver Log |
{"version":3,"file":"commands.min.js","sources":["../src/commands.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 <http://www.gnu.org/licenses/>.\n\n/**\n * Tiny Media commands.\n *\n * @module tiny_media/commands\n * @copyright 2022 Huong Nguyen <huongnv13@gmail.com>\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nimport {getStrings} from
'core/str';\nimport {\n component,\n imageButtonName,\n videoButtonName,\n mediaManagerButtonName\n} from './common';\nimport MediaImage from './image';\nimport MediaEmbed from './embed';\nimport MediaManager from './manager';\nimport {getButtonImage} from 'editor_tiny/utils';\n\nconst isImage = (node) => node.nodeName.toLowerCase() === 'img';\nconst isVideo = (node) => node.nodeName.toLowerCase() === 'video' || node.nodeName.toLowerCase() === 'audio';\n\nconst registerImageCommand = (editor, imageButtonText) => {\n const imageIcon = 'image';\n const handleImageAction = () => {\n const mediaImage = new MediaImage(editor);\n mediaImage.displayDialogue();\n };\n\n // Register the Menu Button as a toggle.\n // This means that when highlighted over an existing Media Image element it will show as toggled on.\n editor.ui.registry.addToggleButton(imageButtonName, {\n icon: imageIcon,\n tooltip: imageButtonText,\n onAction: handleImageAction,\n
onSetup: api => {\n return editor.selection.selectorChangedWithUnbind(\n 'img:not([data-mce-object]):not([data-mce-placeholder]),figure.image',\n api.setActive\n ).unbind;\n }\n });\n\n editor.ui.registry.addMenuItem(imageButtonName, {\n icon: imageIcon,\n text: imageButtonText,\n onAction: handleImageAction,\n });\n\n editor.ui.registry.addContextToolbar(imageButtonName, {\n predicate: isImage,\n items: imageButtonName,\n position: 'node',\n scope: 'node'\n });\n\n editor.ui.registry.addContextMenu(imageButtonName, {\n update: isImage,\n });\n};\n\nconst registerEmbedCommand = (editor, videoButtonText) => {\n const videoIcon = 'embed';\n const handleEmbedAction = () => {\n const mediaImage = new MediaEmbed(editor);\n mediaImage.displayDialogue();\n };\n\n // Register the Menu Button as a toggle.\n // This means that when highlighted over an exis
ting Media Video element it will show as toggled on.\n editor.ui.registry.addToggleButton(videoButtonName, {\n icon: videoIcon,\n tooltip: videoButtonText,\n onAction: handleEmbedAction,\n onSetup: api => {\n return editor.selection.selectorChangedWithUnbind(\n 'video:not([data-mce-object]):not([data-mce-placeholder]),' +\n 'audio:not([data-mce-object]):not([data-mce-placeholder])',\n api.setActive\n ).unbind;\n }\n });\n\n editor.ui.registry.addMenuItem(videoButtonName, {\n icon: videoIcon,\n text: videoButtonText,\n onAction: handleEmbedAction,\n });\n\n editor.ui.registry.addContextMenu(videoButtonName, {\n update: isVideo,\n });\n\n editor.ui.registry.addContextToolbar(videoButtonName, {\n predicate: isVideo,\n items: videoButtonName,\n position: 'node',\n scope: 'node'\n });\n\n};\n\nconst registerManagerCommand = (editor, m
ediaManagerButtonText, mediaManagerButtonImage) => {\n const mediaManagerIcon = 'filemanager';\n const handleMediaManager = () => {\n const mediaManager = new MediaManager(editor);\n mediaManager.displayDialogue();\n };\n\n // Register the Menu Button as a toggle.\n editor.ui.registry.addIcon(mediaManagerIcon, mediaManagerButtonImage.html);\n editor.ui.registry.addButton(mediaManagerButtonName, {\n icon: mediaManagerIcon,\n tooltip: mediaManagerButtonText,\n onAction: () => {\n handleMediaManager();\n }\n });\n\n editor.ui.registry.addMenuItem(mediaManagerButtonName, {\n icon: mediaManagerIcon,\n text: mediaManagerButtonText,\n onAction: () => {\n handleMediaManager();\n }\n });\n};\n\nexport const getSetup = async() => {\n const [\n imageButtonText,\n mediaButtonText,\n mediaManagerButtonText\n ] = await getStrings(['imagebuttontitle', 'mediabuttontitle', 'mediama
nagerbuttontitle'].map((key) => ({key, component})));\n\n const [\n mediaManagerButtonImage,\n ] = await Promise.all([\n getButtonImage('filemanager', component)\n ]);\n\n // Note: The function returned here must be synchronous and cannot use promises.\n // All promises must be resolved prior to returning the function.\n return (editor) => {\n registerImageCommand(editor, imageButtonText);\n registerEmbedCommand(editor, mediaButtonText);\n registerManagerCommand(editor, mediaManagerButtonText, mediaManagerButtonImage);\n };\n};\n"],"names":["isImage","node","nodeName","toLowerCase","isVideo","async","imageButtonText","mediaButtonText","mediaManagerButtonText","map","key","component","mediaManagerButtonImage","Promise","all","editor","handleImageAction","MediaImage","displayDialogue","ui","registry","addToggleButton","imageButtonName","icon","tooltip","onAction","onSetup","api","selection","selectorChangedWithUnbind","setActive","unbind","addMenuItem","t
ext","addContextToolbar","predicate","items","position","scope","addContextMenu","update","registerImageCommand","videoButtonText","handleEmbedAction","MediaEmbed","videoButtonName","registerEmbedCommand","handleMediaManager","MediaManager","addIcon","html","addButton","mediaManagerButtonName","registerManagerCommand"],"mappings":";;;;;;;kNAmCMA,QAAWC,MAAyC,QAAhCA,KAAKC,SAASC,cAClCC,QAAWH,MAAyC,UAAhCA,KAAKC,SAASC,eAA6D,UAAhCF,KAAKC,SAASC,gCA4G3DE,gBAEhBC,gBACAC,gBACAC,8BACM,mBAAW,CAAC,mBAAoB,mBAAoB,2BAA2BC,KAAKC,OAAUA,IAAAA,IAAKC,UAAAA,wBAGzGC,+BACMC,QAAQC,IAAI,EAClB,yBAAe,cAAeH,4BAK1BI,SAzHiB,EAACA,OAAQT,yBAE5BU,kBAAoB,KACH,IAAIC,eAAWF,QACvBG,mBAKfH,OAAOI,GAAGC,SAASC,gBAAgBC,wBAAiB,CAChDC,KATc,QAUdC,QAASlB,gBACTmB,SAAUT,kBACVU,QAASC,KACEZ,OAAOa,UAAUC,0BACpB,sEACAF,IAAIG,WACNC,SAIVhB,OAAOI,GAAGC,SAASY,YAAYV,wBAAiB,CAC5CC,KArBc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