12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133 |
- import {
- __commonJS
- } from "./chunk-2LSFTFF7.js";
- // node_modules/.pnpm/tinymce@5.10.7/node_modules/tinymce/plugins/searchreplace/plugin.js
- var require_plugin = __commonJS({
- "node_modules/.pnpm/tinymce@5.10.7/node_modules/tinymce/plugins/searchreplace/plugin.js"() {
- (function() {
- "use strict";
- var Cell = function(initial) {
- var value2 = initial;
- var get2 = function() {
- return value2;
- };
- var set2 = function(v) {
- value2 = v;
- };
- return {
- get: get2,
- set: set2
- };
- };
- var global$3 = tinymce.util.Tools.resolve("tinymce.PluginManager");
- var __assign = function() {
- __assign = Object.assign || function __assign2(t) {
- for (var s, i = 1, n = arguments.length; i < n; i++) {
- s = arguments[i];
- for (var p in s)
- if (Object.prototype.hasOwnProperty.call(s, p))
- t[p] = s[p];
- }
- return t;
- };
- return __assign.apply(this, arguments);
- };
- var typeOf = function(x) {
- var t = typeof x;
- if (x === null) {
- return "null";
- } else if (t === "object" && (Array.prototype.isPrototypeOf(x) || x.constructor && x.constructor.name === "Array")) {
- return "array";
- } else if (t === "object" && (String.prototype.isPrototypeOf(x) || x.constructor && x.constructor.name === "String")) {
- return "string";
- } else {
- return t;
- }
- };
- var isType$1 = function(type2) {
- return function(value2) {
- return typeOf(value2) === type2;
- };
- };
- var isSimpleType = function(type2) {
- return function(value2) {
- return typeof value2 === type2;
- };
- };
- var isString = isType$1("string");
- var isArray = isType$1("array");
- var isBoolean = isSimpleType("boolean");
- var isNumber = isSimpleType("number");
- var noop = function() {
- };
- var constant = function(value2) {
- return function() {
- return value2;
- };
- };
- var identity = function(x) {
- return x;
- };
- var never = constant(false);
- var always = constant(true);
- var punctuationStr = "[!-#%-*,-\\/:;?@\\[-\\]_{}¡«·»¿;·՚-՟։֊־׀׃׆׳״؉؊،؍؛؞؟٪-٭۔܀-܍߷-߹࠰-࠾࡞।॥॰෴๏๚๛༄-༒༺-༽྅࿐-࿔࿙࿚၊-၏჻፡-፨᐀᙭᙮᚛᚜᛫-᛭᜵᜶។-៖៘-៚᠀-᠊᥄᥅᨞᨟᪠-᪦᪨-᪭᭚-᭠᯼-᯿᰻-᰿᱾᱿᳓‐-‧‰-⁃⁅-⁑⁓-⁞⁽⁾₍₎〈〉❨-❵⟅⟆⟦-⟯⦃-⦘⧘-⧛⧼⧽⳹-⳼⳾⳿⵰⸀-⸮⸰⸱、-〃〈-】〔-〟〰〽゠・꓾꓿꘍-꘏꙳꙾꛲-꛷꡴-꡷꣎꣏꣸-꣺꤮꤯꥟꧁-꧍꧞꧟꩜-꩟꫞꫟꯫﴾﴿︐-︙︰-﹒﹔-﹡﹣﹨﹪﹫!-#%-*,-/:;?@[-]_{}⦅-・]";
- var punctuation$1 = constant(punctuationStr);
- var none = function() {
- return NONE;
- };
- var NONE = function() {
- var call = function(thunk) {
- return thunk();
- };
- var id = identity;
- var me = {
- fold: function(n, _s) {
- return n();
- },
- isSome: never,
- isNone: always,
- getOr: id,
- getOrThunk: call,
- getOrDie: function(msg) {
- throw new Error(msg || "error: getOrDie called on none.");
- },
- getOrNull: constant(null),
- getOrUndefined: constant(void 0),
- or: id,
- orThunk: call,
- map: none,
- each: noop,
- bind: none,
- exists: never,
- forall: always,
- filter: function() {
- return none();
- },
- toArray: function() {
- return [];
- },
- toString: constant("none()")
- };
- return me;
- }();
- var some = function(a) {
- var constant_a = constant(a);
- var self = function() {
- return me;
- };
- var bind2 = function(f) {
- return f(a);
- };
- var me = {
- fold: function(n, s) {
- return s(a);
- },
- isSome: always,
- isNone: never,
- getOr: constant_a,
- getOrThunk: constant_a,
- getOrDie: constant_a,
- getOrNull: constant_a,
- getOrUndefined: constant_a,
- or: self,
- orThunk: self,
- map: function(f) {
- return some(f(a));
- },
- each: function(f) {
- f(a);
- },
- bind: bind2,
- exists: bind2,
- forall: bind2,
- filter: function(f) {
- return f(a) ? me : NONE;
- },
- toArray: function() {
- return [a];
- },
- toString: function() {
- return "some(" + a + ")";
- }
- };
- return me;
- };
- var from = function(value2) {
- return value2 === null || value2 === void 0 ? NONE : some(value2);
- };
- var Optional = {
- some,
- none,
- from
- };
- var punctuation = punctuation$1;
- var global$2 = tinymce.util.Tools.resolve("tinymce.Env");
- var global$1 = tinymce.util.Tools.resolve("tinymce.util.Tools");
- var nativeSlice = Array.prototype.slice;
- var nativePush = Array.prototype.push;
- var map = function(xs, f) {
- var len = xs.length;
- var r = new Array(len);
- for (var i = 0; i < len; i++) {
- var x = xs[i];
- r[i] = f(x, i);
- }
- return r;
- };
- var each = function(xs, f) {
- for (var i = 0, len = xs.length; i < len; i++) {
- var x = xs[i];
- f(x, i);
- }
- };
- var eachr = function(xs, f) {
- for (var i = xs.length - 1; i >= 0; i--) {
- var x = xs[i];
- f(x, i);
- }
- };
- var groupBy = function(xs, f) {
- if (xs.length === 0) {
- return [];
- } else {
- var wasType = f(xs[0]);
- var r = [];
- var group = [];
- for (var i = 0, len = xs.length; i < len; i++) {
- var x = xs[i];
- var type2 = f(x);
- if (type2 !== wasType) {
- r.push(group);
- group = [];
- }
- wasType = type2;
- group.push(x);
- }
- if (group.length !== 0) {
- r.push(group);
- }
- return r;
- }
- };
- var foldl = function(xs, f, acc) {
- each(xs, function(x, i) {
- acc = f(acc, x, i);
- });
- return acc;
- };
- var flatten = function(xs) {
- var r = [];
- for (var i = 0, len = xs.length; i < len; ++i) {
- if (!isArray(xs[i])) {
- throw new Error("Arr.flatten item " + i + " was not an array, input: " + xs);
- }
- nativePush.apply(r, xs[i]);
- }
- return r;
- };
- var bind = function(xs, f) {
- return flatten(map(xs, f));
- };
- var sort = function(xs, comparator) {
- var copy = nativeSlice.call(xs, 0);
- copy.sort(comparator);
- return copy;
- };
- var hasOwnProperty = Object.hasOwnProperty;
- var has = function(obj, key) {
- return hasOwnProperty.call(obj, key);
- };
- typeof window !== "undefined" ? window : Function("return this;")();
- var DOCUMENT = 9;
- var DOCUMENT_FRAGMENT = 11;
- var ELEMENT = 1;
- var TEXT = 3;
- var type = function(element) {
- return element.dom.nodeType;
- };
- var isType = function(t) {
- return function(element) {
- return type(element) === t;
- };
- };
- var isText$1 = isType(TEXT);
- var rawSet = function(dom, key, value2) {
- if (isString(value2) || isBoolean(value2) || isNumber(value2)) {
- dom.setAttribute(key, value2 + "");
- } else {
- console.error("Invalid call to Attribute.set. Key ", key, ":: Value ", value2, ":: Element ", dom);
- throw new Error("Attribute value was not simple");
- }
- };
- var set = function(element, key, value2) {
- rawSet(element.dom, key, value2);
- };
- var compareDocumentPosition = function(a, b, match) {
- return (a.compareDocumentPosition(b) & match) !== 0;
- };
- var documentPositionPreceding = function(a, b) {
- return compareDocumentPosition(a, b, Node.DOCUMENT_POSITION_PRECEDING);
- };
- var fromHtml = function(html, scope) {
- var doc = scope || document;
- var div = doc.createElement("div");
- div.innerHTML = html;
- if (!div.hasChildNodes() || div.childNodes.length > 1) {
- console.error("HTML does not have a single root node", html);
- throw new Error("HTML must have a single root node");
- }
- return fromDom(div.childNodes[0]);
- };
- var fromTag = function(tag, scope) {
- var doc = scope || document;
- var node = doc.createElement(tag);
- return fromDom(node);
- };
- var fromText = function(text, scope) {
- var doc = scope || document;
- var node = doc.createTextNode(text);
- return fromDom(node);
- };
- var fromDom = function(node) {
- if (node === null || node === void 0) {
- throw new Error("Node cannot be null or undefined");
- }
- return { dom: node };
- };
- var fromPoint = function(docElm, x, y) {
- return Optional.from(docElm.dom.elementFromPoint(x, y)).map(fromDom);
- };
- var SugarElement = {
- fromHtml,
- fromTag,
- fromText,
- fromDom,
- fromPoint
- };
- var bypassSelector = function(dom) {
- return dom.nodeType !== ELEMENT && dom.nodeType !== DOCUMENT && dom.nodeType !== DOCUMENT_FRAGMENT || dom.childElementCount === 0;
- };
- var all = function(selector, scope) {
- var base = scope === void 0 ? document : scope.dom;
- return bypassSelector(base) ? [] : map(base.querySelectorAll(selector), SugarElement.fromDom);
- };
- var parent = function(element) {
- return Optional.from(element.dom.parentNode).map(SugarElement.fromDom);
- };
- var children = function(element) {
- return map(element.dom.childNodes, SugarElement.fromDom);
- };
- var spot = function(element, offset) {
- return {
- element,
- offset
- };
- };
- var leaf = function(element, offset) {
- var cs = children(element);
- return cs.length > 0 && offset < cs.length ? spot(cs[offset], 0) : spot(element, offset);
- };
- var before = function(marker, element) {
- var parent$1 = parent(marker);
- parent$1.each(function(v) {
- v.dom.insertBefore(element.dom, marker.dom);
- });
- };
- var append = function(parent2, element) {
- parent2.dom.appendChild(element.dom);
- };
- var wrap = function(element, wrapper) {
- before(element, wrapper);
- append(wrapper, element);
- };
- var NodeValue = function(is, name) {
- var get2 = function(element) {
- if (!is(element)) {
- throw new Error("Can only get " + name + " value of a " + name + " node");
- }
- return getOption(element).getOr("");
- };
- var getOption = function(element) {
- return is(element) ? Optional.from(element.dom.nodeValue) : Optional.none();
- };
- var set2 = function(element, value2) {
- if (!is(element)) {
- throw new Error("Can only set raw " + name + " value of a " + name + " node");
- }
- element.dom.nodeValue = value2;
- };
- return {
- get: get2,
- getOption,
- set: set2
- };
- };
- var api = NodeValue(isText$1, "text");
- var get$1 = function(element) {
- return api.get(element);
- };
- var descendants = function(scope, selector) {
- return all(selector, scope);
- };
- var global = tinymce.util.Tools.resolve("tinymce.dom.TreeWalker");
- var isSimpleBoundary = function(dom, node) {
- return dom.isBlock(node) || has(dom.schema.getShortEndedElements(), node.nodeName);
- };
- var isContentEditableFalse = function(dom, node) {
- return dom.getContentEditable(node) === "false";
- };
- var isContentEditableTrueInCef = function(dom, node) {
- return dom.getContentEditable(node) === "true" && dom.getContentEditableParent(node.parentNode) === "false";
- };
- var isHidden = function(dom, node) {
- return !dom.isBlock(node) && has(dom.schema.getWhiteSpaceElements(), node.nodeName);
- };
- var isBoundary = function(dom, node) {
- return isSimpleBoundary(dom, node) || isContentEditableFalse(dom, node) || isHidden(dom, node) || isContentEditableTrueInCef(dom, node);
- };
- var isText = function(node) {
- return node.nodeType === 3;
- };
- var nuSection = function() {
- return {
- sOffset: 0,
- fOffset: 0,
- elements: []
- };
- };
- var toLeaf = function(node, offset) {
- return leaf(SugarElement.fromDom(node), offset);
- };
- var walk = function(dom, walkerFn, startNode, callbacks, endNode, skipStart) {
- if (skipStart === void 0) {
- skipStart = true;
- }
- var next2 = skipStart ? walkerFn(false) : startNode;
- while (next2) {
- var isCefNode = isContentEditableFalse(dom, next2);
- if (isCefNode || isHidden(dom, next2)) {
- var stopWalking = isCefNode ? callbacks.cef(next2) : callbacks.boundary(next2);
- if (stopWalking) {
- break;
- } else {
- next2 = walkerFn(true);
- continue;
- }
- } else if (isSimpleBoundary(dom, next2)) {
- if (callbacks.boundary(next2)) {
- break;
- }
- } else if (isText(next2)) {
- callbacks.text(next2);
- }
- if (next2 === endNode) {
- break;
- } else {
- next2 = walkerFn(false);
- }
- }
- };
- var collectTextToBoundary = function(dom, section, node, rootNode, forwards) {
- if (isBoundary(dom, node)) {
- return;
- }
- var rootBlock = dom.getParent(rootNode, dom.isBlock);
- var walker = new global(node, rootBlock);
- var walkerFn = forwards ? walker.next.bind(walker) : walker.prev.bind(walker);
- walk(dom, walkerFn, node, {
- boundary: always,
- cef: always,
- text: function(next2) {
- if (forwards) {
- section.fOffset += next2.length;
- } else {
- section.sOffset += next2.length;
- }
- section.elements.push(SugarElement.fromDom(next2));
- }
- });
- };
- var collect = function(dom, rootNode, startNode, endNode, callbacks, skipStart) {
- if (skipStart === void 0) {
- skipStart = true;
- }
- var walker = new global(startNode, rootNode);
- var sections = [];
- var current = nuSection();
- collectTextToBoundary(dom, current, startNode, rootNode, false);
- var finishSection = function() {
- if (current.elements.length > 0) {
- sections.push(current);
- current = nuSection();
- }
- return false;
- };
- walk(dom, walker.next.bind(walker), startNode, {
- boundary: finishSection,
- cef: function(node) {
- finishSection();
- if (callbacks) {
- sections.push.apply(sections, callbacks.cef(node));
- }
- return false;
- },
- text: function(next2) {
- current.elements.push(SugarElement.fromDom(next2));
- if (callbacks) {
- callbacks.text(next2, current);
- }
- }
- }, endNode, skipStart);
- if (endNode) {
- collectTextToBoundary(dom, current, endNode, rootNode, true);
- }
- finishSection();
- return sections;
- };
- var collectRangeSections = function(dom, rng) {
- var start = toLeaf(rng.startContainer, rng.startOffset);
- var startNode = start.element.dom;
- var end = toLeaf(rng.endContainer, rng.endOffset);
- var endNode = end.element.dom;
- return collect(dom, rng.commonAncestorContainer, startNode, endNode, {
- text: function(node, section) {
- if (node === endNode) {
- section.fOffset += node.length - end.offset;
- } else if (node === startNode) {
- section.sOffset += start.offset;
- }
- },
- cef: function(node) {
- var sections = bind(descendants(SugarElement.fromDom(node), "*[contenteditable=true]"), function(e) {
- var ceTrueNode = e.dom;
- return collect(dom, ceTrueNode, ceTrueNode);
- });
- return sort(sections, function(a, b) {
- return documentPositionPreceding(a.elements[0].dom, b.elements[0].dom) ? 1 : -1;
- });
- }
- }, false);
- };
- var fromRng = function(dom, rng) {
- return rng.collapsed ? [] : collectRangeSections(dom, rng);
- };
- var fromNode = function(dom, node) {
- var rng = dom.createRng();
- rng.selectNode(node);
- return fromRng(dom, rng);
- };
- var fromNodes = function(dom, nodes) {
- return bind(nodes, function(node) {
- return fromNode(dom, node);
- });
- };
- var find$2 = function(text, pattern, start, finish) {
- if (start === void 0) {
- start = 0;
- }
- if (finish === void 0) {
- finish = text.length;
- }
- var regex = pattern.regex;
- regex.lastIndex = start;
- var results = [];
- var match;
- while (match = regex.exec(text)) {
- var matchedText = match[pattern.matchIndex];
- var matchStart = match.index + match[0].indexOf(matchedText);
- var matchFinish = matchStart + matchedText.length;
- if (matchFinish > finish) {
- break;
- }
- results.push({
- start: matchStart,
- finish: matchFinish
- });
- regex.lastIndex = matchFinish;
- }
- return results;
- };
- var extract = function(elements, matches) {
- var nodePositions = foldl(elements, function(acc, element) {
- var content = get$1(element);
- var start = acc.last;
- var finish = start + content.length;
- var positions = bind(matches, function(match, matchIdx) {
- if (match.start < finish && match.finish > start) {
- return [{
- element,
- start: Math.max(start, match.start) - start,
- finish: Math.min(finish, match.finish) - start,
- matchId: matchIdx
- }];
- } else {
- return [];
- }
- });
- return {
- results: acc.results.concat(positions),
- last: finish
- };
- }, {
- results: [],
- last: 0
- }).results;
- return groupBy(nodePositions, function(position) {
- return position.matchId;
- });
- };
- var find$1 = function(pattern, sections) {
- return bind(sections, function(section) {
- var elements = section.elements;
- var content = map(elements, get$1).join("");
- var positions = find$2(content, pattern, section.sOffset, content.length - section.fOffset);
- return extract(elements, positions);
- });
- };
- var mark = function(matches, replacementNode) {
- eachr(matches, function(match, idx) {
- eachr(match, function(pos) {
- var wrapper = SugarElement.fromDom(replacementNode.cloneNode(false));
- set(wrapper, "data-mce-index", idx);
- var textNode = pos.element.dom;
- if (textNode.length === pos.finish && pos.start === 0) {
- wrap(pos.element, wrapper);
- } else {
- if (textNode.length !== pos.finish) {
- textNode.splitText(pos.finish);
- }
- var matchNode = textNode.splitText(pos.start);
- wrap(SugarElement.fromDom(matchNode), wrapper);
- }
- });
- });
- };
- var findAndMark = function(dom, pattern, node, replacementNode) {
- var textSections = fromNode(dom, node);
- var matches = find$1(pattern, textSections);
- mark(matches, replacementNode);
- return matches.length;
- };
- var findAndMarkInSelection = function(dom, pattern, selection, replacementNode) {
- var bookmark = selection.getBookmark();
- var nodes = dom.select("td[data-mce-selected],th[data-mce-selected]");
- var textSections = nodes.length > 0 ? fromNodes(dom, nodes) : fromRng(dom, selection.getRng());
- var matches = find$1(pattern, textSections);
- mark(matches, replacementNode);
- selection.moveToBookmark(bookmark);
- return matches.length;
- };
- var getElmIndex = function(elm) {
- var value2 = elm.getAttribute("data-mce-index");
- if (typeof value2 === "number") {
- return "" + value2;
- }
- return value2;
- };
- var markAllMatches = function(editor, currentSearchState, pattern, inSelection) {
- var marker = editor.dom.create("span", { "data-mce-bogus": 1 });
- marker.className = "mce-match-marker";
- var node = editor.getBody();
- done(editor, currentSearchState, false);
- if (inSelection) {
- return findAndMarkInSelection(editor.dom, pattern, editor.selection, marker);
- } else {
- return findAndMark(editor.dom, pattern, node, marker);
- }
- };
- var unwrap = function(node) {
- var parentNode = node.parentNode;
- if (node.firstChild) {
- parentNode.insertBefore(node.firstChild, node);
- }
- node.parentNode.removeChild(node);
- };
- var findSpansByIndex = function(editor, index) {
- var spans = [];
- var nodes = global$1.toArray(editor.getBody().getElementsByTagName("span"));
- if (nodes.length) {
- for (var i = 0; i < nodes.length; i++) {
- var nodeIndex = getElmIndex(nodes[i]);
- if (nodeIndex === null || !nodeIndex.length) {
- continue;
- }
- if (nodeIndex === index.toString()) {
- spans.push(nodes[i]);
- }
- }
- }
- return spans;
- };
- var moveSelection = function(editor, currentSearchState, forward) {
- var searchState = currentSearchState.get();
- var testIndex = searchState.index;
- var dom = editor.dom;
- forward = forward !== false;
- if (forward) {
- if (testIndex + 1 === searchState.count) {
- testIndex = 0;
- } else {
- testIndex++;
- }
- } else {
- if (testIndex - 1 === -1) {
- testIndex = searchState.count - 1;
- } else {
- testIndex--;
- }
- }
- dom.removeClass(findSpansByIndex(editor, searchState.index), "mce-match-marker-selected");
- var spans = findSpansByIndex(editor, testIndex);
- if (spans.length) {
- dom.addClass(findSpansByIndex(editor, testIndex), "mce-match-marker-selected");
- editor.selection.scrollIntoView(spans[0]);
- return testIndex;
- }
- return -1;
- };
- var removeNode = function(dom, node) {
- var parent2 = node.parentNode;
- dom.remove(node);
- if (dom.isEmpty(parent2)) {
- dom.remove(parent2);
- }
- };
- var escapeSearchText = function(text, wholeWord) {
- var escapedText = text.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&").replace(/\s/g, "[^\\S\\r\\n\\uFEFF]");
- var wordRegex = "(" + escapedText + ")";
- return wholeWord ? "(?:^|\\s|" + punctuation() + ")" + wordRegex + ("(?=$|\\s|" + punctuation() + ")") : wordRegex;
- };
- var find = function(editor, currentSearchState, text, matchCase, wholeWord, inSelection) {
- var selection = editor.selection;
- var escapedText = escapeSearchText(text, wholeWord);
- var isForwardSelection = selection.isForward();
- var pattern = {
- regex: new RegExp(escapedText, matchCase ? "g" : "gi"),
- matchIndex: 1
- };
- var count = markAllMatches(editor, currentSearchState, pattern, inSelection);
- if (global$2.browser.isSafari()) {
- selection.setRng(selection.getRng(), isForwardSelection);
- }
- if (count) {
- var newIndex = moveSelection(editor, currentSearchState, true);
- currentSearchState.set({
- index: newIndex,
- count,
- text,
- matchCase,
- wholeWord,
- inSelection
- });
- }
- return count;
- };
- var next = function(editor, currentSearchState) {
- var index = moveSelection(editor, currentSearchState, true);
- currentSearchState.set(__assign(__assign({}, currentSearchState.get()), { index }));
- };
- var prev = function(editor, currentSearchState) {
- var index = moveSelection(editor, currentSearchState, false);
- currentSearchState.set(__assign(__assign({}, currentSearchState.get()), { index }));
- };
- var isMatchSpan = function(node) {
- var matchIndex = getElmIndex(node);
- return matchIndex !== null && matchIndex.length > 0;
- };
- var replace = function(editor, currentSearchState, text, forward, all2) {
- var searchState = currentSearchState.get();
- var currentIndex = searchState.index;
- var currentMatchIndex, nextIndex = currentIndex;
- forward = forward !== false;
- var node = editor.getBody();
- var nodes = global$1.grep(global$1.toArray(node.getElementsByTagName("span")), isMatchSpan);
- for (var i = 0; i < nodes.length; i++) {
- var nodeIndex = getElmIndex(nodes[i]);
- var matchIndex = currentMatchIndex = parseInt(nodeIndex, 10);
- if (all2 || matchIndex === searchState.index) {
- if (text.length) {
- nodes[i].firstChild.nodeValue = text;
- unwrap(nodes[i]);
- } else {
- removeNode(editor.dom, nodes[i]);
- }
- while (nodes[++i]) {
- matchIndex = parseInt(getElmIndex(nodes[i]), 10);
- if (matchIndex === currentMatchIndex) {
- removeNode(editor.dom, nodes[i]);
- } else {
- i--;
- break;
- }
- }
- if (forward) {
- nextIndex--;
- }
- } else if (currentMatchIndex > currentIndex) {
- nodes[i].setAttribute("data-mce-index", String(currentMatchIndex - 1));
- }
- }
- currentSearchState.set(__assign(__assign({}, searchState), {
- count: all2 ? 0 : searchState.count - 1,
- index: nextIndex
- }));
- if (forward) {
- next(editor, currentSearchState);
- } else {
- prev(editor, currentSearchState);
- }
- return !all2 && currentSearchState.get().count > 0;
- };
- var done = function(editor, currentSearchState, keepEditorSelection) {
- var startContainer, endContainer;
- var searchState = currentSearchState.get();
- var nodes = global$1.toArray(editor.getBody().getElementsByTagName("span"));
- for (var i = 0; i < nodes.length; i++) {
- var nodeIndex = getElmIndex(nodes[i]);
- if (nodeIndex !== null && nodeIndex.length) {
- if (nodeIndex === searchState.index.toString()) {
- if (!startContainer) {
- startContainer = nodes[i].firstChild;
- }
- endContainer = nodes[i].firstChild;
- }
- unwrap(nodes[i]);
- }
- }
- currentSearchState.set(__assign(__assign({}, searchState), {
- index: -1,
- count: 0,
- text: ""
- }));
- if (startContainer && endContainer) {
- var rng = editor.dom.createRng();
- rng.setStart(startContainer, 0);
- rng.setEnd(endContainer, endContainer.data.length);
- if (keepEditorSelection !== false) {
- editor.selection.setRng(rng);
- }
- return rng;
- }
- };
- var hasNext = function(editor, currentSearchState) {
- return currentSearchState.get().count > 1;
- };
- var hasPrev = function(editor, currentSearchState) {
- return currentSearchState.get().count > 1;
- };
- var get = function(editor, currentState) {
- var done$1 = function(keepEditorSelection) {
- return done(editor, currentState, keepEditorSelection);
- };
- var find$12 = function(text, matchCase, wholeWord, inSelection) {
- if (inSelection === void 0) {
- inSelection = false;
- }
- return find(editor, currentState, text, matchCase, wholeWord, inSelection);
- };
- var next$1 = function() {
- return next(editor, currentState);
- };
- var prev$1 = function() {
- return prev(editor, currentState);
- };
- var replace$1 = function(text, forward, all2) {
- return replace(editor, currentState, text, forward, all2);
- };
- return {
- done: done$1,
- find: find$12,
- next: next$1,
- prev: prev$1,
- replace: replace$1
- };
- };
- var singleton = function(doRevoke) {
- var subject = Cell(Optional.none());
- var revoke = function() {
- return subject.get().each(doRevoke);
- };
- var clear = function() {
- revoke();
- subject.set(Optional.none());
- };
- var isSet = function() {
- return subject.get().isSome();
- };
- var get2 = function() {
- return subject.get();
- };
- var set2 = function(s) {
- revoke();
- subject.set(Optional.some(s));
- };
- return {
- clear,
- isSet,
- get: get2,
- set: set2
- };
- };
- var value = function() {
- var subject = singleton(noop);
- var on = function(f) {
- return subject.get().each(f);
- };
- return __assign(__assign({}, subject), { on });
- };
- var open = function(editor, currentSearchState) {
- var dialogApi = value();
- editor.undoManager.add();
- var selectedText = global$1.trim(editor.selection.getContent({ format: "text" }));
- var updateButtonStates = function(api2) {
- var updateNext = hasNext(editor, currentSearchState) ? api2.enable : api2.disable;
- updateNext("next");
- var updatePrev = hasPrev(editor, currentSearchState) ? api2.enable : api2.disable;
- updatePrev("prev");
- };
- var updateSearchState = function(api2) {
- var data = api2.getData();
- var current = currentSearchState.get();
- currentSearchState.set(__assign(__assign({}, current), {
- matchCase: data.matchcase,
- wholeWord: data.wholewords,
- inSelection: data.inselection
- }));
- };
- var disableAll = function(api2, disable) {
- var buttons = [
- "replace",
- "replaceall",
- "prev",
- "next"
- ];
- var toggle = disable ? api2.disable : api2.enable;
- each(buttons, toggle);
- };
- var notFoundAlert = function(api2) {
- editor.windowManager.alert("Could not find the specified string.", function() {
- api2.focus("findtext");
- });
- };
- var focusButtonIfRequired = function(api2, name) {
- if (global$2.browser.isSafari() && global$2.deviceType.isTouch() && (name === "find" || name === "replace" || name === "replaceall")) {
- api2.focus(name);
- }
- };
- var reset = function(api2) {
- done(editor, currentSearchState, false);
- disableAll(api2, true);
- updateButtonStates(api2);
- };
- var doFind = function(api2) {
- var data = api2.getData();
- var last = currentSearchState.get();
- if (!data.findtext.length) {
- reset(api2);
- return;
- }
- if (last.text === data.findtext && last.matchCase === data.matchcase && last.wholeWord === data.wholewords) {
- next(editor, currentSearchState);
- } else {
- var count = find(editor, currentSearchState, data.findtext, data.matchcase, data.wholewords, data.inselection);
- if (count <= 0) {
- notFoundAlert(api2);
- }
- disableAll(api2, count === 0);
- }
- updateButtonStates(api2);
- };
- var initialState = currentSearchState.get();
- var initialData = {
- findtext: selectedText,
- replacetext: "",
- wholewords: initialState.wholeWord,
- matchcase: initialState.matchCase,
- inselection: initialState.inSelection
- };
- var spec = {
- title: "Find and Replace",
- size: "normal",
- body: {
- type: "panel",
- items: [
- {
- type: "bar",
- items: [
- {
- type: "input",
- name: "findtext",
- placeholder: "Find",
- maximized: true,
- inputMode: "search"
- },
- {
- type: "button",
- name: "prev",
- text: "Previous",
- icon: "action-prev",
- disabled: true,
- borderless: true
- },
- {
- type: "button",
- name: "next",
- text: "Next",
- icon: "action-next",
- disabled: true,
- borderless: true
- }
- ]
- },
- {
- type: "input",
- name: "replacetext",
- placeholder: "Replace with",
- inputMode: "search"
- }
- ]
- },
- buttons: [
- {
- type: "menu",
- name: "options",
- icon: "preferences",
- tooltip: "Preferences",
- align: "start",
- items: [
- {
- type: "togglemenuitem",
- name: "matchcase",
- text: "Match case"
- },
- {
- type: "togglemenuitem",
- name: "wholewords",
- text: "Find whole words only"
- },
- {
- type: "togglemenuitem",
- name: "inselection",
- text: "Find in selection"
- }
- ]
- },
- {
- type: "custom",
- name: "find",
- text: "Find",
- primary: true
- },
- {
- type: "custom",
- name: "replace",
- text: "Replace",
- disabled: true
- },
- {
- type: "custom",
- name: "replaceall",
- text: "Replace all",
- disabled: true
- }
- ],
- initialData,
- onChange: function(api2, details) {
- if (details.name === "findtext" && currentSearchState.get().count > 0) {
- reset(api2);
- }
- },
- onAction: function(api2, details) {
- var data = api2.getData();
- switch (details.name) {
- case "find":
- doFind(api2);
- break;
- case "replace":
- if (!replace(editor, currentSearchState, data.replacetext)) {
- reset(api2);
- } else {
- updateButtonStates(api2);
- }
- break;
- case "replaceall":
- replace(editor, currentSearchState, data.replacetext, true, true);
- reset(api2);
- break;
- case "prev":
- prev(editor, currentSearchState);
- updateButtonStates(api2);
- break;
- case "next":
- next(editor, currentSearchState);
- updateButtonStates(api2);
- break;
- case "matchcase":
- case "wholewords":
- case "inselection":
- updateSearchState(api2);
- reset(api2);
- break;
- }
- focusButtonIfRequired(api2, details.name);
- },
- onSubmit: function(api2) {
- doFind(api2);
- focusButtonIfRequired(api2, "find");
- },
- onClose: function() {
- editor.focus();
- done(editor, currentSearchState);
- editor.undoManager.add();
- }
- };
- dialogApi.set(editor.windowManager.open(spec, { inline: "toolbar" }));
- };
- var register$1 = function(editor, currentSearchState) {
- editor.addCommand("SearchReplace", function() {
- open(editor, currentSearchState);
- });
- };
- var showDialog = function(editor, currentSearchState) {
- return function() {
- open(editor, currentSearchState);
- };
- };
- var register = function(editor, currentSearchState) {
- editor.ui.registry.addMenuItem("searchreplace", {
- text: "Find and replace...",
- shortcut: "Meta+F",
- onAction: showDialog(editor, currentSearchState),
- icon: "search"
- });
- editor.ui.registry.addButton("searchreplace", {
- tooltip: "Find and replace",
- onAction: showDialog(editor, currentSearchState),
- icon: "search"
- });
- editor.shortcuts.add("Meta+F", "", showDialog(editor, currentSearchState));
- };
- function Plugin() {
- global$3.add("searchreplace", function(editor) {
- var currentSearchState = Cell({
- index: -1,
- count: 0,
- text: "",
- matchCase: false,
- wholeWord: false,
- inSelection: false
- });
- register$1(editor, currentSearchState);
- register(editor, currentSearchState);
- return get(editor, currentSearchState);
- });
- }
- Plugin();
- })();
- }
- });
- // node_modules/.pnpm/tinymce@5.10.7/node_modules/tinymce/plugins/searchreplace/index.js
- require_plugin();
- //# sourceMappingURL=tinymce_plugins_searchreplace.js.map
|