roosterjs-content-model-plugins 9.1.0 → 9.2.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/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/index.d.ts +7 -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 +4 -0
- package/lib/tableEdit/OnTableEditorCreatedCallback.js +3 -0
- package/lib/tableEdit/OnTableEditorCreatedCallback.js.map +1 -0
- package/lib/tableEdit/TableEditPlugin.d.ts +4 -1
- package/lib/tableEdit/TableEditPlugin.js +5 -2
- package/lib/tableEdit/TableEditPlugin.js.map +1 -1
- package/lib/tableEdit/editors/TableEditor.d.ts +4 -1
- package/lib/tableEdit/editors/TableEditor.js +23 -7
- package/lib/tableEdit/editors/TableEditor.js.map +1 -1
- package/lib/tableEdit/editors/features/TableEditFeature.js +3 -3
- package/lib/tableEdit/editors/features/TableEditFeature.js.map +1 -1
- package/lib/tableEdit/editors/features/TableInserter.d.ts +2 -1
- package/lib/tableEdit/editors/features/TableInserter.js +7 -9
- package/lib/tableEdit/editors/features/TableInserter.js.map +1 -1
- package/lib/tableEdit/editors/features/TableMover.d.ts +2 -1
- package/lib/tableEdit/editors/features/TableMover.js +8 -11
- package/lib/tableEdit/editors/features/TableMover.js.map +1 -1
- package/lib/tableEdit/editors/features/TableResizer.d.ts +2 -1
- package/lib/tableEdit/editors/features/TableResizer.js +19 -3
- package/lib/tableEdit/editors/features/TableResizer.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/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/index.d.ts +7 -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 +4 -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 +4 -1
- package/lib-amd/tableEdit/TableEditPlugin.js +5 -2
- package/lib-amd/tableEdit/TableEditPlugin.js.map +1 -1
- package/lib-amd/tableEdit/editors/TableEditor.d.ts +4 -1
- package/lib-amd/tableEdit/editors/TableEditor.js +23 -7
- package/lib-amd/tableEdit/editors/TableEditor.js.map +1 -1
- package/lib-amd/tableEdit/editors/features/TableEditFeature.js +3 -3
- package/lib-amd/tableEdit/editors/features/TableEditFeature.js.map +1 -1
- package/lib-amd/tableEdit/editors/features/TableInserter.d.ts +2 -1
- package/lib-amd/tableEdit/editors/features/TableInserter.js +7 -9
- package/lib-amd/tableEdit/editors/features/TableInserter.js.map +1 -1
- package/lib-amd/tableEdit/editors/features/TableMover.d.ts +2 -1
- package/lib-amd/tableEdit/editors/features/TableMover.js +8 -11
- package/lib-amd/tableEdit/editors/features/TableMover.js.map +1 -1
- package/lib-amd/tableEdit/editors/features/TableResizer.d.ts +2 -1
- package/lib-amd/tableEdit/editors/features/TableResizer.js +19 -4
- package/lib-amd/tableEdit/editors/features/TableResizer.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/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/index.d.ts +7 -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 +4 -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 +4 -1
- package/lib-mjs/tableEdit/TableEditPlugin.js +5 -2
- package/lib-mjs/tableEdit/TableEditPlugin.js.map +1 -1
- package/lib-mjs/tableEdit/editors/TableEditor.d.ts +4 -1
- package/lib-mjs/tableEdit/editors/TableEditor.js +24 -8
- package/lib-mjs/tableEdit/editors/TableEditor.js.map +1 -1
- package/lib-mjs/tableEdit/editors/features/TableEditFeature.js +3 -3
- package/lib-mjs/tableEdit/editors/features/TableEditFeature.js.map +1 -1
- package/lib-mjs/tableEdit/editors/features/TableInserter.d.ts +2 -1
- package/lib-mjs/tableEdit/editors/features/TableInserter.js +7 -9
- package/lib-mjs/tableEdit/editors/features/TableInserter.js.map +1 -1
- package/lib-mjs/tableEdit/editors/features/TableMover.d.ts +2 -1
- package/lib-mjs/tableEdit/editors/features/TableMover.js +8 -11
- package/lib-mjs/tableEdit/editors/features/TableMover.js.map +1 -1
- package/lib-mjs/tableEdit/editors/features/TableResizer.d.ts +2 -1
- package/lib-mjs/tableEdit/editors/features/TableResizer.js +19 -3
- package/lib-mjs/tableEdit/editors/features/TableResizer.js.map +1 -1
- package/package.json +5 -5
|
@@ -6,23 +6,31 @@ export declare type AutoFormatOptions = {
|
|
|
6
6
|
/**
|
|
7
7
|
* When true, after type *, ->, -, --, => , —, > and space key a type of bullet list will be triggered. @default true
|
|
8
8
|
*/
|
|
9
|
-
autoBullet
|
|
9
|
+
autoBullet?: boolean;
|
|
10
10
|
/**
|
|
11
11
|
* 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
|
|
12
12
|
*/
|
|
13
|
-
autoNumbering
|
|
13
|
+
autoNumbering?: boolean;
|
|
14
14
|
/**
|
|
15
15
|
* When press backspace before a link, remove the hyperlink
|
|
16
16
|
*/
|
|
17
|
-
autoUnlink
|
|
17
|
+
autoUnlink?: boolean;
|
|
18
18
|
/**
|
|
19
19
|
* When paste content, create hyperlink for the pasted link
|
|
20
20
|
*/
|
|
21
|
-
autoLink
|
|
21
|
+
autoLink?: boolean;
|
|
22
22
|
/**
|
|
23
23
|
* Transform -- into hyphen, if typed between two words
|
|
24
24
|
*/
|
|
25
|
-
autoHyphen
|
|
25
|
+
autoHyphen?: boolean;
|
|
26
|
+
/**
|
|
27
|
+
* Transform 1/2, 1/4, 3/4 into fraction character
|
|
28
|
+
*/
|
|
29
|
+
autoFraction?: boolean;
|
|
30
|
+
/**
|
|
31
|
+
* Transform ordinal numbers into superscript
|
|
32
|
+
*/
|
|
33
|
+
autoOrdinals?: boolean;
|
|
26
34
|
};
|
|
27
35
|
/**
|
|
28
36
|
* Auto Format plugin handles auto formatting, such as transforming * characters into a bullet list.
|
|
@@ -38,6 +46,8 @@ export declare class AutoFormatPlugin implements EditorPlugin {
|
|
|
38
46
|
* - autoLink: A boolean that enables or disables automatic hyperlink creation when pasting or typing content. Defaults to false.
|
|
39
47
|
* - autoUnlink: A boolean that enables or disables automatic hyperlink removal when pressing backspace. Defaults to false.
|
|
40
48
|
* - autoHyphen: A boolean that enables or disables automatic hyphen transformation. Defaults to false.
|
|
49
|
+
* - autoFraction: A boolean that enables or disables automatic fraction transformation. Defaults to false.
|
|
50
|
+
* - autoOrdinals: A boolean that enables or disables automatic ordinal number transformation. Defaults to false.
|
|
41
51
|
*/
|
|
42
52
|
constructor(options?: AutoFormatOptions);
|
|
43
53
|
/**
|
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.AutoFormatPlugin = void 0;
|
|
4
|
+
var roosterjs_content_model_dom_1 = require("roosterjs-content-model-dom");
|
|
4
5
|
var createLink_1 = require("./link/createLink");
|
|
5
6
|
var createLinkAfterSpace_1 = require("./link/createLinkAfterSpace");
|
|
6
7
|
var roosterjs_content_model_api_1 = require("roosterjs-content-model-api");
|
|
7
8
|
var keyboardListTrigger_1 = require("./list/keyboardListTrigger");
|
|
9
|
+
var transformFraction_1 = require("./numbers/transformFraction");
|
|
8
10
|
var transformHyphen_1 = require("./hyphen/transformHyphen");
|
|
11
|
+
var transformOrdinals_1 = require("./numbers/transformOrdinals");
|
|
9
12
|
var unlink_1 = require("./link/unlink");
|
|
10
13
|
/**
|
|
11
14
|
* @internal
|
|
@@ -16,6 +19,8 @@ var DefaultOptions = {
|
|
|
16
19
|
autoUnlink: false,
|
|
17
20
|
autoLink: false,
|
|
18
21
|
autoHyphen: false,
|
|
22
|
+
autoFraction: false,
|
|
23
|
+
autoOrdinals: false,
|
|
19
24
|
};
|
|
20
25
|
/**
|
|
21
26
|
* Auto Format plugin handles auto formatting, such as transforming * characters into a bullet list.
|
|
@@ -29,6 +34,8 @@ var AutoFormatPlugin = /** @class */ (function () {
|
|
|
29
34
|
* - autoLink: A boolean that enables or disables automatic hyperlink creation when pasting or typing content. Defaults to false.
|
|
30
35
|
* - autoUnlink: A boolean that enables or disables automatic hyperlink removal when pressing backspace. Defaults to false.
|
|
31
36
|
* - autoHyphen: A boolean that enables or disables automatic hyphen transformation. Defaults to false.
|
|
37
|
+
* - autoFraction: A boolean that enables or disables automatic fraction transformation. Defaults to false.
|
|
38
|
+
* - autoOrdinals: A boolean that enables or disables automatic ordinal number transformation. Defaults to false.
|
|
32
39
|
*/
|
|
33
40
|
function AutoFormatPlugin(options) {
|
|
34
41
|
if (options === void 0) { options = DefaultOptions; }
|
|
@@ -89,20 +96,40 @@ var AutoFormatPlugin = /** @class */ (function () {
|
|
|
89
96
|
selection.range.collapsed) {
|
|
90
97
|
switch (rawEvent.data) {
|
|
91
98
|
case ' ':
|
|
99
|
+
var formatOptions_1 = {
|
|
100
|
+
changeSource: '',
|
|
101
|
+
apiName: '',
|
|
102
|
+
};
|
|
92
103
|
(0, roosterjs_content_model_api_1.formatTextSegmentBeforeSelectionMarker)(editor, function (model, previousSegment, paragraph, _markerFormat, context) {
|
|
93
|
-
var _a = _this.options, autoBullet = _a.autoBullet, autoNumbering = _a.autoNumbering, autoLink = _a.autoLink, autoHyphen = _a.autoHyphen;
|
|
104
|
+
var _a = _this.options, autoBullet = _a.autoBullet, autoNumbering = _a.autoNumbering, autoLink = _a.autoLink, autoHyphen = _a.autoHyphen, autoFraction = _a.autoFraction, autoOrdinals = _a.autoOrdinals;
|
|
94
105
|
var shouldHyphen = false;
|
|
95
106
|
var shouldLink = false;
|
|
107
|
+
var shouldList = false;
|
|
108
|
+
var shouldFraction = false;
|
|
109
|
+
var shouldOrdinals = false;
|
|
110
|
+
if (autoBullet || autoNumbering) {
|
|
111
|
+
shouldList = (0, keyboardListTrigger_1.keyboardListTrigger)(model, paragraph, context, autoBullet, autoNumbering);
|
|
112
|
+
}
|
|
96
113
|
if (autoLink) {
|
|
97
114
|
shouldLink = (0, createLinkAfterSpace_1.createLinkAfterSpace)(previousSegment, paragraph, context);
|
|
98
115
|
}
|
|
99
116
|
if (autoHyphen) {
|
|
100
117
|
shouldHyphen = (0, transformHyphen_1.transformHyphen)(previousSegment, paragraph, context);
|
|
101
118
|
}
|
|
102
|
-
|
|
119
|
+
if (autoFraction) {
|
|
120
|
+
shouldFraction = (0, transformFraction_1.transformFraction)(previousSegment, paragraph, context);
|
|
121
|
+
}
|
|
122
|
+
if (autoOrdinals) {
|
|
123
|
+
shouldOrdinals = (0, transformOrdinals_1.transformOrdinals)(previousSegment, paragraph, context);
|
|
124
|
+
}
|
|
125
|
+
formatOptions_1.apiName = getApiName(shouldList, shouldHyphen);
|
|
126
|
+
formatOptions_1.changeSource = getChangeSource(shouldList, shouldHyphen, shouldLink);
|
|
127
|
+
return (shouldList ||
|
|
103
128
|
shouldHyphen ||
|
|
104
|
-
shouldLink
|
|
105
|
-
|
|
129
|
+
shouldLink ||
|
|
130
|
+
shouldFraction ||
|
|
131
|
+
shouldOrdinals);
|
|
132
|
+
}, formatOptions_1);
|
|
106
133
|
break;
|
|
107
134
|
}
|
|
108
135
|
}
|
|
@@ -128,4 +155,14 @@ var AutoFormatPlugin = /** @class */ (function () {
|
|
|
128
155
|
return AutoFormatPlugin;
|
|
129
156
|
}());
|
|
130
157
|
exports.AutoFormatPlugin = AutoFormatPlugin;
|
|
158
|
+
var getApiName = function (shouldList, shouldHyphen) {
|
|
159
|
+
return shouldList ? 'autoToggleList' : shouldHyphen ? 'autoHyphen' : '';
|
|
160
|
+
};
|
|
161
|
+
var getChangeSource = function (shouldList, shouldHyphen, shouldLink) {
|
|
162
|
+
return shouldList || shouldHyphen
|
|
163
|
+
? roosterjs_content_model_dom_1.ChangeSource.AutoFormat
|
|
164
|
+
: shouldLink
|
|
165
|
+
? roosterjs_content_model_dom_1.ChangeSource.AutoLink
|
|
166
|
+
: '';
|
|
167
|
+
};
|
|
131
168
|
//# 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,gDAA+C;AAC/C,oEAAmE;AACnE,2EAAqF;AACrF,kEAAiE;AACjE,4DAA2D;AAC3D,wCAAuC;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;;;GAGG;AACH;IAEI;;;;;;;OAOG;IACH,0BAAoB,OAA2C;QAA3C,wBAAA,EAAA,wBAA2C;QAA3C,YAAO,GAAP,OAAO,CAAoC;QATvD,WAAM,GAAmB,IAAI,CAAC;IAS4B,CAAC;IAEnE;;OAEG;IACH,kCAAO,GAAP;QACI,OAAO,YAAY,CAAC;IACxB,CAAC;IAED;;;;;OAKG;IACH,qCAAU,GAAV,UAAW,MAAe;QACtB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACzB,CAAC;IAED;;;;OAIG;IACH,kCAAO,GAAP;QACI,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC;IACvB,CAAC;IAED;;;;;OAKG;IACH,wCAAa,GAAb,UAAc,KAAkB;QAC5B,IAAI,IAAI,CAAC,MAAM,EAAE;YACb,QAAQ,KAAK,CAAC,SAAS,EAAE;gBACrB,KAAK,OAAO;oBACR,IAAI,CAAC,sBAAsB,CAAC,IAAI,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;oBAChD,MAAM;gBACV,KAAK,SAAS;oBACV,IAAI,CA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oBACF,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,IAAA,eAAM,EAAC,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,IAAA,uBAAU,EAAC,MAAM,CAAC,CAAC;SACtB;IACL,CAAC;IACL,uBAAC;AAAD,CAAC,AApID,IAoIC;AApIY,4CAAgB","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,2EAA2D;AAC3D,gDAA+C;AAC/C,oEAAmE;AACnE,2EAAqF;AACrF,kEAAiE;AACjE,iEAAgE;AAChE,4DAA2D;AAC3D,iEAAgE;AAChE,wCAAuC;AAmDvC;;GAEG;AACH,IAAM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AC,EAAE,CAAC;AAC5E,CAAC,CAAC;AAEF,IAAM,eAAe,GAAG,UAAC,UAAmB,EAAE,YAAqB,EAAE,UAAmB;IACpF,OAAO,UAAU,IAAI,YAAY;QAC7B,CAAC,CAAC,0CAAY,CAAC,UAAU;QACzB,CAAC,CAAC,UAAU;YACZ,CAAC,CAAC,0CAAY,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 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createLink.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-plugins/lib/autoFormat/link/createLink.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"createLink.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-plugins/lib/autoFormat/link/createLink.ts"],"names":[],"mappings":";;;AAAA,2EAAoE;AACpE,2EAAgG;AAGhG;;GAEG;AACH,SAAgB,UAAU,CAAC,MAAe;IACtC,IAAA,oEAAsC,EAClC,MAAM,EACN,UAAC,MAAM,EAAE,WAAW,EAAE,UAAU;QAC5B,IAAI,QAAQ,GAAoB,IAAI,CAAC;QACrC,IAAI,CAAC,WAAW,CAAC,IAAI,IAAI,CAAC,QAAQ,GAAG,IAAA,uCAAS,EAAC,WAAW,CAAC,IAAI,CAAC,CAAC,EAAE;YAC/D,IAAA,qCAAO,EAAC,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,0CAAY,CAAC,QAAQ;KACtC,CACJ,CAAC;AACN,CAAC;AArBD,gCAqBC","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"]}
|
|
@@ -9,15 +9,13 @@ var roosterjs_content_model_api_1 = require("roosterjs-content-model-api");
|
|
|
9
9
|
function keyboardListTrigger(model, paragraph, context, shouldSearchForBullet, shouldSearchForNumbering) {
|
|
10
10
|
if (shouldSearchForBullet === void 0) { shouldSearchForBullet = true; }
|
|
11
11
|
if (shouldSearchForNumbering === void 0) { shouldSearchForNumbering = true; }
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
return true;
|
|
20
|
-
}
|
|
12
|
+
var listStyleType = (0, getListTypeStyle_1.getListTypeStyle)(model, shouldSearchForBullet, shouldSearchForNumbering);
|
|
13
|
+
if (listStyleType) {
|
|
14
|
+
paragraph.segments.splice(0, 1);
|
|
15
|
+
var listType = listStyleType.listType, styleType = listStyleType.styleType, index = listStyleType.index;
|
|
16
|
+
triggerList(model, listType, styleType, index);
|
|
17
|
+
context.canUndoByBackspace = true;
|
|
18
|
+
return true;
|
|
21
19
|
}
|
|
22
20
|
return false;
|
|
23
21
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"keyboardListTrigger.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-plugins/lib/autoFormat/list/keyboardListTrigger.ts"],"names":[],"mappings":";;;AAAA,uDAAsD;AACtD,2EAIqC;AAOrC;;GAEG;AACH,SAAgB,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,uDAAsD;AACtD,2EAIqC;AAOrC;;GAEG;AACH,SAAgB,mBAAmB,CAC/B,KAA2B,EAC3B,SAAgC,EAChC,OAAkC,EAClC,qBAAqC,EACrC,wBAAwC;IADxC,sCAAA,EAAA,4BAAqC;IACrC,yCAAA,EAAA,+BAAwC;IAExC,IAAM,aAAa,GAAG,IAAA,mCAAgB,EAAC,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;AAjBD,kDAiBC;AAED,IAAM,WAAW,GAAG,UAChB,KAA2B,EAC3B,QAAqB,EACrB,SAAiB,EACjB,KAAc;IAEd,IAAA,yCAAW,EAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;IAC7B,IAAM,aAAa,GAAG,QAAQ,IAAI,IAAI,CAAC;IACvC,IAAI,KAAK,IAAI,KAAK,GAAG,CAAC,IAAI,aAAa,EAAE;QACrC,IAAA,qDAAuB,EAAC,KAAK,EAAE,KAAK,CAAC,CAAC;KACzC;IACD,IAAA,+CAAiB,EACb,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,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.transformFraction = void 0;
|
|
4
|
+
var splitTextSegment_1 = require("../../pluginUtils/splitTextSegment");
|
|
5
|
+
var FRACTIONS = {
|
|
6
|
+
'1/2': '½',
|
|
7
|
+
'1/4': '¼',
|
|
8
|
+
'3/4': '¾',
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* @internal
|
|
12
|
+
*/
|
|
13
|
+
function transformFraction(previousSegment, paragraph, context) {
|
|
14
|
+
var _a;
|
|
15
|
+
var fraction = (_a = previousSegment.text.split(' ').pop()) === null || _a === void 0 ? void 0 : _a.trim();
|
|
16
|
+
if (fraction && FRACTIONS[fraction]) {
|
|
17
|
+
var textLength = previousSegment.text.length - 1;
|
|
18
|
+
var textIndex = textLength - fraction.length;
|
|
19
|
+
var textSegment = (0, splitTextSegment_1.splitTextSegment)(previousSegment, paragraph, textIndex, textLength);
|
|
20
|
+
textSegment.text = FRACTIONS[fraction];
|
|
21
|
+
context.canUndoByBackspace = true;
|
|
22
|
+
return true;
|
|
23
|
+
}
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
exports.transformFraction = transformFraction;
|
|
27
|
+
//# 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,uEAAsE;AAOtE,IAAM,SAAS,GAA2B;IACtC,KAAK,EAAE,GAAG;IACV,KAAK,EAAE,GAAG;IACV,KAAK,EAAE,GAAG;CACb,CAAC;AAEF;;GAEG;AACH,SAAgB,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,IAAA,mCAAgB,EAAC,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;AAjBD,8CAiBC","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,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.transformOrdinals = void 0;
|
|
4
|
+
var splitTextSegment_1 = require("../../pluginUtils/splitTextSegment");
|
|
5
|
+
var getOrdinal = function (value) {
|
|
6
|
+
var ORDINALS = {
|
|
7
|
+
1: 'st',
|
|
8
|
+
2: 'nd',
|
|
9
|
+
3: 'rd',
|
|
10
|
+
};
|
|
11
|
+
return ORDINALS[value] || 'th';
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* @internal
|
|
15
|
+
*/
|
|
16
|
+
function transformOrdinals(previousSegment, paragraph, context) {
|
|
17
|
+
var _a;
|
|
18
|
+
var value = (_a = previousSegment.text.split(' ').pop()) === null || _a === void 0 ? void 0 : _a.trim();
|
|
19
|
+
if (value) {
|
|
20
|
+
var ordinal = value.substring(value.length - 2);
|
|
21
|
+
var ordinalValue = parseInt(value);
|
|
22
|
+
if (ordinalValue && getOrdinal(ordinalValue) === ordinal) {
|
|
23
|
+
var ordinalSegment = (0, splitTextSegment_1.splitTextSegment)(previousSegment, paragraph, previousSegment.text.length - 3, previousSegment.text.length - 1);
|
|
24
|
+
ordinalSegment.format.superOrSubScriptSequence = 'super';
|
|
25
|
+
context.canUndoByBackspace = true;
|
|
26
|
+
return true;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
exports.transformOrdinals = transformOrdinals;
|
|
32
|
+
//# 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,uEAAsE;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,SAAgB,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,IAAA,mCAAgB,EACnC,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;AAvBD,8CAuBC","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,87 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CustomReplacePlugin = void 0;
|
|
4
|
+
var roosterjs_content_model_api_1 = require("roosterjs-content-model-api");
|
|
5
|
+
/**
|
|
6
|
+
* CustomReplacePlugin is a plugin that allows you to replace a string with another string in the editor.
|
|
7
|
+
*/
|
|
8
|
+
var CustomReplacePlugin = /** @class */ (function () {
|
|
9
|
+
/**
|
|
10
|
+
* @param customReplacements Custom replacement rules.
|
|
11
|
+
* Ex: [{ stringToReplace: ':)', replacementString: '🙂', replacementHandler: replaceEmojis }]
|
|
12
|
+
*/
|
|
13
|
+
function CustomReplacePlugin(customReplacements) {
|
|
14
|
+
this.customReplacements = customReplacements;
|
|
15
|
+
this.editor = null;
|
|
16
|
+
this.triggerKeys = [];
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Get name of this plugin
|
|
20
|
+
*/
|
|
21
|
+
CustomReplacePlugin.prototype.getName = function () {
|
|
22
|
+
return 'CustomReplace';
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* The first method that editor will call to a plugin when editor is initializing.
|
|
26
|
+
* It will pass in the editor instance, plugin should take this chance to save the
|
|
27
|
+
* editor reference so that it can call to any editor method or format API later.
|
|
28
|
+
* @param editor The editor object
|
|
29
|
+
*/
|
|
30
|
+
CustomReplacePlugin.prototype.initialize = function (editor) {
|
|
31
|
+
this.editor = editor;
|
|
32
|
+
this.triggerKeys = this.customReplacements.map(function (replacement) {
|
|
33
|
+
return replacement.stringToReplace.slice(-1);
|
|
34
|
+
});
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* The last method that editor will call to a plugin before it is disposed.
|
|
38
|
+
* Plugin can take this chance to clear the reference to editor. After this method is
|
|
39
|
+
* called, plugin should not call to any editor method since it will result in error.
|
|
40
|
+
*/
|
|
41
|
+
CustomReplacePlugin.prototype.dispose = function () {
|
|
42
|
+
this.editor = null;
|
|
43
|
+
};
|
|
44
|
+
/**
|
|
45
|
+
* Core method for a plugin. Once an event happens in editor, editor will call this
|
|
46
|
+
* method of each plugin to handle the event as long as the event is not handled
|
|
47
|
+
* exclusively by another plugin.
|
|
48
|
+
* @param event The event to handle:
|
|
49
|
+
*/
|
|
50
|
+
CustomReplacePlugin.prototype.onPluginEvent = function (event) {
|
|
51
|
+
if (this.editor) {
|
|
52
|
+
switch (event.eventType) {
|
|
53
|
+
case 'input':
|
|
54
|
+
this.handleEditorInputEvent(this.editor, event);
|
|
55
|
+
break;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
CustomReplacePlugin.prototype.handleEditorInputEvent = function (editor, event) {
|
|
60
|
+
var _this = this;
|
|
61
|
+
var rawEvent = event.rawEvent;
|
|
62
|
+
var selection = editor.getDOMSelection();
|
|
63
|
+
var key = rawEvent.data;
|
|
64
|
+
if (this.customReplacements.length > 0 &&
|
|
65
|
+
rawEvent.inputType === 'insertText' &&
|
|
66
|
+
selection &&
|
|
67
|
+
selection.type === 'range' &&
|
|
68
|
+
selection.range.collapsed &&
|
|
69
|
+
key &&
|
|
70
|
+
this.triggerKeys.indexOf(key) > -1) {
|
|
71
|
+
(0, roosterjs_content_model_api_1.formatTextSegmentBeforeSelectionMarker)(editor, function (_model, previousSegment, paragraph, _markerFormat, context) {
|
|
72
|
+
var replaced = _this.customReplacements.some(function (_a) {
|
|
73
|
+
var stringToReplace = _a.stringToReplace, replacementString = _a.replacementString, replacementHandler = _a.replacementHandler;
|
|
74
|
+
return replacementHandler(previousSegment, stringToReplace, replacementString, paragraph);
|
|
75
|
+
});
|
|
76
|
+
if (replaced) {
|
|
77
|
+
context.canUndoByBackspace = true;
|
|
78
|
+
return true;
|
|
79
|
+
}
|
|
80
|
+
return false;
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
return CustomReplacePlugin;
|
|
85
|
+
}());
|
|
86
|
+
exports.CustomReplacePlugin = CustomReplacePlugin;
|
|
87
|
+
//# 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,2EAAqF;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;;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AC,IAAI,CACzC,UAAC,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;AA1FY,kDAAmB","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"]}
|
package/lib/edit/EditPlugin.js
CHANGED
|
@@ -73,11 +73,18 @@ var EditPlugin = /** @class */ (function () {
|
|
|
73
73
|
if (!rawEvent.defaultPrevented && !event.handledByEditFeature) {
|
|
74
74
|
switch (rawEvent.key) {
|
|
75
75
|
case 'Backspace':
|
|
76
|
-
case 'Delete':
|
|
77
76
|
// Use our API to handle BACKSPACE/DELETE key.
|
|
78
77
|
// 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
|
|
79
78
|
(0, keyboardDelete_1.keyboardDelete)(editor, rawEvent);
|
|
80
79
|
break;
|
|
80
|
+
case 'Delete':
|
|
81
|
+
// Use our API to handle BACKSPACE/DELETE key.
|
|
82
|
+
// 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
|
|
83
|
+
// And leave it to browser when shift key is pressed so that browser will trigger cut event
|
|
84
|
+
if (!event.rawEvent.shiftKey) {
|
|
85
|
+
(0, keyboardDelete_1.keyboardDelete)(editor, rawEvent);
|
|
86
|
+
}
|
|
87
|
+
break;
|
|
81
88
|
case 'Tab':
|
|
82
89
|
(0, keyboardTab_1.keyboardTab)(editor, rawEvent);
|
|
83
90
|
break;
|
|
@@ -94,6 +101,8 @@ var EditPlugin = /** @class */ (function () {
|
|
|
94
101
|
}
|
|
95
102
|
};
|
|
96
103
|
EditPlugin.prototype.handleBeforeInputEvent = function (editor, rawEvent) {
|
|
104
|
+
var _this = this;
|
|
105
|
+
var _a, _b;
|
|
97
106
|
// Some Android IMEs doesn't fire correct keydown event for BACKSPACE/DELETE key
|
|
98
107
|
// Here we translate input event to BACKSPACE/DELETE keydown event to be compatible with existing logic
|
|
99
108
|
if (!this.shouldHandleNextInputEvent ||
|
|
@@ -121,6 +130,15 @@ var EditPlugin = /** @class */ (function () {
|
|
|
121
130
|
}
|
|
122
131
|
if (handled) {
|
|
123
132
|
rawEvent.preventDefault();
|
|
133
|
+
// Restore the selection to avoid the cursor jump issue
|
|
134
|
+
// See: https://issues.chromium.org/issues/330596261
|
|
135
|
+
var selection_1 = editor.getDOMSelection();
|
|
136
|
+
var doc = (_a = this.editor) === null || _a === void 0 ? void 0 : _a.getDocument();
|
|
137
|
+
(_b = doc === null || doc === void 0 ? void 0 : doc.defaultView) === null || _b === void 0 ? void 0 : _b.requestAnimationFrame(function () {
|
|
138
|
+
if (_this.editor) {
|
|
139
|
+
_this.editor.setDOMSelection(selection_1);
|
|
140
|
+
}
|
|
141
|
+
});
|
|
124
142
|
}
|
|
125
143
|
};
|
|
126
144
|
return EditPlugin;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EditPlugin.js","sourceRoot":"","sources":["../../../../packages/roosterjs-content-model-plugins/lib/edit/EditPlugin.ts"],"names":[],"mappings":";;;AAAA,mDAAkD;AAClD,iDAAgD;AAChD,6CAA4C;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,mDAAkD;AAClD,iDAAgD;AAChD,6CAA4C;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;gBACvC,WAAW,EAAE;oBACT,cAAc,EAAE,UAAA,CAAC,IAAI,OAAA,KAAI,CAAC,sBAAsB,CAAC,MAAM,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qB,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;AA/IY,gCAAU","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"]}
|