%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /home/vacivi36/ava/lib/editor/tiny/plugins/equation/amd/build/
Upload File :
Create Path :
Current File : /home/vacivi36/ava/lib/editor/tiny/plugins/equation/amd/build/ui.min.js.map

{"version":3,"file":"ui.min.js","sources":["../src/ui.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 Equation UI.\n *\n * @module      tiny_equation/ui\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 EquationModal from 'tiny_equation/modal';\nimport ModalFactory from 'core/modal_factory';\nimport ModalEvents from 'core/modal_events';\nimport {getLibraries, getTexDocsUrl} from 'tiny_equation/options';\nimport {notifyFilterContentUpdated} from 'core/event';\nimport * as TinyEquationRepository from 'tiny_equation/repository';\nimport {displayException} from 'core/notification';\nimport {debounce} from 'core/utils';\nimport Selectors from 'tiny_equation/selectors';\nimport {getSourceEquation, getCurrentEquationData, setEquation} from 'tiny_equation/equation';\n\nlet currentForm;\nlet lastCursorPos = 0;\n\n/**\n * Handle action\n * @param {TinyMCE} editor\n */\nexport const handleAction = (editor) => {\n    displayDialogue(editor);\n};\n\n/**\n * Display the equation editor\n * @param {TinyMCE} editor\n * @returns {Promise<void>}\n */\nconst displayDialogue = async(editor) => {\n    let data = {};\n    const currentEquationData = getCurrentEquationData(editor);\n    if (currentEquationData) {\n        Object.assign(data, currentEquationData);\n    }\n    const modalPromises = await ModalFactory.create({\n        type: EquationModal.TYPE,\n        templateContext: getTemplateContext(editor, data),\n        large: true,\n    });\n\n    modalPromises.show();\n    const $root = await modalPromises.getRoot();\n    const root = $root[0];\n    currentForm = root.querySelector(Selectors.elements.form);\n\n    $root.on(ModalEvents.hidden, () => {\n        modalPromises.destroy();\n    });\n\n    $root.on(ModalEvents.shown, () => {\n        const library = root.querySelector(Selectors.elements.library);\n        TinyEquationRepository.filterEquation(1, library.innerHTML).then(async data => {\n            library.innerHTML = data.content;\n            updatePreview();\n            notifyFilter(library);\n            return data;\n        }).catch(displayException);\n    });\n\n    root.addEventListener('click', (e) => {\n        const libraryItem = e.target.closest(Selectors.elements.libraryItem);\n        const submitAction = e.target.closest(Selectors.actions.submit);\n        const textArea = e.target.closest('.tiny_equation_equation');\n        if (libraryItem) {\n            e.preventDefault();\n            selectLibraryItem(libraryItem);\n        }\n        if (submitAction) {\n            e.preventDefault();\n            setEquation(currentForm, editor);\n            modalPromises.destroy();\n        }\n        if (textArea) {\n            debounce(updatePreview(), 500);\n        }\n    });\n\n    root.addEventListener('keyup', (e) => {\n        const textArea = e.target.closest(Selectors.elements.equationTextArea);\n        if (textArea) {\n            debounce(updatePreview(), 500);\n        }\n    });\n\n    root.addEventListener('keydown', (e) => {\n        const libraryItem = e.target.closest(Selectors.elements.libraryItem);\n        if (libraryItem) {\n            if (e.keyCode == 37 || e.keyCode == 39) {\n                groupNavigation(e);\n            }\n        }\n    });\n};\n\n/**\n * Get template context.\n * @param {TinyMCE} editor\n * @param {Object} data\n * @returns {Object}\n */\nconst getTemplateContext = (editor, data) => {\n    const libraries = getLibraries(editor);\n    const texDocsUrl = getTexDocsUrl(editor);\n\n    return Object.assign({}, {\n        elementid: editor.id,\n        libraries: libraries,\n        texdocsurl: texDocsUrl,\n        delimiters: Selectors.delimiters,\n    }, data);\n};\n\n/**\n * Handle select library item.\n * @param {Object} libraryItem\n */\nconst selectLibraryItem = (libraryItem) => {\n    const tex = libraryItem.getAttribute('data-tex');\n    const input = currentForm.querySelector(Selectors.elements.equationTextArea);\n    let oldValue;\n    let newValue;\n    let focusPoint = 0;\n\n    oldValue = input.value;\n\n    newValue = oldValue.substring(0, lastCursorPos);\n    if (newValue.charAt(newValue.length - 1) !== ' ') {\n        newValue += ' ';\n    }\n    newValue += tex;\n    focusPoint = newValue.length;\n\n    if (oldValue.charAt(lastCursorPos) !== ' ') {\n        newValue += ' ';\n    }\n    newValue += oldValue.substring(lastCursorPos, oldValue.length);\n\n    input.value = newValue;\n    input.focus();\n\n    input.selectionStart = input.selectionEnd = focusPoint;\n\n    updatePreview();\n};\n\n/**\n * Update the preview section.\n */\nconst updatePreview = () => {\n    const textarea = currentForm.querySelector(Selectors.elements.equationTextArea);\n    const preview = currentForm.querySelector(Selectors.elements.preview);\n    const prefix = '';\n    const cursorLatex = Selectors.cursorLatex;\n    const isChar = /[a-zA-Z{]/;\n    let currentPos = textarea.selectionStart;\n    let equation = textarea.value;\n\n    // Move the cursor so it does not break expressions.\n    // Start at the very beginning.\n    if (!currentPos) {\n        currentPos = 0;\n    }\n\n    if (getSourceEquation()) {\n        currentPos = equation.length;\n    }\n\n    // First move back to the beginning of the line.\n    while (equation.charAt(currentPos) === '\\\\' && currentPos >= 0) {\n        currentPos -= 1;\n    }\n    if (currentPos !== 0) {\n        if (equation.charAt(currentPos - 1) != '{') {\n            // Now match to the end of the line.\n            while (isChar.test(equation.charAt(currentPos)) &&\n                    currentPos < equation.length &&\n                    isChar.test(equation.charAt(currentPos - 1))) {\n                currentPos += 1;\n            }\n        }\n    }\n    // Save the cursor position - for insertion from the library.\n    lastCursorPos = currentPos;\n    equation = prefix + equation.substring(0, currentPos) + cursorLatex + equation.substring(currentPos);\n\n    equation = Selectors.delimiters.start + ' ' + equation + ' ' + Selectors.delimiters.end;\n    TinyEquationRepository.filterEquation(1, equation).then((data) => {\n        preview.innerHTML = data.content;\n        notifyFilter(preview);\n\n        return data;\n    }).catch(displayException);\n};\n\n/**\n * Notify the filters about the modified nodes\n * @param {Element} element\n */\nconst notifyFilter = (element) => {\n    notifyFilterContentUpdated(element);\n};\n\n/**\n * Callback handling the keyboard navigation in the groups of the library.\n * @param {Event} e\n */\nconst groupNavigation = (e) => {\n    e.preventDefault();\n\n    const current = e.target.closest(Selectors.elements.libraryItem);\n    const parent = current.parentNode; // This must be the <div> containing all the buttons of the group.\n    const buttons = Array.prototype.slice.call(parent.querySelectorAll(Selectors.elements.libraryItem));\n    const direction = e.keyCode !== 37 ? 1 : -1;\n    let index = buttons.indexOf(current);\n    let nextButton;\n\n    if (index < 0) {\n        index = 0;\n    }\n\n    index += direction;\n    if (index < 0) {\n        index = buttons.length - 1;\n    } else if (index >= buttons.length) {\n        index = 0;\n    }\n    nextButton = buttons[index];\n    nextButton.focus();\n};\n"],"names":["currentForm","lastCursorPos","editor","displayDialogue","async","data","currentEquationData","Object","assign","modalPromises","ModalFactory","create","type","EquationModal","TYPE","templateContext","getTemplateContext","large","show","$root","getRoot","root","querySelector","Selectors","elements","form","on","ModalEvents","hidden","destroy","shown","library","TinyEquationRepository","filterEquation","innerHTML","then","content","updatePreview","notifyFilter","catch","displayException","addEventListener","e","libraryItem","target","closest","submitAction","actions","submit","textArea","preventDefault","selectLibraryItem","equationTextArea","keyCode","groupNavigation","libraries","texDocsUrl","elementid","id","texdocsurl","delimiters","tex","getAttribute","input","oldValue","newValue","focusPoint","value","substring","charAt","length","focus","selectionStart","selectionEnd","textarea","preview","cursorLatex","isChar","currentPos","equation","test","start","end","element","current","parent","parentNode","buttons","Array","prototype","slice","call","querySelectorAll","direction","nextButton","index","indexOf"],"mappings":";;;;;;;SAkCIA,+9BACAC,cAAgB,wBAMSC,SACzBC,gBAAgBD,eAQdC,gBAAkBC,MAAAA,aAChBC,KAAO,SACLC,qBAAsB,oCAAuBJ,QAC/CI,qBACAC,OAAOC,OAAOH,KAAMC,2BAElBG,oBAAsBC,uBAAaC,OAAO,CAC5CC,KAAMC,eAAcC,KACpBC,gBAAiBC,mBAAmBd,OAAQG,M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