UNPKG

jodit-pro

Version:

PRO Version of Jodit Editor

239 lines (221 loc) 9.57 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([[726],{ /***/ 36347: /***/ (function(__unused_webpack_module, __unused_webpack___webpack_exports__, __webpack_require__) { /* harmony import */ var jodit_esm_config__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(6441); jodit_esm_config__WEBPACK_IMPORTED_MODULE_0__.Config.prototype.highlightSignature = { processDelay: 0, processInChunkCount: 300, schema: {}, excludeTags: [ 'pre' ] }; /***/ }), /***/ 46958: /***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) { __webpack_require__.r(__webpack_exports__); /* harmony export */ __webpack_require__.d(__webpack_exports__, { /* harmony export */ highlightSignature: function() { return /* binding */ highlightSignature; } /* 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__(36347); /* harmony import */ var jodit_esm_core_decorators__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(65478); /* harmony import */ var jodit_esm_core_dom_dom__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(2748); /* harmony import */ var jodit_esm_core_helpers_utils_attr__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(29960); /* harmony import */ var jodit_esm_core_plugin_plugin__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(20356); /* harmony import */ var jodit_pro_jodit_pro__WEBPACK_IMPORTED_MODULE_7__ = __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 highlightSignature extends jodit_esm_core_plugin_plugin__WEBPACK_IMPORTED_MODULE_6__.Plugin { afterInit(jodit) { if (Object.keys(jodit.o.highlightSignature.schema).length) { jodit.e.on('change afterSetMode', this.walkNodes).on('afterGetValueFromEditor', highlightSignature.removeUtilWrappers); this.walkNodes(); } } beforeDestruct(jodit) { jodit.e.off('change afterSetMode', this.walkNodes).off('afterGetValueFromEditor', highlightSignature.removeUtilWrappers); } walkNodes() { if (!this.j.isEditorMode()) { return; } this.checkUtilsBoxToSchema(); const { j } = this; const nodeIterator = j.ed.createNodeIterator(j.editor, NodeFilter.SHOW_TEXT); this.abortController?.abort(); this.workLoop(nodeIterator); } runWorker(nodeIterator) { let node; this.j.e.mute(); let count = 0; const { processInChunkCount } = this.j.o.highlightSignature; try { do { count += 1; node = nodeIterator.nextNode(); if (!node) { return; } if (this.checkNormalizing(node)) { return; } this.checkReplaceSchemas(node); }while (node && processInChunkCount > count) } finally{ this.j.e.unmute(); } this.workLoop(nodeIterator); } workLoop(nodeIterator) { this.abortController = new AbortController(); this.j.async.schedulerPostTask(()=>this.runWorker(nodeIterator), { delay: this.j.o.highlightSignature.processDelay }).catch(()=>null); } /** * Checks if there are text nodes that are cut into pieces, * if there are, normalizes the editor and starts the loop again */ checkNormalizing(node) { if (jodit_esm_core_dom_dom__WEBPACK_IMPORTED_MODULE_4__.Dom.isText(node.nextSibling)) { this.j.editor.normalize(); this.walkNodes(); return true; } return false; } /** * Checks the content of the text node through the scheme setting and if there is a match, then replaces the found part */ checkReplaceSchemas(node) { if (highlightSignature.hasUtilWrapper(node)) { return; } const value = node.nodeValue; if (value == null) { return; } const { j } = this; const opts = j.o.highlightSignature; for(const schemaKey in opts.schema){ const regExp = RegExp(schemaKey); if (regExp.test(value)) { const matched = value.match(regExp); if (!matched || matched.index === undefined) { continue; } const elm = opts.schema[schemaKey](this.j, matched); if (elm) { jodit_esm_core_dom_dom__WEBPACK_IMPORTED_MODULE_4__.Dom.markTemporary(elm, { dataHighlightSchema: schemaKey }); this.replaceMatchedTextToElm(node, value, matched, elm); return; } } } } /** * Replaces the part that matches the schematic with the created element and restores the cursor position */ replaceMatchedTextToElm(node, value, matched, elm) { const { j } = this, { range } = j.s, hasCursorInside = range.startContainer === node, offset = range.startOffset, index = matched.index ?? 0; node.nodeValue = value.substring(0, index); const rightPartText = value.substring(index + matched[0].length); if (rightPartText.length) { const rightPart = j.createInside.text(rightPartText); jodit_esm_core_dom_dom__WEBPACK_IMPORTED_MODULE_4__.Dom.after(node, rightPart); } elm.innerText = matched[0]; jodit_esm_core_dom_dom__WEBPACK_IMPORTED_MODULE_4__.Dom.after(node, elm); if (hasCursorInside) { this.restoreCursorPosition(offset, node, elm.firstChild, elm.nextSibling); } } /** * The text node already has a parent for highlighting */ static hasUtilWrapper(node) { return jodit_esm_core_dom_dom__WEBPACK_IMPORTED_MODULE_4__.Dom.isTemporary(node.parentElement); } /** * Removes utility highlighting elements from HTML */ static removeUtilWrappers(data) { data.value = jodit_esm_core_dom_dom__WEBPACK_IMPORTED_MODULE_4__.Dom.replaceTemporaryFromString(data.value); } /** * Restores the cursor position to the place where it was before replacement */ restoreCursorPosition(offset, ...nodes) { for (const node of nodes){ if (node && node.nodeValue) { const value = node.nodeValue; if (value.length >= offset) { const range = this.j.s.createRange(); range.setStart(node, offset); this.j.s.selectRange(range, false); break; } offset -= value.length; } } } /** * Removes wrappers whose content no longer matches the schema */ checkUtilsBoxToSchema() { jodit_esm_core_dom_dom__WEBPACK_IMPORTED_MODULE_4__.Dom.temporaryList(this.j.editor).forEach((elm)=>{ const schema = (0,jodit_esm_core_helpers_utils_attr__WEBPACK_IMPORTED_MODULE_5__.attr)(elm, 'dataHighlightSchema'); if (!schema) { return; } const reg = RegExp(schema); const text = elm.innerText ?? ''; if (!reg.test(text) || text.replace(reg, '').length) { this.j.s.save(); jodit_esm_core_dom_dom__WEBPACK_IMPORTED_MODULE_4__.Dom.unwrap(elm); this.j.s.restore(); } }); } constructor(...args){ super(...args), (0,_swc_helpers_define_property__WEBPACK_IMPORTED_MODULE_0__._)(this, "abortController", null); } } /** @override */ (0,_swc_helpers_define_property__WEBPACK_IMPORTED_MODULE_0__._)(highlightSignature, "requires", [ 'license' ]); (0,_swc_helpers_ts_decorate__WEBPACK_IMPORTED_MODULE_1__.__decorate)([ (0,jodit_esm_core_decorators__WEBPACK_IMPORTED_MODULE_3__.debounce)() ], highlightSignature.prototype, "walkNodes", null); (0,_swc_helpers_ts_decorate__WEBPACK_IMPORTED_MODULE_1__.__decorate)([ jodit_esm_core_decorators__WEBPACK_IMPORTED_MODULE_3__.autobind ], highlightSignature.prototype, "runWorker", null); jodit_pro_jodit_pro__WEBPACK_IMPORTED_MODULE_7__.JoditPro.plugins.add('highlight-signature', highlightSignature); /***/ }) }, /******/ function(__webpack_require__) { // webpackRuntimeModules /******/ var __webpack_exec__ = function(moduleId) { return __webpack_require__(__webpack_require__.s = moduleId); } /******/ var __webpack_exports__ = (__webpack_exec__(46958)); /******/ return __webpack_exports__; /******/ } ]); });