UNPKG

jodit-pro

Version:

PRO Version of Jodit Editor

375 lines (346 loc) 15 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 */ "use strict"; (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([[576],{ /***/ 8256: /***/ (function(__unused_webpack_module, __unused_webpack___webpack_exports__, __webpack_require__) { /* harmony import */ var jodit_esm_config__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(6441); /* harmony import */ var jodit_esm_core_dom__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(22732); /* harmony import */ var jodit_esm_core_helpers__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(21537); /*! * 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 common = [ 'tune.up', 'tune.remove', 'tune.down' ], header = [ 'tune.h1', 'tune.h2', 'tune.h3', '\n', 'tune.h4', 'tune.h5', 'tune.h6', '\n', ...common ]; jodit_esm_config__WEBPACK_IMPORTED_MODULE_0__.Config.prototype.tuneBlock = { popup: { p: common, table: common, img: common, blockquote: common, div: common, pre: [ 'tune.editPre', ...common ], h1: header, h2: header, h3: header, h4: header, h5: header, h6: header } }; function headerControl(h) { return { icon: '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 50 50">' + '<text dominant-baseline="text-before-edge" style="font: 45px sans-serif" x="0" y="0">' + h.toUpperCase() + '</text>' + '</svg>', isActive (editor, button) { return button?.target?.tagName.toLowerCase() === h; }, exec (editor, target) { if (target) { editor.selection.save(); const header = jodit_esm_core_dom__WEBPACK_IMPORTED_MODULE_1__.Dom.replace(target, h, editor.createInside); editor.selection.restore(); editor.e.fire('synchro'); editor.e.fire('afterExecTune.tune', header); } return true; } }; } function moveTo(up) { const sibling = up ? 'previousSibling' : 'nextSibling'; return { icon: up ? 'angle-up' : 'angle-down', isDisabled (editor, button) { return !button?.target?.[sibling]; }, exec (editor, target) { const siblingNode = target?.[sibling]; if (target && siblingNode) { editor.selection.save(); (0,jodit_esm_core_helpers__WEBPACK_IMPORTED_MODULE_2__.call)(up ? jodit_esm_core_dom__WEBPACK_IMPORTED_MODULE_1__.Dom.before : jodit_esm_core_dom__WEBPACK_IMPORTED_MODULE_1__.Dom.after, siblingNode, target); editor.selection.restore(); } editor.e.fire('synchro'); editor.e.fire('afterExecTune.tune'); return true; } }; } jodit_esm_config__WEBPACK_IMPORTED_MODULE_0__.Config.prototype.controls.tune = { h1: headerControl('h1'), h2: headerControl('h2'), h3: headerControl('h3'), h4: headerControl('h4'), h5: headerControl('h5'), h6: headerControl('h6'), up: moveTo(true), down: moveTo(false), editPre: { icon: 'pencil', exec (editor, target) { editor.e.fire('editPreInPasteCode', target); } }, remove: { icon: 'bin', exec (editor, target) { jodit_esm_core_dom__WEBPACK_IMPORTED_MODULE_1__.Dom.safeRemove(target); editor.e.fire('synchro'); editor.e.fire('closeTuner.tune'); editor.e.fire('hideTuner.tune'); } } }; /***/ }), /***/ 13152: /***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) { __webpack_require__.r(__webpack_exports__); /* harmony export */ __webpack_require__.d(__webpack_exports__, { /* harmony export */ tuneBlock: function() { return /* binding */ tuneBlock; } /* 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__(8256); /* harmony import */ var _ui_tuner_tuner__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(40104); /* harmony import */ var jodit_esm_core_decorators__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(65478); /* harmony import */ var jodit_esm_core_plugin__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(50911); /* harmony import */ var jodit_pro_jodit_pro__WEBPACK_IMPORTED_MODULE_6__ = __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/ */ /** * Tune block with popup: move, align, change block tag, and another options */ class tuneBlock extends jodit_esm_core_plugin__WEBPACK_IMPORTED_MODULE_5__.Plugin { afterInit(jodit) { this.tuner = new _ui_tuner_tuner__WEBPACK_IMPORTED_MODULE_3__.UITuner(jodit); } /** * Handler: click on an element outside the editor or the keyboard closes the tuner */ hideTuner() { this.tuner.hide(); } onChangeSelection() { if (!this.j.s.isCollapsed()) { this.hideTuner(); } } /** * Handler: click on an element inside the editor */ onClickInBlock(_) { if (this.j.s.isCollapsed()) { this.tuner.show(); } } beforeDestruct(jodit) { this.tuner.destruct(); } constructor(...args){ super(...args), /** * UI element for managing blocks */ (0,_swc_helpers_define_property__WEBPACK_IMPORTED_MODULE_0__._)(this, "tuner", void 0); } } /** @override */ (0,_swc_helpers_define_property__WEBPACK_IMPORTED_MODULE_0__._)(tuneBlock, "requires", [ 'license' ]); (0,_swc_helpers_ts_decorate__WEBPACK_IMPORTED_MODULE_1__.__decorate)([ (0,jodit_esm_core_decorators__WEBPACK_IMPORTED_MODULE_4__.watch)(':outsideClick :keydown') ], tuneBlock.prototype, "hideTuner", null); (0,_swc_helpers_ts_decorate__WEBPACK_IMPORTED_MODULE_1__.__decorate)([ (0,jodit_esm_core_decorators__WEBPACK_IMPORTED_MODULE_4__.watch)('j.ed:selectionchange'), (0,jodit_esm_core_decorators__WEBPACK_IMPORTED_MODULE_4__.debounce)() ], tuneBlock.prototype, "onChangeSelection", null); (0,_swc_helpers_ts_decorate__WEBPACK_IMPORTED_MODULE_1__.__decorate)([ (0,jodit_esm_core_decorators__WEBPACK_IMPORTED_MODULE_4__.watch)(':click') ], tuneBlock.prototype, "onClickInBlock", null); jodit_pro_jodit_pro__WEBPACK_IMPORTED_MODULE_6__.JoditPro.plugins.add('tune-block', tuneBlock); /***/ }), /***/ 40104: /***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) { /* harmony export */ __webpack_require__.d(__webpack_exports__, { /* harmony export */ UITuner: function() { return /* binding */ UITuner; } /* 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 jodit_esm_core_decorators__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(65478); /* harmony import */ var jodit_esm_core_dom__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(22732); /* harmony import */ var jodit_esm_core_helpers__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(21537); /* harmony import */ var jodit_esm_core_ui__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(67510); /* harmony import */ var jodit_esm_modules_toolbar_factory__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(21491); /*! * 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 UITuner extends jodit_esm_core_ui__WEBPACK_IMPORTED_MODULE_5__.UIElement { className() { return 'UITuner'; } render() { return `<div> <div class='&__handle' title='~Click to tune~'/> </div>`; } /** * Shows the tuner, even if it is already shown - recalculates its position */ show() { const target = this.j.s.current(); if (!target) { return this.hide(); } const block = jodit_esm_core_dom__WEBPACK_IMPORTED_MODULE_3__.Dom.isBlock(target) ? target : jodit_esm_core_dom__WEBPACK_IMPORTED_MODULE_3__.Dom.closest(target, (node)=>Boolean(node && this.j.o.tuneBlock.popup[node.nodeName.toLowerCase()]), this.j.editor); if (!block || block === this.j.editor || !this.j.o.tuneBlock.popup[block.tagName.toLowerCase()]) { return this.hide(); } this.currentBlock = block; this.isShown = true; this.closeToolbar(); this.calcPosition(); if (!this.container.parentNode) { this.j.workplace.append(this.container); } } /** * Hides the tuner button */ hide() { if (this.isShown) { this.isShown = false; jodit_esm_core_dom__WEBPACK_IMPORTED_MODULE_3__.Dom.safeRemove(this.container); this.closeToolbar(); } } /** * Recalculates the position of the tuner button when scrolling the editor itself */ onEditorScroll() { if (this.isShown) { this.calcPosition(); } } /** * Calculates the position of the tuner in the editor so that it is always to the right of the block */ calcPosition() { const offset = 15; const marginLeft = (0,jodit_esm_core_helpers__WEBPACK_IMPORTED_MODULE_4__.css)(this.j.editor, 'marginLeft'); const paddingLeft = (0,jodit_esm_core_helpers__WEBPACK_IMPORTED_MODULE_4__.css)(this.j.editor, 'paddingLeft'); const marginTop = (0,jodit_esm_core_helpers__WEBPACK_IMPORTED_MODULE_4__.css)(this.j.editor, 'marginTop'); const left = this.currentBlock.offsetWidth - offset + marginLeft + paddingLeft; const top = this.currentBlock.offsetTop - this.j.editor.scrollTop + marginTop; (0,jodit_esm_core_helpers__WEBPACK_IMPORTED_MODULE_4__.css)(this.container, { transform: `translate3d(${left}px, ${top}px, 0)` }); if (this.popup.isOpened) { this.popup.updatePosition(); } } /** * Handler: `afterExecTune.tune` */ onAfterExecTune(newBlock) { if (newBlock) { this.currentBlock = newBlock; } this.calcPosition(); this.openToolbar(); } /** * To prevent the editor from losing focus when clicking on the handler - we will prevent the click */ onClickPrevent(e) { e.preventDefault(); e.stopPropagation(); } /** * Handler: click on the tuner button */ onTargetClick() { this.toggleToolbar(); } /** * Opens the tuner toolbar */ openToolbar() { this.setMod('opened', true); this.toolbar.build(this.j.o.tuneBlock.popup[this.currentBlock.tagName.toLowerCase()], this.currentBlock); this.popup.setContent(this.toolbar.container); if (!this.popup.isOpened) { const handle = this.getElm('handle'); (0,jodit_esm_core_helpers__WEBPACK_IMPORTED_MODULE_4__.assert)(handle != null, 'Handle element does not exist'); this.popup.open(()=>(0,jodit_esm_core_helpers__WEBPACK_IMPORTED_MODULE_4__.position)(handle)); } } /** * Closes the tuner toolbar */ closeToolbar() { this.setMod('opened', false); this.popup.close(); } toggleToolbar() { this.getMod('opened') ? this.closeToolbar() : this.openToolbar(); } constructor(...args){ super(...args), (0,_swc_helpers_define_property__WEBPACK_IMPORTED_MODULE_0__._)(this, "isShown", false), (0,_swc_helpers_define_property__WEBPACK_IMPORTED_MODULE_0__._)(this, "toolbar", (0,jodit_esm_modules_toolbar_factory__WEBPACK_IMPORTED_MODULE_6__.makeCollection)(this.j, this)), (0,_swc_helpers_define_property__WEBPACK_IMPORTED_MODULE_0__._)(this, "popup", new jodit_esm_core_ui__WEBPACK_IMPORTED_MODULE_5__.Popup(this.j, false)), (0,_swc_helpers_define_property__WEBPACK_IMPORTED_MODULE_0__._)(this, "currentBlock", void 0); } } (0,_swc_helpers_ts_decorate__WEBPACK_IMPORTED_MODULE_1__.__decorate)([ (0,jodit_esm_core_decorators__WEBPACK_IMPORTED_MODULE_2__.watch)(':hideTuner.tune') ], UITuner.prototype, "hide", null); (0,_swc_helpers_ts_decorate__WEBPACK_IMPORTED_MODULE_1__.__decorate)([ (0,jodit_esm_core_decorators__WEBPACK_IMPORTED_MODULE_2__.watch)('j.editor:scroll'), (0,jodit_esm_core_decorators__WEBPACK_IMPORTED_MODULE_2__.throttle)(10) ], UITuner.prototype, "onEditorScroll", null); (0,_swc_helpers_ts_decorate__WEBPACK_IMPORTED_MODULE_1__.__decorate)([ (0,jodit_esm_core_decorators__WEBPACK_IMPORTED_MODULE_2__.watch)(':afterExecTune.tune'), (0,jodit_esm_core_decorators__WEBPACK_IMPORTED_MODULE_2__.idle)() ], UITuner.prototype, "onAfterExecTune", null); (0,_swc_helpers_ts_decorate__WEBPACK_IMPORTED_MODULE_1__.__decorate)([ (0,jodit_esm_core_decorators__WEBPACK_IMPORTED_MODULE_2__.watch)('container:click container:mousedown') ], UITuner.prototype, "onClickPrevent", null); (0,_swc_helpers_ts_decorate__WEBPACK_IMPORTED_MODULE_1__.__decorate)([ (0,jodit_esm_core_decorators__WEBPACK_IMPORTED_MODULE_2__.watch)('handle:click') ], UITuner.prototype, "onTargetClick", null); (0,_swc_helpers_ts_decorate__WEBPACK_IMPORTED_MODULE_1__.__decorate)([ (0,jodit_esm_core_decorators__WEBPACK_IMPORTED_MODULE_2__.watch)(':closeTuner.tune') ], UITuner.prototype, "closeToolbar", null); UITuner = (0,_swc_helpers_ts_decorate__WEBPACK_IMPORTED_MODULE_1__.__decorate)([ jodit_esm_core_decorators__WEBPACK_IMPORTED_MODULE_2__.component ], UITuner); /***/ }) }, /******/ function(__webpack_require__) { // webpackRuntimeModules /******/ var __webpack_exec__ = function(moduleId) { return __webpack_require__(__webpack_require__.s = moduleId); } /******/ var __webpack_exports__ = (__webpack_exec__(13152)); /******/ return __webpack_exports__; /******/ } ]); });