jodit-pro
Version:
PRO Version of Jodit Editor
446 lines (419 loc) • 19.1 kB
JavaScript
/*!
* 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__) {
;
__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_define_property__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(82749);
/* harmony import */ var _swc_helpers_ts_decorate__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(31635);
/* harmony import */ var _config__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(83967);
/* harmony import */ var jodit_esm_core_constants__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(82758);
/* harmony import */ var jodit_esm_core_decorators__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(65478);
/* harmony import */ var jodit_esm_core_helpers__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(21537);
/* harmony import */ var jodit_esm_core_helpers_checker_is_boolean__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(87612);
/* harmony import */ var jodit_esm_core_helpers_html_htmlspecialchars__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(53326);
/* harmony import */ var jodit_esm_core_plugin__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(50911);
/* harmony import */ var jodit_esm_core_ui__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(67510);
/* harmony import */ var jodit_esm_modules__WEBPACK_IMPORTED_MODULE_10__ = __webpack_require__(41409);
/* harmony import */ var jodit_pro_jodit_pro__WEBPACK_IMPORTED_MODULE_11__ = __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/
*/
class pasteCode extends jodit_esm_core_plugin__WEBPACK_IMPORTED_MODULE_8__.Plugin {
className() {
return 'pasteCode';
}
/** @override */ afterInit(jodit) {
jodit.registerCommand('pasteCode', ()=>this.__openCodeEditDialog());
jodit.async.requestIdleCallback(()=>this.__initHighlightLibLoading());
}
__openCodeEditDialog(defLanguage, defValue, pre) {
const jodit = this.j;
const form = this.__createForm();
const { code, language } = (0,jodit_esm_core_helpers__WEBPACK_IMPORTED_MODULE_5__.refs)(form.container);
if (defLanguage) {
language.value = defLanguage;
}
if (defValue) {
code.value = defValue;
}
jodit.async.requestIdleCallback(()=>{
code.focus();
});
jodit.s.save();
const dialog = this.__createDialog(()=>{
if (form.validate()) {
jodit.s.restore();
const newPre = jodit.createInside.fromHTML(jodit.o.pasteCode.insertTemplate(jodit, language.value, code.value));
if (pre) {
jodit_esm_modules__WEBPACK_IMPORTED_MODULE_10__.Dom.replace(pre, newPre, jodit.createInside, false, true);
} else {
const current = jodit.s.current();
const block = jodit_esm_modules__WEBPACK_IMPORTED_MODULE_10__.Dom.up(current, jodit_esm_modules__WEBPACK_IMPORTED_MODULE_10__.Dom.isBlock, jodit.editor);
block && !jodit_esm_modules__WEBPACK_IMPORTED_MODULE_10__.Dom.isCell(block) ? jodit_esm_modules__WEBPACK_IMPORTED_MODULE_10__.Dom.after(block, newPre) : jodit.s.insertNode(newPre);
}
this.__imdOnChange();
return;
}
return false;
}, ()=>{
jodit.s.restore();
});
dialog.setContent(form.container).open(true);
}
/** @override */ beforeDestruct(jodit) {}
__createForm() {
const { jodit } = this;
return new jodit_esm_core_ui__WEBPACK_IMPORTED_MODULE_9__.UIForm(jodit, [
new jodit_esm_core_ui__WEBPACK_IMPORTED_MODULE_9__.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_9__.UITextArea(jodit, {
label: 'Code view',
resizable: false,
name: 'code',
required: true,
className: 'jodit-paste-code__textarea'
})
], {
className: 'jodit-paste-code'
});
}
__createDialog(onSave, onCancel) {
const dialog = new jodit_esm_modules__WEBPACK_IMPORTED_MODULE_10__.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_9__.Button)(dialog, '', 'Cancel', 'default').onAction(()=>{
dialog.close();
onCancel();
}),
(0,jodit_esm_core_ui__WEBPACK_IMPORTED_MODULE_9__.Button)(dialog, 'save', 'Save', 'primary').onAction(()=>{
dialog.close();
onSave();
})
]);
return dialog;
}
__onChange() {
this.__imdOnChange();
}
__imdOnChange() {
(0,jodit_esm_core_helpers__WEBPACK_IMPORTED_MODULE_5__.$$)('pre', this.j.editor).forEach((pre)=>{
if (!(0,jodit_esm_core_helpers__WEBPACK_IMPORTED_MODULE_5__.attr)(pre, 'contenteditable')) {
(0,jodit_esm_core_helpers__WEBPACK_IMPORTED_MODULE_5__.attr)(pre, 'contenteditable', false);
this.__highlightCode(pre).catch(()=>null);
}
});
}
async __highlightCode(pre) {
const language = this.__parseLanguage(pre);
const { highlight } = await this.__initHighlightLibLoading(language);
let container = pre;
if (pre.firstElementChild === pre.lastElementChild && jodit_esm_modules__WEBPACK_IMPORTED_MODULE_10__.Dom.isTag(pre.firstElementChild, 'code')) {
container = pre.firstElementChild;
}
container.innerHTML = highlight(container.innerText, language);
}
onPreEdit(e) {
const pre = jodit_esm_modules__WEBPACK_IMPORTED_MODULE_10__.Dom.isNode(e) && jodit_esm_modules__WEBPACK_IMPORTED_MODULE_10__.Dom.isTag(e, 'pre') ? e : jodit_esm_modules__WEBPACK_IMPORTED_MODULE_10__.Dom.closest(e.target, 'pre', this.j.editor);
if (pre) {
const language = this.__parseLanguage(pre);
this.__openCodeEditDialog(language, pre.innerText, pre);
}
}
__parseLanguage(pre) {
let language = null;
const getLang = (code)=>code.classList.forEach((className)=>{
if (/language-/.test(className)) {
const 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_10__.Dom.isTag(pre.firstElementChild, 'code')) {
getLang(pre.firstElementChild);
}
return this.jodit.o.pasteCode.canonicalLanguageCode(language || 'html');
}
onAfterGetValueFromEditor(data) {
const strip = (_, pre, _1, endPreStart, content, endPre)=>{
return `${pre.trim()}${endPreStart}${(0,jodit_esm_core_helpers_html_htmlspecialchars__WEBPACK_IMPORTED_MODULE_7__.htmlspecialchars)((0,jodit_esm_core_helpers__WEBPACK_IMPORTED_MODULE_5__.stripTags)(content, this.j.ed, new Set([
'br'
])))}${endPre}`;
};
data.value = data.value// pre + code
.replace(// @ts-ignore
/(<pre[^>]*)contenteditable\s*=\s*(['"]?)false\2([^>]*>\s*<code[^>]*>)(.*?)(<\/code>\s*<\/pre>)/gis, strip)// only pre
.replace(// @ts-ignore
/(<pre[^>]*)contenteditable\s*=\s*(['"]?)false\2([^>]*>)(.*?)(<\/pre>)/gis, strip);
}
constructor(...args){
super(...args), /** @override */ (0,_swc_helpers_define_property__WEBPACK_IMPORTED_MODULE_0__._)(this, "buttons", [
{
name: 'pasteCode',
group: 'clipboard'
}
]), (0,_swc_helpers_define_property__WEBPACK_IMPORTED_MODULE_0__._)(this, "__highlightLibJSIsLoaded", false), (0,_swc_helpers_define_property__WEBPACK_IMPORTED_MODULE_0__._)(this, "__loadLanguage", new Map()), (0,_swc_helpers_define_property__WEBPACK_IMPORTED_MODULE_0__._)(this, "__initHighlightLibLoading", async (language)=>{
const { globalHighlightLib, highlightLib: { css, js, langUrl, highlight, isLangLoaded, beforeLibLoad, afterLibLoad } } = this.j.o.pasteCode;
if (!this.__highlightLibJSIsLoaded && !globalHighlightLib) {
this.__highlightLibJSIsLoaded = Promise.resolve(beforeLibLoad?.()).then(()=>waitingPromise(this.async, Promise.allSettled([
(0,jodit_esm_core_helpers__WEBPACK_IMPORTED_MODULE_5__.loadNextStyle)(this.jodit, css).catch(()=>null),
(0,jodit_esm_core_helpers__WEBPACK_IMPORTED_MODULE_5__.loadNext)(this.jodit, js).catch(()=>null)
]))).then(()=>afterLibLoad?.());
}
if (!(0,jodit_esm_core_helpers_checker_is_boolean__WEBPACK_IMPORTED_MODULE_6__.isBoolean)(this.__highlightLibJSIsLoaded)) {
await this.__highlightLibJSIsLoaded;
}
if (language && !isLangLoaded(language) && !globalHighlightLib) {
if (!this.__loadLanguage.has(language)) {
if (!jodit_esm_core_constants__WEBPACK_IMPORTED_MODULE_3__.IS_PROD) {
// eslint-disable-next-line no-console
console.log('Load language', language, 'for paste-code');
}
this.__loadLanguage.set(language, waitingPromise(this.async, (0,jodit_esm_core_helpers__WEBPACK_IMPORTED_MODULE_5__.appendScriptAsync)(this.jodit, langUrl(language)).catch(()=>null)));
}
await this.__loadLanguage.get(language);
}
return {
highlight
};
});
}
}
/** @override */ (0,_swc_helpers_define_property__WEBPACK_IMPORTED_MODULE_0__._)(pasteCode, "requires", [
'license'
]);
(0,_swc_helpers_ts_decorate__WEBPACK_IMPORTED_MODULE_1__.__decorate)([
jodit_esm_core_decorators__WEBPACK_IMPORTED_MODULE_4__.autobind
], pasteCode.prototype, "__openCodeEditDialog", null);
(0,_swc_helpers_ts_decorate__WEBPACK_IMPORTED_MODULE_1__.__decorate)([
(0,jodit_esm_core_decorators__WEBPACK_IMPORTED_MODULE_4__.watch)([
'?:change',
'?:afterInit'
]),
(0,jodit_esm_core_decorators__WEBPACK_IMPORTED_MODULE_4__.debounce)()
], pasteCode.prototype, "__onChange", null);
(0,_swc_helpers_ts_decorate__WEBPACK_IMPORTED_MODULE_1__.__decorate)([
(0,jodit_esm_core_decorators__WEBPACK_IMPORTED_MODULE_4__.watch)([
'?:dblclick',
'?:editPreInPasteCode'
])
], pasteCode.prototype, "onPreEdit", null);
(0,_swc_helpers_ts_decorate__WEBPACK_IMPORTED_MODULE_1__.__decorate)([
(0,jodit_esm_core_decorators__WEBPACK_IMPORTED_MODULE_4__.watch)('?:afterGetValueFromEditor')
], pasteCode.prototype, "onAfterGetValueFromEditor", null);
pasteCode = (0,_swc_helpers_ts_decorate__WEBPACK_IMPORTED_MODULE_1__.__decorate)([
jodit_esm_core_decorators__WEBPACK_IMPORTED_MODULE_4__.component
], pasteCode);
function waitingPromise(async, promise) {
return async.promise((resolve, reject)=>{
promise.then(resolve).catch(reject);
}).catch(()=>null);
}
jodit_pro_jodit_pro__WEBPACK_IMPORTED_MODULE_11__.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__) {
;
/* 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 (lang) {
switch(lang){
case 'ts':
return 'typescript';
case 'js':
return 'javascript';
case 'markup':
return 'html';
}
return lang;
},
highlightLib: {
beforeLibLoad () {
// @ts-ignore
window.Prism = window.Prism || {};
// @ts-ignore
window.Prism.manual = true;
},
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 (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: (lang)=>`https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/components/prism-${lang}.min.js`,
css: [
'https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/themes/prism.min.css'
]
},
defaultLanguage: 'html',
insertTemplate: (jodit, language, value)=>`<pre class="language-${language}">${(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__;
/******/ }
]);
});