roosterjs-content-model-plugins 9.40.0 → 9.41.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/announce/AnnouncePlugin.d.ts +32 -0
- package/lib/announce/AnnouncePlugin.js +66 -0
- package/lib/announce/AnnouncePlugin.js.map +1 -0
- package/lib/announce/tableSelectionUtils.d.ts +17 -0
- package/lib/announce/tableSelectionUtils.js +72 -0
- package/lib/announce/tableSelectionUtils.js.map +1 -0
- package/lib/findReplace/FindReplacePlugin.d.ts +42 -0
- package/lib/findReplace/FindReplacePlugin.js +97 -0
- package/lib/findReplace/FindReplacePlugin.js.map +1 -0
- package/lib/findReplace/createFindReplaceContext.d.ts +8 -0
- package/lib/findReplace/createFindReplaceContext.js +26 -0
- package/lib/findReplace/createFindReplaceContext.js.map +1 -0
- package/lib/findReplace/find.d.ts +11 -0
- package/lib/findReplace/find.js +20 -0
- package/lib/findReplace/find.js.map +1 -0
- package/lib/findReplace/moveHighlight.d.ts +9 -0
- package/lib/findReplace/moveHighlight.js +21 -0
- package/lib/findReplace/moveHighlight.js.map +1 -0
- package/lib/findReplace/replace.d.ts +10 -0
- package/lib/findReplace/replace.js +48 -0
- package/lib/findReplace/replace.js.map +1 -0
- package/lib/findReplace/types/FindReplaceContext.d.ts +38 -0
- package/lib/findReplace/types/FindReplaceContext.js +3 -0
- package/lib/findReplace/types/FindReplaceContext.js.map +1 -0
- package/lib/findReplace/types/FindReplaceHighlightOptions.d.ts +13 -0
- package/lib/findReplace/types/FindReplaceHighlightOptions.js +3 -0
- package/lib/findReplace/types/FindReplaceHighlightOptions.js.map +1 -0
- package/lib/findReplace/types/HighlightHelper.d.ts +23 -0
- package/lib/findReplace/types/HighlightHelper.js +3 -0
- package/lib/findReplace/types/HighlightHelper.js.map +1 -0
- package/lib/findReplace/utils/HighlightHelperImpl.d.ts +9 -0
- package/lib/findReplace/utils/HighlightHelperImpl.js +65 -0
- package/lib/findReplace/utils/HighlightHelperImpl.js.map +1 -0
- package/lib/findReplace/utils/constants.d.ts +28 -0
- package/lib/findReplace/utils/constants.js +32 -0
- package/lib/findReplace/utils/constants.js.map +1 -0
- package/lib/findReplace/utils/replaceTextInRange.d.ts +4 -0
- package/lib/findReplace/utils/replaceTextInRange.js +71 -0
- package/lib/findReplace/utils/replaceTextInRange.js.map +1 -0
- package/lib/findReplace/utils/setMarkedIndex.d.ts +6 -0
- package/lib/findReplace/utils/setMarkedIndex.js +29 -0
- package/lib/findReplace/utils/setMarkedIndex.js.map +1 -0
- package/lib/findReplace/utils/sortRanges.d.ts +5 -0
- package/lib/findReplace/utils/sortRanges.js +23 -0
- package/lib/findReplace/utils/sortRanges.js.map +1 -0
- package/lib/findReplace/utils/updateHighlight.d.ts +6 -0
- package/lib/findReplace/utils/updateHighlight.js +48 -0
- package/lib/findReplace/utils/updateHighlight.js.map +1 -0
- package/lib/index.d.ts +9 -0
- package/lib/index.js +13 -1
- package/lib/index.js.map +1 -1
- package/lib/shortcut/shortcuts.js +15 -3
- package/lib/shortcut/shortcuts.js.map +1 -1
- package/lib-amd/announce/AnnouncePlugin.d.ts +32 -0
- package/lib-amd/announce/AnnouncePlugin.js +67 -0
- package/lib-amd/announce/AnnouncePlugin.js.map +1 -0
- package/lib-amd/announce/tableSelectionUtils.d.ts +17 -0
- package/lib-amd/announce/tableSelectionUtils.js +74 -0
- package/lib-amd/announce/tableSelectionUtils.js.map +1 -0
- package/lib-amd/findReplace/FindReplacePlugin.d.ts +42 -0
- package/lib-amd/findReplace/FindReplacePlugin.js +96 -0
- package/lib-amd/findReplace/FindReplacePlugin.js.map +1 -0
- package/lib-amd/findReplace/createFindReplaceContext.d.ts +8 -0
- package/lib-amd/findReplace/createFindReplaceContext.js +26 -0
- package/lib-amd/findReplace/createFindReplaceContext.js.map +1 -0
- package/lib-amd/findReplace/find.d.ts +11 -0
- package/lib-amd/findReplace/find.js +21 -0
- package/lib-amd/findReplace/find.js.map +1 -0
- package/lib-amd/findReplace/moveHighlight.d.ts +9 -0
- package/lib-amd/findReplace/moveHighlight.js +22 -0
- package/lib-amd/findReplace/moveHighlight.js.map +1 -0
- package/lib-amd/findReplace/replace.d.ts +10 -0
- package/lib-amd/findReplace/replace.js +47 -0
- package/lib-amd/findReplace/replace.js.map +1 -0
- package/lib-amd/findReplace/types/FindReplaceContext.d.ts +38 -0
- package/lib-amd/findReplace/types/FindReplaceContext.js +5 -0
- package/lib-amd/findReplace/types/FindReplaceContext.js.map +1 -0
- package/lib-amd/findReplace/types/FindReplaceHighlightOptions.d.ts +13 -0
- package/lib-amd/findReplace/types/FindReplaceHighlightOptions.js +5 -0
- package/lib-amd/findReplace/types/FindReplaceHighlightOptions.js.map +1 -0
- package/lib-amd/findReplace/types/HighlightHelper.d.ts +23 -0
- package/lib-amd/findReplace/types/HighlightHelper.js +5 -0
- package/lib-amd/findReplace/types/HighlightHelper.js.map +1 -0
- package/lib-amd/findReplace/utils/HighlightHelperImpl.d.ts +9 -0
- package/lib-amd/findReplace/utils/HighlightHelperImpl.js +66 -0
- package/lib-amd/findReplace/utils/HighlightHelperImpl.js.map +1 -0
- package/lib-amd/findReplace/utils/constants.d.ts +28 -0
- package/lib-amd/findReplace/utils/constants.js +34 -0
- package/lib-amd/findReplace/utils/constants.js.map +1 -0
- package/lib-amd/findReplace/utils/replaceTextInRange.d.ts +4 -0
- package/lib-amd/findReplace/utils/replaceTextInRange.js +72 -0
- package/lib-amd/findReplace/utils/replaceTextInRange.js.map +1 -0
- package/lib-amd/findReplace/utils/setMarkedIndex.d.ts +6 -0
- package/lib-amd/findReplace/utils/setMarkedIndex.js +30 -0
- package/lib-amd/findReplace/utils/setMarkedIndex.js.map +1 -0
- package/lib-amd/findReplace/utils/sortRanges.d.ts +5 -0
- package/lib-amd/findReplace/utils/sortRanges.js +25 -0
- package/lib-amd/findReplace/utils/sortRanges.js.map +1 -0
- package/lib-amd/findReplace/utils/updateHighlight.d.ts +6 -0
- package/lib-amd/findReplace/utils/updateHighlight.js +46 -0
- package/lib-amd/findReplace/utils/updateHighlight.js.map +1 -0
- package/lib-amd/index.d.ts +9 -0
- package/lib-amd/index.js +8 -2
- package/lib-amd/index.js.map +1 -1
- package/lib-amd/shortcut/shortcuts.js +15 -3
- package/lib-amd/shortcut/shortcuts.js.map +1 -1
- package/lib-mjs/announce/AnnouncePlugin.d.ts +32 -0
- package/lib-mjs/announce/AnnouncePlugin.js +63 -0
- package/lib-mjs/announce/AnnouncePlugin.js.map +1 -0
- package/lib-mjs/announce/tableSelectionUtils.d.ts +17 -0
- package/lib-mjs/announce/tableSelectionUtils.js +67 -0
- package/lib-mjs/announce/tableSelectionUtils.js.map +1 -0
- package/lib-mjs/findReplace/FindReplacePlugin.d.ts +42 -0
- package/lib-mjs/findReplace/FindReplacePlugin.js +94 -0
- package/lib-mjs/findReplace/FindReplacePlugin.js.map +1 -0
- package/lib-mjs/findReplace/createFindReplaceContext.d.ts +8 -0
- package/lib-mjs/findReplace/createFindReplaceContext.js +22 -0
- package/lib-mjs/findReplace/createFindReplaceContext.js.map +1 -0
- package/lib-mjs/findReplace/find.d.ts +11 -0
- package/lib-mjs/findReplace/find.js +16 -0
- package/lib-mjs/findReplace/find.js.map +1 -0
- package/lib-mjs/findReplace/moveHighlight.d.ts +9 -0
- package/lib-mjs/findReplace/moveHighlight.js +17 -0
- package/lib-mjs/findReplace/moveHighlight.js.map +1 -0
- package/lib-mjs/findReplace/replace.d.ts +10 -0
- package/lib-mjs/findReplace/replace.js +44 -0
- package/lib-mjs/findReplace/replace.js.map +1 -0
- package/lib-mjs/findReplace/types/FindReplaceContext.d.ts +38 -0
- package/lib-mjs/findReplace/types/FindReplaceContext.js +2 -0
- package/lib-mjs/findReplace/types/FindReplaceContext.js.map +1 -0
- package/lib-mjs/findReplace/types/FindReplaceHighlightOptions.d.ts +13 -0
- package/lib-mjs/findReplace/types/FindReplaceHighlightOptions.js +2 -0
- package/lib-mjs/findReplace/types/FindReplaceHighlightOptions.js.map +1 -0
- package/lib-mjs/findReplace/types/HighlightHelper.d.ts +23 -0
- package/lib-mjs/findReplace/types/HighlightHelper.js +2 -0
- package/lib-mjs/findReplace/types/HighlightHelper.js.map +1 -0
- package/lib-mjs/findReplace/utils/HighlightHelperImpl.d.ts +9 -0
- package/lib-mjs/findReplace/utils/HighlightHelperImpl.js +61 -0
- package/lib-mjs/findReplace/utils/HighlightHelperImpl.js.map +1 -0
- package/lib-mjs/findReplace/utils/constants.d.ts +28 -0
- package/lib-mjs/findReplace/utils/constants.js +29 -0
- package/lib-mjs/findReplace/utils/constants.js.map +1 -0
- package/lib-mjs/findReplace/utils/replaceTextInRange.d.ts +4 -0
- package/lib-mjs/findReplace/utils/replaceTextInRange.js +67 -0
- package/lib-mjs/findReplace/utils/replaceTextInRange.js.map +1 -0
- package/lib-mjs/findReplace/utils/setMarkedIndex.d.ts +6 -0
- package/lib-mjs/findReplace/utils/setMarkedIndex.js +25 -0
- package/lib-mjs/findReplace/utils/setMarkedIndex.js.map +1 -0
- package/lib-mjs/findReplace/utils/sortRanges.d.ts +5 -0
- package/lib-mjs/findReplace/utils/sortRanges.js +19 -0
- package/lib-mjs/findReplace/utils/sortRanges.js.map +1 -0
- package/lib-mjs/findReplace/utils/updateHighlight.d.ts +6 -0
- package/lib-mjs/findReplace/utils/updateHighlight.js +44 -0
- package/lib-mjs/findReplace/utils/updateHighlight.js.map +1 -0
- package/lib-mjs/index.d.ts +9 -0
- package/lib-mjs/index.js +6 -0
- package/lib-mjs/index.js.map +1 -1
- package/lib-mjs/shortcut/shortcuts.js +15 -3
- package/lib-mjs/shortcut/shortcuts.js.map +1 -1
- package/package.json +5 -5
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { IEditor, PluginEvent, EditorPlugin } from 'roosterjs-content-model-types';
|
|
2
|
+
/**
|
|
3
|
+
* AnnouncePlugin helps editor announce table selection changes for accessibility
|
|
4
|
+
*/
|
|
5
|
+
export declare class AnnouncePlugin implements EditorPlugin {
|
|
6
|
+
private editor;
|
|
7
|
+
private previousSelection;
|
|
8
|
+
/**
|
|
9
|
+
* Get name of this plugin
|
|
10
|
+
*/
|
|
11
|
+
getName(): string;
|
|
12
|
+
/**
|
|
13
|
+
* The first method that editor will call to a plugin when editor is initializing.
|
|
14
|
+
* It will pass in the editor instance, plugin should take this chance to save the
|
|
15
|
+
* editor reference so that it can call to any editor method or format API later.
|
|
16
|
+
* @param editor The editor object
|
|
17
|
+
*/
|
|
18
|
+
initialize(editor: IEditor): void;
|
|
19
|
+
/**
|
|
20
|
+
* The last method that editor will call to a plugin before it is disposed.
|
|
21
|
+
* Plugin can take this chance to clear the reference to editor. After this method is
|
|
22
|
+
* called, plugin should not call to any editor method since it will result in error.
|
|
23
|
+
*/
|
|
24
|
+
dispose(): void;
|
|
25
|
+
/**
|
|
26
|
+
* Core method for a plugin. Once an event happens in editor, editor will call this
|
|
27
|
+
* method of each plugin to handle the event as long as the event is not handled
|
|
28
|
+
* exclusively by another plugin.
|
|
29
|
+
* @param event The event to handle:
|
|
30
|
+
*/
|
|
31
|
+
onPluginEvent(event: PluginEvent): void;
|
|
32
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AnnouncePlugin = void 0;
|
|
4
|
+
var tableSelectionUtils_1 = require("./tableSelectionUtils");
|
|
5
|
+
/**
|
|
6
|
+
* AnnouncePlugin helps editor announce table selection changes for accessibility
|
|
7
|
+
*/
|
|
8
|
+
var AnnouncePlugin = /** @class */ (function () {
|
|
9
|
+
function AnnouncePlugin() {
|
|
10
|
+
this.editor = null;
|
|
11
|
+
this.previousSelection = null;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Get name of this plugin
|
|
15
|
+
*/
|
|
16
|
+
AnnouncePlugin.prototype.getName = function () {
|
|
17
|
+
return 'Announce';
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* The first method that editor will call to a plugin when editor is initializing.
|
|
21
|
+
* It will pass in the editor instance, plugin should take this chance to save the
|
|
22
|
+
* editor reference so that it can call to any editor method or format API later.
|
|
23
|
+
* @param editor The editor object
|
|
24
|
+
*/
|
|
25
|
+
AnnouncePlugin.prototype.initialize = function (editor) {
|
|
26
|
+
this.editor = editor;
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* The last method that editor will call to a plugin before it is disposed.
|
|
30
|
+
* Plugin can take this chance to clear the reference to editor. After this method is
|
|
31
|
+
* called, plugin should not call to any editor method since it will result in error.
|
|
32
|
+
*/
|
|
33
|
+
AnnouncePlugin.prototype.dispose = function () {
|
|
34
|
+
this.editor = null;
|
|
35
|
+
this.previousSelection = null;
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* Core method for a plugin. Once an event happens in editor, editor will call this
|
|
39
|
+
* method of each plugin to handle the event as long as the event is not handled
|
|
40
|
+
* exclusively by another plugin.
|
|
41
|
+
* @param event The event to handle:
|
|
42
|
+
*/
|
|
43
|
+
AnnouncePlugin.prototype.onPluginEvent = function (event) {
|
|
44
|
+
var _a, _b;
|
|
45
|
+
if (!this.editor) {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
if (event.eventType == 'selectionChanged') {
|
|
49
|
+
if (((_a = event.newSelection) === null || _a === void 0 ? void 0 : _a.type) == 'table') {
|
|
50
|
+
var action = (0, tableSelectionUtils_1.getIsSelectingOrUnselecting)(((_b = this.previousSelection) === null || _b === void 0 ? void 0 : _b.type) == 'table' ? this.previousSelection : null, event.newSelection);
|
|
51
|
+
if (action && event.newSelection.tableSelectionInfo) {
|
|
52
|
+
this.editor.announce({
|
|
53
|
+
defaultStrings: action === 'unselecting' ? 'unselected' : 'selected',
|
|
54
|
+
formatStrings: [
|
|
55
|
+
(0, tableSelectionUtils_1.retrieveStringFromParsedTable)(event.newSelection.tableSelectionInfo),
|
|
56
|
+
],
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
this.previousSelection = event.newSelection;
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
return AnnouncePlugin;
|
|
64
|
+
}());
|
|
65
|
+
exports.AnnouncePlugin = AnnouncePlugin;
|
|
66
|
+
//# sourceMappingURL=AnnouncePlugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AnnouncePlugin.js","sourceRoot":"","sources":["../../../../packages/roosterjs-content-model-plugins/lib/announce/AnnouncePlugin.ts"],"names":[],"mappings":";;;AAAA,6DAAmG;AAQnG;;GAEG;AACH;IAAA;QACY,WAAM,GAAmB,IAAI,CAAC;QAC9B,sBAAiB,GAAwB,IAAI,CAAC;IA2D1D,CAAC;IAzDG;;OAEG;IACH,gCAAO,GAAP;QACI,OAAO,UAAU,CAAC;IACtB,CAAC;IAED;;;;;OAKG;IACH,mCAAU,GAAV,UAAW,MAAe;QACtB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACzB,CAAC;IAED;;;;OAIG;IACH,gCAAO,GAAP;QACI,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC;QACnB,IAAI,CAAC,iBAAiB,GAAG,IAAI,CAAC;IAClC,CAAC;IAED;;;;;OAKG;IACH,sCAAa,GAAb,UAAc,KAAkB;;QAC5B,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE;YACd,OAAO;SACV;QAED,IAAI,KAAK,CAAC,SAAS,IAAI,kBAAkB,EAAE;YACvC,IAAI,CAAA,MAAA,KAAK,CAAC,YAAY,0CAAE,IAAI,KAAI,OAAO,EAAE;gBACrC,IAAM,MAAM,GAAG,IAAA,iDAA2B,EACtC,CAAA,MAAA,IAAI,CAAC,iBAAiB,0CAAE,IAAI,KAAI,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC,CAAC,IAAI,EACvE,KAAK,CAAC,YAAY,CACrB,CAAC;gBACF,IAAI,MAAM,IAAI,KAAK,CAAC,YAAY,CAAC,kBAAkB,EAAE;oBACjD,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC;wBACjB,cAAc,EAAE,MAAM,KAAK,aAAa,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,UAAU;wBACpE,aAAa,EAAE;4BACX,IAAA,mDAA6B,EAAC,KAAK,CAAC,YAAY,CAAC,kBAAkB,CAAC;yBACvE;qBACJ,CAAC,CAAC;iBACN;aACJ;YAED,IAAI,CAAC,iBAAiB,GAAG,KAAK,CAAC,YAAY,CAAC;SAC/C;IACL,CAAC;IACL,qBAAC;AAAD,CAAC,AA7DD,IA6DC;AA7DY,wCAAc","sourcesContent":["import { getIsSelectingOrUnselecting, retrieveStringFromParsedTable } from './tableSelectionUtils';\nimport type {\n IEditor,\n PluginEvent,\n EditorPlugin,\n DOMSelection,\n} from 'roosterjs-content-model-types';\n\n/**\n * AnnouncePlugin helps editor announce table selection changes for accessibility\n */\nexport class AnnouncePlugin implements EditorPlugin {\n private editor: IEditor | null = null;\n private previousSelection: DOMSelection | null = null;\n\n /**\n * Get name of this plugin\n */\n getName() {\n return 'Announce';\n }\n\n /**\n * The first method that editor will call to a plugin when editor is initializing.\n * It will pass in the editor instance, plugin should take this chance to save the\n * editor reference so that it can call to any editor method or format API later.\n * @param editor The editor object\n */\n initialize(editor: IEditor) {\n this.editor = editor;\n }\n\n /**\n * The last method that editor will call to a plugin before it is disposed.\n * Plugin can take this chance to clear the reference to editor. After this method is\n * called, plugin should not call to any editor method since it will result in error.\n */\n dispose() {\n this.editor = null;\n this.previousSelection = null;\n }\n\n /**\n * Core method for a plugin. Once an event happens in editor, editor will call this\n * method of each plugin to handle the event as long as the event is not handled\n * exclusively by another plugin.\n * @param event The event to handle:\n */\n onPluginEvent(event: PluginEvent) {\n if (!this.editor) {\n return;\n }\n\n if (event.eventType == 'selectionChanged') {\n if (event.newSelection?.type == 'table') {\n const action = getIsSelectingOrUnselecting(\n this.previousSelection?.type == 'table' ? this.previousSelection : null,\n event.newSelection\n );\n if (action && event.newSelection.tableSelectionInfo) {\n this.editor.announce({\n defaultStrings: action === 'unselecting' ? 'unselected' : 'selected',\n formatStrings: [\n retrieveStringFromParsedTable(event.newSelection.tableSelectionInfo),\n ],\n });\n }\n }\n\n this.previousSelection = event.newSelection;\n }\n }\n}\n"]}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { TableSelectionInfo, TableSelection } from 'roosterjs-content-model-types';
|
|
2
|
+
/**
|
|
3
|
+
* @internal
|
|
4
|
+
* Retrieves text content from selected table cells in a parsed table structure
|
|
5
|
+
* @param tsInfo Table selection information containing the parsed table and coordinates
|
|
6
|
+
* @returns Combined text content from all selected cells, separated by spaces
|
|
7
|
+
*/
|
|
8
|
+
export declare function retrieveStringFromParsedTable(tsInfo: TableSelectionInfo): string;
|
|
9
|
+
/**
|
|
10
|
+
* @internal
|
|
11
|
+
* Determines whether the table selection is expanding (selecting more) or contracting (selecting less)
|
|
12
|
+
* @param prevTableSelection Previous table selection object containing firstRow, lastRow, firstColumn, and lastColumn properties
|
|
13
|
+
* @param firstCo Current first coordinate of the selection (with row, col properties)
|
|
14
|
+
* @param lastCo Current last coordinate of the selection (with row, col properties)
|
|
15
|
+
* @returns 'selecting' if expanding selection, 'unselecting' if contracting, or null if no change
|
|
16
|
+
*/
|
|
17
|
+
export declare function getIsSelectingOrUnselecting(prevTableSelection: TableSelection | null, newTableSelection: TableSelection): 'selecting' | 'unselecting' | null;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getIsSelectingOrUnselecting = exports.retrieveStringFromParsedTable = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* @internal
|
|
6
|
+
* Retrieves text content from selected table cells in a parsed table structure
|
|
7
|
+
* @param tsInfo Table selection information containing the parsed table and coordinates
|
|
8
|
+
* @returns Combined text content from all selected cells, separated by spaces
|
|
9
|
+
*/
|
|
10
|
+
function retrieveStringFromParsedTable(tsInfo) {
|
|
11
|
+
var parsedTable = tsInfo.parsedTable, firstCo = tsInfo.firstCo, lastCo = tsInfo.lastCo;
|
|
12
|
+
var result = '';
|
|
13
|
+
if (lastCo) {
|
|
14
|
+
for (var r = firstCo.row; r <= lastCo.row; r++) {
|
|
15
|
+
for (var c = firstCo.col; c <= lastCo.col; c++) {
|
|
16
|
+
var cell = parsedTable[r] && parsedTable[r][c];
|
|
17
|
+
if (cell && typeof cell != 'string') {
|
|
18
|
+
result += ' ' + cell.innerText + ',';
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return result;
|
|
24
|
+
}
|
|
25
|
+
exports.retrieveStringFromParsedTable = retrieveStringFromParsedTable;
|
|
26
|
+
/**
|
|
27
|
+
* @internal
|
|
28
|
+
* Determines whether the table selection is expanding (selecting more) or contracting (selecting less)
|
|
29
|
+
* @param prevTableSelection Previous table selection object containing firstRow, lastRow, firstColumn, and lastColumn properties
|
|
30
|
+
* @param firstCo Current first coordinate of the selection (with row, col properties)
|
|
31
|
+
* @param lastCo Current last coordinate of the selection (with row, col properties)
|
|
32
|
+
* @returns 'selecting' if expanding selection, 'unselecting' if contracting, or null if no change
|
|
33
|
+
*/
|
|
34
|
+
function getIsSelectingOrUnselecting(prevTableSelection, newTableSelection) {
|
|
35
|
+
if (!prevTableSelection) {
|
|
36
|
+
return 'selecting';
|
|
37
|
+
}
|
|
38
|
+
var prevFirstRow = prevTableSelection.firstRow, prevLastRow = prevTableSelection.lastRow, prevFirstColumn = prevTableSelection.firstColumn, prevLastColumn = prevTableSelection.lastColumn;
|
|
39
|
+
var newFirstRow = newTableSelection.firstRow, newLastRow = newTableSelection.lastRow, newFirstColumn = newTableSelection.firstColumn, newLastColumn = newTableSelection.lastColumn;
|
|
40
|
+
var prevRowSpan = Math.abs(prevLastRow - prevFirstRow) + 1;
|
|
41
|
+
var prevColSpan = Math.abs(prevLastColumn - prevFirstColumn) + 1;
|
|
42
|
+
var prevArea = prevRowSpan * prevColSpan;
|
|
43
|
+
var newRowSpan = Math.abs(newLastRow - newFirstRow) + 1;
|
|
44
|
+
var newColSpan = Math.abs(newLastColumn - newFirstColumn) + 1;
|
|
45
|
+
var newArea = newRowSpan * newColSpan;
|
|
46
|
+
// Check if selections are identical
|
|
47
|
+
if (prevFirstRow === newFirstRow &&
|
|
48
|
+
prevLastRow === newLastRow &&
|
|
49
|
+
prevFirstColumn === newFirstColumn &&
|
|
50
|
+
prevLastColumn === newLastColumn) {
|
|
51
|
+
return null;
|
|
52
|
+
}
|
|
53
|
+
if (newArea > prevArea) {
|
|
54
|
+
return 'selecting';
|
|
55
|
+
}
|
|
56
|
+
else if (newArea < prevArea) {
|
|
57
|
+
return 'unselecting';
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
// Same area but different positions
|
|
61
|
+
return 'selecting';
|
|
62
|
+
}
|
|
63
|
+
if (prevFirstColumn !== newFirstColumn ||
|
|
64
|
+
prevFirstRow !== newFirstRow ||
|
|
65
|
+
prevLastColumn !== newLastColumn ||
|
|
66
|
+
prevLastRow !== newLastRow) {
|
|
67
|
+
return 'selecting';
|
|
68
|
+
}
|
|
69
|
+
return null;
|
|
70
|
+
}
|
|
71
|
+
exports.getIsSelectingOrUnselecting = getIsSelectingOrUnselecting;
|
|
72
|
+
//# sourceMappingURL=tableSelectionUtils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tableSelectionUtils.js","sourceRoot":"","sources":["../../../../packages/roosterjs-content-model-plugins/lib/announce/tableSelectionUtils.ts"],"names":[],"mappings":";;;AAEA;;;;;GAKG;AACH,SAAgB,6BAA6B,CAAC,MAA0B;IAC5D,IAAA,WAAW,GAAsB,MAAM,YAA5B,EAAE,OAAO,GAAa,MAAM,QAAnB,EAAE,MAAM,GAAK,MAAM,OAAX,CAAY;IAChD,IAAI,MAAM,GAAG,EAAE,CAAC;IAEhB,IAAI,MAAM,EAAE;QACR,KAAK,IAAI,CAAC,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC,IAAI,MAAM,CAAC,GAAG,EAAE,CAAC,EAAE,EAAE;YAC5C,KAAK,IAAI,CAAC,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC,IAAI,MAAM,CAAC,GAAG,EAAE,CAAC,EAAE,EAAE;gBAC5C,IAAM,IAAI,GAAG,WAAW,CAAC,CAAC,CAAC,IAAI,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;gBACjD,IAAI,IAAI,IAAI,OAAO,IAAI,IAAI,QAAQ,EAAE;oBACjC,MAAM,IAAI,GAAG,GAAG,IAAI,CAAC,SAAS,GAAG,GAAG,CAAC;iBACxC;aACJ;SACJ;KACJ;IAED,OAAO,MAAM,CAAC;AAClB,CAAC;AAhBD,sEAgBC;AAED;;;;;;;GAOG;AACH,SAAgB,2BAA2B,CACvC,kBAAyC,EACzC,iBAAiC;IAEjC,IAAI,CAAC,kBAAkB,EAAE;QACrB,OAAO,WAAW,CAAC;KACtB;IAGG,IAAU,YAAY,GAItB,kBAAkB,SAJI,EACb,WAAW,GAGpB,kBAAkB,QAHE,EACP,eAAe,GAE5B,kBAAkB,YAFU,EAChB,cAAc,GAC1B,kBAAkB,WADQ,CACP;IAGnB,IAAU,WAAW,GAIrB,iBAAiB,SAJI,EACZ,UAAU,GAGnB,iBAAiB,QAHE,EACN,cAAc,GAE3B,iBAAiB,YAFU,EACf,aAAa,GACzB,iBAAiB,WADQ,CACP;IAEtB,IAAM,WAAW,GAAG,IAAI,CAAC,GAAG,CAAC,WAAW,GAAG,YAAY,CAAC,GAAG,CAAC,CAAC;IAC7D,IAAM,WAAW,GAAG,IAAI,CAAC,GAAG,CAAC,cAAc,GAAG,eAAe,CAAC,GAAG,CAAC,CAAC;IACnE,IAAM,QAAQ,GAAG,WAAW,GAAG,WAAW,CAAC;IAE3C,IAAM,UAAU,GAAG,IAAI,CAAC,GAAG,CAAC,UAAU,GAAG,WAAW,CAAC,GAAG,CAAC,CAAC;IAC1D,IAAM,UAAU,GAAG,IAAI,CAAC,GAAG,CAAC,aAAa,GAAG,cAAc,CAAC,GAAG,CAAC,CAAC;IAChE,IAAM,OAAO,GAAG,UAAU,GAAG,UAAU,CAAC;IAExC,oCAAoC;IACpC,IACI,YAAY,KAAK,WAAW;QAC5B,WAAW,KAAK,UAAU;QAC1B,eAAe,KAAK,cAAc;QAClC,cAAc,KAAK,aAAa,EAClC;QACE,OAAO,IAAI,CAAC;KACf;IAED,IAAI,OAAO,GAAG,QAAQ,EAAE;QACpB,OAAO,WAAW,CAAC;KACtB;SAAM,IAAI,OAAO,GAAG,QAAQ,EAAE;QAC3B,OAAO,aAAa,CAAC;KACxB;SAAM;QACH,oCAAoC;QACpC,OAAO,WAAW,CAAC;KACtB;IAED,IACI,eAAe,KAAK,cAAc;QAClC,YAAY,KAAK,WAAW;QAC5B,cAAc,KAAK,aAAa;QAChC,WAAW,KAAK,UAAU,EAC5B;QACE,OAAO,WAAW,CAAC;KACtB;IAED,OAAO,IAAI,CAAC;AAChB,CAAC;AA3DD,kEA2DC","sourcesContent":["import type { TableSelectionInfo, TableSelection } from 'roosterjs-content-model-types';\n\n/**\n * @internal\n * Retrieves text content from selected table cells in a parsed table structure\n * @param tsInfo Table selection information containing the parsed table and coordinates\n * @returns Combined text content from all selected cells, separated by spaces\n */\nexport function retrieveStringFromParsedTable(tsInfo: TableSelectionInfo): string {\n const { parsedTable, firstCo, lastCo } = tsInfo;\n let result = '';\n\n if (lastCo) {\n for (let r = firstCo.row; r <= lastCo.row; r++) {\n for (let c = firstCo.col; c <= lastCo.col; c++) {\n const cell = parsedTable[r] && parsedTable[r][c];\n if (cell && typeof cell != 'string') {\n result += ' ' + cell.innerText + ',';\n }\n }\n }\n }\n\n return result;\n}\n\n/**\n * @internal\n * Determines whether the table selection is expanding (selecting more) or contracting (selecting less)\n * @param prevTableSelection Previous table selection object containing firstRow, lastRow, firstColumn, and lastColumn properties\n * @param firstCo Current first coordinate of the selection (with row, col properties)\n * @param lastCo Current last coordinate of the selection (with row, col properties)\n * @returns 'selecting' if expanding selection, 'unselecting' if contracting, or null if no change\n */\nexport function getIsSelectingOrUnselecting(\n prevTableSelection: TableSelection | null,\n newTableSelection: TableSelection\n): 'selecting' | 'unselecting' | null {\n if (!prevTableSelection) {\n return 'selecting';\n }\n\n const {\n firstRow: prevFirstRow,\n lastRow: prevLastRow,\n firstColumn: prevFirstColumn,\n lastColumn: prevLastColumn,\n } = prevTableSelection;\n\n const {\n firstRow: newFirstRow,\n lastRow: newLastRow,\n firstColumn: newFirstColumn,\n lastColumn: newLastColumn,\n } = newTableSelection;\n\n const prevRowSpan = Math.abs(prevLastRow - prevFirstRow) + 1;\n const prevColSpan = Math.abs(prevLastColumn - prevFirstColumn) + 1;\n const prevArea = prevRowSpan * prevColSpan;\n\n const newRowSpan = Math.abs(newLastRow - newFirstRow) + 1;\n const newColSpan = Math.abs(newLastColumn - newFirstColumn) + 1;\n const newArea = newRowSpan * newColSpan;\n\n // Check if selections are identical\n if (\n prevFirstRow === newFirstRow &&\n prevLastRow === newLastRow &&\n prevFirstColumn === newFirstColumn &&\n prevLastColumn === newLastColumn\n ) {\n return null;\n }\n\n if (newArea > prevArea) {\n return 'selecting';\n } else if (newArea < prevArea) {\n return 'unselecting';\n } else {\n // Same area but different positions\n return 'selecting';\n }\n\n if (\n prevFirstColumn !== newFirstColumn ||\n prevFirstRow !== newFirstRow ||\n prevLastColumn !== newLastColumn ||\n prevLastRow !== newLastRow\n ) {\n return 'selecting';\n }\n\n return null;\n}\n"]}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { FindReplaceHighlightOptions } from './types/FindReplaceHighlightOptions';
|
|
2
|
+
import type { EditorPlugin, IEditor, PluginEvent } from 'roosterjs-content-model-types';
|
|
3
|
+
import type { FindReplaceContext } from './types/FindReplaceContext';
|
|
4
|
+
/**
|
|
5
|
+
* Plugin for finding and replacing text in the editor, maintain the highlights for found and replaced text
|
|
6
|
+
*/
|
|
7
|
+
export declare class FindReplacePlugin implements EditorPlugin {
|
|
8
|
+
private context;
|
|
9
|
+
private editor;
|
|
10
|
+
private findHighlightStyle;
|
|
11
|
+
private replaceHighlightStyle;
|
|
12
|
+
/**
|
|
13
|
+
* Creates a FindReplacePlugin instance
|
|
14
|
+
* @param context FindReplaceContext to use. It will be disposed when plugin is being disposed.
|
|
15
|
+
* @param options Options for highlighting styles
|
|
16
|
+
*/
|
|
17
|
+
constructor(context: FindReplaceContext, options?: FindReplaceHighlightOptions);
|
|
18
|
+
/**
|
|
19
|
+
* Get name of this plugin
|
|
20
|
+
*/
|
|
21
|
+
getName(): string;
|
|
22
|
+
/**
|
|
23
|
+
* The first method that editor will call to a plugin when editor is initializing.
|
|
24
|
+
* It will pass in the editor instance, plugin should take this chance to save the
|
|
25
|
+
* editor reference so that it can call to any editor method or format API later.
|
|
26
|
+
* @param editor The editor object
|
|
27
|
+
*/
|
|
28
|
+
initialize(editor: IEditor): void;
|
|
29
|
+
/**
|
|
30
|
+
* The last method that editor will call to a plugin before it is disposed.
|
|
31
|
+
* Plugin can take this chance to clear the reference to editor. After this method is
|
|
32
|
+
* called, plugin should not call to any editor method since it will result in error.
|
|
33
|
+
*/
|
|
34
|
+
dispose(): void;
|
|
35
|
+
/**
|
|
36
|
+
* Core method for a plugin. Once an event happens in editor, editor will call this
|
|
37
|
+
* method of each plugin to handle the event as long as the event is not handled
|
|
38
|
+
* exclusively by another plugin.
|
|
39
|
+
* @param event The event to handle:
|
|
40
|
+
*/
|
|
41
|
+
onPluginEvent(event: PluginEvent): void;
|
|
42
|
+
}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FindReplacePlugin = void 0;
|
|
4
|
+
var roosterjs_content_model_dom_1 = require("roosterjs-content-model-dom");
|
|
5
|
+
var updateHighlight_1 = require("./utils/updateHighlight");
|
|
6
|
+
var constants_1 = require("./utils/constants");
|
|
7
|
+
var DefaultFindHighlightStyle = 'background-color: yellow;';
|
|
8
|
+
var DefaultReplaceHighlightStyle = 'background-color: orange;';
|
|
9
|
+
/**
|
|
10
|
+
* Plugin for finding and replacing text in the editor, maintain the highlights for found and replaced text
|
|
11
|
+
*/
|
|
12
|
+
var FindReplacePlugin = /** @class */ (function () {
|
|
13
|
+
/**
|
|
14
|
+
* Creates a FindReplacePlugin instance
|
|
15
|
+
* @param context FindReplaceContext to use. It will be disposed when plugin is being disposed.
|
|
16
|
+
* @param options Options for highlighting styles
|
|
17
|
+
*/
|
|
18
|
+
function FindReplacePlugin(context, options) {
|
|
19
|
+
var _a, _b;
|
|
20
|
+
this.context = context;
|
|
21
|
+
this.editor = null;
|
|
22
|
+
this.findHighlightStyle = (_a = options === null || options === void 0 ? void 0 : options.findHighlightStyle) !== null && _a !== void 0 ? _a : DefaultFindHighlightStyle;
|
|
23
|
+
this.replaceHighlightStyle = (_b = options === null || options === void 0 ? void 0 : options.replaceHighlightStyle) !== null && _b !== void 0 ? _b : DefaultReplaceHighlightStyle;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Get name of this plugin
|
|
27
|
+
*/
|
|
28
|
+
FindReplacePlugin.prototype.getName = function () {
|
|
29
|
+
return 'FindReplace';
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* The first method that editor will call to a plugin when editor is initializing.
|
|
33
|
+
* It will pass in the editor instance, plugin should take this chance to save the
|
|
34
|
+
* editor reference so that it can call to any editor method or format API later.
|
|
35
|
+
* @param editor The editor object
|
|
36
|
+
*/
|
|
37
|
+
FindReplacePlugin.prototype.initialize = function (editor) {
|
|
38
|
+
var _a;
|
|
39
|
+
this.editor = editor;
|
|
40
|
+
var win = (_a = editor.getDocument().defaultView) !== null && _a !== void 0 ? _a : window;
|
|
41
|
+
this.context.findHighlight.initialize(win);
|
|
42
|
+
this.context.replaceHighlight.initialize(win);
|
|
43
|
+
this.editor.setEditorStyle(constants_1.FindHighlightRuleKey, this.findHighlightStyle, [
|
|
44
|
+
constants_1.FindHighlightSelector,
|
|
45
|
+
]);
|
|
46
|
+
this.editor.setEditorStyle(constants_1.ReplaceHighlightRuleKey, this.replaceHighlightStyle, [
|
|
47
|
+
constants_1.ReplaceHighlightSelector,
|
|
48
|
+
]);
|
|
49
|
+
};
|
|
50
|
+
/**
|
|
51
|
+
* The last method that editor will call to a plugin before it is disposed.
|
|
52
|
+
* Plugin can take this chance to clear the reference to editor. After this method is
|
|
53
|
+
* called, plugin should not call to any editor method since it will result in error.
|
|
54
|
+
*/
|
|
55
|
+
FindReplacePlugin.prototype.dispose = function () {
|
|
56
|
+
this.context.findHighlight.dispose();
|
|
57
|
+
this.context.replaceHighlight.dispose();
|
|
58
|
+
if (this.editor) {
|
|
59
|
+
this.editor.setEditorStyle(constants_1.FindHighlightRuleKey, null /*cssRule*/);
|
|
60
|
+
this.editor.setEditorStyle(constants_1.ReplaceHighlightRuleKey, null /*cssRule*/);
|
|
61
|
+
this.editor = null;
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
/**
|
|
65
|
+
* Core method for a plugin. Once an event happens in editor, editor will call this
|
|
66
|
+
* method of each plugin to handle the event as long as the event is not handled
|
|
67
|
+
* exclusively by another plugin.
|
|
68
|
+
* @param event The event to handle:
|
|
69
|
+
*/
|
|
70
|
+
FindReplacePlugin.prototype.onPluginEvent = function (event) {
|
|
71
|
+
if (!this.context.text || !this.editor) {
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
switch (event.eventType) {
|
|
75
|
+
case 'input':
|
|
76
|
+
var selection = this.editor.getDOMSelection();
|
|
77
|
+
if ((selection === null || selection === void 0 ? void 0 : selection.type) == 'range') {
|
|
78
|
+
var block = this.editor
|
|
79
|
+
.getDOMHelper()
|
|
80
|
+
.findClosestBlockElement(selection.range.startContainer);
|
|
81
|
+
(0, updateHighlight_1.updateHighlight)(this.editor, this.context, [block], [block]);
|
|
82
|
+
}
|
|
83
|
+
break;
|
|
84
|
+
case 'contentChanged':
|
|
85
|
+
if (!event.contentModel && event.source != roosterjs_content_model_dom_1.ChangeSource.Replace) {
|
|
86
|
+
(0, updateHighlight_1.updateHighlight)(this.editor, this.context);
|
|
87
|
+
}
|
|
88
|
+
break;
|
|
89
|
+
case 'rewriteFromModel':
|
|
90
|
+
(0, updateHighlight_1.updateHighlight)(this.editor, this.context, event.addedBlockElements, event.removedBlockElements);
|
|
91
|
+
break;
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
return FindReplacePlugin;
|
|
95
|
+
}());
|
|
96
|
+
exports.FindReplacePlugin = FindReplacePlugin;
|
|
97
|
+
//# sourceMappingURL=FindReplacePlugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FindReplacePlugin.js","sourceRoot":"","sources":["../../../../packages/roosterjs-content-model-plugins/lib/findReplace/FindReplacePlugin.ts"],"names":[],"mappings":";;;AAAA,2EAA2D;AAC3D,2DAA0D;AAE1D,+CAK2B;AAI3B,IAAM,yBAAyB,GAAG,2BAA2B,CAAC;AAC9D,IAAM,4BAA4B,GAAG,2BAA2B,CAAC;AAEjE;;GAEG;AACH;IAKI;;;;OAIG;IACH,2BAAoB,OAA2B,EAAE,OAAqC;;QAAlE,YAAO,GAAP,OAAO,CAAoB;QATvC,WAAM,GAAmB,IAAI,CAAC;QAUlC,IAAI,CAAC,kBAAkB,GAAG,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,kBAAkB,mCAAI,yBAAyB,CAAC;QACnF,IAAI,CAAC,qBAAqB,GAAG,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,qBAAqB,mCAAI,4BAA4B,CAAC;IAChG,CAAC;IAED;;OAEG;IACH,mCAAO,GAAP;QACI,OAAO,aAAa,CAAC;IACzB,CAAC;IAED;;;;;OAKG;IACH,sCAAU,GAAV,UAAW,MAAe;;QACtB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QAErB,IAAM,GAAG,GAAG,MAAA,MAAM,CAAC,WAAW,EAAE,CAAC,WAAW,mCAAI,MAAM,CAAC;QAEvD,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;QAC3C,IAAI,CAAC,OAAO,CAAC,gBAAgB,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;QAE9C,IAAI,CAAC,MAAM,CAAC,cAAc,CAAC,gCAAoB,EAAE,IAAI,CAAC,kBAAkB,EAAE;YACtE,iCAAqB;SACxB,CAAC,CAAC;QACH,IAAI,CAAC,MAAM,CAAC,cAAc,CAAC,mCAAuB,EAAE,IAAI,CAAC,qBAAqB,EAAE;YAC5E,oCAAwB;SAC3B,CAAC,CAAC;IACP,CAAC;IAED;;;;OAIG;IACH,mCAAO,GAAP;QACI,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,OAAO,EAAE,CAAC;QACrC,IAAI,CAAC,OAAO,CAAC,gBAAgB,CAAC,OAAO,EAAE,CAAC;QAExC,IAAI,IAAI,CAAC,MAAM,EAAE;YACb,IAAI,CAAC,MAAM,CAAC,cAAc,CAAC,gCAAoB,EAAE,IAAI,CAAC,WAAW,CAAC,CAAC;YACnE,IAAI,CAAC,MAAM,CAAC,cAAc,CAAC,mCAAuB,EAAE,IAAI,CAAC,WAAW,CAAC,CAAC;YAEtE,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC;SACtB;IACL,CAAC;IAED;;;;;OAKG;IACH,yCAAa,GAAb,UAAc,KAAkB;QAC5B,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE;YACpC,OAAO;SACV;QAED,QAAQ,KAAK,CAAC,SAAS,EAAE;YACrB,KAAK,OAAO;gBACR,IAAM,SAAS,GAAG,IAAI,CAAC,MAAM,CAAC,eAAe,EAAE,CAAC;gBAEhD,IAAI,CAAA,SAAS,aAAT,SAAS,uBAAT,SAAS,CAAE,IAAI,KAAI,OAAO,EAAE;oBAC5B,IAAM,KAAK,GAAG,IAAI,CAAC,MAAM;yBACpB,YAAY,EAAE;yBACd,uBAAuB,CAAC,SAAS,CAAC,KAAK,CAAC,cAAc,CAAC,CAAC;oBAE7D,IAAA,iCAAe,EAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,OAAO,EAAE,CAAC,KAAK,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC;iBAChE;gBAED,MAAM;YACV,KAAK,gBAAgB;gBACjB,IAAI,CAAC,KAAK,CAAC,YAAY,IAAI,KAAK,CAAC,MAAM,IAAI,0CAAY,CAAC,OAAO,EAAE;oBAC7D,IAAA,iCAAe,EAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;iBAC9C;gBAED,MAAM;YAEV,KAAK,kBAAkB;gBACnB,IAAA,iCAAe,EACX,IAAI,CAAC,MAAM,EACX,IAAI,CAAC,OAAO,EACZ,KAAK,CAAC,kBAAkB,EACxB,KAAK,CAAC,oBAAoB,CAC7B,CAAC;gBAEF,MAAM;SACb;IACL,CAAC;IACL,wBAAC;AAAD,CAAC,AAvGD,IAuGC;AAvGY,8CAAiB","sourcesContent":["import { ChangeSource } from 'roosterjs-content-model-dom';\nimport { updateHighlight } from './utils/updateHighlight';\nimport type { FindReplaceHighlightOptions } from './types/FindReplaceHighlightOptions';\nimport {\n FindHighlightRuleKey,\n FindHighlightSelector,\n ReplaceHighlightRuleKey,\n ReplaceHighlightSelector,\n} from './utils/constants';\nimport type { EditorPlugin, IEditor, PluginEvent } from 'roosterjs-content-model-types';\nimport type { FindReplaceContext } from './types/FindReplaceContext';\n\nconst DefaultFindHighlightStyle = 'background-color: yellow;';\nconst DefaultReplaceHighlightStyle = 'background-color: orange;';\n\n/**\n * Plugin for finding and replacing text in the editor, maintain the highlights for found and replaced text\n */\nexport class FindReplacePlugin implements EditorPlugin {\n private editor: IEditor | null = null;\n private findHighlightStyle: string;\n private replaceHighlightStyle: string;\n\n /**\n * Creates a FindReplacePlugin instance\n * @param context FindReplaceContext to use. It will be disposed when plugin is being disposed.\n * @param options Options for highlighting styles\n */\n constructor(private context: FindReplaceContext, options?: FindReplaceHighlightOptions) {\n this.findHighlightStyle = options?.findHighlightStyle ?? DefaultFindHighlightStyle;\n this.replaceHighlightStyle = options?.replaceHighlightStyle ?? DefaultReplaceHighlightStyle;\n }\n\n /**\n * Get name of this plugin\n */\n getName() {\n return 'FindReplace';\n }\n\n /**\n * The first method that editor will call to a plugin when editor is initializing.\n * It will pass in the editor instance, plugin should take this chance to save the\n * editor reference so that it can call to any editor method or format API later.\n * @param editor The editor object\n */\n initialize(editor: IEditor) {\n this.editor = editor;\n\n const win = editor.getDocument().defaultView ?? window;\n\n this.context.findHighlight.initialize(win);\n this.context.replaceHighlight.initialize(win);\n\n this.editor.setEditorStyle(FindHighlightRuleKey, this.findHighlightStyle, [\n FindHighlightSelector,\n ]);\n this.editor.setEditorStyle(ReplaceHighlightRuleKey, this.replaceHighlightStyle, [\n ReplaceHighlightSelector,\n ]);\n }\n\n /**\n * The last method that editor will call to a plugin before it is disposed.\n * Plugin can take this chance to clear the reference to editor. After this method is\n * called, plugin should not call to any editor method since it will result in error.\n */\n dispose() {\n this.context.findHighlight.dispose();\n this.context.replaceHighlight.dispose();\n\n if (this.editor) {\n this.editor.setEditorStyle(FindHighlightRuleKey, null /*cssRule*/);\n this.editor.setEditorStyle(ReplaceHighlightRuleKey, null /*cssRule*/);\n\n this.editor = null;\n }\n }\n\n /**\n * Core method for a plugin. Once an event happens in editor, editor will call this\n * method of each plugin to handle the event as long as the event is not handled\n * exclusively by another plugin.\n * @param event The event to handle:\n */\n onPluginEvent(event: PluginEvent) {\n if (!this.context.text || !this.editor) {\n return;\n }\n\n switch (event.eventType) {\n case 'input':\n const selection = this.editor.getDOMSelection();\n\n if (selection?.type == 'range') {\n const block = this.editor\n .getDOMHelper()\n .findClosestBlockElement(selection.range.startContainer);\n\n updateHighlight(this.editor, this.context, [block], [block]);\n }\n\n break;\n case 'contentChanged':\n if (!event.contentModel && event.source != ChangeSource.Replace) {\n updateHighlight(this.editor, this.context);\n }\n\n break;\n\n case 'rewriteFromModel':\n updateHighlight(\n this.editor,\n this.context,\n event.addedBlockElements,\n event.removedBlockElements\n );\n\n break;\n }\n }\n}\n"]}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { FindReplaceContext } from './types/FindReplaceContext';
|
|
2
|
+
/**
|
|
3
|
+
* Creates a FindReplaceContext object with default values
|
|
4
|
+
* @param win The window object
|
|
5
|
+
* @param scrollMargin Margin size (in pixels) when scrolling to a highlighted item
|
|
6
|
+
* @returns
|
|
7
|
+
*/
|
|
8
|
+
export declare function createFindReplaceContext(scrollMargin?: number): FindReplaceContext;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createFindReplaceContext = void 0;
|
|
4
|
+
var HighlightHelperImpl_1 = require("./utils/HighlightHelperImpl");
|
|
5
|
+
var constants_1 = require("./utils/constants");
|
|
6
|
+
/**
|
|
7
|
+
* Creates a FindReplaceContext object with default values
|
|
8
|
+
* @param win The window object
|
|
9
|
+
* @param scrollMargin Margin size (in pixels) when scrolling to a highlighted item
|
|
10
|
+
* @returns
|
|
11
|
+
*/
|
|
12
|
+
function createFindReplaceContext(scrollMargin) {
|
|
13
|
+
if (scrollMargin === void 0) { scrollMargin = constants_1.ScrollMargin; }
|
|
14
|
+
return {
|
|
15
|
+
text: null,
|
|
16
|
+
matchCase: false,
|
|
17
|
+
wholeWord: false,
|
|
18
|
+
ranges: [],
|
|
19
|
+
markedIndex: -1,
|
|
20
|
+
scrollMargin: scrollMargin,
|
|
21
|
+
findHighlight: (0, HighlightHelperImpl_1.createHighlightHelper)(constants_1.FindHighlightStyleKey),
|
|
22
|
+
replaceHighlight: (0, HighlightHelperImpl_1.createHighlightHelper)(constants_1.ReplaceHighlightStyleKey),
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
exports.createFindReplaceContext = createFindReplaceContext;
|
|
26
|
+
//# sourceMappingURL=createFindReplaceContext.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createFindReplaceContext.js","sourceRoot":"","sources":["../../../../packages/roosterjs-content-model-plugins/lib/findReplace/createFindReplaceContext.ts"],"names":[],"mappings":";;;AAAA,mEAAoE;AACpE,+CAAkG;AAGlG;;;;;GAKG;AACH,SAAgB,wBAAwB,CAAC,YAAmC;IAAnC,6BAAA,EAAA,eAAuB,wBAAY;IACxE,OAAO;QACH,IAAI,EAAE,IAAI;QACV,SAAS,EAAE,KAAK;QAChB,SAAS,EAAE,KAAK;QAChB,MAAM,EAAE,EAAE;QACV,WAAW,EAAE,CAAC,CAAC;QACf,YAAY,cAAA;QACZ,aAAa,EAAE,IAAA,2CAAqB,EAAC,iCAAqB,CAAC;QAC3D,gBAAgB,EAAE,IAAA,2CAAqB,EAAC,oCAAwB,CAAC;KACpE,CAAC;AACN,CAAC;AAXD,4DAWC","sourcesContent":["import { createHighlightHelper } from './utils/HighlightHelperImpl';\nimport { FindHighlightStyleKey, ReplaceHighlightStyleKey, ScrollMargin } from './utils/constants';\nimport type { FindReplaceContext } from './types/FindReplaceContext';\n\n/**\n * Creates a FindReplaceContext object with default values\n * @param win The window object\n * @param scrollMargin Margin size (in pixels) when scrolling to a highlighted item\n * @returns\n */\nexport function createFindReplaceContext(scrollMargin: number = ScrollMargin): FindReplaceContext {\n return {\n text: null,\n matchCase: false,\n wholeWord: false,\n ranges: [],\n markedIndex: -1,\n scrollMargin,\n findHighlight: createHighlightHelper(FindHighlightStyleKey),\n replaceHighlight: createHighlightHelper(ReplaceHighlightStyleKey),\n };\n}\n"]}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { FindReplaceContext } from './types/FindReplaceContext';
|
|
2
|
+
import type { IEditor } from 'roosterjs-content-model-types';
|
|
3
|
+
/**
|
|
4
|
+
* Start a find operation in the editor
|
|
5
|
+
* @param editor The editor instance
|
|
6
|
+
* @param context The FindReplaceContext to use
|
|
7
|
+
* @param text The text to find
|
|
8
|
+
* @param matchCase Whether to match case
|
|
9
|
+
* @param wholeWord Whether to match whole words only
|
|
10
|
+
*/
|
|
11
|
+
export declare function find(editor: IEditor, context: FindReplaceContext, text: string | null, matchCase?: boolean, wholeWord?: boolean): void;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.find = void 0;
|
|
4
|
+
var updateHighlight_1 = require("./utils/updateHighlight");
|
|
5
|
+
/**
|
|
6
|
+
* Start a find operation in the editor
|
|
7
|
+
* @param editor The editor instance
|
|
8
|
+
* @param context The FindReplaceContext to use
|
|
9
|
+
* @param text The text to find
|
|
10
|
+
* @param matchCase Whether to match case
|
|
11
|
+
* @param wholeWord Whether to match whole words only
|
|
12
|
+
*/
|
|
13
|
+
function find(editor, context, text, matchCase, wholeWord) {
|
|
14
|
+
context.text = text;
|
|
15
|
+
context.matchCase = !!matchCase;
|
|
16
|
+
context.wholeWord = !!wholeWord;
|
|
17
|
+
(0, updateHighlight_1.updateHighlight)(editor, context);
|
|
18
|
+
}
|
|
19
|
+
exports.find = find;
|
|
20
|
+
//# sourceMappingURL=find.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"find.js","sourceRoot":"","sources":["../../../../packages/roosterjs-content-model-plugins/lib/findReplace/find.ts"],"names":[],"mappings":";;;AAAA,2DAA0D;AAI1D;;;;;;;GAOG;AACH,SAAgB,IAAI,CAChB,MAAe,EACf,OAA2B,EAC3B,IAAmB,EACnB,SAAmB,EACnB,SAAmB;IAEnB,OAAO,CAAC,IAAI,GAAG,IAAI,CAAC;IACpB,OAAO,CAAC,SAAS,GAAG,CAAC,CAAC,SAAS,CAAC;IAChC,OAAO,CAAC,SAAS,GAAG,CAAC,CAAC,SAAS,CAAC;IAEhC,IAAA,iCAAe,EAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AACrC,CAAC;AAZD,oBAYC","sourcesContent":["import { updateHighlight } from './utils/updateHighlight';\nimport type { FindReplaceContext } from './types/FindReplaceContext';\nimport type { IEditor } from 'roosterjs-content-model-types';\n\n/**\n * Start a find operation in the editor\n * @param editor The editor instance\n * @param context The FindReplaceContext to use\n * @param text The text to find\n * @param matchCase Whether to match case\n * @param wholeWord Whether to match whole words only\n */\nexport function find(\n editor: IEditor,\n context: FindReplaceContext,\n text: string | null,\n matchCase?: boolean,\n wholeWord?: boolean\n): void {\n context.text = text;\n context.matchCase = !!matchCase;\n context.wholeWord = !!wholeWord;\n\n updateHighlight(editor, context);\n}\n"]}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { IEditor } from 'roosterjs-content-model-types';
|
|
2
|
+
import type { FindReplaceContext } from './types/FindReplaceContext';
|
|
3
|
+
/**
|
|
4
|
+
* Move the highlight to next or previous match
|
|
5
|
+
* @param editor The editor instance
|
|
6
|
+
* @param context The FindReplaceContext to use
|
|
7
|
+
* @param forward Whether to move forward or backward
|
|
8
|
+
*/
|
|
9
|
+
export declare function moveHighlight(editor: IEditor, context: FindReplaceContext, forward: boolean): void;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.moveHighlight = void 0;
|
|
4
|
+
var setMarkedIndex_1 = require("./utils/setMarkedIndex");
|
|
5
|
+
/**
|
|
6
|
+
* Move the highlight to next or previous match
|
|
7
|
+
* @param editor The editor instance
|
|
8
|
+
* @param context The FindReplaceContext to use
|
|
9
|
+
* @param forward Whether to move forward or backward
|
|
10
|
+
*/
|
|
11
|
+
function moveHighlight(editor, context, forward) {
|
|
12
|
+
if (context.ranges.length > 0) {
|
|
13
|
+
var newIndex = !forward && context.markedIndex == -1
|
|
14
|
+
? context.ranges.length - 1
|
|
15
|
+
: (context.markedIndex + (forward ? 1 : -1) + context.ranges.length) %
|
|
16
|
+
context.ranges.length;
|
|
17
|
+
(0, setMarkedIndex_1.setMarkedIndex)(editor, context, newIndex);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
exports.moveHighlight = moveHighlight;
|
|
21
|
+
//# sourceMappingURL=moveHighlight.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"moveHighlight.js","sourceRoot":"","sources":["../../../../packages/roosterjs-content-model-plugins/lib/findReplace/moveHighlight.ts"],"names":[],"mappings":";;;AAAA,yDAAwD;AAIxD;;;;;GAKG;AACH,SAAgB,aAAa,CAAC,MAAe,EAAE,OAA2B,EAAE,OAAgB;IACxF,IAAI,OAAO,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE;QAC3B,IAAM,QAAQ,GACV,CAAC,OAAO,IAAI,OAAO,CAAC,WAAW,IAAI,CAAC,CAAC;YACjC,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC;YAC3B,CAAC,CAAC,CAAC,OAAO,CAAC,WAAW,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC;gBAClE,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC;QAEhC,IAAA,+BAAc,EAAC,MAAM,EAAE,OAAO,EAAE,QAAQ,CAAC,CAAC;KAC7C;AACL,CAAC;AAVD,sCAUC","sourcesContent":["import { setMarkedIndex } from './utils/setMarkedIndex';\nimport type { IEditor } from 'roosterjs-content-model-types';\nimport type { FindReplaceContext } from './types/FindReplaceContext';\n\n/**\n * Move the highlight to next or previous match\n * @param editor The editor instance\n * @param context The FindReplaceContext to use\n * @param forward Whether to move forward or backward\n */\nexport function moveHighlight(editor: IEditor, context: FindReplaceContext, forward: boolean) {\n if (context.ranges.length > 0) {\n const newIndex =\n !forward && context.markedIndex == -1\n ? context.ranges.length - 1\n : (context.markedIndex + (forward ? 1 : -1) + context.ranges.length) %\n context.ranges.length;\n\n setMarkedIndex(editor, context, newIndex);\n }\n}\n"]}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { IEditor } from 'roosterjs-content-model-types';
|
|
2
|
+
import type { FindReplaceContext } from './types/FindReplaceContext';
|
|
3
|
+
/**
|
|
4
|
+
* Replace the currently found item or all found items in the editor
|
|
5
|
+
* @param editor The editor instance
|
|
6
|
+
* @param context The FindReplaceContext to use
|
|
7
|
+
* @param replaceText The text to replace with
|
|
8
|
+
* @param replaceAll Whether to replace all found items
|
|
9
|
+
*/
|
|
10
|
+
export declare function replace(editor: IEditor, context: FindReplaceContext, replaceText: string, replaceAll?: boolean): void;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.replace = void 0;
|
|
4
|
+
var roosterjs_content_model_dom_1 = require("roosterjs-content-model-dom");
|
|
5
|
+
var replaceTextInRange_1 = require("./utils/replaceTextInRange");
|
|
6
|
+
var setMarkedIndex_1 = require("./utils/setMarkedIndex");
|
|
7
|
+
/**
|
|
8
|
+
* Replace the currently found item or all found items in the editor
|
|
9
|
+
* @param editor The editor instance
|
|
10
|
+
* @param context The FindReplaceContext to use
|
|
11
|
+
* @param replaceText The text to replace with
|
|
12
|
+
* @param replaceAll Whether to replace all found items
|
|
13
|
+
*/
|
|
14
|
+
function replace(editor, context, replaceText, replaceAll) {
|
|
15
|
+
if (replaceAll === void 0) { replaceAll = false; }
|
|
16
|
+
if (context.text) {
|
|
17
|
+
editor.takeSnapshot();
|
|
18
|
+
var isReplaced = false;
|
|
19
|
+
do {
|
|
20
|
+
var range = context.ranges[context.markedIndex];
|
|
21
|
+
if (!range || !editor.getDOMHelper().isNodeInEditor(range.startContainer)) {
|
|
22
|
+
(0, setMarkedIndex_1.setMarkedIndex)(editor, context, 0);
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
var resultRange = (0, replaceTextInRange_1.replaceTextInRange)(range, replaceText, context.ranges);
|
|
26
|
+
context.ranges.splice(context.markedIndex, 1);
|
|
27
|
+
(0, setMarkedIndex_1.setMarkedIndex)(editor, context, context.markedIndex >= context.ranges.length ? 0 : context.markedIndex, resultRange);
|
|
28
|
+
isReplaced = true;
|
|
29
|
+
}
|
|
30
|
+
} while (replaceAll && context.ranges[context.markedIndex]);
|
|
31
|
+
context.findHighlight.clear();
|
|
32
|
+
if (context.ranges.length > 0) {
|
|
33
|
+
context.findHighlight.addRanges(context.ranges);
|
|
34
|
+
}
|
|
35
|
+
if (isReplaced) {
|
|
36
|
+
editor.takeSnapshot();
|
|
37
|
+
editor.triggerEvent('contentChanged', {
|
|
38
|
+
data: replaceText,
|
|
39
|
+
source: roosterjs_content_model_dom_1.ChangeSource.Replace,
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
(0, setMarkedIndex_1.setMarkedIndex)(editor, context, -1);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
exports.replace = replace;
|
|
48
|
+
//# sourceMappingURL=replace.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"replace.js","sourceRoot":"","sources":["../../../../packages/roosterjs-content-model-plugins/lib/findReplace/replace.ts"],"names":[],"mappings":";;;AAAA,2EAA2D;AAC3D,iEAAgE;AAChE,yDAAwD;AAIxD;;;;;;GAMG;AACH,SAAgB,OAAO,CACnB,MAAe,EACf,OAA2B,EAC3B,WAAmB,EACnB,UAA2B;IAA3B,2BAAA,EAAA,kBAA2B;IAE3B,IAAI,OAAO,CAAC,IAAI,EAAE;QACd,MAAM,CAAC,YAAY,EAAE,CAAC;QACtB,IAAI,UAAU,GAAG,KAAK,CAAC;QAEvB,GAAG;YACC,IAAM,KAAK,GAAG,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC;YAElD,IAAI,CAAC,KAAK,IAAI,CAAC,MAAM,CAAC,YAAY,EAAE,CAAC,cAAc,CAAC,KAAK,CAAC,cAAc,CAAC,EAAE;gBACvE,IAAA,+BAAc,EAAC,MAAM,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC;aACtC;iBAAM;gBACH,IAAM,WAAW,GAAG,IAAA,uCAAkB,EAAC,KAAK,EAAE,WAAW,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC;gBAE3E,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC;gBAC9C,IAAA,+BAAc,EACV,MAAM,EACN,OAAO,EACP,OAAO,CAAC,WAAW,IAAI,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,WAAW,EACtE,WAAW,CACd,CAAC;gBAEF,UAAU,GAAG,IAAI,CAAC;aACrB;SACJ,QAAQ,UAAU,IAAI,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,WAAW,CAAC,EAAE;QAE5D,OAAO,CAAC,aAAa,CAAC,KAAK,EAAE,CAAC;QAE9B,IAAI,OAAO,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE;YAC3B,OAAO,CAAC,aAAa,CAAC,SAAS,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;SACnD;QAED,IAAI,UAAU,EAAE;YACZ,MAAM,CAAC,YAAY,EAAE,CAAC;YACtB,MAAM,CAAC,YAAY,CAAC,gBAAgB,EAAE;gBAClC,IAAI,EAAE,WAAW;gBACjB,MAAM,EAAE,0CAAY,CAAC,OAAO;aAC/B,CAAC,CAAC;SACN;KACJ;SAAM;QACH,IAAA,+BAAc,EAAC,MAAM,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC,CAAC;KACvC;AACL,CAAC;AA9CD,0BA8CC","sourcesContent":["import { ChangeSource } from 'roosterjs-content-model-dom';\nimport { replaceTextInRange } from './utils/replaceTextInRange';\nimport { setMarkedIndex } from './utils/setMarkedIndex';\nimport type { IEditor } from 'roosterjs-content-model-types';\nimport type { FindReplaceContext } from './types/FindReplaceContext';\n\n/**\n * Replace the currently found item or all found items in the editor\n * @param editor The editor instance\n * @param context The FindReplaceContext to use\n * @param replaceText The text to replace with\n * @param replaceAll Whether to replace all found items\n */\nexport function replace(\n editor: IEditor,\n context: FindReplaceContext,\n replaceText: string,\n replaceAll: boolean = false\n): void {\n if (context.text) {\n editor.takeSnapshot();\n let isReplaced = false;\n\n do {\n const range = context.ranges[context.markedIndex];\n\n if (!range || !editor.getDOMHelper().isNodeInEditor(range.startContainer)) {\n setMarkedIndex(editor, context, 0);\n } else {\n const resultRange = replaceTextInRange(range, replaceText, context.ranges);\n\n context.ranges.splice(context.markedIndex, 1);\n setMarkedIndex(\n editor,\n context,\n context.markedIndex >= context.ranges.length ? 0 : context.markedIndex,\n resultRange\n );\n\n isReplaced = true;\n }\n } while (replaceAll && context.ranges[context.markedIndex]);\n\n context.findHighlight.clear();\n\n if (context.ranges.length > 0) {\n context.findHighlight.addRanges(context.ranges);\n }\n\n if (isReplaced) {\n editor.takeSnapshot();\n editor.triggerEvent('contentChanged', {\n data: replaceText,\n source: ChangeSource.Replace,\n });\n }\n } else {\n setMarkedIndex(editor, context, -1);\n }\n}\n"]}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { HighlightHelper } from './HighlightHelper';
|
|
2
|
+
/**
|
|
3
|
+
* Represents a context object used by all find/replace operations
|
|
4
|
+
*/
|
|
5
|
+
export interface FindReplaceContext {
|
|
6
|
+
/**
|
|
7
|
+
* Text to find (null means no find)
|
|
8
|
+
*/
|
|
9
|
+
text: string | null;
|
|
10
|
+
/**
|
|
11
|
+
* Whether to match case when finding text
|
|
12
|
+
*/
|
|
13
|
+
matchCase: boolean;
|
|
14
|
+
/**
|
|
15
|
+
* Whether to match whole word when finding text
|
|
16
|
+
*/
|
|
17
|
+
wholeWord: boolean;
|
|
18
|
+
/**
|
|
19
|
+
* Ranges of found results
|
|
20
|
+
*/
|
|
21
|
+
ranges: Range[];
|
|
22
|
+
/**
|
|
23
|
+
* Current marked index in the ranges array
|
|
24
|
+
*/
|
|
25
|
+
markedIndex: number;
|
|
26
|
+
/**
|
|
27
|
+
* Margin size (in pixels) when scrolling to a highlighted item
|
|
28
|
+
*/
|
|
29
|
+
readonly scrollMargin: number;
|
|
30
|
+
/**
|
|
31
|
+
* Highlight helper used to highlight found results
|
|
32
|
+
*/
|
|
33
|
+
readonly findHighlight: HighlightHelper;
|
|
34
|
+
/**
|
|
35
|
+
* Highlight helper used to highlight the current marked result
|
|
36
|
+
*/
|
|
37
|
+
readonly replaceHighlight: HighlightHelper;
|
|
38
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FindReplaceContext.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-plugins/lib/findReplace/types/FindReplaceContext.ts"],"names":[],"mappings":"","sourcesContent":["import type { HighlightHelper } from './HighlightHelper';\n\n/**\n * Represents a context object used by all find/replace operations\n */\nexport interface FindReplaceContext {\n /**\n * Text to find (null means no find)\n */\n text: string | null;\n\n /**\n * Whether to match case when finding text\n */\n matchCase: boolean;\n\n /**\n * Whether to match whole word when finding text\n */\n wholeWord: boolean;\n\n /**\n * Ranges of found results\n */\n ranges: Range[];\n\n /**\n * Current marked index in the ranges array\n */\n markedIndex: number;\n\n /**\n * Margin size (in pixels) when scrolling to a highlighted item\n */\n readonly scrollMargin: number;\n\n /**\n * Highlight helper used to highlight found results\n */\n readonly findHighlight: HighlightHelper;\n\n /**\n * Highlight helper used to highlight the current marked result\n */\n readonly replaceHighlight: HighlightHelper;\n}\n"]}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Options for creating FindReplaceContext
|
|
3
|
+
*/
|
|
4
|
+
export interface FindReplaceHighlightOptions {
|
|
5
|
+
/**
|
|
6
|
+
* Style for highlighting found items
|
|
7
|
+
*/
|
|
8
|
+
findHighlightStyle?: string;
|
|
9
|
+
/**
|
|
10
|
+
* Style for highlighting replacing items
|
|
11
|
+
*/
|
|
12
|
+
replaceHighlightStyle?: string;
|
|
13
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FindReplaceHighlightOptions.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-plugins/lib/findReplace/types/FindReplaceHighlightOptions.ts"],"names":[],"mappings":"","sourcesContent":["/**\n * Options for creating FindReplaceContext\n */\nexport interface FindReplaceHighlightOptions {\n /**\n * Style for highlighting found items\n */\n findHighlightStyle?: string;\n\n /**\n * Style for highlighting replacing items\n */\n replaceHighlightStyle?: string;\n}\n"]}
|