123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690 |
- import {
- Nu,
- me,
- of,
- pn
- } from "./chunk-T4NNB5UY.js";
- import {
- Ar,
- F,
- Wn,
- an,
- on,
- re as re2
- } from "./chunk-BW43Z7N3.js";
- import "./chunk-QRYBFJ3R.js";
- import "./chunk-MIOQ566M.js";
- import {
- Di,
- K,
- Y,
- _e,
- j,
- m,
- z
- } from "./chunk-NND5TVYZ.js";
- import "./chunk-POAJ2YNP.js";
- import "./chunk-GBYP4PB2.js";
- import "./chunk-PZD7N4BC.js";
- import {
- A1,
- L_,
- Yx,
- q3
- } from "./chunk-2MK3Q52E.js";
- import "./chunk-BSDDCPAW.js";
- import "./chunk-QG2HZMYH.js";
- import {
- D0,
- Fe,
- Gf,
- M0,
- NR,
- Nt,
- OR,
- Ot,
- Pt,
- Ra,
- SE,
- Subject,
- _n,
- ar,
- cn,
- debounceTime,
- en,
- filter,
- fs,
- kt,
- merge,
- ml,
- nt,
- nu,
- oE,
- ot,
- re,
- skip,
- throttleTime
- } from "./chunk-23V3HWTR.js";
- import "./chunk-GNR2UJZM.js";
- import "./chunk-2LSFTFF7.js";
- // node_modules/.pnpm/@univerjs+sheets-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/sheets-find-replace/lib/es/index.js
- var fe = Object.defineProperty;
- var ge = (h, e, t) => e in h ? fe(h, e, { enumerable: true, configurable: true, writable: true, value: t }) : h[e] = t;
- var g = (h, e, t) => ge(h, typeof e != "symbol" ? e + "" : e, t);
- var Ye = "sheets-find-replace.config";
- var G = {};
- var ne = {
- id: "sheet.command.replace",
- type: ar.COMMAND,
- handler: async (h, e) => {
- const t = h.get(cn), i = h.get(Pt), { unitId: n, replacements: r } = e, s = t.__tempBatchingUndoRedo(n), o = await Promise.all(r.map((c) => i.executeCommand(on.id, {
- unitId: n,
- subUnitId: c.subUnitId,
- value: c.value
- })));
- return s.dispose(), Ke(o, r);
- }
- };
- function Ke(h, e) {
- let t = 0, i = 0;
- return h.forEach((n, r) => {
- const s = e[r].count;
- n ? t += s : i += s;
- }), { success: t, failure: i };
- }
- var Qe = class extends q3 {
- constructor(t, i) {
- super(t, i);
- g(this, "_activated", false);
- g(this, "_inHiddenRange", false);
- g(this, "_color");
- i && this.setShapeProps(i);
- }
- setShapeProps(t) {
- this._activated = !!t.activated, typeof t.inHiddenRange < "u" && (this._inHiddenRange = t.inHiddenRange), typeof t.color < "u" && (this._color = t.color), this.transformByState({
- width: t.width,
- height: t.height
- });
- }
- _draw(t) {
- const i = this._activated, n = `rgba(${this._color.r}, ${this._color.g}, ${this._color.b}, 0.35)`, r = `rgb(${this._color.r}, ${this._color.g}, ${this._color.b})`;
- A1.drawWith(t, {
- width: this.width,
- height: this.height,
- fill: n,
- stroke: i ? r : void 0,
- strokeWidth: i ? 2 : 0,
- evented: false
- });
- }
- };
- function Y2(h, e) {
- return h.startRow === e.startRow && h.startColumn === e.startColumn;
- }
- function K2(h, e) {
- return h.startRow < e.startRow || h.startRow === e.startRow && h.startColumn <= e.startColumn;
- }
- function Q(h, e) {
- return h.startColumn < e.startColumn || h.startColumn === e.startColumn && h.startRow <= e.startRow;
- }
- function Xe(h, e) {
- return h.startRow > e.startRow || h.startRow === e.startRow && h.startColumn >= e.startColumn;
- }
- function ze(h, e) {
- return h.startColumn > e.startColumn || h.startColumn === e.startColumn && h.startRow >= e.startRow;
- }
- function Je(h, e) {
- const { range: t } = h, { startRow: i, startColumn: n } = t, r = e.getMergedCell(i, n);
- return r ? en.equals(t, r) : t.endRow === t.startRow && t.endColumn === t.startColumn;
- }
- var Ze = Object.defineProperty;
- var qe = Object.getOwnPropertyDescriptor;
- var E = (h, e, t, i) => {
- for (var n = i > 1 ? void 0 : i ? qe(e, t) : e, r = h.length - 1, s; r >= 0; r--)
- (s = h[r]) && (n = (i ? s(e, t, n) : s(n)) || n);
- return i && n && Ze(e, t, n), n;
- };
- var m2 = (h, e) => (t, i) => e(t, i, h);
- var M = class extends nt {
- constructor(e, t, i, n, r) {
- super();
- g(this, "_provider");
- this._injector = e, this._findReplaceController = t, this._contextService = i, this._findReplaceService = n, this._commandService = r, this._init(), this._initCommands();
- }
- dispose() {
- super.dispose(), this._findReplaceController.closePanel(), this._provider.dispose();
- }
- _init() {
- const e = this._injector.createInstance(F2);
- this._provider = e, this.disposeWithMe(this._findReplaceService.registerFindReplaceProvider(e)), this.disposeWithMe(this._contextService.subscribeContextValue$(oE).pipe(filter((t) => !!t)).subscribe(() => this._findReplaceController.closePanel()));
- }
- _initCommands() {
- [ne].forEach((e) => this.disposeWithMe(this._commandService.registerCommand(e)));
- }
- };
- M = E([
- m2(0, ot(Ot)),
- m2(1, ot(j)),
- m2(2, fs),
- m2(3, m),
- m2(4, Pt)
- ], M);
- var et = "sheets-find-replace-provider";
- var tt = 1e4;
- var W = class extends Di {
- constructor(e, t, i, n, r, s, o, c) {
- super();
- g(this, "_matchesUpdate$", new Subject());
- g(this, "matchesUpdate$", this._matchesUpdate$.asObservable());
- g(this, "_activelyChangingMatch$", new Subject());
- g(this, "activelyChangingMatch$", this._activelyChangingMatch$.asObservable());
- g(this, "_matchesByWorksheet", /* @__PURE__ */ new Map());
- g(this, "_matches", []);
- g(this, "_matchesPosition", 0);
- g(this, "_activeHighlightIndex", -1);
- g(this, "_highlightShapes", []);
- g(this, "_currentHighlightShape", null);
- g(this, "_query", null);
- g(this, "_workbookSelections");
- this._workbook = e, this._sheetSkeletonManagerService = t, this._univerInstanceService = i, this._renderManagerService = n, this._commandService = r, this._contextService = s, this._themeService = o, this._workbookSelections = c.getWorkbookSelections(this.unitId);
- }
- get _matchesCount() {
- return this._matches.length;
- }
- get unitId() {
- return this._workbook.getUnitId();
- }
- get matchesCount() {
- return this._matchesCount;
- }
- get matchesPosition() {
- return this._matchesPosition;
- }
- get currentMatch() {
- return this._matchesPosition > 0 ? this._matches[this._matchesPosition - 1] : null;
- }
- dispose() {
- super.dispose(), this._disposeHighlights(), this._toggleDisplayRawFormula(false);
- }
- getMatches() {
- return this._matches;
- }
- start(e) {
- switch (this._query = e, e.findBy === z.FORMULA ? this._toggleDisplayRawFormula(true) : this._toggleDisplayRawFormula(false), e.findScope) {
- case Y.UNIT:
- this.findInWorkbook(e);
- break;
- case Y.SUBUNIT:
- default:
- this.findInActiveWorksheet(e);
- break;
- }
- }
- _toggleDisplayRawFormula(e) {
- this._contextService.setContextValue(L_, e);
- }
- /**
- * Find all matches in the current workbook no matter which worksheet is activated.
- * @param query the query object
- * @returns the query complete event
- */
- findInWorkbook(e) {
- const t = this._workbook.getUnitId();
- let i, n = true;
- const r = () => {
- const s = this._workbook.getSheets().filter((o) => !o.isSheetHidden()).map((o) => {
- const c = this._findInWorksheet(o, e, t), l = o.getSheetId(), { results: a } = c;
- return a.length ? this._matchesByWorksheet.set(l, c.results) : this._matchesByWorksheet.delete(l), c;
- });
- this._matches = s.map((o) => o.results).flat(), this._updateFindHighlight(), n ? (i = { results: this._matches }, n = false) : this._matchesUpdate$.next(this._matches);
- };
- return this.disposeWithMe(this._sheetSkeletonManagerService.currentSkeleton$.subscribe(() => {
- this._updateFindHighlight(), this._updateCurrentHighlightShape(this._activeHighlightIndex);
- })), this.disposeWithMe(
- Gf(this._commandService.onCommandExecuted.bind(this._commandService)).pipe(filter(([s, o]) => s.id === an.id && !(o != null && o.fromFindReplace))).subscribe(() => {
- const s = this._workbook.getActiveSheet();
- if (!s)
- return;
- const o = s.getSheetId();
- this._matchesByWorksheet.has(o) && this._findNextMatchOnActiveSheetChange(s);
- })
- ), this.disposeWithMe(
- Gf(this._commandService.onCommandExecuted.bind(this._commandService)).pipe(
- filter(
- ([s]) => s.type === ar.MUTATION && s.params.unitId === this._workbook.getUnitId()
- ),
- throttleTime(600, void 0, { leading: false, trailing: true })
- ).subscribe(() => r())
- ), r(), i;
- }
- /**
- * This method is used in `findInWorkbook`. When the active sheet changes, this method helps to find the next match
- * in the new worksheet.
- */
- _findNextMatchOnActiveSheetChange(e) {
- let t, i, n = 0;
- const r = this._matchesByWorksheet.get(e.getSheetId()), s = this._workbookSelections.getCurrentSelections();
- s != null && s.length ? ([t, n] = this._findNextMatchByRange(r, s[0].range), i = r.findIndex((o) => o === t)) : (t = r[0], i = 0, n = this._matches.findIndex((o) => o === t)), this._matchesPosition = n + 1, this._activelyChangingMatch$.next(t), this._activeHighlightIndex = i, this._updateFindHighlight(), this._updateCurrentHighlightShape(i);
- }
- /**
- * Find all matches (only) in the currently activated worksheet.
- * @param query the query object
- * @returns the query complete event
- */
- findInActiveWorksheet(e) {
- const t = this._workbook.getUnitId(), i = () => {
- var d;
- const c = this._workbook.getActiveSheet();
- if (!c)
- return false;
- const l = this._workbookSelections.getCurrentSelections();
- return (d = l == null ? void 0 : l.some((u) => !Je(u, c))) != null ? d : false;
- };
- let n, r = true, s = false;
- const o = () => {
- const c = this._workbook.getActiveSheet();
- if (!c)
- return { results: [] };
- const l = this.currentMatch;
- s = i();
- const a = this._workbookSelections.getCurrentSelections(), d = s ? this._findInSelections(c, a, e, t) : this._findInWorksheet(c, e, t);
- return this._matches = d.results, this._matchesPosition = this._tryRestoreLastMatchesPosition(l, this._matches), r ? (n = d, r = false) : this._matchesUpdate$.next(this._matches), this._updateFindHighlight(), d;
- };
- return this.disposeWithMe(this._sheetSkeletonManagerService.currentSkeleton$.subscribe(() => this._updateFindHighlight())), this.disposeWithMe(
- merge(
- Gf(this._commandService.onCommandExecuted.bind(this._commandService)).pipe(
- filter(([c]) => {
- if (c.type === ar.MUTATION && c.params.unitId === this._workbook.getUnitId())
- return true;
- if (c.id === re2.id && c.params.unitId === t) {
- const l = i();
- return l === false && s === false ? false : (s = l, true);
- }
- return false;
- })
- ),
- // activeSheet$ is a BehaviorSubject, so we need to skip the first
- this._workbook.activeSheet$.pipe(skip(1))
- ).pipe(debounceTime(200)).subscribe(() => o())
- ), o(), n;
- }
- _findInRange(e, t, i, n, r) {
- const s = [], o = e.getSheetId(), c = (t.findDirection === K.COLUMN ? e.iterateByColumn : e.iterateByRow).bind(e)(i);
- for (const l of c) {
- const { row: a, col: d, colSpan: u, rowSpan: _, value: S } = l;
- if (r != null && r(a, d) || !S || e.getRowFiltered(a))
- continue;
- const { hit: p, replaceable: R, isFormula: I } = it(e, a, d, t, S);
- if (p) {
- const y = {
- provider: et,
- unitId: n,
- replaceable: R,
- isFormula: I,
- range: {
- subUnitId: o,
- range: {
- startRow: a,
- startColumn: d,
- endColumn: d + (u != null ? u : 1) - 1,
- endRow: a + (_ != null ? _ : 1) - 1
- }
- }
- };
- s.push(y);
- }
- }
- return { results: s };
- }
- _findInSelections(e, t, i, n) {
- const { findDirection: r } = i, s = r === K.ROW ? K2 : Q, o = /* @__PURE__ */ new Set();
- return { results: t.map((l) => this._findInRange(
- e,
- i,
- l.range,
- n,
- (a, d) => {
- const u = `${a}-${d}`;
- return o.has(u) ? true : (o.add(u), false);
- }
- ).results).flat().sort((l, a) => s(l.range.range, a.range.range) ? -1 : 1) };
- }
- /** Find matches in a given worksheet. */
- _findInWorksheet(e, t, i) {
- const n = e.getRowCount(), r = e.getColumnCount(), s = { startRow: 0, startColumn: 0, endRow: n - 1, endColumn: r - 1 };
- return this._findInRange(e, t, s, i);
- }
- _disposeHighlights() {
- var e;
- this._highlightShapes.forEach((t) => {
- var i;
- (i = t.getScene()) == null || i.makeDirty(), t.dispose();
- }), this._highlightShapes = [], (e = this._currentHighlightShape) == null || e.dispose(), this._currentHighlightShape = null;
- }
- _updateFindHighlight() {
- var d;
- this._disposeHighlights();
- const e = (d = this._sheetSkeletonManagerService.getCurrent()) == null ? void 0 : d.skeleton;
- if (!e)
- return;
- const t = this._workbook.getUnitId(), i = this._renderManagerService.getRenderById(t);
- if (i == null)
- return;
- const { scene: n } = i, r = this._matches, s = this._themeService.getCurrentTheme().gold400, o = new Nt(s).toRgb(), c = this._workbook.getActiveSheet();
- if (!c)
- return;
- const l = c.getSheetId(), a = r.filter((u) => u.range.subUnitId === l).map((u, _) => {
- const { startColumn: S, startRow: p, endColumn: R, endRow: I } = u.range.range, y = Nu(p, S, n, e), oe = Nu(I, R, n, e), { startX: O, startY: A } = y, { endX: he, endY: ce } = oe, N = !c.getRowRawVisible(p), D = !c.getColVisible(S), ae = N || D, le = D ? 2 : he - O, de = N ? 2 : ce - A, ue = {
- left: O,
- top: A,
- color: o,
- width: le,
- height: de,
- evented: false,
- inHiddenRange: ae,
- zIndex: tt
- };
- return new Qe(`find-highlight-${_}`, ue);
- });
- n.addObjects(a), this._highlightShapes = a, n.makeDirty();
- }
- _updateCurrentHighlightShape(e) {
- var t;
- if ((t = this._currentHighlightShape) == null || t.setShapeProps({ activated: false }), this._currentHighlightShape = null, e !== void 0) {
- const i = this._highlightShapes[e];
- if (!i)
- return;
- this._currentHighlightShape = i, i.setShapeProps({ activated: true });
- }
- }
- _getSheetObject() {
- return pn(this._univerInstanceService, this._renderManagerService);
- }
- _focusMatch(e) {
- var i;
- const t = e.range.subUnitId;
- t !== ((i = this._workbook.getActiveSheet()) == null ? void 0 : i.getSheetId()) && this._commandService.executeCommand(
- Ar.id,
- { unitId: this._workbook.getUnitId(), subUnitId: t },
- { fromFindReplace: true }
- ), this._commandService.executeCommand(
- of.id,
- { range: e.range.range },
- { fromFindReplace: true }
- );
- }
- _tryRestoreLastMatchesPosition(e, t) {
- if (!e)
- return 0;
- const { subUnitId: i } = e.range, { startColumn: n, startRow: r } = e.range.range, s = t.findIndex((o) => {
- if (i !== o.range.subUnitId)
- return false;
- const { startColumn: c, startRow: l } = o.range.range;
- return c === n && l === r;
- });
- return s > -1 ? s + 1 : 0;
- }
- moveToNextMatch(e) {
- var o, c, l, a, d;
- if (!this._matches.length)
- return null;
- const t = (o = e == null ? void 0 : e.loop) != null ? o : false, i = (c = e == null ? void 0 : e.stayIfOnMatch) != null ? c : false, n = (l = e == null ? void 0 : e.noFocus) != null ? l : false, r = (a = e == null ? void 0 : e.ignoreSelection) != null ? a : false, s = this._findNextMatch(t, i, r);
- if (s) {
- const [u, _] = s;
- return this._matchesPosition = _ + 1, this._query.findScope === Y.UNIT ? this._activeHighlightIndex = this._matchesByWorksheet.get(u.range.subUnitId).findIndex((S) => S === u) : this._activeHighlightIndex = _, n || this._focusMatch(u), ((d = this._workbook.getActiveSheet()) == null ? void 0 : d.getSheetId()) === u.range.subUnitId && this._updateCurrentHighlightShape(this._activeHighlightIndex), u;
- }
- return this._matchesPosition = 0, this._updateCurrentHighlightShape(), null;
- }
- moveToPreviousMatch(e) {
- var o, c, l, a, d;
- if (!this._matches.length)
- return null;
- const t = (o = e == null ? void 0 : e.loop) != null ? o : false, i = (c = e == null ? void 0 : e.stayIfOnMatch) != null ? c : false, n = (l = e == null ? void 0 : e.noFocus) != null ? l : false, r = (a = e == null ? void 0 : e.ignoreSelection) != null ? a : false, s = this._findPreviousMatch(t, i, r);
- if (s) {
- const [u, _] = s;
- return this._matchesPosition = _ + 1, this._query.findScope === Y.UNIT ? this._activeHighlightIndex = this._matchesByWorksheet.get(u.range.subUnitId).findIndex((S) => S === u) : this._activeHighlightIndex = _, n || this._focusMatch(u), ((d = this._workbook.getActiveSheet()) == null ? void 0 : d.getSheetId()) === u.range.subUnitId && this._updateCurrentHighlightShape(this._activeHighlightIndex), u;
- }
- return this._matchesPosition = 0, this._updateCurrentHighlightShape(), null;
- }
- _findPreviousMatch(e = false, t = false, i = false) {
- var o;
- if (this.currentMatch) {
- const c = this._matches.findIndex((u) => u === this.currentMatch);
- if (t)
- return [this.currentMatch, c];
- const l = c - 1;
- if (!e && l < 0)
- return null;
- const a = this._matches.length, d = (l + a) % a;
- return [this._matches[d], d];
- }
- const n = this._workbookSelections.getCurrentLastSelection();
- if (i || !n) {
- const c = this._matches.length - 1;
- return [this._matches[c], c];
- }
- if (this._query.findScope !== Y.UNIT)
- return this._findPreviousMatchByRange(this._matches, n.range);
- const r = (o = this._workbook.getActiveSheet()) == null ? void 0 : o.getSheetId();
- if (!r)
- return null;
- const s = this._findPreviousWorksheetThatHasAMatch(r, e);
- return s ? this._findPreviousMatchByRange(this._matchesByWorksheet.get(s), n.range) : null;
- }
- _findNextMatch(e = false, t = false, i = false) {
- var o;
- if (this.currentMatch) {
- const c = this._matches.findIndex((u) => u === this.currentMatch);
- if (t)
- return [this.currentMatch, c];
- const l = c + 1, a = this._matches.length;
- if (!e && l >= a)
- return null;
- const d = l % a;
- return [this._matches[d], d];
- }
- const n = this._workbookSelections.getCurrentLastSelection();
- if (i || !n)
- return [this._matches[0], 0];
- if (this._query.findScope !== Y.UNIT)
- return this._findNextMatchByRange(this._matches, n.range, t);
- const r = (o = this._workbook.getActiveSheet()) == null ? void 0 : o.getSheetId();
- if (!r)
- return null;
- const s = this._findNextWorksheetThatHasAMatch(r, e);
- return s ? this._findNextMatchByRange(this._matchesByWorksheet.get(s), n.range) : null;
- }
- _findPreviousWorksheetThatHasAMatch(e, t = false) {
- const i = this._workbook.getSheetOrders(), n = i.findIndex((o) => o === e), s = (t ? M0(i, n + 1) : i.slice(0, n + 1)).findLast((o) => this._matchesByWorksheet.has(o));
- return s != null ? s : null;
- }
- _findNextWorksheetThatHasAMatch(e, t = false) {
- const i = this._workbook.getSheetOrders(), n = i.findIndex((o) => o === e), s = (t ? M0(i, n) : i.slice(n)).find((o) => this._matchesByWorksheet.has(o));
- return s != null ? s : null;
- }
- _findNextMatchByRange(e, t, i = false) {
- const n = this._query.findDirection === K.ROW;
- let r = e.findIndex((o) => {
- const c = o.range.range;
- if (!(n ? K2(t, c) : Q(t, c)))
- return false;
- const a = Y2(t, c);
- return i ? a : !a;
- });
- r === -1 && (r = e.length - 1);
- const s = e[r];
- return [s, this._matches.findIndex((o) => o === s)];
- }
- _findPreviousMatchByRange(e, t, i = false) {
- const n = this._query.findDirection === K.ROW;
- let r = this._matches.findLastIndex((o) => {
- const c = o.range.range;
- if (!(n ? Xe(t, c) : ze(t, c)))
- return false;
- const a = Y2(t, c);
- return i ? a : !a;
- });
- r === -1 && (r = 0);
- const s = e[r];
- return [s, this._matches.findIndex((o) => o === s)];
- }
- async replace(e) {
- if (this._matchesCount === 0 || !this.currentMatch || !this._query || !this.currentMatch.replaceable)
- return false;
- const t = this.currentMatch.range, i = this._workbook.getSheetBySheetId(this.currentMatch.range.subUnitId), n = this._getReplacedCellData(
- this.currentMatch,
- i,
- this._query.findBy === z.FORMULA,
- this._query.findString,
- e,
- this._query.caseSensitive ? "g" : "ig"
- ), r = {
- unitId: this.currentMatch.unitId,
- subUnitId: t.subUnitId,
- value: {
- [t.range.startRow]: {
- [t.range.startColumn]: n
- }
- }
- };
- return this._commandService.executeCommand(on.id, r);
- }
- async replaceAll(e) {
- if (this._matchesCount === 0 || !this._query)
- return { success: 0, failure: 0 };
- const t = this._workbook.getUnitId(), { findString: i, caseSensitive: n, findBy: r } = this._query, s = r === z.FORMULA, o = n ? "g" : "ig", c = [];
- return D0(this._matches.filter((a) => a.replaceable), (a) => a.range.subUnitId).forEach((a, d) => {
- const u = new kt(), _ = this._workbook.getSheetBySheetId(d);
- a.forEach((S) => {
- const { startColumn: p, startRow: R } = S.range.range, I = this._getReplacedCellData(S, _, s, i, e, o);
- I && u.setValue(R, p, I);
- }), c.push({
- count: a.length,
- subUnitId: d,
- value: u.getMatrix()
- });
- }), c ? this._commandService.executeCommand(ne.id, {
- unitId: t,
- replacements: c
- }) : { success: 0, failure: 0 };
- }
- _getReplacedCellData(e, t, i, n, r, s) {
- var _;
- const o = e.range.range, { startRow: c, startColumn: l } = o, a = t.getCellRaw(c, l);
- if (e.isFormula)
- return i ? { f: a.f.replace(new RegExp(X(n), s), r), v: null } : null;
- if (!!((_ = a.p) != null && _.body)) {
- const S = re.deepClone(a.p);
- return NR(S.body, n, r, this._query.caseSensitive), { p: S };
- }
- return { v: a.v.toString().replace(new RegExp(X(n), s), r) };
- }
- };
- W = E([
- m2(2, _n),
- m2(3, Yx),
- m2(4, Pt),
- m2(5, fs),
- m2(6, ot(ml)),
- m2(7, ot(F))
- ], W);
- function X(h) {
- return h.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
- }
- var F2 = class extends nt {
- constructor(e, t, i) {
- super();
- g(this, "_findModelsByUnitId", /* @__PURE__ */ new Map());
- this._univerInstanceService = e, this._renderManagerService = t, this._injector = i;
- }
- async find(e) {
- this._terminate();
- const t = this._univerInstanceService.getAllUnitsForType(Fe.UNIVER_SHEET), i = this._preprocessQuery(e);
- return t.map((r) => {
- const s = this._renderManagerService.getRenderById(r.getUnitId()).with(me), o = this._injector.createInstance(W, r, s);
- return this._findModelsByUnitId.set(r.getUnitId(), o), o.start(i), o;
- });
- }
- terminate() {
- this._terminate();
- }
- _terminate() {
- this._findModelsByUnitId.forEach((e) => e.dispose()), this._findModelsByUnitId.clear();
- }
- /**
- * Parsed the query object before do actual searching in favor of performance.
- * @param query the raw query object
- * @returns the parsed query object
- */
- _preprocessQuery(e) {
- let t = e.caseSensitive ? e.findString : e.findString.toLowerCase();
- return t = t.trim(), {
- ...e,
- findString: t
- };
- }
- };
- F2 = E([
- m2(0, _n),
- m2(1, Yx),
- m2(2, ot(Ot))
- ], F2);
- var f = { hit: false, replaceable: false, isFormula: false, rawData: null };
- function it(h, e, t, i, n) {
- const { findBy: r } = i, s = r === z.FORMULA, o = h.getCellRaw(e, t);
- return f.rawData = o, !(o != null && o.f) ? (f.isFormula = false, U(n, i) ? o ? (f.hit = true, f.replaceable = true) : (f.hit = true, f.replaceable = false) : (f.hit = false, f.replaceable = false), f) : (f.isFormula = true, s ? U({ v: o.f }, i) ? (f.hit = true, f.replaceable = true, f) : (f.hit = false, f.replaceable = false, f) : (f.replaceable = false, U(n, i) ? f.hit = true : f.hit = false, f));
- }
- function U(h, e) {
- let t = nt2(h);
- return t ? e.matchesTheWholeCell ? (t = st(t), e.caseSensitive ? t === e.findString : t.toLowerCase() === e.findString) : e.caseSensitive ? t.indexOf(e.findString) > -1 : t.toLowerCase().indexOf(e.findString) > -1 : false;
- }
- function nt2(h) {
- var t, i, n;
- const e = (n = (i = (t = h == null ? void 0 : h.p) == null ? void 0 : t.body) == null ? void 0 : i.dataStream) != null ? n : h == null ? void 0 : h.v;
- return typeof e == "number" ? `${e}` : typeof e == "boolean" ? e ? "1" : "0" : e;
- }
- function st(h) {
- return h.replace(/^ +/g, "").replace(/ +$/g, "");
- }
- var se = Object.defineProperty;
- var rt = Object.getOwnPropertyDescriptor;
- var ot2 = (h, e, t) => e in h ? se(h, e, { enumerable: true, configurable: true, writable: true, value: t }) : h[e] = t;
- var ht = (h, e, t, i) => {
- for (var n = i > 1 ? void 0 : i ? rt(e, t) : e, r = h.length - 1, s; r >= 0; r--)
- (s = h[r]) && (n = (i ? s(e, t, n) : s(n)) || n);
- return i && n && se(e, t, n), n;
- };
- var z2 = (h, e) => (t, i) => e(t, i, h);
- var re3 = (h, e, t) => ot2(h, typeof e != "symbol" ? e + "" : e, t);
- var ct = "SHEET_FIND_REPLACE_PLUGIN";
- var x = class extends Ra {
- constructor(h = G, e, t) {
- super(), this._config = h, this._injector = e, this._configService = t;
- const { ...i } = nu(
- {},
- G,
- this._config
- );
- this._configService.setConfig(Ye, i);
- }
- onStarting() {
- [[M]].forEach((h) => this._injector.add(h));
- }
- onSteady() {
- this._injector.get(M);
- }
- };
- re3(x, "pluginName", ct);
- re3(x, "type", Fe.UNIVER_SHEET);
- x = ht([
- OR(Wn, Wn, _e),
- z2(1, ot(Ot)),
- z2(2, SE)
- ], x);
- export {
- ne as SheetReplaceCommand,
- M as SheetsFindReplaceController,
- x as UniverSheetsFindReplacePlugin
- };
- //# sourceMappingURL=@univerjs_sheets-find-replace.js.map
|