@univerjs/sheets-find-replace 1.0.0-alpha.8 → 1.0.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/facade.js +2 -2
- package/lib/cjs/index.js +16 -21
- package/lib/es/facade.js +2 -2
- package/lib/es/index.js +16 -21
- package/lib/facade.js +2 -2
- package/lib/index.js +16 -21
- package/lib/umd/facade.js +1 -1
- package/lib/umd/index.js +1 -1
- package/package.json +7 -7
package/lib/cjs/facade.js
CHANGED
|
@@ -135,12 +135,12 @@ let FTextFinder = class FTextFinder extends _univerjs_core.Disposable {
|
|
|
135
135
|
return this;
|
|
136
136
|
}
|
|
137
137
|
async replaceAllWithAsync(replaceText) {
|
|
138
|
-
var _await$this$_model$re,
|
|
138
|
+
var _await$this$_model$re, _this$_model4;
|
|
139
139
|
await this._state.changeState({
|
|
140
140
|
replaceRevealed: true,
|
|
141
141
|
replaceString: replaceText
|
|
142
142
|
});
|
|
143
|
-
const res = (_await$this$_model$re =
|
|
143
|
+
const res = ((_await$this$_model$re = await ((_this$_model4 = this._model) === null || _this$_model4 === void 0 ? void 0 : _this$_model4.replaceAll())) === null || _await$this$_model$re === void 0 ? void 0 : _await$this$_model$re.success) ?? 0;
|
|
144
144
|
this._state.changeState({ replaceRevealed: false });
|
|
145
145
|
return res;
|
|
146
146
|
}
|
package/lib/cjs/index.js
CHANGED
|
@@ -364,11 +364,10 @@ let SheetFindModel = class SheetFindModel extends _univerjs_find_replace.FindMod
|
|
|
364
364
|
findInActiveWorksheet(query) {
|
|
365
365
|
const unitId = this._workbook.getUnitId();
|
|
366
366
|
const checkShouldFindInSelections = () => {
|
|
367
|
-
var _currentSelections$so;
|
|
368
367
|
const currentWorksheet = this._workbook.getActiveSheet();
|
|
369
368
|
if (!currentWorksheet) return false;
|
|
370
369
|
const currentSelections = this._workbookSelections.getCurrentSelections();
|
|
371
|
-
return (
|
|
370
|
+
return (currentSelections === null || currentSelections === void 0 ? void 0 : currentSelections.some((selection) => !isSelectionSingleCell(selection, currentWorksheet))) ?? false;
|
|
372
371
|
};
|
|
373
372
|
let complete;
|
|
374
373
|
let firstSearch = true;
|
|
@@ -423,8 +422,8 @@ let SheetFindModel = class SheetFindModel extends _univerjs_find_replace.FindMod
|
|
|
423
422
|
range: {
|
|
424
423
|
startRow: row,
|
|
425
424
|
startColumn: col,
|
|
426
|
-
endColumn: col + (colSpan
|
|
427
|
-
endRow: row + (rowSpan
|
|
425
|
+
endColumn: col + (colSpan ?? 1) - 1,
|
|
426
|
+
endRow: row + (rowSpan ?? 1) - 1
|
|
428
427
|
}
|
|
429
428
|
}
|
|
430
429
|
};
|
|
@@ -553,12 +552,11 @@ let SheetFindModel = class SheetFindModel extends _univerjs_find_replace.FindMod
|
|
|
553
552
|
return index > -1 ? index + 1 : 0;
|
|
554
553
|
}
|
|
555
554
|
moveToNextMatch(params) {
|
|
556
|
-
var _params$loop, _params$stayIfOnMatch, _params$noFocus, _params$ignoreSelecti;
|
|
557
555
|
if (!this._matches.length) return null;
|
|
558
|
-
const loop = (
|
|
559
|
-
const stayIfOnMatch = (
|
|
560
|
-
const noFocus = (
|
|
561
|
-
const ignoreSelection = (
|
|
556
|
+
const loop = (params === null || params === void 0 ? void 0 : params.loop) ?? false;
|
|
557
|
+
const stayIfOnMatch = (params === null || params === void 0 ? void 0 : params.stayIfOnMatch) ?? false;
|
|
558
|
+
const noFocus = (params === null || params === void 0 ? void 0 : params.noFocus) ?? false;
|
|
559
|
+
const ignoreSelection = (params === null || params === void 0 ? void 0 : params.ignoreSelection) ?? false;
|
|
562
560
|
const matchToMove = this._findNextMatch(loop, stayIfOnMatch, ignoreSelection);
|
|
563
561
|
if (matchToMove) {
|
|
564
562
|
const [match, index] = matchToMove;
|
|
@@ -574,12 +572,11 @@ let SheetFindModel = class SheetFindModel extends _univerjs_find_replace.FindMod
|
|
|
574
572
|
return null;
|
|
575
573
|
}
|
|
576
574
|
moveToPreviousMatch(params) {
|
|
577
|
-
var _params$loop2, _params$stayIfOnMatch2, _params$noFocus2, _params$ignoreSelecti2;
|
|
578
575
|
if (!this._matches.length) return null;
|
|
579
|
-
const loop = (
|
|
580
|
-
const stayIfOnMatch = (
|
|
581
|
-
const noFocus = (
|
|
582
|
-
const ignoreSelection = (
|
|
576
|
+
const loop = (params === null || params === void 0 ? void 0 : params.loop) ?? false;
|
|
577
|
+
const stayIfOnMatch = (params === null || params === void 0 ? void 0 : params.stayIfOnMatch) ?? false;
|
|
578
|
+
const noFocus = (params === null || params === void 0 ? void 0 : params.noFocus) ?? false;
|
|
579
|
+
const ignoreSelection = (params === null || params === void 0 ? void 0 : params.ignoreSelection) ?? false;
|
|
583
580
|
const matchToMove = this._findPreviousMatch(loop, stayIfOnMatch, ignoreSelection);
|
|
584
581
|
if (matchToMove) {
|
|
585
582
|
const [match, index] = matchToMove;
|
|
@@ -640,14 +637,12 @@ let SheetFindModel = class SheetFindModel extends _univerjs_find_replace.FindMod
|
|
|
640
637
|
_findPreviousWorksheetThatHasAMatch(currentWorksheet, loop = false) {
|
|
641
638
|
const rawWorksheetsInOrder = this._workbook.getSheetOrders();
|
|
642
639
|
const currentSheetIndex = rawWorksheetsInOrder.findIndex((sheet) => sheet === currentWorksheet);
|
|
643
|
-
|
|
644
|
-
return first !== null && first !== void 0 ? first : null;
|
|
640
|
+
return (loop ? (0, _univerjs_core.rotate)(rawWorksheetsInOrder, currentSheetIndex + 1) : rawWorksheetsInOrder.slice(0, currentSheetIndex + 1)).findLast((worksheet) => this._matchesByWorksheet.has(worksheet)) ?? null;
|
|
645
641
|
}
|
|
646
642
|
_findNextWorksheetThatHasAMatch(currentWorksheet, loop = false) {
|
|
647
643
|
const rawWorksheetsInOrder = this._workbook.getSheetOrders();
|
|
648
644
|
const currentSheetIndex = rawWorksheetsInOrder.findIndex((sheet) => sheet === currentWorksheet);
|
|
649
|
-
|
|
650
|
-
return first !== null && first !== void 0 ? first : null;
|
|
645
|
+
return (loop ? (0, _univerjs_core.rotate)(rawWorksheetsInOrder, currentSheetIndex) : rawWorksheetsInOrder.slice(currentSheetIndex)).find((worksheet) => this._matchesByWorksheet.has(worksheet)) ?? null;
|
|
651
646
|
}
|
|
652
647
|
_findNextMatchByRange(matches, range, stayIfOnMatch = false) {
|
|
653
648
|
const findByRow = this._query.findDirection === _univerjs_find_replace.FindDirection.ROW;
|
|
@@ -864,8 +859,8 @@ function matchCellData(cellData, query) {
|
|
|
864
859
|
return query.caseSensitive ? value.indexOf(query.findString) > -1 : value.toLowerCase().indexOf(query.findString) > -1;
|
|
865
860
|
}
|
|
866
861
|
function extractPureValue(cell) {
|
|
867
|
-
var _cell$p
|
|
868
|
-
const rawValue = (
|
|
862
|
+
var _cell$p;
|
|
863
|
+
const rawValue = (cell === null || cell === void 0 || (_cell$p = cell.p) === null || _cell$p === void 0 || (_cell$p = _cell$p.body) === null || _cell$p === void 0 ? void 0 : _cell$p.dataStream) ?? (cell === null || cell === void 0 ? void 0 : cell.v);
|
|
869
864
|
if (typeof rawValue === "number") return `${rawValue}`;
|
|
870
865
|
if (typeof rawValue === "boolean") return rawValue ? "1" : "0";
|
|
871
866
|
return rawValue;
|
|
@@ -881,7 +876,7 @@ function trimLeadingTrailingWhitespace(value) {
|
|
|
881
876
|
//#endregion
|
|
882
877
|
//#region package.json
|
|
883
878
|
var name = "@univerjs/sheets-find-replace";
|
|
884
|
-
var version = "1.0.0-
|
|
879
|
+
var version = "1.0.0-beta.0";
|
|
885
880
|
|
|
886
881
|
//#endregion
|
|
887
882
|
//#region src/config/config.ts
|
package/lib/es/facade.js
CHANGED
|
@@ -135,12 +135,12 @@ let FTextFinder = class FTextFinder extends Disposable {
|
|
|
135
135
|
return this;
|
|
136
136
|
}
|
|
137
137
|
async replaceAllWithAsync(replaceText) {
|
|
138
|
-
var _await$this$_model$re,
|
|
138
|
+
var _await$this$_model$re, _this$_model4;
|
|
139
139
|
await this._state.changeState({
|
|
140
140
|
replaceRevealed: true,
|
|
141
141
|
replaceString: replaceText
|
|
142
142
|
});
|
|
143
|
-
const res = (_await$this$_model$re =
|
|
143
|
+
const res = ((_await$this$_model$re = await ((_this$_model4 = this._model) === null || _this$_model4 === void 0 ? void 0 : _this$_model4.replaceAll())) === null || _await$this$_model$re === void 0 ? void 0 : _await$this$_model$re.success) ?? 0;
|
|
144
144
|
this._state.changeState({ replaceRevealed: false });
|
|
145
145
|
return res;
|
|
146
146
|
}
|
package/lib/es/index.js
CHANGED
|
@@ -363,11 +363,10 @@ let SheetFindModel = class SheetFindModel extends FindModel {
|
|
|
363
363
|
findInActiveWorksheet(query) {
|
|
364
364
|
const unitId = this._workbook.getUnitId();
|
|
365
365
|
const checkShouldFindInSelections = () => {
|
|
366
|
-
var _currentSelections$so;
|
|
367
366
|
const currentWorksheet = this._workbook.getActiveSheet();
|
|
368
367
|
if (!currentWorksheet) return false;
|
|
369
368
|
const currentSelections = this._workbookSelections.getCurrentSelections();
|
|
370
|
-
return (
|
|
369
|
+
return (currentSelections === null || currentSelections === void 0 ? void 0 : currentSelections.some((selection) => !isSelectionSingleCell(selection, currentWorksheet))) ?? false;
|
|
371
370
|
};
|
|
372
371
|
let complete;
|
|
373
372
|
let firstSearch = true;
|
|
@@ -422,8 +421,8 @@ let SheetFindModel = class SheetFindModel extends FindModel {
|
|
|
422
421
|
range: {
|
|
423
422
|
startRow: row,
|
|
424
423
|
startColumn: col,
|
|
425
|
-
endColumn: col + (colSpan
|
|
426
|
-
endRow: row + (rowSpan
|
|
424
|
+
endColumn: col + (colSpan ?? 1) - 1,
|
|
425
|
+
endRow: row + (rowSpan ?? 1) - 1
|
|
427
426
|
}
|
|
428
427
|
}
|
|
429
428
|
};
|
|
@@ -552,12 +551,11 @@ let SheetFindModel = class SheetFindModel extends FindModel {
|
|
|
552
551
|
return index > -1 ? index + 1 : 0;
|
|
553
552
|
}
|
|
554
553
|
moveToNextMatch(params) {
|
|
555
|
-
var _params$loop, _params$stayIfOnMatch, _params$noFocus, _params$ignoreSelecti;
|
|
556
554
|
if (!this._matches.length) return null;
|
|
557
|
-
const loop = (
|
|
558
|
-
const stayIfOnMatch = (
|
|
559
|
-
const noFocus = (
|
|
560
|
-
const ignoreSelection = (
|
|
555
|
+
const loop = (params === null || params === void 0 ? void 0 : params.loop) ?? false;
|
|
556
|
+
const stayIfOnMatch = (params === null || params === void 0 ? void 0 : params.stayIfOnMatch) ?? false;
|
|
557
|
+
const noFocus = (params === null || params === void 0 ? void 0 : params.noFocus) ?? false;
|
|
558
|
+
const ignoreSelection = (params === null || params === void 0 ? void 0 : params.ignoreSelection) ?? false;
|
|
561
559
|
const matchToMove = this._findNextMatch(loop, stayIfOnMatch, ignoreSelection);
|
|
562
560
|
if (matchToMove) {
|
|
563
561
|
const [match, index] = matchToMove;
|
|
@@ -573,12 +571,11 @@ let SheetFindModel = class SheetFindModel extends FindModel {
|
|
|
573
571
|
return null;
|
|
574
572
|
}
|
|
575
573
|
moveToPreviousMatch(params) {
|
|
576
|
-
var _params$loop2, _params$stayIfOnMatch2, _params$noFocus2, _params$ignoreSelecti2;
|
|
577
574
|
if (!this._matches.length) return null;
|
|
578
|
-
const loop = (
|
|
579
|
-
const stayIfOnMatch = (
|
|
580
|
-
const noFocus = (
|
|
581
|
-
const ignoreSelection = (
|
|
575
|
+
const loop = (params === null || params === void 0 ? void 0 : params.loop) ?? false;
|
|
576
|
+
const stayIfOnMatch = (params === null || params === void 0 ? void 0 : params.stayIfOnMatch) ?? false;
|
|
577
|
+
const noFocus = (params === null || params === void 0 ? void 0 : params.noFocus) ?? false;
|
|
578
|
+
const ignoreSelection = (params === null || params === void 0 ? void 0 : params.ignoreSelection) ?? false;
|
|
582
579
|
const matchToMove = this._findPreviousMatch(loop, stayIfOnMatch, ignoreSelection);
|
|
583
580
|
if (matchToMove) {
|
|
584
581
|
const [match, index] = matchToMove;
|
|
@@ -639,14 +636,12 @@ let SheetFindModel = class SheetFindModel extends FindModel {
|
|
|
639
636
|
_findPreviousWorksheetThatHasAMatch(currentWorksheet, loop = false) {
|
|
640
637
|
const rawWorksheetsInOrder = this._workbook.getSheetOrders();
|
|
641
638
|
const currentSheetIndex = rawWorksheetsInOrder.findIndex((sheet) => sheet === currentWorksheet);
|
|
642
|
-
|
|
643
|
-
return first !== null && first !== void 0 ? first : null;
|
|
639
|
+
return (loop ? rotate(rawWorksheetsInOrder, currentSheetIndex + 1) : rawWorksheetsInOrder.slice(0, currentSheetIndex + 1)).findLast((worksheet) => this._matchesByWorksheet.has(worksheet)) ?? null;
|
|
644
640
|
}
|
|
645
641
|
_findNextWorksheetThatHasAMatch(currentWorksheet, loop = false) {
|
|
646
642
|
const rawWorksheetsInOrder = this._workbook.getSheetOrders();
|
|
647
643
|
const currentSheetIndex = rawWorksheetsInOrder.findIndex((sheet) => sheet === currentWorksheet);
|
|
648
|
-
|
|
649
|
-
return first !== null && first !== void 0 ? first : null;
|
|
644
|
+
return (loop ? rotate(rawWorksheetsInOrder, currentSheetIndex) : rawWorksheetsInOrder.slice(currentSheetIndex)).find((worksheet) => this._matchesByWorksheet.has(worksheet)) ?? null;
|
|
650
645
|
}
|
|
651
646
|
_findNextMatchByRange(matches, range, stayIfOnMatch = false) {
|
|
652
647
|
const findByRow = this._query.findDirection === FindDirection.ROW;
|
|
@@ -863,8 +858,8 @@ function matchCellData(cellData, query) {
|
|
|
863
858
|
return query.caseSensitive ? value.indexOf(query.findString) > -1 : value.toLowerCase().indexOf(query.findString) > -1;
|
|
864
859
|
}
|
|
865
860
|
function extractPureValue(cell) {
|
|
866
|
-
var _cell$p
|
|
867
|
-
const rawValue = (
|
|
861
|
+
var _cell$p;
|
|
862
|
+
const rawValue = (cell === null || cell === void 0 || (_cell$p = cell.p) === null || _cell$p === void 0 || (_cell$p = _cell$p.body) === null || _cell$p === void 0 ? void 0 : _cell$p.dataStream) ?? (cell === null || cell === void 0 ? void 0 : cell.v);
|
|
868
863
|
if (typeof rawValue === "number") return `${rawValue}`;
|
|
869
864
|
if (typeof rawValue === "boolean") return rawValue ? "1" : "0";
|
|
870
865
|
return rawValue;
|
|
@@ -880,7 +875,7 @@ function trimLeadingTrailingWhitespace(value) {
|
|
|
880
875
|
//#endregion
|
|
881
876
|
//#region package.json
|
|
882
877
|
var name = "@univerjs/sheets-find-replace";
|
|
883
|
-
var version = "1.0.0-
|
|
878
|
+
var version = "1.0.0-beta.0";
|
|
884
879
|
|
|
885
880
|
//#endregion
|
|
886
881
|
//#region src/config/config.ts
|
package/lib/facade.js
CHANGED
|
@@ -135,12 +135,12 @@ let FTextFinder = class FTextFinder extends Disposable {
|
|
|
135
135
|
return this;
|
|
136
136
|
}
|
|
137
137
|
async replaceAllWithAsync(replaceText) {
|
|
138
|
-
var _await$this$_model$re,
|
|
138
|
+
var _await$this$_model$re, _this$_model4;
|
|
139
139
|
await this._state.changeState({
|
|
140
140
|
replaceRevealed: true,
|
|
141
141
|
replaceString: replaceText
|
|
142
142
|
});
|
|
143
|
-
const res = (_await$this$_model$re =
|
|
143
|
+
const res = ((_await$this$_model$re = await ((_this$_model4 = this._model) === null || _this$_model4 === void 0 ? void 0 : _this$_model4.replaceAll())) === null || _await$this$_model$re === void 0 ? void 0 : _await$this$_model$re.success) ?? 0;
|
|
144
144
|
this._state.changeState({ replaceRevealed: false });
|
|
145
145
|
return res;
|
|
146
146
|
}
|
package/lib/index.js
CHANGED
|
@@ -363,11 +363,10 @@ let SheetFindModel = class SheetFindModel extends FindModel {
|
|
|
363
363
|
findInActiveWorksheet(query) {
|
|
364
364
|
const unitId = this._workbook.getUnitId();
|
|
365
365
|
const checkShouldFindInSelections = () => {
|
|
366
|
-
var _currentSelections$so;
|
|
367
366
|
const currentWorksheet = this._workbook.getActiveSheet();
|
|
368
367
|
if (!currentWorksheet) return false;
|
|
369
368
|
const currentSelections = this._workbookSelections.getCurrentSelections();
|
|
370
|
-
return (
|
|
369
|
+
return (currentSelections === null || currentSelections === void 0 ? void 0 : currentSelections.some((selection) => !isSelectionSingleCell(selection, currentWorksheet))) ?? false;
|
|
371
370
|
};
|
|
372
371
|
let complete;
|
|
373
372
|
let firstSearch = true;
|
|
@@ -422,8 +421,8 @@ let SheetFindModel = class SheetFindModel extends FindModel {
|
|
|
422
421
|
range: {
|
|
423
422
|
startRow: row,
|
|
424
423
|
startColumn: col,
|
|
425
|
-
endColumn: col + (colSpan
|
|
426
|
-
endRow: row + (rowSpan
|
|
424
|
+
endColumn: col + (colSpan ?? 1) - 1,
|
|
425
|
+
endRow: row + (rowSpan ?? 1) - 1
|
|
427
426
|
}
|
|
428
427
|
}
|
|
429
428
|
};
|
|
@@ -552,12 +551,11 @@ let SheetFindModel = class SheetFindModel extends FindModel {
|
|
|
552
551
|
return index > -1 ? index + 1 : 0;
|
|
553
552
|
}
|
|
554
553
|
moveToNextMatch(params) {
|
|
555
|
-
var _params$loop, _params$stayIfOnMatch, _params$noFocus, _params$ignoreSelecti;
|
|
556
554
|
if (!this._matches.length) return null;
|
|
557
|
-
const loop = (
|
|
558
|
-
const stayIfOnMatch = (
|
|
559
|
-
const noFocus = (
|
|
560
|
-
const ignoreSelection = (
|
|
555
|
+
const loop = (params === null || params === void 0 ? void 0 : params.loop) ?? false;
|
|
556
|
+
const stayIfOnMatch = (params === null || params === void 0 ? void 0 : params.stayIfOnMatch) ?? false;
|
|
557
|
+
const noFocus = (params === null || params === void 0 ? void 0 : params.noFocus) ?? false;
|
|
558
|
+
const ignoreSelection = (params === null || params === void 0 ? void 0 : params.ignoreSelection) ?? false;
|
|
561
559
|
const matchToMove = this._findNextMatch(loop, stayIfOnMatch, ignoreSelection);
|
|
562
560
|
if (matchToMove) {
|
|
563
561
|
const [match, index] = matchToMove;
|
|
@@ -573,12 +571,11 @@ let SheetFindModel = class SheetFindModel extends FindModel {
|
|
|
573
571
|
return null;
|
|
574
572
|
}
|
|
575
573
|
moveToPreviousMatch(params) {
|
|
576
|
-
var _params$loop2, _params$stayIfOnMatch2, _params$noFocus2, _params$ignoreSelecti2;
|
|
577
574
|
if (!this._matches.length) return null;
|
|
578
|
-
const loop = (
|
|
579
|
-
const stayIfOnMatch = (
|
|
580
|
-
const noFocus = (
|
|
581
|
-
const ignoreSelection = (
|
|
575
|
+
const loop = (params === null || params === void 0 ? void 0 : params.loop) ?? false;
|
|
576
|
+
const stayIfOnMatch = (params === null || params === void 0 ? void 0 : params.stayIfOnMatch) ?? false;
|
|
577
|
+
const noFocus = (params === null || params === void 0 ? void 0 : params.noFocus) ?? false;
|
|
578
|
+
const ignoreSelection = (params === null || params === void 0 ? void 0 : params.ignoreSelection) ?? false;
|
|
582
579
|
const matchToMove = this._findPreviousMatch(loop, stayIfOnMatch, ignoreSelection);
|
|
583
580
|
if (matchToMove) {
|
|
584
581
|
const [match, index] = matchToMove;
|
|
@@ -639,14 +636,12 @@ let SheetFindModel = class SheetFindModel extends FindModel {
|
|
|
639
636
|
_findPreviousWorksheetThatHasAMatch(currentWorksheet, loop = false) {
|
|
640
637
|
const rawWorksheetsInOrder = this._workbook.getSheetOrders();
|
|
641
638
|
const currentSheetIndex = rawWorksheetsInOrder.findIndex((sheet) => sheet === currentWorksheet);
|
|
642
|
-
|
|
643
|
-
return first !== null && first !== void 0 ? first : null;
|
|
639
|
+
return (loop ? rotate(rawWorksheetsInOrder, currentSheetIndex + 1) : rawWorksheetsInOrder.slice(0, currentSheetIndex + 1)).findLast((worksheet) => this._matchesByWorksheet.has(worksheet)) ?? null;
|
|
644
640
|
}
|
|
645
641
|
_findNextWorksheetThatHasAMatch(currentWorksheet, loop = false) {
|
|
646
642
|
const rawWorksheetsInOrder = this._workbook.getSheetOrders();
|
|
647
643
|
const currentSheetIndex = rawWorksheetsInOrder.findIndex((sheet) => sheet === currentWorksheet);
|
|
648
|
-
|
|
649
|
-
return first !== null && first !== void 0 ? first : null;
|
|
644
|
+
return (loop ? rotate(rawWorksheetsInOrder, currentSheetIndex) : rawWorksheetsInOrder.slice(currentSheetIndex)).find((worksheet) => this._matchesByWorksheet.has(worksheet)) ?? null;
|
|
650
645
|
}
|
|
651
646
|
_findNextMatchByRange(matches, range, stayIfOnMatch = false) {
|
|
652
647
|
const findByRow = this._query.findDirection === FindDirection.ROW;
|
|
@@ -863,8 +858,8 @@ function matchCellData(cellData, query) {
|
|
|
863
858
|
return query.caseSensitive ? value.indexOf(query.findString) > -1 : value.toLowerCase().indexOf(query.findString) > -1;
|
|
864
859
|
}
|
|
865
860
|
function extractPureValue(cell) {
|
|
866
|
-
var _cell$p
|
|
867
|
-
const rawValue = (
|
|
861
|
+
var _cell$p;
|
|
862
|
+
const rawValue = (cell === null || cell === void 0 || (_cell$p = cell.p) === null || _cell$p === void 0 || (_cell$p = _cell$p.body) === null || _cell$p === void 0 ? void 0 : _cell$p.dataStream) ?? (cell === null || cell === void 0 ? void 0 : cell.v);
|
|
868
863
|
if (typeof rawValue === "number") return `${rawValue}`;
|
|
869
864
|
if (typeof rawValue === "boolean") return rawValue ? "1" : "0";
|
|
870
865
|
return rawValue;
|
|
@@ -880,7 +875,7 @@ function trimLeadingTrailingWhitespace(value) {
|
|
|
880
875
|
//#endregion
|
|
881
876
|
//#region package.json
|
|
882
877
|
var name = "@univerjs/sheets-find-replace";
|
|
883
|
-
var version = "1.0.0-
|
|
878
|
+
var version = "1.0.0-beta.0";
|
|
884
879
|
|
|
885
880
|
//#endregion
|
|
886
881
|
//#region src/config/config.ts
|
package/lib/umd/facade.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(e,t){typeof exports==`object`&&typeof module<`u`?t(require("@univerjs/core"),require("@univerjs/find-replace"),require("@univerjs/sheets/facade"),require("rxjs"),require("@univerjs/core/facade")):typeof define==`function`&&define.amd?define([`@univerjs/core`,`@univerjs/find-replace`,`@univerjs/sheets/facade`,`rxjs`,`@univerjs/core/facade`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.UniverCore,e.UniverFindReplace,e.UniverSheetsFacade,e.rxjs,e.UniverCoreFacade))})(this,function(e,t,n,r,i){function a(e){"@babel/helpers - typeof";return a=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},a(e)}function o(e,t){if(a(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(a(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function s(e){var t=o(e,`string`);return a(t)==`symbol`?t:t+``}function c(e,t,n){return(t=s(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function l(e,t){return function(n,r){t(n,r,e)}}function u(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}let d=class extends e.Disposable{constructor(e,n,r,i){super(),this._injector=n,this._univerInstanceService=r,this._findReplaceService=i,c(this,`_state`,new t.FindReplaceState),c(this,`_model`,void 0),c(this,`_complete`,void 0);let a=this._findReplaceService.getProviders();this._model=this._injector.createInstance(t.FindReplaceModel,this._state,a);let o={...(0,t.createInitFindReplaceState)(),...e};this._state.changeState(o)}findAll(){return!this._state.findCompleted||!this._complete?[]:this._complete.results.map(e=>this._findMatchToFRange(e))}findNext(){var e;if(!this._state.findCompleted||!this._complete)return null;let t=(e=this._model)==null?void 0:e.moveToNextMatch();return t?this._findMatchToFRange(t):null}findPrevious(){var e;let t=(e=this._model)==null?void 0:e.moveToPreviousMatch();return t?this._findMatchToFRange(t):null}getCurrentMatch(){var e;if(!this._state.findCompleted||!this._complete)throw Error(`Find operation is not completed.`);let t=(e=this._model)==null?void 0:e.currentMatch$.value;return t?this._findMatchToFRange(t):null}async matchCaseAsync(e){return this._state.changeState({caseSensitive:e,findCompleted:!1}),await(0,r.firstValueFrom)(this._state.stateUpdates$.pipe((0,r.filter)(e=>e.findCompleted===!0))),await this.ensureCompleteAsync(),this}async matchEntireCellAsync(e){return this._state.changeState({matchesTheWholeCell:e,findCompleted:!1}),await(0,r.firstValueFrom)(this._state.stateUpdates$.pipe((0,r.filter)(e=>e.findCompleted===!0))),await this.ensureCompleteAsync(),this}async matchFormulaTextAsync(e){return this._state.changeState({findBy:e?t.FindBy.FORMULA:t.FindBy.VALUE,findCompleted:!1}),await(0,r.firstValueFrom)(this._state.stateUpdates$.pipe((0,r.filter)(e=>e.findCompleted===!0))),await this.ensureCompleteAsync(),this}async replaceAllWithAsync(e){var t,n
|
|
1
|
+
(function(e,t){typeof exports==`object`&&typeof module<`u`?t(require("@univerjs/core"),require("@univerjs/find-replace"),require("@univerjs/sheets/facade"),require("rxjs"),require("@univerjs/core/facade")):typeof define==`function`&&define.amd?define([`@univerjs/core`,`@univerjs/find-replace`,`@univerjs/sheets/facade`,`rxjs`,`@univerjs/core/facade`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.UniverCore,e.UniverFindReplace,e.UniverSheetsFacade,e.rxjs,e.UniverCoreFacade))})(this,function(e,t,n,r,i){function a(e){"@babel/helpers - typeof";return a=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},a(e)}function o(e,t){if(a(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(a(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function s(e){var t=o(e,`string`);return a(t)==`symbol`?t:t+``}function c(e,t,n){return(t=s(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function l(e,t){return function(n,r){t(n,r,e)}}function u(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}let d=class extends e.Disposable{constructor(e,n,r,i){super(),this._injector=n,this._univerInstanceService=r,this._findReplaceService=i,c(this,`_state`,new t.FindReplaceState),c(this,`_model`,void 0),c(this,`_complete`,void 0);let a=this._findReplaceService.getProviders();this._model=this._injector.createInstance(t.FindReplaceModel,this._state,a);let o={...(0,t.createInitFindReplaceState)(),...e};this._state.changeState(o)}findAll(){return!this._state.findCompleted||!this._complete?[]:this._complete.results.map(e=>this._findMatchToFRange(e))}findNext(){var e;if(!this._state.findCompleted||!this._complete)return null;let t=(e=this._model)==null?void 0:e.moveToNextMatch();return t?this._findMatchToFRange(t):null}findPrevious(){var e;let t=(e=this._model)==null?void 0:e.moveToPreviousMatch();return t?this._findMatchToFRange(t):null}getCurrentMatch(){var e;if(!this._state.findCompleted||!this._complete)throw Error(`Find operation is not completed.`);let t=(e=this._model)==null?void 0:e.currentMatch$.value;return t?this._findMatchToFRange(t):null}async matchCaseAsync(e){return this._state.changeState({caseSensitive:e,findCompleted:!1}),await(0,r.firstValueFrom)(this._state.stateUpdates$.pipe((0,r.filter)(e=>e.findCompleted===!0))),await this.ensureCompleteAsync(),this}async matchEntireCellAsync(e){return this._state.changeState({matchesTheWholeCell:e,findCompleted:!1}),await(0,r.firstValueFrom)(this._state.stateUpdates$.pipe((0,r.filter)(e=>e.findCompleted===!0))),await this.ensureCompleteAsync(),this}async matchFormulaTextAsync(e){return this._state.changeState({findBy:e?t.FindBy.FORMULA:t.FindBy.VALUE,findCompleted:!1}),await(0,r.firstValueFrom)(this._state.stateUpdates$.pipe((0,r.filter)(e=>e.findCompleted===!0))),await this.ensureCompleteAsync(),this}async replaceAllWithAsync(e){var t,n;await this._state.changeState({replaceRevealed:!0,replaceString:e});let r=((t=await((n=this._model)==null?void 0:n.replaceAll()))==null?void 0:t.success)??0;return this._state.changeState({replaceRevealed:!1}),r}async replaceWithAsync(e){var t;return await this._state.changeState({replaceRevealed:!0,replaceString:e}),await((t=this._model)==null?void 0:t.replace()),this._state.changeState({replaceRevealed:!1}),!0}async ensureCompleteAsync(){var e;this._complete=await((e=this._model)==null?void 0:e.start())}_findMatchToFRange(e){let{unitId:t}=e,{subUnitId:r,range:i}=e.range,a=this._univerInstanceService.getUnit(t),o=a.getSheetBySheetId(r);return this._injector.createInstance(n.FRange,a,o,i)}};d=u([l(1,(0,e.Inject)(e.Injector)),l(2,e.IUniverInstanceService),l(3,t.IFindReplaceService)],d);var f=class extends i.FUniver{async createTextFinderAsync(e){let t={findString:e},n=this._injector.createInstance(d,t);return await n.ensureCompleteAsync(),n}};i.FUniver.extend(f)});
|
package/lib/umd/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require("@univerjs/core"),require("@univerjs/sheets"),require("@univerjs/engine-render"),require("@univerjs/find-replace"),require("@univerjs/sheets-ui"),require("rxjs")):typeof define==`function`&&define.amd?define([`exports`,`@univerjs/core`,`@univerjs/sheets`,`@univerjs/engine-render`,`@univerjs/find-replace`,`@univerjs/sheets-ui`,`rxjs`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.UniverSheetsFindReplace={},e.UniverCore,e.UniverSheets,e.UniverEngineRender,e.UniverFindReplace,e.UniverSheetsUi,e.rxjs))})(this,function(e,t,n,r,i,a,o){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});let s={id:`sheet.command.replace`,type:t.CommandType.COMMAND,handler:async(e,r)=>{let i=e.get(t.IUndoRedoService),a=e.get(t.ICommandService),{unitId:o,replacements:s}=r,l=i.__tempBatchingUndoRedo(o),u=await Promise.all(s.map(e=>a.executeCommand(n.SetRangeValuesCommand.id,{unitId:o,subUnitId:e.subUnitId,value:e.value})));return l.dispose(),c(u,s)}};function c(e,t){let n=0,r=0;return e.forEach((e,i)=>{let a=t[i].count;e?n+=a:r+=a}),{success:n,failure:r}}function l(e){"@babel/helpers - typeof";return l=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},l(e)}function u(e,t){if(l(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(l(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function d(e){var t=u(e,`string`);return l(t)==`symbol`?t:t+``}function f(e,t,n){return(t=d(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}var p=class extends r.Shape{constructor(e,t){super(e,t),f(this,`_activated`,!1),f(this,`_inHiddenRange`,!1),f(this,`_color`,void 0),t&&this.setShapeProps(t)}setShapeProps(e){this._activated=!!e.activated,e.inHiddenRange!==void 0&&(this._inHiddenRange=e.inHiddenRange),e.color!==void 0&&(this._color=e.color),this.transformByState({width:e.width,height:e.height})}_draw(e){let t=this._activated,n=`rgba(${this._color.r}, ${this._color.g}, ${this._color.b}, 0.35)`,i=`rgb(${this._color.r}, ${this._color.g}, ${this._color.b})`;r.Rect.drawWith(e,{width:this.width,height:this.height,fill:n,stroke:t?i:void 0,strokeWidth:t?2:0,evented:!1})}};function m(e,t){return e.startRow===t.startRow&&e.startColumn===t.startColumn}function h(e,t){return e.startRow<t.startRow||e.startRow===t.startRow&&e.startColumn<=t.startColumn}function g(e,t){return e.startColumn<t.startColumn||e.startColumn===t.startColumn&&e.startRow<=t.startRow}function _(e,t){return e.startRow>t.startRow||e.startRow===t.startRow&&e.startColumn>=t.startColumn}function v(e,t){return e.startColumn>t.startColumn||e.startColumn===t.startColumn&&e.startRow>=t.startRow}function y(e,n){let{range:r}=e,{startRow:i,startColumn:a}=r,o=n.getMergedCell(i,a);return o?t.Rectangle.equals(r,o):r.endRow===r.startRow&&r.endColumn===r.startColumn}function b(e,t){return function(n,r){t(n,r,e)}}function x(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}let S=class extends t.Disposable{constructor(e,t,n,r,i){super(),this._injector=e,this._findReplaceController=t,this._contextService=n,this._findReplaceService=r,this._commandService=i,f(this,`_provider`,void 0),this._init(),this._initCommands()}dispose(){super.dispose(),this._findReplaceController.closePanel(),this._provider.dispose()}_init(){let e=this._injector.createInstance(w);this._provider=e,this.disposeWithMe(this._findReplaceService.registerFindReplaceProvider(e)),this.disposeWithMe(this._contextService.subscribeContextValue$(t.EDITOR_ACTIVATED).pipe((0,o.filter)(e=>!!e)).subscribe(()=>this._findReplaceController.closePanel()))}_initCommands(){[s].forEach(e=>this.disposeWithMe(this._commandService.registerCommand(e)))}};S=x([b(0,(0,t.Inject)(t.Injector)),b(1,(0,t.Inject)(i.FindReplaceController)),b(2,t.IContextService),b(3,i.IFindReplaceService),b(4,t.ICommandService)],S);let C=class extends i.FindModel{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}constructor(e,t,n,r,i,a,s,c){super(),this._workbook=e,this._sheetSkeletonManagerService=t,this._univerInstanceService=n,this._renderManagerService=r,this._commandService=i,this._contextService=a,this._themeService=s,f(this,`_matchesUpdate$`,new o.Subject),f(this,`matchesUpdate$`,this._matchesUpdate$.asObservable()),f(this,`_activelyChangingMatch$`,new o.Subject),f(this,`activelyChangingMatch$`,this._activelyChangingMatch$.asObservable()),f(this,`_matchesByWorksheet`,new Map),f(this,`_matches`,[]),f(this,`_matchesPosition`,0),f(this,`_activeHighlightIndex`,-1),f(this,`_highlightShapes`,[]),f(this,`_currentHighlightShape`,null),f(this,`_query`,null),f(this,`_workbookSelections`,void 0),this._workbookSelections=c.getWorkbookSelections(this.unitId)}dispose(){super.dispose(),this._disposeHighlights(),this._toggleDisplayRawFormula(!1)}getMatches(){return this._matches}start(e){switch(this._query=e,e.findBy===i.FindBy.FORMULA?this._toggleDisplayRawFormula(!0):this._toggleDisplayRawFormula(!1),e.findScope){case i.FindScope.UNIT:this.findInWorkbook(e);break;case i.FindScope.SUBUNIT:default:this.findInActiveWorksheet(e);break}}focusSelection(){let e=this.currentMatch;e&&this._commandService.executeCommand(n.SelectRangeCommand.id,{unitId:e.unitId,subUnit:e.range.subUnitId,range:e.range.range})}_toggleDisplayRawFormula(e){this._contextService.setContextValue(r.RENDER_RAW_FORMULA_KEY,e)}findInWorkbook(e){let r=this._workbook.getUnitId(),i,a=!0,s=()=>{let t=this._workbook.getSheets().filter(e=>!e.isSheetHidden()).map(t=>{let n=this._findInWorksheet(t,e,r),i=t.getSheetId(),{results:a}=n;return a.length?this._matchesByWorksheet.set(i,n.results):this._matchesByWorksheet.delete(i),n});this._matches=t.map(e=>e.results).flat(),this._updateFindHighlight(),a?(i={results:this._matches},a=!1):this._matchesUpdate$.next(this._matches)};return this.disposeWithMe(this._sheetSkeletonManagerService.currentSkeleton$.subscribe(()=>{this._updateFindHighlight(),this._updateCurrentHighlightShape(this._activeHighlightIndex)})),this.disposeWithMe((0,t.fromCallback)(this._commandService.onCommandExecuted.bind(this._commandService)).pipe((0,o.filter)(([e,t])=>e.id===n.SetWorksheetActiveOperation.id&&!(t!=null&&t.fromFindReplace))).subscribe(()=>{let e=this._workbook.getActiveSheet();if(!e)return;let t=e.getSheetId();this._matchesByWorksheet.has(t)&&this._findNextMatchOnActiveSheetChange(e)})),this.disposeWithMe((0,t.fromCallback)(this._commandService.onCommandExecuted.bind(this._commandService)).pipe((0,o.filter)(([e])=>e.type===t.CommandType.MUTATION&&e.params.unitId===this._workbook.getUnitId()),(0,o.throttleTime)(600,void 0,{leading:!1,trailing:!0})).subscribe(()=>s())),s(),i}_findNextMatchOnActiveSheetChange(e){let t,n,r=0,i=this._matchesByWorksheet.get(e.getSheetId()),a=this._workbookSelections.getCurrentSelections();a!=null&&a.length?([t,r]=this._findNextMatchByRange(i,a[0].range),n=i.findIndex(e=>e===t)):(t=i[0],n=0,r=this._matches.findIndex(e=>e===t)),this._matchesPosition=r+1,this._activelyChangingMatch$.next(t),this._activeHighlightIndex=n,this._updateFindHighlight(),this._updateCurrentHighlightShape(n)}findInActiveWorksheet(e){let r=this._workbook.getUnitId(),i=()=>{var e;let t=this._workbook.getActiveSheet();if(!t)return!1;let n=this._workbookSelections.getCurrentSelections();return(e=n==null?void 0:n.some(e=>!y(e,t)))!=null&&e},a,s=!0,c=!1,l=()=>{let t=this._workbook.getActiveSheet();if(!t)return{results:[]};let n=this.currentMatch;c=i();let o=this._workbookSelections.getCurrentSelections(),l=c?this._findInSelections(t,o,e,r):this._findInWorksheet(t,e,r);return this._matches=l.results,this._matchesPosition=this._tryRestoreLastMatchesPosition(n,this._matches),s?(a=l,s=!1):this._matchesUpdate$.next(this._matches),this._updateFindHighlight(),l};return this.disposeWithMe(this._sheetSkeletonManagerService.currentSkeleton$.subscribe(()=>this._updateFindHighlight())),this.disposeWithMe((0,o.merge)((0,t.fromCallback)(this._commandService.onCommandExecuted.bind(this._commandService)).pipe((0,o.filter)(([e])=>{if(e.type===t.CommandType.MUTATION&&e.params.unitId===this._workbook.getUnitId())return!0;if(e.id===n.SetSelectionsOperation.id&&e.params.unitId===r){let e=i();return e===!1&&c===!1?!1:(c=e,!0)}return!1})),this._workbook.activeSheet$.pipe((0,o.skip)(1))).pipe((0,o.debounceTime)(200)).subscribe(()=>l())),l(),a}_findInRange(e,t,n,r,a){let o=[],s=e.getSheetId(),c=(t.findDirection===i.FindDirection.COLUMN?e.iterateByColumn:e.iterateByRow).bind(e)(n);for(let n of c){let{row:i,col:c,colSpan:l,rowSpan:u,value:d}=n;if(a!=null&&a(i,c)||!d||e.getRowFiltered(i))continue;let{hit:f,replaceable:p,isFormula:m}=E(e,i,c,t,d);if(f){let e={provider:`sheets-find-replace-provider`,unitId:r,replaceable:p,isFormula:m,range:{subUnitId:s,range:{startRow:i,startColumn:c,endColumn:c+(l==null?1:l)-1,endRow:i+(u==null?1:u)-1}}};o.push(e)}}return{results:o}}_findInSelections(e,t,n,r){let{findDirection:a}=n,o=a===i.FindDirection.ROW?h:g,s=new Set;return{results:t.map(t=>this._findInRange(e,n,t.range,r,(e,t)=>{let n=`${e}-${t}`;return s.has(n)?!0:(s.add(n),!1)}).results).flat().sort((e,t)=>o(e.range.range,t.range.range)?-1:1)}}_findInWorksheet(e,t,n){let r=e.getRowCount(),i=e.getColumnCount(),a={startRow:0,startColumn:0,endRow:r-1,endColumn:i-1};return this._findInRange(e,t,a,n)}_disposeHighlights(){var e;this._highlightShapes.forEach(e=>{var t;(t=e.getScene())==null||t.makeDirty(),e.dispose()}),this._highlightShapes=[],(e=this._currentHighlightShape)==null||e.dispose(),this._currentHighlightShape=null}_updateFindHighlight(){this._disposeHighlights();let e=this._sheetSkeletonManagerService.getCurrentSkeleton();if(!e)return;let n=this._workbook.getUnitId(),r=this._renderManagerService.getRenderUnitById(n);if(r==null)return;let{scene:i}=r,o=this._matches,s=new t.ColorKit(this._themeService.getColorFromTheme(`yellow.400`)).toRgb(),c=this._workbook.getActiveSheet();if(!c)return;let l=c.getSheetId(),u=o.filter(e=>e.range.subUnitId===l).map((t,n)=>{let{startColumn:r,startRow:o,endColumn:l,endRow:u}=t.range.range,d=(0,a.getCoordByCell)(o,r,i,e),f=(0,a.getCoordByCell)(u,l,i,e),{startX:m,startY:h}=d,{endX:g,endY:_}=f,v=!0;for(let e=o;e<=u;e++)if(c.getRowRawVisible(e)){v=!1;break}let y=!0;for(let e=r;e<=l;e++)if(c.getColVisible(e)){y=!1;break}let b=v||y,x=y?2:g-m,S=v?2:_-h,C={left:m,top:h,color:s,width:x,height:S,evented:!1,inHiddenRange:b,zIndex:1e4};return new p(`find-highlight-${n}`,C)});i.addObjects(u),this._highlightShapes=u,i.makeDirty()}_updateCurrentHighlightShape(e){var t;if((t=this._currentHighlightShape)==null||t.setShapeProps({activated:!1}),this._currentHighlightShape=null,e!==void 0){let t=this._highlightShapes[e];if(!t)return;this._currentHighlightShape=t,t.setShapeProps({activated:!0})}}_getSheetObject(){return(0,a.getSheetObject)(this._univerInstanceService,this._renderManagerService)}async _focusMatch(e){var t;let{subUnitId:r,range:i}=e.range;if(r!==((t=this._workbook.getActiveSheet())==null?void 0:t.getSheetId())){let e=this._workbook.getUnitId();await this._commandService.executeCommand(n.SetWorksheetActivateCommand.id,{unitId:e,subUnitId:r},{fromFindReplace:!0})}this._commandService.executeCommand(a.ScrollToCellCommand.id,{range:i},{fromFindReplace:!0})}_tryRestoreLastMatchesPosition(e,t){if(!e)return 0;let{subUnitId:n}=e.range,{startColumn:r,startRow:i}=e.range.range,a=t.findIndex(e=>{if(n!==e.range.subUnitId)return!1;let{startColumn:t,startRow:a}=e.range.range;return t===r&&a===i});return a>-1?a+1:0}moveToNextMatch(e){var t,n,r,a;if(!this._matches.length)return null;let o=(t=e==null?void 0:e.loop)!=null&&t,s=(n=e==null?void 0:e.stayIfOnMatch)!=null&&n,c=(r=e==null?void 0:e.noFocus)!=null&&r,l=(a=e==null?void 0:e.ignoreSelection)!=null&&a,u=this._findNextMatch(o,s,l);if(u){let[e,t]=u;return this._matchesPosition=t+1,this._query.findScope===i.FindScope.UNIT?this._activeHighlightIndex=this._matchesByWorksheet.get(e.range.subUnitId).findIndex(t=>t===e):this._activeHighlightIndex=t,c||this._focusMatch(e),this._updateCurrentHighlightShape(this._activeHighlightIndex),e}return this._matchesPosition=0,this._updateCurrentHighlightShape(),null}moveToPreviousMatch(e){var t,n,r,a;if(!this._matches.length)return null;let o=(t=e==null?void 0:e.loop)!=null&&t,s=(n=e==null?void 0:e.stayIfOnMatch)!=null&&n,c=(r=e==null?void 0:e.noFocus)!=null&&r,l=(a=e==null?void 0:e.ignoreSelection)!=null&&a,u=this._findPreviousMatch(o,s,l);if(u){let[e,t]=u;return this._matchesPosition=t+1,this._query.findScope===i.FindScope.UNIT?this._activeHighlightIndex=this._matchesByWorksheet.get(e.range.subUnitId).findIndex(t=>t===e):this._activeHighlightIndex=t,c||this._focusMatch(e),this._updateCurrentHighlightShape(this._activeHighlightIndex),e}return this._matchesPosition=0,this._updateCurrentHighlightShape(),null}_findPreviousMatch(e=!1,t=!1,n=!1){var r;if(this.currentMatch){let n=this._matches.findIndex(e=>e===this.currentMatch);if(t)return[this.currentMatch,n];let r=n-1;if(!e&&r<0)return null;let i=this._matches.length,a=(r+i)%i;return[this._matches[a],a]}let a=this._workbookSelections.getCurrentLastSelection();if(n||!a){let e=this._matches.length-1;return[this._matches[e],e]}if(this._query.findScope!==i.FindScope.UNIT)return this._findPreviousMatchByRange(this._matches,a.range);let o=(r=this._workbook.getActiveSheet())==null?void 0:r.getSheetId();if(!o)return null;let s=this._findPreviousWorksheetThatHasAMatch(o,e);return s?this._findPreviousMatchByRange(this._matchesByWorksheet.get(s),a.range):null}_findNextMatch(e=!1,t=!1,n=!1){var r;if(this.currentMatch){let n=this._matches.findIndex(e=>e===this.currentMatch);if(t)return[this.currentMatch,n];let r=n+1,i=this._matches.length;if(!e&&r>=i)return null;let a=r%i;return[this._matches[a],a]}let a=this._workbookSelections.getCurrentLastSelection();if(n||!a)return[this._matches[0],0];if(this._query.findScope!==i.FindScope.UNIT)return this._findNextMatchByRange(this._matches,a.range,t);let o=(r=this._workbook.getActiveSheet())==null?void 0:r.getSheetId();if(!o)return null;let s=this._findNextWorksheetThatHasAMatch(o,e);return s?this._findNextMatchByRange(this._matchesByWorksheet.get(s),a.range):null}_findPreviousWorksheetThatHasAMatch(e,n=!1){let r=this._workbook.getSheetOrders(),i=r.findIndex(t=>t===e),a=(n?(0,t.rotate)(r,i+1):r.slice(0,i+1)).findLast(e=>this._matchesByWorksheet.has(e));return a==null?null:a}_findNextWorksheetThatHasAMatch(e,n=!1){let r=this._workbook.getSheetOrders(),i=r.findIndex(t=>t===e),a=(n?(0,t.rotate)(r,i):r.slice(i)).find(e=>this._matchesByWorksheet.has(e));return a==null?null:a}_findNextMatchByRange(e,t,n=!1){let r=this._query.findDirection===i.FindDirection.ROW,a=e.findIndex(e=>{let i=e.range.range;if(!(r?h(t,i):g(t,i)))return!1;let a=m(t,i);return n?a:!a});a===-1&&(a=e.length-1);let o=e[a];return[o,this._matches.findIndex(e=>e===o)]}_findPreviousMatchByRange(e,t,n=!1){let r=this._query.findDirection===i.FindDirection.ROW,a=this._matches.findLastIndex(e=>{let i=e.range.range;if(!(r?_(t,i):v(t,i)))return!1;let a=m(t,i);return n?a:!a});a===-1&&(a=0);let o=e[a];return[o,this._matches.findIndex(e=>e===o)]}async replace(e){if(this._matchesCount===0||!this.currentMatch||!this._query||!this.currentMatch.replaceable)return!1;let t=this.currentMatch.range,r=this._workbook.getSheetBySheetId(this.currentMatch.range.subUnitId),a=this._getReplacedCellData(this.currentMatch,r,this._query.findBy===i.FindBy.FORMULA,this._query.findString,e,this._query.caseSensitive?`g`:`ig`),o={unitId:this.currentMatch.unitId,subUnitId:t.subUnitId,value:{[t.range.startRow]:{[t.range.startColumn]:a}}};return this._commandService.executeCommand(n.SetRangeValuesCommand.id,o)}async replaceAll(e){if(this._matchesCount===0||!this._query)return{success:0,failure:0};let n=this._workbook.getUnitId(),{findString:r,caseSensitive:a,findBy:o}=this._query,c=o===i.FindBy.FORMULA,l=a?`g`:`ig`,u=[];return(0,t.groupBy)(this._matches.filter(e=>e.replaceable),e=>e.range.subUnitId).forEach((n,i)=>{let a=new t.ObjectMatrix,o=this._workbook.getSheetBySheetId(i);n.forEach(t=>{let{startColumn:n,startRow:i}=t.range.range,s=this._getReplacedCellData(t,o,c,r,e,l);s&&a.setValue(i,n,s)}),u.push({count:n.length,subUnitId:i,value:a.getMatrix()})}),u?this._commandService.executeCommand(s.id,{unitId:n,replacements:u}):{success:0,failure:0}}_getReplacedCellData(e,n,r,i,a,o){var s;let{startRow:c,startColumn:l}=e.range.range,u=n.getCellRaw(c,l);if(e.isFormula)return r?{f:u.f.replace(t.regexp.createLiteralRegExp(i,o),a),v:null}:null;if((s=u.p)!=null&&s.body){let e=t.Tools.deepClone(u.p);return(0,t.replaceInDocumentBody)(e.body,i,a,this._query.caseSensitive),{p:e}}return{v:u.v.toString().replace(t.regexp.createLiteralRegExp(i,o),a)}}};C=x([b(2,t.IUniverInstanceService),b(3,r.IRenderManagerService),b(4,t.ICommandService),b(5,t.IContextService),b(6,(0,t.Inject)(t.ThemeService)),b(7,(0,t.Inject)(n.SheetsSelectionsService))],C);let w=class extends t.Disposable{constructor(e,t,n){super(),this._univerInstanceService=e,this._renderManagerService=t,this._injector=n,f(this,`capabilities`,{caseSensitive:!0,matchesTheWholeWord:!1,matchesTheWholeCell:!0,findDirection:!0,findScope:!0,findBy:!0}),f(this,`_findModelsByUnitId`,new Map)}isSupported(e){return e.type===t.UniverInstanceType.UNIVER_SHEET}async find(e){this._terminate();let n=this._univerInstanceService.getCurrentUnitOfType(t.UniverInstanceType.UNIVER_SHEET);if(!n)return[];let r=this._preprocessQuery(e),i=this._renderManagerService.getRenderUnitById(n.getUnitId()).with(a.SheetSkeletonManagerService),o=this._injector.createInstance(C,n,i);return this._findModelsByUnitId.set(n.getUnitId(),o),o.start(r),[o]}terminate(){this._terminate()}_terminate(){this._findModelsByUnitId.forEach(e=>e.dispose()),this._findModelsByUnitId.clear()}_preprocessQuery(e){let t=e.caseSensitive?e.findString:e.findString.toLowerCase();return t=t.trim(),{...e,findString:t}}};w=x([b(0,t.IUniverInstanceService),b(1,r.IRenderManagerService),b(2,(0,t.Inject)(t.Injector))],w);let T={hit:!1,replaceable:!1,isFormula:!1,rawData:null};function E(e,t,n,r,a){let{findBy:o}=r,s=o===i.FindBy.FORMULA,c=e.getCellRaw(t,n);return T.rawData=c,c!=null&&c.f?(T.isFormula=!0,s?D({v:c.f},r)?(T.hit=!0,T.replaceable=!0,T):(T.hit=!1,T.replaceable=!1,T):(T.replaceable=!1,D(a,r)?T.hit=!0:T.hit=!1,T)):(T.isFormula=!1,D(a,r)?c?(T.hit=!0,T.replaceable=!0):(T.hit=!0,T.replaceable=!1):(T.hit=!1,T.replaceable=!1),T)}function D(e,t){let n=O(e);return n?t.matchesTheWholeCell?(n=k(n),t.caseSensitive?n===t.findString:n.toLowerCase()===t.findString):t.caseSensitive?n.indexOf(t.findString)>-1:n.toLowerCase().indexOf(t.findString)>-1:!1}function O(e){var t,n;let r=(t=e==null||(n=e.p)==null||(n=n.body)==null?void 0:n.dataStream)==null?e==null?void 0:e.v:t;return typeof r==`number`?`${r}`:typeof r==`boolean`?r?`1`:`0`:r}function k(e){return e.replace(/^ +/g,``).replace(/ +$/g,``)}var A=`@univerjs/sheets-find-replace`,j=`1.0.0-alpha.8`;let M={},N=class extends t.Plugin{constructor(e=M,n,r){super(),this._config=e,this._injector=n,this._configService=r;let{...i}=(0,t.merge)({},M,this._config);this._configService.setConfig(`sheets-find-replace.config`,i)}onStarting(){[[S]].forEach(e=>this._injector.add(e))}onSteady(){this._injector.get(S)}};f(N,`pluginName`,`SHEET_FIND_REPLACE_PLUGIN`),f(N,`packageName`,A),f(N,`version`,j),f(N,`type`,t.UniverInstanceType.UNIVER_SHEET),N=x([(0,t.DependentOn)(r.UniverRenderEnginePlugin,n.UniverSheetsPlugin,i.UniverFindReplacePlugin,a.UniverSheetsUIPlugin),b(1,(0,t.Inject)(t.Injector)),b(2,t.IConfigService)],N),e.SheetReplaceCommand=s,Object.defineProperty(e,"SheetsFindReplaceController",{enumerable:!0,get:function(){return S}}),Object.defineProperty(e,"UniverSheetsFindReplacePlugin",{enumerable:!0,get:function(){return N}})});
|
|
1
|
+
(function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require("@univerjs/core"),require("@univerjs/sheets"),require("@univerjs/engine-render"),require("@univerjs/find-replace"),require("@univerjs/sheets-ui"),require("rxjs")):typeof define==`function`&&define.amd?define([`exports`,`@univerjs/core`,`@univerjs/sheets`,`@univerjs/engine-render`,`@univerjs/find-replace`,`@univerjs/sheets-ui`,`rxjs`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.UniverSheetsFindReplace={},e.UniverCore,e.UniverSheets,e.UniverEngineRender,e.UniverFindReplace,e.UniverSheetsUi,e.rxjs))})(this,function(e,t,n,r,i,a,o){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});let s={id:`sheet.command.replace`,type:t.CommandType.COMMAND,handler:async(e,r)=>{let i=e.get(t.IUndoRedoService),a=e.get(t.ICommandService),{unitId:o,replacements:s}=r,l=i.__tempBatchingUndoRedo(o),u=await Promise.all(s.map(e=>a.executeCommand(n.SetRangeValuesCommand.id,{unitId:o,subUnitId:e.subUnitId,value:e.value})));return l.dispose(),c(u,s)}};function c(e,t){let n=0,r=0;return e.forEach((e,i)=>{let a=t[i].count;e?n+=a:r+=a}),{success:n,failure:r}}function l(e){"@babel/helpers - typeof";return l=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},l(e)}function u(e,t){if(l(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(l(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function d(e){var t=u(e,`string`);return l(t)==`symbol`?t:t+``}function f(e,t,n){return(t=d(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}var p=class extends r.Shape{constructor(e,t){super(e,t),f(this,`_activated`,!1),f(this,`_inHiddenRange`,!1),f(this,`_color`,void 0),t&&this.setShapeProps(t)}setShapeProps(e){this._activated=!!e.activated,e.inHiddenRange!==void 0&&(this._inHiddenRange=e.inHiddenRange),e.color!==void 0&&(this._color=e.color),this.transformByState({width:e.width,height:e.height})}_draw(e){let t=this._activated,n=`rgba(${this._color.r}, ${this._color.g}, ${this._color.b}, 0.35)`,i=`rgb(${this._color.r}, ${this._color.g}, ${this._color.b})`;r.Rect.drawWith(e,{width:this.width,height:this.height,fill:n,stroke:t?i:void 0,strokeWidth:t?2:0,evented:!1})}};function m(e,t){return e.startRow===t.startRow&&e.startColumn===t.startColumn}function h(e,t){return e.startRow<t.startRow||e.startRow===t.startRow&&e.startColumn<=t.startColumn}function g(e,t){return e.startColumn<t.startColumn||e.startColumn===t.startColumn&&e.startRow<=t.startRow}function _(e,t){return e.startRow>t.startRow||e.startRow===t.startRow&&e.startColumn>=t.startColumn}function v(e,t){return e.startColumn>t.startColumn||e.startColumn===t.startColumn&&e.startRow>=t.startRow}function y(e,n){let{range:r}=e,{startRow:i,startColumn:a}=r,o=n.getMergedCell(i,a);return o?t.Rectangle.equals(r,o):r.endRow===r.startRow&&r.endColumn===r.startColumn}function b(e,t){return function(n,r){t(n,r,e)}}function x(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}let S=class extends t.Disposable{constructor(e,t,n,r,i){super(),this._injector=e,this._findReplaceController=t,this._contextService=n,this._findReplaceService=r,this._commandService=i,f(this,`_provider`,void 0),this._init(),this._initCommands()}dispose(){super.dispose(),this._findReplaceController.closePanel(),this._provider.dispose()}_init(){let e=this._injector.createInstance(w);this._provider=e,this.disposeWithMe(this._findReplaceService.registerFindReplaceProvider(e)),this.disposeWithMe(this._contextService.subscribeContextValue$(t.EDITOR_ACTIVATED).pipe((0,o.filter)(e=>!!e)).subscribe(()=>this._findReplaceController.closePanel()))}_initCommands(){[s].forEach(e=>this.disposeWithMe(this._commandService.registerCommand(e)))}};S=x([b(0,(0,t.Inject)(t.Injector)),b(1,(0,t.Inject)(i.FindReplaceController)),b(2,t.IContextService),b(3,i.IFindReplaceService),b(4,t.ICommandService)],S);let C=class extends i.FindModel{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}constructor(e,t,n,r,i,a,s,c){super(),this._workbook=e,this._sheetSkeletonManagerService=t,this._univerInstanceService=n,this._renderManagerService=r,this._commandService=i,this._contextService=a,this._themeService=s,f(this,`_matchesUpdate$`,new o.Subject),f(this,`matchesUpdate$`,this._matchesUpdate$.asObservable()),f(this,`_activelyChangingMatch$`,new o.Subject),f(this,`activelyChangingMatch$`,this._activelyChangingMatch$.asObservable()),f(this,`_matchesByWorksheet`,new Map),f(this,`_matches`,[]),f(this,`_matchesPosition`,0),f(this,`_activeHighlightIndex`,-1),f(this,`_highlightShapes`,[]),f(this,`_currentHighlightShape`,null),f(this,`_query`,null),f(this,`_workbookSelections`,void 0),this._workbookSelections=c.getWorkbookSelections(this.unitId)}dispose(){super.dispose(),this._disposeHighlights(),this._toggleDisplayRawFormula(!1)}getMatches(){return this._matches}start(e){switch(this._query=e,e.findBy===i.FindBy.FORMULA?this._toggleDisplayRawFormula(!0):this._toggleDisplayRawFormula(!1),e.findScope){case i.FindScope.UNIT:this.findInWorkbook(e);break;case i.FindScope.SUBUNIT:default:this.findInActiveWorksheet(e);break}}focusSelection(){let e=this.currentMatch;e&&this._commandService.executeCommand(n.SelectRangeCommand.id,{unitId:e.unitId,subUnit:e.range.subUnitId,range:e.range.range})}_toggleDisplayRawFormula(e){this._contextService.setContextValue(r.RENDER_RAW_FORMULA_KEY,e)}findInWorkbook(e){let r=this._workbook.getUnitId(),i,a=!0,s=()=>{let t=this._workbook.getSheets().filter(e=>!e.isSheetHidden()).map(t=>{let n=this._findInWorksheet(t,e,r),i=t.getSheetId(),{results:a}=n;return a.length?this._matchesByWorksheet.set(i,n.results):this._matchesByWorksheet.delete(i),n});this._matches=t.map(e=>e.results).flat(),this._updateFindHighlight(),a?(i={results:this._matches},a=!1):this._matchesUpdate$.next(this._matches)};return this.disposeWithMe(this._sheetSkeletonManagerService.currentSkeleton$.subscribe(()=>{this._updateFindHighlight(),this._updateCurrentHighlightShape(this._activeHighlightIndex)})),this.disposeWithMe((0,t.fromCallback)(this._commandService.onCommandExecuted.bind(this._commandService)).pipe((0,o.filter)(([e,t])=>e.id===n.SetWorksheetActiveOperation.id&&!(t!=null&&t.fromFindReplace))).subscribe(()=>{let e=this._workbook.getActiveSheet();if(!e)return;let t=e.getSheetId();this._matchesByWorksheet.has(t)&&this._findNextMatchOnActiveSheetChange(e)})),this.disposeWithMe((0,t.fromCallback)(this._commandService.onCommandExecuted.bind(this._commandService)).pipe((0,o.filter)(([e])=>e.type===t.CommandType.MUTATION&&e.params.unitId===this._workbook.getUnitId()),(0,o.throttleTime)(600,void 0,{leading:!1,trailing:!0})).subscribe(()=>s())),s(),i}_findNextMatchOnActiveSheetChange(e){let t,n,r=0,i=this._matchesByWorksheet.get(e.getSheetId()),a=this._workbookSelections.getCurrentSelections();a!=null&&a.length?([t,r]=this._findNextMatchByRange(i,a[0].range),n=i.findIndex(e=>e===t)):(t=i[0],n=0,r=this._matches.findIndex(e=>e===t)),this._matchesPosition=r+1,this._activelyChangingMatch$.next(t),this._activeHighlightIndex=n,this._updateFindHighlight(),this._updateCurrentHighlightShape(n)}findInActiveWorksheet(e){let r=this._workbook.getUnitId(),i=()=>{let e=this._workbook.getActiveSheet();if(!e)return!1;let t=this._workbookSelections.getCurrentSelections();return(t==null?void 0:t.some(t=>!y(t,e)))??!1},a,s=!0,c=!1,l=()=>{let t=this._workbook.getActiveSheet();if(!t)return{results:[]};let n=this.currentMatch;c=i();let o=this._workbookSelections.getCurrentSelections(),l=c?this._findInSelections(t,o,e,r):this._findInWorksheet(t,e,r);return this._matches=l.results,this._matchesPosition=this._tryRestoreLastMatchesPosition(n,this._matches),s?(a=l,s=!1):this._matchesUpdate$.next(this._matches),this._updateFindHighlight(),l};return this.disposeWithMe(this._sheetSkeletonManagerService.currentSkeleton$.subscribe(()=>this._updateFindHighlight())),this.disposeWithMe((0,o.merge)((0,t.fromCallback)(this._commandService.onCommandExecuted.bind(this._commandService)).pipe((0,o.filter)(([e])=>{if(e.type===t.CommandType.MUTATION&&e.params.unitId===this._workbook.getUnitId())return!0;if(e.id===n.SetSelectionsOperation.id&&e.params.unitId===r){let e=i();return e===!1&&c===!1?!1:(c=e,!0)}return!1})),this._workbook.activeSheet$.pipe((0,o.skip)(1))).pipe((0,o.debounceTime)(200)).subscribe(()=>l())),l(),a}_findInRange(e,t,n,r,a){let o=[],s=e.getSheetId(),c=(t.findDirection===i.FindDirection.COLUMN?e.iterateByColumn:e.iterateByRow).bind(e)(n);for(let n of c){let{row:i,col:c,colSpan:l,rowSpan:u,value:d}=n;if(a!=null&&a(i,c)||!d||e.getRowFiltered(i))continue;let{hit:f,replaceable:p,isFormula:m}=E(e,i,c,t,d);if(f){let e={provider:`sheets-find-replace-provider`,unitId:r,replaceable:p,isFormula:m,range:{subUnitId:s,range:{startRow:i,startColumn:c,endColumn:c+(l??1)-1,endRow:i+(u??1)-1}}};o.push(e)}}return{results:o}}_findInSelections(e,t,n,r){let{findDirection:a}=n,o=a===i.FindDirection.ROW?h:g,s=new Set;return{results:t.map(t=>this._findInRange(e,n,t.range,r,(e,t)=>{let n=`${e}-${t}`;return s.has(n)?!0:(s.add(n),!1)}).results).flat().sort((e,t)=>o(e.range.range,t.range.range)?-1:1)}}_findInWorksheet(e,t,n){let r=e.getRowCount(),i=e.getColumnCount(),a={startRow:0,startColumn:0,endRow:r-1,endColumn:i-1};return this._findInRange(e,t,a,n)}_disposeHighlights(){var e;this._highlightShapes.forEach(e=>{var t;(t=e.getScene())==null||t.makeDirty(),e.dispose()}),this._highlightShapes=[],(e=this._currentHighlightShape)==null||e.dispose(),this._currentHighlightShape=null}_updateFindHighlight(){this._disposeHighlights();let e=this._sheetSkeletonManagerService.getCurrentSkeleton();if(!e)return;let n=this._workbook.getUnitId(),r=this._renderManagerService.getRenderUnitById(n);if(r==null)return;let{scene:i}=r,o=this._matches,s=new t.ColorKit(this._themeService.getColorFromTheme(`yellow.400`)).toRgb(),c=this._workbook.getActiveSheet();if(!c)return;let l=c.getSheetId(),u=o.filter(e=>e.range.subUnitId===l).map((t,n)=>{let{startColumn:r,startRow:o,endColumn:l,endRow:u}=t.range.range,d=(0,a.getCoordByCell)(o,r,i,e),f=(0,a.getCoordByCell)(u,l,i,e),{startX:m,startY:h}=d,{endX:g,endY:_}=f,v=!0;for(let e=o;e<=u;e++)if(c.getRowRawVisible(e)){v=!1;break}let y=!0;for(let e=r;e<=l;e++)if(c.getColVisible(e)){y=!1;break}let b=v||y,x=y?2:g-m,S=v?2:_-h,C={left:m,top:h,color:s,width:x,height:S,evented:!1,inHiddenRange:b,zIndex:1e4};return new p(`find-highlight-${n}`,C)});i.addObjects(u),this._highlightShapes=u,i.makeDirty()}_updateCurrentHighlightShape(e){var t;if((t=this._currentHighlightShape)==null||t.setShapeProps({activated:!1}),this._currentHighlightShape=null,e!==void 0){let t=this._highlightShapes[e];if(!t)return;this._currentHighlightShape=t,t.setShapeProps({activated:!0})}}_getSheetObject(){return(0,a.getSheetObject)(this._univerInstanceService,this._renderManagerService)}async _focusMatch(e){var t;let{subUnitId:r,range:i}=e.range;if(r!==((t=this._workbook.getActiveSheet())==null?void 0:t.getSheetId())){let e=this._workbook.getUnitId();await this._commandService.executeCommand(n.SetWorksheetActivateCommand.id,{unitId:e,subUnitId:r},{fromFindReplace:!0})}this._commandService.executeCommand(a.ScrollToCellCommand.id,{range:i},{fromFindReplace:!0})}_tryRestoreLastMatchesPosition(e,t){if(!e)return 0;let{subUnitId:n}=e.range,{startColumn:r,startRow:i}=e.range.range,a=t.findIndex(e=>{if(n!==e.range.subUnitId)return!1;let{startColumn:t,startRow:a}=e.range.range;return t===r&&a===i});return a>-1?a+1:0}moveToNextMatch(e){if(!this._matches.length)return null;let t=(e==null?void 0:e.loop)??!1,n=(e==null?void 0:e.stayIfOnMatch)??!1,r=(e==null?void 0:e.noFocus)??!1,a=(e==null?void 0:e.ignoreSelection)??!1,o=this._findNextMatch(t,n,a);if(o){let[e,t]=o;return this._matchesPosition=t+1,this._query.findScope===i.FindScope.UNIT?this._activeHighlightIndex=this._matchesByWorksheet.get(e.range.subUnitId).findIndex(t=>t===e):this._activeHighlightIndex=t,r||this._focusMatch(e),this._updateCurrentHighlightShape(this._activeHighlightIndex),e}return this._matchesPosition=0,this._updateCurrentHighlightShape(),null}moveToPreviousMatch(e){if(!this._matches.length)return null;let t=(e==null?void 0:e.loop)??!1,n=(e==null?void 0:e.stayIfOnMatch)??!1,r=(e==null?void 0:e.noFocus)??!1,a=(e==null?void 0:e.ignoreSelection)??!1,o=this._findPreviousMatch(t,n,a);if(o){let[e,t]=o;return this._matchesPosition=t+1,this._query.findScope===i.FindScope.UNIT?this._activeHighlightIndex=this._matchesByWorksheet.get(e.range.subUnitId).findIndex(t=>t===e):this._activeHighlightIndex=t,r||this._focusMatch(e),this._updateCurrentHighlightShape(this._activeHighlightIndex),e}return this._matchesPosition=0,this._updateCurrentHighlightShape(),null}_findPreviousMatch(e=!1,t=!1,n=!1){var r;if(this.currentMatch){let n=this._matches.findIndex(e=>e===this.currentMatch);if(t)return[this.currentMatch,n];let r=n-1;if(!e&&r<0)return null;let i=this._matches.length,a=(r+i)%i;return[this._matches[a],a]}let a=this._workbookSelections.getCurrentLastSelection();if(n||!a){let e=this._matches.length-1;return[this._matches[e],e]}if(this._query.findScope!==i.FindScope.UNIT)return this._findPreviousMatchByRange(this._matches,a.range);let o=(r=this._workbook.getActiveSheet())==null?void 0:r.getSheetId();if(!o)return null;let s=this._findPreviousWorksheetThatHasAMatch(o,e);return s?this._findPreviousMatchByRange(this._matchesByWorksheet.get(s),a.range):null}_findNextMatch(e=!1,t=!1,n=!1){var r;if(this.currentMatch){let n=this._matches.findIndex(e=>e===this.currentMatch);if(t)return[this.currentMatch,n];let r=n+1,i=this._matches.length;if(!e&&r>=i)return null;let a=r%i;return[this._matches[a],a]}let a=this._workbookSelections.getCurrentLastSelection();if(n||!a)return[this._matches[0],0];if(this._query.findScope!==i.FindScope.UNIT)return this._findNextMatchByRange(this._matches,a.range,t);let o=(r=this._workbook.getActiveSheet())==null?void 0:r.getSheetId();if(!o)return null;let s=this._findNextWorksheetThatHasAMatch(o,e);return s?this._findNextMatchByRange(this._matchesByWorksheet.get(s),a.range):null}_findPreviousWorksheetThatHasAMatch(e,n=!1){let r=this._workbook.getSheetOrders(),i=r.findIndex(t=>t===e);return(n?(0,t.rotate)(r,i+1):r.slice(0,i+1)).findLast(e=>this._matchesByWorksheet.has(e))??null}_findNextWorksheetThatHasAMatch(e,n=!1){let r=this._workbook.getSheetOrders(),i=r.findIndex(t=>t===e);return(n?(0,t.rotate)(r,i):r.slice(i)).find(e=>this._matchesByWorksheet.has(e))??null}_findNextMatchByRange(e,t,n=!1){let r=this._query.findDirection===i.FindDirection.ROW,a=e.findIndex(e=>{let i=e.range.range;if(!(r?h(t,i):g(t,i)))return!1;let a=m(t,i);return n?a:!a});a===-1&&(a=e.length-1);let o=e[a];return[o,this._matches.findIndex(e=>e===o)]}_findPreviousMatchByRange(e,t,n=!1){let r=this._query.findDirection===i.FindDirection.ROW,a=this._matches.findLastIndex(e=>{let i=e.range.range;if(!(r?_(t,i):v(t,i)))return!1;let a=m(t,i);return n?a:!a});a===-1&&(a=0);let o=e[a];return[o,this._matches.findIndex(e=>e===o)]}async replace(e){if(this._matchesCount===0||!this.currentMatch||!this._query||!this.currentMatch.replaceable)return!1;let t=this.currentMatch.range,r=this._workbook.getSheetBySheetId(this.currentMatch.range.subUnitId),a=this._getReplacedCellData(this.currentMatch,r,this._query.findBy===i.FindBy.FORMULA,this._query.findString,e,this._query.caseSensitive?`g`:`ig`),o={unitId:this.currentMatch.unitId,subUnitId:t.subUnitId,value:{[t.range.startRow]:{[t.range.startColumn]:a}}};return this._commandService.executeCommand(n.SetRangeValuesCommand.id,o)}async replaceAll(e){if(this._matchesCount===0||!this._query)return{success:0,failure:0};let n=this._workbook.getUnitId(),{findString:r,caseSensitive:a,findBy:o}=this._query,c=o===i.FindBy.FORMULA,l=a?`g`:`ig`,u=[];return(0,t.groupBy)(this._matches.filter(e=>e.replaceable),e=>e.range.subUnitId).forEach((n,i)=>{let a=new t.ObjectMatrix,o=this._workbook.getSheetBySheetId(i);n.forEach(t=>{let{startColumn:n,startRow:i}=t.range.range,s=this._getReplacedCellData(t,o,c,r,e,l);s&&a.setValue(i,n,s)}),u.push({count:n.length,subUnitId:i,value:a.getMatrix()})}),u?this._commandService.executeCommand(s.id,{unitId:n,replacements:u}):{success:0,failure:0}}_getReplacedCellData(e,n,r,i,a,o){var s;let{startRow:c,startColumn:l}=e.range.range,u=n.getCellRaw(c,l);if(e.isFormula)return r?{f:u.f.replace(t.regexp.createLiteralRegExp(i,o),a),v:null}:null;if((s=u.p)!=null&&s.body){let e=t.Tools.deepClone(u.p);return(0,t.replaceInDocumentBody)(e.body,i,a,this._query.caseSensitive),{p:e}}return{v:u.v.toString().replace(t.regexp.createLiteralRegExp(i,o),a)}}};C=x([b(2,t.IUniverInstanceService),b(3,r.IRenderManagerService),b(4,t.ICommandService),b(5,t.IContextService),b(6,(0,t.Inject)(t.ThemeService)),b(7,(0,t.Inject)(n.SheetsSelectionsService))],C);let w=class extends t.Disposable{constructor(e,t,n){super(),this._univerInstanceService=e,this._renderManagerService=t,this._injector=n,f(this,`capabilities`,{caseSensitive:!0,matchesTheWholeWord:!1,matchesTheWholeCell:!0,findDirection:!0,findScope:!0,findBy:!0}),f(this,`_findModelsByUnitId`,new Map)}isSupported(e){return e.type===t.UniverInstanceType.UNIVER_SHEET}async find(e){this._terminate();let n=this._univerInstanceService.getCurrentUnitOfType(t.UniverInstanceType.UNIVER_SHEET);if(!n)return[];let r=this._preprocessQuery(e),i=this._renderManagerService.getRenderUnitById(n.getUnitId()).with(a.SheetSkeletonManagerService),o=this._injector.createInstance(C,n,i);return this._findModelsByUnitId.set(n.getUnitId(),o),o.start(r),[o]}terminate(){this._terminate()}_terminate(){this._findModelsByUnitId.forEach(e=>e.dispose()),this._findModelsByUnitId.clear()}_preprocessQuery(e){let t=e.caseSensitive?e.findString:e.findString.toLowerCase();return t=t.trim(),{...e,findString:t}}};w=x([b(0,t.IUniverInstanceService),b(1,r.IRenderManagerService),b(2,(0,t.Inject)(t.Injector))],w);let T={hit:!1,replaceable:!1,isFormula:!1,rawData:null};function E(e,t,n,r,a){let{findBy:o}=r,s=o===i.FindBy.FORMULA,c=e.getCellRaw(t,n);return T.rawData=c,c!=null&&c.f?(T.isFormula=!0,s?D({v:c.f},r)?(T.hit=!0,T.replaceable=!0,T):(T.hit=!1,T.replaceable=!1,T):(T.replaceable=!1,D(a,r)?T.hit=!0:T.hit=!1,T)):(T.isFormula=!1,D(a,r)?c?(T.hit=!0,T.replaceable=!0):(T.hit=!0,T.replaceable=!1):(T.hit=!1,T.replaceable=!1),T)}function D(e,t){let n=O(e);return n?t.matchesTheWholeCell?(n=k(n),t.caseSensitive?n===t.findString:n.toLowerCase()===t.findString):t.caseSensitive?n.indexOf(t.findString)>-1:n.toLowerCase().indexOf(t.findString)>-1:!1}function O(e){var t;let n=(e==null||(t=e.p)==null||(t=t.body)==null?void 0:t.dataStream)??(e==null?void 0:e.v);return typeof n==`number`?`${n}`:typeof n==`boolean`?n?`1`:`0`:n}function k(e){return e.replace(/^ +/g,``).replace(/ +$/g,``)}var A=`@univerjs/sheets-find-replace`,j=`1.0.0-beta.0`;let M={},N=class extends t.Plugin{constructor(e=M,n,r){super(),this._config=e,this._injector=n,this._configService=r;let{...i}=(0,t.merge)({},M,this._config);this._configService.setConfig(`sheets-find-replace.config`,i)}onStarting(){[[S]].forEach(e=>this._injector.add(e))}onSteady(){this._injector.get(S)}};f(N,`pluginName`,`SHEET_FIND_REPLACE_PLUGIN`),f(N,`packageName`,A),f(N,`version`,j),f(N,`type`,t.UniverInstanceType.UNIVER_SHEET),N=x([(0,t.DependentOn)(r.UniverRenderEnginePlugin,n.UniverSheetsPlugin,i.UniverFindReplacePlugin,a.UniverSheetsUIPlugin),b(1,(0,t.Inject)(t.Injector)),b(2,t.IConfigService)],N),e.SheetReplaceCommand=s,Object.defineProperty(e,"SheetsFindReplaceController",{enumerable:!0,get:function(){return S}}),Object.defineProperty(e,"UniverSheetsFindReplacePlugin",{enumerable:!0,get:function(){return N}})});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@univerjs/sheets-find-replace",
|
|
3
|
-
"version": "1.0.0-
|
|
3
|
+
"version": "1.0.0-beta.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Find and replace integration for Univer Sheets.",
|
|
6
6
|
"author": "DreamNum Co., Ltd. <developer@univer.ai>",
|
|
@@ -62,17 +62,17 @@
|
|
|
62
62
|
"rxjs": ">=7.0.0"
|
|
63
63
|
},
|
|
64
64
|
"dependencies": {
|
|
65
|
-
"@univerjs/
|
|
66
|
-
"@univerjs/
|
|
67
|
-
"@univerjs/
|
|
68
|
-
"@univerjs/sheets": "1.0.0-
|
|
69
|
-
"@univerjs/
|
|
65
|
+
"@univerjs/core": "1.0.0-beta.0",
|
|
66
|
+
"@univerjs/engine-render": "1.0.0-beta.0",
|
|
67
|
+
"@univerjs/find-replace": "1.0.0-beta.0",
|
|
68
|
+
"@univerjs/sheets-ui": "1.0.0-beta.0",
|
|
69
|
+
"@univerjs/sheets": "1.0.0-beta.0"
|
|
70
70
|
},
|
|
71
71
|
"devDependencies": {
|
|
72
72
|
"rxjs": "^7.8.2",
|
|
73
73
|
"typescript": "^6.0.3",
|
|
74
74
|
"vitest": "^4.1.10",
|
|
75
|
-
"@univerjs-infra/shared": "1.0.0-
|
|
75
|
+
"@univerjs-infra/shared": "1.0.0-beta.0"
|
|
76
76
|
},
|
|
77
77
|
"scripts": {
|
|
78
78
|
"test": "vitest run",
|