1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030 |
- import {
- $e,
- Ae,
- Fa,
- I1,
- _1,
- d3,
- h3,
- it,
- l1,
- m1,
- n1,
- o3
- } from "./chunk-POAJ2YNP.js";
- import {
- HO,
- Po,
- QC,
- QO,
- VO,
- WO,
- Xw,
- r_,
- um
- } from "./chunk-GBYP4PB2.js";
- import {
- L_
- } from "./chunk-2MK3Q52E.js";
- import {
- BehaviorSubject,
- Ct,
- Fe,
- Gn,
- J0,
- Mi,
- Ot,
- Pt,
- Ra,
- SE,
- Subject,
- Vr,
- W0,
- Ze,
- _n,
- ar,
- combineLatest,
- debounceTime,
- fromEvent,
- fs,
- map,
- nt,
- nu,
- oE,
- ot,
- takeUntil,
- throttleTime,
- z0
- } from "./chunk-23V3HWTR.js";
- import {
- require_react
- } from "./chunk-GNR2UJZM.js";
- import {
- __toESM
- } from "./chunk-2LSFTFF7.js";
- // node_modules/.pnpm/@univerjs+find-replace@0.5.5_@grpc+grpc-js@1.13.4_react-dom@18.3.1_react@18.3.1_rxjs@7.8.1_typescript@5.4.5/node_modules/@univerjs/find-replace/lib/es/index.js
- var import_react = __toESM(require_react());
- var at = Object.defineProperty;
- var ot2 = (t, e, n) => e in t ? at(t, e, { enumerable: true, configurable: true, writable: true, value: n }) : t[e] = n;
- var l = (t, e, n) => ot2(t, typeof e != "symbol" ? e + "" : e, n);
- var Nt = "find-replace.config";
- var de = {};
- var g = function() {
- return g = Object.assign || function(t) {
- for (var e, n = 1, i = arguments.length; n < i; n++) {
- e = arguments[n];
- for (var r in e)
- Object.prototype.hasOwnProperty.call(e, r) && (t[r] = e[r]);
- }
- return t;
- }, g.apply(this, arguments);
- };
- var $t = function(t, e) {
- var n = {};
- for (var i in t)
- Object.prototype.hasOwnProperty.call(t, i) && e.indexOf(i) < 0 && (n[i] = t[i]);
- if (t != null && typeof Object.getOwnPropertySymbols == "function")
- for (var r = 0, i = Object.getOwnPropertySymbols(t); r < i.length; r++)
- e.indexOf(i[r]) < 0 && Object.prototype.propertyIsEnumerable.call(t, i[r]) && (n[i[r]] = t[i[r]]);
- return n;
- };
- var xe = (0, import_react.forwardRef)(function(t, e) {
- var n = t.icon, i = t.id, r = t.className, s = t.extend, a = $t(t, ["icon", "id", "className", "extend"]), d = "univerjs-icon univerjs-icon-".concat(i, " ").concat(r || "").trim(), c = (0, import_react.useRef)("_".concat(jt()));
- return ye(n, "".concat(i), { defIds: n.defIds, idSuffix: c.current }, g({ ref: e, className: d }, a), s);
- });
- function ye(t, e, n, i, r) {
- return (0, import_react.createElement)(t.tag, g(g({ key: e }, At(t, n, r)), i), (Lt(t, n).children || []).map(function(s, a) {
- return ye(s, "".concat(e, "-").concat(t.tag, "-").concat(a), n, void 0, r);
- }));
- }
- function At(t, e, n) {
- var i = g({}, t.attrs);
- n != null && n.colorChannel1 && i.fill === "colorChannel1" && (i.fill = n.colorChannel1);
- var r = e.defIds;
- return !r || r.length === 0 || (t.tag === "use" && i["xlink:href"] && (i["xlink:href"] = i["xlink:href"] + e.idSuffix), Object.entries(i).forEach(function(s) {
- var a = s[0], d = s[1];
- typeof d == "string" && (i[a] = d.replace(/url\(#(.*)\)/, "url(#$1".concat(e.idSuffix, ")")));
- })), i;
- }
- function Lt(t, e) {
- var n, i = e.defIds;
- return !i || i.length === 0 ? t : t.tag === "defs" && (!((n = t.children) === null || n === void 0) && n.length) ? g(g({}, t), { children: t.children.map(function(r) {
- return typeof r.attrs.id == "string" && i && i.indexOf(r.attrs.id) > -1 ? g(g({}, r), { attrs: g(g({}, r.attrs), { id: r.attrs.id + e.idSuffix }) }) : r;
- }) }) : t;
- }
- function jt() {
- return Math.random().toString(36).substring(2, 8);
- }
- xe.displayName = "UniverIcon";
- var wt = { tag: "svg", attrs: { fill: "none", viewBox: "0 0 17 17", width: "1em", height: "1em" }, children: [{ tag: "mask", attrs: { id: "mask0_217_40", style: { maskType: "alpha" }, width: 17, height: 17, x: 0, y: 0, maskUnits: "userSpaceOnUse" }, children: [{ tag: "path", attrs: { fill: "#D9D9D9", d: "M0.9 0.09H16.9V16.09H0.9z" } }] }, { tag: "g", attrs: { mask: "url(#mask0_217_40)" }, children: [{ tag: "path", attrs: { fill: "currentColor", d: "M2.39551 7.37266C2.39551 4.18105 4.98281 1.59375 8.17441 1.59375C11.366 1.59375 13.9533 4.18105 13.9533 7.37266C13.9533 8.72342 13.4898 9.96603 12.7133 10.95L15.1964 13.4331C15.4619 13.6986 15.4619 14.1291 15.1964 14.3946C14.9309 14.6601 14.5004 14.6601 14.2349 14.3946L11.7518 11.9115C10.7678 12.6881 9.52525 13.1516 8.17441 13.1516C4.98281 13.1516 2.39551 10.5642 2.39551 7.37266ZM8.17441 2.95349C5.73378 2.95349 3.75525 4.93202 3.75525 7.37266C3.75525 9.81333 5.73378 11.7918 8.17441 11.7918C10.6151 11.7918 12.5936 9.81333 12.5936 7.37266C12.5936 4.93202 10.6151 2.95349 8.17441 2.95349Z", fillRule: "evenodd", clipRule: "evenodd" } }] }] };
- var Ie = (0, import_react.forwardRef)(function(t, e) {
- return (0, import_react.createElement)(xe, Object.assign({}, t, {
- id: "search-single-16",
- ref: e,
- icon: wt
- }));
- });
- Ie.displayName = "SearchSingle16";
- var Fe2 = "FIND_REPLACE_INPUT_FOCUS";
- var De = "FIND_REPLACE_DIALOG_FOCUS";
- var Pe = "FIND_REPLACE_REPLACE_REVEALED";
- var Ut = Object.defineProperty;
- var Bt = Object.getOwnPropertyDescriptor;
- var Oe = (t, e, n, i) => {
- for (var r = i > 1 ? void 0 : i ? Bt(e, n) : e, s = t.length - 1, a; s >= 0; s--)
- (a = t[s]) && (r = (i ? a(e, n, r) : a(r)) || r);
- return i && r && Ut(e, n, r), r;
- };
- var q = (t, e) => (n, i) => e(n, i, t);
- var Di = class extends nt {
- };
- var m = Ct("find-replace.service");
- function Wt(t) {
- return typeof t.findString < "u" || typeof t.inputtingFindString < "u" || typeof t.findDirection < "u" || typeof t.matchesTheWholeCell < "u" || typeof t.caseSensitive < "u" || typeof t.findScope < "u" || typeof t.findBy < "u";
- }
- var J = class extends nt {
- constructor(e, n, i) {
- super();
- l(this, "currentMatch$", new BehaviorSubject(null));
- l(this, "replaceables$", new BehaviorSubject([]));
- l(this, "_findModels", []);
- l(this, "_matchingModel", null);
- l(this, "_matches", []);
- l(this, "_currentSearchingDisposables", null);
- this._state = e, this._providers = n, this._univerInstanceService = i, this.disposeWithMe(
- this._state.stateUpdates$.pipe(throttleTime(200, void 0, { leading: true, trailing: true })).subscribe(async (r) => {
- const s = this._state.state;
- Wt(r) && (s.findString !== "" && !s.replaceRevealed ? (await this._startSearching(), this._state.changeState({ findCompleted: true })) : r.replaceRevealed !== true && this._stopSearching());
- })
- );
- }
- get searched() {
- return this._findModels.length > 0;
- }
- dispose() {
- super.dispose(), this._stopSearching(), this.currentMatch$.complete(), this.replaceables$.complete(), this._state.changeState({ ...ne(), revealed: false });
- }
- async start() {
- if (!this._state.findString)
- return { results: [] };
- const e = await this._startSearching();
- return this._state.changeState({ findCompleted: true }), e;
- }
- /** Call this method to start a `searching`. */
- async _startSearching() {
- if (!this._state.findString)
- return { results: [] };
- const e = Array.from(this._providers), n = this._findModels = (await Promise.all(e.map((r) => r.find({
- findString: this._state.findString,
- findDirection: this._state.findDirection,
- findScope: this._state.findScope,
- findBy: this._state.findBy,
- replaceRevealed: this._state.replaceRevealed,
- caseSensitive: this._state.caseSensitive,
- matchesTheWholeCell: this._state.matchesTheWholeCell
- })))).flat();
- this._subscribeToModelsChanges(n);
- const i = this._matches = n.map((r) => r.getMatches()).flat();
- return this.replaceables$.next(i.filter((r) => r.replaceable)), i.length ? (this._moveToInitialMatch(n), this._state.changeState({ matchesCount: i.length }), { results: i }) : (this._state.changeState({ matchesCount: 0, matchesPosition: 0 }), { results: [] });
- }
- /** Terminate the current searching session, when searching string is empty. */
- _stopSearching() {
- var e;
- this._providers.forEach((n) => n.terminate()), this._findModels = [], this._matches = [], this._matchingModel = null, (e = this._currentSearchingDisposables) == null || e.dispose(), this._currentSearchingDisposables = null, this.currentMatch$.next(null), this.replaceables$.next([]), this._state.changeState({
- findCompleted: false,
- matchesCount: 0,
- matchesPosition: 0
- });
- }
- // When a document's content changes, we should reset all matches and try to move to the next match.
- _subscribeToModelsChanges(e) {
- const n = this._currentSearchingDisposables = new Mi(), i = combineLatest(e.map((r) => r.matchesUpdate$)).pipe(debounceTime(220)).subscribe(([...r]) => {
- const s = this._matches = r.flat();
- s.length ? (this._moveToInitialMatch(this._findModels, true), this._state.changeState({ matchesCount: s.length }), this.replaceables$.next(s.filter((a) => a.replaceable))) : (this._state.changeState({ matchesCount: 0, matchesPosition: 0 }), this.replaceables$.next([]));
- });
- e.forEach((r) => n.add(Ze(r.activelyChangingMatch$.subscribe((s) => {
- const a = this._matches.findIndex((d) => d === s);
- this._state.changeState({ matchesPosition: a + 1 });
- })))), n.add(Ze(i));
- }
- async replace() {
- return this._matchingModel ? this._matchingModel.replace(this._state.replaceString) : false;
- }
- async replaceAll() {
- const e = await Promise.all(this._findModels.map((n) => n.replaceAll(this._state.replaceString))).then((n) => n.reduce((i, r) => (i.success += r.success, i.failure += r.failure, i), { success: 0, failure: 0 }));
- return e.failure === 0 && this._stopSearching(), e;
- }
- getCurrentMatch() {
- return this._state.matchesPosition > 0 ? this._matches[this._state.matchesPosition - 1] : null;
- }
- _markMatch(e) {
- const n = this._matches.findIndex((i) => i === e);
- this.currentMatch$.next(e), this._state.changeState({ matchesPosition: n + 1 });
- }
- moveToNextMatch() {
- if (!this._matchingModel)
- return;
- const e = this._findModels.length === 1, n = this._matchingModel.moveToNextMatch({ loop: e });
- if (n)
- return this._markMatch(n), n;
- {
- const i = this._findModels.findIndex((r) => r === this._matchingModel);
- return this._moveToNextUnitMatch(i);
- }
- }
- _moveToNextUnitMatch(e) {
- const n = this._findModels.length;
- for (let i = (e + 1) % n; i !== e; ) {
- const r = this._findModels[i], s = r.moveToNextMatch({ ignoreSelection: true });
- if (s)
- return this._matchingModel = r, this._markMatch(s), s;
- i = (i + 1) % n;
- }
- if (this._matchingModel) {
- const i = this._matchingModel.moveToNextMatch({ ignoreSelection: true });
- return i && this._markMatch(i), i;
- }
- }
- moveToPreviousMatch() {
- if (!this._matchingModel)
- return;
- const e = this._findModels.length === 1, n = this._matchingModel.moveToPreviousMatch({ loop: e });
- if (n) {
- const i = this._matches.findIndex((r) => r === n);
- return this.currentMatch$.next(n), this._state.changeState({ matchesPosition: i + 1 }), n;
- } else {
- const i = this._findModels.length, r = this._findModels.findIndex((a) => a === this._matchingModel);
- for (let a = (r - 1 + i) % i; a !== r; ) {
- const d = this._findModels[a], c = d.moveToPreviousMatch({ ignoreSelection: true });
- if (c)
- return this._matchingModel = d, this._markMatch(c), c;
- a = (a - 1) % i;
- }
- const s = this._matchingModel.moveToPreviousMatch({ ignoreSelection: true });
- return s && this._markMatch(s), s;
- }
- }
- _moveToInitialMatch(e, n = false) {
- var s;
- const i = (s = this._univerInstanceService.getFocusedUnit()) == null ? void 0 : s.getUnitId();
- if (!i)
- return -1;
- const r = e.findIndex((a) => a.unitId === i);
- if (r !== -1) {
- this._matchingModel = e[r];
- const a = this._matchingModel.moveToNextMatch({ stayIfOnMatch: true, noFocus: n });
- if (a)
- return this._markMatch(a), r;
- }
- return this._moveToNextUnitMatch(r), 0;
- }
- };
- J = Oe([
- q(2, _n)
- ], J);
- var K = ((t) => (t.ROW = "row", t.COLUMN = "column", t))(K || {});
- var z = ((t) => (t.VALUE = "value", t.FORMULA = "formula", t))(z || {});
- var Y = ((t) => (t.SUBUNIT = "subunit", t.UNIT = "unit", t))(Y || {});
- function ne() {
- return {
- caseSensitive: false,
- findBy: "value",
- findCompleted: false,
- findDirection: "row",
- findScope: "subunit",
- findString: "",
- inputtingFindString: "",
- matchesCount: 0,
- matchesPosition: 0,
- matchesTheWholeCell: false,
- replaceRevealed: false,
- replaceString: "",
- revealed: true
- };
- }
- var Gt = class {
- constructor() {
- l(this, "_stateUpdates$", new Subject());
- l(this, "stateUpdates$", this._stateUpdates$.asObservable());
- l(this, "_state$", new BehaviorSubject(ne()));
- l(this, "state$", this._state$.asObservable());
- l(this, "_findString", "");
- l(this, "_inputtingFindString", "");
- l(this, "_replaceString", "");
- l(this, "_revealed", false);
- l(this, "_replaceRevealed", false);
- l(this, "_matchesPosition", 0);
- l(this, "_matchesCount", 0);
- l(this, "_caseSensitive", true);
- l(this, "_matchesTheWholeCell", false);
- l(this, "_findDirection", "row");
- l(this, "_findScope", "subunit");
- l(this, "_findBy", "value");
- l(this, "_findCompleted", false);
- }
- get state() {
- return this._state$.getValue();
- }
- get inputtingFindString() {
- return this._inputtingFindString;
- }
- get findString() {
- return this._findString;
- }
- get revealed() {
- return this._revealed;
- }
- get replaceRevealed() {
- return this._replaceRevealed;
- }
- get matchesPosition() {
- return this._matchesPosition;
- }
- get matchesCount() {
- return this._matchesCount;
- }
- get replaceString() {
- return this._replaceString;
- }
- get caseSensitive() {
- return this._caseSensitive;
- }
- get matchesTheWholeCell() {
- return this._matchesTheWholeCell;
- }
- get findDirection() {
- return this._findDirection;
- }
- get findScope() {
- return this._findScope;
- }
- get findBy() {
- return this._findBy;
- }
- get findCompleted() {
- return this._findCompleted;
- }
- // eslint-disable-next-line max-lines-per-function, complexity
- changeState(e) {
- let n = false;
- const i = {};
- typeof e.findString < "u" && e.findString !== this._findString && (this._findString = e.findString, i.findString = this._findString, n = true), typeof e.revealed < "u" && e.revealed !== this._revealed && (this._revealed = e.revealed, i.revealed = e.revealed, n = true), typeof e.replaceRevealed < "u" && e.replaceRevealed !== this._replaceRevealed && (this._replaceRevealed = e.replaceRevealed, i.replaceRevealed = e.replaceRevealed, n = true), typeof e.replaceString < "u" && e.replaceString !== this._replaceString && (this._replaceString = e.replaceString, i.replaceString = e.replaceString, n = true), typeof e.matchesCount < "u" && e.matchesCount !== this._matchesCount && (this._matchesCount = e.matchesCount, i.matchesCount = e.matchesCount, n = true), typeof e.matchesPosition < "u" && e.matchesPosition !== this._matchesPosition && (this._matchesPosition = e.matchesPosition, i.matchesPosition = e.matchesPosition, n = true), typeof e.findBy < "u" && e.findBy !== this._findBy && (this._findBy = e.findBy, i.findBy = e.findBy, n = true), typeof e.findScope < "u" && e.findScope !== this._findScope && (this._findScope = e.findScope, i.findScope = e.findScope, n = true), typeof e.findDirection < "u" && e.findDirection !== this._findDirection && (this._findDirection = e.findDirection, i.findDirection = e.findDirection, n = true), typeof e.caseSensitive < "u" && e.caseSensitive !== this._caseSensitive && (this._caseSensitive = e.caseSensitive, i.caseSensitive = e.caseSensitive, n = true), typeof e.matchesTheWholeCell < "u" && e.matchesTheWholeCell !== this._matchesTheWholeCell && (this._matchesTheWholeCell = e.matchesTheWholeCell, i.matchesTheWholeCell = e.matchesTheWholeCell, n = true), typeof e.inputtingFindString < "u" && e.inputtingFindString !== this._inputtingFindString && (this._inputtingFindString = e.inputtingFindString, i.inputtingFindString = e.inputtingFindString, n = true), typeof e.findCompleted < "u" && e.findCompleted !== this._findCompleted && (this._findCompleted = e.findCompleted, i.findCompleted = e.findCompleted, n = true), n && (this._state$.next({
- caseSensitive: this._caseSensitive,
- findBy: this._findBy,
- findCompleted: this._findCompleted,
- findDirection: this._findDirection,
- findScope: this._findScope,
- findString: this._findString,
- inputtingFindString: this._inputtingFindString,
- matchesCount: this._matchesCount,
- matchesPosition: this._matchesPosition,
- matchesTheWholeCell: this._matchesTheWholeCell,
- replaceRevealed: this._replaceRevealed,
- revealed: this._revealed
- }), this._stateUpdates$.next(i));
- }
- };
- var Z = class extends nt {
- constructor(e, n) {
- super();
- l(this, "_providers", /* @__PURE__ */ new Set());
- l(this, "_state", new Gt());
- l(this, "_model");
- l(this, "_currentMatch$", new BehaviorSubject(null));
- l(this, "currentMatch$", this._currentMatch$.asObservable());
- l(this, "_replaceables$", new BehaviorSubject([]));
- l(this, "replaceables$", this._replaceables$.asObservable());
- l(this, "_focusSignal$", new Subject());
- l(this, "focusSignal$", this._focusSignal$.asObservable());
- this._injector = e, this._contextService = n;
- }
- get stateUpdates$() {
- return this._state.stateUpdates$;
- }
- get state$() {
- return this._state.state$;
- }
- get revealed() {
- return this._state.revealed;
- }
- get replaceRevealed() {
- return this._state.replaceRevealed;
- }
- dispose() {
- super.dispose(), this._currentMatch$.next(null), this._currentMatch$.complete(), this._replaceables$.next([]), this._replaceables$.complete(), this._focusSignal$.complete();
- }
- getProviders() {
- return this._providers;
- }
- getCurrentMatch() {
- var e;
- return (e = this._model) == null ? void 0 : e.getCurrentMatch();
- }
- getFindString() {
- return this._state.findString;
- }
- changeFindString(e) {
- this._state.changeState({ findString: e });
- }
- focusFindInput() {
- this._focusSignal$.next();
- }
- changeInputtingFindString(e) {
- e ? this._state.changeState({ inputtingFindString: e }) : this._state.changeState({ inputtingFindString: "", findString: "" });
- }
- changeReplaceString(e) {
- this._state.changeState({ replaceString: e });
- }
- changeMatchesTheWholeCell(e) {
- this._state.changeState({ matchesTheWholeCell: e });
- }
- changeCaseSensitive(e) {
- this._state.changeState({ caseSensitive: e });
- }
- changeFindBy(e) {
- this._state.changeState({ findBy: e }), this._toggleDisplayRawFormula(
- e === "formula"
- /* FORMULA */
- );
- }
- changeFindScope(e) {
- this._state.changeState({ findScope: e });
- }
- changeFindDirection(e) {
- this._state.changeState({ findDirection: e });
- }
- moveToNextMatch() {
- this._model && (this._state.replaceRevealed && !this._model.searched ? (this._state.changeState({ findString: this._state.inputtingFindString }), this._model.start()) : this._model.moveToNextMatch(), this._focusSignal$.next());
- }
- moveToPreviousMatch() {
- this._model && (this._state.replaceRevealed && !this._model.searched ? (this._state.changeState({ findString: this._state.inputtingFindString }), this._model.start()) : this._model.moveToPreviousMatch(), this._focusSignal$.next());
- }
- async replace() {
- return this._model ? this._model.replace() : false;
- }
- async replaceAll() {
- if (!this._model)
- throw new Error("[FindReplaceService] replaceAll: model is not initialized!");
- return this._model.replaceAll();
- }
- revealReplace() {
- this._state.changeState({ replaceRevealed: true, inputtingFindString: this._state.findString }), this._toggleRevealReplace(true);
- }
- start(e = false) {
- if (this._providers.size === 0)
- return false;
- this._model = this._injector.createInstance(J, this._state, this._providers), this._model.currentMatch$.subscribe((i) => this._currentMatch$.next(i)), this._model.replaceables$.subscribe((i) => this._replaceables$.next(i));
- const n = ne();
- return e && (n.replaceRevealed = true), this._state.changeState(n), this._toggleRevealReplace(e), true;
- }
- find() {
- var e;
- (e = this._model) == null || e.start();
- }
- terminate() {
- var e;
- (e = this._model) == null || e.dispose(), this._model = null, this._toggleDisplayRawFormula(false), this._toggleRevealReplace(false);
- }
- registerFindReplaceProvider(e) {
- return this._providers.add(e), Ze(() => this._providers.delete(e));
- }
- _toggleRevealReplace(e) {
- this._contextService.setContextValue(Pe, e);
- }
- _toggleDisplayRawFormula(e) {
- this._contextService.setContextValue(L_, e);
- }
- };
- Z = Oe([
- q(0, ot(Ot)),
- q(1, fs)
- ], Z);
- var Te = {
- id: "ui.command.replace-current-match",
- type: ar.COMMAND,
- handler: (t) => t.get(m).replace()
- };
- var kt = "CONFIRM_REPLACE_ALL";
- var Ee = {
- id: "ui.command.replace-all-matches",
- type: ar.COMMAND,
- handler: async (t) => {
- const e = t.get(d3), n = t.get(Vr), i = t.get(o3);
- if (!await e.confirm({
- id: kt,
- title: { title: n.t("find-replace.replace.confirm.title") },
- cancelText: n.t("button.cancel"),
- confirmText: n.t("button.confirm")
- }))
- return false;
- const s = await t.get(m).replaceAll(), { success: a, failure: d } = s;
- return d > 0 ? (a === 0 ? i.show({
- type: Xw.Error,
- content: n.t("find-replace.replace.all-failure")
- }) : i.show({
- type: Xw.Warning,
- content: n.t("find-replace.replace.partial-success", `${a}`, `${d}`)
- }), false) : (i.show({
- type: Xw.Success,
- content: n.t("find-replace.replace.all-success", `${a}`)
- }), true);
- }
- };
- var O = {
- id: "ui.operation.open-find-dialog",
- type: ar.OPERATION,
- handler: (t) => {
- const e = t.get(m);
- return e.revealed ? e.focusFindInput() : e.start(), true;
- }
- };
- var re = {
- id: "ui.operation.open-replace-dialog",
- type: ar.OPERATION,
- handler: (t) => {
- const e = t.get(m);
- return e.revealed ? e.replaceRevealed ? e.focusFindInput() : e.revealReplace() : e.start(true), true;
- }
- };
- var Ne = {
- type: ar.OPERATION,
- id: "ui.operation.go-to-next-match",
- handler: (t) => (t.get(m).moveToNextMatch(), true)
- };
- var $e2 = {
- type: ar.OPERATION,
- id: "ui.operation.go-to-previous-match",
- handler: (t) => (t.get(m).moveToPreviousMatch(), true)
- };
- var k = { exports: {} };
- var I = {};
- var ue;
- function Vt() {
- if (ue)
- return I;
- ue = 1;
- var t = import_react.default, e = Symbol.for("react.element"), n = Symbol.for("react.fragment"), i = Object.prototype.hasOwnProperty, r = t.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner, s = { key: true, ref: true, __self: true, __source: true };
- function a(d, c, _) {
- var u, h = {}, R = null, v = null;
- _ !== void 0 && (R = "" + _), c.key !== void 0 && (R = "" + c.key), c.ref !== void 0 && (v = c.ref);
- for (u in c)
- i.call(c, u) && !s.hasOwnProperty(u) && (h[u] = c[u]);
- if (d && d.defaultProps)
- for (u in c = d.defaultProps, c)
- h[u] === void 0 && (h[u] = c[u]);
- return { $$typeof: e, type: d, key: R, ref: v, props: h, _owner: r.current };
- }
- return I.Fragment = n, I.jsx = a, I.jsxs = a, I;
- }
- var he;
- function Ht() {
- return he || (he = 1, k.exports = Vt()), k.exports;
- }
- var o = Ht();
- var qt = "univer-find-replace-dialog-container";
- var Jt = "univer-find-replace-expand-container";
- var Kt = "univer-button-text";
- var zt = "univer-find-replace-buttons-group";
- var Yt = "univer-find-replace-buttons-group-right";
- var L = {
- findReplaceDialogContainer: qt,
- findReplaceExpandContainer: Jt,
- buttonText: Kt,
- findReplaceButtonsGroup: zt,
- findReplaceButtonsGroupRight: Yt
- };
- function Ae2(t) {
- const { findCompleted: e, localeService: n, matchesCount: i, matchesPosition: r, findString: s, findReplaceService: a, onChange: d, ...c } = t, u = e && i === 0 ? n.t("find-replace.dialog.no-result") : i === 0 ? " " : void 0;
- return o.jsx(
- WO,
- {
- autoFocus: true,
- placeholder: n.t("find-replace.dialog.find-placeholder"),
- slot: o.jsx(
- QO,
- {
- loop: true,
- text: u,
- value: r,
- total: i,
- onChange: (h) => {
- r === i && h === 1 ? a.moveToNextMatch() : r === 1 && h === i || h < r ? a.moveToPreviousMatch() : a.moveToNextMatch();
- }
- }
- ),
- value: s,
- onChange: (h) => d == null ? void 0 : d(h),
- ...c
- }
- );
- }
- function Le(t, e) {
- const n = (0, import_react.useCallback)(() => {
- var r;
- (r = document.querySelector(".univer-find-input input")) == null || r.focus();
- }, []), i = (0, import_react.useCallback)(() => {
- const r = document.querySelectorAll(".univer-find-replace-dialog-container .univer-select-selection-search-input");
- return Array.from(r).some((s) => s === document.activeElement);
- }, []);
- return (0, import_react.useImperativeHandle)(e, () => ({ focus: n, selectHasFocus: i })), (0, import_react.useEffect)(() => {
- const r = t.focusSignal$.subscribe(() => n());
- return () => r.unsubscribe();
- }, [t, n]), { focus: n, selectHasFocus: i };
- }
- var Zt = (0, import_react.forwardRef)(function(e, n) {
- const i = W0(Vr), r = W0(m), s = W0(Pt), a = z0(r.state$, void 0, true), { findCompleted: d, findString: c, matchesCount: _, matchesPosition: u } = a, h = (0, import_react.useCallback)(() => {
- s.executeCommand(re.id);
- }, [s]), R = (0, import_react.useCallback)((v) => r.changeFindString(v), [r]);
- return Le(r, n), o.jsxs(o.Fragment, { children: [
- o.jsx(
- Ae2,
- {
- findCompleted: d,
- className: "univer-find-input",
- matchesCount: _,
- matchesPosition: u,
- findReplaceService: r,
- localeService: i,
- findString: c,
- onChange: R
- }
- ),
- o.jsx("div", { className: L.findReplaceExpandContainer, children: o.jsx(Po, { type: "text", size: "small", onClick: h, children: i.t("find-replace.dialog.advanced-finding") }) })
- ] });
- });
- var Qt = (0, import_react.forwardRef)(function(e, n) {
- const i = W0(m), r = W0(Vr), s = W0(Pt), a = W0(o3), d = z0(i.currentMatch$, void 0, true), c = z0(i.replaceables$, void 0, true), _ = z0(i.state$, void 0, true), {
- matchesCount: u,
- matchesPosition: h,
- findString: R,
- inputtingFindString: v,
- replaceString: Ue,
- caseSensitive: Be,
- matchesTheWholeCell: We,
- findDirection: Ge,
- findScope: ke,
- findBy: Ve,
- findCompleted: W
- } = _, He = v.length === 0, qe = u === 0 || !(d != null && d.replaceable), Je = c.length === 0, Ke = (0, import_react.useCallback)(
- (f) => i.changeInputtingFindString(f),
- [i]
- ), ze = (0, import_react.useCallback)(
- (f) => i.changeReplaceString(f),
- [i]
- ), { focus: Ye } = Le(i, n), Ze2 = (0, import_react.useCallback)(() => {
- R === v ? i.moveToNextMatch() : (i.changeFindString(v), i.find());
- }, [R, v, i]), Qe = (0, import_react.useCallback)(() => s.executeCommand(Te.id), [s]), Xe = (0, import_react.useCallback)(async () => {
- await s.executeCommand(Ee.id), Ye();
- }, [s]), et = (0, import_react.useCallback)((f) => {
- i.changeFindDirection(f);
- }, [i]), tt = (0, import_react.useCallback)((f) => {
- i.changeFindScope(f);
- }, [i]), it2 = (0, import_react.useCallback)((f) => {
- i.changeFindBy(f);
- }, [i]), nt2 = ei(r), rt = ti(r), st = ii(r);
- return (0, import_react.useEffect)(() => {
- W && u === 0 && a.show({
- content: r.t("find-replace.dialog.no-match"),
- type: Xw.Warning,
- duration: 5e3
- });
- }, [W, u, a, r]), o.jsxs(o.Fragment, { children: [
- o.jsx(HO, { label: r.t("find-replace.dialog.find"), children: o.jsx(
- Ae2,
- {
- findCompleted: W,
- className: "univer-find-input",
- matchesCount: u,
- matchesPosition: h,
- findReplaceService: i,
- localeService: r,
- findString: v,
- onChange: Ke
- }
- ) }),
- o.jsx(HO, { label: r.t("find-replace.dialog.replace"), children: o.jsx(
- QC,
- {
- placeholder: r.t("find-replace.dialog.replace-placeholder"),
- value: Ue,
- onChange: (f) => ze(f)
- }
- ) }),
- o.jsx(HO, { label: r.t("find-replace.dialog.find-direction.title"), children: o.jsx(r_, { value: Ge, options: rt, onChange: et }) }),
- o.jsx(VO, { children: o.jsxs(o.Fragment, { children: [
- o.jsx(HO, { label: r.t("find-replace.dialog.find-scope.title"), children: o.jsx(r_, { value: ke, options: nt2, onChange: tt }) }),
- o.jsx(HO, { label: r.t("find-replace.dialog.find-by.title"), children: o.jsx(r_, { value: Ve, options: st, onChange: it2 }) })
- ] }) }),
- o.jsx(VO, { children: o.jsxs(o.Fragment, { children: [
- o.jsx(HO, { children: o.jsx(
- um,
- {
- checked: Be,
- onChange: (f) => {
- i.changeCaseSensitive(f);
- },
- children: r.t("find-replace.dialog.case-sensitive")
- }
- ) }),
- o.jsx(HO, { children: o.jsx(
- um,
- {
- checked: We,
- onChange: (f) => {
- i.changeMatchesTheWholeCell(f);
- },
- children: r.t("find-replace.dialog.match-the-whole-cell")
- }
- ) })
- ] }) }),
- o.jsxs("div", { className: L.findReplaceButtonsGroup, children: [
- o.jsx(Po, { type: "primary", onClick: Ze2, disabled: He, children: r.t("find-replace.dialog.find") }),
- o.jsxs("span", { className: L.findReplaceButtonsGroupRight, children: [
- o.jsx(Po, { disabled: qe, onClick: Qe, children: r.t("find-replace.dialog.replace") }),
- o.jsx(Po, { disabled: Je, onClick: Xe, children: r.t("find-replace.dialog.replace-all") })
- ] })
- ] })
- ] });
- });
- function Xt() {
- const t = W0(m), e = W0(_1), n = W0(fs), i = z0(t.state$, void 0, true), r = (0, import_react.useRef)(null);
- (0, import_react.useEffect)(() => {
- let c;
- return r.current && (c = e.registerContainerElement(r.current)), () => c == null ? void 0 : c.dispose();
- }, [e]);
- const s = (0, import_react.useRef)(null), a = (0, import_react.useCallback)(
- (c) => n.setContextValue(De, c),
- [n]
- ), d = (0, import_react.useCallback)(
- (c) => n.setContextValue(Fe2, c),
- [n]
- );
- return (0, import_react.useEffect)(() => {
- var _;
- const c = fromEvent(document, "focusin").subscribe((u) => {
- var h;
- u.target && ((h = r.current) != null && h.contains(u.target)) ? a(true) : a(false), !s.current || !s.current.selectHasFocus() ? d(true) : d(false);
- });
- return (_ = s.current) == null || _.focus(), a(true), d(true), () => {
- c.unsubscribe(), a(false);
- };
- }, [a, d]), o.jsx("div", { className: L.findReplaceDialogContainer, ref: r, children: i.replaceRevealed ? o.jsx(Qt, { ref: s }) : o.jsx(Zt, { ref: s }) });
- }
- function ei(t) {
- const e = t.getCurrentLocale();
- return (0, import_react.useMemo)(() => [
- { label: t.t("find-replace.dialog.find-scope.current-sheet"), value: Y.SUBUNIT },
- { label: t.t("find-replace.dialog.find-scope.workbook"), value: Y.UNIT }
- ], [e]);
- }
- function ti(t) {
- const e = t.getCurrentLocale();
- return (0, import_react.useMemo)(() => [
- { label: t.t("find-replace.dialog.find-direction.row"), value: K.ROW },
- { label: t.t("find-replace.dialog.find-direction.column"), value: K.COLUMN }
- ], [e]);
- }
- function ii(t) {
- const e = t.getCurrentLocale();
- return (0, import_react.useMemo)(() => [
- { label: t.t("find-replace.dialog.find-by.value"), value: z.VALUE },
- { label: t.t("find-replace.dialog.find-by.formula"), value: z.FORMULA }
- ], [e]);
- }
- function T(t) {
- return t.getContextValue(De);
- }
- function ni(t) {
- return t.getContextValue(Pe);
- }
- function je(t) {
- return t.getContextValue(Fe2);
- }
- var B = "7_find-replace-shortcuts";
- function se(t) {
- return t.getContextValue(Gn);
- }
- function ae(t) {
- return !t.getContextValue(oE);
- }
- var ri = {
- id: O.id,
- description: "find-replace.shortcut.open-find-dialog",
- binding: I1.F | Ae.CTRL_COMMAND,
- group: B,
- preconditions(t) {
- return !T(t) && se(t) && ae(t);
- }
- };
- var si = {
- id: O.id,
- description: "find-replace.shortcut.open-find-dialog",
- binding: I1.F | Ae.CTRL_COMMAND,
- mac: I1.F | Ae.MAC_CTRL,
- preconditions(t) {
- return !T(t) && se(t) && ae(t);
- }
- };
- var ai = {
- id: re.id,
- description: "find-replace.shortcut.open-replace-dialog",
- binding: I1.H | Ae.CTRL_COMMAND,
- mac: I1.H | Ae.MAC_CTRL,
- group: B,
- preconditions(t) {
- return se(t) && ae(t) && (!T(t) || !ni(t));
- }
- };
- var oi = {
- id: Ne.id,
- description: "find-replace.shortcut.go-to-next-match",
- binding: I1.ENTER,
- group: B,
- priority: 1e3,
- preconditions(t) {
- return je(t) && T(t);
- }
- };
- var ci = {
- id: $e2.id,
- description: "find-replace.shortcut.go-to-previous-match",
- binding: I1.ENTER | Ae.SHIFT,
- group: B,
- priority: 1e3,
- preconditions(t) {
- return je(t) && T(t);
- }
- };
- function li(t) {
- const e = t.get(fs);
- return {
- id: O.id,
- icon: "SearchIcon",
- tooltip: "find-replace.toolbar",
- type: $e.BUTTON,
- hidden$: Fa(t, Fe.UNIVER_SHEET),
- disabled$: combineLatest([
- e.subscribeContextValue$(oE),
- e.subscribeContextValue$(Gn)
- ]).pipe(map(([n, i]) => n || !i))
- };
- }
- var di = {
- [l1.OTHERS]: {
- [O.id]: {
- order: 2,
- menuItemFactory: li
- }
- }
- };
- var ui = Object.defineProperty;
- var hi = Object.getOwnPropertyDescriptor;
- var fi = (t, e, n, i) => {
- for (var r = i > 1 ? void 0 : i ? hi(e, n) : e, s = t.length - 1, a; s >= 0; s--)
- (a = t[s]) && (r = (i ? a(e, n, r) : a(r)) || r);
- return i && r && ui(e, n, r), r;
- };
- var S = (t, e) => (n, i) => e(n, i, t);
- var fe = "DESKTOP_FIND_REPLACE_DIALOG";
- var we = 350;
- var pi = 20;
- var _i = -90;
- var j = class extends J0 {
- constructor(e, n, i, r, s, a, d, c, _, u) {
- super();
- l(this, "_closingListenerDisposable");
- this._univerInstanceService = e, this._menuManagerService = n, this._shortcutService = i, this._commandService = r, this._findReplaceService = s, this._dialogService = a, this._layoutService = d, this._localeService = c, this._componentManager = _, this._injector = u, this._initCommands(), this._initUI(), this._initShortcuts();
- }
- dispose() {
- var e;
- super.dispose(), (e = this._closingListenerDisposable) == null || e.dispose(), this._closingListenerDisposable = null;
- }
- _initCommands() {
- [
- O,
- re,
- Ne,
- $e2,
- Ee,
- Te
- ].forEach((e) => {
- this.disposeWithMe(this._commandService.registerCommand(e));
- });
- }
- _initShortcuts() {
- [
- ai,
- ri,
- si,
- ci,
- oi
- ].forEach((e) => this.disposeWithMe(this._shortcutService.registerShortcut(e)));
- }
- _initUI() {
- this.disposeWithMe(this._componentManager.register("FindReplaceDialog", Xt)), this.disposeWithMe(this._componentManager.register("SearchIcon", Ie)), this._menuManagerService.mergeMenu(di), this._findReplaceService.stateUpdates$.pipe(takeUntil(this.dispose$)).subscribe((e) => {
- e.revealed === true && this._openPanel();
- });
- }
- _openPanel() {
- this._dialogService.open({
- id: fe,
- draggable: true,
- width: we,
- title: { title: this._localeService.t("find-replace.dialog.title") },
- children: { label: "FindReplaceDialog" },
- destroyOnClose: true,
- defaultPosition: gi(),
- preservePositionOnDestroy: true,
- onClose: () => this.closePanel()
- }), this._closingListenerDisposable = Ze(this._univerInstanceService.focused$.pipe(takeUntil(this.dispose$)).subscribe((e) => {
- (!e || !this._univerInstanceService.getUniverSheetInstance(e)) && this.closePanel();
- }));
- }
- closePanel() {
- this._closingListenerDisposable && (this._closingListenerDisposable.dispose(), this._closingListenerDisposable = null, this._dialogService.close(fe), this._findReplaceService.terminate(), queueMicrotask(() => this._layoutService.focus()));
- }
- };
- j = fi([
- S(0, _n),
- S(1, m1),
- S(2, it),
- S(3, Pt),
- S(4, m),
- S(5, h3),
- S(6, _1),
- S(7, ot(Vr)),
- S(8, ot(n1)),
- S(9, ot(Ot))
- ], j);
- function gi() {
- const { innerWidth: t } = window;
- return { x: (t - we) / 2 - pi, y: _i };
- }
- var mi = Object.defineProperty;
- var vi = Object.getOwnPropertyDescriptor;
- var Si = (t, e, n, i) => {
- for (var r = i > 1 ? void 0 : i ? vi(e, n) : e, s = t.length - 1, a; s >= 0; s--)
- (a = t[s]) && (r = (i ? a(e, n, r) : a(r)) || r);
- return i && r && mi(e, n, r), r;
- };
- var pe = (t, e) => (n, i) => e(n, i, t);
- var Ci = "UNIVER_FIND_REPLACE_PLUGIN";
- var V;
- var _e = (V = class extends Ra {
- constructor(t = de, e, n) {
- super(), this._config = t, this._injector = e, this._configService = n;
- const { ...i } = nu(
- {},
- de,
- this._config
- );
- this._configService.setConfig(Nt, i);
- }
- onStarting() {
- [
- [j],
- [m, { useClass: Z }]
- ].forEach((t) => this._injector.add(t));
- }
- onRendered() {
- this._injector.get(j);
- }
- }, l(V, "pluginName", Ci), V);
- _e = Si([
- pe(1, ot(Ot)),
- pe(2, SE)
- ], _e);
- export {
- Di,
- m,
- J,
- K,
- z,
- Y,
- ne,
- Gt,
- Te,
- Ee,
- O,
- re,
- Ne,
- $e2 as $e,
- j,
- _e
- };
- /*! Bundled license information:
- @univerjs/find-replace/lib/es/index.js:
- (**
- * @license React
- * react-jsx-runtime.production.min.js
- *
- * Copyright (c) Facebook, Inc. and its affiliates.
- *
- * This source code is licensed under the MIT license found in the
- * LICENSE file in the root directory of this source tree.
- *)
- */
- //# sourceMappingURL=chunk-NND5TVYZ.js.map
|