roosterjs-content-model-plugins 9.6.0 → 9.7.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/hyphen/transformHyphen.js +3 -3
- package/lib/autoFormat/hyphen/transformHyphen.js.map +1 -1
- package/lib/autoFormat/link/createLink.js +7 -2
- package/lib/autoFormat/link/createLink.js.map +1 -1
- package/lib/autoFormat/link/createLinkAfterSpace.js +1 -2
- package/lib/autoFormat/link/createLinkAfterSpace.js.map +1 -1
- package/lib/autoFormat/numbers/transformFraction.js +2 -2
- package/lib/autoFormat/numbers/transformFraction.js.map +1 -1
- package/lib/autoFormat/numbers/transformOrdinals.js +2 -2
- package/lib/autoFormat/numbers/transformOrdinals.js.map +1 -1
- package/lib/edit/EditPlugin.d.ts +15 -0
- package/lib/edit/EditPlugin.js +14 -2
- package/lib/edit/EditPlugin.js.map +1 -1
- package/lib/imageEdit/ImageEditPlugin.d.ts +11 -5
- package/lib/imageEdit/ImageEditPlugin.js +209 -103
- package/lib/imageEdit/ImageEditPlugin.js.map +1 -1
- package/lib/imageEdit/types/ImageAndParagraph.d.ts +8 -0
- package/lib/imageEdit/types/ImageAndParagraph.js +3 -0
- package/lib/imageEdit/types/ImageAndParagraph.js.map +1 -0
- package/lib/imageEdit/types/ImageEditOptions.d.ts +1 -1
- package/lib/imageEdit/types/ImageEditOptions.js.map +1 -1
- package/lib/imageEdit/utils/applyChange.js +4 -8
- package/lib/imageEdit/utils/applyChange.js.map +1 -1
- package/lib/imageEdit/utils/createImageWrapper.d.ts +1 -1
- package/lib/imageEdit/utils/createImageWrapper.js +10 -6
- package/lib/imageEdit/utils/createImageWrapper.js.map +1 -1
- package/lib/imageEdit/utils/findEditingImage.d.ts +6 -0
- package/lib/imageEdit/utils/findEditingImage.js +43 -0
- package/lib/imageEdit/utils/findEditingImage.js.map +1 -0
- package/lib/imageEdit/utils/getSelectedImage.d.ts +6 -0
- package/lib/imageEdit/utils/getSelectedImage.js +21 -0
- package/lib/imageEdit/utils/getSelectedImage.js.map +1 -0
- package/lib/imageEdit/utils/updateImageEditInfo.d.ts +1 -1
- package/lib/imageEdit/utils/updateImageEditInfo.js +10 -6
- package/lib/imageEdit/utils/updateImageEditInfo.js.map +1 -1
- package/lib/imageEdit/utils/updateWrapper.js +2 -2
- package/lib/imageEdit/utils/updateWrapper.js.map +1 -1
- package/lib/index.d.ts +1 -1
- package/lib/index.js.map +1 -1
- package/lib/markdown/utils/setFormat.js +1 -2
- package/lib/markdown/utils/setFormat.js.map +1 -1
- package/lib/picker/getQueryString.js +2 -2
- package/lib/picker/getQueryString.js.map +1 -1
- package/lib/tableEdit/editors/TableEditor.js +4 -2
- package/lib/tableEdit/editors/TableEditor.js.map +1 -1
- package/lib/tableEdit/editors/features/TableMover.d.ts +2 -2
- package/lib/tableEdit/editors/features/TableMover.js +4 -4
- package/lib/tableEdit/editors/features/TableMover.js.map +1 -1
- package/lib/watermark/WatermarkPlugin.d.ts +2 -0
- package/lib/watermark/WatermarkPlugin.js +24 -4
- package/lib/watermark/WatermarkPlugin.js.map +1 -1
- package/lib-amd/autoFormat/hyphen/transformHyphen.js +3 -3
- package/lib-amd/autoFormat/hyphen/transformHyphen.js.map +1 -1
- package/lib-amd/autoFormat/link/createLink.js +7 -2
- package/lib-amd/autoFormat/link/createLink.js.map +1 -1
- package/lib-amd/autoFormat/link/createLinkAfterSpace.js +2 -2
- package/lib-amd/autoFormat/link/createLinkAfterSpace.js.map +1 -1
- package/lib-amd/autoFormat/numbers/transformFraction.js +2 -2
- package/lib-amd/autoFormat/numbers/transformFraction.js.map +1 -1
- package/lib-amd/autoFormat/numbers/transformOrdinals.js +2 -2
- package/lib-amd/autoFormat/numbers/transformOrdinals.js.map +1 -1
- package/lib-amd/edit/EditPlugin.d.ts +15 -0
- package/lib-amd/edit/EditPlugin.js +14 -2
- package/lib-amd/edit/EditPlugin.js.map +1 -1
- package/lib-amd/imageEdit/ImageEditPlugin.d.ts +11 -5
- package/lib-amd/imageEdit/ImageEditPlugin.js +208 -104
- package/lib-amd/imageEdit/ImageEditPlugin.js.map +1 -1
- package/lib-amd/imageEdit/types/ImageAndParagraph.d.ts +8 -0
- package/lib-amd/imageEdit/types/ImageAndParagraph.js +5 -0
- package/lib-amd/imageEdit/types/ImageAndParagraph.js.map +1 -0
- package/lib-amd/imageEdit/types/ImageEditOptions.d.ts +1 -1
- package/lib-amd/imageEdit/types/ImageEditOptions.js.map +1 -1
- package/lib-amd/imageEdit/utils/applyChange.js +4 -8
- package/lib-amd/imageEdit/utils/applyChange.js.map +1 -1
- package/lib-amd/imageEdit/utils/createImageWrapper.d.ts +1 -1
- package/lib-amd/imageEdit/utils/createImageWrapper.js +10 -7
- package/lib-amd/imageEdit/utils/createImageWrapper.js.map +1 -1
- package/lib-amd/imageEdit/utils/findEditingImage.d.ts +6 -0
- package/lib-amd/imageEdit/utils/findEditingImage.js +45 -0
- package/lib-amd/imageEdit/utils/findEditingImage.js.map +1 -0
- package/lib-amd/imageEdit/utils/getSelectedImage.d.ts +6 -0
- package/lib-amd/imageEdit/utils/getSelectedImage.js +22 -0
- package/lib-amd/imageEdit/utils/getSelectedImage.js.map +1 -0
- package/lib-amd/imageEdit/utils/updateImageEditInfo.d.ts +1 -1
- package/lib-amd/imageEdit/utils/updateImageEditInfo.js +10 -6
- package/lib-amd/imageEdit/utils/updateImageEditInfo.js.map +1 -1
- package/lib-amd/imageEdit/utils/updateWrapper.js +2 -2
- package/lib-amd/imageEdit/utils/updateWrapper.js.map +1 -1
- package/lib-amd/index.d.ts +1 -1
- package/lib-amd/index.js.map +1 -1
- package/lib-amd/markdown/utils/setFormat.js +2 -2
- package/lib-amd/markdown/utils/setFormat.js.map +1 -1
- package/lib-amd/picker/getQueryString.js +2 -2
- package/lib-amd/picker/getQueryString.js.map +1 -1
- package/lib-amd/tableEdit/editors/TableEditor.js +4 -2
- package/lib-amd/tableEdit/editors/TableEditor.js.map +1 -1
- package/lib-amd/tableEdit/editors/features/TableMover.d.ts +2 -2
- package/lib-amd/tableEdit/editors/features/TableMover.js +4 -4
- package/lib-amd/tableEdit/editors/features/TableMover.js.map +1 -1
- package/lib-amd/watermark/WatermarkPlugin.d.ts +2 -0
- package/lib-amd/watermark/WatermarkPlugin.js +24 -5
- package/lib-amd/watermark/WatermarkPlugin.js.map +1 -1
- package/lib-mjs/autoFormat/hyphen/transformHyphen.js +1 -1
- package/lib-mjs/autoFormat/hyphen/transformHyphen.js.map +1 -1
- package/lib-mjs/autoFormat/link/createLink.js +7 -2
- package/lib-mjs/autoFormat/link/createLink.js.map +1 -1
- package/lib-mjs/autoFormat/link/createLinkAfterSpace.js +1 -2
- package/lib-mjs/autoFormat/link/createLinkAfterSpace.js.map +1 -1
- package/lib-mjs/autoFormat/numbers/transformFraction.js +1 -1
- package/lib-mjs/autoFormat/numbers/transformFraction.js.map +1 -1
- package/lib-mjs/autoFormat/numbers/transformOrdinals.js +1 -1
- package/lib-mjs/autoFormat/numbers/transformOrdinals.js.map +1 -1
- package/lib-mjs/edit/EditPlugin.d.ts +15 -0
- package/lib-mjs/edit/EditPlugin.js +14 -2
- package/lib-mjs/edit/EditPlugin.js.map +1 -1
- package/lib-mjs/imageEdit/ImageEditPlugin.d.ts +11 -5
- package/lib-mjs/imageEdit/ImageEditPlugin.js +211 -105
- package/lib-mjs/imageEdit/ImageEditPlugin.js.map +1 -1
- package/lib-mjs/imageEdit/types/ImageAndParagraph.d.ts +8 -0
- package/lib-mjs/imageEdit/types/ImageAndParagraph.js +2 -0
- package/lib-mjs/imageEdit/types/ImageAndParagraph.js.map +1 -0
- package/lib-mjs/imageEdit/types/ImageEditOptions.d.ts +1 -1
- package/lib-mjs/imageEdit/types/ImageEditOptions.js.map +1 -1
- package/lib-mjs/imageEdit/utils/applyChange.js +5 -9
- package/lib-mjs/imageEdit/utils/applyChange.js.map +1 -1
- package/lib-mjs/imageEdit/utils/createImageWrapper.d.ts +1 -1
- package/lib-mjs/imageEdit/utils/createImageWrapper.js +10 -6
- package/lib-mjs/imageEdit/utils/createImageWrapper.js.map +1 -1
- package/lib-mjs/imageEdit/utils/findEditingImage.d.ts +6 -0
- package/lib-mjs/imageEdit/utils/findEditingImage.js +39 -0
- package/lib-mjs/imageEdit/utils/findEditingImage.js.map +1 -0
- package/lib-mjs/imageEdit/utils/getSelectedImage.d.ts +6 -0
- package/lib-mjs/imageEdit/utils/getSelectedImage.js +17 -0
- package/lib-mjs/imageEdit/utils/getSelectedImage.js.map +1 -0
- package/lib-mjs/imageEdit/utils/updateImageEditInfo.d.ts +1 -1
- package/lib-mjs/imageEdit/utils/updateImageEditInfo.js +11 -7
- package/lib-mjs/imageEdit/utils/updateImageEditInfo.js.map +1 -1
- package/lib-mjs/imageEdit/utils/updateWrapper.js +2 -2
- package/lib-mjs/imageEdit/utils/updateWrapper.js.map +1 -1
- package/lib-mjs/index.d.ts +1 -1
- package/lib-mjs/index.js.map +1 -1
- package/lib-mjs/markdown/utils/setFormat.js +1 -2
- package/lib-mjs/markdown/utils/setFormat.js.map +1 -1
- package/lib-mjs/picker/getQueryString.js +1 -1
- package/lib-mjs/picker/getQueryString.js.map +1 -1
- package/lib-mjs/tableEdit/editors/TableEditor.js +4 -2
- package/lib-mjs/tableEdit/editors/TableEditor.js.map +1 -1
- package/lib-mjs/tableEdit/editors/features/TableMover.d.ts +2 -2
- package/lib-mjs/tableEdit/editors/features/TableMover.js +4 -4
- package/lib-mjs/tableEdit/editors/features/TableMover.js.map +1 -1
- package/lib-mjs/watermark/WatermarkPlugin.d.ts +2 -0
- package/lib-mjs/watermark/WatermarkPlugin.js +25 -5
- package/lib-mjs/watermark/WatermarkPlugin.js.map +1 -1
- package/package.json +5 -5
- package/lib/imageEdit/utils/getSelectedContentModelImage.d.ts +0 -5
- package/lib/imageEdit/utils/getSelectedContentModelImage.js +0 -16
- package/lib/imageEdit/utils/getSelectedContentModelImage.js.map +0 -1
- package/lib/pluginUtils/splitTextSegment.d.ts +0 -5
- package/lib/pluginUtils/splitTextSegment.js +0 -26
- package/lib/pluginUtils/splitTextSegment.js.map +0 -1
- package/lib-amd/imageEdit/utils/getSelectedContentModelImage.d.ts +0 -5
- package/lib-amd/imageEdit/utils/getSelectedContentModelImage.js +0 -17
- package/lib-amd/imageEdit/utils/getSelectedContentModelImage.js.map +0 -1
- package/lib-amd/pluginUtils/splitTextSegment.d.ts +0 -5
- package/lib-amd/pluginUtils/splitTextSegment.js +0 -26
- package/lib-amd/pluginUtils/splitTextSegment.js.map +0 -1
- package/lib-mjs/imageEdit/utils/getSelectedContentModelImage.d.ts +0 -5
- package/lib-mjs/imageEdit/utils/getSelectedContentModelImage.js +0 -12
- package/lib-mjs/imageEdit/utils/getSelectedContentModelImage.js.map +0 -1
- package/lib-mjs/pluginUtils/splitTextSegment.d.ts +0 -5
- package/lib-mjs/pluginUtils/splitTextSegment.js +0 -22
- package/lib-mjs/pluginUtils/splitTextSegment.js.map +0 -1
|
@@ -1,4 +1,13 @@
|
|
|
1
1
|
import type { EditorPlugin, IEditor, PluginEvent } from 'roosterjs-content-model-types';
|
|
2
|
+
/**
|
|
3
|
+
* Options to customize the keyboard handling behavior of Edit plugin
|
|
4
|
+
*/
|
|
5
|
+
export declare type EditOptions = {
|
|
6
|
+
/**
|
|
7
|
+
* Whether to handle Tab key in keyboard. @default true
|
|
8
|
+
*/
|
|
9
|
+
handleTabKey?: boolean;
|
|
10
|
+
};
|
|
2
11
|
/**
|
|
3
12
|
* Edit plugins helps editor to do editing operation on top of content model.
|
|
4
13
|
* This includes:
|
|
@@ -7,11 +16,17 @@ import type { EditorPlugin, IEditor, PluginEvent } from 'roosterjs-content-model
|
|
|
7
16
|
* 3. Tab Key
|
|
8
17
|
*/
|
|
9
18
|
export declare class EditPlugin implements EditorPlugin {
|
|
19
|
+
private options;
|
|
10
20
|
private editor;
|
|
11
21
|
private disposer;
|
|
12
22
|
private shouldHandleNextInputEvent;
|
|
13
23
|
private selectionAfterDelete;
|
|
14
24
|
private handleNormalEnter;
|
|
25
|
+
/**
|
|
26
|
+
* @param options An optional parameter that takes in an object of type EditOptions, which includes the following properties:
|
|
27
|
+
* handleTabKey: A boolean that enables or disables Tab key handling. Defaults to true.
|
|
28
|
+
*/
|
|
29
|
+
constructor(options?: EditOptions);
|
|
15
30
|
/**
|
|
16
31
|
* Get name of this plugin
|
|
17
32
|
*/
|
|
@@ -4,6 +4,9 @@ define(["require", "exports", "./keyboardDelete", "./keyboardEnter", "./keyboard
|
|
|
4
4
|
exports.EditPlugin = void 0;
|
|
5
5
|
var BACKSPACE_KEY = 8;
|
|
6
6
|
var DELETE_KEY = 46;
|
|
7
|
+
var DefaultOptions = {
|
|
8
|
+
handleTabKey: true,
|
|
9
|
+
};
|
|
7
10
|
/**
|
|
8
11
|
* Edit plugins helps editor to do editing operation on top of content model.
|
|
9
12
|
* This includes:
|
|
@@ -12,7 +15,13 @@ define(["require", "exports", "./keyboardDelete", "./keyboardEnter", "./keyboard
|
|
|
12
15
|
* 3. Tab Key
|
|
13
16
|
*/
|
|
14
17
|
var EditPlugin = /** @class */ (function () {
|
|
15
|
-
|
|
18
|
+
/**
|
|
19
|
+
* @param options An optional parameter that takes in an object of type EditOptions, which includes the following properties:
|
|
20
|
+
* handleTabKey: A boolean that enables or disables Tab key handling. Defaults to true.
|
|
21
|
+
*/
|
|
22
|
+
function EditPlugin(options) {
|
|
23
|
+
if (options === void 0) { options = DefaultOptions; }
|
|
24
|
+
this.options = options;
|
|
16
25
|
this.editor = null;
|
|
17
26
|
this.disposer = null;
|
|
18
27
|
this.shouldHandleNextInputEvent = false;
|
|
@@ -85,6 +94,7 @@ define(["require", "exports", "./keyboardDelete", "./keyboardEnter", "./keyboard
|
|
|
85
94
|
*/
|
|
86
95
|
EditPlugin.prototype.willHandleEventExclusively = function (event) {
|
|
87
96
|
if (this.editor &&
|
|
97
|
+
this.options.handleTabKey &&
|
|
88
98
|
event.eventType == 'keyDown' &&
|
|
89
99
|
event.rawEvent.key == 'Tab' &&
|
|
90
100
|
!event.rawEvent.shiftKey) {
|
|
@@ -126,7 +136,9 @@ define(["require", "exports", "./keyboardDelete", "./keyboardEnter", "./keyboard
|
|
|
126
136
|
}
|
|
127
137
|
break;
|
|
128
138
|
case 'Tab':
|
|
129
|
-
(
|
|
139
|
+
if (this.options.handleTabKey) {
|
|
140
|
+
(0, keyboardTab_1.keyboardTab)(editor, rawEvent);
|
|
141
|
+
}
|
|
130
142
|
break;
|
|
131
143
|
case 'Unidentified':
|
|
132
144
|
if (editor.getEnvironment().isAndroid) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EditPlugin.js","sourceRoot":"","sources":["../../../../packages/roosterjs-content-model-plugins/lib/edit/EditPlugin.ts"],"names":[],"mappings":";;;;IAaA,IAAM,aAAa,GAAG,CAAC,CAAC;IACxB,IAAM,UAAU,GAAG,EAAE,CAAC;IAEtB;;;;;;OAMG;IACH;QAAA;YACY,WAAM,GAAmB,IAAI,CAAC;YAC9B,aAAQ,GAAwB,IAAI,CAAC;YACrC,+BAA0B,GAAG,KAAK,CAAC;YACnC,yBAAoB,GAAwB,IAAI,CAAC;YACjD,sBAAiB,GAAG,KAAK,CAAC;QAyLtC,CAAC;QAvLG;;WAEG;QACH,4BAAO,GAAP;YACI,OAAO,MAAM,CAAC;QAClB,CAAC;QAED;;;;;WAKG;QACH,+BAAU,GAAV,UAAW,MAAe;YAA1B,iBAWC;YAVG,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;YACrB,IAAI,CAAC,iBAAiB,GAAG,IAAI,CAAC,MAAM,CAAC,4BAA4B,CAAC,cAAc,CAAC,CAAC;YAElF,IAAI,MAAM,CAAC,cAAc,EAAE,CAAC,SAAS,EAAE;gBACnC,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,MAAM,CAAC,cAAc,CAAC;oBACvC,WAAW,EAAE;wBACT,cAAc,EAAE,UAAA,CAAC,IAAI,OAAA,KAAI,CAAC,sBAAsB,CAAC,MAAM,EAAE,CAAC,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oB,GAAG,MAAM,CAAC,eAAe,EAAE,CAAC;aACxD;QACL,CAAC;QACL,iBAAC;IAAD,CAAC,AA9LD,IA8LC;IA9LY,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\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 private selectionAfterDelete: DOMSelection | null = null;\n private handleNormalEnter = 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 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 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 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 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":";;;;IAuBA,IAAM,aAAa,GAAG,CAAC,CAAC;IACxB,IAAM,UAAU,GAAG,EAAE,CAAC;IAEtB,IAAM,cAAc,GAAyB;QACzC,YAAY,EAAE,IAAI;KACrB,CAAC;IAEF;;;;;;OAMG;IACH;QAOI;;;WAGG;QACH,oBAAoB,OAAqC;YAArC,wBAAA,EAAA,wBAAqC;YAArC,YAAO,GA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AAC,0BAA0B;gBAChC,CAAC,CAAC,QAAQ,YAAY,UAAU,CAAC;gBACjC,QAAQ,CAAC,gBAAgB,EAC3B;gBACE,OAAO;aACV;YACD,IAAI,CAAC,0BAA0B,GAAG,KAAK,CAAC;YAExC,IAAI,OAAO,GAAG,KAAK,CAAC;YACpB,QAAQ,QAAQ,CAAC,SAAS,EAAE;gBACxB,KAAK,uBAAuB;oBACxB,OAAO,GAAG,IAAA,+BAAc,EACpB,MAAM,EACN,IAAI,aAAa,CAAC,SAAS,EAAE;wBACzB,GAAG,EAAE,WAAW;wBAChB,OAAO,EAAE,aAAa;wBACtB,KAAK,EAAE,aAAa;qBACvB,CAAC,CACL,CAAC;oBACF,MAAM;gBACV,KAAK,sBAAsB;oBACvB,OAAO,GAAG,IAAA,+BAAc,EACpB,MAAM,EACN,IAAI,aAAa,CAAC,SAAS,EAAE;wBACzB,GAAG,EAAE,QAAQ;wBACb,OAAO,EAAE,UAAU;wBACnB,KAAK,EAAE,UAAU;qBACpB,CAAC,CACL,CAAC;oBACF,MAAM;aACb;YAED,IAAI,OAAO,EAAE;gBACT,QAAQ,CAAC,cAAc,EAAE,CAAC;gBAE1B,sEAAsE;gBACtE,oDAAoD;gBACpD,IAAI,CAAC,oBAAoB,GAAG,MAAM,CAAC,eAAe,EAAE,CAAC;aACxD;QACL,CAAC;QACL,iBAAC;IAAD,CAAC,AAvMD,IAuMC;IAvMY,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"]}
|
|
@@ -12,7 +12,7 @@ export declare class ImageEditPlugin implements ImageEditor, EditorPlugin {
|
|
|
12
12
|
protected editor: IEditor | null;
|
|
13
13
|
private shadowSpan;
|
|
14
14
|
private selectedImage;
|
|
15
|
-
wrapper: HTMLSpanElement | null;
|
|
15
|
+
protected wrapper: HTMLSpanElement | null;
|
|
16
16
|
private imageEditInfo;
|
|
17
17
|
private imageHTMLOptions;
|
|
18
18
|
private dndHelpers;
|
|
@@ -25,6 +25,7 @@ export declare class ImageEditPlugin implements ImageEditor, EditorPlugin {
|
|
|
25
25
|
private croppers;
|
|
26
26
|
private zoomScale;
|
|
27
27
|
private disposer;
|
|
28
|
+
protected isEditing: boolean;
|
|
28
29
|
constructor(options?: ImageEditOptions);
|
|
29
30
|
/**
|
|
30
31
|
* Get name of this plugin
|
|
@@ -49,18 +50,23 @@ export declare class ImageEditPlugin implements ImageEditor, EditorPlugin {
|
|
|
49
50
|
* exclusively by another plugin.
|
|
50
51
|
* @param event The event to handle:
|
|
51
52
|
*/
|
|
52
|
-
onPluginEvent(
|
|
53
|
+
onPluginEvent(event: PluginEvent): void;
|
|
54
|
+
private isImageSelection;
|
|
55
|
+
private mouseUpHandler;
|
|
56
|
+
private selectBeforeEditingImage;
|
|
57
|
+
private keyDownHandler;
|
|
58
|
+
private applyFormatWithContentModel;
|
|
53
59
|
private startEditing;
|
|
54
|
-
startRotateAndResize(editor: IEditor, image: HTMLImageElement
|
|
60
|
+
startRotateAndResize(editor: IEditor, image: HTMLImageElement): void;
|
|
55
61
|
private updateRotateHandleState;
|
|
56
62
|
isOperationAllowed(operation: ImageEditOperation): boolean;
|
|
57
63
|
canRegenerateImage(image: HTMLImageElement): boolean;
|
|
64
|
+
private startCropMode;
|
|
58
65
|
cropImage(): void;
|
|
59
66
|
private editImage;
|
|
60
67
|
private cleanInfo;
|
|
61
|
-
private formatImageWithContentModel;
|
|
62
68
|
private removeImageWrapper;
|
|
63
69
|
flipImage(direction: 'horizontal' | 'vertical'): void;
|
|
64
70
|
rotateImage(angleRad: number): void;
|
|
65
|
-
|
|
71
|
+
get isEditingImage(): boolean;
|
|
66
72
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
define(["require", "exports", "tslib", "./utils/applyChange", "./utils/canRegenerateImage", "./utils/imageEditUtils", "./utils/createImageWrapper", "./Cropper/cropperContext", "./utils/getDropAndDragHelpers", "./utils/getHTMLImageOptions", "./utils/updateImageEditInfo", "./types/ImageEditElementClass", "./Resizer/resizerContext", "./Rotator/rotatorContext", "./Rotator/updateRotateHandle", "./utils/updateWrapper", "roosterjs-content-model-dom"], function (require, exports, tslib_1, applyChange_1, canRegenerateImage_1, imageEditUtils_1, createImageWrapper_1, cropperContext_1, getDropAndDragHelpers_1, getHTMLImageOptions_1, updateImageEditInfo_1, ImageEditElementClass_1, resizerContext_1, rotatorContext_1, updateRotateHandle_1, updateWrapper_1, roosterjs_content_model_dom_1) {
|
|
1
|
+
define(["require", "exports", "tslib", "./utils/applyChange", "./utils/canRegenerateImage", "./utils/imageEditUtils", "./utils/createImageWrapper", "./Cropper/cropperContext", "./utils/findEditingImage", "./utils/getDropAndDragHelpers", "./utils/getHTMLImageOptions", "./utils/getSelectedImage", "./utils/updateImageEditInfo", "./types/ImageEditElementClass", "./Resizer/resizerContext", "./Rotator/rotatorContext", "./Rotator/updateRotateHandle", "./utils/updateWrapper", "roosterjs-content-model-dom"], function (require, exports, tslib_1, applyChange_1, canRegenerateImage_1, imageEditUtils_1, createImageWrapper_1, cropperContext_1, findEditingImage_1, getDropAndDragHelpers_1, getHTMLImageOptions_1, getSelectedImage_1, updateImageEditInfo_1, ImageEditElementClass_1, resizerContext_1, rotatorContext_1, updateRotateHandle_1, updateWrapper_1, roosterjs_content_model_dom_1) {
|
|
2
2
|
"use strict";
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
exports.ImageEditPlugin = void 0;
|
|
@@ -9,9 +9,9 @@ define(["require", "exports", "tslib", "./utils/applyChange", "./utils/canRegene
|
|
|
9
9
|
preserveRatio: true,
|
|
10
10
|
disableRotate: false,
|
|
11
11
|
disableSideResize: false,
|
|
12
|
-
onSelectState: 'resize',
|
|
12
|
+
onSelectState: ['resize', 'rotate'],
|
|
13
13
|
};
|
|
14
|
-
var
|
|
14
|
+
var MouseRightButton = 2;
|
|
15
15
|
/**
|
|
16
16
|
* ImageEdit plugin handles the following image editing features:
|
|
17
17
|
* - Resize image
|
|
@@ -39,6 +39,8 @@ define(["require", "exports", "tslib", "./utils/applyChange", "./utils/canRegene
|
|
|
39
39
|
this.croppers = [];
|
|
40
40
|
this.zoomScale = 1;
|
|
41
41
|
this.disposer = null;
|
|
42
|
+
//EXPOSED FOR TEST ONLY
|
|
43
|
+
this.isEditing = false;
|
|
42
44
|
}
|
|
43
45
|
/**
|
|
44
46
|
* Get name of this plugin
|
|
@@ -58,7 +60,9 @@ define(["require", "exports", "tslib", "./utils/applyChange", "./utils/canRegene
|
|
|
58
60
|
this.disposer = editor.attachDomEvent({
|
|
59
61
|
blur: {
|
|
60
62
|
beforeDispatch: function () {
|
|
61
|
-
_this.
|
|
63
|
+
if (_this.editor) {
|
|
64
|
+
_this.applyFormatWithContentModel(_this.editor, _this.isCropMode, true /* shouldSelectImage */);
|
|
65
|
+
}
|
|
62
66
|
},
|
|
63
67
|
},
|
|
64
68
|
});
|
|
@@ -70,6 +74,7 @@ define(["require", "exports", "tslib", "./utils/applyChange", "./utils/canRegene
|
|
|
70
74
|
*/
|
|
71
75
|
ImageEditPlugin.prototype.dispose = function () {
|
|
72
76
|
this.editor = null;
|
|
77
|
+
this.isEditing = false;
|
|
73
78
|
this.cleanInfo();
|
|
74
79
|
if (this.disposer) {
|
|
75
80
|
this.disposer();
|
|
@@ -82,16 +87,145 @@ define(["require", "exports", "tslib", "./utils/applyChange", "./utils/canRegene
|
|
|
82
87
|
* exclusively by another plugin.
|
|
83
88
|
* @param event The event to handle:
|
|
84
89
|
*/
|
|
85
|
-
ImageEditPlugin.prototype.onPluginEvent = function (
|
|
86
|
-
|
|
87
|
-
var imageSpan = image.parentElement;
|
|
88
|
-
if (!imageSpan || (imageSpan && !(0, roosterjs_content_model_dom_1.isElementOfType)(imageSpan, 'span'))) {
|
|
90
|
+
ImageEditPlugin.prototype.onPluginEvent = function (event) {
|
|
91
|
+
if (!this.editor) {
|
|
89
92
|
return;
|
|
90
93
|
}
|
|
91
|
-
|
|
94
|
+
switch (event.eventType) {
|
|
95
|
+
case 'mouseUp':
|
|
96
|
+
this.mouseUpHandler(this.editor, event);
|
|
97
|
+
break;
|
|
98
|
+
case 'keyDown':
|
|
99
|
+
this.keyDownHandler(this.editor, event);
|
|
100
|
+
break;
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
ImageEditPlugin.prototype.isImageSelection = function (target) {
|
|
104
|
+
return ((0, roosterjs_content_model_dom_1.isNodeOfType)(target, 'ELEMENT_NODE') &&
|
|
105
|
+
((0, roosterjs_content_model_dom_1.isElementOfType)(target, 'img') ||
|
|
106
|
+
!!((0, roosterjs_content_model_dom_1.isElementOfType)(target, 'span') &&
|
|
107
|
+
target.firstElementChild &&
|
|
108
|
+
(0, roosterjs_content_model_dom_1.isNodeOfType)(target.firstElementChild, 'ELEMENT_NODE') &&
|
|
109
|
+
(0, roosterjs_content_model_dom_1.isElementOfType)(target.firstElementChild, 'img'))));
|
|
110
|
+
};
|
|
111
|
+
ImageEditPlugin.prototype.mouseUpHandler = function (editor, event) {
|
|
112
|
+
var selection = editor.getDOMSelection();
|
|
113
|
+
if ((selection && selection.type == 'image') || this.isEditing) {
|
|
114
|
+
var shouldSelectImage = this.isImageSelection(event.rawEvent.target) &&
|
|
115
|
+
event.rawEvent.button === MouseRightButton;
|
|
116
|
+
this.applyFormatWithContentModel(editor, this.isCropMode, shouldSelectImage);
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
//Sometimes the cursor can be inside the editing image and inside shadow dom, then the cursor need to moved out of shadow dom
|
|
120
|
+
ImageEditPlugin.prototype.selectBeforeEditingImage = function (editor, element) {
|
|
121
|
+
var parent = element.parentNode;
|
|
122
|
+
if (parent && (0, roosterjs_content_model_dom_1.isNodeOfType)(parent, 'ELEMENT_NODE') && parent.shadowRoot) {
|
|
123
|
+
element = parent;
|
|
124
|
+
parent = parent.parentNode;
|
|
125
|
+
}
|
|
126
|
+
var index = parent && (0, roosterjs_content_model_dom_1.toArray)(parent.childNodes).indexOf(element);
|
|
127
|
+
if (index !== null && index >= 0 && parent) {
|
|
128
|
+
var doc = editor.getDocument();
|
|
129
|
+
var range = doc.createRange();
|
|
130
|
+
range.setStart(parent, index);
|
|
131
|
+
range.collapse();
|
|
132
|
+
editor.setDOMSelection({
|
|
133
|
+
type: 'range',
|
|
134
|
+
range: range,
|
|
135
|
+
isReverted: false,
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
};
|
|
139
|
+
ImageEditPlugin.prototype.keyDownHandler = function (editor, event) {
|
|
140
|
+
if (this.isEditing) {
|
|
141
|
+
if (event.rawEvent.key === 'Escape') {
|
|
142
|
+
this.removeImageWrapper();
|
|
143
|
+
}
|
|
144
|
+
else {
|
|
145
|
+
var selection = editor.getDOMSelection();
|
|
146
|
+
var isImageSelection = (selection === null || selection === void 0 ? void 0 : selection.type) == 'image';
|
|
147
|
+
if (isImageSelection) {
|
|
148
|
+
this.selectBeforeEditingImage(editor, selection.image);
|
|
149
|
+
}
|
|
150
|
+
this.applyFormatWithContentModel(editor, this.isCropMode, ((0, roosterjs_content_model_dom_1.isModifierKey)(event.rawEvent) || event.rawEvent.shiftKey) && isImageSelection //if it's a modifier key over a image, the image should select the image
|
|
151
|
+
);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
};
|
|
155
|
+
ImageEditPlugin.prototype.applyFormatWithContentModel = function (editor, isCropMode, shouldSelectImage, isApiOperation) {
|
|
156
|
+
var _this = this;
|
|
157
|
+
var editingImageModel;
|
|
158
|
+
var selection = editor.getDOMSelection();
|
|
159
|
+
editor.formatContentModel(function (model) {
|
|
160
|
+
var editingImage = (0, getSelectedImage_1.getSelectedImage)(model);
|
|
161
|
+
var previousSelectedImage = isApiOperation
|
|
162
|
+
? editingImage
|
|
163
|
+
: (0, findEditingImage_1.findEditingImage)(model);
|
|
164
|
+
var result = false;
|
|
165
|
+
if (shouldSelectImage ||
|
|
166
|
+
(previousSelectedImage === null || previousSelectedImage === void 0 ? void 0 : previousSelectedImage.image) != (editingImage === null || editingImage === void 0 ? void 0 : editingImage.image) ||
|
|
167
|
+
(previousSelectedImage === null || previousSelectedImage === void 0 ? void 0 : previousSelectedImage.image.dataset.isEditing) ||
|
|
168
|
+
isApiOperation) {
|
|
169
|
+
var _a = _this, lastSrc_1 = _a.lastSrc, selectedImage_1 = _a.selectedImage, imageEditInfo_1 = _a.imageEditInfo, clonedImage_1 = _a.clonedImage;
|
|
170
|
+
if ((_this.isEditing || isApiOperation) &&
|
|
171
|
+
previousSelectedImage &&
|
|
172
|
+
lastSrc_1 &&
|
|
173
|
+
selectedImage_1 &&
|
|
174
|
+
imageEditInfo_1 &&
|
|
175
|
+
clonedImage_1) {
|
|
176
|
+
(0, roosterjs_content_model_dom_1.mutateSegment)(previousSelectedImage.paragraph, previousSelectedImage.image, function (image) {
|
|
177
|
+
(0, applyChange_1.applyChange)(editor, selectedImage_1, image, imageEditInfo_1, lastSrc_1, _this.wasImageResized || _this.isCropMode, clonedImage_1);
|
|
178
|
+
delete image.dataset.isEditing;
|
|
179
|
+
image.isSelected = shouldSelectImage;
|
|
180
|
+
image.isSelectedAsImageSelection = shouldSelectImage;
|
|
181
|
+
});
|
|
182
|
+
_this.cleanInfo();
|
|
183
|
+
result = true;
|
|
184
|
+
}
|
|
185
|
+
_this.isEditing = false;
|
|
186
|
+
_this.isCropMode = false;
|
|
187
|
+
if (editingImage &&
|
|
188
|
+
(selection === null || selection === void 0 ? void 0 : selection.type) == 'image' &&
|
|
189
|
+
!shouldSelectImage &&
|
|
190
|
+
!isApiOperation) {
|
|
191
|
+
_this.isEditing = true;
|
|
192
|
+
_this.isCropMode = isCropMode;
|
|
193
|
+
(0, roosterjs_content_model_dom_1.mutateSegment)(editingImage.paragraph, editingImage.image, function (image) {
|
|
194
|
+
editingImageModel = image;
|
|
195
|
+
_this.imageEditInfo = (0, updateImageEditInfo_1.updateImageEditInfo)(image, selection.image);
|
|
196
|
+
image.dataset.isEditing = 'true';
|
|
197
|
+
});
|
|
198
|
+
result = true;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
return result;
|
|
202
|
+
}, {
|
|
203
|
+
onNodeCreated: function (model, node) {
|
|
204
|
+
if (!isApiOperation &&
|
|
205
|
+
editingImageModel &&
|
|
206
|
+
editingImageModel == model &&
|
|
207
|
+
editingImageModel.dataset.isEditing &&
|
|
208
|
+
(0, roosterjs_content_model_dom_1.isNodeOfType)(node, 'ELEMENT_NODE') &&
|
|
209
|
+
(0, roosterjs_content_model_dom_1.isElementOfType)(node, 'img')) {
|
|
210
|
+
if (isCropMode) {
|
|
211
|
+
_this.startCropMode(editor, node);
|
|
212
|
+
}
|
|
213
|
+
else {
|
|
214
|
+
_this.startRotateAndResize(editor, node);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
},
|
|
218
|
+
}, {
|
|
219
|
+
tryGetFromCache: true,
|
|
220
|
+
});
|
|
221
|
+
};
|
|
222
|
+
ImageEditPlugin.prototype.startEditing = function (editor, image, apiOperation) {
|
|
223
|
+
if (!this.imageEditInfo) {
|
|
224
|
+
this.imageEditInfo = (0, updateImageEditInfo_1.getSelectedImageMetadata)(editor, image);
|
|
225
|
+
}
|
|
92
226
|
this.lastSrc = image.getAttribute('src');
|
|
93
227
|
this.imageHTMLOptions = (0, getHTMLImageOptions_1.getHTMLImageOptions)(editor, this.options, this.imageEditInfo);
|
|
94
|
-
var _a = (0, createImageWrapper_1.createImageWrapper)(editor, image,
|
|
228
|
+
var _a = (0, createImageWrapper_1.createImageWrapper)(editor, image, this.options, this.imageEditInfo, this.imageHTMLOptions, apiOperation), resizers = _a.resizers, rotators = _a.rotators, wrapper = _a.wrapper, shadowSpan = _a.shadowSpan, imageClone = _a.imageClone, croppers = _a.croppers;
|
|
95
229
|
this.shadowSpan = shadowSpan;
|
|
96
230
|
this.selectedImage = image;
|
|
97
231
|
this.wrapper = wrapper;
|
|
@@ -105,34 +239,33 @@ define(["require", "exports", "tslib", "./utils/applyChange", "./utils/canRegene
|
|
|
105
239
|
"span:has(>img#" + this.selectedImage.id + ")",
|
|
106
240
|
]);
|
|
107
241
|
};
|
|
108
|
-
ImageEditPlugin.prototype.startRotateAndResize = function (editor, image
|
|
242
|
+
ImageEditPlugin.prototype.startRotateAndResize = function (editor, image) {
|
|
109
243
|
var _this = this;
|
|
110
244
|
var _a;
|
|
111
|
-
if (this.
|
|
112
|
-
this.
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
this.updateRotateHandleState(editor, this.selectedImage, this.wrapper, this.rotators, (_a = this.imageEditInfo) === null || _a === void 0 ? void 0 : _a.angleRad);
|
|
245
|
+
if (this.imageEditInfo) {
|
|
246
|
+
this.startEditing(editor, image, ['resize', 'rotate']);
|
|
247
|
+
if (this.selectedImage && this.imageEditInfo && this.wrapper && this.clonedImage) {
|
|
248
|
+
this.dndHelpers = (0, tslib_1.__spreadArray)((0, tslib_1.__spreadArray)([], (0, tslib_1.__read)((0, getDropAndDragHelpers_1.getDropAndDragHelpers)(this.wrapper, this.imageEditInfo, this.options, ImageEditElementClass_1.ImageEditElementClass.ResizeHandle, resizerContext_1.Resizer, function () {
|
|
249
|
+
if (_this.imageEditInfo &&
|
|
250
|
+
_this.selectedImage &&
|
|
251
|
+
_this.wrapper &&
|
|
252
|
+
_this.clonedImage) {
|
|
253
|
+
(0, updateWrapper_1.updateWrapper)(_this.imageEditInfo, _this.options, _this.selectedImage, _this.clonedImage, _this.wrapper, _this.resizers);
|
|
254
|
+
_this.wasImageResized = true;
|
|
255
|
+
}
|
|
256
|
+
}, this.zoomScale)), false), (0, tslib_1.__read)((0, getDropAndDragHelpers_1.getDropAndDragHelpers)(this.wrapper, this.imageEditInfo, this.options, ImageEditElementClass_1.ImageEditElementClass.RotateHandle, rotatorContext_1.Rotator, function () {
|
|
257
|
+
var _a;
|
|
258
|
+
if (_this.imageEditInfo &&
|
|
259
|
+
_this.selectedImage &&
|
|
260
|
+
_this.wrapper &&
|
|
261
|
+
_this.clonedImage) {
|
|
262
|
+
(0, updateWrapper_1.updateWrapper)(_this.imageEditInfo, _this.options, _this.selectedImage, _this.clonedImage, _this.wrapper);
|
|
263
|
+
_this.updateRotateHandleState(editor, _this.selectedImage, _this.wrapper, _this.rotators, (_a = _this.imageEditInfo) === null || _a === void 0 ? void 0 : _a.angleRad);
|
|
264
|
+
}
|
|
265
|
+
}, this.zoomScale)), false);
|
|
266
|
+
(0, updateWrapper_1.updateWrapper)(this.imageEditInfo, this.options, this.selectedImage, this.clonedImage, this.wrapper, this.resizers);
|
|
267
|
+
this.updateRotateHandleState(editor, this.selectedImage, this.wrapper, this.rotators, (_a = this.imageEditInfo) === null || _a === void 0 ? void 0 : _a.angleRad);
|
|
268
|
+
}
|
|
136
269
|
}
|
|
137
270
|
};
|
|
138
271
|
ImageEditPlugin.prototype.updateRotateHandleState = function (editor, image, wrapper, rotators, angleRad) {
|
|
@@ -148,49 +281,52 @@ define(["require", "exports", "tslib", "./utils/applyChange", "./utils/canRegene
|
|
|
148
281
|
}
|
|
149
282
|
};
|
|
150
283
|
ImageEditPlugin.prototype.isOperationAllowed = function (operation) {
|
|
151
|
-
return operation === 'resize' ||
|
|
284
|
+
return (operation === 'resize' ||
|
|
285
|
+
operation === 'rotate' ||
|
|
286
|
+
operation === 'flip' ||
|
|
287
|
+
operation === 'crop');
|
|
152
288
|
};
|
|
153
289
|
ImageEditPlugin.prototype.canRegenerateImage = function (image) {
|
|
154
290
|
return (0, canRegenerateImage_1.canRegenerateImage)(image);
|
|
155
291
|
};
|
|
156
|
-
ImageEditPlugin.prototype.
|
|
292
|
+
ImageEditPlugin.prototype.startCropMode = function (editor, image) {
|
|
157
293
|
var _this = this;
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
294
|
+
if (this.imageEditInfo) {
|
|
295
|
+
this.startEditing(editor, image, ['crop']);
|
|
296
|
+
if (this.imageEditInfo && this.selectedImage && this.wrapper && this.clonedImage) {
|
|
297
|
+
this.dndHelpers = (0, tslib_1.__spreadArray)([], (0, tslib_1.__read)((0, getDropAndDragHelpers_1.getDropAndDragHelpers)(this.wrapper, this.imageEditInfo, this.options, ImageEditElementClass_1.ImageEditElementClass.CropHandle, cropperContext_1.Cropper, function () {
|
|
298
|
+
if (_this.imageEditInfo &&
|
|
299
|
+
_this.selectedImage &&
|
|
300
|
+
_this.wrapper &&
|
|
301
|
+
_this.clonedImage) {
|
|
302
|
+
(0, updateWrapper_1.updateWrapper)(_this.imageEditInfo, _this.options, _this.selectedImage, _this.clonedImage, _this.wrapper, undefined, _this.croppers);
|
|
303
|
+
_this.isCropMode = true;
|
|
304
|
+
}
|
|
305
|
+
}, this.zoomScale)), false);
|
|
306
|
+
(0, updateWrapper_1.updateWrapper)(this.imageEditInfo, this.options, this.selectedImage, this.clonedImage, this.wrapper, undefined, this.croppers);
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
};
|
|
310
|
+
ImageEditPlugin.prototype.cropImage = function () {
|
|
311
|
+
if (!this.editor) {
|
|
161
312
|
return;
|
|
162
313
|
}
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
image = (_b = this.removeImageWrapper()) !== null && _b !== void 0 ? _b : image;
|
|
314
|
+
if (!this.editor.getEnvironment().isSafari) {
|
|
315
|
+
this.editor.focus(); // Safari will keep the selection when click crop, then the focus() call should not be called
|
|
166
316
|
}
|
|
167
|
-
this.
|
|
168
|
-
if (
|
|
169
|
-
|
|
317
|
+
var selection = this.editor.getDOMSelection();
|
|
318
|
+
if ((selection === null || selection === void 0 ? void 0 : selection.type) == 'image') {
|
|
319
|
+
this.applyFormatWithContentModel(this.editor, true /* isCropMode */, false /* shouldSelectImage */);
|
|
170
320
|
}
|
|
171
|
-
this.dndHelpers = (0, tslib_1.__spreadArray)([], (0, tslib_1.__read)((0, getDropAndDragHelpers_1.getDropAndDragHelpers)(this.wrapper, this.imageEditInfo, this.options, ImageEditElementClass_1.ImageEditElementClass.CropHandle, cropperContext_1.Cropper, function () {
|
|
172
|
-
if (_this.imageEditInfo &&
|
|
173
|
-
_this.selectedImage &&
|
|
174
|
-
_this.wrapper &&
|
|
175
|
-
_this.clonedImage) {
|
|
176
|
-
(0, updateWrapper_1.updateWrapper)(_this.imageEditInfo, _this.options, _this.selectedImage, _this.clonedImage, _this.wrapper, undefined, _this.croppers);
|
|
177
|
-
_this.isCropMode = true;
|
|
178
|
-
}
|
|
179
|
-
}, this.zoomScale)), false);
|
|
180
|
-
(0, updateWrapper_1.updateWrapper)(this.imageEditInfo, this.options, this.selectedImage, this.clonedImage, this.wrapper, undefined, this.croppers);
|
|
181
321
|
};
|
|
182
322
|
ImageEditPlugin.prototype.editImage = function (editor, image, apiOperation, operation) {
|
|
183
|
-
var _a;
|
|
184
|
-
if (this.wrapper && this.selectedImage && this.shadowSpan) {
|
|
185
|
-
image = (_a = this.removeImageWrapper()) !== null && _a !== void 0 ? _a : image;
|
|
186
|
-
}
|
|
187
323
|
this.startEditing(editor, image, apiOperation);
|
|
188
324
|
if (!this.selectedImage || !this.imageEditInfo || !this.wrapper || !this.clonedImage) {
|
|
189
325
|
return;
|
|
190
326
|
}
|
|
191
327
|
operation(this.imageEditInfo);
|
|
192
328
|
(0, updateWrapper_1.updateWrapper)(this.imageEditInfo, this.options, this.selectedImage, this.clonedImage, this.wrapper);
|
|
193
|
-
this.
|
|
329
|
+
this.applyFormatWithContentModel(editor, false /* isCrop */, true /* shouldSelect*/, true /* isApiOperation */);
|
|
194
330
|
};
|
|
195
331
|
ImageEditPlugin.prototype.cleanInfo = function () {
|
|
196
332
|
var _a;
|
|
@@ -210,42 +346,6 @@ define(["require", "exports", "tslib", "./utils/applyChange", "./utils/canRegene
|
|
|
210
346
|
this.rotators = [];
|
|
211
347
|
this.croppers = [];
|
|
212
348
|
};
|
|
213
|
-
ImageEditPlugin.prototype.formatImageWithContentModel = function (editor, shouldSelectImage, shouldSelectAsImageSelection) {
|
|
214
|
-
var _this = this;
|
|
215
|
-
if (this.lastSrc &&
|
|
216
|
-
this.selectedImage &&
|
|
217
|
-
this.imageEditInfo &&
|
|
218
|
-
this.clonedImage &&
|
|
219
|
-
this.shadowSpan) {
|
|
220
|
-
editor.formatContentModel(function (model) {
|
|
221
|
-
var selectedSegmentsAndParagraphs = (0, roosterjs_content_model_dom_1.getSelectedSegmentsAndParagraphs)(model, false);
|
|
222
|
-
if (!selectedSegmentsAndParagraphs[0]) {
|
|
223
|
-
return false;
|
|
224
|
-
}
|
|
225
|
-
var segment = selectedSegmentsAndParagraphs[0][0];
|
|
226
|
-
var paragraph = selectedSegmentsAndParagraphs[0][1];
|
|
227
|
-
if (paragraph && segment.segmentType == 'Image') {
|
|
228
|
-
(0, roosterjs_content_model_dom_1.mutateSegment)(paragraph, segment, function (image) {
|
|
229
|
-
if (_this.lastSrc &&
|
|
230
|
-
_this.selectedImage &&
|
|
231
|
-
_this.imageEditInfo &&
|
|
232
|
-
_this.clonedImage) {
|
|
233
|
-
(0, applyChange_1.applyChange)(editor, _this.selectedImage, image, _this.imageEditInfo, _this.lastSrc, _this.wasImageResized || _this.isCropMode, _this.clonedImage);
|
|
234
|
-
image.isSelected = shouldSelectImage;
|
|
235
|
-
image.isSelectedAsImageSelection = shouldSelectAsImageSelection;
|
|
236
|
-
}
|
|
237
|
-
});
|
|
238
|
-
return true;
|
|
239
|
-
}
|
|
240
|
-
return false;
|
|
241
|
-
}, {
|
|
242
|
-
changeSource: IMAGE_EDIT_CHANGE_SOURCE,
|
|
243
|
-
onNodeCreated: function () {
|
|
244
|
-
_this.cleanInfo();
|
|
245
|
-
},
|
|
246
|
-
});
|
|
247
|
-
}
|
|
248
|
-
};
|
|
249
349
|
ImageEditPlugin.prototype.removeImageWrapper = function () {
|
|
250
350
|
var image = null;
|
|
251
351
|
if (this.shadowSpan && this.shadowSpan.parentElement) {
|
|
@@ -268,7 +368,7 @@ define(["require", "exports", "tslib", "./utils/applyChange", "./utils/canRegene
|
|
|
268
368
|
}
|
|
269
369
|
var image = selection.image;
|
|
270
370
|
if (this.editor) {
|
|
271
|
-
this.editImage(this.editor, image, 'flip', function (imageEditInfo) {
|
|
371
|
+
this.editImage(this.editor, image, ['flip'], function (imageEditInfo) {
|
|
272
372
|
var angleRad = imageEditInfo.angleRad || 0;
|
|
273
373
|
var isInVerticalPostion = (angleRad >= Math.PI / 2 && angleRad < (3 * Math.PI) / 4) ||
|
|
274
374
|
(angleRad <= -Math.PI / 2 && angleRad > (-3 * Math.PI) / 4);
|
|
@@ -299,15 +399,19 @@ define(["require", "exports", "tslib", "./utils/applyChange", "./utils/canRegene
|
|
|
299
399
|
}
|
|
300
400
|
var image = selection.image;
|
|
301
401
|
if (this.editor) {
|
|
302
|
-
this.editImage(this.editor, image,
|
|
402
|
+
this.editImage(this.editor, image, [], function (imageEditInfo) {
|
|
303
403
|
imageEditInfo.angleRad = (imageEditInfo.angleRad || 0) + angleRad;
|
|
304
404
|
});
|
|
305
405
|
}
|
|
306
406
|
};
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
407
|
+
Object.defineProperty(ImageEditPlugin.prototype, "isEditingImage", {
|
|
408
|
+
//EXPOSED FOR TEST ONLY
|
|
409
|
+
get: function () {
|
|
410
|
+
return this.isEditing;
|
|
411
|
+
},
|
|
412
|
+
enumerable: false,
|
|
413
|
+
configurable: true
|
|
414
|
+
});
|
|
311
415
|
return ImageEditPlugin;
|
|
312
416
|
}());
|
|
313
417
|
exports.ImageEditPlugin = ImageEditPlugin;
|