UNPKG

jodit-pro

Version:

PRO Version of Jodit Editor

578 lines (544 loc) 26.6 kB
/*! * jodit-pro - PRO Version of Jodit Editor * Author: Chupurnov Valerii <chupurnov@gmail.com> * Version: v4.9.27 * Url: https://xdsoft.net/jodit/pro/ * License(s): SEE LICENSE IN LICENSE.md */ (function webpackUniversalModuleDefinition(root, factory) { if(typeof exports === 'object' && typeof module === 'object') module.exports = factory(); else if(typeof define === 'function' && define.amd) define([], factory); else { var a = factory(); for(var i in a) (typeof exports === 'object' ? exports : root)[i] = a[i]; } })(self, function() { return (self["webpackChunkjodit_pro"] = self["webpackChunkjodit_pro"] || []).push([[150],{ /***/ 41406: /***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) { "use strict"; __webpack_require__.r(__webpack_exports__); /* harmony export */ __webpack_require__.d(__webpack_exports__, { /* harmony export */ pasteCode: function() { return /* binding */ pasteCode; } /* harmony export */ }); /* harmony import */ var _swc_helpers_async_to_generator__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(77688); /* harmony import */ var _swc_helpers_call_super__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(80294); /* harmony import */ var _swc_helpers_class_call_check__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(20616); /* harmony import */ var _swc_helpers_create_class__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(67709); /* harmony import */ var _swc_helpers_define_property__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(82749); /* harmony import */ var _swc_helpers_inherits__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(18766); /* harmony import */ var _swc_helpers_wrap_native_super__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(23078); /* harmony import */ var _swc_helpers_ts_decorate__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(31635); /* harmony import */ var _swc_helpers_ts_generator__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(62361); /* harmony import */ var _config__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(83967); /* harmony import */ var jodit_esm_core_constants__WEBPACK_IMPORTED_MODULE_10__ = __webpack_require__(82758); /* harmony import */ var jodit_esm_core_decorators__WEBPACK_IMPORTED_MODULE_11__ = __webpack_require__(65478); /* harmony import */ var jodit_esm_core_helpers__WEBPACK_IMPORTED_MODULE_12__ = __webpack_require__(21537); /* harmony import */ var jodit_esm_core_helpers_checker_is_boolean__WEBPACK_IMPORTED_MODULE_13__ = __webpack_require__(87612); /* harmony import */ var jodit_esm_core_helpers_html_htmlspecialchars__WEBPACK_IMPORTED_MODULE_14__ = __webpack_require__(53326); /* harmony import */ var jodit_esm_core_plugin__WEBPACK_IMPORTED_MODULE_15__ = __webpack_require__(50911); /* harmony import */ var jodit_esm_core_ui__WEBPACK_IMPORTED_MODULE_16__ = __webpack_require__(67510); /* harmony import */ var jodit_esm_modules__WEBPACK_IMPORTED_MODULE_17__ = __webpack_require__(41409); /* harmony import */ var jodit_pro_jodit_pro__WEBPACK_IMPORTED_MODULE_18__ = __webpack_require__(2692); /*! * Jodit Editor PRO (https://xdsoft.net/jodit/) * See LICENSE.md in the project root for license information. * Copyright (c) 2013-2026 Valerii Chupurnov. All rights reserved. https://xdsoft.net/jodit/pro/ */ var pasteCode = /*#__PURE__*/ function(Plugin) { "use strict"; (0,_swc_helpers_inherits__WEBPACK_IMPORTED_MODULE_5__._)(pasteCode, Plugin); function pasteCode() { (0,_swc_helpers_class_call_check__WEBPACK_IMPORTED_MODULE_2__._)(this, pasteCode); var _this; var _this1; _this = (0,_swc_helpers_call_super__WEBPACK_IMPORTED_MODULE_1__._)(this, pasteCode, arguments), _this1 = _this, /** @override */ (0,_swc_helpers_define_property__WEBPACK_IMPORTED_MODULE_4__._)(_this, "buttons", [ { name: 'pasteCode', group: 'clipboard' } ]), (0,_swc_helpers_define_property__WEBPACK_IMPORTED_MODULE_4__._)(_this, "__highlightLibJSIsLoaded", false), (0,_swc_helpers_define_property__WEBPACK_IMPORTED_MODULE_4__._)(_this, "__loadLanguage", new Map()), (0,_swc_helpers_define_property__WEBPACK_IMPORTED_MODULE_4__._)(_this, "__initHighlightLibLoading", function(language) { return (0,_swc_helpers_async_to_generator__WEBPACK_IMPORTED_MODULE_0__._)(function() { var _this_j_o_pasteCode, globalHighlightLib, _this_j_o_pasteCode_highlightLib, css, js, langUrl, highlight, isLangLoaded, beforeLibLoad, afterLibLoad; return (0,_swc_helpers_ts_generator__WEBPACK_IMPORTED_MODULE_8__._)(this, function(_state) { switch(_state.label){ case 0: _this_j_o_pasteCode = _this1.j.o.pasteCode, globalHighlightLib = _this_j_o_pasteCode.globalHighlightLib, _this_j_o_pasteCode_highlightLib = _this_j_o_pasteCode.highlightLib, css = _this_j_o_pasteCode_highlightLib.css, js = _this_j_o_pasteCode_highlightLib.js, langUrl = _this_j_o_pasteCode_highlightLib.langUrl, highlight = _this_j_o_pasteCode_highlightLib.highlight, isLangLoaded = _this_j_o_pasteCode_highlightLib.isLangLoaded, beforeLibLoad = _this_j_o_pasteCode_highlightLib.beforeLibLoad, afterLibLoad = _this_j_o_pasteCode_highlightLib.afterLibLoad; if (!_this1.__highlightLibJSIsLoaded && !globalHighlightLib) { _this1.__highlightLibJSIsLoaded = Promise.resolve(beforeLibLoad === null || beforeLibLoad === void 0 ? void 0 : beforeLibLoad()).then(function() { return waitingPromise(_this1.async, Promise.allSettled([ (0,jodit_esm_core_helpers__WEBPACK_IMPORTED_MODULE_12__.loadNextStyle)(_this1.jodit, css).catch(function() { return null; }), (0,jodit_esm_core_helpers__WEBPACK_IMPORTED_MODULE_12__.loadNext)(_this1.jodit, js).catch(function() { return null; }) ])); }).then(function() { return afterLibLoad === null || afterLibLoad === void 0 ? void 0 : afterLibLoad(); }); } if (!!(0,jodit_esm_core_helpers_checker_is_boolean__WEBPACK_IMPORTED_MODULE_13__.isBoolean)(_this1.__highlightLibJSIsLoaded)) return [ 3, 2 ]; return [ 4, _this1.__highlightLibJSIsLoaded ]; case 1: _state.sent(); _state.label = 2; case 2: if (!(language && !isLangLoaded(language) && !globalHighlightLib)) return [ 3, 4 ]; if (!_this1.__loadLanguage.has(language)) { if (!jodit_esm_core_constants__WEBPACK_IMPORTED_MODULE_10__.IS_PROD) { // eslint-disable-next-line no-console console.log('Load language', language, 'for paste-code'); } _this1.__loadLanguage.set(language, waitingPromise(_this1.async, (0,jodit_esm_core_helpers__WEBPACK_IMPORTED_MODULE_12__.appendScriptAsync)(_this1.jodit, langUrl(language)).catch(function() { return null; }))); } return [ 4, _this1.__loadLanguage.get(language) ]; case 3: _state.sent(); _state.label = 4; case 4: return [ 2, { highlight: highlight } ]; } }); })(); }); return _this; } (0,_swc_helpers_create_class__WEBPACK_IMPORTED_MODULE_3__._)(pasteCode, [ { key: "className", value: function className() { return 'pasteCode'; } }, { key: "afterInit", value: /** @override */ function afterInit(jodit) { var _this = this; jodit.registerCommand('pasteCode', function() { return _this.__openCodeEditDialog(); }); jodit.async.requestIdleCallback(function() { return _this.__initHighlightLibLoading(); }); } }, { key: "__openCodeEditDialog", value: function __openCodeEditDialog(defLanguage, defValue, pre) { var _this = this; var jodit = this.j; var form = this.__createForm(); var _refs = (0,jodit_esm_core_helpers__WEBPACK_IMPORTED_MODULE_12__.refs)(form.container), code = _refs.code, language = _refs.language; if (defLanguage) { language.value = defLanguage; } if (defValue) { code.value = defValue; } jodit.async.requestIdleCallback(function() { code.focus(); }); jodit.s.save(); var dialog = this.__createDialog(function() { if (form.validate()) { jodit.s.restore(); var newPre = jodit.createInside.fromHTML(jodit.o.pasteCode.insertTemplate(jodit, language.value, code.value)); if (pre) { jodit_esm_modules__WEBPACK_IMPORTED_MODULE_17__.Dom.replace(pre, newPre, jodit.createInside, false, true); } else { var current = jodit.s.current(); var block = jodit_esm_modules__WEBPACK_IMPORTED_MODULE_17__.Dom.up(current, jodit_esm_modules__WEBPACK_IMPORTED_MODULE_17__.Dom.isBlock, jodit.editor); block && !jodit_esm_modules__WEBPACK_IMPORTED_MODULE_17__.Dom.isCell(block) ? jodit_esm_modules__WEBPACK_IMPORTED_MODULE_17__.Dom.after(block, newPre) : jodit.s.insertNode(newPre); } _this.__imdOnChange(); return; } return false; }, function() { jodit.s.restore(); }); dialog.setContent(form.container).open(true); } }, { key: "beforeDestruct", value: /** @override */ function beforeDestruct(jodit) {} }, { key: "__createForm", value: function __createForm() { var jodit = this.jodit; return new jodit_esm_core_ui__WEBPACK_IMPORTED_MODULE_16__.UIForm(jodit, [ new jodit_esm_core_ui__WEBPACK_IMPORTED_MODULE_16__.UISelect(jodit, { name: 'language', label: 'Language', value: jodit.o.pasteCode.defaultLanguage, options: jodit.o.pasteCode.languages, required: true }), new jodit_esm_core_ui__WEBPACK_IMPORTED_MODULE_16__.UITextArea(jodit, { label: 'Code view', resizable: false, name: 'code', required: true, className: 'jodit-paste-code__textarea' }) ], { className: 'jodit-paste-code' }); } }, { key: "__createDialog", value: function __createDialog(onSave, onCancel) { var dialog = new jodit_esm_modules__WEBPACK_IMPORTED_MODULE_17__.Dialog({ language: this.j.o.language }); dialog.setHeader('Insert/Edit Code Sample').setSize(this.j.o.pasteCode.dialog.width, this.j.o.pasteCode.dialog.height).setFooter([ (0,jodit_esm_core_ui__WEBPACK_IMPORTED_MODULE_16__.Button)(dialog, '', 'Cancel', 'default').onAction(function() { dialog.close(); onCancel(); }), (0,jodit_esm_core_ui__WEBPACK_IMPORTED_MODULE_16__.Button)(dialog, 'save', 'Save', 'primary').onAction(function() { dialog.close(); onSave(); }) ]); return dialog; } }, { key: "__onChange", value: function __onChange() { this.__imdOnChange(); } }, { key: "__imdOnChange", value: function __imdOnChange() { var _this = this; (0,jodit_esm_core_helpers__WEBPACK_IMPORTED_MODULE_12__.$$)('pre', this.j.editor).forEach(function(pre) { if (!(0,jodit_esm_core_helpers__WEBPACK_IMPORTED_MODULE_12__.attr)(pre, 'contenteditable')) { (0,jodit_esm_core_helpers__WEBPACK_IMPORTED_MODULE_12__.attr)(pre, 'contenteditable', false); _this.__highlightCode(pre).catch(function() { return null; }); } }); } }, { key: "__highlightCode", value: function __highlightCode(pre) { return (0,_swc_helpers_async_to_generator__WEBPACK_IMPORTED_MODULE_0__._)(function() { var language, highlight, container; return (0,_swc_helpers_ts_generator__WEBPACK_IMPORTED_MODULE_8__._)(this, function(_state) { switch(_state.label){ case 0: language = this.__parseLanguage(pre); return [ 4, this.__initHighlightLibLoading(language) ]; case 1: highlight = _state.sent().highlight; container = pre; if (pre.firstElementChild === pre.lastElementChild && jodit_esm_modules__WEBPACK_IMPORTED_MODULE_17__.Dom.isTag(pre.firstElementChild, 'code')) { container = pre.firstElementChild; } container.innerHTML = highlight(container.innerText, language); return [ 2 ]; } }); }).call(this); } }, { key: "onPreEdit", value: function onPreEdit(e) { var pre = jodit_esm_modules__WEBPACK_IMPORTED_MODULE_17__.Dom.isNode(e) && jodit_esm_modules__WEBPACK_IMPORTED_MODULE_17__.Dom.isTag(e, 'pre') ? e : jodit_esm_modules__WEBPACK_IMPORTED_MODULE_17__.Dom.closest(e.target, 'pre', this.j.editor); if (pre) { var language = this.__parseLanguage(pre); this.__openCodeEditDialog(language, pre.innerText, pre); } } }, { key: "__parseLanguage", value: function __parseLanguage(pre) { var language = null; var getLang = function getLang(code) { return code.classList.forEach(function(className) { if (/language-/.test(className)) { var lng = /language-(.*)/.exec(className); if (lng && lng[1]) { language = lng[1]; } } }); }; getLang(pre); if (language == null && pre.firstElementChild === pre.lastElementChild && jodit_esm_modules__WEBPACK_IMPORTED_MODULE_17__.Dom.isTag(pre.firstElementChild, 'code')) { getLang(pre.firstElementChild); } return this.jodit.o.pasteCode.canonicalLanguageCode(language || 'html'); } }, { key: "onAfterGetValueFromEditor", value: function onAfterGetValueFromEditor(data) { var _this = this; var strip = function strip(_, pre, _1, endPreStart, content, endPre) { return "".concat(pre.trim()).concat(endPreStart).concat((0,jodit_esm_core_helpers_html_htmlspecialchars__WEBPACK_IMPORTED_MODULE_14__.htmlspecialchars)((0,jodit_esm_core_helpers__WEBPACK_IMPORTED_MODULE_12__.stripTags)(content, _this.j.ed, new Set([ 'br' ])))).concat(endPre); }; data.value = data.value// pre + code .replace(// @ts-ignore RegExp("(<pre[^>]*)contenteditable\\s*=\\s*(['\"]?)false\\2([^>]*>\\s*<code[^>]*>)(.*?)(<\\/code>\\s*<\\/pre>)", "gis"), strip)// only pre .replace(// @ts-ignore RegExp("(<pre[^>]*)contenteditable\\s*=\\s*(['\"]?)false\\2([^>]*>)(.*?)(<\\/pre>)", "gis"), strip); } } ]); return pasteCode; }((0,_swc_helpers_wrap_native_super__WEBPACK_IMPORTED_MODULE_6__._)(jodit_esm_core_plugin__WEBPACK_IMPORTED_MODULE_15__.Plugin)); /** @override */ (0,_swc_helpers_define_property__WEBPACK_IMPORTED_MODULE_4__._)(pasteCode, "requires", [ 'license' ]); (0,_swc_helpers_ts_decorate__WEBPACK_IMPORTED_MODULE_7__.__decorate)([ jodit_esm_core_decorators__WEBPACK_IMPORTED_MODULE_11__.autobind ], pasteCode.prototype, "__openCodeEditDialog", null); (0,_swc_helpers_ts_decorate__WEBPACK_IMPORTED_MODULE_7__.__decorate)([ (0,jodit_esm_core_decorators__WEBPACK_IMPORTED_MODULE_11__.watch)([ '?:change', '?:afterInit' ]), (0,jodit_esm_core_decorators__WEBPACK_IMPORTED_MODULE_11__.debounce)() ], pasteCode.prototype, "__onChange", null); (0,_swc_helpers_ts_decorate__WEBPACK_IMPORTED_MODULE_7__.__decorate)([ (0,jodit_esm_core_decorators__WEBPACK_IMPORTED_MODULE_11__.watch)([ '?:dblclick', '?:editPreInPasteCode' ]) ], pasteCode.prototype, "onPreEdit", null); (0,_swc_helpers_ts_decorate__WEBPACK_IMPORTED_MODULE_7__.__decorate)([ (0,jodit_esm_core_decorators__WEBPACK_IMPORTED_MODULE_11__.watch)('?:afterGetValueFromEditor') ], pasteCode.prototype, "onAfterGetValueFromEditor", null); pasteCode = (0,_swc_helpers_ts_decorate__WEBPACK_IMPORTED_MODULE_7__.__decorate)([ jodit_esm_core_decorators__WEBPACK_IMPORTED_MODULE_11__.component ], pasteCode); function waitingPromise(async, promise) { return async.promise(function(resolve, reject) { promise.then(resolve).catch(reject); }).catch(function() { return null; }); } jodit_pro_jodit_pro__WEBPACK_IMPORTED_MODULE_18__.JoditPro.plugins.add('paste-code', pasteCode); /***/ }), /***/ 75689: /***/ (function(module) { module.exports = "<svg viewBox=\"0 0 24 24\" xml:space=\"preserve\" xmlns=\"http://www.w3.org/2000/svg\"> <path d=\"M2.5244141,23.5h18.9511719c0.4140625,0,0.75-0.3359375,0.75-0.75V4.9208984 c0-0.1992188-0.0795898-0.390625-0.2207031-0.53125L18.3198242,0.71875C18.1791992,0.5786133,17.9887695,0.5,17.7905273,0.5 H2.5244141c-0.4140625,0-0.75,0.3359375-0.75,0.75v21.5C1.7744141,23.1640625,2.1103516,23.5,2.5244141,23.5z M20.7128296,5.2197266 h-2.6986694V2.531189L20.7128296,5.2197266z M3.2744141,2h13.2397461v3.9697266c0,0.4140625,0.3359375,0.75,0.75,0.75h3.4614258V22 H3.2744141V2z\" fill=\"#1D1D1D\"/> <path d=\"M8.75,10.25h1.75c0.4140625,0,0.75-0.3359375,0.75-0.75s-0.3359375-0.75-0.75-0.75H8 c-0.4140625,0-0.75,0.3359375-0.75,0.75v2.75H6c-0.4140625,0-0.75,0.3359375-0.75,0.75S5.5859375,13.75,6,13.75h1.25v2.75 c0,0.4140625,0.3359375,0.75,0.75,0.75h2.5c0.4140625,0,0.75-0.3359375,0.75-0.75s-0.3359375-0.75-0.75-0.75H8.75V10.25z\" fill=\"#1D1D1D\"/> <path d=\"M18.5,12.25h-1.25V9.5c0-0.4140625-0.3359375-0.75-0.75-0.75H14c-0.4140625,0-0.75,0.3359375-0.75,0.75 s0.3359375,0.75,0.75,0.75h1.75v5.5H14c-0.4140625,0-0.75,0.3359375-0.75,0.75s0.3359375,0.75,0.75,0.75h2.5 c0.4140625,0,0.75-0.3359375,0.75-0.75v-2.75h1.25c0.4140625,0,0.75-0.3359375,0.75-0.75S18.9140625,12.25,18.5,12.25z\" fill=\"#1D1D1D\"/></svg>" /***/ }), /***/ 83967: /***/ (function(__unused_webpack_module, __unused_webpack___webpack_exports__, __webpack_require__) { "use strict"; /* harmony import */ var _icon_svg__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(75689); /* harmony import */ var _icon_svg__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_icon_svg__WEBPACK_IMPORTED_MODULE_0__); /* harmony import */ var jodit_esm_config__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(6441); /* harmony import */ var jodit_esm_core_helpers_html_htmlspecialchars__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(53326); /*! * Jodit Editor PRO (https://xdsoft.net/jodit/) * See LICENSE.md in the project root for license information. * Copyright (c) 2013-2026 Valerii Chupurnov. All rights reserved. https://xdsoft.net/jodit/pro/ */ jodit_esm_config__WEBPACK_IMPORTED_MODULE_1__.Config.prototype.controls.pasteCode = { icon: (_icon_svg__WEBPACK_IMPORTED_MODULE_0___default()), tooltip: 'Paste code', command: 'pasteCode' }; jodit_esm_config__WEBPACK_IMPORTED_MODULE_1__.Config.prototype.pasteCode = { globalHighlightLib: false, canonicalLanguageCode: function canonicalLanguageCode(lang) { switch(lang){ case 'ts': return 'typescript'; case 'js': return 'javascript'; case 'markup': return 'html'; } return lang; }, highlightLib: { beforeLibLoad: function beforeLibLoad() { // @ts-ignore window.Prism = window.Prism || {}; // @ts-ignore window.Prism.manual = true; }, highlight: function highlight(code, language) { return typeof Prism !== 'undefined' ? Prism.highlight(code, Prism.languages[language] || Prism.languages.plain, language) : (0,jodit_esm_core_helpers_html_htmlspecialchars__WEBPACK_IMPORTED_MODULE_2__.htmlspecialchars)(code); }, isLangLoaded: function isLangLoaded(lang) { if (lang === 'html') { return true; } return typeof Prism !== 'undefined' ? Boolean(Prism.languages[lang]) : false; }, js: [ 'https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/prism.min.js', 'https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/plugins/autoloader/prism-autoloader.min.js' ], langUrl: function langUrl(lang) { return "https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/components/prism-".concat(lang, ".min.js"); }, css: [ 'https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/themes/prism.min.css' ] }, defaultLanguage: 'html', insertTemplate: function insertTemplate(jodit, language, value) { return '<pre class="language-'.concat(language, '">').concat((0,jodit_esm_core_helpers_html_htmlspecialchars__WEBPACK_IMPORTED_MODULE_2__.htmlspecialchars)(value), "</pre>"); }, languages: [ { value: 'plaintext', text: 'Plain' }, { value: 'html', text: 'HTML/XML' }, { value: 'bash', text: 'Bash' }, { value: 'php', text: 'PHP' }, { value: 'javascript', text: 'JavaScript' }, { value: 'typescript', text: 'TypeScript' }, { value: 'jsx', text: 'JSX' }, { value: 'java', text: 'Java' }, { value: 'css', text: 'CSS' }, { value: 'php', text: 'PHP' }, { value: 'ruby', text: 'Ruby' }, { value: 'python', text: 'Python' }, { value: 'java', text: 'Java' }, { value: 'c', text: 'C' }, { value: 'csharp', text: 'C#' }, { value: 'cpp', text: 'C++' }, { value: 'sql', text: 'SQL' }, { value: 'docker', text: 'Docker' }, { value: 'http', text: 'HTTP' }, { value: 'ini', text: 'INI' }, { value: 'yaml', text: 'YAML' }, { value: 'json', text: 'JSON' }, { value: 'json5', text: 'JSON5' }, { value: 'makefile', text: 'Makefile' }, { value: 'swift', text: 'Swift' } ], dialog: { width: 700, height: 600 } }; /***/ }) }, /******/ function(__webpack_require__) { // webpackRuntimeModules /******/ var __webpack_exec__ = function(moduleId) { return __webpack_require__(__webpack_require__.s = moduleId); } /******/ var __webpack_exports__ = (__webpack_exec__(41406)); /******/ return __webpack_exports__; /******/ } ]); });