roosterjs-content-model-plugins 9.1.0 → 9.3.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/autoFormat/AutoFormatPlugin.d.ts +15 -5
- package/lib/autoFormat/AutoFormatPlugin.js +41 -4
- package/lib/autoFormat/AutoFormatPlugin.js.map +1 -1
- package/lib/autoFormat/link/createLink.js +2 -0
- package/lib/autoFormat/link/createLink.js.map +1 -1
- package/lib/autoFormat/list/keyboardListTrigger.js +7 -9
- package/lib/autoFormat/list/keyboardListTrigger.js.map +1 -1
- package/lib/autoFormat/numbers/transformFraction.d.ts +5 -0
- package/lib/autoFormat/numbers/transformFraction.js +27 -0
- package/lib/autoFormat/numbers/transformFraction.js.map +1 -0
- package/lib/autoFormat/numbers/transformOrdinals.d.ts +5 -0
- package/lib/autoFormat/numbers/transformOrdinals.js +32 -0
- package/lib/autoFormat/numbers/transformOrdinals.js.map +1 -0
- package/lib/customReplace/CustomReplacePlugin.d.ts +61 -0
- package/lib/customReplace/CustomReplacePlugin.js +87 -0
- package/lib/customReplace/CustomReplacePlugin.js.map +1 -0
- package/lib/edit/EditPlugin.js +19 -1
- package/lib/edit/EditPlugin.js.map +1 -1
- package/lib/edit/inputSteps/handleEnterOnList.js +8 -1
- package/lib/edit/inputSteps/handleEnterOnList.js.map +1 -1
- package/lib/edit/keyboardDelete.js +1 -0
- package/lib/edit/keyboardDelete.js.map +1 -1
- package/lib/edit/keyboardInput.js +1 -0
- package/lib/edit/keyboardInput.js.map +1 -1
- package/lib/edit/keyboardTab.js +5 -5
- package/lib/edit/keyboardTab.js.map +1 -1
- package/lib/edit/tabUtils/handleTabOnList.d.ts +2 -2
- package/lib/edit/tabUtils/handleTabOnList.js +3 -3
- package/lib/edit/tabUtils/handleTabOnList.js.map +1 -1
- package/lib/edit/tabUtils/handleTabOnParagraph.d.ts +2 -2
- package/lib/edit/tabUtils/handleTabOnParagraph.js +2 -2
- package/lib/edit/tabUtils/handleTabOnParagraph.js.map +1 -1
- package/lib/hyperlink/HyperlinkPlugin.js +4 -1
- package/lib/hyperlink/HyperlinkPlugin.js.map +1 -1
- package/lib/index.d.ts +8 -1
- package/lib/index.js +8 -1
- package/lib/index.js.map +1 -1
- package/lib/markdown/utils/setFormat.js +11 -9
- package/lib/markdown/utils/setFormat.js.map +1 -1
- package/lib/picker/PickerHandler.d.ts +112 -0
- package/lib/picker/PickerHandler.js +3 -0
- package/lib/picker/PickerHandler.js.map +1 -0
- package/lib/picker/PickerHelper.d.ts +22 -0
- package/lib/picker/PickerHelper.js +3 -0
- package/lib/picker/PickerHelper.js.map +1 -0
- package/lib/picker/PickerHelperImpl.d.ts +25 -0
- package/lib/picker/PickerHelperImpl.js +54 -0
- package/lib/picker/PickerHelperImpl.js.map +1 -0
- package/lib/picker/PickerPlugin.d.ts +54 -0
- package/lib/picker/PickerPlugin.js +217 -0
- package/lib/picker/PickerPlugin.js.map +1 -0
- package/lib/picker/getQueryString.d.ts +5 -0
- package/lib/picker/getQueryString.js +36 -0
- package/lib/picker/getQueryString.js.map +1 -0
- package/lib/pluginUtils/Rect/getDOMInsertPointRect.d.ts +7 -0
- package/lib/pluginUtils/Rect/getDOMInsertPointRect.js +57 -0
- package/lib/pluginUtils/Rect/getDOMInsertPointRect.js.map +1 -0
- package/lib/shortcut/ShortcutPlugin.js +1 -0
- package/lib/shortcut/ShortcutPlugin.js.map +1 -1
- package/lib/shortcut/shortcuts.d.ts +7 -0
- package/lib/shortcut/shortcuts.js +15 -1
- package/lib/shortcut/shortcuts.js.map +1 -1
- package/lib/shortcut/utils/setShortcutIndentationCommand.js +2 -2
- package/lib/shortcut/utils/setShortcutIndentationCommand.js.map +1 -1
- package/lib/tableEdit/OnTableEditorCreatedCallback.d.ts +5 -0
- package/lib/tableEdit/OnTableEditorCreatedCallback.js +3 -0
- package/lib/tableEdit/OnTableEditorCreatedCallback.js.map +1 -0
- package/lib/tableEdit/TableEditPlugin.d.ts +7 -1
- package/lib/tableEdit/TableEditPlugin.js +7 -2
- package/lib/tableEdit/TableEditPlugin.js.map +1 -1
- package/lib/tableEdit/editors/TableEditor.d.ts +9 -1
- package/lib/tableEdit/editors/TableEditor.js +51 -15
- package/lib/tableEdit/editors/TableEditor.js.map +1 -1
- package/lib/tableEdit/editors/features/CellResizer.d.ts +9 -1
- package/lib/tableEdit/editors/features/CellResizer.js +11 -3
- package/lib/tableEdit/editors/features/CellResizer.js.map +1 -1
- package/lib/tableEdit/editors/features/TableEditFeature.d.ts +1 -1
- package/lib/tableEdit/editors/features/TableEditFeature.js +6 -6
- package/lib/tableEdit/editors/features/TableEditFeature.js.map +1 -1
- package/lib/tableEdit/editors/features/TableEditFeatureName.d.ts +4 -0
- package/lib/tableEdit/editors/features/TableEditFeatureName.js +3 -0
- package/lib/tableEdit/editors/features/TableEditFeatureName.js.map +1 -0
- package/lib/tableEdit/editors/features/TableInserter.d.ts +10 -1
- package/lib/tableEdit/editors/features/TableInserter.js +18 -12
- package/lib/tableEdit/editors/features/TableInserter.js.map +1 -1
- package/lib/tableEdit/editors/features/TableMover.d.ts +48 -3
- package/lib/tableEdit/editors/features/TableMover.js +212 -24
- package/lib/tableEdit/editors/features/TableMover.js.map +1 -1
- package/lib/tableEdit/editors/features/TableResizer.d.ts +7 -2
- package/lib/tableEdit/editors/features/TableResizer.js +25 -6
- package/lib/tableEdit/editors/features/TableResizer.js.map +1 -1
- package/lib/watermark/WatermarkPlugin.d.ts +1 -1
- package/lib/watermark/WatermarkPlugin.js +2 -1
- package/lib/watermark/WatermarkPlugin.js.map +1 -1
- package/lib/watermark/isModelEmptyFast.js +4 -0
- package/lib/watermark/isModelEmptyFast.js.map +1 -1
- package/lib-amd/autoFormat/AutoFormatPlugin.d.ts +15 -5
- package/lib-amd/autoFormat/AutoFormatPlugin.js +39 -5
- package/lib-amd/autoFormat/AutoFormatPlugin.js.map +1 -1
- package/lib-amd/autoFormat/link/createLink.js +2 -0
- package/lib-amd/autoFormat/link/createLink.js.map +1 -1
- package/lib-amd/autoFormat/list/keyboardListTrigger.js +7 -9
- package/lib-amd/autoFormat/list/keyboardListTrigger.js.map +1 -1
- package/lib-amd/autoFormat/numbers/transformFraction.d.ts +5 -0
- package/lib-amd/autoFormat/numbers/transformFraction.js +28 -0
- package/lib-amd/autoFormat/numbers/transformFraction.js.map +1 -0
- package/lib-amd/autoFormat/numbers/transformOrdinals.d.ts +5 -0
- package/lib-amd/autoFormat/numbers/transformOrdinals.js +33 -0
- package/lib-amd/autoFormat/numbers/transformOrdinals.js.map +1 -0
- package/lib-amd/customReplace/CustomReplacePlugin.d.ts +61 -0
- package/lib-amd/customReplace/CustomReplacePlugin.js +88 -0
- package/lib-amd/customReplace/CustomReplacePlugin.js.map +1 -0
- package/lib-amd/edit/EditPlugin.js +19 -1
- package/lib-amd/edit/EditPlugin.js.map +1 -1
- package/lib-amd/edit/inputSteps/handleEnterOnList.js +8 -2
- package/lib-amd/edit/inputSteps/handleEnterOnList.js.map +1 -1
- package/lib-amd/edit/keyboardDelete.js +1 -0
- package/lib-amd/edit/keyboardDelete.js.map +1 -1
- package/lib-amd/edit/keyboardInput.js +1 -0
- package/lib-amd/edit/keyboardInput.js.map +1 -1
- package/lib-amd/edit/keyboardTab.js +5 -5
- package/lib-amd/edit/keyboardTab.js.map +1 -1
- package/lib-amd/edit/tabUtils/handleTabOnList.d.ts +2 -2
- package/lib-amd/edit/tabUtils/handleTabOnList.js +3 -3
- package/lib-amd/edit/tabUtils/handleTabOnList.js.map +1 -1
- package/lib-amd/edit/tabUtils/handleTabOnParagraph.d.ts +2 -2
- package/lib-amd/edit/tabUtils/handleTabOnParagraph.js +2 -2
- package/lib-amd/edit/tabUtils/handleTabOnParagraph.js.map +1 -1
- package/lib-amd/hyperlink/HyperlinkPlugin.js +4 -1
- package/lib-amd/hyperlink/HyperlinkPlugin.js.map +1 -1
- package/lib-amd/index.d.ts +8 -1
- package/lib-amd/index.js +6 -2
- package/lib-amd/index.js.map +1 -1
- package/lib-amd/markdown/utils/setFormat.js +11 -9
- package/lib-amd/markdown/utils/setFormat.js.map +1 -1
- package/lib-amd/picker/PickerHandler.d.ts +112 -0
- package/lib-amd/picker/PickerHandler.js +5 -0
- package/lib-amd/picker/PickerHandler.js.map +1 -0
- package/lib-amd/picker/PickerHelper.d.ts +22 -0
- package/lib-amd/picker/PickerHelper.js +5 -0
- package/lib-amd/picker/PickerHelper.js.map +1 -0
- package/lib-amd/picker/PickerHelperImpl.d.ts +25 -0
- package/lib-amd/picker/PickerHelperImpl.js +53 -0
- package/lib-amd/picker/PickerHelperImpl.js.map +1 -0
- package/lib-amd/picker/PickerPlugin.d.ts +54 -0
- package/lib-amd/picker/PickerPlugin.js +215 -0
- package/lib-amd/picker/PickerPlugin.js.map +1 -0
- package/lib-amd/picker/getQueryString.d.ts +5 -0
- package/lib-amd/picker/getQueryString.js +37 -0
- package/lib-amd/picker/getQueryString.js.map +1 -0
- package/lib-amd/pluginUtils/Rect/getDOMInsertPointRect.d.ts +7 -0
- package/lib-amd/pluginUtils/Rect/getDOMInsertPointRect.js +58 -0
- package/lib-amd/pluginUtils/Rect/getDOMInsertPointRect.js.map +1 -0
- package/lib-amd/shortcut/ShortcutPlugin.js +1 -0
- package/lib-amd/shortcut/ShortcutPlugin.js.map +1 -1
- package/lib-amd/shortcut/shortcuts.d.ts +7 -0
- package/lib-amd/shortcut/shortcuts.js +15 -1
- package/lib-amd/shortcut/shortcuts.js.map +1 -1
- package/lib-amd/shortcut/utils/setShortcutIndentationCommand.js +2 -2
- package/lib-amd/shortcut/utils/setShortcutIndentationCommand.js.map +1 -1
- package/lib-amd/tableEdit/OnTableEditorCreatedCallback.d.ts +5 -0
- package/lib-amd/tableEdit/OnTableEditorCreatedCallback.js +5 -0
- package/lib-amd/tableEdit/OnTableEditorCreatedCallback.js.map +1 -0
- package/lib-amd/tableEdit/TableEditPlugin.d.ts +7 -1
- package/lib-amd/tableEdit/TableEditPlugin.js +7 -2
- package/lib-amd/tableEdit/TableEditPlugin.js.map +1 -1
- package/lib-amd/tableEdit/editors/TableEditor.d.ts +9 -1
- package/lib-amd/tableEdit/editors/TableEditor.js +51 -15
- package/lib-amd/tableEdit/editors/TableEditor.js.map +1 -1
- package/lib-amd/tableEdit/editors/features/CellResizer.d.ts +9 -1
- package/lib-amd/tableEdit/editors/features/CellResizer.js +11 -3
- package/lib-amd/tableEdit/editors/features/CellResizer.js.map +1 -1
- package/lib-amd/tableEdit/editors/features/TableEditFeature.d.ts +1 -1
- package/lib-amd/tableEdit/editors/features/TableEditFeature.js +6 -6
- package/lib-amd/tableEdit/editors/features/TableEditFeature.js.map +1 -1
- package/lib-amd/tableEdit/editors/features/TableEditFeatureName.d.ts +4 -0
- package/lib-amd/tableEdit/editors/features/TableEditFeatureName.js +5 -0
- package/lib-amd/tableEdit/editors/features/TableEditFeatureName.js.map +1 -0
- package/lib-amd/tableEdit/editors/features/TableInserter.d.ts +10 -1
- package/lib-amd/tableEdit/editors/features/TableInserter.js +18 -12
- package/lib-amd/tableEdit/editors/features/TableInserter.js.map +1 -1
- package/lib-amd/tableEdit/editors/features/TableMover.d.ts +48 -3
- package/lib-amd/tableEdit/editors/features/TableMover.js +212 -25
- package/lib-amd/tableEdit/editors/features/TableMover.js.map +1 -1
- package/lib-amd/tableEdit/editors/features/TableResizer.d.ts +7 -2
- package/lib-amd/tableEdit/editors/features/TableResizer.js +25 -7
- package/lib-amd/tableEdit/editors/features/TableResizer.js.map +1 -1
- package/lib-amd/watermark/WatermarkPlugin.d.ts +1 -1
- package/lib-amd/watermark/WatermarkPlugin.js +2 -1
- package/lib-amd/watermark/WatermarkPlugin.js.map +1 -1
- package/lib-amd/watermark/isModelEmptyFast.js +4 -0
- package/lib-amd/watermark/isModelEmptyFast.js.map +1 -1
- package/lib-mjs/autoFormat/AutoFormatPlugin.d.ts +15 -5
- package/lib-mjs/autoFormat/AutoFormatPlugin.js +41 -4
- package/lib-mjs/autoFormat/AutoFormatPlugin.js.map +1 -1
- package/lib-mjs/autoFormat/link/createLink.js +3 -1
- package/lib-mjs/autoFormat/link/createLink.js.map +1 -1
- package/lib-mjs/autoFormat/list/keyboardListTrigger.js +7 -9
- package/lib-mjs/autoFormat/list/keyboardListTrigger.js.map +1 -1
- package/lib-mjs/autoFormat/numbers/transformFraction.d.ts +5 -0
- package/lib-mjs/autoFormat/numbers/transformFraction.js +23 -0
- package/lib-mjs/autoFormat/numbers/transformFraction.js.map +1 -0
- package/lib-mjs/autoFormat/numbers/transformOrdinals.d.ts +5 -0
- package/lib-mjs/autoFormat/numbers/transformOrdinals.js +28 -0
- package/lib-mjs/autoFormat/numbers/transformOrdinals.js.map +1 -0
- package/lib-mjs/customReplace/CustomReplacePlugin.d.ts +61 -0
- package/lib-mjs/customReplace/CustomReplacePlugin.js +84 -0
- package/lib-mjs/customReplace/CustomReplacePlugin.js.map +1 -0
- package/lib-mjs/edit/EditPlugin.js +19 -1
- package/lib-mjs/edit/EditPlugin.js.map +1 -1
- package/lib-mjs/edit/inputSteps/handleEnterOnList.js +8 -1
- package/lib-mjs/edit/inputSteps/handleEnterOnList.js.map +1 -1
- package/lib-mjs/edit/keyboardDelete.js +1 -0
- package/lib-mjs/edit/keyboardDelete.js.map +1 -1
- package/lib-mjs/edit/keyboardInput.js +1 -0
- package/lib-mjs/edit/keyboardInput.js.map +1 -1
- package/lib-mjs/edit/keyboardTab.js +5 -5
- package/lib-mjs/edit/keyboardTab.js.map +1 -1
- package/lib-mjs/edit/tabUtils/handleTabOnList.d.ts +2 -2
- package/lib-mjs/edit/tabUtils/handleTabOnList.js +3 -3
- package/lib-mjs/edit/tabUtils/handleTabOnList.js.map +1 -1
- package/lib-mjs/edit/tabUtils/handleTabOnParagraph.d.ts +2 -2
- package/lib-mjs/edit/tabUtils/handleTabOnParagraph.js +2 -2
- package/lib-mjs/edit/tabUtils/handleTabOnParagraph.js.map +1 -1
- package/lib-mjs/hyperlink/HyperlinkPlugin.js +4 -1
- package/lib-mjs/hyperlink/HyperlinkPlugin.js.map +1 -1
- package/lib-mjs/index.d.ts +8 -1
- package/lib-mjs/index.js +4 -1
- package/lib-mjs/index.js.map +1 -1
- package/lib-mjs/markdown/utils/setFormat.js +11 -9
- package/lib-mjs/markdown/utils/setFormat.js.map +1 -1
- package/lib-mjs/picker/PickerHandler.d.ts +112 -0
- package/lib-mjs/picker/PickerHandler.js +2 -0
- package/lib-mjs/picker/PickerHandler.js.map +1 -0
- package/lib-mjs/picker/PickerHelper.d.ts +22 -0
- package/lib-mjs/picker/PickerHelper.js +2 -0
- package/lib-mjs/picker/PickerHelper.js.map +1 -0
- package/lib-mjs/picker/PickerHelperImpl.d.ts +25 -0
- package/lib-mjs/picker/PickerHelperImpl.js +51 -0
- package/lib-mjs/picker/PickerHelperImpl.js.map +1 -0
- package/lib-mjs/picker/PickerPlugin.d.ts +54 -0
- package/lib-mjs/picker/PickerPlugin.js +214 -0
- package/lib-mjs/picker/PickerPlugin.js.map +1 -0
- package/lib-mjs/picker/getQueryString.d.ts +5 -0
- package/lib-mjs/picker/getQueryString.js +32 -0
- package/lib-mjs/picker/getQueryString.js.map +1 -0
- package/lib-mjs/pluginUtils/Rect/getDOMInsertPointRect.d.ts +7 -0
- package/lib-mjs/pluginUtils/Rect/getDOMInsertPointRect.js +53 -0
- package/lib-mjs/pluginUtils/Rect/getDOMInsertPointRect.js.map +1 -0
- package/lib-mjs/shortcut/ShortcutPlugin.js +2 -1
- package/lib-mjs/shortcut/ShortcutPlugin.js.map +1 -1
- package/lib-mjs/shortcut/shortcuts.d.ts +7 -0
- package/lib-mjs/shortcut/shortcuts.js +14 -0
- package/lib-mjs/shortcut/shortcuts.js.map +1 -1
- package/lib-mjs/shortcut/utils/setShortcutIndentationCommand.js +2 -2
- package/lib-mjs/shortcut/utils/setShortcutIndentationCommand.js.map +1 -1
- package/lib-mjs/tableEdit/OnTableEditorCreatedCallback.d.ts +5 -0
- package/lib-mjs/tableEdit/OnTableEditorCreatedCallback.js +2 -0
- package/lib-mjs/tableEdit/OnTableEditorCreatedCallback.js.map +1 -0
- package/lib-mjs/tableEdit/TableEditPlugin.d.ts +7 -1
- package/lib-mjs/tableEdit/TableEditPlugin.js +7 -2
- package/lib-mjs/tableEdit/TableEditPlugin.js.map +1 -1
- package/lib-mjs/tableEdit/editors/TableEditor.d.ts +9 -1
- package/lib-mjs/tableEdit/editors/TableEditor.js +52 -16
- package/lib-mjs/tableEdit/editors/TableEditor.js.map +1 -1
- package/lib-mjs/tableEdit/editors/features/CellResizer.d.ts +9 -1
- package/lib-mjs/tableEdit/editors/features/CellResizer.js +10 -2
- package/lib-mjs/tableEdit/editors/features/CellResizer.js.map +1 -1
- package/lib-mjs/tableEdit/editors/features/TableEditFeature.d.ts +1 -1
- package/lib-mjs/tableEdit/editors/features/TableEditFeature.js +6 -6
- package/lib-mjs/tableEdit/editors/features/TableEditFeature.js.map +1 -1
- package/lib-mjs/tableEdit/editors/features/TableEditFeatureName.d.ts +4 -0
- package/lib-mjs/tableEdit/editors/features/TableEditFeatureName.js +2 -0
- package/lib-mjs/tableEdit/editors/features/TableEditFeatureName.js.map +1 -0
- package/lib-mjs/tableEdit/editors/features/TableInserter.d.ts +10 -1
- package/lib-mjs/tableEdit/editors/features/TableInserter.js +17 -11
- package/lib-mjs/tableEdit/editors/features/TableInserter.js.map +1 -1
- package/lib-mjs/tableEdit/editors/features/TableMover.d.ts +48 -3
- package/lib-mjs/tableEdit/editors/features/TableMover.js +209 -24
- package/lib-mjs/tableEdit/editors/features/TableMover.js.map +1 -1
- package/lib-mjs/tableEdit/editors/features/TableResizer.d.ts +7 -2
- package/lib-mjs/tableEdit/editors/features/TableResizer.js +23 -4
- package/lib-mjs/tableEdit/editors/features/TableResizer.js.map +1 -1
- package/lib-mjs/watermark/WatermarkPlugin.d.ts +1 -1
- package/lib-mjs/watermark/WatermarkPlugin.js +2 -1
- package/lib-mjs/watermark/WatermarkPlugin.js.map +1 -1
- package/lib-mjs/watermark/isModelEmptyFast.js +4 -0
- package/lib-mjs/watermark/isModelEmptyFast.js.map +1 -1
- package/package.json +5 -5
|
@@ -1,8 +1,11 @@
|
|
|
1
|
+
import { ChangeSource } from 'roosterjs-content-model-dom';
|
|
1
2
|
import { createLink } from './link/createLink';
|
|
2
3
|
import { createLinkAfterSpace } from './link/createLinkAfterSpace';
|
|
3
4
|
import { formatTextSegmentBeforeSelectionMarker } from 'roosterjs-content-model-api';
|
|
4
5
|
import { keyboardListTrigger } from './list/keyboardListTrigger';
|
|
6
|
+
import { transformFraction } from './numbers/transformFraction';
|
|
5
7
|
import { transformHyphen } from './hyphen/transformHyphen';
|
|
8
|
+
import { transformOrdinals } from './numbers/transformOrdinals';
|
|
6
9
|
import { unlink } from './link/unlink';
|
|
7
10
|
/**
|
|
8
11
|
* @internal
|
|
@@ -13,6 +16,8 @@ var DefaultOptions = {
|
|
|
13
16
|
autoUnlink: false,
|
|
14
17
|
autoLink: false,
|
|
15
18
|
autoHyphen: false,
|
|
19
|
+
autoFraction: false,
|
|
20
|
+
autoOrdinals: false,
|
|
16
21
|
};
|
|
17
22
|
/**
|
|
18
23
|
* Auto Format plugin handles auto formatting, such as transforming * characters into a bullet list.
|
|
@@ -26,6 +31,8 @@ var AutoFormatPlugin = /** @class */ (function () {
|
|
|
26
31
|
* - autoLink: A boolean that enables or disables automatic hyperlink creation when pasting or typing content. Defaults to false.
|
|
27
32
|
* - autoUnlink: A boolean that enables or disables automatic hyperlink removal when pressing backspace. Defaults to false.
|
|
28
33
|
* - autoHyphen: A boolean that enables or disables automatic hyphen transformation. Defaults to false.
|
|
34
|
+
* - autoFraction: A boolean that enables or disables automatic fraction transformation. Defaults to false.
|
|
35
|
+
* - autoOrdinals: A boolean that enables or disables automatic ordinal number transformation. Defaults to false.
|
|
29
36
|
*/
|
|
30
37
|
function AutoFormatPlugin(options) {
|
|
31
38
|
if (options === void 0) { options = DefaultOptions; }
|
|
@@ -86,20 +93,40 @@ var AutoFormatPlugin = /** @class */ (function () {
|
|
|
86
93
|
selection.range.collapsed) {
|
|
87
94
|
switch (rawEvent.data) {
|
|
88
95
|
case ' ':
|
|
96
|
+
var formatOptions_1 = {
|
|
97
|
+
changeSource: '',
|
|
98
|
+
apiName: '',
|
|
99
|
+
};
|
|
89
100
|
formatTextSegmentBeforeSelectionMarker(editor, function (model, previousSegment, paragraph, _markerFormat, context) {
|
|
90
|
-
var _a = _this.options, autoBullet = _a.autoBullet, autoNumbering = _a.autoNumbering, autoLink = _a.autoLink, autoHyphen = _a.autoHyphen;
|
|
101
|
+
var _a = _this.options, autoBullet = _a.autoBullet, autoNumbering = _a.autoNumbering, autoLink = _a.autoLink, autoHyphen = _a.autoHyphen, autoFraction = _a.autoFraction, autoOrdinals = _a.autoOrdinals;
|
|
91
102
|
var shouldHyphen = false;
|
|
92
103
|
var shouldLink = false;
|
|
104
|
+
var shouldList = false;
|
|
105
|
+
var shouldFraction = false;
|
|
106
|
+
var shouldOrdinals = false;
|
|
107
|
+
if (autoBullet || autoNumbering) {
|
|
108
|
+
shouldList = keyboardListTrigger(model, paragraph, context, autoBullet, autoNumbering);
|
|
109
|
+
}
|
|
93
110
|
if (autoLink) {
|
|
94
111
|
shouldLink = createLinkAfterSpace(previousSegment, paragraph, context);
|
|
95
112
|
}
|
|
96
113
|
if (autoHyphen) {
|
|
97
114
|
shouldHyphen = transformHyphen(previousSegment, paragraph, context);
|
|
98
115
|
}
|
|
99
|
-
|
|
116
|
+
if (autoFraction) {
|
|
117
|
+
shouldFraction = transformFraction(previousSegment, paragraph, context);
|
|
118
|
+
}
|
|
119
|
+
if (autoOrdinals) {
|
|
120
|
+
shouldOrdinals = transformOrdinals(previousSegment, paragraph, context);
|
|
121
|
+
}
|
|
122
|
+
formatOptions_1.apiName = getApiName(shouldList, shouldHyphen);
|
|
123
|
+
formatOptions_1.changeSource = getChangeSource(shouldList, shouldHyphen, shouldLink);
|
|
124
|
+
return (shouldList ||
|
|
100
125
|
shouldHyphen ||
|
|
101
|
-
shouldLink
|
|
102
|
-
|
|
126
|
+
shouldLink ||
|
|
127
|
+
shouldFraction ||
|
|
128
|
+
shouldOrdinals);
|
|
129
|
+
}, formatOptions_1);
|
|
103
130
|
break;
|
|
104
131
|
}
|
|
105
132
|
}
|
|
@@ -125,4 +152,14 @@ var AutoFormatPlugin = /** @class */ (function () {
|
|
|
125
152
|
return AutoFormatPlugin;
|
|
126
153
|
}());
|
|
127
154
|
export { AutoFormatPlugin };
|
|
155
|
+
var getApiName = function (shouldList, shouldHyphen) {
|
|
156
|
+
return shouldList ? 'autoToggleList' : shouldHyphen ? 'autoHyphen' : '';
|
|
157
|
+
};
|
|
158
|
+
var getChangeSource = function (shouldList, shouldHyphen, shouldLink) {
|
|
159
|
+
return shouldList || shouldHyphen
|
|
160
|
+
? ChangeSource.AutoFormat
|
|
161
|
+
: shouldLink
|
|
162
|
+
? ChangeSource.AutoLink
|
|
163
|
+
: '';
|
|
164
|
+
};
|
|
128
165
|
//# sourceMappingURL=AutoFormatPlugin.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AutoFormatPlugin.js","sourceRoot":"","sources":["../../../../packages/roosterjs-content-model-plugins/lib/autoFormat/AutoFormatPlugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC/C,OAAO,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAC;AACnE,OAAO,EAAE,sCAAsC,EAAE,MAAM,6BAA6B,CAAC;AACrF,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AACjE,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAC3D,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAwCvC;;GAEG;AACH,IAAM,cAAc,GAAgC;IAChD,UAAU,EAAE,KAAK;IACjB,aAAa,EAAE,KAAK;IACpB,UAAU,EAAE,KAAK;IACjB,QAAQ,EAAE,KAAK;IACf,UAAU,EAAE,KAAK;CACpB,CAAC;AAEF;;;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AU,CAAC,MAAM,CAAC,CAAC;SACtB;IACL,CAAC;IACL,uBAAC;AAAD,CAAC,AApID,IAoIC","sourcesContent":["import { createLink } from './link/createLink';\nimport { createLinkAfterSpace } from './link/createLinkAfterSpace';\nimport { formatTextSegmentBeforeSelectionMarker } from 'roosterjs-content-model-api';\nimport { keyboardListTrigger } from './list/keyboardListTrigger';\nimport { transformHyphen } from './hyphen/transformHyphen';\nimport { unlink } from './link/unlink';\nimport type {\n ContentChangedEvent,\n EditorInputEvent,\n EditorPlugin,\n IEditor,\n KeyDownEvent,\n PluginEvent,\n} from 'roosterjs-content-model-types';\n\n/**\n * Options to customize the Content Model Auto Format Plugin\n */\nexport type AutoFormatOptions = {\n /**\n * When true, after type *, ->, -, --, => , —, > and space key a type of bullet list will be triggered. @default true\n */\n autoBullet: boolean;\n\n /**\n * When true, after type 1, A, a, i, I followed by ., ), - or between () and space key a type of numbering list will be triggered. @default true\n */\n autoNumbering: boolean;\n\n /**\n * When press backspace before a link, remove the hyperlink\n */\n autoUnlink: boolean;\n\n /**\n * When paste content, create hyperlink for the pasted link\n */\n autoLink: boolean;\n\n /**\n * Transform -- into hyphen, if typed between two words\n */\n autoHyphen: boolean;\n};\n\n/**\n * @internal\n */\nconst DefaultOptions: Required<AutoFormatOptions> = {\n autoBullet: false,\n autoNumbering: false,\n autoUnlink: false,\n autoLink: false,\n autoHyphen: false,\n};\n\n/**\n * Auto Format plugin handles auto formatting, such as transforming * characters into a bullet list.\n * It can be customized with options to enable or disable auto list features.\n */\nexport class AutoFormatPlugin implements EditorPlugin {\n private editor: IEditor | null = null;\n /**\n * @param options An optional parameter that takes in an object of type AutoFormatOptions, which includes the following properties:\n * - autoBullet: A boolean that enables or disables automatic bullet list formatting. Defaults to false.\n * - autoNumbering: A boolean that enables or disables automatic numbering formatting. Defaults to false.\n * - autoLink: A boolean that enables or disables automatic hyperlink creation when pasting or typing content. Defaults to false.\n * - autoUnlink: A boolean that enables or disables automatic hyperlink removal when pressing backspace. Defaults to false.\n * - autoHyphen: A boolean that enables or disables automatic hyphen transformation. Defaults to false.\n */\n constructor(private options: AutoFormatOptions = DefaultOptions) {}\n\n /**\n * Get name of this plugin\n */\n getName() {\n return 'AutoFormat';\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 }\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 switch (event.eventType) {\n case 'input':\n this.handleEditorInputEvent(this.editor, event);\n break;\n case 'keyDown':\n this.handleKeyDownEvent(this.editor, event);\n break;\n case 'contentChanged':\n this.handleContentChangedEvent(this.editor, event);\n break;\n }\n }\n }\n\n private handleEditorInputEvent(editor: IEditor, event: EditorInputEvent) {\n const rawEvent = event.rawEvent;\n const selection = editor.getDOMSelection();\n if (\n rawEvent.inputType === 'insertText' &&\n selection &&\n selection.type === 'range' &&\n selection.range.collapsed\n ) {\n switch (rawEvent.data) {\n case ' ':\n formatTextSegmentBeforeSelectionMarker(\n editor,\n (model, previousSegment, paragraph, _markerFormat, context) => {\n const {\n autoBullet,\n autoNumbering,\n autoLink,\n autoHyphen,\n } = this.options;\n let shouldHyphen = false;\n let shouldLink = false;\n\n if (autoLink) {\n shouldLink = createLinkAfterSpace(\n previousSegment,\n paragraph,\n context\n );\n }\n\n if (autoHyphen) {\n shouldHyphen = transformHyphen(previousSegment, paragraph, context);\n }\n\n return (\n keyboardListTrigger(\n model,\n paragraph,\n context,\n autoBullet,\n autoNumbering\n ) ||\n shouldHyphen ||\n shouldLink\n );\n }\n );\n break;\n }\n }\n }\n\n private handleKeyDownEvent(editor: IEditor, event: KeyDownEvent) {\n const rawEvent = event.rawEvent;\n if (!rawEvent.defaultPrevented && !event.handledByEditFeature) {\n switch (rawEvent.key) {\n case 'Backspace':\n if (this.options.autoUnlink) {\n unlink(editor, rawEvent);\n }\n break;\n }\n }\n }\n\n private handleContentChangedEvent(editor: IEditor, event: ContentChangedEvent) {\n const { autoLink } = this.options;\n if (event.source == 'Paste' && autoLink) {\n createLink(editor);\n }\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"AutoFormatPlugin.js","sourceRoot":"","sources":["../../../../packages/roosterjs-content-model-plugins/lib/autoFormat/AutoFormatPlugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAC3D,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC/C,OAAO,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAC;AACnE,OAAO,EAAE,sCAAsC,EAAE,MAAM,6BAA6B,CAAC;AACrF,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AACjE,OAAO,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAC3D,OAAO,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAmDvC;;GAEG;AACH,IAAM,cAAc,GAA+B;IAC/C,UAAU,EAAE,KAAK;IACjB,aAAa,EAAE,KAAK;IACpB,UAAU,EAAE,KAAK;IACjB,QAAQ,EAAE,KAAK;IACf,UAAU,EAAE,KAAK;IACjB,YAAY,EAAE,KAAK;IACnB,YAAY,EAAE,KAAK;CACtB,CAAC;AAEF;;;GAGG;AACH;IAEI;;;;;;;;;OASG;IACH,0BAAoB,OAA2C;QAA3C,wBAAA,EAAA,wBAA2C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,CACjB,CAAC;oBACN,CAAC,EACD,eAAa,CAChB,CAAC;oBAEF,MAAM;aACb;SACJ;IACL,CAAC;IAEO,6CAAkB,GAA1B,UAA2B,MAAe,EAAE,KAAmB;QAC3D,IAAM,QAAQ,GAAG,KAAK,CAAC,QAAQ,CAAC;QAChC,IAAI,CAAC,QAAQ,CAAC,gBAAgB,IAAI,CAAC,KAAK,CAAC,oBAAoB,EAAE;YAC3D,QAAQ,QAAQ,CAAC,GAAG,EAAE;gBAClB,KAAK,WAAW;oBACZ,IAAI,IAAI,CAAC,OAAO,CAAC,UAAU,EAAE;wBACzB,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;qBAC5B;oBACD,MAAM;aACb;SACJ;IACL,CAAC;IAEO,oDAAyB,GAAjC,UAAkC,MAAe,EAAE,KAA0B;QACjE,IAAA,QAAQ,GAAK,IAAI,CAAC,OAAO,SAAjB,CAAkB;QAClC,IAAI,KAAK,CAAC,MAAM,IAAI,OAAO,IAAI,QAAQ,EAAE;YACrC,UAAU,CAAC,MAAM,CAAC,CAAC;SACtB;IACL,CAAC;IACL,uBAAC;AAAD,CAAC,AA9KD,IA8KC;;AAED,IAAM,UAAU,GAAG,UAAC,UAAmB,EAAE,YAAqB;IAC1D,OAAO,UAAU,CAAC,CAAC,CAAC,gBAAgB,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,EAAE,CAAC;AAC5E,CAAC,CAAC;AAEF,IAAM,eAAe,GAAG,UAAC,UAAmB,EAAE,YAAqB,EAAE,UAAmB;IACpF,OAAO,UAAU,IAAI,YAAY;QAC7B,CAAC,CAAC,YAAY,CAAC,UAAU;QACzB,CAAC,CAAC,UAAU;YACZ,CAAC,CAAC,YAAY,CAAC,QAAQ;YACvB,CAAC,CAAC,EAAE,CAAC;AACb,CAAC,CAAC","sourcesContent":["import { ChangeSource } from 'roosterjs-content-model-dom';\nimport { createLink } from './link/createLink';\nimport { createLinkAfterSpace } from './link/createLinkAfterSpace';\nimport { formatTextSegmentBeforeSelectionMarker } from 'roosterjs-content-model-api';\nimport { keyboardListTrigger } from './list/keyboardListTrigger';\nimport { transformFraction } from './numbers/transformFraction';\nimport { transformHyphen } from './hyphen/transformHyphen';\nimport { transformOrdinals } from './numbers/transformOrdinals';\nimport { unlink } from './link/unlink';\nimport type {\n ContentChangedEvent,\n EditorInputEvent,\n EditorPlugin,\n FormatContentModelOptions,\n IEditor,\n KeyDownEvent,\n PluginEvent,\n} from 'roosterjs-content-model-types';\n\n/**\n * Options to customize the Content Model Auto Format Plugin\n */\nexport type AutoFormatOptions = {\n /**\n * When true, after type *, ->, -, --, => , —, > and space key a type of bullet list will be triggered. @default true\n */\n autoBullet?: boolean;\n\n /**\n * When true, after type 1, A, a, i, I followed by ., ), - or between () and space key a type of numbering list will be triggered. @default true\n */\n autoNumbering?: boolean;\n\n /**\n * When press backspace before a link, remove the hyperlink\n */\n autoUnlink?: boolean;\n\n /**\n * When paste content, create hyperlink for the pasted link\n */\n autoLink?: boolean;\n\n /**\n * Transform -- into hyphen, if typed between two words\n */\n autoHyphen?: boolean;\n\n /**\n * Transform 1/2, 1/4, 3/4 into fraction character\n */\n autoFraction?: boolean;\n\n /**\n * Transform ordinal numbers into superscript\n */\n autoOrdinals?: boolean;\n};\n\n/**\n * @internal\n */\nconst DefaultOptions: Partial<AutoFormatOptions> = {\n autoBullet: false,\n autoNumbering: false,\n autoUnlink: false,\n autoLink: false,\n autoHyphen: false,\n autoFraction: false,\n autoOrdinals: false,\n};\n\n/**\n * Auto Format plugin handles auto formatting, such as transforming * characters into a bullet list.\n * It can be customized with options to enable or disable auto list features.\n */\nexport class AutoFormatPlugin implements EditorPlugin {\n private editor: IEditor | null = null;\n /**\n * @param options An optional parameter that takes in an object of type AutoFormatOptions, which includes the following properties:\n * - autoBullet: A boolean that enables or disables automatic bullet list formatting. Defaults to false.\n * - autoNumbering: A boolean that enables or disables automatic numbering formatting. Defaults to false.\n * - autoLink: A boolean that enables or disables automatic hyperlink creation when pasting or typing content. Defaults to false.\n * - autoUnlink: A boolean that enables or disables automatic hyperlink removal when pressing backspace. Defaults to false.\n * - autoHyphen: A boolean that enables or disables automatic hyphen transformation. Defaults to false.\n * - autoFraction: A boolean that enables or disables automatic fraction transformation. Defaults to false.\n * - autoOrdinals: A boolean that enables or disables automatic ordinal number transformation. Defaults to false.\n */\n constructor(private options: AutoFormatOptions = DefaultOptions) {}\n\n /**\n * Get name of this plugin\n */\n getName() {\n return 'AutoFormat';\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 }\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 switch (event.eventType) {\n case 'input':\n this.handleEditorInputEvent(this.editor, event);\n break;\n case 'keyDown':\n this.handleKeyDownEvent(this.editor, event);\n break;\n case 'contentChanged':\n this.handleContentChangedEvent(this.editor, event);\n break;\n }\n }\n }\n\n private handleEditorInputEvent(editor: IEditor, event: EditorInputEvent) {\n const rawEvent = event.rawEvent;\n const selection = editor.getDOMSelection();\n if (\n rawEvent.inputType === 'insertText' &&\n selection &&\n selection.type === 'range' &&\n selection.range.collapsed\n ) {\n switch (rawEvent.data) {\n case ' ':\n const formatOptions: FormatContentModelOptions = {\n changeSource: '',\n apiName: '',\n };\n formatTextSegmentBeforeSelectionMarker(\n editor,\n (model, previousSegment, paragraph, _markerFormat, context) => {\n const {\n autoBullet,\n autoNumbering,\n autoLink,\n autoHyphen,\n autoFraction,\n autoOrdinals,\n } = this.options;\n let shouldHyphen = false;\n let shouldLink = false;\n let shouldList = false;\n let shouldFraction = false;\n let shouldOrdinals = false;\n\n if (autoBullet || autoNumbering) {\n shouldList = keyboardListTrigger(\n model,\n paragraph,\n context,\n autoBullet,\n autoNumbering\n );\n }\n\n if (autoLink) {\n shouldLink = createLinkAfterSpace(\n previousSegment,\n paragraph,\n context\n );\n }\n\n if (autoHyphen) {\n shouldHyphen = transformHyphen(previousSegment, paragraph, context);\n }\n\n if (autoFraction) {\n shouldFraction = transformFraction(\n previousSegment,\n paragraph,\n context\n );\n }\n\n if (autoOrdinals) {\n shouldOrdinals = transformOrdinals(\n previousSegment,\n paragraph,\n context\n );\n }\n\n formatOptions.apiName = getApiName(shouldList, shouldHyphen);\n formatOptions.changeSource = getChangeSource(\n shouldList,\n shouldHyphen,\n shouldLink\n );\n\n return (\n shouldList ||\n shouldHyphen ||\n shouldLink ||\n shouldFraction ||\n shouldOrdinals\n );\n },\n formatOptions\n );\n\n break;\n }\n }\n }\n\n private handleKeyDownEvent(editor: IEditor, event: KeyDownEvent) {\n const rawEvent = event.rawEvent;\n if (!rawEvent.defaultPrevented && !event.handledByEditFeature) {\n switch (rawEvent.key) {\n case 'Backspace':\n if (this.options.autoUnlink) {\n unlink(editor, rawEvent);\n }\n break;\n }\n }\n }\n\n private handleContentChangedEvent(editor: IEditor, event: ContentChangedEvent) {\n const { autoLink } = this.options;\n if (event.source == 'Paste' && autoLink) {\n createLink(editor);\n }\n }\n}\n\nconst getApiName = (shouldList: boolean, shouldHyphen: boolean) => {\n return shouldList ? 'autoToggleList' : shouldHyphen ? 'autoHyphen' : '';\n};\n\nconst getChangeSource = (shouldList: boolean, shouldHyphen: boolean, shouldLink: boolean) => {\n return shouldList || shouldHyphen\n ? ChangeSource.AutoFormat\n : shouldLink\n ? ChangeSource.AutoLink\n : '';\n};\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { addLink } from 'roosterjs-content-model-dom';
|
|
1
|
+
import { addLink, ChangeSource } from 'roosterjs-content-model-dom';
|
|
2
2
|
import { formatTextSegmentBeforeSelectionMarker, matchLink } from 'roosterjs-content-model-api';
|
|
3
3
|
/**
|
|
4
4
|
* @internal
|
|
@@ -17,6 +17,8 @@ export function createLink(editor) {
|
|
|
17
17
|
return true;
|
|
18
18
|
}
|
|
19
19
|
return false;
|
|
20
|
+
}, {
|
|
21
|
+
changeSource: ChangeSource.AutoLink,
|
|
20
22
|
});
|
|
21
23
|
}
|
|
22
24
|
//# sourceMappingURL=createLink.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createLink.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-plugins/lib/autoFormat/link/createLink.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,6BAA6B,CAAC;
|
|
1
|
+
{"version":3,"file":"createLink.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-plugins/lib/autoFormat/link/createLink.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AACpE,OAAO,EAAE,sCAAsC,EAAE,SAAS,EAAE,MAAM,6BAA6B,CAAC;AAGhG;;GAEG;AACH,MAAM,UAAU,UAAU,CAAC,MAAe;IACtC,sCAAsC,CAClC,MAAM,EACN,UAAC,MAAM,EAAE,WAAW,EAAE,UAAU;QAC5B,IAAI,QAAQ,GAAoB,IAAI,CAAC;QACrC,IAAI,CAAC,WAAW,CAAC,IAAI,IAAI,CAAC,QAAQ,GAAG,SAAS,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,EAAE;YAC/D,OAAO,CAAC,WAAW,EAAE;gBACjB,MAAM,EAAE;oBACJ,IAAI,EAAE,QAAQ,CAAC,aAAa;oBAC5B,SAAS,EAAE,IAAI;iBAClB;gBACD,OAAO,EAAE,EAAE;aACd,CAAC,CAAC;YACH,OAAO,IAAI,CAAC;SACf;QACD,OAAO,KAAK,CAAC;IACjB,CAAC,EACD;QACI,YAAY,EAAE,YAAY,CAAC,QAAQ;KACtC,CACJ,CAAC;AACN,CAAC","sourcesContent":["import { addLink, ChangeSource } from 'roosterjs-content-model-dom';\nimport { formatTextSegmentBeforeSelectionMarker, matchLink } from 'roosterjs-content-model-api';\nimport type { IEditor, LinkData } from 'roosterjs-content-model-types';\n\n/**\n * @internal\n */\nexport function createLink(editor: IEditor) {\n formatTextSegmentBeforeSelectionMarker(\n editor,\n (_model, linkSegment, _paragraph) => {\n let linkData: LinkData | null = null;\n if (!linkSegment.link && (linkData = matchLink(linkSegment.text))) {\n addLink(linkSegment, {\n format: {\n href: linkData.normalizedUrl,\n underline: true,\n },\n dataset: {},\n });\n return true;\n }\n return false;\n },\n {\n changeSource: ChangeSource.AutoLink,\n }\n );\n}\n"]}
|
|
@@ -6,15 +6,13 @@ import { setListType, setModelListStartNumber, setModelListStyle, } from 'rooste
|
|
|
6
6
|
export function keyboardListTrigger(model, paragraph, context, shouldSearchForBullet, shouldSearchForNumbering) {
|
|
7
7
|
if (shouldSearchForBullet === void 0) { shouldSearchForBullet = true; }
|
|
8
8
|
if (shouldSearchForNumbering === void 0) { shouldSearchForNumbering = true; }
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
return true;
|
|
17
|
-
}
|
|
9
|
+
var listStyleType = getListTypeStyle(model, shouldSearchForBullet, shouldSearchForNumbering);
|
|
10
|
+
if (listStyleType) {
|
|
11
|
+
paragraph.segments.splice(0, 1);
|
|
12
|
+
var listType = listStyleType.listType, styleType = listStyleType.styleType, index = listStyleType.index;
|
|
13
|
+
triggerList(model, listType, styleType, index);
|
|
14
|
+
context.canUndoByBackspace = true;
|
|
15
|
+
return true;
|
|
18
16
|
}
|
|
19
17
|
return false;
|
|
20
18
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"keyboardListTrigger.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-plugins/lib/autoFormat/list/keyboardListTrigger.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EACH,WAAW,EACX,uBAAuB,EACvB,iBAAiB,GACpB,MAAM,6BAA6B,CAAC;AAOrC;;GAEG;AACH,MAAM,UAAU,mBAAmB,CAC/B,KAA2B,EAC3B,SAAgC,EAChC,OAAkC,EAClC,qBAAqC,EACrC,wBAAwC;IADxC,sCAAA,EAAA,4BAAqC;IACrC,yCAAA,EAAA,+BAAwC;IAExC,
|
|
1
|
+
{"version":3,"file":"keyboardListTrigger.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-plugins/lib/autoFormat/list/keyboardListTrigger.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EACH,WAAW,EACX,uBAAuB,EACvB,iBAAiB,GACpB,MAAM,6BAA6B,CAAC;AAOrC;;GAEG;AACH,MAAM,UAAU,mBAAmB,CAC/B,KAA2B,EAC3B,SAAgC,EAChC,OAAkC,EAClC,qBAAqC,EACrC,wBAAwC;IADxC,sCAAA,EAAA,4BAAqC;IACrC,yCAAA,EAAA,+BAAwC;IAExC,IAAM,aAAa,GAAG,gBAAgB,CAAC,KAAK,EAAE,qBAAqB,EAAE,wBAAwB,CAAC,CAAC;IAC/F,IAAI,aAAa,EAAE;QACf,SAAS,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;QACxB,IAAA,QAAQ,GAAuB,aAAa,SAApC,EAAE,SAAS,GAAY,aAAa,UAAzB,EAAE,KAAK,GAAK,aAAa,MAAlB,CAAmB;QACrD,WAAW,CAAC,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,KAAK,CAAC,CAAC;QAC/C,OAAO,CAAC,kBAAkB,GAAG,IAAI,CAAC;QAElC,OAAO,IAAI,CAAC;KACf;IACD,OAAO,KAAK,CAAC;AACjB,CAAC;AAED,IAAM,WAAW,GAAG,UAChB,KAA2B,EAC3B,QAAqB,EACrB,SAAiB,EACjB,KAAc;IAEd,WAAW,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;IAC7B,IAAM,aAAa,GAAG,QAAQ,IAAI,IAAI,CAAC;IACvC,IAAI,KAAK,IAAI,KAAK,GAAG,CAAC,IAAI,aAAa,EAAE;QACrC,uBAAuB,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;KACzC;IACD,iBAAiB,CACb,KAAK,EACL,aAAa;QACT,CAAC,CAAC;YACI,gBAAgB,EAAE,SAAS;SAC9B;QACH,CAAC,CAAC;YACI,kBAAkB,EAAE,SAAS;SAChC,CACV,CAAC;AACN,CAAC,CAAC","sourcesContent":["import { getListTypeStyle } from './getListTypeStyle';\nimport {\n setListType,\n setModelListStartNumber,\n setModelListStyle,\n} from 'roosterjs-content-model-api';\nimport type {\n ContentModelDocument,\n ContentModelParagraph,\n FormatContentModelContext,\n} from 'roosterjs-content-model-types';\n\n/**\n * @internal\n */\nexport function keyboardListTrigger(\n model: ContentModelDocument,\n paragraph: ContentModelParagraph,\n context: FormatContentModelContext,\n shouldSearchForBullet: boolean = true,\n shouldSearchForNumbering: boolean = true\n) {\n const listStyleType = getListTypeStyle(model, shouldSearchForBullet, shouldSearchForNumbering);\n if (listStyleType) {\n paragraph.segments.splice(0, 1);\n const { listType, styleType, index } = listStyleType;\n triggerList(model, listType, styleType, index);\n context.canUndoByBackspace = true;\n\n return true;\n }\n return false;\n}\n\nconst triggerList = (\n model: ContentModelDocument,\n listType: 'OL' | 'UL',\n styleType: number,\n index?: number\n) => {\n setListType(model, listType);\n const isOrderedList = listType == 'OL';\n if (index && index > 1 && isOrderedList) {\n setModelListStartNumber(model, index);\n }\n setModelListStyle(\n model,\n isOrderedList\n ? {\n orderedStyleType: styleType,\n }\n : {\n unorderedStyleType: styleType,\n }\n );\n};\n"]}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { ContentModelParagraph, ContentModelText, FormatContentModelContext } from 'roosterjs-content-model-types';
|
|
2
|
+
/**
|
|
3
|
+
* @internal
|
|
4
|
+
*/
|
|
5
|
+
export declare function transformFraction(previousSegment: ContentModelText, paragraph: ContentModelParagraph, context: FormatContentModelContext): boolean;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { splitTextSegment } from '../../pluginUtils/splitTextSegment';
|
|
2
|
+
var FRACTIONS = {
|
|
3
|
+
'1/2': '½',
|
|
4
|
+
'1/4': '¼',
|
|
5
|
+
'3/4': '¾',
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* @internal
|
|
9
|
+
*/
|
|
10
|
+
export function transformFraction(previousSegment, paragraph, context) {
|
|
11
|
+
var _a;
|
|
12
|
+
var fraction = (_a = previousSegment.text.split(' ').pop()) === null || _a === void 0 ? void 0 : _a.trim();
|
|
13
|
+
if (fraction && FRACTIONS[fraction]) {
|
|
14
|
+
var textLength = previousSegment.text.length - 1;
|
|
15
|
+
var textIndex = textLength - fraction.length;
|
|
16
|
+
var textSegment = splitTextSegment(previousSegment, paragraph, textIndex, textLength);
|
|
17
|
+
textSegment.text = FRACTIONS[fraction];
|
|
18
|
+
context.canUndoByBackspace = true;
|
|
19
|
+
return true;
|
|
20
|
+
}
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=transformFraction.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transformFraction.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-plugins/lib/autoFormat/numbers/transformFraction.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,oCAAoC,CAAC;AAOtE,IAAM,SAAS,GAA2B;IACtC,KAAK,EAAE,GAAG;IACV,KAAK,EAAE,GAAG;IACV,KAAK,EAAE,GAAG;CACb,CAAC;AAEF;;GAEG;AACH,MAAM,UAAU,iBAAiB,CAC7B,eAAiC,EACjC,SAAgC,EAChC,OAAkC;;IAElC,IAAM,QAAQ,GAAG,MAAA,eAAe,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,0CAAE,IAAI,EAAE,CAAC;IAC/D,IAAI,QAAQ,IAAI,SAAS,CAAC,QAAQ,CAAC,EAAE;QACjC,IAAM,UAAU,GAAG,eAAe,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC;QACnD,IAAM,SAAS,GAAG,UAAU,GAAG,QAAQ,CAAC,MAAM,CAAC;QAC/C,IAAM,WAAW,GAAG,gBAAgB,CAAC,eAAe,EAAE,SAAS,EAAE,SAAS,EAAE,UAAU,CAAC,CAAC;QACxF,WAAW,CAAC,IAAI,GAAG,SAAS,CAAC,QAAQ,CAAC,CAAC;QAEvC,OAAO,CAAC,kBAAkB,GAAG,IAAI,CAAC;QAClC,OAAO,IAAI,CAAC;KACf;IAED,OAAO,KAAK,CAAC;AACjB,CAAC","sourcesContent":["import { splitTextSegment } from '../../pluginUtils/splitTextSegment';\nimport type {\n ContentModelParagraph,\n ContentModelText,\n FormatContentModelContext,\n} from 'roosterjs-content-model-types';\n\nconst FRACTIONS: Record<string, string> = {\n '1/2': '½',\n '1/4': '¼',\n '3/4': '¾',\n};\n\n/**\n * @internal\n */\nexport function transformFraction(\n previousSegment: ContentModelText,\n paragraph: ContentModelParagraph,\n context: FormatContentModelContext\n): boolean {\n const fraction = previousSegment.text.split(' ').pop()?.trim();\n if (fraction && FRACTIONS[fraction]) {\n const textLength = previousSegment.text.length - 1;\n const textIndex = textLength - fraction.length;\n const textSegment = splitTextSegment(previousSegment, paragraph, textIndex, textLength);\n textSegment.text = FRACTIONS[fraction];\n\n context.canUndoByBackspace = true;\n return true;\n }\n\n return false;\n}\n"]}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { ContentModelParagraph, ContentModelText, FormatContentModelContext } from 'roosterjs-content-model-types';
|
|
2
|
+
/**
|
|
3
|
+
* @internal
|
|
4
|
+
*/
|
|
5
|
+
export declare function transformOrdinals(previousSegment: ContentModelText, paragraph: ContentModelParagraph, context: FormatContentModelContext): boolean;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { splitTextSegment } from '../../pluginUtils/splitTextSegment';
|
|
2
|
+
var getOrdinal = function (value) {
|
|
3
|
+
var ORDINALS = {
|
|
4
|
+
1: 'st',
|
|
5
|
+
2: 'nd',
|
|
6
|
+
3: 'rd',
|
|
7
|
+
};
|
|
8
|
+
return ORDINALS[value] || 'th';
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* @internal
|
|
12
|
+
*/
|
|
13
|
+
export function transformOrdinals(previousSegment, paragraph, context) {
|
|
14
|
+
var _a;
|
|
15
|
+
var value = (_a = previousSegment.text.split(' ').pop()) === null || _a === void 0 ? void 0 : _a.trim();
|
|
16
|
+
if (value) {
|
|
17
|
+
var ordinal = value.substring(value.length - 2);
|
|
18
|
+
var ordinalValue = parseInt(value);
|
|
19
|
+
if (ordinalValue && getOrdinal(ordinalValue) === ordinal) {
|
|
20
|
+
var ordinalSegment = splitTextSegment(previousSegment, paragraph, previousSegment.text.length - 3, previousSegment.text.length - 1);
|
|
21
|
+
ordinalSegment.format.superOrSubScriptSequence = 'super';
|
|
22
|
+
context.canUndoByBackspace = true;
|
|
23
|
+
return true;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=transformOrdinals.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transformOrdinals.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-plugins/lib/autoFormat/numbers/transformOrdinals.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,oCAAoC,CAAC;AAOtE,IAAM,UAAU,GAAG,UAAC,KAAa;IAC7B,IAAM,QAAQ,GAA2B;QACrC,CAAC,EAAE,IAAI;QACP,CAAC,EAAE,IAAI;QACP,CAAC,EAAE,IAAI;KACV,CAAC;IACF,OAAO,QAAQ,CAAC,KAAK,CAAC,IAAI,IAAI,CAAC;AACnC,CAAC,CAAC;AAEF;;GAEG;AACH,MAAM,UAAU,iBAAiB,CAC7B,eAAiC,EACjC,SAAgC,EAChC,OAAkC;;IAElC,IAAM,KAAK,GAAG,MAAA,eAAe,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,0CAAE,IAAI,EAAE,CAAC;IAC5D,IAAI,KAAK,EAAE;QACP,IAAM,OAAO,GAAG,KAAK,CAAC,SAAS,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;QAClD,IAAM,YAAY,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC;QACrC,IAAI,YAAY,IAAI,UAAU,CAAC,YAAY,CAAC,KAAK,OAAO,EAAE;YACtD,IAAM,cAAc,GAAG,gBAAgB,CACnC,eAAe,EACf,SAAS,EACT,eAAe,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,EAC/B,eAAe,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAClC,CAAC;YAEF,cAAc,CAAC,MAAM,CAAC,wBAAwB,GAAG,OAAO,CAAC;YACzD,OAAO,CAAC,kBAAkB,GAAG,IAAI,CAAC;YAClC,OAAO,IAAI,CAAC;SACf;KACJ;IACD,OAAO,KAAK,CAAC;AACjB,CAAC","sourcesContent":["import { splitTextSegment } from '../../pluginUtils/splitTextSegment';\nimport type {\n ContentModelParagraph,\n ContentModelText,\n FormatContentModelContext,\n} from 'roosterjs-content-model-types';\n\nconst getOrdinal = (value: number) => {\n const ORDINALS: Record<number, string> = {\n 1: 'st',\n 2: 'nd',\n 3: 'rd',\n };\n return ORDINALS[value] || 'th';\n};\n\n/**\n * @internal\n */\nexport function transformOrdinals(\n previousSegment: ContentModelText,\n paragraph: ContentModelParagraph,\n context: FormatContentModelContext\n): boolean {\n const value = previousSegment.text.split(' ').pop()?.trim();\n if (value) {\n const ordinal = value.substring(value.length - 2);\n const ordinalValue = parseInt(value);\n if (ordinalValue && getOrdinal(ordinalValue) === ordinal) {\n const ordinalSegment = splitTextSegment(\n previousSegment,\n paragraph,\n previousSegment.text.length - 3,\n previousSegment.text.length - 1\n );\n\n ordinalSegment.format.superOrSubScriptSequence = 'super';\n context.canUndoByBackspace = true;\n return true;\n }\n }\n return false;\n}\n"]}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import type { ContentModelParagraph, ContentModelText, EditorPlugin, IEditor, PluginEvent } from 'roosterjs-content-model-types';
|
|
2
|
+
/**
|
|
3
|
+
* The CustomReplace interface defines a custom replacement that can be used in CustomReplacePlugin.
|
|
4
|
+
*/
|
|
5
|
+
export interface CustomReplace {
|
|
6
|
+
/**
|
|
7
|
+
* The string to replace in the editor.
|
|
8
|
+
*/
|
|
9
|
+
stringToReplace: string;
|
|
10
|
+
/**
|
|
11
|
+
* The string to replace with.
|
|
12
|
+
*/
|
|
13
|
+
replacementString: string;
|
|
14
|
+
/**
|
|
15
|
+
* The handler to replace the string.
|
|
16
|
+
* @param previousSegment The text segment to replace.
|
|
17
|
+
* @param stringToReplace The string to replace.
|
|
18
|
+
* @param replacementString The string to replace with.
|
|
19
|
+
* @param paragraph The paragraph that contains the text segment.
|
|
20
|
+
* @returns True if the string is replaced successfully, otherwise false.
|
|
21
|
+
*/
|
|
22
|
+
replacementHandler: (previousSegment: ContentModelText, stringToReplace: string, replacementString: string, paragraph?: ContentModelParagraph) => boolean;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* CustomReplacePlugin is a plugin that allows you to replace a string with another string in the editor.
|
|
26
|
+
*/
|
|
27
|
+
export declare class CustomReplacePlugin implements EditorPlugin {
|
|
28
|
+
private customReplacements;
|
|
29
|
+
private editor;
|
|
30
|
+
private triggerKeys;
|
|
31
|
+
/**
|
|
32
|
+
* @param customReplacements Custom replacement rules.
|
|
33
|
+
* Ex: [{ stringToReplace: ':)', replacementString: '🙂', replacementHandler: replaceEmojis }]
|
|
34
|
+
*/
|
|
35
|
+
constructor(customReplacements: CustomReplace[]);
|
|
36
|
+
/**
|
|
37
|
+
* Get name of this plugin
|
|
38
|
+
*/
|
|
39
|
+
getName(): string;
|
|
40
|
+
/**
|
|
41
|
+
* The first method that editor will call to a plugin when editor is initializing.
|
|
42
|
+
* It will pass in the editor instance, plugin should take this chance to save the
|
|
43
|
+
* editor reference so that it can call to any editor method or format API later.
|
|
44
|
+
* @param editor The editor object
|
|
45
|
+
*/
|
|
46
|
+
initialize(editor: IEditor): void;
|
|
47
|
+
/**
|
|
48
|
+
* The last method that editor will call to a plugin before it is disposed.
|
|
49
|
+
* Plugin can take this chance to clear the reference to editor. After this method is
|
|
50
|
+
* called, plugin should not call to any editor method since it will result in error.
|
|
51
|
+
*/
|
|
52
|
+
dispose(): void;
|
|
53
|
+
/**
|
|
54
|
+
* Core method for a plugin. Once an event happens in editor, editor will call this
|
|
55
|
+
* method of each plugin to handle the event as long as the event is not handled
|
|
56
|
+
* exclusively by another plugin.
|
|
57
|
+
* @param event The event to handle:
|
|
58
|
+
*/
|
|
59
|
+
onPluginEvent(event: PluginEvent): void;
|
|
60
|
+
private handleEditorInputEvent;
|
|
61
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { formatTextSegmentBeforeSelectionMarker } from 'roosterjs-content-model-api';
|
|
2
|
+
/**
|
|
3
|
+
* CustomReplacePlugin is a plugin that allows you to replace a string with another string in the editor.
|
|
4
|
+
*/
|
|
5
|
+
var CustomReplacePlugin = /** @class */ (function () {
|
|
6
|
+
/**
|
|
7
|
+
* @param customReplacements Custom replacement rules.
|
|
8
|
+
* Ex: [{ stringToReplace: ':)', replacementString: '🙂', replacementHandler: replaceEmojis }]
|
|
9
|
+
*/
|
|
10
|
+
function CustomReplacePlugin(customReplacements) {
|
|
11
|
+
this.customReplacements = customReplacements;
|
|
12
|
+
this.editor = null;
|
|
13
|
+
this.triggerKeys = [];
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Get name of this plugin
|
|
17
|
+
*/
|
|
18
|
+
CustomReplacePlugin.prototype.getName = function () {
|
|
19
|
+
return 'CustomReplace';
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* The first method that editor will call to a plugin when editor is initializing.
|
|
23
|
+
* It will pass in the editor instance, plugin should take this chance to save the
|
|
24
|
+
* editor reference so that it can call to any editor method or format API later.
|
|
25
|
+
* @param editor The editor object
|
|
26
|
+
*/
|
|
27
|
+
CustomReplacePlugin.prototype.initialize = function (editor) {
|
|
28
|
+
this.editor = editor;
|
|
29
|
+
this.triggerKeys = this.customReplacements.map(function (replacement) {
|
|
30
|
+
return replacement.stringToReplace.slice(-1);
|
|
31
|
+
});
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* The last method that editor will call to a plugin before it is disposed.
|
|
35
|
+
* Plugin can take this chance to clear the reference to editor. After this method is
|
|
36
|
+
* called, plugin should not call to any editor method since it will result in error.
|
|
37
|
+
*/
|
|
38
|
+
CustomReplacePlugin.prototype.dispose = function () {
|
|
39
|
+
this.editor = null;
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* Core method for a plugin. Once an event happens in editor, editor will call this
|
|
43
|
+
* method of each plugin to handle the event as long as the event is not handled
|
|
44
|
+
* exclusively by another plugin.
|
|
45
|
+
* @param event The event to handle:
|
|
46
|
+
*/
|
|
47
|
+
CustomReplacePlugin.prototype.onPluginEvent = function (event) {
|
|
48
|
+
if (this.editor) {
|
|
49
|
+
switch (event.eventType) {
|
|
50
|
+
case 'input':
|
|
51
|
+
this.handleEditorInputEvent(this.editor, event);
|
|
52
|
+
break;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
CustomReplacePlugin.prototype.handleEditorInputEvent = function (editor, event) {
|
|
57
|
+
var _this = this;
|
|
58
|
+
var rawEvent = event.rawEvent;
|
|
59
|
+
var selection = editor.getDOMSelection();
|
|
60
|
+
var key = rawEvent.data;
|
|
61
|
+
if (this.customReplacements.length > 0 &&
|
|
62
|
+
rawEvent.inputType === 'insertText' &&
|
|
63
|
+
selection &&
|
|
64
|
+
selection.type === 'range' &&
|
|
65
|
+
selection.range.collapsed &&
|
|
66
|
+
key &&
|
|
67
|
+
this.triggerKeys.indexOf(key) > -1) {
|
|
68
|
+
formatTextSegmentBeforeSelectionMarker(editor, function (_model, previousSegment, paragraph, _markerFormat, context) {
|
|
69
|
+
var replaced = _this.customReplacements.some(function (_a) {
|
|
70
|
+
var stringToReplace = _a.stringToReplace, replacementString = _a.replacementString, replacementHandler = _a.replacementHandler;
|
|
71
|
+
return replacementHandler(previousSegment, stringToReplace, replacementString, paragraph);
|
|
72
|
+
});
|
|
73
|
+
if (replaced) {
|
|
74
|
+
context.canUndoByBackspace = true;
|
|
75
|
+
return true;
|
|
76
|
+
}
|
|
77
|
+
return false;
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
return CustomReplacePlugin;
|
|
82
|
+
}());
|
|
83
|
+
export { CustomReplacePlugin };
|
|
84
|
+
//# sourceMappingURL=CustomReplacePlugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CustomReplacePlugin.js","sourceRoot":"","sources":["../../../../packages/roosterjs-content-model-plugins/lib/customReplace/CustomReplacePlugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sCAAsC,EAAE,MAAM,6BAA6B,CAAC;AAwCrF;;GAEG;AACH;IAII;;;OAGG;IACH,6BAAoB,kBAAmC;QAAnC,uBAAkB,GAAlB,kBAAkB,CAAiB;QAP/C,WAAM,GAAmB,IAAI,CAAC;QAC9B,gBAAW,GAAa,EAAE,CAAC;IAMuB,CAAC;IAE3D;;OAEG;IACH,qCAAO,GAAP;QACI,OAAO,eAAe,CAAC;IAC3B,CAAC;IAED;;;;;OAKG;IACH,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,EAA0D;wBAAxD,eAAe,qBAAA,EAAE,iBAAiB,uBAAA,EAAE,kBAAkB,wBAAA;oBACrD,OAAO,kBAAkB,CACrB,eAAe,EACf,eAAe,EACf,iBAAiB,EACjB,SAAS,CACZ,CAAC;gBACN,CAAC,CACJ,CAAC;gBACF,IAAI,QAAQ,EAAE;oBACV,OAAO,CAAC,kBAAkB,GAAG,IAAI,CAAC;oBAClC,OAAO,IAAI,CAAC;iBACf;gBACD,OAAO,KAAK,CAAC;YACjB,CAAC,CACJ,CAAC;SACL;IACL,CAAC;IACL,0BAAC;AAAD,CAAC,AA1FD,IA0FC","sourcesContent":["import { formatTextSegmentBeforeSelectionMarker } from 'roosterjs-content-model-api';\nimport type {\n ContentModelParagraph,\n ContentModelText,\n EditorInputEvent,\n EditorPlugin,\n IEditor,\n PluginEvent,\n} from 'roosterjs-content-model-types';\n\n/**\n * The CustomReplace interface defines a custom replacement that can be used in CustomReplacePlugin.\n */\nexport interface CustomReplace {\n /**\n * The string to replace in the editor.\n */\n stringToReplace: string;\n\n /**\n * The string to replace with.\n */\n replacementString: string;\n\n /**\n * The handler to replace the string.\n * @param previousSegment The text segment to replace.\n * @param stringToReplace The string to replace.\n * @param replacementString The string to replace with.\n * @param paragraph The paragraph that contains the text segment.\n * @returns True if the string is replaced successfully, otherwise false.\n */\n replacementHandler: (\n previousSegment: ContentModelText,\n stringToReplace: string,\n replacementString: string,\n paragraph?: ContentModelParagraph\n ) => boolean;\n}\n\n/**\n * CustomReplacePlugin is a plugin that allows you to replace a string with another string in the editor.\n */\nexport class CustomReplacePlugin implements EditorPlugin {\n private editor: IEditor | null = null;\n private triggerKeys: string[] = [];\n\n /**\n * @param customReplacements Custom replacement rules.\n * Ex: [{ stringToReplace: ':)', replacementString: '🙂', replacementHandler: replaceEmojis }]\n */\n constructor(private customReplacements: CustomReplace[]) {}\n\n /**\n * Get name of this plugin\n */\n getName() {\n return 'CustomReplace';\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 this.triggerKeys = this.customReplacements.map(replacement =>\n replacement.stringToReplace.slice(-1)\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.editor = 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 switch (event.eventType) {\n case 'input':\n this.handleEditorInputEvent(this.editor, event);\n break;\n }\n }\n }\n\n private handleEditorInputEvent(editor: IEditor, event: EditorInputEvent) {\n const rawEvent = event.rawEvent;\n const selection = editor.getDOMSelection();\n const key = rawEvent.data;\n if (\n this.customReplacements.length > 0 &&\n rawEvent.inputType === 'insertText' &&\n selection &&\n selection.type === 'range' &&\n selection.range.collapsed &&\n key &&\n this.triggerKeys.indexOf(key) > -1\n ) {\n formatTextSegmentBeforeSelectionMarker(\n editor,\n (_model, previousSegment, paragraph, _markerFormat, context) => {\n const replaced = this.customReplacements.some(\n ({ stringToReplace, replacementString, replacementHandler }) => {\n return replacementHandler(\n previousSegment,\n stringToReplace,\n replacementString,\n paragraph\n );\n }\n );\n if (replaced) {\n context.canUndoByBackspace = true;\n return true;\n }\n return false;\n }\n );\n }\n }\n}\n"]}
|
|
@@ -70,11 +70,18 @@ var EditPlugin = /** @class */ (function () {
|
|
|
70
70
|
if (!rawEvent.defaultPrevented && !event.handledByEditFeature) {
|
|
71
71
|
switch (rawEvent.key) {
|
|
72
72
|
case 'Backspace':
|
|
73
|
-
case 'Delete':
|
|
74
73
|
// Use our API to handle BACKSPACE/DELETE key.
|
|
75
74
|
// No need to clear cache here since if we rely on browser's behavior, there will be Input event and its handler will reconcile cache
|
|
76
75
|
keyboardDelete(editor, rawEvent);
|
|
77
76
|
break;
|
|
77
|
+
case 'Delete':
|
|
78
|
+
// Use our API to handle BACKSPACE/DELETE key.
|
|
79
|
+
// No need to clear cache here since if we rely on browser's behavior, there will be Input event and its handler will reconcile cache
|
|
80
|
+
// And leave it to browser when shift key is pressed so that browser will trigger cut event
|
|
81
|
+
if (!event.rawEvent.shiftKey) {
|
|
82
|
+
keyboardDelete(editor, rawEvent);
|
|
83
|
+
}
|
|
84
|
+
break;
|
|
78
85
|
case 'Tab':
|
|
79
86
|
keyboardTab(editor, rawEvent);
|
|
80
87
|
break;
|
|
@@ -91,6 +98,8 @@ var EditPlugin = /** @class */ (function () {
|
|
|
91
98
|
}
|
|
92
99
|
};
|
|
93
100
|
EditPlugin.prototype.handleBeforeInputEvent = function (editor, rawEvent) {
|
|
101
|
+
var _this = this;
|
|
102
|
+
var _a, _b;
|
|
94
103
|
// Some Android IMEs doesn't fire correct keydown event for BACKSPACE/DELETE key
|
|
95
104
|
// Here we translate input event to BACKSPACE/DELETE keydown event to be compatible with existing logic
|
|
96
105
|
if (!this.shouldHandleNextInputEvent ||
|
|
@@ -118,6 +127,15 @@ var EditPlugin = /** @class */ (function () {
|
|
|
118
127
|
}
|
|
119
128
|
if (handled) {
|
|
120
129
|
rawEvent.preventDefault();
|
|
130
|
+
// Restore the selection to avoid the cursor jump issue
|
|
131
|
+
// See: https://issues.chromium.org/issues/330596261
|
|
132
|
+
var selection_1 = editor.getDOMSelection();
|
|
133
|
+
var doc = (_a = this.editor) === null || _a === void 0 ? void 0 : _a.getDocument();
|
|
134
|
+
(_b = doc === null || doc === void 0 ? void 0 : doc.defaultView) === null || _b === void 0 ? void 0 : _b.requestAnimationFrame(function () {
|
|
135
|
+
if (_this.editor) {
|
|
136
|
+
_this.editor.setDOMSelection(selection_1);
|
|
137
|
+
}
|
|
138
|
+
});
|
|
121
139
|
}
|
|
122
140
|
};
|
|
123
141
|
return EditPlugin;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EditPlugin.js","sourceRoot":"","sources":["../../../../packages/roosterjs-content-model-plugins/lib/edit/EditPlugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAQ5C,IAAM,aAAa,GAAG,CAAC,CAAC;AACxB,IAAM,UAAU,GAAG,EAAE,CAAC;AAEtB;;;;;;GAMG;AACH;IAAA;QACY,WAAM,GAAmB,IAAI,CAAC;QAC9B,aAAQ,GAAwB,IAAI,CAAC;QACrC,+BAA0B,GAAG,KAAK,CAAC;
|
|
1
|
+
{"version":3,"file":"EditPlugin.js","sourceRoot":"","sources":["../../../../packages/roosterjs-content-model-plugins/lib/edit/EditPlugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAQ5C,IAAM,aAAa,GAAG,CAAC,CAAC;AACxB,IAAM,UAAU,GAAG,EAAE,CAAC;AAEtB;;;;;;GAMG;AACH;IAAA;QACY,WAAM,GAAmB,IAAI,CAAC;QAC9B,aAAQ,GAAwB,IAAI,CAAC;QACrC,+BAA0B,GAAG,KAAK,CAAC;IA4I/C,CAAC;IA1IG;;OAEG;IACH,4BAAO,GAAP;QACI,OAAO,MAAM,CAAC;IAClB,CAAC;IAED;;;;;OAKG;IACH,+BAAU,GAAV,UAAW,MAAe;QAA1B,iBASC;QARG,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,MAAM,CAAC,cAAc,EAAE,CAAC,SAAS,EAAE;YACnC,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,MAAM,CAAC,cAAc,CAAC;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,aAAH,GAAG,uBAAH,GAAG,CAAE,WAAW,0CAAE,qBAAqB,CAAC;gBACpC,IAAI,KAAI,CAAC,MAAM,EAAE;oBACb,KAAI,CAAC,MAAM,CAAC,eAAe,CAAC,WAAS,CAAC,CAAC;iBAC1C;YACL,CAAC,CAAC,CAAC;SACN;IACL,CAAC;IACL,iBAAC;AAAD,CAAC,AA/ID,IA+IC","sourcesContent":["import { keyboardDelete } from './keyboardDelete';\nimport { keyboardInput } from './keyboardInput';\nimport { keyboardTab } from './keyboardTab';\nimport type {\n EditorPlugin,\n IEditor,\n KeyDownEvent,\n PluginEvent,\n} from 'roosterjs-content-model-types';\n\nconst BACKSPACE_KEY = 8;\nconst DELETE_KEY = 46;\n\n/**\n * Edit plugins helps editor to do editing operation on top of content model.\n * This includes:\n * 1. Delete Key\n * 2. Backspace Key\n * 3. Tab Key\n */\nexport class EditPlugin implements EditorPlugin {\n private editor: IEditor | null = null;\n private disposer: (() => void) | null = null;\n private shouldHandleNextInputEvent = false;\n\n /**\n * Get name of this plugin\n */\n getName() {\n return 'Edit';\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 if (editor.getEnvironment().isAndroid) {\n this.disposer = this.editor.attachDomEvent({\n beforeinput: {\n beforeDispatch: e => this.handleBeforeInputEvent(editor, e),\n },\n });\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.editor = null;\n this.disposer?.();\n this.disposer = 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 switch (event.eventType) {\n case 'keyDown':\n this.handleKeyDownEvent(this.editor, event);\n break;\n }\n }\n }\n\n private handleKeyDownEvent(editor: IEditor, event: KeyDownEvent) {\n const rawEvent = event.rawEvent;\n\n if (!rawEvent.defaultPrevented && !event.handledByEditFeature) {\n switch (rawEvent.key) {\n case 'Backspace':\n // Use our API to handle BACKSPACE/DELETE key.\n // No need to clear cache here since if we rely on browser's behavior, there will be Input event and its handler will reconcile cache\n keyboardDelete(editor, rawEvent);\n break;\n\n case 'Delete':\n // Use our API to handle BACKSPACE/DELETE key.\n // No need to clear cache here since if we rely on browser's behavior, there will be Input event and its handler will reconcile cache\n // And leave it to browser when shift key is pressed so that browser will trigger cut event\n if (!event.rawEvent.shiftKey) {\n keyboardDelete(editor, rawEvent);\n }\n break;\n\n case 'Tab':\n keyboardTab(editor, rawEvent);\n break;\n case 'Unidentified':\n if (editor.getEnvironment().isAndroid) {\n this.shouldHandleNextInputEvent = true;\n }\n break;\n\n case 'Enter':\n default:\n keyboardInput(editor, rawEvent);\n break;\n }\n }\n }\n\n private handleBeforeInputEvent(editor: IEditor, rawEvent: Event) {\n // Some Android IMEs doesn't fire correct keydown event for BACKSPACE/DELETE key\n // Here we translate input event to BACKSPACE/DELETE keydown event to be compatible with existing logic\n if (\n !this.shouldHandleNextInputEvent ||\n !(rawEvent instanceof InputEvent) ||\n rawEvent.defaultPrevented\n ) {\n return;\n }\n this.shouldHandleNextInputEvent = false;\n\n let handled = false;\n switch (rawEvent.inputType) {\n case 'deleteContentBackward':\n handled = keyboardDelete(\n editor,\n new KeyboardEvent('keydown', {\n key: 'Backspace',\n keyCode: BACKSPACE_KEY,\n which: BACKSPACE_KEY,\n })\n );\n break;\n case 'deleteContentForward':\n handled = keyboardDelete(\n editor,\n new KeyboardEvent('keydown', {\n key: 'Delete',\n keyCode: DELETE_KEY,\n which: DELETE_KEY,\n })\n );\n break;\n }\n\n if (handled) {\n rawEvent.preventDefault();\n\n // Restore the selection to avoid the cursor jump issue\n // See: https://issues.chromium.org/issues/330596261\n const selection = editor.getDOMSelection();\n const doc = this.editor?.getDocument();\n doc?.defaultView?.requestAnimationFrame(() => {\n if (this.editor) {\n this.editor.setDOMSelection(selection);\n }\n });\n }\n }\n}\n"]}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { __assign, __read, __spreadArray } from "tslib";
|
|
2
|
+
import { getListAnnounceData } from 'roosterjs-content-model-api';
|
|
2
3
|
import { createBr, createListItem, createListLevel, createParagraph, createSelectionMarker, normalizeContentModel, normalizeParagraph, setParagraphNotImplicit, getClosestAncestorBlockGroupIndex, isBlockGroupOfType, } from 'roosterjs-content-model-dom';
|
|
3
4
|
/**
|
|
4
5
|
* @internal
|
|
@@ -45,7 +46,12 @@ export var handleEnterOnList = function (context) {
|
|
|
45
46
|
listItem_1.levels.pop();
|
|
46
47
|
}
|
|
47
48
|
else {
|
|
48
|
-
createNewListItem(context, listItem_1, listParent);
|
|
49
|
+
var newListItem = createNewListItem(context, listItem_1, listParent);
|
|
50
|
+
if (context.formatContext) {
|
|
51
|
+
context.formatContext.announceData = getListAnnounceData(__spreadArray([
|
|
52
|
+
newListItem
|
|
53
|
+
], __read(path.slice(index + 1)), false));
|
|
54
|
+
}
|
|
49
55
|
}
|
|
50
56
|
}
|
|
51
57
|
rawEvent === null || rawEvent === void 0 ? void 0 : rawEvent.preventDefault();
|
|
@@ -70,6 +76,7 @@ var createNewListItem = function (context, listItem, listParent) {
|
|
|
70
76
|
insertPoint.paragraph = newParagraph;
|
|
71
77
|
context.lastParagraph = newParagraph;
|
|
72
78
|
listParent.blocks.splice(listIndex + 1, 0, newListItem);
|
|
79
|
+
return newListItem;
|
|
73
80
|
};
|
|
74
81
|
var createNewListLevel = function (listItem) {
|
|
75
82
|
return listItem.levels.map(function (level) {
|