UNPKG

jodit-pro

Version:

PRO Version of Jodit Editor

402 lines (361 loc) 15.4 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([[850],{ /***/ 5440: /***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) { "use strict"; /* harmony export */ __webpack_require__.d(__webpack_exports__, { /* harmony export */ buildStylePopup: function() { return /* binding */ buildStylePopup; } /* harmony export */ }); /* harmony import */ var _helpers_apply_style__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(31105); /* harmony import */ var _helpers_classify_definitions__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(8060); /* harmony import */ var _helpers_detect_active_style__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(69341); /*! * 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/ */ const CLASS_NAME = 'jodit-style-popup'; function buildStylePopup(editor, definitions, close) { const groups = (0,_helpers_classify_definitions__WEBPACK_IMPORTED_MODULE_1__.classifyDefinitions)(definitions); const active = (0,_helpers_detect_active_style__WEBPACK_IMPORTED_MODULE_2__.detectActiveStyle)(editor, definitions); const container = editor.c.div(CLASS_NAME); for (const group of groups){ const title = editor.c.div(`${CLASS_NAME}__group-title`); title.textContent = editor.i18n(group.title); container.appendChild(title); const grid = editor.c.div(`${CLASS_NAME}__grid`); for (const def of group.definitions){ const card = editor.c.element('button'); card.type = 'button'; const isActive = active === def; card.className = `${CLASS_NAME}__card` + (isActive ? ` ${CLASS_NAME}__card_active_true` : ''); const preview = editor.c.div(`${CLASS_NAME}__card-preview`); const previewEl = editor.c.element(def.element); for (const cls of def.classes){ previewEl.classList.add(cls); } previewEl.textContent = def.name; preview.appendChild(previewEl); card.appendChild(preview); const label = editor.c.div(`${CLASS_NAME}__card-label`); label.textContent = def.name; card.appendChild(label); editor.e.on(card, 'click', ()=>{ editor.s.focus(); (0,_helpers_apply_style__WEBPACK_IMPORTED_MODULE_0__.applyStyle)(editor, def, definitions); editor.synchronizeValues(); close(); }); grid.appendChild(card); } container.appendChild(grid); } return container; } /***/ }), /***/ 8060: /***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) { "use strict"; /* harmony export */ __webpack_require__.d(__webpack_exports__, { /* harmony export */ classifyDefinitions: function() { return /* binding */ classifyDefinitions; } /* harmony export */ }); /* harmony import */ var jodit_esm_core_constants__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(82758); /*! * 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/ */ function classifyDefinitions(definitions) { const block = []; const inline = []; for (const def of definitions){ if (jodit_esm_core_constants__WEBPACK_IMPORTED_MODULE_0__.IS_BLOCK.test(def.element)) { block.push(def); } else { inline.push(def); } } const groups = []; if (block.length) { groups.push({ title: 'Block styles', definitions: block }); } if (inline.length) { groups.push({ title: 'Text styles', definitions: inline }); } return groups; } /***/ }), /***/ 28609: /***/ (function(__unused_webpack_module, __unused_webpack___webpack_exports__, __webpack_require__) { "use strict"; /* harmony import */ var _helpers_detect_active_style__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(69341); /* harmony import */ var _ui_style_popup__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(5440); /* harmony import */ var _icon_svg__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(78955); /* harmony import */ var _icon_svg__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_icon_svg__WEBPACK_IMPORTED_MODULE_2__); /* harmony import */ var jodit_esm_config__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(6441); /*! * 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_3__.Config.prototype.customStyles = { definitions: [] }; jodit_esm_config__WEBPACK_IMPORTED_MODULE_3__.Config.prototype.controls.style = { tooltip: 'Styles', icon: (_icon_svg__WEBPACK_IMPORTED_MODULE_2___default()), isDisabled (editor) { return !editor.o.customStyles.definitions.length; }, isActive (editor) { const definitions = editor.o.customStyles.definitions; if (!definitions.length) { return false; } return (0,_helpers_detect_active_style__WEBPACK_IMPORTED_MODULE_0__.detectActiveStyle)(editor, definitions) != null; }, update (editor, button) { const definitions = editor.o.customStyles.definitions; if (!definitions.length) { return; } const active = (0,_helpers_detect_active_style__WEBPACK_IMPORTED_MODULE_0__.detectActiveStyle)(editor, definitions); const isSelect = button.control?.component === 'select'; if (editor.o.textIcons || isSelect) { if (active) { button.state.text = active.name; } else { button.state.text = isSelect ? editor.i18n('Styles') : ''; } } }, exec () { return false; }, popup (editor, _current, close) { const definitions = editor.o.customStyles.definitions; if (!definitions.length) { return false; } if (!editor.s.current()) { editor.s.focus(); } editor.s.save(); const popup = (0,_ui_style_popup__WEBPACK_IMPORTED_MODULE_1__.buildStylePopup)(editor, definitions, ()=>{ editor.s.restore(); close(); }); editor.e.one('beforePopupClose', ()=>{ editor.s.restore(); }); return popup; } }; /***/ }), /***/ 31105: /***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) { "use strict"; /* harmony export */ __webpack_require__.d(__webpack_exports__, { /* harmony export */ applyStyle: function() { return /* binding */ applyStyle; } /* harmony export */ }); /* harmony import */ var _detect_active_style__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(69341); /* harmony import */ var jodit_esm_core_constants__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(82758); /* harmony import */ var jodit_esm_core_dom_dom__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(2748); /*! * 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/ */ function findTarget(editor, def) { const current = editor.s.current(); if (!current) { return null; } if (jodit_esm_core_constants__WEBPACK_IMPORTED_MODULE_1__.IS_BLOCK.test(def.element)) { return jodit_esm_core_dom_dom__WEBPACK_IMPORTED_MODULE_2__.Dom.closest(current, jodit_esm_core_dom_dom__WEBPACK_IMPORTED_MODULE_2__.Dom.isBlock, editor.editor); } let node = jodit_esm_core_dom_dom__WEBPACK_IMPORTED_MODULE_2__.Dom.isElement(current) ? current : current.parentNode; while(node && node !== editor.editor){ if (jodit_esm_core_dom_dom__WEBPACK_IMPORTED_MODULE_2__.Dom.isElement(node) && node.nodeName.toLowerCase() === def.element) { return node; } node = node.parentNode; } return null; } function removeClassesFromElement(el, classes) { for (const cls of classes){ el.classList.remove(cls); } if (el.className === '') { el.removeAttribute('class'); } } function cleanupExtraClasses(editor, def) { if (def.classes.length <= 1) { return; } const current = editor.s.current(); if (!current) { return; } if (jodit_esm_core_constants__WEBPACK_IMPORTED_MODULE_1__.IS_BLOCK.test(def.element)) { const block = jodit_esm_core_dom_dom__WEBPACK_IMPORTED_MODULE_2__.Dom.closest(current, jodit_esm_core_dom_dom__WEBPACK_IMPORTED_MODULE_2__.Dom.isBlock, editor.editor); if (block) { removeClassesFromElement(block, def.classes.slice(1)); } } else { const target = findTarget(editor, def); if (target) { removeClassesFromElement(target, def.classes.slice(1)); if (target.nodeName.toLowerCase() === 'span' && !target.attributes.length) { jodit_esm_core_dom_dom__WEBPACK_IMPORTED_MODULE_2__.Dom.unwrap(target); } } } } function addExtraClasses(editor, def) { if (def.classes.length <= 1) { return; } const target = findTarget(editor, def); if (!target) { return; } for(let i = 1; i < def.classes.length; i++){ target.classList.add(def.classes[i]); } } function applyStyle(editor, def, definitions) { const active = (0,_detect_active_style__WEBPACK_IMPORTED_MODULE_0__.detectActiveStyle)(editor, definitions); if (active) { editor.s.commitStyle({ element: active.element, attributes: { class: active.classes[0] } }); cleanupExtraClasses(editor, active); if (active === def) { return; } } editor.s.commitStyle({ element: def.element, attributes: { class: def.classes[0] } }); addExtraClasses(editor, def); } /***/ }), /***/ 69341: /***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) { "use strict"; /* harmony export */ __webpack_require__.d(__webpack_exports__, { /* harmony export */ detectActiveStyle: function() { return /* binding */ detectActiveStyle; } /* harmony export */ }); /* harmony import */ var jodit_esm_core_constants__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(82758); /* harmony import */ var jodit_esm_core_dom_dom__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(2748); /*! * 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/ */ function elementMatchesDefinition(el, def) { if (el.nodeName.toLowerCase() !== def.element) { return false; } return def.classes.every((cls)=>el.classList.contains(cls)); } function detectActiveStyle(editor, definitions) { const current = editor.s.current(); if (!current) { return null; } for (const def of definitions){ if (jodit_esm_core_constants__WEBPACK_IMPORTED_MODULE_0__.IS_BLOCK.test(def.element)) { const block = jodit_esm_core_dom_dom__WEBPACK_IMPORTED_MODULE_1__.Dom.closest(current, jodit_esm_core_dom_dom__WEBPACK_IMPORTED_MODULE_1__.Dom.isBlock, editor.editor); if (block && elementMatchesDefinition(block, def)) { return def; } } else { let node = jodit_esm_core_dom_dom__WEBPACK_IMPORTED_MODULE_1__.Dom.isElement(current) ? current : current.parentNode; while(node && node !== editor.editor){ if (jodit_esm_core_dom_dom__WEBPACK_IMPORTED_MODULE_1__.Dom.isElement(node) && elementMatchesDefinition(node, def)) { return def; } node = node.parentNode; } } } return null; } /***/ }), /***/ 75554: /***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) { "use strict"; __webpack_require__.r(__webpack_exports__); /* harmony export */ __webpack_require__.d(__webpack_exports__, { /* harmony export */ style: function() { return /* binding */ style; } /* harmony export */ }); /* harmony import */ var _swc_helpers_define_property__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(82749); /* harmony import */ var _config__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(28609); /* harmony import */ var jodit_esm_core_plugin__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(50911); /* harmony import */ var jodit_pro_jodit_pro__WEBPACK_IMPORTED_MODULE_3__ = __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 style extends jodit_esm_core_plugin__WEBPACK_IMPORTED_MODULE_2__.Plugin { /** @override */ afterInit(_jodit) {} /** @override */ beforeDestruct(_jodit) {} constructor(...args){ super(...args), /** @override */ (0,_swc_helpers_define_property__WEBPACK_IMPORTED_MODULE_0__._)(this, "buttons", [ { name: 'style', group: 'font' } ]); } } /** @override */ (0,_swc_helpers_define_property__WEBPACK_IMPORTED_MODULE_0__._)(style, "requires", [ 'license' ]); jodit_pro_jodit_pro__WEBPACK_IMPORTED_MODULE_3__.JoditPro.plugins.add('style', style); /***/ }), /***/ 78955: /***/ (function(module) { module.exports = "<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 24 24\" width=\"24\" height=\"24\" stroke=\"currentColor\" stroke-width=\"1.5\"> <rect x=\"2\" y=\"3.5\" width=\"9\" height=\"9\" rx=\"1.5\" fill=\"none\"/> <rect x=\"2\" y=\"14.5\" width=\"9\" height=\"9\" rx=\"1.5\" fill=\"none\"/> <rect x=\"13\" y=\"14.5\" width=\"9\" height=\"9\" rx=\"1.5\" fill=\"none\"/> <rect x=\"13\" y=\"3.5\" width=\"9\" height=\"9\" rx=\"1.5\" fill=\"currentColor\" transform=\"rotate(45 17.5 8)\"/> </svg>" /***/ }) }, /******/ function(__webpack_require__) { // webpackRuntimeModules /******/ var __webpack_exec__ = function(moduleId) { return __webpack_require__(__webpack_require__.s = moduleId); } /******/ var __webpack_exports__ = (__webpack_exec__(75554)); /******/ return __webpack_exports__; /******/ } ]); });