roosterjs-content-model-plugins 9.26.0 → 9.27.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.
Files changed (139) hide show
  1. package/lib/autoFormat/AutoFormatPlugin.d.ts +4 -1
  2. package/lib/autoFormat/AutoFormatPlugin.js +94 -96
  3. package/lib/autoFormat/AutoFormatPlugin.js.map +1 -1
  4. package/lib/autoFormat/horizontalLine/checkAndInsertHorizontalLine.d.ts +3 -3
  5. package/lib/autoFormat/horizontalLine/checkAndInsertHorizontalLine.js +14 -21
  6. package/lib/autoFormat/horizontalLine/checkAndInsertHorizontalLine.js.map +1 -1
  7. package/lib/edit/EditPlugin.d.ts +9 -0
  8. package/lib/edit/EditPlugin.js +19 -3
  9. package/lib/edit/EditPlugin.js.map +1 -1
  10. package/lib/edit/utils/splitParagraph.d.ts +3 -2
  11. package/lib/edit/utils/splitParagraph.js +41 -2
  12. package/lib/edit/utils/splitParagraph.js.map +1 -1
  13. package/lib/imageEdit/ImageEditPlugin.js +9 -9
  14. package/lib/imageEdit/ImageEditPlugin.js.map +1 -1
  15. package/lib/imageEdit/utils/findEditingImage.d.ts +4 -0
  16. package/lib/imageEdit/utils/findEditingImage.js +7 -2
  17. package/lib/imageEdit/utils/findEditingImage.js.map +1 -1
  18. package/lib/paste/PastePlugin.js +3 -3
  19. package/lib/paste/PastePlugin.js.map +1 -1
  20. package/lib/paste/PowerPoint/processPastedContentFromPowerPoint.js +132 -1
  21. package/lib/paste/PowerPoint/processPastedContentFromPowerPoint.js.map +1 -1
  22. package/lib/paste/WordDesktop/getStyleMetadata.d.ts +2 -2
  23. package/lib/paste/WordDesktop/getStyleMetadata.js +22 -5
  24. package/lib/paste/WordDesktop/getStyleMetadata.js.map +1 -1
  25. package/lib/paste/WordDesktop/processPastedContentFromWordDesktop.d.ts +2 -2
  26. package/lib/paste/WordDesktop/processPastedContentFromWordDesktop.js +5 -5
  27. package/lib/paste/WordDesktop/processPastedContentFromWordDesktop.js.map +1 -1
  28. package/lib/paste/WordDesktop/processWordLists.js +25 -60
  29. package/lib/paste/WordDesktop/processWordLists.js.map +1 -1
  30. package/lib/paste/parsers/deprecatedColorParser.js.map +1 -0
  31. package/lib/paste/parsers/linkParser.js.map +1 -0
  32. package/lib/paste/{WordDesktop → parsers}/removeNegativeTextIndentParser.js +1 -1
  33. package/lib/paste/parsers/removeNegativeTextIndentParser.js.map +1 -0
  34. package/lib/paste/utils/customListUtils.d.ts +9 -0
  35. package/lib/paste/utils/customListUtils.js +63 -0
  36. package/lib/paste/utils/customListUtils.js.map +1 -0
  37. package/lib/watermark/WatermarkPlugin.js +1 -1
  38. package/lib/watermark/WatermarkPlugin.js.map +1 -1
  39. package/lib-amd/autoFormat/AutoFormatPlugin.d.ts +4 -1
  40. package/lib-amd/autoFormat/AutoFormatPlugin.js +94 -96
  41. package/lib-amd/autoFormat/AutoFormatPlugin.js.map +1 -1
  42. package/lib-amd/autoFormat/horizontalLine/checkAndInsertHorizontalLine.d.ts +3 -3
  43. package/lib-amd/autoFormat/horizontalLine/checkAndInsertHorizontalLine.js +15 -21
  44. package/lib-amd/autoFormat/horizontalLine/checkAndInsertHorizontalLine.js.map +1 -1
  45. package/lib-amd/edit/EditPlugin.d.ts +9 -0
  46. package/lib-amd/edit/EditPlugin.js +19 -3
  47. package/lib-amd/edit/EditPlugin.js.map +1 -1
  48. package/lib-amd/edit/utils/splitParagraph.d.ts +3 -2
  49. package/lib-amd/edit/utils/splitParagraph.js +41 -2
  50. package/lib-amd/edit/utils/splitParagraph.js.map +1 -1
  51. package/lib-amd/imageEdit/ImageEditPlugin.js +9 -9
  52. package/lib-amd/imageEdit/ImageEditPlugin.js.map +1 -1
  53. package/lib-amd/imageEdit/utils/findEditingImage.d.ts +4 -0
  54. package/lib-amd/imageEdit/utils/findEditingImage.js +7 -2
  55. package/lib-amd/imageEdit/utils/findEditingImage.js.map +1 -1
  56. package/lib-amd/paste/PastePlugin.js +2 -2
  57. package/lib-amd/paste/PastePlugin.js.map +1 -1
  58. package/lib-amd/paste/PowerPoint/processPastedContentFromPowerPoint.js +128 -2
  59. package/lib-amd/paste/PowerPoint/processPastedContentFromPowerPoint.js.map +1 -1
  60. package/lib-amd/paste/WordDesktop/getStyleMetadata.d.ts +2 -2
  61. package/lib-amd/paste/WordDesktop/getStyleMetadata.js +22 -5
  62. package/lib-amd/paste/WordDesktop/getStyleMetadata.js.map +1 -1
  63. package/lib-amd/paste/WordDesktop/processPastedContentFromWordDesktop.d.ts +2 -2
  64. package/lib-amd/paste/WordDesktop/processPastedContentFromWordDesktop.js +5 -5
  65. package/lib-amd/paste/WordDesktop/processPastedContentFromWordDesktop.js.map +1 -1
  66. package/lib-amd/paste/WordDesktop/processWordLists.js +25 -60
  67. package/lib-amd/paste/WordDesktop/processWordLists.js.map +1 -1
  68. package/lib-amd/paste/parsers/deprecatedColorParser.js.map +1 -0
  69. package/lib-amd/paste/parsers/linkParser.js.map +1 -0
  70. package/lib-amd/paste/{WordDesktop → parsers}/removeNegativeTextIndentParser.js +1 -1
  71. package/lib-amd/paste/parsers/removeNegativeTextIndentParser.js.map +1 -0
  72. package/lib-amd/paste/utils/customListUtils.d.ts +9 -0
  73. package/lib-amd/paste/utils/customListUtils.js +63 -0
  74. package/lib-amd/paste/utils/customListUtils.js.map +1 -0
  75. package/lib-amd/watermark/WatermarkPlugin.js +1 -1
  76. package/lib-amd/watermark/WatermarkPlugin.js.map +1 -1
  77. package/lib-mjs/autoFormat/AutoFormatPlugin.d.ts +4 -1
  78. package/lib-mjs/autoFormat/AutoFormatPlugin.js +95 -97
  79. package/lib-mjs/autoFormat/AutoFormatPlugin.js.map +1 -1
  80. package/lib-mjs/autoFormat/horizontalLine/checkAndInsertHorizontalLine.d.ts +3 -3
  81. package/lib-mjs/autoFormat/horizontalLine/checkAndInsertHorizontalLine.js +15 -22
  82. package/lib-mjs/autoFormat/horizontalLine/checkAndInsertHorizontalLine.js.map +1 -1
  83. package/lib-mjs/edit/EditPlugin.d.ts +9 -0
  84. package/lib-mjs/edit/EditPlugin.js +19 -3
  85. package/lib-mjs/edit/EditPlugin.js.map +1 -1
  86. package/lib-mjs/edit/utils/splitParagraph.d.ts +3 -2
  87. package/lib-mjs/edit/utils/splitParagraph.js +42 -3
  88. package/lib-mjs/edit/utils/splitParagraph.js.map +1 -1
  89. package/lib-mjs/imageEdit/ImageEditPlugin.js +11 -11
  90. package/lib-mjs/imageEdit/ImageEditPlugin.js.map +1 -1
  91. package/lib-mjs/imageEdit/utils/findEditingImage.d.ts +4 -0
  92. package/lib-mjs/imageEdit/utils/findEditingImage.js +6 -1
  93. package/lib-mjs/imageEdit/utils/findEditingImage.js.map +1 -1
  94. package/lib-mjs/paste/PastePlugin.js +3 -3
  95. package/lib-mjs/paste/PastePlugin.js.map +1 -1
  96. package/lib-mjs/paste/PowerPoint/processPastedContentFromPowerPoint.js +133 -2
  97. package/lib-mjs/paste/PowerPoint/processPastedContentFromPowerPoint.js.map +1 -1
  98. package/lib-mjs/paste/WordDesktop/getStyleMetadata.d.ts +2 -2
  99. package/lib-mjs/paste/WordDesktop/getStyleMetadata.js +22 -5
  100. package/lib-mjs/paste/WordDesktop/getStyleMetadata.js.map +1 -1
  101. package/lib-mjs/paste/WordDesktop/processPastedContentFromWordDesktop.d.ts +2 -2
  102. package/lib-mjs/paste/WordDesktop/processPastedContentFromWordDesktop.js +5 -5
  103. package/lib-mjs/paste/WordDesktop/processPastedContentFromWordDesktop.js.map +1 -1
  104. package/lib-mjs/paste/WordDesktop/processWordLists.js +26 -61
  105. package/lib-mjs/paste/WordDesktop/processWordLists.js.map +1 -1
  106. package/lib-mjs/paste/parsers/deprecatedColorParser.js.map +1 -0
  107. package/lib-mjs/paste/parsers/linkParser.js.map +1 -0
  108. package/lib-mjs/paste/{WordDesktop → parsers}/removeNegativeTextIndentParser.js +1 -1
  109. package/lib-mjs/paste/parsers/removeNegativeTextIndentParser.js.map +1 -0
  110. package/lib-mjs/paste/utils/customListUtils.d.ts +9 -0
  111. package/lib-mjs/paste/utils/customListUtils.js +58 -0
  112. package/lib-mjs/paste/utils/customListUtils.js.map +1 -0
  113. package/lib-mjs/watermark/WatermarkPlugin.js +1 -1
  114. package/lib-mjs/watermark/WatermarkPlugin.js.map +1 -1
  115. package/package.json +5 -5
  116. package/lib/paste/WordDesktop/removeNegativeTextIndentParser.js.map +0 -1
  117. package/lib/paste/utils/deprecatedColorParser.js.map +0 -1
  118. package/lib/paste/utils/linkParser.js.map +0 -1
  119. package/lib-amd/paste/WordDesktop/removeNegativeTextIndentParser.js.map +0 -1
  120. package/lib-amd/paste/utils/deprecatedColorParser.js.map +0 -1
  121. package/lib-amd/paste/utils/linkParser.js.map +0 -1
  122. package/lib-mjs/paste/WordDesktop/removeNegativeTextIndentParser.js.map +0 -1
  123. package/lib-mjs/paste/utils/deprecatedColorParser.js.map +0 -1
  124. package/lib-mjs/paste/utils/linkParser.js.map +0 -1
  125. /package/lib/paste/{utils → parsers}/deprecatedColorParser.d.ts +0 -0
  126. /package/lib/paste/{utils → parsers}/deprecatedColorParser.js +0 -0
  127. /package/lib/paste/{utils → parsers}/linkParser.d.ts +0 -0
  128. /package/lib/paste/{utils → parsers}/linkParser.js +0 -0
  129. /package/lib/paste/{WordDesktop → parsers}/removeNegativeTextIndentParser.d.ts +0 -0
  130. /package/lib-amd/paste/{utils → parsers}/deprecatedColorParser.d.ts +0 -0
  131. /package/lib-amd/paste/{utils → parsers}/deprecatedColorParser.js +0 -0
  132. /package/lib-amd/paste/{utils → parsers}/linkParser.d.ts +0 -0
  133. /package/lib-amd/paste/{utils → parsers}/linkParser.js +0 -0
  134. /package/lib-amd/paste/{WordDesktop → parsers}/removeNegativeTextIndentParser.d.ts +0 -0
  135. /package/lib-mjs/paste/{utils → parsers}/deprecatedColorParser.d.ts +0 -0
  136. /package/lib-mjs/paste/{utils → parsers}/deprecatedColorParser.js +0 -0
  137. /package/lib-mjs/paste/{utils → parsers}/linkParser.d.ts +0 -0
  138. /package/lib-mjs/paste/{utils → parsers}/linkParser.js +0 -0
  139. /package/lib-mjs/paste/{WordDesktop → parsers}/removeNegativeTextIndentParser.d.ts +0 -0
