roosterjs-content-model-plugins 9.10.0 → 9.11.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 +5 -35
- package/lib/autoFormat/AutoFormatPlugin.js +18 -8
- package/lib/autoFormat/AutoFormatPlugin.js.map +1 -1
- package/lib/autoFormat/interface/AutoFormatOptions.d.ts +26 -0
- package/lib/autoFormat/interface/AutoFormatOptions.js +3 -0
- package/lib/autoFormat/interface/AutoFormatOptions.js.map +1 -0
- package/lib/autoFormat/interface/AutoLinkOptions.d.ts +21 -0
- package/lib/autoFormat/interface/AutoLinkOptions.js +3 -0
- package/lib/autoFormat/interface/AutoLinkOptions.js.map +1 -0
- package/lib/autoFormat/link/createLink.d.ts +2 -1
- package/lib/autoFormat/link/createLink.js +5 -4
- package/lib/autoFormat/link/createLink.js.map +1 -1
- package/lib/autoFormat/link/createLinkAfterSpace.d.ts +2 -1
- package/lib/autoFormat/link/createLinkAfterSpace.js +5 -4
- package/lib/autoFormat/link/createLinkAfterSpace.js.map +1 -1
- package/lib/autoFormat/link/getLinkUrl.d.ts +5 -0
- package/lib/autoFormat/link/getLinkUrl.js +26 -0
- package/lib/autoFormat/link/getLinkUrl.js.map +1 -0
- package/lib/edit/EditPlugin.js +1 -1
- package/lib/edit/EditPlugin.js.map +1 -1
- package/lib/edit/keyboardEnter.js +2 -1
- package/lib/edit/keyboardEnter.js.map +1 -1
- package/lib/edit/keyboardInput.js +1 -0
- package/lib/edit/keyboardInput.js.map +1 -1
- package/lib/edit/keyboardTab.js +2 -1
- package/lib/edit/keyboardTab.js.map +1 -1
- package/lib/imageEdit/ImageEditPlugin.d.ts +2 -2
- package/lib/imageEdit/ImageEditPlugin.js +7 -3
- package/lib/imageEdit/ImageEditPlugin.js.map +1 -1
- package/lib/imageEdit/utils/findEditingImage.js +2 -2
- package/lib/imageEdit/utils/findEditingImage.js.map +1 -1
- package/lib/index.d.ts +3 -1
- package/lib/index.js.map +1 -1
- package/lib-amd/autoFormat/AutoFormatPlugin.d.ts +5 -35
- package/lib-amd/autoFormat/AutoFormatPlugin.js +18 -8
- package/lib-amd/autoFormat/AutoFormatPlugin.js.map +1 -1
- package/lib-amd/autoFormat/interface/AutoFormatOptions.d.ts +26 -0
- package/lib-amd/autoFormat/interface/AutoFormatOptions.js +5 -0
- package/lib-amd/autoFormat/interface/AutoFormatOptions.js.map +1 -0
- package/lib-amd/autoFormat/interface/AutoLinkOptions.d.ts +21 -0
- package/lib-amd/autoFormat/interface/AutoLinkOptions.js +5 -0
- package/lib-amd/autoFormat/interface/AutoLinkOptions.js.map +1 -0
- package/lib-amd/autoFormat/link/createLink.d.ts +2 -1
- package/lib-amd/autoFormat/link/createLink.js +5 -5
- package/lib-amd/autoFormat/link/createLink.js.map +1 -1
- package/lib-amd/autoFormat/link/createLinkAfterSpace.d.ts +2 -1
- package/lib-amd/autoFormat/link/createLinkAfterSpace.js +5 -5
- package/lib-amd/autoFormat/link/createLinkAfterSpace.js.map +1 -1
- package/lib-amd/autoFormat/link/getLinkUrl.d.ts +5 -0
- package/lib-amd/autoFormat/link/getLinkUrl.js +27 -0
- package/lib-amd/autoFormat/link/getLinkUrl.js.map +1 -0
- package/lib-amd/edit/EditPlugin.js +1 -1
- package/lib-amd/edit/EditPlugin.js.map +1 -1
- package/lib-amd/edit/keyboardEnter.js +2 -1
- package/lib-amd/edit/keyboardEnter.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 +2 -1
- package/lib-amd/edit/keyboardTab.js.map +1 -1
- package/lib-amd/imageEdit/ImageEditPlugin.d.ts +2 -2
- package/lib-amd/imageEdit/ImageEditPlugin.js +7 -3
- package/lib-amd/imageEdit/ImageEditPlugin.js.map +1 -1
- package/lib-amd/imageEdit/utils/findEditingImage.js +2 -2
- package/lib-amd/imageEdit/utils/findEditingImage.js.map +1 -1
- package/lib-amd/index.d.ts +3 -1
- package/lib-amd/index.js.map +1 -1
- package/lib-mjs/autoFormat/AutoFormatPlugin.d.ts +5 -35
- package/lib-mjs/autoFormat/AutoFormatPlugin.js +18 -8
- package/lib-mjs/autoFormat/AutoFormatPlugin.js.map +1 -1
- package/lib-mjs/autoFormat/interface/AutoFormatOptions.d.ts +26 -0
- package/lib-mjs/autoFormat/interface/AutoFormatOptions.js +2 -0
- package/lib-mjs/autoFormat/interface/AutoFormatOptions.js.map +1 -0
- package/lib-mjs/autoFormat/interface/AutoLinkOptions.d.ts +21 -0
- package/lib-mjs/autoFormat/interface/AutoLinkOptions.js +2 -0
- package/lib-mjs/autoFormat/interface/AutoLinkOptions.js.map +1 -0
- package/lib-mjs/autoFormat/link/createLink.d.ts +2 -1
- package/lib-mjs/autoFormat/link/createLink.js +6 -5
- package/lib-mjs/autoFormat/link/createLink.js.map +1 -1
- package/lib-mjs/autoFormat/link/createLinkAfterSpace.d.ts +2 -1
- package/lib-mjs/autoFormat/link/createLinkAfterSpace.js +6 -5
- package/lib-mjs/autoFormat/link/createLinkAfterSpace.js.map +1 -1
- package/lib-mjs/autoFormat/link/getLinkUrl.d.ts +5 -0
- package/lib-mjs/autoFormat/link/getLinkUrl.js +22 -0
- package/lib-mjs/autoFormat/link/getLinkUrl.js.map +1 -0
- package/lib-mjs/edit/EditPlugin.js +1 -1
- package/lib-mjs/edit/EditPlugin.js.map +1 -1
- package/lib-mjs/edit/keyboardEnter.js +2 -1
- package/lib-mjs/edit/keyboardEnter.js.map +1 -1
- package/lib-mjs/edit/keyboardInput.js +2 -1
- package/lib-mjs/edit/keyboardInput.js.map +1 -1
- package/lib-mjs/edit/keyboardTab.js +2 -1
- package/lib-mjs/edit/keyboardTab.js.map +1 -1
- package/lib-mjs/imageEdit/ImageEditPlugin.d.ts +2 -2
- package/lib-mjs/imageEdit/ImageEditPlugin.js +7 -3
- package/lib-mjs/imageEdit/ImageEditPlugin.js.map +1 -1
- package/lib-mjs/imageEdit/utils/findEditingImage.js +2 -2
- package/lib-mjs/imageEdit/utils/findEditingImage.js.map +1 -1
- package/lib-mjs/index.d.ts +3 -1
- package/lib-mjs/index.js.map +1 -1
- package/package.json +5 -5
|
@@ -1,37 +1,5 @@
|
|
|
1
|
+
import type { AutoFormatOptions } from './interface/AutoFormatOptions';
|
|
1
2
|
import type { EditorPlugin, IEditor, PluginEvent } from 'roosterjs-content-model-types';
|
|
2
|
-
/**
|
|
3
|
-
* Options to customize the Content Model Auto Format Plugin
|
|
4
|
-
*/
|
|
5
|
-
export declare type AutoFormatOptions = {
|
|
6
|
-
/**
|
|
7
|
-
* When true, after type *, ->, -, --, => , —, > and space key a type of bullet list will be triggered. @default true
|
|
8
|
-
*/
|
|
9
|
-
autoBullet?: boolean;
|
|
10
|
-
/**
|
|
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
|
-
*/
|
|
13
|
-
autoNumbering?: boolean;
|
|
14
|
-
/**
|
|
15
|
-
* When press backspace before a link, remove the hyperlink
|
|
16
|
-
*/
|
|
17
|
-
autoUnlink?: boolean;
|
|
18
|
-
/**
|
|
19
|
-
* When paste content, create hyperlink for the pasted link
|
|
20
|
-
*/
|
|
21
|
-
autoLink?: boolean;
|
|
22
|
-
/**
|
|
23
|
-
* Transform -- into hyphen, if typed between two words
|
|
24
|
-
*/
|
|
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;
|
|
34
|
-
};
|
|
35
3
|
/**
|
|
36
4
|
* Auto Format plugin handles auto formatting, such as transforming * characters into a bullet list.
|
|
37
5
|
* It can be customized with options to enable or disable auto list features.
|
|
@@ -43,11 +11,13 @@ export declare class AutoFormatPlugin implements EditorPlugin {
|
|
|
43
11
|
* @param options An optional parameter that takes in an object of type AutoFormatOptions, which includes the following properties:
|
|
44
12
|
* - autoBullet: A boolean that enables or disables automatic bullet list formatting. Defaults to false.
|
|
45
13
|
* - autoNumbering: A boolean that enables or disables automatic numbering formatting. Defaults to false.
|
|
46
|
-
* - autoLink: A boolean that enables or disables automatic hyperlink creation when pasting or typing content. Defaults to false.
|
|
47
|
-
* - autoUnlink: A boolean that enables or disables automatic hyperlink removal when pressing backspace. Defaults to false.
|
|
48
14
|
* - autoHyphen: A boolean that enables or disables automatic hyphen transformation. Defaults to false.
|
|
49
15
|
* - autoFraction: A boolean that enables or disables automatic fraction transformation. Defaults to false.
|
|
50
16
|
* - autoOrdinals: A boolean that enables or disables automatic ordinal number transformation. Defaults to false.
|
|
17
|
+
* - autoLink: A boolean that enables or disables automatic hyperlink url address creation when pasting or typing content. Defaults to false.
|
|
18
|
+
* - autoUnlink: A boolean that enables or disables automatic hyperlink removal when pressing backspace. Defaults to false.
|
|
19
|
+
* - autoTel: A boolean that enables or disables automatic hyperlink telephone numbers transformation. Defaults to false.
|
|
20
|
+
* - autoMailto: A boolean that enables or disables automatic hyperlink email address transformation. Defaults to false.
|
|
51
21
|
*/
|
|
52
22
|
constructor(options?: AutoFormatOptions);
|
|
53
23
|
/**
|
|
@@ -31,11 +31,13 @@ var AutoFormatPlugin = /** @class */ (function () {
|
|
|
31
31
|
* @param options An optional parameter that takes in an object of type AutoFormatOptions, which includes the following properties:
|
|
32
32
|
* - autoBullet: A boolean that enables or disables automatic bullet list formatting. Defaults to false.
|
|
33
33
|
* - autoNumbering: A boolean that enables or disables automatic numbering formatting. Defaults to false.
|
|
34
|
-
* - autoLink: A boolean that enables or disables automatic hyperlink creation when pasting or typing content. Defaults to false.
|
|
35
|
-
* - autoUnlink: A boolean that enables or disables automatic hyperlink removal when pressing backspace. Defaults to false.
|
|
36
34
|
* - autoHyphen: A boolean that enables or disables automatic hyphen transformation. Defaults to false.
|
|
37
35
|
* - autoFraction: A boolean that enables or disables automatic fraction transformation. Defaults to false.
|
|
38
36
|
* - autoOrdinals: A boolean that enables or disables automatic ordinal number transformation. Defaults to false.
|
|
37
|
+
* - autoLink: A boolean that enables or disables automatic hyperlink url address creation when pasting or typing content. Defaults to false.
|
|
38
|
+
* - autoUnlink: A boolean that enables or disables automatic hyperlink removal when pressing backspace. Defaults to false.
|
|
39
|
+
* - autoTel: A boolean that enables or disables automatic hyperlink telephone numbers transformation. Defaults to false.
|
|
40
|
+
* - autoMailto: A boolean that enables or disables automatic hyperlink email address transformation. Defaults to false.
|
|
39
41
|
*/
|
|
40
42
|
function AutoFormatPlugin(options) {
|
|
41
43
|
if (options === void 0) { options = DefaultOptions; }
|
|
@@ -101,7 +103,7 @@ var AutoFormatPlugin = /** @class */ (function () {
|
|
|
101
103
|
apiName: '',
|
|
102
104
|
};
|
|
103
105
|
(0, roosterjs_content_model_api_1.formatTextSegmentBeforeSelectionMarker)(editor, function (model, previousSegment, paragraph, _markerFormat, context) {
|
|
104
|
-
var _a = _this.options, autoBullet = _a.autoBullet, autoNumbering = _a.autoNumbering, autoLink = _a.autoLink, autoHyphen = _a.autoHyphen, autoFraction = _a.autoFraction, autoOrdinals = _a.autoOrdinals;
|
|
106
|
+
var _a = _this.options, autoBullet = _a.autoBullet, autoNumbering = _a.autoNumbering, autoLink = _a.autoLink, autoHyphen = _a.autoHyphen, autoFraction = _a.autoFraction, autoOrdinals = _a.autoOrdinals, autoMailto = _a.autoMailto, autoTel = _a.autoTel;
|
|
105
107
|
var shouldHyphen = false;
|
|
106
108
|
var shouldLink = false;
|
|
107
109
|
var shouldList = false;
|
|
@@ -110,8 +112,12 @@ var AutoFormatPlugin = /** @class */ (function () {
|
|
|
110
112
|
if (autoBullet || autoNumbering) {
|
|
111
113
|
shouldList = (0, keyboardListTrigger_1.keyboardListTrigger)(model, paragraph, context, autoBullet, autoNumbering);
|
|
112
114
|
}
|
|
113
|
-
if (autoLink) {
|
|
114
|
-
shouldLink = (0, createLinkAfterSpace_1.createLinkAfterSpace)(previousSegment, paragraph, context
|
|
115
|
+
if (autoLink || autoTel || autoMailto) {
|
|
116
|
+
shouldLink = (0, createLinkAfterSpace_1.createLinkAfterSpace)(previousSegment, paragraph, context, {
|
|
117
|
+
autoLink: autoLink,
|
|
118
|
+
autoTel: autoTel,
|
|
119
|
+
autoMailto: autoMailto,
|
|
120
|
+
});
|
|
115
121
|
}
|
|
116
122
|
if (autoHyphen) {
|
|
117
123
|
shouldHyphen = (0, transformHyphen_1.transformHyphen)(previousSegment, paragraph, context);
|
|
@@ -147,9 +153,13 @@ var AutoFormatPlugin = /** @class */ (function () {
|
|
|
147
153
|
}
|
|
148
154
|
};
|
|
149
155
|
AutoFormatPlugin.prototype.handleContentChangedEvent = function (editor, event) {
|
|
150
|
-
var
|
|
151
|
-
if (event.source == 'Paste' && autoLink) {
|
|
152
|
-
(0, createLink_1.createLink)(editor
|
|
156
|
+
var _a = this.options, autoLink = _a.autoLink, autoTel = _a.autoTel, autoMailto = _a.autoMailto;
|
|
157
|
+
if (event.source == 'Paste' && (autoLink || autoTel || autoMailto)) {
|
|
158
|
+
(0, createLink_1.createLink)(editor, {
|
|
159
|
+
autoLink: autoLink,
|
|
160
|
+
autoTel: autoTel,
|
|
161
|
+
autoMailto: autoMailto,
|
|
162
|
+
});
|
|
153
163
|
}
|
|
154
164
|
};
|
|
155
165
|
return AutoFormatPlugin;
|
|
@@ -1 +1 @@
|
|
|
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,cAAc,GAA+B;IAC/C,U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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
|
+
{"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;AAYvC;;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;;;;;;;;;;;OAWG;IACH,0BAAoB,OAA2C;QAA3C,wBAAA,EAAA,wBAA2C;QAA3C,YAAO,GAAP,OAAO,CAAoC;QAbvD,WAAM,GAAmB,IAAI,CAAC;IAa4B,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,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,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;QACnE,IAAA,KAAoC,IAAI,CAAC,OAAO,EAA9C,QAAQ,cAAA,EAAE,OAAO,aAAA,EAAE,UAAU,gBAAiB,CAAC;QACvD,IAAI,KAAK,CAAC,MAAM,IAAI,OAAO,IAAI,CAAC,QAAQ,IAAI,OAAO,IAAI,UAAU,CAAC,EAAE;YAChE,IAAA,uBAAU,EAAC,MAAM,EAAE;gBACf,QAAQ,UAAA;gBACR,OAAO,SAAA;gBACP,UAAU,YAAA;aACb,CAAC,CAAC;SACN;IACL,CAAC;IACL,uBAAC;AAAD,CAAC,AA3LD,IA2LC;AA3LY,4CAAgB;AA6L7B,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,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 { AutoFormatOptions } from './interface/AutoFormatOptions';\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 * @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 * - 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 * - autoLink: A boolean that enables or disables automatic hyperlink url address 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 * - autoTel: A boolean that enables or disables automatic hyperlink telephone numbers transformation. Defaults to false.\n * - autoMailto: A boolean that enables or disables automatic hyperlink email address 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 autoMailto,\n autoTel,\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 || autoTel || autoMailto) {\n shouldLink = createLinkAfterSpace(\n previousSegment,\n paragraph,\n context,\n {\n autoLink,\n autoTel,\n autoMailto,\n }\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, autoTel, autoMailto } = this.options;\n if (event.source == 'Paste' && (autoLink || autoTel || autoMailto)) {\n createLink(editor, {\n autoLink,\n autoTel,\n autoMailto,\n });\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"]}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { AutoLinkOptions } from './AutoLinkOptions';
|
|
2
|
+
/**
|
|
3
|
+
* Options to customize the Content Model Auto Format Plugin
|
|
4
|
+
*/
|
|
5
|
+
export interface AutoFormatOptions extends AutoLinkOptions {
|
|
6
|
+
/**
|
|
7
|
+
* When true, after type *, ->, -, --, => , —, > and space key a type of bullet list will be triggered.
|
|
8
|
+
*/
|
|
9
|
+
autoBullet?: boolean;
|
|
10
|
+
/**
|
|
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.
|
|
12
|
+
*/
|
|
13
|
+
autoNumbering?: boolean;
|
|
14
|
+
/**
|
|
15
|
+
* Transform -- into hyphen, if typed between two words
|
|
16
|
+
*/
|
|
17
|
+
autoHyphen?: boolean;
|
|
18
|
+
/**
|
|
19
|
+
* Transform 1/2, 1/4, 3/4 into fraction character
|
|
20
|
+
*/
|
|
21
|
+
autoFraction?: boolean;
|
|
22
|
+
/**
|
|
23
|
+
* Transform ordinal numbers into superscript
|
|
24
|
+
*/
|
|
25
|
+
autoOrdinals?: boolean;
|
|
26
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AutoFormatOptions.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-plugins/lib/autoFormat/interface/AutoFormatOptions.ts"],"names":[],"mappings":"","sourcesContent":["import type { AutoLinkOptions } from './AutoLinkOptions';\n\n/**\n * Options to customize the Content Model Auto Format Plugin\n */\nexport interface AutoFormatOptions extends AutoLinkOptions {\n /**\n * When true, after type *, ->, -, --, => , —, > and space key a type of bullet list will be triggered.\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.\n */\n autoNumbering?: 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"]}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Options to customize the Auto link options in Auto Format Plugin
|
|
3
|
+
*/
|
|
4
|
+
export interface AutoLinkOptions {
|
|
5
|
+
/**
|
|
6
|
+
* When press backspace before a link, remove the hyperlink
|
|
7
|
+
*/
|
|
8
|
+
autoUnlink?: boolean;
|
|
9
|
+
/**
|
|
10
|
+
* When paste or type content with a link, create hyperlink for the link
|
|
11
|
+
*/
|
|
12
|
+
autoLink?: boolean;
|
|
13
|
+
/**
|
|
14
|
+
* When paste content or type content with telephone, create hyperlink for the telephone number
|
|
15
|
+
*/
|
|
16
|
+
autoTel?: boolean;
|
|
17
|
+
/**
|
|
18
|
+
* When paste or type a content with mailto, create hyperlink for the content
|
|
19
|
+
*/
|
|
20
|
+
autoMailto?: boolean;
|
|
21
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AutoLinkOptions.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-plugins/lib/autoFormat/interface/AutoLinkOptions.ts"],"names":[],"mappings":"","sourcesContent":["/**\n * Options to customize the Auto link options in Auto Format Plugin\n */\nexport interface AutoLinkOptions {\n /**\n * When press backspace before a link, remove the hyperlink\n */\n autoUnlink?: boolean;\n\n /**\n * When paste or type content with a link, create hyperlink for the link\n */\n autoLink?: boolean;\n\n /**\n * When paste content or type content with telephone, create hyperlink for the telephone number\n */\n autoTel?: boolean;\n\n /**\n * When paste or type a content with mailto, create hyperlink for the content\n */\n autoMailto?: boolean;\n}\n"]}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import type { AutoLinkOptions } from '../interface/AutoLinkOptions';
|
|
1
2
|
import type { IEditor } from 'roosterjs-content-model-types';
|
|
2
3
|
/**
|
|
3
4
|
* @internal
|
|
4
5
|
*/
|
|
5
|
-
export declare function createLink(editor: IEditor): void;
|
|
6
|
+
export declare function createLink(editor: IEditor, autoLinkOptions: AutoLinkOptions): void;
|
|
@@ -3,10 +3,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.createLink = void 0;
|
|
4
4
|
var roosterjs_content_model_dom_1 = require("roosterjs-content-model-dom");
|
|
5
5
|
var roosterjs_content_model_api_1 = require("roosterjs-content-model-api");
|
|
6
|
+
var getLinkUrl_1 = require("./getLinkUrl");
|
|
6
7
|
/**
|
|
7
8
|
* @internal
|
|
8
9
|
*/
|
|
9
|
-
function createLink(editor) {
|
|
10
|
+
function createLink(editor, autoLinkOptions) {
|
|
10
11
|
var anchorNode = null;
|
|
11
12
|
var links = [];
|
|
12
13
|
(0, roosterjs_content_model_api_1.formatTextSegmentBeforeSelectionMarker)(editor, function (_model, linkSegment, _paragraph) {
|
|
@@ -14,11 +15,11 @@ function createLink(editor) {
|
|
|
14
15
|
links.push(linkSegment.link);
|
|
15
16
|
return true;
|
|
16
17
|
}
|
|
17
|
-
var
|
|
18
|
-
if (!linkSegment.link && (
|
|
18
|
+
var linkUrl = undefined;
|
|
19
|
+
if (!linkSegment.link && (linkUrl = (0, getLinkUrl_1.getLinkUrl)(linkSegment.text, autoLinkOptions))) {
|
|
19
20
|
(0, roosterjs_content_model_dom_1.addLink)(linkSegment, {
|
|
20
21
|
format: {
|
|
21
|
-
href:
|
|
22
|
+
href: linkUrl,
|
|
22
23
|
underline: true,
|
|
23
24
|
},
|
|
24
25
|
dataset: {},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createLink.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-plugins/lib/autoFormat/link/createLink.ts"],"names":[],"mappings":";;;AAAA,2EAAoE;AACpE,
|
|
1
|
+
{"version":3,"file":"createLink.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-plugins/lib/autoFormat/link/createLink.ts"],"names":[],"mappings":";;;AAAA,2EAAoE;AACpE,2EAAqF;AACrF,2CAA0C;AAI1C;;GAEG;AACH,SAAgB,UAAU,CAAC,MAAe,EAAE,eAAgC;IACxE,IAAI,UAAU,GAAgB,IAAI,CAAC;IACnC,IAAM,KAAK,GAAuB,EAAE,CAAC;IACrC,IAAA,oEAAsC,EAClC,MAAM,EACN,UAAC,MAAM,EAAE,WAAW,EAAE,UAAU;QAC5B,IAAI,WAAW,CAAC,IAAI,EAAE;YAClB,KAAK,CAAC,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;YAC7B,OAAO,IAAI,CAAC;SACf;QACD,IAAI,OAAO,GAAuB,SAAS,CAAC;QAC5C,IAAI,CAAC,WAAW,CAAC,IAAI,IAAI,CAAC,OAAO,GAAG,IAAA,uBAAU,EAAC,WAAW,CAAC,IAAI,EAAE,eAAe,CAAC,CAAC,EAAE;YAChF,IAAA,qCAAO,EAAC,WAAW,EAAE;gBACjB,MAAM,EAAE;oBACJ,IAAI,EAAE,OAAO;oBACb,SAAS,EAAE,IAAI;iBAClB;gBACD,OAAO,EAAE,EAAE;aACd,CAAC,CAAC;YACH,IAAI,WAAW,CAAC,IAAI,EAAE;gBAClB,KAAK,CAAC,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;aAChC;YACD,OAAO,IAAI,CAAC;SACf;QAED,OAAO,KAAK,CAAC;IACjB,CAAC,EACD;QACI,YAAY,EAAE,0CAAY,CAAC,QAAQ;QACnC,aAAa,EAAE,UAAC,YAAY,EAAE,IAAI;YAC9B,IAAI,CAAC,UAAU,IAAI,KAAK,CAAC,OAAO,CAAC,YAAgC,CAAC,IAAI,CAAC,EAAE;gBACrE,UAAU,GAAG,IAAI,CAAC;aACrB;QACL,CAAC;QACD,aAAa,EAAE,cAAM,OAAA,UAAU,EAAV,CAAU;KAClC,CACJ,CAAC;AACN,CAAC;AArCD,gCAqCC","sourcesContent":["import { addLink, ChangeSource } from 'roosterjs-content-model-dom';\nimport { formatTextSegmentBeforeSelectionMarker } from 'roosterjs-content-model-api';\nimport { getLinkUrl } from './getLinkUrl';\nimport type { AutoLinkOptions } from '../interface/AutoLinkOptions';\nimport type { ContentModelLink, IEditor } from 'roosterjs-content-model-types';\n\n/**\n * @internal\n */\nexport function createLink(editor: IEditor, autoLinkOptions: AutoLinkOptions) {\n let anchorNode: Node | null = null;\n const links: ContentModelLink[] = [];\n formatTextSegmentBeforeSelectionMarker(\n editor,\n (_model, linkSegment, _paragraph) => {\n if (linkSegment.link) {\n links.push(linkSegment.link);\n return true;\n }\n let linkUrl: string | undefined = undefined;\n if (!linkSegment.link && (linkUrl = getLinkUrl(linkSegment.text, autoLinkOptions))) {\n addLink(linkSegment, {\n format: {\n href: linkUrl,\n underline: true,\n },\n dataset: {},\n });\n if (linkSegment.link) {\n links.push(linkSegment.link);\n }\n return true;\n }\n\n return false;\n },\n {\n changeSource: ChangeSource.AutoLink,\n onNodeCreated: (modelElement, node) => {\n if (!anchorNode && links.indexOf(modelElement as ContentModelLink) >= 0) {\n anchorNode = node;\n }\n },\n getChangeData: () => anchorNode,\n }\n );\n}\n"]}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import type { AutoLinkOptions } from '../interface/AutoLinkOptions';
|
|
1
2
|
import type { ContentModelText, FormatContentModelContext, ShallowMutableContentModelParagraph } from 'roosterjs-content-model-types';
|
|
2
3
|
/**
|
|
3
4
|
* @internal
|
|
4
5
|
*/
|
|
5
|
-
export declare function createLinkAfterSpace(previousSegment: ContentModelText, paragraph: ShallowMutableContentModelParagraph, context: FormatContentModelContext): boolean;
|
|
6
|
+
export declare function createLinkAfterSpace(previousSegment: ContentModelText, paragraph: ShallowMutableContentModelParagraph, context: FormatContentModelContext, autoLinkOptions: AutoLinkOptions): boolean;
|
|
@@ -1,19 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createLinkAfterSpace = void 0;
|
|
4
|
+
var getLinkUrl_1 = require("./getLinkUrl");
|
|
4
5
|
var roosterjs_content_model_api_1 = require("roosterjs-content-model-api");
|
|
5
6
|
/**
|
|
6
7
|
* @internal
|
|
7
8
|
*/
|
|
8
|
-
function createLinkAfterSpace(previousSegment, paragraph, context) {
|
|
9
|
+
function createLinkAfterSpace(previousSegment, paragraph, context, autoLinkOptions) {
|
|
9
10
|
var link = previousSegment.text.split(' ').pop();
|
|
10
11
|
var url = link === null || link === void 0 ? void 0 : link.trim();
|
|
11
|
-
var
|
|
12
|
-
if (url && link && (
|
|
12
|
+
var linkUrl = undefined;
|
|
13
|
+
if (url && link && (linkUrl = (0, getLinkUrl_1.getLinkUrl)(url, autoLinkOptions))) {
|
|
13
14
|
var linkSegment = (0, roosterjs_content_model_api_1.splitTextSegment)(previousSegment, paragraph, previousSegment.text.length - link.trimLeft().length, previousSegment.text.trimRight().length);
|
|
14
15
|
linkSegment.link = {
|
|
15
16
|
format: {
|
|
16
|
-
href:
|
|
17
|
+
href: linkUrl,
|
|
17
18
|
underline: true,
|
|
18
19
|
},
|
|
19
20
|
dataset: {},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createLinkAfterSpace.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-plugins/lib/autoFormat/link/createLinkAfterSpace.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"createLinkAfterSpace.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-plugins/lib/autoFormat/link/createLinkAfterSpace.ts"],"names":[],"mappings":";;;AAAA,2CAA0C;AAC1C,2EAA+D;AAQ/D;;GAEG;AACH,SAAgB,oBAAoB,CAChC,eAAiC,EACjC,SAA8C,EAC9C,OAAkC,EAClC,eAAgC;IAEhC,IAAM,IAAI,GAAG,eAAe,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,CAAC;IACnD,IAAM,GAAG,GAAG,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,IAAI,EAAE,CAAC;IACzB,IAAI,OAAO,GAAuB,SAAS,CAAC;IAC5C,IAAI,GAAG,IAAI,IAAI,IAAI,CAAC,OAAO,GAAG,IAAA,uBAAU,EAAC,GAAG,EAAE,eAAe,CAAC,CAAC,EAAE;QAC7D,IAAM,WAAW,GAAG,IAAA,8CAAgB,EAChC,eAAe,EACf,SAAS,EACT,eAAe,CAAC,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,QAAQ,EAAE,CAAC,MAAM,EACpD,eAAe,CAAC,IAAI,CAAC,SAAS,EAAE,CAAC,MAAM,CAC1C,CAAC;QACF,WAAW,CAAC,IAAI,GAAG;YACf,MAAM,EAAE;gBACJ,IAAI,EAAE,OAAO;gBACb,SAAS,EAAE,IAAI;aAClB;YACD,OAAO,EAAE,EAAE;SACd,CAAC;QAEF,OAAO,CAAC,kBAAkB,GAAG,IAAI,CAAC;QAElC,OAAO,IAAI,CAAC;KACf;IACD,OAAO,KAAK,CAAC;AACjB,CAAC;AA7BD,oDA6BC","sourcesContent":["import { getLinkUrl } from './getLinkUrl';\nimport { splitTextSegment } from 'roosterjs-content-model-api';\nimport type { AutoLinkOptions } from '../interface/AutoLinkOptions';\nimport type {\n ContentModelText,\n FormatContentModelContext,\n ShallowMutableContentModelParagraph,\n} from 'roosterjs-content-model-types';\n\n/**\n * @internal\n */\nexport function createLinkAfterSpace(\n previousSegment: ContentModelText,\n paragraph: ShallowMutableContentModelParagraph,\n context: FormatContentModelContext,\n autoLinkOptions: AutoLinkOptions\n) {\n const link = previousSegment.text.split(' ').pop();\n const url = link?.trim();\n let linkUrl: string | undefined = undefined;\n if (url && link && (linkUrl = getLinkUrl(url, autoLinkOptions))) {\n const linkSegment = splitTextSegment(\n previousSegment,\n paragraph,\n previousSegment.text.length - link.trimLeft().length,\n previousSegment.text.trimRight().length\n );\n linkSegment.link = {\n format: {\n href: linkUrl,\n underline: true,\n },\n dataset: {},\n };\n\n context.canUndoByBackspace = true;\n\n return true;\n }\n return false;\n}\n"]}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getLinkUrl = void 0;
|
|
4
|
+
var roosterjs_content_model_api_1 = require("roosterjs-content-model-api");
|
|
5
|
+
var COMMON_REGEX = "[s]*[a-zA-Z0-9+][s]*";
|
|
6
|
+
var TELEPHONE_REGEX = "(T|t)el:" + COMMON_REGEX;
|
|
7
|
+
var MAILTO_REGEX = "(M|m)ailto:" + COMMON_REGEX;
|
|
8
|
+
/**
|
|
9
|
+
* @internal
|
|
10
|
+
*/
|
|
11
|
+
function getLinkUrl(text, autoLinkOptions) {
|
|
12
|
+
var _a;
|
|
13
|
+
var autoLink = autoLinkOptions.autoLink, autoMailto = autoLinkOptions.autoMailto, autoTel = autoLinkOptions.autoTel;
|
|
14
|
+
var linkMatch = autoLink ? (_a = (0, roosterjs_content_model_api_1.matchLink)(text)) === null || _a === void 0 ? void 0 : _a.normalizedUrl : undefined;
|
|
15
|
+
var telMatch = autoTel ? matchTel(text) : undefined;
|
|
16
|
+
var mailtoMatch = autoMailto ? matchMailTo(text) : undefined;
|
|
17
|
+
return linkMatch || telMatch || mailtoMatch;
|
|
18
|
+
}
|
|
19
|
+
exports.getLinkUrl = getLinkUrl;
|
|
20
|
+
function matchTel(text) {
|
|
21
|
+
return text.match(TELEPHONE_REGEX) ? text.toLocaleLowerCase() : undefined;
|
|
22
|
+
}
|
|
23
|
+
function matchMailTo(text) {
|
|
24
|
+
return text.match(MAILTO_REGEX) ? text.toLocaleLowerCase() : undefined;
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=getLinkUrl.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getLinkUrl.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-plugins/lib/autoFormat/link/getLinkUrl.ts"],"names":[],"mappings":";;;AAAA,2EAAwD;AAGxD,IAAM,YAAY,GAAG,sBAAwB,CAAC;AAC9C,IAAM,eAAe,GAAG,aAAW,YAAc,CAAC;AAClD,IAAM,YAAY,GAAG,gBAAc,YAAc,CAAC;AAElD;;GAEG;AACH,SAAgB,UAAU,CAAC,IAAY,EAAE,eAAgC;;IAC7D,IAAA,QAAQ,GAA0B,eAAe,SAAzC,EAAE,UAAU,GAAc,eAAe,WAA7B,EAAE,OAAO,GAAK,eAAe,QAApB,CAAqB;IAC1D,IAAM,SAAS,GAAG,QAAQ,CAAC,CAAC,CAAC,MAAA,IAAA,uCAAS,EAAC,IAAI,CAAC,0CAAE,aAAa,CAAC,CAAC,CAAC,SAAS,CAAC;IACxE,IAAM,QAAQ,GAAG,OAAO,CAAC,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;IACtD,IAAM,WAAW,GAAG,UAAU,CAAC,CAAC,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;IAE/D,OAAO,SAAS,IAAI,QAAQ,IAAI,WAAW,CAAC;AAChD,CAAC;AAPD,gCAOC;AAED,SAAS,QAAQ,CAAC,IAAY;IAC1B,OAAO,IAAI,CAAC,KAAK,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,iBAAiB,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC;AAC9E,CAAC;AAED,SAAS,WAAW,CAAC,IAAY;IAC7B,OAAO,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,iBAAiB,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC;AAC3E,CAAC","sourcesContent":["import { matchLink } from 'roosterjs-content-model-api';\nimport type { AutoLinkOptions } from '../interface/AutoLinkOptions';\n\nconst COMMON_REGEX = `[\\s]*[a-zA-Z0-9+][\\s]*`;\nconst TELEPHONE_REGEX = `(T|t)el:${COMMON_REGEX}`;\nconst MAILTO_REGEX = `(M|m)ailto:${COMMON_REGEX}`;\n\n/**\n * @internal\n */\nexport function getLinkUrl(text: string, autoLinkOptions: AutoLinkOptions): string | undefined {\n const { autoLink, autoMailto, autoTel } = autoLinkOptions;\n const linkMatch = autoLink ? matchLink(text)?.normalizedUrl : undefined;\n const telMatch = autoTel ? matchTel(text) : undefined;\n const mailtoMatch = autoMailto ? matchMailTo(text) : undefined;\n\n return linkMatch || telMatch || mailtoMatch;\n}\n\nfunction matchTel(text: string) {\n return text.match(TELEPHONE_REGEX) ? text.toLocaleLowerCase() : undefined;\n}\n\nfunction matchMailTo(text: string) {\n return text.match(MAILTO_REGEX) ? text.toLocaleLowerCase() : undefined;\n}\n"]}
|
package/lib/edit/EditPlugin.js
CHANGED
|
@@ -47,7 +47,7 @@ var EditPlugin = /** @class */ (function () {
|
|
|
47
47
|
EditPlugin.prototype.initialize = function (editor) {
|
|
48
48
|
var _this = this;
|
|
49
49
|
this.editor = editor;
|
|
50
|
-
this.handleNormalEnter = this.editor.isExperimentalFeatureEnabled('
|
|
50
|
+
this.handleNormalEnter = this.editor.isExperimentalFeatureEnabled('HandleEnterKey');
|
|
51
51
|
if (editor.getEnvironment().isAndroid) {
|
|
52
52
|
this.disposer = this.editor.attachDomEvent({
|
|
53
53
|
beforeinput: {
|
|
@@ -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,iDAAgD;AAChD,6CAA4C;AAC5C,2EAA8D;AAmB9D,IAAM,aAAa,GAAG,CAAC,CAAC;AACxB,IAAM,UAAU,GAAG,EAAE,CAAC;AAEtB,IAAM,cAAc,GAAyB;IACzC,YAAY,EAAE,IAAI;CACrB,CAAC;AAEF;;;;;;GAMG;AACH;IAOI;;;OAGG;IACH,oBAAoB,OAAqC;QAArC,wBAAA,EAAA,wBAAqC;QAArC,YAAO,GAAP,OAAO,CAA8B;QAVjD,WAAM,GAAmB,IAAI,CAAC;QAC9B,aAAQ,GAAwB,IAAI,CAAC;QACrC,+BAA0B,GAAG,KAAK,CAAC;QACnC,yBAAoB,GAAwB,IAAI,CAAC;QACjD,sBAAiB,GAAG,KAAK,CAAC;IAM0B,CAAC;IAE7D;;OAEG;IACH,4BAAO,GAAP;QACI,OAAO,MAAM,CAAC;IAClB,CAAC;IAED;;;;;OAKG;IACH,+BAAU,GAAV,UAAW,MAAe;QAA1B,iBAWC;QAVG,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAA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;iBACvB,CAAC,CACL,CAAC;gBACF,MAAM;YACV,KAAK,sBAAsB;gBACvB,OAAO,GAAG,IAAA,+BAAc,EACpB,MAAM,EACN,IAAI,aAAa,CAAC,SAAS,EAAE;oBACzB,GAAG,EAAE,QAAQ;oBACb,OAAO,EAAE,UAAU;oBACnB,KAAK,EAAE,UAAU;iBACpB,CAAC,CACL,CAAC;gBACF,MAAM;SACb;QAED,IAAI,OAAO,EAAE;YACT,QAAQ,CAAC,cAAc,EAAE,CAAC;YAE1B,sEAAsE;YACtE,oDAAoD;YACpD,IAAI,CAAC,oBAAoB,GAAG,MAAM,CAAC,eAAe,EAAE,CAAC;SACxD;IACL,CAAC;IACL,iBAAC;AAAD,CAAC,AAvMD,IAuMC;AAvMY,gCAAU","sourcesContent":["import { keyboardDelete } from './keyboardDelete';\nimport { keyboardEnter } from './keyboardEnter';\nimport { keyboardInput } from './keyboardInput';\nimport { keyboardTab } from './keyboardTab';\nimport { parseTableCells } from 'roosterjs-content-model-dom';\nimport type {\n DOMSelection,\n EditorPlugin,\n IEditor,\n KeyDownEvent,\n PluginEvent,\n} from 'roosterjs-content-model-types';\n\n/**\n * Options to customize the keyboard handling behavior of Edit plugin\n */\nexport type EditOptions = {\n /**\n * Whether to handle Tab key in keyboard. @default true\n */\n handleTabKey?: boolean;\n};\n\nconst BACKSPACE_KEY = 8;\nconst DELETE_KEY = 46;\n\nconst DefaultOptions: Partial<EditOptions> = {\n handleTabKey: true,\n};\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 private selectionAfterDelete: DOMSelection | null = null;\n private handleNormalEnter = false;\n\n /**\n * @param options An optional parameter that takes in an object of type EditOptions, which includes the following properties:\n * handleTabKey: A boolean that enables or disables Tab key handling. Defaults to true.\n */\n constructor(private options: EditOptions = DefaultOptions) {}\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 this.handleNormalEnter = this.editor.isExperimentalFeatureEnabled('PersistCache');\n\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 case 'keyUp':\n if (this.selectionAfterDelete) {\n this.editor.setDOMSelection(this.selectionAfterDelete);\n this.selectionAfterDelete = null;\n }\n break;\n }\n }\n }\n\n /**\n * Check if the plugin should handle the given event exclusively.\n * Handle an event exclusively means other plugin will not receive this event in\n * onPluginEvent method.\n * If two plugins will return true in willHandleEventExclusively() for the same event,\n * the final result depends on the order of the plugins are added into editor\n * @param event The event to check:\n */\n willHandleEventExclusively(event: PluginEvent) {\n if (\n this.editor &&\n this.options.handleTabKey &&\n event.eventType == 'keyDown' &&\n event.rawEvent.key == 'Tab' &&\n !event.rawEvent.shiftKey\n ) {\n const selection = this.editor.getDOMSelection();\n const startContainer =\n selection?.type == 'range' && selection.range.collapsed\n ? selection.range.startContainer\n : null;\n const table = startContainer\n ? this.editor.getDOMHelper().findClosestElementAncestor(startContainer, 'table')\n : null;\n const parsedTable = table && parseTableCells(table);\n\n if (parsedTable) {\n const lastRow = parsedTable[parsedTable.length - 1];\n const lastCell = lastRow && lastRow[lastRow.length - 1];\n\n if (typeof lastCell == 'object' && lastCell.contains(startContainer)) {\n // When TAB in the last cell of a table, we will generate new table row, so prevent other plugins handling this event\n // e.g. SelectionPlugin will move the focus out of table, which is conflict with this behavior\n return true;\n }\n }\n }\n\n return false;\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 if (this.options.handleTabKey) {\n keyboardTab(editor, rawEvent);\n }\n break;\n case 'Unidentified':\n if (editor.getEnvironment().isAndroid) {\n this.shouldHandleNextInputEvent = true;\n }\n break;\n\n case 'Enter':\n keyboardEnter(editor, rawEvent, this.handleNormalEnter);\n break;\n\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 on keyup event to avoid the cursor jump issue\n // See: https://issues.chromium.org/issues/330596261\n this.selectionAfterDelete = editor.getDOMSelection();\n }\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"EditPlugin.js","sourceRoot":"","sources":["../../../../packages/roosterjs-content-model-plugins/lib/edit/EditPlugin.ts"],"names":[],"mappings":";;;AAAA,mDAAkD;AAClD,iDAAgD;AAChD,iDAAgD;AAChD,6CAA4C;AAC5C,2EAA8D;AAmB9D,IAAM,aAAa,GAAG,CAAC,CAAC;AACxB,IAAM,UAAU,GAAG,EAAE,CAAC;AAEtB,IAAM,cAAc,GAAyB;IACzC,YAAY,EAAE,IAAI;CACrB,CAAC;AAEF;;;;;;GAMG;AACH;IAOI;;;OAGG;IACH,oBAAoB,OAAqC;QAArC,wBAAA,EAAA,wBAAqC;QAArC,YAAO,GAAP,OAAO,CAA8B;QAVjD,WAAM,GAAmB,IAAI,CAAC;QAC9B,aAAQ,GAAwB,IAAI,CAAC;QACrC,+BAA0B,GAAG,KAAK,CAAC;QACnC,yBAAoB,GAAwB,IAAI,CAAC;QACjD,sBAAiB,GAAG,KAAK,CAAC;IAM0B,CAAC;IAE7D;;OAEG;IACH,4BAAO,GAAP;QACI,OAAO,MAAM,CAAC;IAClB,CAAC;IAED;;;;;OAKG;IACH,+BAAU,GAAV,UAAW,MAAe;QAA1B,iBAWC;QAVG,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,iBAAiB,GAAG,IAAI,CAAC,MAAM,CAAC,4BAA4B,CAAC,gBAAgB,CAAC,CAAC;QAEpF,IAAI,MAA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EACpB,MAAM,EACN,IAAI,aAAa,CAAC,SAAS,EAAE;oBACzB,GAAG,EAAE,QAAQ;oBACb,OAAO,EAAE,UAAU;oBACnB,KAAK,EAAE,UAAU;iBACpB,CAAC,CACL,CAAC;gBACF,MAAM;SACb;QAED,IAAI,OAAO,EAAE;YACT,QAAQ,CAAC,cAAc,EAAE,CAAC;YAE1B,sEAAsE;YACtE,oDAAoD;YACpD,IAAI,CAAC,oBAAoB,GAAG,MAAM,CAAC,eAAe,EAAE,CAAC;SACxD;IACL,CAAC;IACL,iBAAC;AAAD,CAAC,AAvMD,IAuMC;AAvMY,gCAAU","sourcesContent":["import { keyboardDelete } from './keyboardDelete';\nimport { keyboardEnter } from './keyboardEnter';\nimport { keyboardInput } from './keyboardInput';\nimport { keyboardTab } from './keyboardTab';\nimport { parseTableCells } from 'roosterjs-content-model-dom';\nimport type {\n DOMSelection,\n EditorPlugin,\n IEditor,\n KeyDownEvent,\n PluginEvent,\n} from 'roosterjs-content-model-types';\n\n/**\n * Options to customize the keyboard handling behavior of Edit plugin\n */\nexport type EditOptions = {\n /**\n * Whether to handle Tab key in keyboard. @default true\n */\n handleTabKey?: boolean;\n};\n\nconst BACKSPACE_KEY = 8;\nconst DELETE_KEY = 46;\n\nconst DefaultOptions: Partial<EditOptions> = {\n handleTabKey: true,\n};\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 private selectionAfterDelete: DOMSelection | null = null;\n private handleNormalEnter = false;\n\n /**\n * @param options An optional parameter that takes in an object of type EditOptions, which includes the following properties:\n * handleTabKey: A boolean that enables or disables Tab key handling. Defaults to true.\n */\n constructor(private options: EditOptions = DefaultOptions) {}\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 this.handleNormalEnter = this.editor.isExperimentalFeatureEnabled('HandleEnterKey');\n\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 case 'keyUp':\n if (this.selectionAfterDelete) {\n this.editor.setDOMSelection(this.selectionAfterDelete);\n this.selectionAfterDelete = null;\n }\n break;\n }\n }\n }\n\n /**\n * Check if the plugin should handle the given event exclusively.\n * Handle an event exclusively means other plugin will not receive this event in\n * onPluginEvent method.\n * If two plugins will return true in willHandleEventExclusively() for the same event,\n * the final result depends on the order of the plugins are added into editor\n * @param event The event to check:\n */\n willHandleEventExclusively(event: PluginEvent) {\n if (\n this.editor &&\n this.options.handleTabKey &&\n event.eventType == 'keyDown' &&\n event.rawEvent.key == 'Tab' &&\n !event.rawEvent.shiftKey\n ) {\n const selection = this.editor.getDOMSelection();\n const startContainer =\n selection?.type == 'range' && selection.range.collapsed\n ? selection.range.startContainer\n : null;\n const table = startContainer\n ? this.editor.getDOMHelper().findClosestElementAncestor(startContainer, 'table')\n : null;\n const parsedTable = table && parseTableCells(table);\n\n if (parsedTable) {\n const lastRow = parsedTable[parsedTable.length - 1];\n const lastCell = lastRow && lastRow[lastRow.length - 1];\n\n if (typeof lastCell == 'object' && lastCell.contains(startContainer)) {\n // When TAB in the last cell of a table, we will generate new table row, so prevent other plugins handling this event\n // e.g. SelectionPlugin will move the focus out of table, which is conflict with this behavior\n return true;\n }\n }\n }\n\n return false;\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 if (this.options.handleTabKey) {\n keyboardTab(editor, rawEvent);\n }\n break;\n case 'Unidentified':\n if (editor.getEnvironment().isAndroid) {\n this.shouldHandleNextInputEvent = true;\n }\n break;\n\n case 'Enter':\n keyboardEnter(editor, rawEvent, this.handleNormalEnter);\n break;\n\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 on keyup event to avoid the cursor jump issue\n // See: https://issues.chromium.org/issues/330596261\n this.selectionAfterDelete = editor.getDOMSelection();\n }\n }\n}\n"]}
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.keyboardEnter = void 0;
|
|
4
4
|
var deleteEmptyQuote_1 = require("./deleteSteps/deleteEmptyQuote");
|
|
5
|
-
var roosterjs_content_model_dom_1 = require("roosterjs-content-model-dom");
|
|
6
5
|
var handleEnterOnList_1 = require("./inputSteps/handleEnterOnList");
|
|
7
6
|
var handleEnterOnParagraph_1 = require("./inputSteps/handleEnterOnParagraph");
|
|
7
|
+
var roosterjs_content_model_dom_1 = require("roosterjs-content-model-dom");
|
|
8
8
|
/**
|
|
9
9
|
* @internal
|
|
10
10
|
*/
|
|
@@ -38,6 +38,7 @@ function keyboardEnter(editor, rawEvent, handleNormalEnter) {
|
|
|
38
38
|
}, {
|
|
39
39
|
rawEvent: rawEvent,
|
|
40
40
|
scrollCaretIntoView: true,
|
|
41
|
+
changeSource: roosterjs_content_model_dom_1.ChangeSource.Keyboard,
|
|
41
42
|
});
|
|
42
43
|
}
|
|
43
44
|
exports.keyboardEnter = keyboardEnter;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"keyboardEnter.js","sourceRoot":"","sources":["../../../../packages/roosterjs-content-model-plugins/lib/edit/keyboardEnter.ts"],"names":[],"mappings":";;;AAAA,mEAAkE;AAClE,
|
|
1
|
+
{"version":3,"file":"keyboardEnter.js","sourceRoot":"","sources":["../../../../packages/roosterjs-content-model-plugins/lib/edit/keyboardEnter.ts"],"names":[],"mappings":";;;AAAA,mEAAkE;AAClE,oEAAmE;AACnE,8EAA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List } from './inputSteps/handleEnterOnList';\nimport { handleEnterOnParagraph } from './inputSteps/handleEnterOnParagraph';\nimport {\n ChangeSource,\n deleteSelection,\n normalizeContentModel,\n runEditSteps,\n} from 'roosterjs-content-model-dom';\nimport type { IEditor } from 'roosterjs-content-model-types';\n\n/**\n * @internal\n */\nexport function keyboardEnter(\n editor: IEditor,\n rawEvent: KeyboardEvent,\n handleNormalEnter: boolean\n) {\n const selection = editor.getDOMSelection();\n\n editor.formatContentModel(\n (model, context) => {\n // 1. delete the expanded selection if any, then merge paragraph\n const result = deleteSelection(model, [], context);\n\n // 2. Add line break\n if (selection && selection.type != 'table') {\n // For ENTER key, although we may have deleted something, since we still need to split the line, we always treat it as not delete\n // so further delete steps can keep working\n result.deleteResult = 'notDeleted';\n\n const steps = rawEvent.shiftKey ? [] : [handleEnterOnList, deleteEmptyQuote];\n\n if (handleNormalEnter) {\n steps.push(handleEnterOnParagraph);\n }\n\n runEditSteps(steps, result);\n }\n\n if (result.deleteResult == 'range') {\n // We have deleted something, next input should inherit the segment format from deleted content, so set pending format here\n context.newPendingFormat = result.insertPoint?.marker.format;\n\n normalizeContentModel(model);\n\n rawEvent.preventDefault();\n return true;\n } else {\n return false;\n }\n },\n {\n rawEvent,\n scrollCaretIntoView: true,\n changeSource: ChangeSource.Keyboard,\n }\n );\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"keyboardInput.js","sourceRoot":"","sources":["../../../../packages/roosterjs-content-model-plugins/lib/edit/keyboardInput.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"keyboardInput.js","sourceRoot":"","sources":["../../../../packages/roosterjs-content-model-plugins/lib/edit/keyboardInput.ts"],"names":[],"mappings":";;;AAAA,2EAKqC;AAGrC;;GAEG;AACH,SAAgB,aAAa,CAAC,MAAe,EAAE,QAAuB;IAClE,IAAM,SAAS,GAAG,MAAM,CAAC,eAAe,EAAE,CAAC;IAE3C,IAAI,2BAA2B,CAA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\nimport type { DOMSelection, IEditor } from 'roosterjs-content-model-types';\n\n/**\n * @internal\n */\nexport function keyboardInput(editor: IEditor, rawEvent: KeyboardEvent) {\n const selection = editor.getDOMSelection();\n\n if (shouldInputWithContentModel(selection, rawEvent)) {\n editor.takeSnapshot();\n\n editor.formatContentModel(\n (model, context) => {\n const result = deleteSelection(model, [], context);\n\n // Skip undo snapshot here and add undo snapshot before the operation so that we don't add another undo snapshot in middle of this replace operation\n context.skipUndoSnapshot = true;\n\n if (result.deleteResult == 'range') {\n // We have deleted something, next input should inherit the segment format from deleted content, so set pending format here\n context.newPendingFormat = result.insertPoint?.marker.format;\n\n normalizeContentModel(model);\n\n // Do not preventDefault since we still want browser to handle the final input for now\n return true;\n } else {\n return false;\n }\n },\n {\n scrollCaretIntoView: true,\n rawEvent,\n changeSource: ChangeSource.Keyboard,\n }\n );\n\n return true;\n }\n}\n\nfunction shouldInputWithContentModel(selection: DOMSelection | null, rawEvent: KeyboardEvent) {\n if (!selection) {\n return false; // Nothing to delete\n } else if (!isModifierKey(rawEvent) && (rawEvent.key == 'Space' || rawEvent.key.length == 1)) {\n return selection.type != 'range' || !selection.range.collapsed;\n } else {\n return false;\n }\n}\n"]}
|
package/lib/edit/keyboardTab.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.keyboardTab = void 0;
|
|
4
|
-
var roosterjs_content_model_dom_1 = require("roosterjs-content-model-dom");
|
|
5
4
|
var handleTabOnList_1 = require("./tabUtils/handleTabOnList");
|
|
6
5
|
var handleTabOnParagraph_1 = require("./tabUtils/handleTabOnParagraph");
|
|
7
6
|
var handleTabOnTable_1 = require("./tabUtils/handleTabOnTable");
|
|
8
7
|
var handleTabOnTableCell_1 = require("./tabUtils/handleTabOnTableCell");
|
|
9
8
|
var roosterjs_content_model_api_1 = require("roosterjs-content-model-api");
|
|
9
|
+
var roosterjs_content_model_dom_1 = require("roosterjs-content-model-dom");
|
|
10
10
|
/**
|
|
11
11
|
* @internal
|
|
12
12
|
*/
|
|
@@ -25,6 +25,7 @@ function keyboardTab(editor, rawEvent) {
|
|
|
25
25
|
return (0, handleTabOnTable_1.handleTabOnTable)(model, rawEvent);
|
|
26
26
|
}, {
|
|
27
27
|
apiName: 'handleTabKey',
|
|
28
|
+
changeSource: roosterjs_content_model_dom_1.ChangeSource.Keyboard,
|
|
28
29
|
});
|
|
29
30
|
return true;
|
|
30
31
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"keyboardTab.js","sourceRoot":"","sources":["../../../../packages/roosterjs-content-model-plugins/lib/edit/keyboardTab.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"keyboardTab.js","sourceRoot":"","sources":["../../../../packages/roosterjs-content-model-plugins/lib/edit/keyboardTab.ts"],"names":[],"mappings":";;;AAAA,8DAA6D;AAC7D,wEAAuE;AACvE,gEAA+D;AAC/D,wEAAuE;AACvE,2EAAkE;AAClE,2EAIqC;AASrC;;GAEG;AACH,SAAgB,WAAW,CAAC,MAAe,EAAE,QAAuB;IAChE,IAAM,SAAS,GAAG,MAAM,CAAC,eAAe,EAAE,CAAC;IAE3C,QAAQ,SAAS,aAAT,SAAS,uBAAT,SAAS,CAAE,IAAI,EAAE;QACrB,KAAK,OAAO;YACR,MAAM,CAAC,kBAAkB,CACrB,UAAC,KAAK,EAAE,OAAO;gBACX,OAAO,SAAS,CAAC,KAAK,EAAE,QAAQ,EAAE,OAAO,CAAC,CAAC;YAC/C,CAAC,EACD;gBACI,OAAO,EAAE,cAAc;aAC1B,CACJ,CAAC;YAEF,OAAO,IAAI,CAAC;QAChB,KAAK,OAAO;YACR,MAAM,CAAC,kBAAkB,CACrB,UAAA,KAAK;gBACD,OAAO,IAAA,mCAAgB,EAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;YAC7C,CAAC,EACD;gBACI,OAAO,EAAE,cAAc;gBACv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raph } from './tabUtils/handleTabOnParagraph';\nimport { handleTabOnTable } from './tabUtils/handleTabOnTable';\nimport { handleTabOnTableCell } from './tabUtils/handleTabOnTableCell';\nimport { setModelIndentation } from 'roosterjs-content-model-api';\nimport {\n ChangeSource,\n getOperationalBlocks,\n isBlockGroupOfType,\n} from 'roosterjs-content-model-dom';\nimport type {\n ContentModelListItem,\n ContentModelTableCell,\n FormatContentModelContext,\n IEditor,\n ReadonlyContentModelDocument,\n} from 'roosterjs-content-model-types';\n\n/**\n * @internal\n */\nexport function keyboardTab(editor: IEditor, rawEvent: KeyboardEvent) {\n const selection = editor.getDOMSelection();\n\n switch (selection?.type) {\n case 'range':\n editor.formatContentModel(\n (model, context) => {\n return handleTab(model, rawEvent, context);\n },\n {\n apiName: 'handleTabKey',\n }\n );\n\n return true;\n case 'table':\n editor.formatContentModel(\n model => {\n return handleTabOnTable(model, rawEvent);\n },\n {\n apiName: 'handleTabKey',\n changeSource: ChangeSource.Keyboard,\n }\n );\n return true;\n }\n}\n\n/**\n * If multiple blocks are selected, indent or outdent the selected blocks with setModelIndentation.\n * If only one block is selected:\n * - If it is a table cell, call handleTabOnTableCell to handle the tab key.\n * - If it is a paragraph, call handleTabOnParagraph to handle the tab key.\n * - If it is a list item, call handleTabOnList to handle the tab key.\n */\nfunction handleTab(\n model: ReadonlyContentModelDocument,\n rawEvent: KeyboardEvent,\n context: FormatContentModelContext\n) {\n const blocks = getOperationalBlocks<ContentModelListItem | ContentModelTableCell>(\n model,\n ['ListItem', 'TableCell'],\n []\n );\n const block = blocks.length > 0 ? blocks[0].block : undefined;\n\n if (blocks.length > 1) {\n setModelIndentation(model, rawEvent.shiftKey ? 'outdent' : 'indent');\n rawEvent.preventDefault();\n return true;\n } else if (isBlockGroupOfType<ContentModelTableCell>(block, 'TableCell')) {\n return handleTabOnTableCell(model, block, rawEvent);\n } else if (block?.blockType === 'Paragraph') {\n return handleTabOnParagraph(model, block, rawEvent, context);\n } else if (isBlockGroupOfType<ContentModelListItem>(block, 'ListItem')) {\n return handleTabOnList(model, block, rawEvent, context);\n }\n return false;\n}\n"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ImageEditOptions } from './types/ImageEditOptions';
|
|
2
|
-
import type { EditorPlugin, IEditor, ImageEditOperation, ImageEditor, PluginEvent } from 'roosterjs-content-model-types';
|
|
2
|
+
import type { EditorPlugin, IEditor, ImageEditOperation, ImageEditor, ImageMetadataFormat, PluginEvent } from 'roosterjs-content-model-types';
|
|
3
3
|
/**
|
|
4
4
|
* ImageEdit plugin handles the following image editing features:
|
|
5
5
|
* - Resize image
|
|
@@ -13,7 +13,7 @@ export declare class ImageEditPlugin implements ImageEditor, EditorPlugin {
|
|
|
13
13
|
private shadowSpan;
|
|
14
14
|
private selectedImage;
|
|
15
15
|
protected wrapper: HTMLSpanElement | null;
|
|
16
|
-
|
|
16
|
+
protected imageEditInfo: ImageMetadataFormat | null;
|
|
17
17
|
private imageHTMLOptions;
|
|
18
18
|
private dndHelpers;
|
|
19
19
|
private clonedImage;
|