jodit-pro
Version:
PRO Version of Jodit Editor
323 lines (300 loc) • 14.2 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
*/
"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_call_super__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(80294);
/* harmony import */ var _swc_helpers_class_call_check__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(20616);
/* harmony import */ var _swc_helpers_create_class__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(67709);
/* harmony import */ var _swc_helpers_define_property__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(82749);
/* harmony import */ var _swc_helpers_inherits__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(18766);
/* harmony import */ var _swc_helpers_wrap_native_super__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(23078);
/* harmony import */ var _swc_helpers_ts_decorate__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(31635);
/* harmony import */ var _config__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(36347);
/* harmony import */ var jodit_esm_core_decorators__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(65478);
/* harmony import */ var jodit_esm_core_dom_dom__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(2748);
/* harmony import */ var jodit_esm_core_helpers_utils_attr__WEBPACK_IMPORTED_MODULE_10__ = __webpack_require__(29960);
/* harmony import */ var jodit_esm_core_plugin_plugin__WEBPACK_IMPORTED_MODULE_11__ = __webpack_require__(20356);
/* harmony import */ var jodit_pro_jodit_pro__WEBPACK_IMPORTED_MODULE_12__ = __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 highlightSignature = /*#__PURE__*/ function(Plugin) {
"use strict";
(0,_swc_helpers_inherits__WEBPACK_IMPORTED_MODULE_4__._)(highlightSignature, Plugin);
function highlightSignature() {
(0,_swc_helpers_class_call_check__WEBPACK_IMPORTED_MODULE_1__._)(this, highlightSignature);
var _this;
_this = (0,_swc_helpers_call_super__WEBPACK_IMPORTED_MODULE_0__._)(this, highlightSignature, arguments), (0,_swc_helpers_define_property__WEBPACK_IMPORTED_MODULE_3__._)(_this, "abortController", null);
return _this;
}
(0,_swc_helpers_create_class__WEBPACK_IMPORTED_MODULE_2__._)(highlightSignature, [
{
key: "afterInit",
value: function afterInit(jodit) {
if (Object.keys(jodit.o.highlightSignature.schema).length) {
jodit.e.on('change afterSetMode', this.walkNodes).on('afterGetValueFromEditor', highlightSignature.removeUtilWrappers);
this.walkNodes();
}
}
},
{
key: "beforeDestruct",
value: function beforeDestruct(jodit) {
jodit.e.off('change afterSetMode', this.walkNodes).off('afterGetValueFromEditor', highlightSignature.removeUtilWrappers);
}
},
{
key: "walkNodes",
value: function walkNodes() {
var _this_abortController;
if (!this.j.isEditorMode()) {
return;
}
this.checkUtilsBoxToSchema();
var j = this.j;
var nodeIterator = j.ed.createNodeIterator(j.editor, NodeFilter.SHOW_TEXT);
(_this_abortController = this.abortController) === null || _this_abortController === void 0 ? void 0 : _this_abortController.abort();
this.workLoop(nodeIterator);
}
},
{
key: "runWorker",
value: function runWorker(nodeIterator) {
var node;
this.j.e.mute();
var count = 0;
var processInChunkCount = this.j.o.highlightSignature.processInChunkCount;
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);
}
},
{
key: "workLoop",
value: function workLoop(nodeIterator) {
var _this = this;
this.abortController = new AbortController();
this.j.async.schedulerPostTask(function() {
return _this.runWorker(nodeIterator);
}, {
delay: this.j.o.highlightSignature.processDelay
}).catch(function() {
return null;
});
}
},
{
key: "checkNormalizing",
value: /**
* Checks if there are text nodes that are cut into pieces,
* if there are, normalizes the editor and starts the loop again
*/ function checkNormalizing(node) {
if (jodit_esm_core_dom_dom__WEBPACK_IMPORTED_MODULE_9__.Dom.isText(node.nextSibling)) {
this.j.editor.normalize();
this.walkNodes();
return true;
}
return false;
}
},
{
key: "checkReplaceSchemas",
value: /**
* Checks the content of the text node through the scheme setting and if there is a match, then replaces the found part
*/ function checkReplaceSchemas(node) {
if (highlightSignature.hasUtilWrapper(node)) {
return;
}
var value = node.nodeValue;
if (value == null) {
return;
}
var j = this.j;
var opts = j.o.highlightSignature;
for(var schemaKey in opts.schema){
var regExp = RegExp(schemaKey);
if (regExp.test(value)) {
var matched = value.match(regExp);
if (!matched || matched.index === undefined) {
continue;
}
var elm = opts.schema[schemaKey](this.j, matched);
if (elm) {
jodit_esm_core_dom_dom__WEBPACK_IMPORTED_MODULE_9__.Dom.markTemporary(elm, {
dataHighlightSchema: schemaKey
});
this.replaceMatchedTextToElm(node, value, matched, elm);
return;
}
}
}
}
},
{
key: "replaceMatchedTextToElm",
value: /**
* Replaces the part that matches the schematic with the created element and restores the cursor position
*/ function replaceMatchedTextToElm(node, value, matched, elm) {
var _matched_index;
var j = this.j, range = j.s.range, hasCursorInside = range.startContainer === node, offset = range.startOffset, index = (_matched_index = matched.index) !== null && _matched_index !== void 0 ? _matched_index : 0;
node.nodeValue = value.substring(0, index);
var rightPartText = value.substring(index + matched[0].length);
if (rightPartText.length) {
var rightPart = j.createInside.text(rightPartText);
jodit_esm_core_dom_dom__WEBPACK_IMPORTED_MODULE_9__.Dom.after(node, rightPart);
}
elm.innerText = matched[0];
jodit_esm_core_dom_dom__WEBPACK_IMPORTED_MODULE_9__.Dom.after(node, elm);
if (hasCursorInside) {
this.restoreCursorPosition(offset, node, elm.firstChild, elm.nextSibling);
}
}
},
{
key: "restoreCursorPosition",
value: /**
* Restores the cursor position to the place where it was before replacement
*/ function restoreCursorPosition(offset) {
for(var _len = arguments.length, nodes = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++){
nodes[_key - 1] = arguments[_key];
}
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
try {
for(var _iterator = nodes[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
var node = _step.value;
if (node && node.nodeValue) {
var value = node.nodeValue;
if (value.length >= offset) {
var range = this.j.s.createRange();
range.setStart(node, offset);
this.j.s.selectRange(range, false);
break;
}
offset -= value.length;
}
}
} catch (err) {
_didIteratorError = true;
_iteratorError = err;
} finally{
try {
if (!_iteratorNormalCompletion && _iterator.return != null) {
_iterator.return();
}
} finally{
if (_didIteratorError) {
throw _iteratorError;
}
}
}
}
},
{
key: "checkUtilsBoxToSchema",
value: /**
* Removes wrappers whose content no longer matches the schema
*/ function checkUtilsBoxToSchema() {
var _this = this;
jodit_esm_core_dom_dom__WEBPACK_IMPORTED_MODULE_9__.Dom.temporaryList(this.j.editor).forEach(function(elm) {
var _elm_innerText;
var schema = (0,jodit_esm_core_helpers_utils_attr__WEBPACK_IMPORTED_MODULE_10__.attr)(elm, 'dataHighlightSchema');
if (!schema) {
return;
}
var reg = RegExp(schema);
var text = (_elm_innerText = elm.innerText) !== null && _elm_innerText !== void 0 ? _elm_innerText : '';
if (!reg.test(text) || text.replace(reg, '').length) {
_this.j.s.save();
jodit_esm_core_dom_dom__WEBPACK_IMPORTED_MODULE_9__.Dom.unwrap(elm);
_this.j.s.restore();
}
});
}
}
], [
{
key: "hasUtilWrapper",
value: /**
* The text node already has a parent for highlighting
*/ function hasUtilWrapper(node) {
return jodit_esm_core_dom_dom__WEBPACK_IMPORTED_MODULE_9__.Dom.isTemporary(node.parentElement);
}
},
{
key: "removeUtilWrappers",
value: /**
* Removes utility highlighting elements from HTML
*/ function removeUtilWrappers(data) {
data.value = jodit_esm_core_dom_dom__WEBPACK_IMPORTED_MODULE_9__.Dom.replaceTemporaryFromString(data.value);
}
}
]);
return highlightSignature;
}((0,_swc_helpers_wrap_native_super__WEBPACK_IMPORTED_MODULE_5__._)(jodit_esm_core_plugin_plugin__WEBPACK_IMPORTED_MODULE_11__.Plugin));
/** @override */ (0,_swc_helpers_define_property__WEBPACK_IMPORTED_MODULE_3__._)(highlightSignature, "requires", [
'license'
]);
(0,_swc_helpers_ts_decorate__WEBPACK_IMPORTED_MODULE_6__.__decorate)([
(0,jodit_esm_core_decorators__WEBPACK_IMPORTED_MODULE_8__.debounce)()
], highlightSignature.prototype, "walkNodes", null);
(0,_swc_helpers_ts_decorate__WEBPACK_IMPORTED_MODULE_6__.__decorate)([
jodit_esm_core_decorators__WEBPACK_IMPORTED_MODULE_8__.autobind
], highlightSignature.prototype, "runWorker", null);
jodit_pro_jodit_pro__WEBPACK_IMPORTED_MODULE_12__.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__;
/******/ }
]);
});