@@ -12,6 +12,13 @@ export declare type EditOptions = {
12
12
  * @default true
13
13
  */
14
14
  handleExpandedSelectionOnDelete?: boolean;
15
+ /**
16
+ * Callback function to determine whether the Rooster should handle the Enter key press.
17
+ * If the function returns true, the Rooster will handle the Enter key press instead of the browser.
18
+ * @param editor - The editor instance.
19
+ * @returns A boolean
20
+ */
21
+ shouldHandleEnterKey?: ((editor: IEditor) => boolean) | boolean;
15
22
  };
16
23
  /**
17
24
  * Edit plugins helps editor to do editing operation on top of content model.
@@ -32,6 +39,8 @@ export declare class EditPlugin implements EditorPlugin {
32
39
  * handleTabKey: A boolean that enables or disables Tab key handling. Defaults to true.
33
40
  */
34
41
  constructor(options?: EditOptions);
42
+ private createNormalEnterChecker;
43
+ private getHandleNormalEnter;
35
44
  /**
36
45
  * Get name of this plugin
37
46
  */
@@ -34,8 +34,24 @@ define(["require", "exports", "./keyboardDelete", "./keyboardEnter", "./keyboard
34
34
  this.disposer = null;
35
35
  this.shouldHandleNextInputEvent = false;
36
36
  this.selectionAfterDelete = null;
37
- this.handleNormalEnter = false;
37
+ this.handleNormalEnter = function (editor) { return false; };
38
38
  }
39
+ EditPlugin.prototype.createNormalEnterChecker = function (result) {
40
+ return result ? function () { return true; } : function () { return false; };
41
+ };
42
+ EditPlugin.prototype.getHandleNormalEnter = function (editor) {
43
+ switch (typeof this.options.shouldHandleEnterKey) {
44
+ case 'function':
45
+ return this.options.shouldHandleEnterKey;
46
+ break;
47
+ case 'boolean':
48
+ return this.createNormalEnterChecker(this.options.shouldHandleEnterKey);
49
+ break;
50
+ default:
51
+ return this.createNormalEnterChecker(editor.isExperimentalFeatureEnabled('HandleEnterKey'));
52
+ break;
53
+ }
54
+ };
39
55
  /**
40
56
  * Get name of this plugin
41
57
  */
@@ -51,7 +67,7 @@ define(["require", "exports", "./keyboardDelete", "./keyboardEnter", "./keyboard
51
67
  EditPlugin.prototype.initialize = function (editor) {
52
68
  var _this = this;
53
69
  this.editor = editor;
54
- this.handleNormalEnter = this.editor.isExperimentalFeatureEnabled('HandleEnterKey');
70
+ this.handleNormalEnter = this.getHandleNormalEnter(editor);
55
71
  if (editor.getEnvironment().isAndroid) {
56
72
  this.disposer = this.editor.attachDomEvent({
57
73
  beforeinput: {
@@ -158,7 +174,7 @@ define(["require", "exports", "./keyboardDelete", "./keyboardEnter", "./keyboard
158
174
  if (!hasCtrlOrMetaKey &&
159
175
  !event.rawEvent.isComposing &&
160
176
  event.rawEvent.keyCode !== DEAD_KEY) {
161
- (0, keyboardEnter_1.keyboardEnter)(editor, rawEvent, this.handleNormalEnter);
177
+ (0, keyboardEnter_1.keyboardEnter)(editor, rawEvent, this.handleNormalEnter(editor));
162
178
  }
163
179
  break;
164
180
  default:
@@ -1 +1 @@
1
- {"version":3,"file":"EditPlugin.js","sourceRoot":"","sources":["../../../../packages/roosterjs-content-model-plugins/lib/edit/EditPlugin.ts"],"names":[],"mappings":";;;;IA6BA,IAAM,aAAa,GAAG,CAAC,CAAC;IACxB,IAAM,UAAU,GAAG,EAAE,CAAC;IACtB;;;;;OAKG;IACH,IAAM,QAAQ,GAAG,GAAG,CAAC;IAErB,IAAM,cAAc,GAAyB;QACzC,YAAY,EAAE,IAAI;QAClB,+BAA+B,EAAE,IAAI;KACxC,CAAC;IAEF;;;;;;OAMG;IACH;QAOI;;;WAGG;QACH,oBAAoB,OAAqC;YAArC,wBAAA,EAAA,wBAAqC;YAArC,YAAO,GAAP,OAAO,CAA8B;YAVjD,WAAM,GAAmB,IAAI,CAAC;YAC9B,aAAQ,GAAwB,IAAI,CAAC;YACrC,+BAA0B,GAAG,KAAK,CAAC;YACnC,yBAAoB,GAAwB,IAAI,CAAC;YACjD,sBAAiB,GAAG,KAAK,CAAC;QAM0B,CAAC;QAE7D;;WAEG;QACH,4BAAO,GAAP;YACI,OAAO,MAAM,CAAC;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QAAe;YAC3D,gFAAgF;YAChF,uGAAuG;YACvG,IACI,CAAC,IAAI,CAAC,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,EACF,IAAI,CAAC,OAAO,CAAC,+BAA+B,CAC/C,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,EACF,IAAI,CAAC,OAAO,CAAC,+BAA+B,CAC/C,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,AApND,IAoNC;IApNY,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 /**\n * Whether expanded selection within a text node should be handled by CM when pressing Backspace/Delete key.\n * @default true\n */\n handleExpandedSelectionOnDelete?: boolean;\n};\n\nconst BACKSPACE_KEY = 8;\nconst DELETE_KEY = 46;\n/**\n * According to https://lists.w3.org/Archives/Public/www-dom/2010JulSep/att-0182/keyCode-spec.html\n * 229 can be sent in variants generated when Long press (iOS) or using IM.\n *\n * Other cases: https://stackoverflow.com/questions/25043934/is-it-ok-to-ignore-keydown-events-with-keycode-229\n */\nconst DEAD_KEY = 229;\n\nconst DefaultOptions: Partial<EditOptions> = {\n handleTabKey: true,\n handleExpandedSelectionOnDelete: 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 const hasCtrlOrMetaKey = rawEvent.ctrlKey || rawEvent.metaKey;\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, this.options.handleExpandedSelectionOnDelete);\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(\n editor,\n rawEvent,\n this.options.handleExpandedSelectionOnDelete\n );\n }\n break;\n\n case 'Tab':\n if (this.options.handleTabKey && !hasCtrlOrMetaKey) {\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 if (\n !hasCtrlOrMetaKey &&\n !event.rawEvent.isComposing &&\n event.rawEvent.keyCode !== DEAD_KEY\n ) {\n keyboardEnter(editor, rawEvent, this.handleNormalEnter);\n }\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 this.options.handleExpandedSelectionOnDelete\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 this.options.handleExpandedSelectionOnDelete\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":";;;;IAqCA,IAAM,aAAa,GAAG,CAAC,CAAC;IACxB,IAAM,UAAU,GAAG,EAAE,CAAC;IACtB;;;;;OAKG;IACH,IAAM,QAAQ,GAAG,GAAG,CAAC;IAErB,IAAM,cAAc,GAAyB;QACzC,YAAY,EAAE,IAAI;QAClB,+BAA+B,EAAE,IAAI;KACxC,CAAC;IAEF;;;;;;OAMG;IACH;QAOI;;;WAGG;QACH,oBAAoB,OAAqC;YAArC,wBAAA,EAAA,wBAAqC;YAArC,YAAO,GAAP,OAAO,CAA8B;YAVjD,WAAM,GAAmB,IAAI,CAAC;YAC9B,aAAQ,GAAwB,IAAI,CAAC;YACrC,+BAA0B,GAAG,KAAK,CAAC;YACnC,yBAAoB,GAAwB,IAAI,CAAC;YACjD,sBAAiB,GAAiC,UAAC,MAAe,IAAK,OAAA,KAAK,EAAL,CAAK,CAAC;QAMzB,CAAC;QAErD,6CAAwB,GAAhC,UAAiC,MAAe;YAC5C,OAAO,MAAM,CAAC,CAAC,CAAC,cAAM,OAAA,IAAI,EAAJ,CAAI,CAAC,CAAC,CAAC,cAAM,OAAA,KAAK,EAAL,CAAK,CAAC;QAC7C,CAAC;QAEO,yCAAoB,GAA5B,UAA6B,MAAe;YACxC,QAAQ,OAAO,IAAI,CAAC,OAAO,CAAC,oBAAoB,EAAE;gBAC9C,KAAK,UAAU;oBACX,OAAO,IAAI,CAAC,OAAO,CAAC,oBAAoB,CAAC;oBACzC,MAAM;gBACV,KAAK,SA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C;aACxD;QACL,CAAC;QACL,iBAAC;IAAD,CAAC,AAxOD,IAwOC;IAxOY,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 /**\n * Whether expanded selection within a text node should be handled by CM when pressing Backspace/Delete key.\n * @default true\n */\n handleExpandedSelectionOnDelete?: boolean;\n\n /**\n * Callback function to determine whether the Rooster should handle the Enter key press.\n * If the function returns true, the Rooster will handle the Enter key press instead of the browser.\n * @param editor - The editor instance.\n * @returns A boolean\n */\n shouldHandleEnterKey?: ((editor: IEditor) => boolean) | boolean;\n};\n\nconst BACKSPACE_KEY = 8;\nconst DELETE_KEY = 46;\n/**\n * According to https://lists.w3.org/Archives/Public/www-dom/2010JulSep/att-0182/keyCode-spec.html\n * 229 can be sent in variants generated when Long press (iOS) or using IM.\n *\n * Other cases: https://stackoverflow.com/questions/25043934/is-it-ok-to-ignore-keydown-events-with-keycode-229\n */\nconst DEAD_KEY = 229;\n\nconst DefaultOptions: Partial<EditOptions> = {\n handleTabKey: true,\n handleExpandedSelectionOnDelete: 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: (editor: IEditor) => boolean = (editor: IEditor) => 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 private createNormalEnterChecker(result: boolean) {\n return result ? () => true : () => false;\n }\n\n private getHandleNormalEnter(editor: IEditor) {\n switch (typeof this.options.shouldHandleEnterKey) {\n case 'function':\n return this.options.shouldHandleEnterKey;\n break;\n case 'boolean':\n return this.createNormalEnterChecker(this.options.shouldHandleEnterKey);\n break;\n default:\n return this.createNormalEnterChecker(\n editor.isExperimentalFeatureEnabled('HandleEnterKey')\n );\n break;\n }\n }\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.getHandleNormalEnter(editor);\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 const hasCtrlOrMetaKey = rawEvent.ctrlKey || rawEvent.metaKey;\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, this.options.handleExpandedSelectionOnDelete);\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(\n editor,\n rawEvent,\n this.options.handleExpandedSelectionOnDelete\n );\n }\n break;\n\n case 'Tab':\n if (this.options.handleTabKey && !hasCtrlOrMetaKey) {\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 if (\n !hasCtrlOrMetaKey &&\n !event.rawEvent.isComposing &&\n event.rawEvent.keyCode !== DEAD_KEY\n ) {\n keyboardEnter(editor, rawEvent, this.handleNormalEnter(editor));\n }\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 this.options.handleExpandedSelectionOnDelete\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 this.options.handleExpandedSelectionOnDelete\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,9 +1,10 @@
1
- import type { InsertPoint, ShallowMutableContentModelParagraph } from 'roosterjs-content-model-types';
1
+ import type { ContentModelBlockFormat, InsertPoint, ShallowMutableContentModelParagraph } from 'roosterjs-content-model-types';
2
2
  /**
3
3
  * @internal
4
4
  * Split the given paragraph from insert point into two paragraphs,
5
5
  * and move the selection marker to the beginning of the second paragraph
6
6
  * @param insertPoint The input insert point which includes the paragraph and selection marker
7
+ * @param formatKeys The format that needs to be copied from the splitted paragraph, if not specified, some default format will be copied
7
8
  * @returns The new paragraph it created
8
9
  */
9
- export declare function splitParagraph(insertPoint: InsertPoint): ShallowMutableContentModelParagraph;
10
+ export declare function splitParagraph(insertPoint: InsertPoint, formatKeys?: Partial<keyof ContentModelBlockFormat>[]): ShallowMutableContentModelParagraph;
@@ -2,17 +2,36 @@ define(["require", "exports", "tslib", "roosterjs-content-model-dom"], function
2
2
  "use strict";
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.splitParagraph = void 0;
5
+ var DEFAULT_FORMAT_KEYS = [
6
+ 'backgroundColor',
7
+ 'direction',
8
+ 'textAlign',
9
+ 'htmlAlign',
10
+ 'lineHeight',
11
+ 'textIndent',
12
+ 'marginTop',
13
+ 'marginRight',
14
+ 'marginBottom',
15
+ 'marginLeft',
16
+ 'paddingTop',
17
+ 'paddingRight',
18
+ 'paddingBottom',
19
+ 'paddingLeft',
20
+ ];
5
21
  /**
6
22
  * @internal
7
23
  * Split the given paragraph from insert point into two paragraphs,
8
24
  * and move the selection marker to the beginning of the second paragraph
9
25
  * @param insertPoint The input insert point which includes the paragraph and selection marker
26
+ * @param formatKeys The format that needs to be copied from the splitted paragraph, if not specified, some default format will be copied
10
27
  * @returns The new paragraph it created
11
28
  */
12
- function splitParagraph(insertPoint) {
29
+ function splitParagraph(insertPoint, formatKeys) {
13
30
  var _a;
31
+ if (formatKeys === void 0) { formatKeys = DEFAULT_FORMAT_KEYS; }
14
32
  var paragraph = insertPoint.paragraph, marker = insertPoint.marker;
15
- var newParagraph = (0, roosterjs_content_model_dom_1.createParagraph)(false /*isImplicit*/, paragraph.format, paragraph.segmentFormat);
33
+ var newFormat = createNewFormat(paragraph.format, formatKeys);
34
+ var newParagraph = (0, roosterjs_content_model_dom_1.createParagraph)(false /*isImplicit*/, newFormat, paragraph.segmentFormat);
16
35
  var markerIndex = paragraph.segments.indexOf(marker);
17
36
  var segments = paragraph.segments.splice(markerIndex, paragraph.segments.length - markerIndex);
18
37
  if (paragraph.segments.length == 0) {
@@ -25,5 +44,25 @@ define(["require", "exports", "tslib", "roosterjs-content-model-dom"], function
25
44
  return newParagraph;
26
45
  }
27
46
  exports.splitParagraph = splitParagraph;
47
+ var createNewFormat = function (format, formatKeys) {
48
+ var e_1, _a, _b;
49
+ var newFormat = {};
50
+ try {
51
+ for (var formatKeys_1 = (0, tslib_1.__values)(formatKeys), formatKeys_1_1 = formatKeys_1.next(); !formatKeys_1_1.done; formatKeys_1_1 = formatKeys_1.next()) {
52
+ var key = formatKeys_1_1.value;
53
+ if (format[key]) {
54
+ newFormat = (0, tslib_1.__assign)((0, tslib_1.__assign)({}, newFormat), (_b = {}, _b[key] = format[key], _b));
55
+ }
56
+ }
57
+ }
58
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
59
+ finally {
60
+ try {
61
+ if (formatKeys_1_1 && !formatKeys_1_1.done && (_a = formatKeys_1.return)) _a.call(formatKeys_1);
62
+ }
63
+ finally { if (e_1) throw e_1.error; }
64
+ }
65
+ return newFormat;
66
+ };
28
67
  });
29
68
  //# sourceMappingURL=splitParagraph.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"splitParagraph.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-plugins/lib/edit/utils/splitParagraph.ts"],"names":[],"mappings":";;;;IAWA;;;;;;OAMG;IACH,SAAgB,cAAc,CAAC,WAAwB;;QAC3C,IAAA,SAAS,GAAa,WAAW,UAAxB,EAAE,MAAM,GAAK,WAAW,OAAhB,CAAiB;QAC1C,IAAM,YAAY,GAAwC,IAAA,6CAAe,EACrE,KAAK,CAAC,cAAc,EACpB,SAAS,CAAC,MAAM,EAChB,SAAS,CAAC,aAAa,CAC1B,CAAC;QAEF,IAAM,WAAW,GAAG,SAAS,CAAC,QAAQ,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;QACvD,IAAM,QAAQ,GAAG,SAAS,CAAC,QAAQ,CAAC,MAAM,CACtC,WAAW,EACX,SAAS,CAAC,QAAQ,CAAC,MAAM,GAAG,WAAW,CAC1C,CAAC;QAEF,IAAI,SAAS,CAAC,QAAQ,CAAC,MAAM,IAAI,CAAC,EAAE;YAChC,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAA,sCAAQ,EAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC;SACpD;QAED,CAAA,KAAA,YAAY,CAAC,QAAQ,CAAA,CAAC,IAAI,8DAAI,QAAQ,WAAE;QAExC,IAAA,qDAAuB,EAAC,SAAS,CAAC,CAAC;QAEnC,WAAW,CAAC,SAAS,GAAG,YAAY,CAAC;QAErC,IAAA,gDAAkB,EAAC,SAAS,CAAC,CAAC;QAE9B,OAAO,YAAY,CAAC;IACxB,CAAC;IA3BD,wCA2BC","sourcesContent":["import {\n createBr,\n createParagraph,\n normalizeParagraph,\n setParagraphNotImplicit,\n} from 'roosterjs-content-model-dom';\nimport type {\n InsertPoint,\n ShallowMutableContentModelParagraph,\n} from 'roosterjs-content-model-types';\n\n/**\n * @internal\n * Split the given paragraph from insert point into two paragraphs,\n * and move the selection marker to the beginning of the second paragraph\n * @param insertPoint The input insert point which includes the paragraph and selection marker\n * @returns The new paragraph it created\n */\nexport function splitParagraph(insertPoint: InsertPoint) {\n const { paragraph, marker } = insertPoint;\n const newParagraph: ShallowMutableContentModelParagraph = createParagraph(\n false /*isImplicit*/,\n paragraph.format,\n paragraph.segmentFormat\n );\n\n const markerIndex = paragraph.segments.indexOf(marker);\n const segments = paragraph.segments.splice(\n markerIndex,\n paragraph.segments.length - markerIndex\n );\n\n if (paragraph.segments.length == 0) {\n paragraph.segments.push(createBr(marker.format));\n }\n\n newParagraph.segments.push(...segments);\n\n setParagraphNotImplicit(paragraph);\n\n insertPoint.paragraph = newParagraph;\n\n normalizeParagraph(paragraph);\n\n return newParagraph;\n}\n"]}
1
+ {"version":3,"file":"splitParagraph.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-plugins/lib/edit/utils/splitParagraph.ts"],"names":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G,UACpB,MAA+B,EAC/B,UAAoD;;QAEpD,IAAI,SAAS,GAA4B,EAAE,CAAC;;YAC5C,KAAkB,IAAA,eAAA,sBAAA,UAAU,CAAA,sCAAA,8DAAE;gBAAzB,IAAM,GAAG,uBAAA;gBACV,IAAI,MAAM,CAAC,GAAG,CAAC,EAAE;oBACb,SAAS,mDACF,SAAS,gBACX,GAAG,IAAG,MAAM,CAAC,GAAG,CAAC,MACrB,CAAC;iBACL;aACJ;;;;;;;;;QACD,OAAO,SAAS,CAAC;IACrB,CAAC,CAAC","sourcesContent":["import {\n createBr,\n createParagraph,\n normalizeParagraph,\n setParagraphNotImplicit,\n} from 'roosterjs-content-model-dom';\nimport type {\n ContentModelBlockFormat,\n InsertPoint,\n ShallowMutableContentModelParagraph,\n} from 'roosterjs-content-model-types';\n\nconst DEFAULT_FORMAT_KEYS: Partial<keyof ContentModelBlockFormat>[] = [\n 'backgroundColor',\n 'direction',\n 'textAlign',\n 'htmlAlign',\n 'lineHeight',\n 'textIndent',\n 'marginTop',\n 'marginRight',\n 'marginBottom',\n 'marginLeft',\n 'paddingTop',\n 'paddingRight',\n 'paddingBottom',\n 'paddingLeft',\n];\n\n/**\n * @internal\n * Split the given paragraph from insert point into two paragraphs,\n * and move the selection marker to the beginning of the second paragraph\n * @param insertPoint The input insert point which includes the paragraph and selection marker\n * @param formatKeys The format that needs to be copied from the splitted paragraph, if not specified, some default format will be copied\n * @returns The new paragraph it created\n */\nexport function splitParagraph(\n insertPoint: InsertPoint,\n formatKeys: Partial<keyof ContentModelBlockFormat>[] = DEFAULT_FORMAT_KEYS\n) {\n const { paragraph, marker } = insertPoint;\n const newFormat = createNewFormat(paragraph.format, formatKeys);\n const newParagraph: ShallowMutableContentModelParagraph = createParagraph(\n false /*isImplicit*/,\n newFormat,\n paragraph.segmentFormat\n );\n\n const markerIndex = paragraph.segments.indexOf(marker);\n const segments = paragraph.segments.splice(\n markerIndex,\n paragraph.segments.length - markerIndex\n );\n\n if (paragraph.segments.length == 0) {\n paragraph.segments.push(createBr(marker.format));\n }\n\n newParagraph.segments.push(...segments);\n\n setParagraphNotImplicit(paragraph);\n\n insertPoint.paragraph = newParagraph;\n\n normalizeParagraph(paragraph);\n\n return newParagraph;\n}\n\nconst createNewFormat = (\n format: ContentModelBlockFormat,\n formatKeys: Partial<keyof ContentModelBlockFormat>[]\n) => {\n let newFormat: ContentModelBlockFormat = {};\n for (const key of formatKeys) {\n if (format[key]) {\n newFormat = {\n ...newFormat,\n [key]: format[key],\n };\n }\n }\n return newFormat;\n};\n"]}
@@ -135,9 +135,6 @@ define(["require", "exports", "tslib", "./utils/applyChange", "./utils/canRegene
135
135
  ImageEditPlugin.prototype.removeImageEditing = function (clonedRoot) {
136
136
  var images = clonedRoot.querySelectorAll('img');
137
137
  images.forEach(function (image) {
138
- if (image.dataset.isEditing) {
139
- delete image.dataset.isEditing;
140
- }
141
138
  if (image.dataset.editingInfo) {
142
139
  delete image.dataset.editingInfo;
143
140
  }
@@ -208,8 +205,11 @@ define(["require", "exports", "tslib", "./utils/applyChange", "./utils/canRegene
208
205
  };
209
206
  ImageEditPlugin.prototype.setContentHandler = function (editor) {
210
207
  var selection = editor.getDOMSelection();
211
- if ((selection === null || selection === void 0 ? void 0 : selection.type) == 'image' && selection.image.dataset.isEditing && !this.isEditing) {
212
- delete selection.image.dataset.isEditing;
208
+ if ((selection === null || selection === void 0 ? void 0 : selection.type) == 'image') {
209
+ this.cleanInfo();
210
+ (0, roosterjs_content_model_dom_1.setImageState)(selection.image, '');
211
+ this.isEditing = false;
212
+ this.isCropMode = false;
213
213
  }
214
214
  };
215
215
  ImageEditPlugin.prototype.formatEventHandler = function (event) {
@@ -247,7 +247,7 @@ define(["require", "exports", "tslib", "./utils/applyChange", "./utils/canRegene
247
247
  var result = false;
248
248
  if (shouldSelectImage ||
249
249
  (previousSelectedImage === null || previousSelectedImage === void 0 ? void 0 : previousSelectedImage.image) != (editingImage === null || editingImage === void 0 ? void 0 : editingImage.image) ||
250
- (previousSelectedImage === null || previousSelectedImage === void 0 ? void 0 : previousSelectedImage.image.dataset.isEditing) ||
250
+ (previousSelectedImage === null || previousSelectedImage === void 0 ? void 0 : previousSelectedImage.image.format.imageState) == findEditingImage_1.EDITING_MARKER ||
251
251
  isApiOperation) {
252
252
  var _a = _this, lastSrc_1 = _a.lastSrc, selectedImage_1 = _a.selectedImage, imageEditInfo_1 = _a.imageEditInfo, clonedImage_1 = _a.clonedImage;
253
253
  if ((_this.isEditing || isApiOperation) &&
@@ -260,7 +260,7 @@ define(["require", "exports", "tslib", "./utils/applyChange", "./utils/canRegene
260
260
  (0, applyChange_1.applyChange)(editor, selectedImage_1, image, imageEditInfo_1, lastSrc_1, _this.wasImageResized || _this.isCropMode, clonedImage_1);
261
261
  image.isSelected = shouldSelectImage;
262
262
  image.isSelectedAsImageSelection = shouldSelectImage;
263
- delete image.dataset.isEditing;
263
+ image.format.imageState = undefined;
264
264
  if ((selection === null || selection === void 0 ? void 0 : selection.type) == 'range' && !selection.range.collapsed) {
265
265
  var selectedParagraphs = (0, roosterjs_content_model_dom_1.getSelectedParagraphs)(model, true);
266
266
  var isImageInRange = selectedParagraphs.some(function (paragraph) {
@@ -288,7 +288,7 @@ define(["require", "exports", "tslib", "./utils/applyChange", "./utils/canRegene
288
288
  (0, roosterjs_content_model_dom_1.mutateSegment)(editingImage.paragraph, editingImage.image, function (image) {
289
289
  editingImageModel = image;
290
290
  _this.imageEditInfo = (0, updateImageEditInfo_1.updateImageEditInfo)(image, selection.image);
291
- image.dataset.isEditing = 'true';
291
+ image.format.imageState = 'isEditing';
292
292
  });
293
293
  result = true;
294
294
  }
@@ -299,7 +299,7 @@ define(["require", "exports", "tslib", "./utils/applyChange", "./utils/canRegene
299
299
  if (!isApiOperation &&
300
300
  editingImageModel &&
301
301
  editingImageModel == model &&
302
- editingImageModel.dataset.isEditing &&
302
+ editingImageModel.format.imageState == findEditingImage_1.EDITING_MARKER &&
303
303
  (0, roosterjs_content_model_dom_1.isNodeOfType)(node, 'ELEMENT_NODE') &&
304
304
  (0, roosterjs_content_model_dom_1.isElementOfType)(node, 'img')) {
305
305
  if (isCropMode) {
@@ -1 +1 @@
1
- {"version":3,"file":"ImageEditPlugin.js","sourceRoot":"","sources":["../../../../packages/roosterjs-content-model-plugins/lib/imageEdit/ImageEditPlugin.ts"],"names":[],"mappings":";;;;IA4CA,IAAM,cAAc,GAA8B;QAC9C,WAAW,EAAE,SAAS;QACtB,QAAQ,EAAE,EAAE;QACZ,SAAS,EAAE,EAAE;QACb,aAAa,EAAE,IAAI;QACnB,aAAa,EAAE,KAAK;QACpB,iBAAiB,EAAE,KAAK;QACxB,aAAa,EAAE,CAAC,QAAQ,EAAE,QAAQ,CAAC;KACtC,CAAC;IAEF,IAAM,gBAAgB,GAAG,CAAC,CAAC;IAC3B,IAAM,OAAO,GAAG,WAAW,CAAC;IAC5B,IAAM,gBAAgB,GAAG,WAAW,CAAC;IACrC,IAAM,sBAAsB,GAAG,qBAAqB,CAAC;IACrD,IAAM,uBAAuB,GAAG,gBAAgB,CAAC;IAEjD;;;;;;OAMG;IACH;QAmBI,yBAAsB,OAA0C;YAA1C,wBAAA,EAAA,wBAA0C;YAA1C,YAAO,GAAP,OAAO,CAAmC;YAlBtD,WAAM,GAAmB,IAAI,CAAC;YAChC,eAAU,GAA2B,IAAI,CAAC;YAC1C,kBAAa,GAA4B,IAAI,CAAC;YAC5C,YAAO,GAA2B,IAAI,CAAC;YACvC,kBAAa,GAA+B,IAAI,CAAC;YACnD,qBAAgB,GAA4B,IAAI,CAAC;YACjD,eAAU,GAAiD,EAAE,CAAC;YAC9D,gBAAW,GAA4B,IAAI,CAAC;YAC5C,YAAO,GAAkB,IAAI,CAAC;YAC9B,oBAAe,GAAY,KAAK,CAAC;YACjC,eAAU,GAAY,KAAK,CAAC;YAC5B,aAAQ,GAAqB,EAAE,CAAC;YAChC,aAAQ,GAAqB,EAAE,CAAC;YAChC,aAAQ,GAAqB,EAAE,CAAC;YAChC,c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esContent":["import { applyChange } from './utils/applyChange';\nimport { canRegenerateImage } from './utils/canRegenerateImage';\nimport { checkIfImageWasResized, isASmallImage } from './utils/imageEditUtils';\nimport { createImageWrapper } from './utils/createImageWrapper';\nimport { Cropper } from './Cropper/cropperContext';\nimport { findEditingImage } from './utils/findEditingImage';\nimport { getDropAndDragHelpers } from './utils/getDropAndDragHelpers';\nimport { getHTMLImageOptions } from './utils/getHTMLImageOptions';\nimport { getSelectedImage } from './utils/getSelectedImage';\nimport { getSelectedImageMetadata, updateImageEditInfo } from './utils/updateImageEditInfo';\nimport { ImageEditElementClass } from './types/ImageEditElementClass';\nimport { normalizeImageSelection } from './utils/normalizeImageSelection';\nimport { Resizer } from './Resizer/resizerContext';\nimport { Rotator } from './Rotator/rotatorContext';\nimport { updateRotateHandle } from './Rotator/updateRotateHandle';\nimport { updateWrapper } from './utils/updateWrapper';\nimport {\n ChangeSource,\n getSafeIdSelector,\n getSelectedParagraphs,\n isElementOfType,\n isNodeOfType,\n mutateBlock,\n mutateSegment,\n unwrap,\n} from 'roosterjs-content-model-dom';\nimport type { DragAndDropHelper } from '../pluginUtils/DragAndDrop/DragAndDropHelper';\nimport type { DragAndDropContext } from './types/DragAndDropContext';\nimport type { ImageHtmlOptions } from './types/ImageHtmlOptions';\nimport type { ImageEditOptions } from './types/ImageEditOptions';\nimport type {\n ContentChangedEvent,\n ContentModelImage,\n EditorPlugin,\n IEditor,\n ImageEditOperation,\n ImageEditor,\n ImageMetadataFormat,\n KeyDownEvent,\n MouseDownEvent,\n MouseUpEvent,\n PluginEvent,\n} from 'roosterjs-content-model-types';\n\nconst DefaultOptions: Partial<ImageEditOptions> = {\n borderColor: '#DB626C',\n minWidth: 10,\n minHeight: 10,\n preserveRatio: true,\n disableRotate: false,\n disableSideResize: false,\n onSelectState: ['resize', 'rotate'],\n};\n\nconst MouseRightButton = 2;\nconst DRAG_ID = '_dragging';\nconst IMAGE_EDIT_CLASS = 'imageEdit';\nconst IMAGE_EDIT_CLASS_CARET = 'imageEditCaretColor';\nconst IMAGE_EDIT_FORMAT_EVENT = 'ImageEditEvent';\n\n/**\n * ImageEdit plugin handles the following image editing features:\n * - Resize image\n * - Crop image\n * - Rotate image\n * - Flip image\n */\nexport class ImageEditPlugin implements ImageEditor, EditorPlugin {\n protected editor: IEditor | null = null;\n private shadowSpan: HTMLSpanElement | null = null;\n private selectedImage: HTMLImageElement | null = null;\n protected wrapper: HTMLSpanElement | null = null;\n protected imageEditInfo: ImageMetadataFormat | null = null;\n private imageHTMLOptions: ImageHtmlOptions | null = null;\n private dndHelpers: DragAndDropHelper<DragAndDropContext, any>[] = [];\n private clonedImage: HTMLImageElement | null = null;\n private lastSrc: string | null = null;\n private wasImageResized: boolean = false;\n private isCropMode: boolean = false;\n private resizers: HTMLDivElement[] = [];\n private rotators: HTMLDivElement[] = [];\n private croppers: HTMLDivElement[] = [];\n private zoomScale: number = 1;\n private disposer: (() => void) | null = null;\n protected isEditing = false;\n\n constructor(protected options: ImageEditOptions = DefaultOptions) {}\n\n /**\n * Get name of this plugin\n */\n getName() {\n return 'ImageEdit';\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.disposer = editor.attachDomEvent({\n blur: {\n beforeDispatch: () => {\n if (this.isEditing && this.editor && !this.editor.isDisposed()) {\n this.applyFormatWithContentModel(\n this.editor,\n this.isCropMode,\n true /* shouldSelectImage */\n );\n }\n },\n },\n dragstart: {\n beforeDispatch: ev => {\n if (this.editor) {\n const target = ev.target as Node;\n if (this.isImageSelection(target)) {\n target.id = target.id + DRAG_ID;\n }\n }\n },\n },\n dragend: {\n beforeDispatch: ev => {\n if (this.editor) {\n const target = ev.target as Node;\n if (this.isImageSelection(target) && target.id.includes(DRAG_ID)) {\n target.id = target.id.replace(DRAG_ID, '').trim();\n }\n }\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 if (this.disposer) {\n this.disposer();\n this.disposer = null;\n }\n this.isEditing = false;\n this.cleanInfo();\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 return;\n }\n switch (event.eventType) {\n case 'mouseDown':\n this.mouseDownHandler(this.editor, event);\n break;\n case 'mouseUp':\n this.mouseUpHandler(this.editor, event);\n break;\n case 'keyDown':\n this.keyDownHandler(this.editor, event);\n break;\n case 'contentChanged':\n this.contentChangedHandler(this.editor, event);\n break;\n case 'extractContentWithDom':\n this.removeImageEditing(event.clonedRoot);\n break;\n }\n }\n\n private removeImageEditing(clonedRoot: HTMLElement) {\n const images = clonedRoot.querySelectorAll('img');\n images.forEach(image => {\n if (image.dataset.isEditing) {\n delete image.dataset.isEditing;\n }\n if (image.dataset.editingInfo) {\n delete image.dataset.editingInfo;\n }\n });\n }\n\n private isImageSelection(target: Node): target is HTMLElement {\n return (\n isNodeOfType(target, 'ELEMENT_NODE') &&\n (isElementOfType(target, 'img') ||\n !!(\n isElementOfType(target, 'span') &&\n target.firstElementChild &&\n isNodeOfType(target.firstElementChild, 'ELEMENT_NODE') &&\n isElementOfType(target.firstElementChild, 'img')\n ))\n );\n }\n\n private mouseUpHandler(editor: IEditor, event: MouseUpEvent) {\n const selection = editor.getDOMSelection();\n if ((selection && selection.type == 'image') || this.isEditing) {\n const shouldSelectImage =\n this.isImageSelection(event.rawEvent.target as Node) &&\n event.rawEvent.button === MouseRightButton;\n this.applyFormatWithContentModel(editor, this.isCropMode, shouldSelectImage);\n }\n }\n\n private mouseDownHandler(editor: IEditor, event: MouseDownEvent) {\n if (\n this.isEditing &&\n this.isImageSelection(event.rawEvent.target as Node) &&\n event.rawEvent.button !== MouseRightButton &&\n !this.isCropMode\n ) {\n this.applyFormatWithContentModel(\n editor,\n this.isCropMode,\n this.shadowSpan === event.rawEvent.target\n );\n }\n }\n\n private onDropHandler(editor: IEditor) {\n const selection = editor.getDOMSelection();\n if (selection?.type == 'image') {\n editor.formatContentModel(model => {\n const imageDragged = findEditingImage(model, selection.image.id);\n const imageDropped = findEditingImage(\n model,\n selection.image.id.replace(DRAG_ID, '').trim()\n );\n if (imageDragged && imageDropped) {\n const draggedIndex = imageDragged.paragraph.segments.indexOf(\n imageDragged.image\n );\n mutateBlock(imageDragged.paragraph).segments.splice(draggedIndex, 1);\n const segment = imageDropped.image;\n const paragraph = imageDropped.paragraph;\n mutateSegment(paragraph, segment, image => {\n image.isSelected = true;\n image.isSelectedAsImageSelection = true;\n });\n\n return true;\n }\n return false;\n });\n }\n }\n\n private keyDownHandler(editor: IEditor, event: KeyDownEvent) {\n if (this.isEditing) {\n if (\n event.rawEvent.key === 'Escape' ||\n event.rawEvent.key === 'Delete' ||\n event.rawEvent.key === 'Backspace'\n ) {\n if (event.rawEvent.key === 'Escape') {\n this.removeImageWrapper();\n }\n this.cleanInfo();\n } else {\n if (event.rawEvent.key == 'Enter' && this.isCropMode) {\n event.rawEvent.preventDefault();\n }\n this.applyFormatWithContentModel(\n editor,\n this.isCropMode,\n true /** should selectImage */,\n false /* isApiOperation */\n );\n }\n }\n }\n\n private setContentHandler(editor: IEditor) {\n const selection = editor.getDOMSelection();\n if (selection?.type == 'image' && selection.image.dataset.isEditing && !this.isEditing) {\n delete selection.image.dataset.isEditing;\n }\n }\n\n private formatEventHandler(event: ContentChangedEvent) {\n if (this.isEditing && event.formatApiName !== IMAGE_EDIT_FORMAT_EVENT) {\n this.cleanInfo();\n this.isEditing = false;\n this.isCropMode = false;\n }\n }\n\n private contentChangedHandler(editor: IEditor, event: ContentChangedEvent) {\n switch (event.source) {\n case ChangeSource.SetContent:\n this.setContentHandler(editor);\n break;\n case ChangeSource.Format:\n this.formatEventHandler(event);\n break;\n case ChangeSource.Drop:\n this.onDropHandler(editor);\n break;\n }\n }\n\n /**\n * EXPOSED FOR TESTING PURPOSE ONLY\n */\n protected applyFormatWithContentModel(\n editor: IEditor,\n isCropMode: boolean,\n shouldSelectImage: boolean,\n isApiOperation?: boolean\n ) {\n let editingImageModel: ContentModelImage | undefined;\n const selection = editor.getDOMSelection();\n\n editor.formatContentModel(\n model => {\n const editingImage = getSelectedImage(model);\n const previousSelectedImage = isApiOperation\n ? editingImage\n : findEditingImage(model);\n let result = false;\n\n if (\n shouldSelectImage ||\n previousSelectedImage?.image != editingImage?.image ||\n previousSelectedImage?.image.dataset.isEditing ||\n isApiOperation\n ) {\n const { lastSrc, selectedImage, imageEditInfo, clonedImage } = this;\n if (\n (this.isEditing || isApiOperation) &&\n previousSelectedImage &&\n lastSrc &&\n selectedImage &&\n imageEditInfo &&\n clonedImage\n ) {\n mutateSegment(\n previousSelectedImage.paragraph,\n previousSelectedImage.image,\n image => {\n applyChange(\n editor,\n selectedImage,\n image,\n imageEditInfo,\n lastSrc,\n this.wasImageResized || this.isCropMode,\n clonedImage\n );\n\n image.isSelected = shouldSelectImage;\n image.isSelectedAsImageSelection = shouldSelectImage;\n delete image.dataset.isEditing;\n\n if (selection?.type == 'range' && !selection.range.collapsed) {\n const selectedParagraphs = getSelectedParagraphs(model, true);\n const isImageInRange = selectedParagraphs.some(paragraph =>\n paragraph.segments.includes(image)\n );\n if (isImageInRange) {\n image.isSelected = true;\n }\n }\n }\n );\n\n if (shouldSelectImage) {\n normalizeImageSelection(previousSelectedImage);\n }\n\n this.cleanInfo();\n result = true;\n }\n\n this.isEditing = false;\n this.isCropMode = false;\n\n if (\n editingImage &&\n selection?.type == 'image' &&\n !shouldSelectImage &&\n !isApiOperation\n ) {\n this.isEditing = true;\n this.isCropMode = isCropMode;\n mutateSegment(editingImage.paragraph, editingImage.image, image => {\n editingImageModel = image;\n this.imageEditInfo = updateImageEditInfo(image, selection.image);\n image.dataset.isEditing = 'true';\n });\n\n result = true;\n }\n }\n\n return result;\n },\n {\n onNodeCreated: (model, node) => {\n if (\n !isApiOperation &&\n editingImageModel &&\n editingImageModel == model &&\n editingImageModel.dataset.isEditing &&\n isNodeOfType(node, 'ELEMENT_NODE') &&\n isElementOfType(node, 'img')\n ) {\n if (isCropMode) {\n this.startCropMode(editor, node);\n } else {\n this.startRotateAndResize(editor, node);\n }\n }\n },\n apiName: IMAGE_EDIT_FORMAT_EVENT,\n },\n {\n tryGetFromCache: true,\n }\n );\n }\n\n private startEditing(\n editor: IEditor,\n image: HTMLImageElement,\n apiOperation: ImageEditOperation[]\n ) {\n if (!this.imageEditInfo) {\n this.imageEditInfo = getSelectedImageMetadata(editor, image);\n }\n this.lastSrc = image.getAttribute('src');\n this.imageHTMLOptions = getHTMLImageOptions(editor, this.options, this.imageEditInfo);\n const {\n resizers,\n rotators,\n wrapper,\n shadowSpan,\n imageClone,\n croppers,\n } = createImageWrapper(\n editor,\n image,\n this.options,\n this.imageEditInfo,\n this.imageHTMLOptions,\n apiOperation\n );\n this.shadowSpan = shadowSpan;\n this.selectedImage = image;\n this.wrapper = wrapper;\n this.clonedImage = imageClone;\n this.wasImageResized = checkIfImageWasResized(image);\n this.resizers = resizers;\n this.rotators = rotators;\n this.croppers = croppers;\n this.zoomScale = editor.getDOMHelper().calculateZoomScale();\n\n editor.setEditorStyle(IMAGE_EDIT_CLASS, `outline-style:none!important;`, [\n `span:has(>img${getSafeIdSelector(this.selectedImage.id)})`,\n ]);\n\n editor.setEditorStyle(IMAGE_EDIT_CLASS_CARET, `caret-color: transparent;`);\n }\n\n public startRotateAndResize(editor: IEditor, image: HTMLImageElement) {\n if (this.imageEditInfo) {\n this.startEditing(editor, image, ['resize', 'rotate']);\n if (this.selectedImage && this.imageEditInfo && this.wrapper && this.clonedImage) {\n const isMobileOrTable = !!editor.getEnvironment().isMobileOrTablet;\n this.dndHelpers = [\n ...getDropAndDragHelpers(\n this.wrapper,\n this.imageEditInfo,\n this.options,\n ImageEditElementClass.ResizeHandle,\n Resizer,\n () => {\n if (\n this.imageEditInfo &&\n this.selectedImage &&\n this.wrapper &&\n this.clonedImage\n ) {\n updateWrapper(\n this.imageEditInfo,\n this.options,\n this.selectedImage,\n this.clonedImage,\n this.wrapper,\n this.resizers\n );\n this.wasImageResized = true;\n }\n },\n this.zoomScale,\n isMobileOrTable\n ),\n ...getDropAndDragHelpers(\n this.wrapper,\n this.imageEditInfo,\n this.options,\n ImageEditElementClass.RotateHandle,\n Rotator,\n () => {\n if (\n this.imageEditInfo &&\n this.selectedImage &&\n this.wrapper &&\n this.clonedImage\n ) {\n updateWrapper(\n this.imageEditInfo,\n this.options,\n this.selectedImage,\n this.clonedImage,\n this.wrapper\n );\n this.updateRotateHandleState(\n editor,\n this.selectedImage,\n this.wrapper,\n this.rotators,\n this.imageEditInfo?.angleRad\n );\n }\n },\n this.zoomScale,\n isMobileOrTable\n ),\n ];\n\n updateWrapper(\n this.imageEditInfo,\n this.options,\n this.selectedImage,\n this.clonedImage,\n this.wrapper,\n this.resizers\n );\n\n this.updateRotateHandleState(\n editor,\n this.selectedImage,\n this.wrapper,\n this.rotators,\n this.imageEditInfo?.angleRad\n );\n }\n }\n }\n\n private updateRotateHandleState(\n editor: IEditor,\n image: HTMLImageElement,\n wrapper: HTMLSpanElement,\n rotators: HTMLDivElement[],\n angleRad: number | undefined\n ) {\n const viewport = editor.getVisibleViewport();\n const smallImage = isASmallImage(image.width, image.height);\n if (viewport && rotators && rotators.length > 0) {\n const rotator = rotators[0];\n const rotatorHandle = rotator.firstElementChild;\n if (\n isNodeOfType(rotatorHandle, 'ELEMENT_NODE') &&\n isElementOfType(rotatorHandle, 'div')\n ) {\n updateRotateHandle(\n viewport,\n angleRad ?? 0,\n wrapper,\n rotator,\n rotatorHandle,\n smallImage\n );\n }\n }\n }\n\n public isOperationAllowed(operation: ImageEditOperation): boolean {\n return (\n operation === 'resize' ||\n operation === 'rotate' ||\n operation === 'flip' ||\n operation === 'crop'\n );\n }\n\n public canRegenerateImage(image: HTMLImageElement): boolean {\n return canRegenerateImage(image);\n }\n\n private startCropMode(editor: IEditor, image: HTMLImageElement) {\n if (this.imageEditInfo) {\n this.startEditing(editor, image, ['crop']);\n if (this.imageEditInfo && this.selectedImage && this.wrapper && this.clonedImage) {\n this.dndHelpers = [\n ...getDropAndDragHelpers(\n this.wrapper,\n this.imageEditInfo,\n this.options,\n ImageEditElementClass.CropHandle,\n Cropper,\n () => {\n if (\n this.imageEditInfo &&\n this.selectedImage &&\n this.wrapper &&\n this.clonedImage\n ) {\n updateWrapper(\n this.imageEditInfo,\n this.options,\n this.selectedImage,\n this.clonedImage,\n this.wrapper,\n undefined,\n this.croppers\n );\n this.isCropMode = true;\n }\n },\n this.zoomScale,\n !!editor.getEnvironment().isMobileOrTablet\n ),\n ];\n updateWrapper(\n this.imageEditInfo,\n this.options,\n this.selectedImage,\n this.clonedImage,\n this.wrapper,\n undefined,\n this.croppers\n );\n }\n }\n }\n\n public cropImage() {\n if (!this.editor) {\n return;\n }\n if (!this.editor.getEnvironment().isSafari) {\n this.editor.focus(); // Safari will keep the selection when click crop, then the focus() call should not be called\n }\n const selection = this.editor.getDOMSelection();\n if (selection?.type == 'image') {\n this.applyFormatWithContentModel(\n this.editor,\n true /* isCropMode */,\n false /* shouldSelectImage */\n );\n }\n }\n\n private editImage(\n editor: IEditor,\n image: HTMLImageElement,\n apiOperation: ImageEditOperation[],\n operation: (imageEditInfo: ImageMetadataFormat) => void\n ) {\n this.startEditing(editor, image, apiOperation);\n if (!this.selectedImage || !this.imageEditInfo || !this.wrapper || !this.clonedImage) {\n return;\n }\n\n operation(this.imageEditInfo);\n\n updateWrapper(\n this.imageEditInfo,\n this.options,\n this.selectedImage,\n this.clonedImage,\n this.wrapper\n );\n\n this.applyFormatWithContentModel(\n editor,\n false /* isCrop */,\n true /* shouldSelect*/,\n true /* isApiOperation */\n );\n }\n\n /**\n * Exported for testing purpose only\n */\n public cleanInfo() {\n this.editor?.setEditorStyle(IMAGE_EDIT_CLASS, null);\n this.editor?.setEditorStyle(IMAGE_EDIT_CLASS_CARET, null);\n this.selectedImage = null;\n this.shadowSpan = null;\n this.wrapper = null;\n this.imageEditInfo = null;\n this.imageHTMLOptions = null;\n this.dndHelpers.forEach(helper => helper.dispose());\n this.dndHelpers = [];\n this.clonedImage = null;\n this.lastSrc = null;\n this.wasImageResized = false;\n this.isCropMode = false;\n this.resizers = [];\n this.rotators = [];\n this.croppers = [];\n }\n\n private removeImageWrapper() {\n let image: HTMLImageElement | null = null;\n if (this.shadowSpan && this.shadowSpan.parentElement) {\n if (\n this.shadowSpan.firstElementChild &&\n isNodeOfType(this.shadowSpan.firstElementChild, 'ELEMENT_NODE') &&\n isElementOfType(this.shadowSpan.firstElementChild, 'img')\n ) {\n image = this.shadowSpan.firstElementChild;\n }\n unwrap(this.shadowSpan);\n this.shadowSpan = null;\n this.wrapper = null;\n }\n\n return image;\n }\n\n public flipImage(direction: 'horizontal' | 'vertical') {\n const selection = this.editor?.getDOMSelection();\n if (!this.editor || !selection || selection.type !== 'image') {\n return;\n }\n const image = selection.image;\n if (this.editor) {\n this.editImage(this.editor, image, ['flip'], imageEditInfo => {\n const angleRad = imageEditInfo.angleRad || 0;\n const isInVerticalPostion =\n (angleRad >= Math.PI / 2 && angleRad < (3 * Math.PI) / 4) ||\n (angleRad <= -Math.PI / 2 && angleRad > (-3 * Math.PI) / 4);\n if (isInVerticalPostion) {\n if (direction === 'horizontal') {\n imageEditInfo.flippedVertical = !imageEditInfo.flippedVertical;\n } else {\n imageEditInfo.flippedHorizontal = !imageEditInfo.flippedHorizontal;\n }\n } else {\n if (direction === 'vertical') {\n imageEditInfo.flippedVertical = !imageEditInfo.flippedVertical;\n } else {\n imageEditInfo.flippedHorizontal = !imageEditInfo.flippedHorizontal;\n }\n }\n });\n }\n }\n\n public rotateImage(angleRad: number) {\n const selection = this.editor?.getDOMSelection();\n if (!this.editor || !selection || selection.type !== 'image') {\n return;\n }\n const image = selection.image;\n if (this.editor) {\n this.editImage(this.editor, image, [], imageEditInfo => {\n imageEditInfo.angleRad = (imageEditInfo.angleRad || 0) + angleRad;\n });\n }\n }\n}\n"]}
1
+ {"version":3,"file":"ImageEditPlugin.js","sourceRoot":"","sources":["../../../../packages/roosterjs-content-model-plugins/lib/imageEdit/ImageEditPlugin.ts"],"names":[],"mappings":";;;;IA6CA,IAAM,cAAc,GAA8B;QAC9C,WAAW,EAAE,SAAS;QACtB,QAAQ,EAAE,EAAE;QACZ,SAAS,EAAE,EAAE;QACb,aAAa,EAAE,IAAI;QACnB,aAAa,EAAE,KAAK;QACpB,iBAAiB,EAAE,KAAK;QACxB,aAAa,EAAE,CAAC,QAAQ,EAAE,QAAQ,CAAC;KACtC,CAAC;IAEF,IAAM,gBAAgB,GAAG,CAAC,CAAC;IAC3B,IAAM,OAAO,GAAG,WAAW,CAAC;IAC5B,IAAM,gBAAgB,GAAG,WAAW,CAAC;IACrC,IAAM,sBAAsB,GAAG,qBAAqB,CAAC;IACrD,IAAM,uBAAuB,GAAG,gBAAgB,CAAC;IAEjD;;;;;;OAMG;IACH;QAmBI,yBAAsB,OAA0C;YAA1C,wBAAA,EAAA,wBAA0C;YAA1C,YAAO,GAAP,OAAO,CAAmC;YAlBtD,WAAM,GAAmB,IAAI,CAAC;YAChC,eAAU,GAA2B,IAAI,CAAC;YAC1C,kBAAa,GAA4B,IAAI,CAAC;YAC5C,YAAO,GAA2B,IAAI,CAAC;YACvC,kBAAa,GAA+B,IAAI,CAAC;YACnD,qBAAgB,GAA4B,IAAI,CAAC;YACjD,eAAU,GAAiD,EAAE,CAAC;YAC9D,gBAAW,GAA4B,IAAI,CAAC;YAC5C,YAAO,GAAkB,IAAI,CAAC;YAC9B,oBAAe,GAAY,KAAK,CAAC;YACjC,eAAU,GAAY,KAAK,CAAC;YAC5B,aAAQ,GAAqB,EAAE,CAAC;YAChC,aAAQ,GAAqB,EAAE,CAAC;YAChC,aAAQ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CAAe","sourcesContent":["import { applyChange } from './utils/applyChange';\nimport { canRegenerateImage } from './utils/canRegenerateImage';\nimport { checkIfImageWasResized, isASmallImage } from './utils/imageEditUtils';\nimport { createImageWrapper } from './utils/createImageWrapper';\nimport { Cropper } from './Cropper/cropperContext';\nimport { EDITING_MARKER, findEditingImage } from './utils/findEditingImage';\nimport { getDropAndDragHelpers } from './utils/getDropAndDragHelpers';\nimport { getHTMLImageOptions } from './utils/getHTMLImageOptions';\nimport { getSelectedImage } from './utils/getSelectedImage';\nimport { getSelectedImageMetadata, updateImageEditInfo } from './utils/updateImageEditInfo';\nimport { ImageEditElementClass } from './types/ImageEditElementClass';\nimport { normalizeImageSelection } from './utils/normalizeImageSelection';\nimport { Resizer } from './Resizer/resizerContext';\nimport { Rotator } from './Rotator/rotatorContext';\nimport { updateRotateHandle } from './Rotator/updateRotateHandle';\nimport { updateWrapper } from './utils/updateWrapper';\nimport {\n ChangeSource,\n getSafeIdSelector,\n getSelectedParagraphs,\n isElementOfType,\n isNodeOfType,\n mutateBlock,\n mutateSegment,\n setImageState,\n unwrap,\n} from 'roosterjs-content-model-dom';\nimport type { DragAndDropHelper } from '../pluginUtils/DragAndDrop/DragAndDropHelper';\nimport type { DragAndDropContext } from './types/DragAndDropContext';\nimport type { ImageHtmlOptions } from './types/ImageHtmlOptions';\nimport type { ImageEditOptions } from './types/ImageEditOptions';\nimport type {\n ContentChangedEvent,\n ContentModelImage,\n EditorPlugin,\n IEditor,\n ImageEditOperation,\n ImageEditor,\n ImageMetadataFormat,\n KeyDownEvent,\n MouseDownEvent,\n MouseUpEvent,\n PluginEvent,\n} from 'roosterjs-content-model-types';\n\nconst DefaultOptions: Partial<ImageEditOptions> = {\n borderColor: '#DB626C',\n minWidth: 10,\n minHeight: 10,\n preserveRatio: true,\n disableRotate: false,\n disableSideResize: false,\n onSelectState: ['resize', 'rotate'],\n};\n\nconst MouseRightButton = 2;\nconst DRAG_ID = '_dragging';\nconst IMAGE_EDIT_CLASS = 'imageEdit';\nconst IMAGE_EDIT_CLASS_CARET = 'imageEditCaretColor';\nconst IMAGE_EDIT_FORMAT_EVENT = 'ImageEditEvent';\n\n/**\n * ImageEdit plugin handles the following image editing features:\n * - Resize image\n * - Crop image\n * - Rotate image\n * - Flip image\n */\nexport class ImageEditPlugin implements ImageEditor, EditorPlugin {\n protected editor: IEditor | null = null;\n private shadowSpan: HTMLSpanElement | null = null;\n private selectedImage: HTMLImageElement | null = null;\n protected wrapper: HTMLSpanElement | null = null;\n protected imageEditInfo: ImageMetadataFormat | null = null;\n private imageHTMLOptions: ImageHtmlOptions | null = null;\n private dndHelpers: DragAndDropHelper<DragAndDropContext, any>[] = [];\n private clonedImage: HTMLImageElement | null = null;\n private lastSrc: string | null = null;\n private wasImageResized: boolean = false;\n private isCropMode: boolean = false;\n private resizers: HTMLDivElement[] = [];\n private rotators: HTMLDivElement[] = [];\n private croppers: HTMLDivElement[] = [];\n private zoomScale: number = 1;\n private disposer: (() => void) | null = null;\n protected isEditing = false;\n\n constructor(protected options: ImageEditOptions = DefaultOptions) {}\n\n /**\n * Get name of this plugin\n */\n getName() {\n return 'ImageEdit';\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.disposer = editor.attachDomEvent({\n blur: {\n beforeDispatch: () => {\n if (this.isEditing && this.editor && !this.editor.isDisposed()) {\n this.applyFormatWithContentModel(\n this.editor,\n this.isCropMode,\n true /* shouldSelectImage */\n );\n }\n },\n },\n dragstart: {\n beforeDispatch: ev => {\n if (this.editor) {\n const target = ev.target as Node;\n if (this.isImageSelection(target)) {\n target.id = target.id + DRAG_ID;\n }\n }\n },\n },\n dragend: {\n beforeDispatch: ev => {\n if (this.editor) {\n const target = ev.target as Node;\n if (this.isImageSelection(target) && target.id.includes(DRAG_ID)) {\n target.id = target.id.replace(DRAG_ID, '').trim();\n }\n }\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 if (this.disposer) {\n this.disposer();\n this.disposer = null;\n }\n this.isEditing = false;\n this.cleanInfo();\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 return;\n }\n switch (event.eventType) {\n case 'mouseDown':\n this.mouseDownHandler(this.editor, event);\n break;\n case 'mouseUp':\n this.mouseUpHandler(this.editor, event);\n break;\n case 'keyDown':\n this.keyDownHandler(this.editor, event);\n break;\n case 'contentChanged':\n this.contentChangedHandler(this.editor, event);\n break;\n case 'extractContentWithDom':\n this.removeImageEditing(event.clonedRoot);\n break;\n }\n }\n\n private removeImageEditing(clonedRoot: HTMLElement) {\n const images = clonedRoot.querySelectorAll('img');\n images.forEach(image => {\n if (image.dataset.editingInfo) {\n delete image.dataset.editingInfo;\n }\n });\n }\n\n private isImageSelection(target: Node): target is HTMLElement {\n return (\n isNodeOfType(target, 'ELEMENT_NODE') &&\n (isElementOfType(target, 'img') ||\n !!(\n isElementOfType(target, 'span') &&\n target.firstElementChild &&\n isNodeOfType(target.firstElementChild, 'ELEMENT_NODE') &&\n isElementOfType(target.firstElementChild, 'img')\n ))\n );\n }\n\n private mouseUpHandler(editor: IEditor, event: MouseUpEvent) {\n const selection = editor.getDOMSelection();\n if ((selection && selection.type == 'image') || this.isEditing) {\n const shouldSelectImage =\n this.isImageSelection(event.rawEvent.target as Node) &&\n event.rawEvent.button === MouseRightButton;\n this.applyFormatWithContentModel(editor, this.isCropMode, shouldSelectImage);\n }\n }\n\n private mouseDownHandler(editor: IEditor, event: MouseDownEvent) {\n if (\n this.isEditing &&\n this.isImageSelection(event.rawEvent.target as Node) &&\n event.rawEvent.button !== MouseRightButton &&\n !this.isCropMode\n ) {\n this.applyFormatWithContentModel(\n editor,\n this.isCropMode,\n this.shadowSpan === event.rawEvent.target\n );\n }\n }\n\n private onDropHandler(editor: IEditor) {\n const selection = editor.getDOMSelection();\n if (selection?.type == 'image') {\n editor.formatContentModel(model => {\n const imageDragged = findEditingImage(model, selection.image.id);\n const imageDropped = findEditingImage(\n model,\n selection.image.id.replace(DRAG_ID, '').trim()\n );\n if (imageDragged && imageDropped) {\n const draggedIndex = imageDragged.paragraph.segments.indexOf(\n imageDragged.image\n );\n mutateBlock(imageDragged.paragraph).segments.splice(draggedIndex, 1);\n const segment = imageDropped.image;\n const paragraph = imageDropped.paragraph;\n mutateSegment(paragraph, segment, image => {\n image.isSelected = true;\n image.isSelectedAsImageSelection = true;\n });\n\n return true;\n }\n return false;\n });\n }\n }\n\n private keyDownHandler(editor: IEditor, event: KeyDownEvent) {\n if (this.isEditing) {\n if (\n event.rawEvent.key === 'Escape' ||\n event.rawEvent.key === 'Delete' ||\n event.rawEvent.key === 'Backspace'\n ) {\n if (event.rawEvent.key === 'Escape') {\n this.removeImageWrapper();\n }\n this.cleanInfo();\n } else {\n if (event.rawEvent.key == 'Enter' && this.isCropMode) {\n event.rawEvent.preventDefault();\n }\n this.applyFormatWithContentModel(\n editor,\n this.isCropMode,\n true /** should selectImage */,\n false /* isApiOperation */\n );\n }\n }\n }\n\n private setContentHandler(editor: IEditor) {\n const selection = editor.getDOMSelection();\n if (selection?.type == 'image') {\n this.cleanInfo();\n setImageState(selection.image, '');\n this.isEditing = false;\n this.isCropMode = false;\n }\n }\n\n private formatEventHandler(event: ContentChangedEvent) {\n if (this.isEditing && event.formatApiName !== IMAGE_EDIT_FORMAT_EVENT) {\n this.cleanInfo();\n this.isEditing = false;\n this.isCropMode = false;\n }\n }\n\n private contentChangedHandler(editor: IEditor, event: ContentChangedEvent) {\n switch (event.source) {\n case ChangeSource.SetContent:\n this.setContentHandler(editor);\n break;\n case ChangeSource.Format:\n this.formatEventHandler(event);\n break;\n case ChangeSource.Drop:\n this.onDropHandler(editor);\n break;\n }\n }\n\n /**\n * EXPOSED FOR TESTING PURPOSE ONLY\n */\n protected applyFormatWithContentModel(\n editor: IEditor,\n isCropMode: boolean,\n shouldSelectImage: boolean,\n isApiOperation?: boolean\n ) {\n let editingImageModel: ContentModelImage | undefined;\n const selection = editor.getDOMSelection();\n\n editor.formatContentModel(\n model => {\n const editingImage = getSelectedImage(model);\n const previousSelectedImage = isApiOperation\n ? editingImage\n : findEditingImage(model);\n let result = false;\n\n if (\n shouldSelectImage ||\n previousSelectedImage?.image != editingImage?.image ||\n previousSelectedImage?.image.format.imageState == EDITING_MARKER ||\n isApiOperation\n ) {\n const { lastSrc, selectedImage, imageEditInfo, clonedImage } = this;\n if (\n (this.isEditing || isApiOperation) &&\n previousSelectedImage &&\n lastSrc &&\n selectedImage &&\n imageEditInfo &&\n clonedImage\n ) {\n mutateSegment(\n previousSelectedImage.paragraph,\n previousSelectedImage.image,\n image => {\n applyChange(\n editor,\n selectedImage,\n image,\n imageEditInfo,\n lastSrc,\n this.wasImageResized || this.isCropMode,\n clonedImage\n );\n\n image.isSelected = shouldSelectImage;\n image.isSelectedAsImageSelection = shouldSelectImage;\n image.format.imageState = undefined;\n\n if (selection?.type == 'range' && !selection.range.collapsed) {\n const selectedParagraphs = getSelectedParagraphs(model, true);\n const isImageInRange = selectedParagraphs.some(paragraph =>\n paragraph.segments.includes(image)\n );\n if (isImageInRange) {\n image.isSelected = true;\n }\n }\n }\n );\n\n if (shouldSelectImage) {\n normalizeImageSelection(previousSelectedImage);\n }\n\n this.cleanInfo();\n result = true;\n }\n\n this.isEditing = false;\n this.isCropMode = false;\n\n if (\n editingImage &&\n selection?.type == 'image' &&\n !shouldSelectImage &&\n !isApiOperation\n ) {\n this.isEditing = true;\n this.isCropMode = isCropMode;\n mutateSegment(editingImage.paragraph, editingImage.image, image => {\n editingImageModel = image;\n this.imageEditInfo = updateImageEditInfo(image, selection.image);\n image.format.imageState = 'isEditing';\n });\n\n result = true;\n }\n }\n\n return result;\n },\n {\n onNodeCreated: (model, node) => {\n if (\n !isApiOperation &&\n editingImageModel &&\n editingImageModel == model &&\n editingImageModel.format.imageState == EDITING_MARKER &&\n isNodeOfType(node, 'ELEMENT_NODE') &&\n isElementOfType(node, 'img')\n ) {\n if (isCropMode) {\n this.startCropMode(editor, node);\n } else {\n this.startRotateAndResize(editor, node);\n }\n }\n },\n apiName: IMAGE_EDIT_FORMAT_EVENT,\n },\n {\n tryGetFromCache: true,\n }\n );\n }\n\n private startEditing(\n editor: IEditor,\n image: HTMLImageElement,\n apiOperation: ImageEditOperation[]\n ) {\n if (!this.imageEditInfo) {\n this.imageEditInfo = getSelectedImageMetadata(editor, image);\n }\n this.lastSrc = image.getAttribute('src');\n this.imageHTMLOptions = getHTMLImageOptions(editor, this.options, this.imageEditInfo);\n const {\n resizers,\n rotators,\n wrapper,\n shadowSpan,\n imageClone,\n croppers,\n } = createImageWrapper(\n editor,\n image,\n this.options,\n this.imageEditInfo,\n this.imageHTMLOptions,\n apiOperation\n );\n this.shadowSpan = shadowSpan;\n this.selectedImage = image;\n this.wrapper = wrapper;\n this.clonedImage = imageClone;\n this.wasImageResized = checkIfImageWasResized(image);\n this.resizers = resizers;\n this.rotators = rotators;\n this.croppers = croppers;\n this.zoomScale = editor.getDOMHelper().calculateZoomScale();\n\n editor.setEditorStyle(IMAGE_EDIT_CLASS, `outline-style:none!important;`, [\n `span:has(>img${getSafeIdSelector(this.selectedImage.id)})`,\n ]);\n\n editor.setEditorStyle(IMAGE_EDIT_CLASS_CARET, `caret-color: transparent;`);\n }\n\n public startRotateAndResize(editor: IEditor, image: HTMLImageElement) {\n if (this.imageEditInfo) {\n this.startEditing(editor, image, ['resize', 'rotate']);\n if (this.selectedImage && this.imageEditInfo && this.wrapper && this.clonedImage) {\n const isMobileOrTable = !!editor.getEnvironment().isMobileOrTablet;\n this.dndHelpers = [\n ...getDropAndDragHelpers(\n this.wrapper,\n this.imageEditInfo,\n this.options,\n ImageEditElementClass.ResizeHandle,\n Resizer,\n () => {\n if (\n this.imageEditInfo &&\n this.selectedImage &&\n this.wrapper &&\n this.clonedImage\n ) {\n updateWrapper(\n this.imageEditInfo,\n this.options,\n this.selectedImage,\n this.clonedImage,\n this.wrapper,\n this.resizers\n );\n this.wasImageResized = true;\n }\n },\n this.zoomScale,\n isMobileOrTable\n ),\n ...getDropAndDragHelpers(\n this.wrapper,\n this.imageEditInfo,\n this.options,\n ImageEditElementClass.RotateHandle,\n Rotator,\n () => {\n if (\n this.imageEditInfo &&\n this.selectedImage &&\n this.wrapper &&\n this.clonedImage\n ) {\n updateWrapper(\n this.imageEditInfo,\n this.options,\n this.selectedImage,\n this.clonedImage,\n this.wrapper\n );\n this.updateRotateHandleState(\n editor,\n this.selectedImage,\n this.wrapper,\n this.rotators,\n this.imageEditInfo?.angleRad\n );\n }\n },\n this.zoomScale,\n isMobileOrTable\n ),\n ];\n\n updateWrapper(\n this.imageEditInfo,\n this.options,\n this.selectedImage,\n this.clonedImage,\n this.wrapper,\n this.resizers\n );\n\n this.updateRotateHandleState(\n editor,\n this.selectedImage,\n this.wrapper,\n this.rotators,\n this.imageEditInfo?.angleRad\n );\n }\n }\n }\n\n private updateRotateHandleState(\n editor: IEditor,\n image: HTMLImageElement,\n wrapper: HTMLSpanElement,\n rotators: HTMLDivElement[],\n angleRad: number | undefined\n ) {\n const viewport = editor.getVisibleViewport();\n const smallImage = isASmallImage(image.width, image.height);\n if (viewport && rotators && rotators.length > 0) {\n const rotator = rotators[0];\n const rotatorHandle = rotator.firstElementChild;\n if (\n isNodeOfType(rotatorHandle, 'ELEMENT_NODE') &&\n isElementOfType(rotatorHandle, 'div')\n ) {\n updateRotateHandle(\n viewport,\n angleRad ?? 0,\n wrapper,\n rotator,\n rotatorHandle,\n smallImage\n );\n }\n }\n }\n\n public isOperationAllowed(operation: ImageEditOperation): boolean {\n return (\n operation === 'resize' ||\n operation === 'rotate' ||\n operation === 'flip' ||\n operation === 'crop'\n );\n }\n\n public canRegenerateImage(image: HTMLImageElement): boolean {\n return canRegenerateImage(image);\n }\n\n private startCropMode(editor: IEditor, image: HTMLImageElement) {\n if (this.imageEditInfo) {\n this.startEditing(editor, image, ['crop']);\n if (this.imageEditInfo && this.selectedImage && this.wrapper && this.clonedImage) {\n this.dndHelpers = [\n ...getDropAndDragHelpers(\n this.wrapper,\n this.imageEditInfo,\n this.options,\n ImageEditElementClass.CropHandle,\n Cropper,\n () => {\n if (\n this.imageEditInfo &&\n this.selectedImage &&\n this.wrapper &&\n this.clonedImage\n ) {\n updateWrapper(\n this.imageEditInfo,\n this.options,\n this.selectedImage,\n this.clonedImage,\n this.wrapper,\n undefined,\n this.croppers\n );\n this.isCropMode = true;\n }\n },\n this.zoomScale,\n !!editor.getEnvironment().isMobileOrTablet\n ),\n ];\n updateWrapper(\n this.imageEditInfo,\n this.options,\n this.selectedImage,\n this.clonedImage,\n this.wrapper,\n undefined,\n this.croppers\n );\n }\n }\n }\n\n public cropImage() {\n if (!this.editor) {\n return;\n }\n if (!this.editor.getEnvironment().isSafari) {\n this.editor.focus(); // Safari will keep the selection when click crop, then the focus() call should not be called\n }\n const selection = this.editor.getDOMSelection();\n if (selection?.type == 'image') {\n this.applyFormatWithContentModel(\n this.editor,\n true /* isCropMode */,\n false /* shouldSelectImage */\n );\n }\n }\n\n private editImage(\n editor: IEditor,\n image: HTMLImageElement,\n apiOperation: ImageEditOperation[],\n operation: (imageEditInfo: ImageMetadataFormat) => void\n ) {\n this.startEditing(editor, image, apiOperation);\n if (!this.selectedImage || !this.imageEditInfo || !this.wrapper || !this.clonedImage) {\n return;\n }\n\n operation(this.imageEditInfo);\n\n updateWrapper(\n this.imageEditInfo,\n this.options,\n this.selectedImage,\n this.clonedImage,\n this.wrapper\n );\n\n this.applyFormatWithContentModel(\n editor,\n false /* isCrop */,\n true /* shouldSelect*/,\n true /* isApiOperation */\n );\n }\n\n /**\n * Exported for testing purpose only\n */\n public cleanInfo() {\n this.editor?.setEditorStyle(IMAGE_EDIT_CLASS, null);\n this.editor?.setEditorStyle(IMAGE_EDIT_CLASS_CARET, null);\n this.selectedImage = null;\n this.shadowSpan = null;\n this.wrapper = null;\n this.imageEditInfo = null;\n this.imageHTMLOptions = null;\n this.dndHelpers.forEach(helper => helper.dispose());\n this.dndHelpers = [];\n this.clonedImage = null;\n this.lastSrc = null;\n this.wasImageResized = false;\n this.isCropMode = false;\n this.resizers = [];\n this.rotators = [];\n this.croppers = [];\n }\n\n private removeImageWrapper() {\n let image: HTMLImageElement | null = null;\n if (this.shadowSpan && this.shadowSpan.parentElement) {\n if (\n this.shadowSpan.firstElementChild &&\n isNodeOfType(this.shadowSpan.firstElementChild, 'ELEMENT_NODE') &&\n isElementOfType(this.shadowSpan.firstElementChild, 'img')\n ) {\n image = this.shadowSpan.firstElementChild;\n }\n unwrap(this.shadowSpan);\n this.shadowSpan = null;\n this.wrapper = null;\n }\n\n return image;\n }\n\n public flipImage(direction: 'horizontal' | 'vertical') {\n const selection = this.editor?.getDOMSelection();\n if (!this.editor || !selection || selection.type !== 'image') {\n return;\n }\n const image = selection.image;\n if (this.editor) {\n this.editImage(this.editor, image, ['flip'], imageEditInfo => {\n const angleRad = imageEditInfo.angleRad || 0;\n const isInVerticalPostion =\n (angleRad >= Math.PI / 2 && angleRad < (3 * Math.PI) / 4) ||\n (angleRad <= -Math.PI / 2 && angleRad > (-3 * Math.PI) / 4);\n if (isInVerticalPostion) {\n if (direction === 'horizontal') {\n imageEditInfo.flippedVertical = !imageEditInfo.flippedVertical;\n } else {\n imageEditInfo.flippedHorizontal = !imageEditInfo.flippedHorizontal;\n }\n } else {\n if (direction === 'vertical') {\n imageEditInfo.flippedVertical = !imageEditInfo.flippedVertical;\n } else {\n imageEditInfo.flippedHorizontal = !imageEditInfo.flippedHorizontal;\n }\n }\n });\n }\n }\n\n public rotateImage(angleRad: number) {\n const selection = this.editor?.getDOMSelection();\n if (!this.editor || !selection || selection.type !== 'image') {\n return;\n }\n const image = selection.image;\n if (this.editor) {\n this.editImage(this.editor, image, [], imageEditInfo => {\n imageEditInfo.angleRad = (imageEditInfo.angleRad || 0) + angleRad;\n });\n }\n }\n}\n"]}
@@ -1,5 +1,9 @@
1
1
  import type { ReadonlyContentModelBlockGroup } from 'roosterjs-content-model-types';
2
2
  import type { ImageAndParagraph } from '../types/ImageAndParagraph';
3
+ /**
4
+ * @internal
5
+ */
6
+ export declare const EDITING_MARKER = "isEditing";
3
7
  /**
4
8
  * @internal
5
9
  */
@@ -1,7 +1,11 @@
1
1
  define(["require", "exports", "tslib", "roosterjs-content-model-api"], function (require, exports, tslib_1, roosterjs_content_model_api_1) {
2
2
  "use strict";
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.findEditingImage = void 0;
4
+ exports.findEditingImage = exports.EDITING_MARKER = void 0;
5
+ /**
6
+ * @internal
7
+ */
8
+ exports.EDITING_MARKER = 'isEditing';
5
9
  /**
6
10
  * @internal
7
11
  */
@@ -13,7 +17,8 @@ define(["require", "exports", "tslib", "roosterjs-content-model-api"], function
13
17
  for (var _b = (0, tslib_1.__values)(paragraph.segments), _c = _b.next(); !_c.done; _c = _b.next()) {
14
18
  var segment = _c.value;
15
19
  if (segment.segmentType == 'Image' &&
16
- ((imageId && segment.format.id == imageId) || segment.dataset.isEditing)) {
20
+ ((imageId && segment.format.id == imageId) ||
21
+ segment.format.imageState == exports.EDITING_MARKER)) {
17
22
  imageAndParagraph = { image: segment, paragraph: paragraph };
18
23
  return true;
19
24
  }
@@ -1 +1 @@
1
- {"version":3,"file":"findEditingImage.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-plugins/lib/imageEdit/utils/findEditingImage.ts"],"names":[],"mappings":";;;;IAOA;;OAEG;IACH,SAAgB,gBAAgB,CAC5B,KAAqC,EACrC,OAAgB;QAEhB,IAAI,iBAAiB,GAA6B,IAAI,CAAC;QACvD,IAAA,qDAAuB,EACnB,KAAK,EACL,WAAW,EACX,UAAC,SAAwC;;;gBACrC,KAAsB,IAAA,KAAA,sBAAA,SAAS,CAAC,QAAQ,CAAA,gBAAA,4BAAE;oBAArC,IAAM,OAAO,WAAA;oBACd,IACI,OAAO,CAAC,WAAW,IAAI,OAAO;wBAC9B,CAAC,CAAC,OAAO,IAAI,OAAO,CAAC,MAAM,CAAC,EAAE,IAAI,OAAO,CAAC,IAAI,OAAO,CAAC,OAAO,CAAC,SAAS,CAAC,EAC1E;wBACE,iBAAiB,GAAG,EAAE,KAAK,EAAE,OAAO,EAAE,SAAS,WAAA,EAAE,CAAC;wBAClD,OAAO,IAAI,CAAC;qBACf;iBACJ;;;;;;;;;YACD,OAAO,KAAK,CAAC;QACjB,CAAC,EACD,IAAI,CAAC,iBAAiB,CACzB,CAAC;QAEF,OAAO,iBAAiB,CAAC;IAC7B,CAAC;IAxBD,4CAwBC","sourcesContent":["import { queryContentModelBlocks } from 'roosterjs-content-model-api';\nimport type {\n ReadonlyContentModelBlockGroup,\n ReadonlyContentModelParagraph,\n} from 'roosterjs-content-model-types';\nimport type { ImageAndParagraph } from '../types/ImageAndParagraph';\n\n/**\n * @internal\n */\nexport function findEditingImage(\n group: ReadonlyContentModelBlockGroup,\n imageId?: string\n): ImageAndParagraph | null {\n let imageAndParagraph: ImageAndParagraph | null = null;\n queryContentModelBlocks<ReadonlyContentModelParagraph>(\n group,\n 'Paragraph',\n (paragraph: ReadonlyContentModelParagraph): paragraph is ReadonlyContentModelParagraph => {\n for (const segment of paragraph.segments) {\n if (\n segment.segmentType == 'Image' &&\n ((imageId && segment.format.id == imageId) || segment.dataset.isEditing)\n ) {\n imageAndParagraph = { image: segment, paragraph };\n return true;\n }\n }\n return false;\n },\n true /*findFirstOnly*/\n );\n\n return imageAndParagraph;\n}\n"]}
1
+ {"version":3,"file":"findEditingImage.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-plugins/lib/imageEdit/utils/findEditingImage.ts"],"names":[],"mappings":";;;;IAOA;;OAEG;IACU,QAAA,cAAc,GAAG,WAAW,CAAC;IAE1C;;OAEG;IACH,SAAgB,gBAAgB,CAC5B,KAAqC,EACrC,OAAgB;QAEhB,IAAI,iBAAiB,GAA6B,IAAI,CAAC;QACvD,IAAA,qDAAuB,EACnB,KAAK,EACL,WAAW,EACX,UAAC,SAAwC;;;gBACrC,KAAsB,IAAA,KAAA,sBAAA,SAAS,CAAC,QAAQ,CAAA,gBAAA,4BAAE;oBAArC,IAAM,OAAO,WAAA;oBACd,IACI,OAAO,CAAC,WAAW,IAAI,OAAO;wBAC9B,CAAC,CAAC,OAAO,IAAI,OAAO,CAAC,MAAM,CAAC,EAAE,IAAI,OAAO,CAAC;4BACtC,OAAO,CAAC,MAAM,CAAC,UAAU,IAAI,sBAAc,CAAC,EAClD;wBACE,iBAAiB,GAAG,EAAE,KAAK,EAAE,OAAO,EAAE,SAAS,WAAA,EAAE,CAAC;wBAClD,OAAO,IAAI,CAAC;qBACf;iBACJ;;;;;;;;;YACD,OAAO,KAAK,CAAC;QACjB,CAAC,EACD,IAAI,CAAC,iBAAiB,CACzB,CAAC;QAEF,OAAO,iBAAiB,CAAC;IAC7B,CAAC;IAzBD,4CAyBC","sourcesContent":["import { queryContentModelBlocks } from 'roosterjs-content-model-api';\nimport type {\n ReadonlyContentModelBlockGroup,\n ReadonlyContentModelParagraph,\n} from 'roosterjs-content-model-types';\nimport type { ImageAndParagraph } from '../types/ImageAndParagraph';\n\n/**\n * @internal\n */\nexport const EDITING_MARKER = 'isEditing';\n\n/**\n * @internal\n */\nexport function findEditingImage(\n group: ReadonlyContentModelBlockGroup,\n imageId?: string\n): ImageAndParagraph | null {\n let imageAndParagraph: ImageAndParagraph | null = null;\n queryContentModelBlocks<ReadonlyContentModelParagraph>(\n group,\n 'Paragraph',\n (paragraph: ReadonlyContentModelParagraph): paragraph is ReadonlyContentModelParagraph => {\n for (const segment of paragraph.segments) {\n if (\n segment.segmentType == 'Image' &&\n ((imageId && segment.format.id == imageId) ||\n segment.format.imageState == EDITING_MARKER)\n ) {\n imageAndParagraph = { image: segment, paragraph };\n return true;\n }\n }\n return false;\n },\n true /*findFirstOnly*/\n );\n\n return imageAndParagraph;\n}\n"]}
@@ -1,4 +1,4 @@
1
- define(["require", "exports", "tslib", "./utils/addParser", "roosterjs-content-model-dom", "./utils/chainSanitizerCallback", "./DefaultSanitizers", "./utils/deprecatedColorParser", "./pasteSourceValidations/getPasteSource", "./utils/linkParser", "./pasteSourceValidations/constants", "./Excel/processPastedContentFromExcel", "./oneNote/processPastedContentFromOneNote", "./PowerPoint/processPastedContentFromPowerPoint", "./WordDesktop/processPastedContentFromWordDesktop", "./WacComponents/processPastedContentWacComponents"], function (require, exports, tslib_1, addParser_1, roosterjs_content_model_dom_1, chainSanitizerCallback_1, DefaultSanitizers_1, deprecatedColorParser_1, getPasteSource_1, linkParser_1, constants_1, processPastedContentFromExcel_1, processPastedContentFromOneNote_1, processPastedContentFromPowerPoint_1, processPastedContentFromWordDesktop_1, processPastedContentWacComponents_1) {
1
+ define(["require", "exports", "tslib", "./utils/addParser", "roosterjs-content-model-dom", "./utils/chainSanitizerCallback", "./DefaultSanitizers", "./parsers/deprecatedColorParser", "./pasteSourceValidations/getPasteSource", "./parsers/linkParser", "./pasteSourceValidations/constants", "./Excel/processPastedContentFromExcel", "./oneNote/processPastedContentFromOneNote", "./PowerPoint/processPastedContentFromPowerPoint", "./WordDesktop/processPastedContentFromWordDesktop", "./WacComponents/processPastedContentWacComponents"], function (require, exports, tslib_1, addParser_1, roosterjs_content_model_dom_1, chainSanitizerCallback_1, DefaultSanitizers_1, deprecatedColorParser_1, getPasteSource_1, linkParser_1, constants_1, processPastedContentFromExcel_1, processPastedContentFromOneNote_1, processPastedContentFromPowerPoint_1, processPastedContentFromWordDesktop_1, processPastedContentWacComponents_1) {
2
2
  "use strict";
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.PastePlugin = void 0;
@@ -66,7 +66,7 @@ define(["require", "exports", "tslib", "./utils/addParser", "roosterjs-content-m
66
66
  var pasteType = event.pasteType;
67
67
  switch (pasteSource) {
68
68
  case 'wordDesktop':
69
- (0, processPastedContentFromWordDesktop_1.processPastedContentFromWordDesktop)(event, this.editor.getDOMCreator());
69
+ (0, processPastedContentFromWordDesktop_1.processPastedContentFromWordDesktop)(event);
70
70
  break;
71
71
  case 'wacComponents':
72
72
  (0, processPastedContentWacComponents_1.processPastedContentWacComponents)(event);