roosterjs-content-model-plugins 0.23.0 → 0.24.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 (154) hide show
  1. package/lib/edit/ContentModelEditPlugin.d.ts +2 -2
  2. package/lib/edit/ContentModelEditPlugin.js +1 -2
  3. package/lib/edit/ContentModelEditPlugin.js.map +1 -1
  4. package/lib/edit/deleteSteps/deleteList.d.ts +5 -0
  5. package/lib/edit/deleteSteps/deleteList.js +24 -0
  6. package/lib/edit/deleteSteps/deleteList.js.map +1 -0
  7. package/lib/edit/handleKeyboardEventCommon.d.ts +2 -3
  8. package/lib/edit/handleKeyboardEventCommon.js +1 -1
  9. package/lib/edit/handleKeyboardEventCommon.js.map +1 -1
  10. package/lib/edit/keyboardDelete.d.ts +2 -2
  11. package/lib/edit/keyboardDelete.js +8 -1
  12. package/lib/edit/keyboardDelete.js.map +1 -1
  13. package/lib/edit/keyboardInput.d.ts +2 -2
  14. package/lib/edit/keyboardInput.js.map +1 -1
  15. package/lib/paste/ContentModelPastePlugin.d.ts +2 -2
  16. package/lib/paste/ContentModelPastePlugin.js +16 -25
  17. package/lib/paste/ContentModelPastePlugin.js.map +1 -1
  18. package/lib/paste/Excel/processPastedContentFromExcel.d.ts +2 -3
  19. package/lib/paste/Excel/processPastedContentFromExcel.js.map +1 -1
  20. package/lib/paste/PowerPoint/processPastedContentFromPowerPoint.d.ts +1 -1
  21. package/lib/paste/PowerPoint/processPastedContentFromPowerPoint.js.map +1 -1
  22. package/lib/paste/WacComponents/processPastedContentWacComponents.d.ts +2 -2
  23. package/lib/paste/WacComponents/processPastedContentWacComponents.js +59 -61
  24. package/lib/paste/WacComponents/processPastedContentWacComponents.js.map +1 -1
  25. package/lib/paste/WordDesktop/getStyleMetadata.d.ts +2 -2
  26. package/lib/paste/WordDesktop/getStyleMetadata.js.map +1 -1
  27. package/lib/paste/WordDesktop/processPastedContentFromWordDesktop.d.ts +2 -2
  28. package/lib/paste/WordDesktop/processPastedContentFromWordDesktop.js +2 -0
  29. package/lib/paste/WordDesktop/processPastedContentFromWordDesktop.js.map +1 -1
  30. package/lib/paste/WordDesktop/processWordLists.js +2 -0
  31. package/lib/paste/WordDesktop/processWordLists.js.map +1 -1
  32. package/lib/paste/WordDesktop/removeNegativeTextIndentParser.d.ts +5 -0
  33. package/lib/paste/WordDesktop/removeNegativeTextIndentParser.js +14 -0
  34. package/lib/paste/WordDesktop/removeNegativeTextIndentParser.js.map +1 -0
  35. package/lib/paste/pasteSourceValidations/constants.d.ts +5 -5
  36. package/lib/paste/pasteSourceValidations/constants.js +5 -6
  37. package/lib/paste/pasteSourceValidations/constants.js.map +1 -1
  38. package/lib/paste/pasteSourceValidations/getPasteSource.d.ts +1 -2
  39. package/lib/paste/pasteSourceValidations/getPasteSource.js.map +1 -1
  40. package/lib/paste/pasteSourceValidations/isExcelDesktopDocument.js +2 -1
  41. package/lib/paste/pasteSourceValidations/isExcelDesktopDocument.js.map +1 -1
  42. package/lib/paste/pasteSourceValidations/isExcelOnlineDocument.js +3 -2
  43. package/lib/paste/pasteSourceValidations/isExcelOnlineDocument.js.map +1 -1
  44. package/lib/paste/pasteSourceValidations/isGoogleSheetDocument.js +2 -1
  45. package/lib/paste/pasteSourceValidations/isGoogleSheetDocument.js.map +1 -1
  46. package/lib/paste/pasteSourceValidations/isPowerPointDesktopDocument.js +2 -1
  47. package/lib/paste/pasteSourceValidations/isPowerPointDesktopDocument.js.map +1 -1
  48. package/lib/paste/pasteSourceValidations/isWordDesktopDocument.js +2 -1
  49. package/lib/paste/pasteSourceValidations/isWordDesktopDocument.js.map +1 -1
  50. package/lib/paste/utils/addParser.d.ts +2 -2
  51. package/lib/paste/utils/addParser.js.map +1 -1
  52. package/lib-amd/edit/ContentModelEditPlugin.d.ts +2 -2
  53. package/lib-amd/edit/ContentModelEditPlugin.js +1 -2
  54. package/lib-amd/edit/ContentModelEditPlugin.js.map +1 -1
  55. package/lib-amd/edit/deleteSteps/deleteList.d.ts +5 -0
  56. package/lib-amd/edit/deleteSteps/deleteList.js +25 -0
  57. package/lib-amd/edit/deleteSteps/deleteList.js.map +1 -0
  58. package/lib-amd/edit/handleKeyboardEventCommon.d.ts +2 -3
  59. package/lib-amd/edit/handleKeyboardEventCommon.js +1 -1
  60. package/lib-amd/edit/handleKeyboardEventCommon.js.map +1 -1
  61. package/lib-amd/edit/keyboardDelete.d.ts +2 -2
  62. package/lib-amd/edit/keyboardDelete.js +8 -2
  63. package/lib-amd/edit/keyboardDelete.js.map +1 -1
  64. package/lib-amd/edit/keyboardInput.d.ts +2 -2
  65. package/lib-amd/edit/keyboardInput.js.map +1 -1
  66. package/lib-amd/paste/ContentModelPastePlugin.d.ts +2 -2
  67. package/lib-amd/paste/ContentModelPastePlugin.js +16 -26
  68. package/lib-amd/paste/ContentModelPastePlugin.js.map +1 -1
  69. package/lib-amd/paste/Excel/processPastedContentFromExcel.d.ts +2 -3
  70. package/lib-amd/paste/Excel/processPastedContentFromExcel.js.map +1 -1
  71. package/lib-amd/paste/PowerPoint/processPastedContentFromPowerPoint.d.ts +1 -1
  72. package/lib-amd/paste/PowerPoint/processPastedContentFromPowerPoint.js.map +1 -1
  73. package/lib-amd/paste/WacComponents/processPastedContentWacComponents.d.ts +2 -2
  74. package/lib-amd/paste/WacComponents/processPastedContentWacComponents.js +58 -62
  75. package/lib-amd/paste/WacComponents/processPastedContentWacComponents.js.map +1 -1
  76. package/lib-amd/paste/WordDesktop/getStyleMetadata.d.ts +2 -2
  77. package/lib-amd/paste/WordDesktop/getStyleMetadata.js.map +1 -1
  78. package/lib-amd/paste/WordDesktop/processPastedContentFromWordDesktop.d.ts +2 -2
  79. package/lib-amd/paste/WordDesktop/processPastedContentFromWordDesktop.js +2 -1
  80. package/lib-amd/paste/WordDesktop/processPastedContentFromWordDesktop.js.map +1 -1
  81. package/lib-amd/paste/WordDesktop/processWordLists.js +2 -1
  82. package/lib-amd/paste/WordDesktop/processWordLists.js.map +1 -1
  83. package/lib-amd/paste/WordDesktop/removeNegativeTextIndentParser.d.ts +5 -0
  84. package/lib-amd/paste/WordDesktop/removeNegativeTextIndentParser.js +16 -0
  85. package/lib-amd/paste/WordDesktop/removeNegativeTextIndentParser.js.map +1 -0
  86. package/lib-amd/paste/pasteSourceValidations/constants.d.ts +5 -5
  87. package/lib-amd/paste/pasteSourceValidations/constants.js +5 -6
  88. package/lib-amd/paste/pasteSourceValidations/constants.js.map +1 -1
  89. package/lib-amd/paste/pasteSourceValidations/getPasteSource.d.ts +1 -2
  90. package/lib-amd/paste/pasteSourceValidations/getPasteSource.js.map +1 -1
  91. package/lib-amd/paste/pasteSourceValidations/isExcelDesktopDocument.js +2 -2
  92. package/lib-amd/paste/pasteSourceValidations/isExcelDesktopDocument.js.map +1 -1
  93. package/lib-amd/paste/pasteSourceValidations/isExcelOnlineDocument.js +3 -3
  94. package/lib-amd/paste/pasteSourceValidations/isExcelOnlineDocument.js.map +1 -1
  95. package/lib-amd/paste/pasteSourceValidations/isGoogleSheetDocument.js +2 -2
  96. package/lib-amd/paste/pasteSourceValidations/isGoogleSheetDocument.js.map +1 -1
  97. package/lib-amd/paste/pasteSourceValidations/isPowerPointDesktopDocument.js +2 -2
  98. package/lib-amd/paste/pasteSourceValidations/isPowerPointDesktopDocument.js.map +1 -1
  99. package/lib-amd/paste/pasteSourceValidations/isWordDesktopDocument.js +2 -2
  100. package/lib-amd/paste/pasteSourceValidations/isWordDesktopDocument.js.map +1 -1
  101. package/lib-amd/paste/utils/addParser.d.ts +2 -2
  102. package/lib-amd/paste/utils/addParser.js.map +1 -1
  103. package/lib-mjs/edit/ContentModelEditPlugin.d.ts +2 -2
  104. package/lib-mjs/edit/ContentModelEditPlugin.js +1 -2
  105. package/lib-mjs/edit/ContentModelEditPlugin.js.map +1 -1
  106. package/lib-mjs/edit/deleteSteps/deleteList.d.ts +5 -0
  107. package/lib-mjs/edit/deleteSteps/deleteList.js +20 -0
  108. package/lib-mjs/edit/deleteSteps/deleteList.js.map +1 -0
  109. package/lib-mjs/edit/handleKeyboardEventCommon.d.ts +2 -3
  110. package/lib-mjs/edit/handleKeyboardEventCommon.js +1 -1
  111. package/lib-mjs/edit/handleKeyboardEventCommon.js.map +1 -1
  112. package/lib-mjs/edit/keyboardDelete.d.ts +2 -2
  113. package/lib-mjs/edit/keyboardDelete.js +8 -1
  114. package/lib-mjs/edit/keyboardDelete.js.map +1 -1
  115. package/lib-mjs/edit/keyboardInput.d.ts +2 -2
  116. package/lib-mjs/edit/keyboardInput.js.map +1 -1
  117. package/lib-mjs/paste/ContentModelPastePlugin.d.ts +2 -2
  118. package/lib-mjs/paste/ContentModelPastePlugin.js +16 -25
  119. package/lib-mjs/paste/ContentModelPastePlugin.js.map +1 -1
  120. package/lib-mjs/paste/Excel/processPastedContentFromExcel.d.ts +2 -3
  121. package/lib-mjs/paste/Excel/processPastedContentFromExcel.js.map +1 -1
  122. package/lib-mjs/paste/PowerPoint/processPastedContentFromPowerPoint.d.ts +1 -1
  123. package/lib-mjs/paste/PowerPoint/processPastedContentFromPowerPoint.js.map +1 -1
  124. package/lib-mjs/paste/WacComponents/processPastedContentWacComponents.d.ts +2 -2
  125. package/lib-mjs/paste/WacComponents/processPastedContentWacComponents.js +59 -61
  126. package/lib-mjs/paste/WacComponents/processPastedContentWacComponents.js.map +1 -1
  127. package/lib-mjs/paste/WordDesktop/getStyleMetadata.d.ts +2 -2
  128. package/lib-mjs/paste/WordDesktop/getStyleMetadata.js.map +1 -1
  129. package/lib-mjs/paste/WordDesktop/processPastedContentFromWordDesktop.d.ts +2 -2
  130. package/lib-mjs/paste/WordDesktop/processPastedContentFromWordDesktop.js +2 -0
  131. package/lib-mjs/paste/WordDesktop/processPastedContentFromWordDesktop.js.map +1 -1
  132. package/lib-mjs/paste/WordDesktop/processWordLists.js +2 -0
  133. package/lib-mjs/paste/WordDesktop/processWordLists.js.map +1 -1
  134. package/lib-mjs/paste/WordDesktop/removeNegativeTextIndentParser.d.ts +5 -0
  135. package/lib-mjs/paste/WordDesktop/removeNegativeTextIndentParser.js +10 -0
  136. package/lib-mjs/paste/WordDesktop/removeNegativeTextIndentParser.js.map +1 -0
  137. package/lib-mjs/paste/pasteSourceValidations/constants.d.ts +5 -5
  138. package/lib-mjs/paste/pasteSourceValidations/constants.js +5 -6
  139. package/lib-mjs/paste/pasteSourceValidations/constants.js.map +1 -1
  140. package/lib-mjs/paste/pasteSourceValidations/getPasteSource.d.ts +1 -2
  141. package/lib-mjs/paste/pasteSourceValidations/getPasteSource.js.map +1 -1
  142. package/lib-mjs/paste/pasteSourceValidations/isExcelDesktopDocument.js +2 -1
  143. package/lib-mjs/paste/pasteSourceValidations/isExcelDesktopDocument.js.map +1 -1
  144. package/lib-mjs/paste/pasteSourceValidations/isExcelOnlineDocument.js +3 -2
  145. package/lib-mjs/paste/pasteSourceValidations/isExcelOnlineDocument.js.map +1 -1
  146. package/lib-mjs/paste/pasteSourceValidations/isGoogleSheetDocument.js +2 -1
  147. package/lib-mjs/paste/pasteSourceValidations/isGoogleSheetDocument.js.map +1 -1
  148. package/lib-mjs/paste/pasteSourceValidations/isPowerPointDesktopDocument.js +2 -1
  149. package/lib-mjs/paste/pasteSourceValidations/isPowerPointDesktopDocument.js.map +1 -1
  150. package/lib-mjs/paste/pasteSourceValidations/isWordDesktopDocument.js +2 -1
  151. package/lib-mjs/paste/pasteSourceValidations/isWordDesktopDocument.js.map +1 -1
  152. package/lib-mjs/paste/utils/addParser.d.ts +2 -2
  153. package/lib-mjs/paste/utils/addParser.js.map +1 -1
  154. package/package.json +5 -5
@@ -1,4 +1,4 @@
1
- import type { EditorPlugin, IEditor, PluginEvent } from 'roosterjs-editor-types';
1
+ import type { EditorPlugin, IStandaloneEditor, PluginEvent } from 'roosterjs-content-model-types';
2
2
  /**
3
3
  * ContentModel edit plugins helps editor to do editing operation on top of content model.
4
4
  * This includes:
@@ -17,7 +17,7 @@ export declare class ContentModelEditPlugin implements EditorPlugin {
17
17
  * editor reference so that it can call to any editor method or format API later.
18
18
  * @param editor The editor object
19
19
  */
20
- initialize(editor: IEditor): void;
20
+ initialize(editor: IStandaloneEditor): void;
21
21
  /**
22
22
  * The last method that editor will call to a plugin before it is disposed.
23
23
  * Plugin can take this chance to clear the reference to editor. After this method is
@@ -46,7 +46,7 @@ var ContentModelEditPlugin = /** @class */ (function () {
46
46
  ContentModelEditPlugin.prototype.onPluginEvent = function (event) {
47
47
  if (this.editor) {
48
48
  switch (event.eventType) {
49
- case 0 /* KeyDown */:
49
+ case 'keyDown':
50
50
  this.handleKeyDownEvent(this.editor, event);
51
51
  break;
52
52
  }
@@ -55,7 +55,6 @@ var ContentModelEditPlugin = /** @class */ (function () {
55
55
  ContentModelEditPlugin.prototype.handleKeyDownEvent = function (editor, event) {
56
56
  var rawEvent = event.rawEvent;
57
57
  if (!rawEvent.defaultPrevented && !event.handledByEditFeature) {
58
- // TODO: Consider use ContentEditFeature and need to hide other conflict features that are not based on Content Model
59
58
  switch (rawEvent.key) {
60
59
  case 'Backspace':
61
60
  case 'Delete':
@@ -1 +1 @@
1
- {"version":3,"file":"ContentModelEditPlugin.js","sourceRoot":"","sources":["../../../../packages-content-model/roosterjs-content-model-plugins/lib/edit/ContentModelEditPlugin.ts"],"names":[],"mappings":";;;AAAA,mDAAkD;AAClD,iDAAgD;AAUhD;;;;;GAKG;AACH;IAAA;QACY,WAAM,GAA+B,IAAI,CAAC;IAiEtD,CAAC;IA/DG;;OAEG;IACH,wCAAO,GAAP;QACI,OAAO,kBAAkB,CAAC;IAC9B,CAAC;IAED;;;;;OAKG;IACH,2CAAU,GAAV,UAAW,MAAe;QACtB,gFAAgF;QAChF,IAAI,CAAC,MAAM,GAAG,MAA6B,CAAC;IAChD,CAAC;IAED;;;;OAIG;IACH,wCAAO,GAAP;QACI,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC;IACvB,CAAC;IAED;;;;;OAKG;IACH,8CAAa,GAAb,UAAc,KAAkB;QAC5B,IAAI,IAAI,CAAC,MAAM,EAAE;YACb,QAAQ,KAAK,CAAC,SAAS,EAAE;gBACrB;oBACI,IAAI,CAAC,kBAAkB,CAAC,IAAI,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;oBAC5C,MAAM;aACb;SACJ;IACL,CAAC;IAEO,mDAAkB,GAA1B,UAA2B,MAA2B,EAAE,KAAyB;QAC7E,IAAM,QAAQ,GAAG,KAAK,CAAC,QAAQ,CAAC;QAEhC,IAAI,CAAC,QAAQ,CAAC,gBAAgB,IAAI,CAAC,KAAK,CAAC,oBAAoB,EAAE;YAC3D,qHAAqH;YACrH,QAAQ,QAAQ,CAAC,GAAG,EAAE;gBAClB,KAAK,WAAW,CAAC;gBACjB,KAAK,QAAQ;oBACT,8CAA8C;oBAC9C,qIAAqI;oBACrI,IAAA,+BAAc,EAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;oBACjC,MAAM;gBAEV,KAAK,OAAO,CAAC;gBACb;oBACI,IAAA,6BAAa,EAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;oBAChC,MAAM;aACb;SACJ;IACL,CAAC;IACL,6BAAC;AAAD,CAAC,AAlED,IAkEC;AAlEY,wDAAsB","sourcesContent":["import { keyboardDelete } from './keyboardDelete';\nimport { keyboardInput } from './keyboardInput';\nimport { PluginEventType } from 'roosterjs-editor-types';\nimport type { IContentModelEditor } from 'roosterjs-content-model-editor';\nimport type {\n EditorPlugin,\n IEditor,\n PluginEvent,\n PluginKeyDownEvent,\n} from 'roosterjs-editor-types';\n\n/**\n * ContentModel 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 */\nexport class ContentModelEditPlugin implements EditorPlugin {\n private editor: IContentModelEditor | null = null;\n\n /**\n * Get name of this plugin\n */\n getName() {\n return 'ContentModelEdit';\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 // TODO: Later we may need a different interface for Content Model editor plugin\n this.editor = editor as IContentModelEditor;\n }\n\n /**\n * The last method that editor will call to a plugin before it is disposed.\n * Plugin can take this chance to clear the reference to editor. After this method is\n * called, plugin should not call to any editor method since it will result in error.\n */\n dispose() {\n this.editor = null;\n }\n\n /**\n * Core method for a plugin. Once an event happens in editor, editor will call this\n * method of each plugin to handle the event as long as the event is not handled\n * exclusively by another plugin.\n * @param event The event to handle:\n */\n onPluginEvent(event: PluginEvent) {\n if (this.editor) {\n switch (event.eventType) {\n case PluginEventType.KeyDown:\n this.handleKeyDownEvent(this.editor, event);\n break;\n }\n }\n }\n\n private handleKeyDownEvent(editor: IContentModelEditor, event: PluginKeyDownEvent) {\n const rawEvent = event.rawEvent;\n\n if (!rawEvent.defaultPrevented && !event.handledByEditFeature) {\n // TODO: Consider use ContentEditFeature and need to hide other conflict features that are not based on Content Model\n switch (rawEvent.key) {\n case 'Backspace':\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 keyboardDelete(editor, rawEvent);\n break;\n\n case 'Enter':\n default:\n keyboardInput(editor, rawEvent);\n break;\n }\n }\n }\n}\n"]}
1
+ {"version":3,"file":"ContentModelEditPlugin.js","sourceRoot":"","sources":["../../../../packages-content-model/roosterjs-content-model-plugins/lib/edit/ContentModelEditPlugin.ts"],"names":[],"mappings":";;;AAAA,mDAAkD;AAClD,iDAAgD;AAQhD;;;;;GAKG;AACH;IAAA;QACY,WAAM,GAA6B,IAAI,CAAC;IAgEpD,CAAC;IA9DG;;OAEG;IACH,wCAAO,GAAP;QACI,OAAO,kBAAkB,CAAC;IAC9B,CAAC;IAED;;;;;OAKG;IACH,2CAAU,GAAV,UAAW,MAAyB;QAChC,gFAAgF;QAChF,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACzB,CAAC;IAED;;;;OAIG;IACH,wCAAO,GAAP;QACI,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC;IACvB,CAAC;IAED;;;;;OAKG;IACH,8CAAa,GAAb,UAAc,KAAkB;QAC5B,IAAI,IAAI,CAAC,MAAM,EAAE;YACb,QAAQ,KAAK,CAAC,SAAS,EAAE;gBACrB,KAAK,SAAS;oBACV,IAAI,CAAC,kBAAkB,CAAC,IAAI,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;oBAC5C,MAAM;aACb;SACJ;IACL,CAAC;IAEO,mDAAkB,GAA1B,UAA2B,MAAyB,EAAE,KAAmB;QACrE,IAAM,QAAQ,GAAG,KAAK,CAAC,QAAQ,CAAC;QAEhC,IAAI,CAAC,QAAQ,CAAC,gBAAgB,IAAI,CAAC,KAAK,CAAC,oBAAoB,EAAE;YAC3D,QAAQ,QAAQ,CAAC,GAAG,EAAE;gBAClB,KAAK,WAAW,CAAC;gBACjB,KAAK,QAAQ;oBACT,8CAA8C;oBAC9C,qIAAqI;oBACrI,IAAA,+BAAc,EAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;oBACjC,MAAM;gBAEV,KAAK,OAAO,CAAC;gBACb;oBACI,IAAA,6BAAa,EAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;oBAChC,MAAM;aACb;SACJ;IACL,CAAC;IACL,6BAAC;AAAD,CAAC,AAjED,IAiEC;AAjEY,wDAAsB","sourcesContent":["import { keyboardDelete } from './keyboardDelete';\nimport { keyboardInput } from './keyboardInput';\nimport type {\n EditorPlugin,\n IStandaloneEditor,\n KeyDownEvent,\n PluginEvent,\n} from 'roosterjs-content-model-types';\n\n/**\n * ContentModel 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 */\nexport class ContentModelEditPlugin implements EditorPlugin {\n private editor: IStandaloneEditor | null = null;\n\n /**\n * Get name of this plugin\n */\n getName() {\n return 'ContentModelEdit';\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: IStandaloneEditor) {\n // TODO: Later we may need a different interface for Content Model editor plugin\n this.editor = editor;\n }\n\n /**\n * The last method that editor will call to a plugin before it is disposed.\n * Plugin can take this chance to clear the reference to editor. After this method is\n * called, plugin should not call to any editor method since it will result in error.\n */\n dispose() {\n this.editor = null;\n }\n\n /**\n * Core method for a plugin. Once an event happens in editor, editor will call this\n * method of each plugin to handle the event as long as the event is not handled\n * exclusively by another plugin.\n * @param event The event to handle:\n */\n onPluginEvent(event: PluginEvent) {\n if (this.editor) {\n switch (event.eventType) {\n case 'keyDown':\n this.handleKeyDownEvent(this.editor, event);\n break;\n }\n }\n }\n\n private handleKeyDownEvent(editor: IStandaloneEditor, event: KeyDownEvent) {\n const rawEvent = event.rawEvent;\n\n if (!rawEvent.defaultPrevented && !event.handledByEditFeature) {\n switch (rawEvent.key) {\n case 'Backspace':\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 keyboardDelete(editor, rawEvent);\n break;\n\n case 'Enter':\n default:\n keyboardInput(editor, rawEvent);\n break;\n }\n }\n }\n}\n"]}
@@ -0,0 +1,5 @@
1
+ import type { DeleteSelectionStep } from 'roosterjs-content-model-types';
2
+ /**
3
+ * @internal
4
+ */
5
+ export declare const deleteList: DeleteSelectionStep;
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.deleteList = void 0;
4
+ var roosterjs_content_model_core_1 = require("roosterjs-content-model-core");
5
+ /**
6
+ * @internal
7
+ */
8
+ var deleteList = function (context) {
9
+ var _a = context.insertPoint, paragraph = _a.paragraph, marker = _a.marker, path = _a.path;
10
+ if (context.deleteResult == 'nothingToDelete' || context.deleteResult == 'notDeleted') {
11
+ var index = (0, roosterjs_content_model_core_1.getClosestAncestorBlockGroupIndex)(path, ['ListItem', 'TableCell']);
12
+ var item = path[index];
13
+ if (index >= 0 &&
14
+ paragraph.segments[0] == marker &&
15
+ item.blockGroupType == 'ListItem' &&
16
+ (paragraph.segments.length == 1 ||
17
+ (paragraph.segments.length == 2 && paragraph.segments[1].segmentType == 'Br'))) {
18
+ item.levels = [];
19
+ context.deleteResult = 'range';
20
+ }
21
+ }
22
+ };
23
+ exports.deleteList = deleteList;
24
+ //# sourceMappingURL=deleteList.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"deleteList.js","sourceRoot":"","sources":["../../../../../packages-content-model/roosterjs-content-model-plugins/lib/edit/deleteSteps/deleteList.ts"],"names":[],"mappings":";;;AAAA,6EAAiF;AAGjF;;GAEG;AACI,IAAM,UAAU,GAAwB,UAAA,OAAO;IAC5C,IAAA,KAA8B,OAAO,CAAC,WAAW,EAA/C,SAAS,eAAA,EAAE,MAAM,YAAA,EAAE,IAAI,UAAwB,CAAC;IAExD,IAAI,OAAO,CAAC,YAAY,IAAI,iBAAiB,IAAI,OAAO,CAAC,YAAY,IAAI,YAAY,EAAE;QACnF,IAAM,KAAK,GAAG,IAAA,gEAAiC,EAAC,IAAI,EAAE,CAAC,UAAU,EAAE,WAAW,CAAC,CAAC,CAAC;QACjF,IAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC;QACzB,IACI,KAAK,IAAI,CAAC;YACV,SAAS,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,MAAM;YAC/B,IAAI,CAAC,cAAc,IAAI,UAAU;YACjC,CAAC,SAAS,CAAC,QAAQ,CAAC,MAAM,IAAI,CAAC;gBAC3B,CAAC,SAAS,CAAC,QAAQ,CAAC,MAAM,IAAI,CAAC,IAAI,SAAS,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,WAAW,IAAI,IAAI,CAAC,CAAC,EACpF;YACE,IAAI,CAAC,MAAM,GAAG,EAAE,CAAC;YACjB,OAAO,CAAC,YAAY,GAAG,OAAO,CAAC;SAClC;KACJ;AACL,CAAC,CAAC;AAjBW,QAAA,UAAU,cAiBrB","sourcesContent":["import { getClosestAncestorBlockGroupIndex } from 'roosterjs-content-model-core';\nimport type { DeleteSelectionStep } from 'roosterjs-content-model-types';\n\n/**\n * @internal\n */\nexport const deleteList: DeleteSelectionStep = context => {\n const { paragraph, marker, path } = context.insertPoint;\n\n if (context.deleteResult == 'nothingToDelete' || context.deleteResult == 'notDeleted') {\n const index = getClosestAncestorBlockGroupIndex(path, ['ListItem', 'TableCell']);\n const item = path[index];\n if (\n index >= 0 &&\n paragraph.segments[0] == marker &&\n item.blockGroupType == 'ListItem' &&\n (paragraph.segments.length == 1 ||\n (paragraph.segments.length == 2 && paragraph.segments[1].segmentType == 'Br'))\n ) {\n item.levels = [];\n context.deleteResult = 'range';\n }\n }\n};\n"]}
@@ -1,10 +1,9 @@
1
- import type { IContentModelEditor } from 'roosterjs-content-model-editor';
2
- import type { ContentModelDocument, DeleteResult, FormatWithContentModelContext } from 'roosterjs-content-model-types';
1
+ import type { ContentModelDocument, DeleteResult, FormatWithContentModelContext, IStandaloneEditor } from 'roosterjs-content-model-types';
3
2
  /**
4
3
  * @internal
5
4
  * @return True means content is changed, so need to rewrite content model to editor. Otherwise false
6
5
  */
7
- export declare function handleKeyboardEventResult(editor: IContentModelEditor, model: ContentModelDocument, rawEvent: KeyboardEvent, result: DeleteResult, context: FormatWithContentModelContext): boolean;
6
+ export declare function handleKeyboardEventResult(editor: IStandaloneEditor, model: ContentModelDocument, rawEvent: KeyboardEvent, result: DeleteResult, context: FormatWithContentModelContext): boolean;
8
7
  /**
9
8
  * @internal
10
9
  */
@@ -30,7 +30,7 @@ function handleKeyboardEventResult(editor, model, rawEvent, result, context) {
30
30
  }
31
31
  // Trigger an event to let plugins know the content is about to be changed by Content Model keyboard editing.
32
32
  // So plugins can do proper handling. e.g. UndoPlugin can decide whether take a snapshot before this change happens.
33
- editor.triggerPluginEvent(23 /* BeforeKeyboardEditing */, {
33
+ editor.triggerEvent('beforeKeyboardEditing', {
34
34
  rawEvent: rawEvent,
35
35
  });
36
36
  return true;
@@ -1 +1 @@
1
- {"version":3,"file":"handleKeyboardEventCommon.js","sourceRoot":"","sources":["../../../../packages-content-model/roosterjs-content-model-plugins/lib/edit/handleKeyboardEventCommon.ts"],"names":[],"mappings":";;;AAAA,2EAAoE;AASpE;;;GAGG;AACH,SAAgB,yBAAyB,CACrC,MAA2B,EAC3B,KAA2B,EAC3B,QAAuB,EACvB,MAAoB,EACpB,OAAsC;IAEtC,OAAO,CAAC,gBAAgB,GAAG,IAAI,CAAC;IAChC,OAAO,CAAC,eAAe,GAAG,KAAK,CAAC;IAEhC,QAAQ,MAAM,EAAE;QACZ,KAAK,YAAY;YACb,kHAAkH;YAClH,OAAO,CAAC,eAAe,GAAG,IAAI,CAAC;YAE/B,6GAA6G;YAC7G,OAAO,KAAK,CAAC;QAEjB,KAAK,iBAAiB;YAClB,sFAAsF;YACtF,QAAQ,CAAC,cAAc,EAAE,CAAC;YAC1B,OAAO,KAAK,CAAC;QAEjB,KAAK,OAAO,CAAC;QACb,KAAK,YAAY;YACb,kGAAkG;YAClG,QAAQ,CAAC,cAAc,EAAE,CAAC;YAC1B,IAAA,mDAAqB,EAAC,KAAK,CAAC,CAAC;YAE7B,IAAI,MAAM,IAAI,OAAO,EAAE;gBACnB,sEAAsE;gBACtE,OAAO,CAAC,gBAAgB,GAAG,KAAK,CAAC;aACpC;YAED,6GAA6G;YAC7G,oHAAoH;YACpH,MAAM,CAAC,kBAAkB,iCAAwC;gBAC7D,QAAQ,UAAA;aACX,CAAC,CAAC;YAEH,OAAO,IAAI,CAAC;KACnB;AACL,CAAC;AA1CD,8DA0CC;AAED;;GAEG;AACH,SAAgB,gBAAgB,CAAC,QAAuB,EAAE,KAAc;IACpE,OAAO,CACH,CAAC,KAAK,IAAI,QAAQ,CAAC,MAAM,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC;QAC/C,CAAC,CAAC,KAAK,IAAI,QAAQ,CAAC,OAAO,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,CACnD,CAAC;AACN,CAAC;AALD,4CAKC;AAED;;GAEG;AACH,SAAgB,6BAA6B,CAAC,QAAuB;IACjE,OAAO,QAAQ,CAAC,OAAO,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC;AAChD,CAAC;AAFD,sEAEC","sourcesContent":["import { normalizeContentModel } from 'roosterjs-content-model-dom';\nimport { PluginEventType } from 'roosterjs-editor-types';\nimport type { IContentModelEditor } from 'roosterjs-content-model-editor';\nimport type {\n ContentModelDocument,\n DeleteResult,\n FormatWithContentModelContext,\n} from 'roosterjs-content-model-types';\n\n/**\n * @internal\n * @return True means content is changed, so need to rewrite content model to editor. Otherwise false\n */\nexport function handleKeyboardEventResult(\n editor: IContentModelEditor,\n model: ContentModelDocument,\n rawEvent: KeyboardEvent,\n result: DeleteResult,\n context: FormatWithContentModelContext\n): boolean {\n context.skipUndoSnapshot = true;\n context.clearModelCache = false;\n\n switch (result) {\n case 'notDeleted':\n // We have not delete anything, we will let browser handle this event, so that current cached model may be invalid\n context.clearModelCache = true;\n\n // Return false here since we didn't do any change to Content Model, so no need to rewrite with Content Model\n return false;\n\n case 'nothingToDelete':\n // We known there is nothing to delete, no need to let browser keep handling the event\n rawEvent.preventDefault();\n return false;\n\n case 'range':\n case 'singleChar':\n // We have deleted what we need from content model, no need to let browser keep handling the event\n rawEvent.preventDefault();\n normalizeContentModel(model);\n\n if (result == 'range') {\n // A range is about to be deleted, so add an undo snapshot immediately\n context.skipUndoSnapshot = false;\n }\n\n // Trigger an event to let plugins know the content is about to be changed by Content Model keyboard editing.\n // So plugins can do proper handling. e.g. UndoPlugin can decide whether take a snapshot before this change happens.\n editor.triggerPluginEvent(PluginEventType.BeforeKeyboardEditing, {\n rawEvent,\n });\n\n return true;\n }\n}\n\n/**\n * @internal\n */\nexport function shouldDeleteWord(rawEvent: KeyboardEvent, isMac: boolean) {\n return (\n (isMac && rawEvent.altKey && !rawEvent.metaKey) ||\n (!isMac && rawEvent.ctrlKey && !rawEvent.altKey)\n );\n}\n\n/**\n * @internal\n */\nexport function shouldDeleteAllSegmentsBefore(rawEvent: KeyboardEvent) {\n return rawEvent.metaKey && !rawEvent.altKey;\n}\n"]}
1
+ {"version":3,"file":"handleKeyboardEventCommon.js","sourceRoot":"","sources":["../../../../packages-content-model/roosterjs-content-model-plugins/lib/edit/handleKeyboardEventCommon.ts"],"names":[],"mappings":";;;AAAA,2EAAoE;AAQpE;;;GAGG;AACH,SAAgB,yBAAyB,CACrC,MAAyB,EACzB,KAA2B,EAC3B,QAAuB,EACvB,MAAoB,EACpB,OAAsC;IAEtC,OAAO,CAAC,gBAAgB,GAAG,IAAI,CAAC;IAChC,OAAO,CAAC,eAAe,GAAG,KAAK,CAAC;IAEhC,QAAQ,MAAM,EAAE;QACZ,KAAK,YAAY;YACb,kHAAkH;YAClH,OAAO,CAAC,eAAe,GAAG,IAAI,CAAC;YAE/B,6GAA6G;YAC7G,OAAO,KAAK,CAAC;QAEjB,KAAK,iBAAiB;YAClB,sFAAsF;YACtF,QAAQ,CAAC,cAAc,EAAE,CAAC;YAC1B,OAAO,KAAK,CAAC;QAEjB,KAAK,OAAO,CAAC;QACb,KAAK,YAAY;YACb,kGAAkG;YAClG,QAAQ,CAAC,cAAc,EAAE,CAAC;YAC1B,IAAA,mDAAqB,EAAC,KAAK,CAAC,CAAC;YAE7B,IAAI,MAAM,IAAI,OAAO,EAAE;gBACnB,sEAAsE;gBACtE,OAAO,CAAC,gBAAgB,GAAG,KAAK,CAAC;aACpC;YAED,6GAA6G;YAC7G,oHAAoH;YACpH,MAAM,CAAC,YAAY,CAAC,uBAAuB,EAAE;gBACzC,QAAQ,UAAA;aACX,CAAC,CAAC;YAEH,OAAO,IAAI,CAAC;KACnB;AACL,CAAC;AA1CD,8DA0CC;AAED;;GAEG;AACH,SAAgB,gBAAgB,CAAC,QAAuB,EAAE,KAAc;IACpE,OAAO,CACH,CAAC,KAAK,IAAI,QAAQ,CAAC,MAAM,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC;QAC/C,CAAC,CAAC,KAAK,IAAI,QAAQ,CAAC,OAAO,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,CACnD,CAAC;AACN,CAAC;AALD,4CAKC;AAED;;GAEG;AACH,SAAgB,6BAA6B,CAAC,QAAuB;IACjE,OAAO,QAAQ,CAAC,OAAO,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC;AAChD,CAAC;AAFD,sEAEC","sourcesContent":["import { normalizeContentModel } from 'roosterjs-content-model-dom';\nimport type {\n ContentModelDocument,\n DeleteResult,\n FormatWithContentModelContext,\n IStandaloneEditor,\n} from 'roosterjs-content-model-types';\n\n/**\n * @internal\n * @return True means content is changed, so need to rewrite content model to editor. Otherwise false\n */\nexport function handleKeyboardEventResult(\n editor: IStandaloneEditor,\n model: ContentModelDocument,\n rawEvent: KeyboardEvent,\n result: DeleteResult,\n context: FormatWithContentModelContext\n): boolean {\n context.skipUndoSnapshot = true;\n context.clearModelCache = false;\n\n switch (result) {\n case 'notDeleted':\n // We have not delete anything, we will let browser handle this event, so that current cached model may be invalid\n context.clearModelCache = true;\n\n // Return false here since we didn't do any change to Content Model, so no need to rewrite with Content Model\n return false;\n\n case 'nothingToDelete':\n // We known there is nothing to delete, no need to let browser keep handling the event\n rawEvent.preventDefault();\n return false;\n\n case 'range':\n case 'singleChar':\n // We have deleted what we need from content model, no need to let browser keep handling the event\n rawEvent.preventDefault();\n normalizeContentModel(model);\n\n if (result == 'range') {\n // A range is about to be deleted, so add an undo snapshot immediately\n context.skipUndoSnapshot = false;\n }\n\n // Trigger an event to let plugins know the content is about to be changed by Content Model keyboard editing.\n // So plugins can do proper handling. e.g. UndoPlugin can decide whether take a snapshot before this change happens.\n editor.triggerEvent('beforeKeyboardEditing', {\n rawEvent,\n });\n\n return true;\n }\n}\n\n/**\n * @internal\n */\nexport function shouldDeleteWord(rawEvent: KeyboardEvent, isMac: boolean) {\n return (\n (isMac && rawEvent.altKey && !rawEvent.metaKey) ||\n (!isMac && rawEvent.ctrlKey && !rawEvent.altKey)\n );\n}\n\n/**\n * @internal\n */\nexport function shouldDeleteAllSegmentsBefore(rawEvent: KeyboardEvent) {\n return rawEvent.metaKey && !rawEvent.altKey;\n}\n"]}
@@ -1,8 +1,8 @@
1
- import type { IContentModelEditor } from 'roosterjs-content-model-editor';
1
+ import type { IStandaloneEditor } from 'roosterjs-content-model-types';
2
2
  /**
3
3
  * @internal
4
4
  * Do keyboard event handling for DELETE/BACKSPACE key
5
5
  * @param editor The Content Model Editor
6
6
  * @param rawEvent DOM keyboard event
7
7
  */
8
- export declare function keyboardDelete(editor: IContentModelEditor, rawEvent: KeyboardEvent): true | undefined;
8
+ export declare function keyboardDelete(editor: IStandaloneEditor, rawEvent: KeyboardEvent): true | undefined;
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.keyboardDelete = void 0;
4
4
  var roosterjs_content_model_core_1 = require("roosterjs-content-model-core");
5
5
  var deleteAllSegmentBefore_1 = require("./deleteSteps/deleteAllSegmentBefore");
6
+ var deleteList_1 = require("./deleteSteps/deleteList");
6
7
  var roosterjs_content_model_dom_1 = require("roosterjs-content-model-dom");
7
8
  var handleKeyboardEventCommon_1 = require("./handleKeyboardEventCommon");
8
9
  var deleteWordSelection_1 = require("./deleteSteps/deleteWordSelection");
@@ -40,7 +41,13 @@ function getDeleteSteps(rawEvent, isMac) {
40
41
  var deleteCollapsedSelection = isForward
41
42
  ? deleteCollapsedSelection_1.forwardDeleteCollapsedSelection
42
43
  : deleteCollapsedSelection_1.backwardDeleteCollapsedSelection;
43
- return [deleteAllSegmentBeforeStep, deleteWordSelection, deleteCollapsedSelection];
44
+ var deleteListStep = !isForward ? deleteList_1.deleteList : null;
45
+ return [
46
+ deleteAllSegmentBeforeStep,
47
+ deleteWordSelection,
48
+ deleteCollapsedSelection,
49
+ deleteListStep,
50
+ ];
44
51
  }
45
52
  function shouldDeleteWithContentModel(selection, rawEvent) {
46
53
  if (!selection) {
@@ -1 +1 @@
1
- {"version":3,"file":"keyboardDelete.js","sourceRoot":"","sources":["../../../../packages-content-model/roosterjs-content-model-plugins/lib/edit/keyboardDelete.ts"],"names":[],"mappings":";;;AAAA,6EAA4F;AAC5F,+EAA8E;AAC9E,2EAA2D;AAC3D,yEAIqC;AACrC,yEAG2C;AAC3C,mFAGgD;AAIhD;;;;;GAKG;AACH,SAAgB,cAAc,CAAC,MAA2B,EAAE,QAAuB;IAC/E,IAAM,SAAS,GAAG,MAAM,CAAC,eAAe,EAAE,CAAC;IAE3C,IAAI,4BAA4B,CAAC,SAAS,EAAE,QAAQ,CAAC,EAAE;QACnD,MAAM,CAAC,kBAAkB,CACrB,UAAC,KAAK,EAAE,OAAO;YACX,IAAM,MAAM,GAAG,IAAA,8CAAe,EAC1B,KAAK,EACL,cAAc,CAAC,QAAQ,EAAE,CAAC,CAAC,MAAM,CAAC,cAAc,EAAE,CAAC,KAAK,CAAC,EACzD,OAAO,CACV,CAAC,YAAY,CAAC;YAEf,OAAO,IAAA,qDAAyB,EAAC,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;QAC/E,CAAC,EACD;YACI,QAAQ,UAAA;YACR,YAAY,EAAE,2CAAY,CAAC,QAAQ;YACnC,aAAa,EAAE,cAAM,OAAA,QAAQ,CAAC,KAAK,EAAd,CAAc;YACnC,OAAO,EAAE,QAAQ,CAAC,GAAG,IAAI,QAAQ,CAAC,CAAC,CAAC,iBAAiB,CAAC,CAAC,CAAC,oBAAoB;SAC/E,CACJ,CAAC;QAEF,OAAO,IAAI,CAAC;KACf;AACL,CAAC;AAxBD,wCAwBC;AAED,SAAS,cAAc,CAAC,QAAuB,EAAE,KAAc;IAC3D,IAAM,SAAS,GAAG,QAAQ,CAAC,GAAG,IAAI,QAAQ,CAAC;IAC3C,IAAM,0BAA0B,GAC5B,IAAA,yDAA6B,EAAC,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC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AW,GAAG,CAAC,MAAA,MAAA,KAAK,CAAC,cAAc,CAAC,SAAS,0CAAE,MAAM,mCAAI,CAAC,CAAC,GAAG,CAAC,CACxE,CAAC;AACN,CAAC","sourcesContent":["import { ChangeSource, deleteSelection, isModifierKey } from 'roosterjs-content-model-core';\nimport { deleteAllSegmentBefore } from './deleteSteps/deleteAllSegmentBefore';\nimport { isNodeOfType } from 'roosterjs-content-model-dom';\nimport {\n handleKeyboardEventResult,\n shouldDeleteAllSegmentsBefore,\n shouldDeleteWord,\n} from './handleKeyboardEventCommon';\nimport {\n backwardDeleteWordSelection,\n forwardDeleteWordSelection,\n} from './deleteSteps/deleteWordSelection';\nimport {\n backwardDeleteCollapsedSelection,\n forwardDeleteCollapsedSelection,\n} from './deleteSteps/deleteCollapsedSelection';\nimport type { IContentModelEditor } from 'roosterjs-content-model-editor';\nimport type { DOMSelection, DeleteSelectionStep } from 'roosterjs-content-model-types';\n\n/**\n * @internal\n * Do keyboard event handling for DELETE/BACKSPACE key\n * @param editor The Content Model Editor\n * @param rawEvent DOM keyboard event\n */\nexport function keyboardDelete(editor: IContentModelEditor, rawEvent: KeyboardEvent) {\n const selection = editor.getDOMSelection();\n\n if (shouldDeleteWithContentModel(selection, rawEvent)) {\n editor.formatContentModel(\n (model, context) => {\n const result = deleteSelection(\n model,\n getDeleteSteps(rawEvent, !!editor.getEnvironment().isMac),\n context\n ).deleteResult;\n\n return handleKeyboardEventResult(editor, model, rawEvent, result, context);\n },\n {\n rawEvent,\n changeSource: ChangeSource.Keyboard,\n getChangeData: () => rawEvent.which,\n apiName: rawEvent.key == 'Delete' ? 'handleDeleteKey' : 'handleBackspaceKey',\n }\n );\n\n return true;\n }\n}\n\nfunction getDeleteSteps(rawEvent: KeyboardEvent, isMac: boolean): (DeleteSelectionStep | null)[] {\n const isForward = rawEvent.key == 'Delete';\n const deleteAllSegmentBeforeStep =\n shouldDeleteAllSegmentsBefore(rawEvent) && !isForward ? deleteAllSegmentBefore : null;\n const deleteWordSelection = shouldDeleteWord(rawEvent, isMac)\n ? isForward\n ? forwardDeleteWordSelection\n : backwardDeleteWordSelection\n : null;\n const deleteCollapsedSelection = isForward\n ? forwardDeleteCollapsedSelection\n : backwardDeleteCollapsedSelection;\n return [deleteAllSegmentBeforeStep, deleteWordSelection, deleteCollapsedSelection];\n}\n\nfunction shouldDeleteWithContentModel(selection: DOMSelection | null, rawEvent: KeyboardEvent) {\n if (!selection) {\n return false; // Nothing to delete\n } else if (selection.type != 'range' || !selection.range.collapsed) {\n return true; // Selection is not collapsed, need to delete all selections\n } else {\n const range = selection.range;\n\n // When selection is collapsed and is in middle of text node, no need to use Content Model to delete\n return !(\n isNodeOfType(range.startContainer, 'TEXT_NODE') &&\n !isModifierKey(rawEvent) &&\n (canDeleteBefore(rawEvent, range) || canDeleteAfter(rawEvent, range))\n );\n }\n}\n\nfunction canDeleteBefore(rawEvent: KeyboardEvent, range: Range) {\n return rawEvent.key == 'Backspace' && range.startOffset > 1;\n}\n\nfunction canDeleteAfter(rawEvent: KeyboardEvent, range: Range) {\n return (\n rawEvent.key == 'Delete' &&\n range.startOffset < (range.startContainer.nodeValue?.length ?? 0) - 1\n );\n}\n"]}
1
+ {"version":3,"file":"keyboardDelete.js","sourceRoot":"","sources":["../../../../packages-content-model/roosterjs-content-model-plugins/lib/edit/keyboardDelete.ts"],"names":[],"mappings":";;;AAAA,6EAA4F;AAC5F,+EAA8E;AAC9E,uDAAsD;AACtD,2EAA2D;AAC3D,yEAIqC;AACrC,yEAG2C;AAC3C,mFAGgD;AAOhD;;;;;GAKG;AACH,SAAgB,cAAc,CAAC,MAAyB,EAAE,QAAuB;IAC7E,IAAM,SAAS,GAAG,MAAM,CAAC,eAAe,EAAE,CAAC;IAE3C,IAAI,4BAA4B,CAAC,SAAS,EAAE,QAAQ,CAAC,EAAE;QACnD,MAAM,CAAC,kBAAkB,CACrB,UAAC,KAAK,EAAE,OAAO;YACX,IAAM,MAAM,GAAG,IAAA,8CAAe,EAC1B,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;AAED,SAAS,4BAA4B,CAAC,SAA8B,EAAE,QAAuB;IACzF,IAAI,CAAC,SAAS,EAAE;QACZ,OAAO,KAAK,CAAC,CAAC,oBAAoB;KACrC;SAAM,IAAI,SAAS,CAAC,IAAI,IAAI,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,SAAS,EAAE;QAChE,OAAO,IAAI,CAAC,CAAC,4DAA4D;KAC5E;SAAM;QACH,IAAM,KAAK,GAAG,SAAS,CAAC,KAAK,CAAC;QAE9B,oGAAoG;QACpG,OAAO,CAAC,CACJ,IAAA,0CAAY,EAAC,KAAK,CAAC,cAAc,EAAE,WAAW,CAAC;YAC/C,CAAC,IAAA,4CAAa,EAAC,QAAQ,CAAC;YACxB,CAAC,eAAe,CAAC,QAAQ,EAAE,KAAK,CAAC,IAAI,cAAc,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC,CACxE,CAAC;KACL;AACL,CAAC;AAED,SAAS,eAAe,CAAC,QAAuB,EAAE,KAAY;IAC1D,OAAO,QAAQ,CAAC,GAAG,IAAI,WAAW,IAAI,KAAK,CAAC,WAAW,GAAG,CAAC,CAAC;AAChE,CAAC;AAED,SAAS,cAAc,CAAC,QAAuB,EAAE,KAAY;;IACzD,OAAO,CACH,QAAQ,CAAC,GAAG,IAAI,QAAQ;QACxB,KAAK,CAAC,WAAW,GAAG,CAAC,MAAA,MAAA,KAAK,CAAC,cAAc,CAAC,SAAS,0CAAE,MAAM,mCAAI,CAAC,CAAC,GAAG,CAAC,CACxE,CAAC;AACN,CAAC","sourcesContent":["import { ChangeSource, deleteSelection, isModifierKey } from 'roosterjs-content-model-core';\nimport { deleteAllSegmentBefore } from './deleteSteps/deleteAllSegmentBefore';\nimport { deleteList } from './deleteSteps/deleteList';\nimport { isNodeOfType } from 'roosterjs-content-model-dom';\nimport {\n handleKeyboardEventResult,\n shouldDeleteAllSegmentsBefore,\n shouldDeleteWord,\n} from './handleKeyboardEventCommon';\nimport {\n backwardDeleteWordSelection,\n forwardDeleteWordSelection,\n} from './deleteSteps/deleteWordSelection';\nimport {\n backwardDeleteCollapsedSelection,\n forwardDeleteCollapsedSelection,\n} from './deleteSteps/deleteCollapsedSelection';\nimport type {\n DOMSelection,\n DeleteSelectionStep,\n IStandaloneEditor,\n} from 'roosterjs-content-model-types';\n\n/**\n * @internal\n * Do keyboard event handling for DELETE/BACKSPACE key\n * @param editor The Content Model Editor\n * @param rawEvent DOM keyboard event\n */\nexport function keyboardDelete(editor: IStandaloneEditor, rawEvent: KeyboardEvent) {\n const selection = editor.getDOMSelection();\n\n if (shouldDeleteWithContentModel(selection, rawEvent)) {\n editor.formatContentModel(\n (model, context) => {\n const result = deleteSelection(\n model,\n getDeleteSteps(rawEvent, !!editor.getEnvironment().isMac),\n context\n ).deleteResult;\n\n return handleKeyboardEventResult(editor, model, rawEvent, result, context);\n },\n {\n rawEvent,\n changeSource: ChangeSource.Keyboard,\n getChangeData: () => rawEvent.which,\n apiName: rawEvent.key == 'Delete' ? 'handleDeleteKey' : 'handleBackspaceKey',\n }\n );\n\n return true;\n }\n}\n\nfunction getDeleteSteps(rawEvent: KeyboardEvent, isMac: boolean): (DeleteSelectionStep | null)[] {\n const isForward = rawEvent.key == 'Delete';\n const deleteAllSegmentBeforeStep =\n shouldDeleteAllSegmentsBefore(rawEvent) && !isForward ? deleteAllSegmentBefore : null;\n const deleteWordSelection = shouldDeleteWord(rawEvent, isMac)\n ? isForward\n ? forwardDeleteWordSelection\n : backwardDeleteWordSelection\n : null;\n const deleteCollapsedSelection = isForward\n ? forwardDeleteCollapsedSelection\n : backwardDeleteCollapsedSelection;\n const deleteListStep = !isForward ? deleteList : null;\n return [\n deleteAllSegmentBeforeStep,\n deleteWordSelection,\n deleteCollapsedSelection,\n deleteListStep,\n ];\n}\n\nfunction shouldDeleteWithContentModel(selection: DOMSelection | null, rawEvent: KeyboardEvent) {\n if (!selection) {\n return false; // Nothing to delete\n } else if (selection.type != 'range' || !selection.range.collapsed) {\n return true; // Selection is not collapsed, need to delete all selections\n } else {\n const range = selection.range;\n\n // When selection is collapsed and is in middle of text node, no need to use Content Model to delete\n return !(\n isNodeOfType(range.startContainer, 'TEXT_NODE') &&\n !isModifierKey(rawEvent) &&\n (canDeleteBefore(rawEvent, range) || canDeleteAfter(rawEvent, range))\n );\n }\n}\n\nfunction canDeleteBefore(rawEvent: KeyboardEvent, range: Range) {\n return rawEvent.key == 'Backspace' && range.startOffset > 1;\n}\n\nfunction canDeleteAfter(rawEvent: KeyboardEvent, range: Range) {\n return (\n rawEvent.key == 'Delete' &&\n range.startOffset < (range.startContainer.nodeValue?.length ?? 0) - 1\n );\n}\n"]}
@@ -1,5 +1,5 @@
1
- import type { IContentModelEditor } from 'roosterjs-content-model-editor';
1
+ import type { IStandaloneEditor } from 'roosterjs-content-model-types';
2
2
  /**
3
3
  * @internal
4
4
  */
5
- export declare function keyboardInput(editor: IContentModelEditor, rawEvent: KeyboardEvent): true | undefined;
5
+ export declare function keyboardInput(editor: IStandaloneEditor, rawEvent: KeyboardEvent): true | undefined;
@@ -1 +1 @@
1
- {"version":3,"file":"keyboardInput.js","sourceRoot":"","sources":["../../../../packages-content-model/roosterjs-content-model-plugins/lib/edit/keyboardInput.ts"],"names":[],"mappings":";;;AAAA,6EAA8E;AAC9E,2EAAoE;AAIpE;;GAEG;AACH,SAAgB,aAAa,CAAC,MAA2B,EAAE,QAAuB;IAC9E,IAAM,SAAS,GAAG,MAAM,CAAC,eAAe,EAAE,CAAC;IAE3C,IAAI,2BAA2B,CAAC,SAAS,EAAE,QAAQ,EAAE,MAAM,CAAC,OAAO,EAAE,CAAC,EAAE;QACpE,MAAM,CAAC,YAAY,EAAE,CAAC;QAEtB,MAAM,CAAC,kBAAkB,CACrB,UAAC,KAAK,EAAE,OAAO;;YACX,IAAM,MAAM,GAAG,IAAA,8CAAe,EAAC,KAAK,EAAE,EAAE,EAAE,OAAO,CAAC,CAAC;YAEnD,0EAA0E;YAC1E,qFAAqF;YACrF,OAAO,CAAC,eAAe,GAAG,IAAI,CAAC;YAE/B,oJAAoJ;YACpJ,OAAO,CAAC,gBAAgB,GAAG,IAAI,CAAC;YAEhC,IAAI,MAAM,CAAC,YAAY,IAAI,OAAO,EAAE;gBAChC,2HAA2H;gBAC3H,OAAO,CAAC,gBAAgB,GAAG,MAAA,MAAM,CAAC,WAAW,0CAAE,MAAM,CAAC,MAAM,CAAC;gBAE7D,IAAA,mDAAqB,EAAC,KAAK,CAAC,CAAC;gBAE7B,sFAAsF;gBACtF,OAAO,IAAI,CAAC;aACf;iBAAM;gBACH,OAAO,KAAK,CAAC;aAChB;QACL,CAAC,EACD;YACI,QAAQ,UAAA;SACX,CACJ,CAAC;QAEF,OAAO,IAAI,CAAC;KACf;AACL,CAAC;AApCD,sCAoCC;AAED,SAAS,2BAA2B,CAChC,SAA8B,EAC9B,QAAuB,EACvB,OAAgB;IAEhB,IAAI,CAAC,SAAS,EAAE;QACZ,OAAO,KAAK,CAAC,CAAC,oBAAoB;KACrC;SAAM,IACH,CAAC,IAAA,4CAAa,EAAC,QAAQ,CAAC;QACxB,CAAC,QAAQ,CAAC,GAAG,IAAI,OAAO,IAAI,QAAQ,CAAC,GAAG,IAAI,OAAO,IAAI,QAAQ,CAAC,GAAG,CAAC,MAAM,IAAI,CAAC,CAAC,EAClF;QACE,OAAO,CACH,SAAS,CAAC,IAAI,IAAI,OAAO;YACzB,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,SAAS,IAAI,CAAC,QAAQ,CAAC,WAAW,IAAI,CAAC,OAAO,CAAC,CACpE,CAAC,CAAC,0DAA0D;KAChE;SAAM;QACH,OAAO,KAAK,CAAC;KAChB;AACL,CAAC","sourcesContent":["import { deleteSelection, isModifierKey } from 'roosterjs-content-model-core';\nimport { normalizeContentModel } from 'roosterjs-content-model-dom';\nimport type { IContentModelEditor } from 'roosterjs-content-model-editor';\nimport type { DOMSelection } from 'roosterjs-content-model-types';\n\n/**\n * @internal\n */\nexport function keyboardInput(editor: IContentModelEditor, rawEvent: KeyboardEvent) {\n const selection = editor.getDOMSelection();\n\n if (shouldInputWithContentModel(selection, rawEvent, editor.isInIME())) {\n editor.takeSnapshot();\n\n editor.formatContentModel(\n (model, context) => {\n const result = deleteSelection(model, [], context);\n\n // We have deleted selection then we will let browser to handle the input.\n // With this combined operation, we don't wan to mass up the cached model so clear it\n context.clearModelCache = true;\n\n // Skip undo snapshot here and add undo snapshot before the operation so that we don't add another undo snapshot in middle of this replace operation\n context.skipUndoSnapshot = true;\n\n if (result.deleteResult == 'range') {\n // We have deleted something, next input should inherit the segment format from deleted content, so set pending format here\n context.newPendingFormat = result.insertPoint?.marker.format;\n\n normalizeContentModel(model);\n\n // Do not preventDefault since we still want browser to handle the final input for now\n return true;\n } else {\n return false;\n }\n },\n {\n rawEvent,\n }\n );\n\n return true;\n }\n}\n\nfunction shouldInputWithContentModel(\n selection: DOMSelection | null,\n rawEvent: KeyboardEvent,\n isInIME: boolean\n) {\n if (!selection) {\n return false; // Nothing to delete\n } else if (\n !isModifierKey(rawEvent) &&\n (rawEvent.key == 'Enter' || rawEvent.key == 'Space' || rawEvent.key.length == 1)\n ) {\n return (\n selection.type != 'range' ||\n (!selection.range.collapsed && !rawEvent.isComposing && !isInIME)\n ); // TODO: Also handle Enter key even selection is collapsed\n } else {\n return false;\n }\n}\n"]}
1
+ {"version":3,"file":"keyboardInput.js","sourceRoot":"","sources":["../../../../packages-content-model/roosterjs-content-model-plugins/lib/edit/keyboardInput.ts"],"names":[],"mappings":";;;AAAA,6EAA8E;AAC9E,2EAAoE;AAGpE;;GAEG;AACH,SAAgB,aAAa,CAAC,MAAyB,EAAE,QAAuB;IAC5E,IAAM,SAAS,GAAG,MAAM,CAAC,eAAe,EAAE,CAAC;IAE3C,IAAI,2BAA2B,CAAC,SAAS,EAAE,QAAQ,EAAE,MAAM,CAAC,OAAO,EAAE,CAAC,EAAE;QACpE,MAAM,CAAC,YAAY,EAAE,CAAC;QAEtB,MAAM,CAAC,kBAAkB,CACrB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content-model-core';\nimport { normalizeContentModel } from 'roosterjs-content-model-dom';\nimport type { DOMSelection, IStandaloneEditor } from 'roosterjs-content-model-types';\n\n/**\n * @internal\n */\nexport function keyboardInput(editor: IStandaloneEditor, rawEvent: KeyboardEvent) {\n const selection = editor.getDOMSelection();\n\n if (shouldInputWithContentModel(selection, rawEvent, editor.isInIME())) {\n editor.takeSnapshot();\n\n editor.formatContentModel(\n (model, context) => {\n const result = deleteSelection(model, [], context);\n\n // We have deleted selection then we will let browser to handle the input.\n // With this combined operation, we don't wan to mass up the cached model so clear it\n context.clearModelCache = true;\n\n // Skip undo snapshot here and add undo snapshot before the operation so that we don't add another undo snapshot in middle of this replace operation\n context.skipUndoSnapshot = true;\n\n if (result.deleteResult == 'range') {\n // We have deleted something, next input should inherit the segment format from deleted content, so set pending format here\n context.newPendingFormat = result.insertPoint?.marker.format;\n\n normalizeContentModel(model);\n\n // Do not preventDefault since we still want browser to handle the final input for now\n return true;\n } else {\n return false;\n }\n },\n {\n rawEvent,\n }\n );\n\n return true;\n }\n}\n\nfunction shouldInputWithContentModel(\n selection: DOMSelection | null,\n rawEvent: KeyboardEvent,\n isInIME: boolean\n) {\n if (!selection) {\n return false; // Nothing to delete\n } else if (\n !isModifierKey(rawEvent) &&\n (rawEvent.key == 'Enter' || rawEvent.key == 'Space' || rawEvent.key.length == 1)\n ) {\n return (\n selection.type != 'range' ||\n (!selection.range.collapsed && !rawEvent.isComposing && !isInIME)\n ); // TODO: Also handle Enter key even selection is collapsed\n } else {\n return false;\n }\n}\n"]}
@@ -1,4 +1,4 @@
1
- import type { EditorPlugin, IEditor, PluginEvent } from 'roosterjs-editor-types';
1
+ import type { EditorPlugin, IStandaloneEditor, PluginEvent } from 'roosterjs-content-model-types';
2
2
  /**
3
3
  * Paste plugin, handles BeforePaste event and reformat some special content, including:
4
4
  * 1. Content copied from Word
@@ -26,7 +26,7 @@ export declare class ContentModelPastePlugin implements EditorPlugin {
26
26
  * editor reference so that it can call to any editor method or format API later.
27
27
  * @param editor The editor object
28
28
  */
29
- initialize(editor: IEditor): void;
29
+ initialize(editor: IStandaloneEditor): void;
30
30
  /**
31
31
  * The last method that editor will call to a plugin before it is disposed.
32
32
  * Plugin can take this chance to clear the reference to editor. After this method is
@@ -1,5 +1,4 @@
1
1
  "use strict";
2
- var _a;
3
2
  Object.defineProperty(exports, "__esModule", { value: true });
4
3
  exports.ContentModelPastePlugin = void 0;
5
4
  var addParser_1 = require("./utils/addParser");
@@ -7,18 +6,11 @@ var roosterjs_content_model_dom_1 = require("roosterjs-content-model-dom");
7
6
  var deprecatedColorParser_1 = require("./utils/deprecatedColorParser");
8
7
  var getPasteSource_1 = require("./pasteSourceValidations/getPasteSource");
9
8
  var linkParser_1 = require("./utils/linkParser");
9
+ var constants_1 = require("./pasteSourceValidations/constants");
10
10
  var processPastedContentFromExcel_1 = require("./Excel/processPastedContentFromExcel");
11
11
  var processPastedContentFromPowerPoint_1 = require("./PowerPoint/processPastedContentFromPowerPoint");
12
12
  var processPastedContentFromWordDesktop_1 = require("./WordDesktop/processPastedContentFromWordDesktop");
13
13
  var processPastedContentWacComponents_1 = require("./WacComponents/processPastedContentWacComponents");
14
- // Map old PasteType to new PasteType
15
- // TODO: We can remove this once we have standalone editor
16
- var PasteTypeMap = (_a = {},
17
- _a[3 /* AsImage */] = 'asImage',
18
- _a[1 /* AsPlainText */] = 'asPlainText',
19
- _a[2 /* MergeFormat */] = 'mergeFormat',
20
- _a[0 /* Normal */] = 'normal',
21
- _a);
22
14
  /**
23
15
  * Paste plugin, handles BeforePaste event and reformat some special content, including:
24
16
  * 1. Content copied from Word
@@ -68,43 +60,42 @@ var ContentModelPastePlugin = /** @class */ (function () {
68
60
  * @param event The event to handle:
69
61
  */
70
62
  ContentModelPastePlugin.prototype.onPluginEvent = function (event) {
71
- if (!this.editor || event.eventType != 10 /* BeforePaste */) {
63
+ if (!this.editor || event.eventType != 'beforePaste') {
72
64
  return;
73
65
  }
74
- var ev = event;
75
- if (!ev.domToModelOption) {
66
+ if (!event.domToModelOption) {
76
67
  return;
77
68
  }
78
- var pasteSource = (0, getPasteSource_1.getPasteSource)(ev, false);
79
- var pasteType = PasteTypeMap[ev.pasteType];
69
+ var pasteSource = (0, getPasteSource_1.getPasteSource)(event, false);
70
+ var pasteType = event.pasteType;
80
71
  switch (pasteSource) {
81
72
  case 'wordDesktop':
82
- (0, processPastedContentFromWordDesktop_1.processPastedContentFromWordDesktop)(ev, this.editor.getTrustedHTMLHandler());
73
+ (0, processPastedContentFromWordDesktop_1.processPastedContentFromWordDesktop)(event, this.editor.getTrustedHTMLHandler());
83
74
  break;
84
75
  case 'wacComponents':
85
- (0, processPastedContentWacComponents_1.processPastedContentWacComponents)(ev);
76
+ (0, processPastedContentWacComponents_1.processPastedContentWacComponents)(event);
86
77
  break;
87
78
  case 'excelOnline':
88
79
  case 'excelDesktop':
89
80
  if (pasteType === 'normal' || pasteType === 'mergeFormat') {
90
81
  // Handle HTML copied from Excel
91
- (0, processPastedContentFromExcel_1.processPastedContentFromExcel)(ev, this.editor.getTrustedHTMLHandler(), this.allowExcelNoBorderTable);
82
+ (0, processPastedContentFromExcel_1.processPastedContentFromExcel)(event, this.editor.getTrustedHTMLHandler(), this.allowExcelNoBorderTable);
92
83
  }
93
84
  break;
94
85
  case 'googleSheets':
95
- ev.domToModelOption.additionalAllowedTags.push("google-sheets-html-origin" /* GOOGLE_SHEET_NODE_NAME */);
86
+ event.domToModelOption.additionalAllowedTags.push(constants_1.PastePropertyNames.GOOGLE_SHEET_NODE_NAME);
96
87
  break;
97
88
  case 'powerPointDesktop':
98
- (0, processPastedContentFromPowerPoint_1.processPastedContentFromPowerPoint)(ev, this.editor.getTrustedHTMLHandler());
89
+ (0, processPastedContentFromPowerPoint_1.processPastedContentFromPowerPoint)(event, this.editor.getTrustedHTMLHandler());
99
90
  break;
100
91
  }
101
- (0, addParser_1.default)(ev.domToModelOption, 'link', linkParser_1.parseLink);
102
- (0, addParser_1.default)(ev.domToModelOption, 'tableCell', deprecatedColorParser_1.deprecatedBorderColorParser);
103
- (0, addParser_1.default)(ev.domToModelOption, 'tableCell', tableBorderParser);
104
- (0, addParser_1.default)(ev.domToModelOption, 'table', deprecatedColorParser_1.deprecatedBorderColorParser);
92
+ (0, addParser_1.default)(event.domToModelOption, 'link', linkParser_1.parseLink);
93
+ (0, addParser_1.default)(event.domToModelOption, 'tableCell', deprecatedColorParser_1.deprecatedBorderColorParser);
94
+ (0, addParser_1.default)(event.domToModelOption, 'tableCell', tableBorderParser);
95
+ (0, addParser_1.default)(event.domToModelOption, 'table', deprecatedColorParser_1.deprecatedBorderColorParser);
105
96
  if (pasteType === 'mergeFormat') {
106
- (0, addParser_1.default)(ev.domToModelOption, 'block', blockElementParser);
107
- (0, addParser_1.default)(ev.domToModelOption, 'listLevel', blockElementParser);
97
+ (0, addParser_1.default)(event.domToModelOption, 'block', blockElementParser);
98
+ (0, addParser_1.default)(event.domToModelOption, 'listLevel', blockElementParser);
108
99
  }
109
100
  };
110
101
  return ContentModelPastePlugin;
@@ -1 +1 @@
1
- {"version":3,"file":"ContentModelPastePlugin.js","sourceRoot":"","sources":["../../../../packages-content-model/roosterjs-content-model-plugins/lib/paste/ContentModelPastePlugin.ts"],"names":[],"mappings":";;;;AAAA,+CAA0C;AAC1C,2EAAyD;AACzD,uEAA4E;AAC5E,0EAAyE;AACzE,iDAA+C;AAG/C,uFAAsF;AACtF,sGAAqG;AACrG,yGAAwG;AACxG,uGAAsG;AAYtG,qCAAqC;AACrC,0DAA0D;AAC1D,IAAM,YAAY;IACd,sBAAwB,SAAS;IACjC,0BAA4B,aAAa;IACzC,0BAA4B,aAAa;IACzC,qBAAuB,QAAQ;OAClC,CAAC;AAEF;;;;;;;GAOG;AACH;IAGI;;;;OAIG;IACH,iCAAoB,uBAAiC;QAAjC,4BAAuB,GAAvB,uBAAuB,CAAU;QAP7C,WAAM,GAA+B,IAAI,CAAC;IAOM,CAAC;IAEzD;;OAEG;IACH,yCAAO,GAAP;Q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,EAAE,CAAC,EAAE,mBAAmB,EAAE,CAAC;IAC5F,CAAC,YAAY,EAAE,EAAE,CAAC,EAAE,iBAAiB,EAAE,CAAC,EAAE,iBAAiB,EAAE,CAAC,EAAE,iBAAiB,EAAE,CAAC;CACvF,CAAC,CAAC;AAEH,SAAS,iBAAiB,CAAC,MAAmC,EAAE,OAAoB;IAChF,wCAAU,CAAC,OAAO,CAAC,UAAA,GAAG;QAClB,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE;YACd,IAAM,QAAQ,GAAG,iBAAiB,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;YAC5C,IACI,QAAQ;gBACR,OAAO,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC;gBACzB,OAAO,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC;gBACzB,CAAC,OAAO,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,EAC5B;gBACE,MAAM,CAAC,GAAG,CAAC,GAAM,OAAO,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,SAAI,OAAO,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAG,CAAC;aAC7E;SACJ;IACL,CAAC,CAAC,CAAC;AACP,CAAC","sourcesContent":["import addParser from './utils/addParser';\nimport { BorderKeys } from 'roosterjs-content-model-dom';\nimport { deprecatedBorderColorParser } from './utils/deprecatedColorParser';\nimport { getPasteSource } from './pasteSourceValidations/getPasteSource';\nimport { parseLink } from './utils/linkParser';\nimport { PastePropertyNames } from './pasteSourceValidations/constants';\nimport { PasteType as OldPasteType, PluginEventType } from 'roosterjs-editor-types';\nimport { processPastedContentFromExcel } from './Excel/processPastedContentFromExcel';\nimport { processPastedContentFromPowerPoint } from './PowerPoint/processPastedContentFromPowerPoint';\nimport { processPastedContentFromWordDesktop } from './WordDesktop/processPastedContentFromWordDesktop';\nimport { processPastedContentWacComponents } from './WacComponents/processPastedContentWacComponents';\nimport type { IContentModelEditor } from 'roosterjs-content-model-editor';\nimport type {\n BorderFormat,\n ContentModelBeforePasteEvent,\n ContentModelBlockFormat,\n ContentModelTableCellFormat,\n FormatParser,\n PasteType,\n} from 'roosterjs-content-model-types';\nimport type { EditorPlugin, IEditor, PluginEvent } from 'roosterjs-editor-types';\n\n// Map old PasteType to new PasteType\n// TODO: We can remove this once we have standalone editor\nconst PasteTypeMap: Record<OldPasteType, PasteType> = {\n [OldPasteType.AsImage]: 'asImage',\n [OldPasteType.AsPlainText]: 'asPlainText',\n [OldPasteType.MergeFormat]: 'mergeFormat',\n [OldPasteType.Normal]: 'normal',\n};\n\n/**\n * Paste plugin, handles BeforePaste event and reformat some special content, including:\n * 1. Content copied from Word\n * 2. Content copied from Excel\n * 3. Content copied from Word Online or OneNote Online\n * 4. Content copied from Power Point\n * (This class is still under development, and may still be changed in the future with some breaking changes)\n */\nexport class ContentModelPastePlugin implements EditorPlugin {\n private editor: IContentModelEditor | null = null;\n\n /**\n * Construct a new instance of Paste class\n * @param unknownTagReplacement Replace solution of unknown tags, default behavior is to replace with SPAN\n * @param allowExcelNoBorderTable Allow table copied from Excel without border\n */\n constructor(private allowExcelNoBorderTable?: boolean) {}\n\n /**\n * Get name of this plugin\n */\n getName() {\n return 'ContentModelPaste';\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 // TODO: Later we may need a different interface for Content Model editor plugin\n this.editor = editor as IContentModelEditor;\n }\n\n /**\n * The last method that editor will call to a plugin before it is disposed.\n * Plugin can take this chance to clear the reference to editor. After this method is\n * called, plugin should not call to any editor method since it will result in error.\n */\n dispose() {\n this.editor = null;\n }\n\n /**\n * Core method for a plugin. Once an event happens in editor, editor will call this\n * method of each plugin to handle the event as long as the event is not handled\n * exclusively by another plugin.\n * @param event The event to handle:\n */\n onPluginEvent(event: PluginEvent) {\n if (!this.editor || event.eventType != PluginEventType.BeforePaste) {\n return;\n }\n\n const ev = event as ContentModelBeforePasteEvent;\n\n if (!ev.domToModelOption) {\n return;\n }\n\n const pasteSource = getPasteSource(ev, false);\n const pasteType = PasteTypeMap[ev.pasteType];\n\n switch (pasteSource) {\n case 'wordDesktop':\n processPastedContentFromWordDesktop(ev, this.editor.getTrustedHTMLHandler());\n break;\n case 'wacComponents':\n processPastedContentWacComponents(ev);\n break;\n case 'excelOnline':\n case 'excelDesktop':\n if (pasteType === 'normal' || pasteType === 'mergeFormat') {\n // Handle HTML copied from Excel\n processPastedContentFromExcel(\n ev,\n this.editor.getTrustedHTMLHandler(),\n this.allowExcelNoBorderTable\n );\n }\n break;\n case 'googleSheets':\n ev.domToModelOption.additionalAllowedTags.push(\n PastePropertyNames.GOOGLE_SHEET_NODE_NAME\n );\n break;\n case 'powerPointDesktop':\n processPastedContentFromPowerPoint(ev, this.editor.getTrustedHTMLHandler());\n break;\n }\n\n addParser(ev.domToModelOption, 'link', parseLink);\n addParser(ev.domToModelOption, 'tableCell', deprecatedBorderColorParser);\n addParser(ev.domToModelOption, 'tableCell', tableBorderParser);\n addParser(ev.domToModelOption, 'table', deprecatedBorderColorParser);\n\n if (pasteType === 'mergeFormat') {\n addParser(ev.domToModelOption, 'block', blockElementParser);\n addParser(ev.domToModelOption, 'listLevel', blockElementParser);\n }\n }\n}\n\n/**\n * For block elements that have background color style, remove the background color when user selects the merge current format\n * paste option\n */\nconst blockElementParser: FormatParser<ContentModelBlockFormat> = (\n format: ContentModelBlockFormat,\n element: HTMLElement\n) => {\n if (element.style.backgroundColor) {\n delete format.backgroundColor;\n }\n};\n\nconst ElementBorderKeys = new Map<\n keyof BorderFormat,\n {\n c: keyof CSSStyleDeclaration;\n s: keyof CSSStyleDeclaration;\n w: keyof CSSStyleDeclaration;\n }\n>([\n ['borderTop', { w: 'borderTopWidth', s: 'borderTopStyle', c: 'borderTopColor' }],\n ['borderRight', { w: 'borderRightWidth', s: 'borderRightStyle', c: 'borderRightColor' }],\n ['borderBottom', { w: 'borderBottomWidth', s: 'borderBottomStyle', c: 'borderBottomColor' }],\n ['borderLeft', { w: 'borderLeftWidth', s: 'borderLeftStyle', c: 'borderLeftColor' }],\n]);\n\nfunction tableBorderParser(format: ContentModelTableCellFormat, element: HTMLElement): void {\n BorderKeys.forEach(key => {\n if (!format[key]) {\n const styleSet = ElementBorderKeys.get(key);\n if (\n styleSet &&\n element.style[styleSet.w] &&\n element.style[styleSet.s] &&\n !element.style[styleSet.c]\n ) {\n format[key] = `${element.style[styleSet.w]} ${element.style[styleSet.s]}`;\n }\n }\n });\n}\n"]}
1
+ {"version":3,"file":"ContentModelPastePlugin.js","sourceRoot":"","sources":["../../../../packages-content-model/roosterjs-content-model-plugins/lib/paste/ContentModelPastePlugin.ts"],"names":[],"mappings":";;;AAAA,+CAA0C;AAC1C,2EAAyD;AACzD,uEAA4E;AAC5E,0EAAyE;AACzE,iDAA+C;AAC/C,gEAAwE;AACxE,uFAAsF;AACtF,sGAAqG;AACrG,yGAAwG;AACxG,uGAAsG;AAWtG;;;;;;;GAOG;AACH;IAGI;;;;OAIG;IACH,iCAAoB,uBAAiC;QAAjC,4BAAuB,GAAvB,uBAAuB,CAAU;QAP7C,WAAM,GAA6B,IAAI,CAAC;IAOQ,CAAC;IAEzD;;OAEG;IACH,yCAAO,GAAP;QACI,OAAO,mBAAmB,CAAC;IAC/B,CAAC;IAED;;;;;OAKG;IACH,4CAAU,GAAV,UAAW,MAAyB;QAChC,gFAAgF;QAChF,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACzB,CAAC;IAED;;;;OAIG;IACH,yCAAO,GAAP;QACI,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC;IACvB,CAAC;IAED;;;;;OAKG;IACH,+CAAa,GAAb,UAAc,KAAkB;QAC5B,IAAI,CAAC,IAAI,CAAC,MAAM,IAAI,KAAK,CAAC,SAAS,IAAI,aAAa,EAAE;YAClD,OAAO;SACV;QAED,IAAI,CAAC,KA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,QAAQ,CAAC,CAAC,CAAC;gBACzB,OAAO,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC;gBACzB,CAAC,OAAO,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,EAC5B;gBACE,MAAM,CAAC,GAAG,CAAC,GAAM,OAAO,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,SAAI,OAAO,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAG,CAAC;aAC7E;SACJ;IACL,CAAC,CAAC,CAAC;AACP,CAAC","sourcesContent":["import addParser from './utils/addParser';\nimport { BorderKeys } from 'roosterjs-content-model-dom';\nimport { deprecatedBorderColorParser } from './utils/deprecatedColorParser';\nimport { getPasteSource } from './pasteSourceValidations/getPasteSource';\nimport { parseLink } from './utils/linkParser';\nimport { PastePropertyNames } from './pasteSourceValidations/constants';\nimport { processPastedContentFromExcel } from './Excel/processPastedContentFromExcel';\nimport { processPastedContentFromPowerPoint } from './PowerPoint/processPastedContentFromPowerPoint';\nimport { processPastedContentFromWordDesktop } from './WordDesktop/processPastedContentFromWordDesktop';\nimport { processPastedContentWacComponents } from './WacComponents/processPastedContentWacComponents';\nimport type {\n BorderFormat,\n ContentModelBlockFormat,\n ContentModelTableCellFormat,\n EditorPlugin,\n FormatParser,\n IStandaloneEditor,\n PluginEvent,\n} from 'roosterjs-content-model-types';\n\n/**\n * Paste plugin, handles BeforePaste event and reformat some special content, including:\n * 1. Content copied from Word\n * 2. Content copied from Excel\n * 3. Content copied from Word Online or OneNote Online\n * 4. Content copied from Power Point\n * (This class is still under development, and may still be changed in the future with some breaking changes)\n */\nexport class ContentModelPastePlugin implements EditorPlugin {\n private editor: IStandaloneEditor | null = null;\n\n /**\n * Construct a new instance of Paste class\n * @param unknownTagReplacement Replace solution of unknown tags, default behavior is to replace with SPAN\n * @param allowExcelNoBorderTable Allow table copied from Excel without border\n */\n constructor(private allowExcelNoBorderTable?: boolean) {}\n\n /**\n * Get name of this plugin\n */\n getName() {\n return 'ContentModelPaste';\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: IStandaloneEditor) {\n // TODO: Later we may need a different interface for Content Model editor plugin\n this.editor = editor;\n }\n\n /**\n * The last method that editor will call to a plugin before it is disposed.\n * Plugin can take this chance to clear the reference to editor. After this method is\n * called, plugin should not call to any editor method since it will result in error.\n */\n dispose() {\n this.editor = null;\n }\n\n /**\n * Core method for a plugin. Once an event happens in editor, editor will call this\n * method of each plugin to handle the event as long as the event is not handled\n * exclusively by another plugin.\n * @param event The event to handle:\n */\n onPluginEvent(event: PluginEvent) {\n if (!this.editor || event.eventType != 'beforePaste') {\n return;\n }\n\n if (!event.domToModelOption) {\n return;\n }\n\n const pasteSource = getPasteSource(event, false);\n const pasteType = event.pasteType;\n\n switch (pasteSource) {\n case 'wordDesktop':\n processPastedContentFromWordDesktop(event, this.editor.getTrustedHTMLHandler());\n break;\n case 'wacComponents':\n processPastedContentWacComponents(event);\n break;\n case 'excelOnline':\n case 'excelDesktop':\n if (pasteType === 'normal' || pasteType === 'mergeFormat') {\n // Handle HTML copied from Excel\n processPastedContentFromExcel(\n event,\n this.editor.getTrustedHTMLHandler(),\n this.allowExcelNoBorderTable\n );\n }\n break;\n case 'googleSheets':\n event.domToModelOption.additionalAllowedTags.push(\n PastePropertyNames.GOOGLE_SHEET_NODE_NAME as Lowercase<string>\n );\n break;\n case 'powerPointDesktop':\n processPastedContentFromPowerPoint(event, this.editor.getTrustedHTMLHandler());\n break;\n }\n\n addParser(event.domToModelOption, 'link', parseLink);\n addParser(event.domToModelOption, 'tableCell', deprecatedBorderColorParser);\n addParser(event.domToModelOption, 'tableCell', tableBorderParser);\n addParser(event.domToModelOption, 'table', deprecatedBorderColorParser);\n\n if (pasteType === 'mergeFormat') {\n addParser(event.domToModelOption, 'block', blockElementParser);\n addParser(event.domToModelOption, 'listLevel', blockElementParser);\n }\n }\n}\n\n/**\n * For block elements that have background color style, remove the background color when user selects the merge current format\n * paste option\n */\nconst blockElementParser: FormatParser<ContentModelBlockFormat> = (\n format: ContentModelBlockFormat,\n element: HTMLElement\n) => {\n if (element.style.backgroundColor) {\n delete format.backgroundColor;\n }\n};\n\nconst ElementBorderKeys = new Map<\n keyof BorderFormat,\n {\n c: keyof CSSStyleDeclaration;\n s: keyof CSSStyleDeclaration;\n w: keyof CSSStyleDeclaration;\n }\n>([\n ['borderTop', { w: 'borderTopWidth', s: 'borderTopStyle', c: 'borderTopColor' }],\n ['borderRight', { w: 'borderRightWidth', s: 'borderRightStyle', c: 'borderRightColor' }],\n ['borderBottom', { w: 'borderBottomWidth', s: 'borderBottomStyle', c: 'borderBottomColor' }],\n ['borderLeft', { w: 'borderLeftWidth', s: 'borderLeftStyle', c: 'borderLeftColor' }],\n]);\n\nfunction tableBorderParser(format: ContentModelTableCellFormat, element: HTMLElement): void {\n BorderKeys.forEach(key => {\n if (!format[key]) {\n const styleSet = ElementBorderKeys.get(key);\n if (\n styleSet &&\n element.style[styleSet.w] &&\n element.style[styleSet.s] &&\n !element.style[styleSet.c]\n ) {\n format[key] = `${element.style[styleSet.w]} ${element.style[styleSet.s]}`;\n }\n }\n });\n}\n"]}
@@ -1,11 +1,10 @@
1
- import type { TrustedHTMLHandler } from 'roosterjs-editor-types';
2
- import type { ContentModelBeforePasteEvent } from 'roosterjs-content-model-types';
1
+ import type { BeforePasteEvent, TrustedHTMLHandler } from 'roosterjs-content-model-types';
3
2
  /**
4
3
  * @internal
5
4
  * Convert pasted content from Excel, add borders when source doc doesn't have a border
6
5
  * @param event The BeforePaste event
7
6
  */
8
- export declare function processPastedContentFromExcel(event: ContentModelBeforePasteEvent, trustedHTMLHandler: TrustedHTMLHandler, allowExcelNoBorderTable?: boolean): void;
7
+ export declare function processPastedContentFromExcel(event: BeforePasteEvent, trustedHTMLHandler: TrustedHTMLHandler, allowExcelNoBorderTable?: boolean): void;
9
8
  /**
10
9
  * @internal Export for test only
11
10
  * @param html Source html
@@ -1 +1 @@
1
- {"version":3,"file":"processPastedContentFromExcel.js","sourceRoot":"","sources":["../../../../../packages-content-model/roosterjs-content-model-plugins/lib/paste/Excel/processPastedContentFromExcel.ts"],"names":[],"mappings":";;;;AAAA,gDAA2C;AAC3C,2EAA2E;AAC3E,sDAAqD;AAIrD,IAAM,iBAAiB,GAAG,yCAAyC,CAAC;AACpE,IAAM,iBAAiB,GAAG,4CAA4C,CAAC;AACvE,IAAM,aAAa,GAAG,iBAAiB,CAAC;AACxC,IAAM,gBAAgB,GAAG,oBAAoB,CAAC;AAC9C,IAAM,oBAAoB,GAAG,mBAAmB,CAAC;AAEjD;;;;GAIG;AAEH,SAAgB,6BAA6B,CACzC,KAAmC,EACnC,kBAAsC,EACtC,uBAAiC;IAEzB,IAAA,QAAQ,GAAgC,KAAK,SAArC,EAAE,UAAU,GAAoB,KAAK,WAAzB,EAAE,aAAa,GAAK,KAAK,cAAV,CAAW;IACtD,IAAM,IAAI,GAAG,aAAa,CAAC,IAAI,CAAC,CAAC,CAAC,YAAY,CAAC,aAAa,CAAC,IAAI,EAAE,UAAU,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;IAE3F,IAAI,IAAI,IAAI,aAAa,CAAC,IAAI,IAAI,IAAI,EAAE;QACpC,IAAM,GAAG,GAAG,IAAI,SAAS,EAAE,CAAC,eAAe,CAAC,kBAAkB,CAAC,IAAI,CAAC,EAAE,WAAW,CAAC,CAAC;QACnF,IAAA,4CAAc,EAAC,QAAQ,EAAE,GAAG,aAAH,GAAG,uBAAH,GAAG,CAAE,IAAI,CAAC,CAAC;KACvC;IAED,mBAAmB;IACnB,IAAM,UAAU,GAAG,QAAQ,CAAC,UAAU,CAAC;IACvC,IACI,IAAA,0CAAY,EAAC,UAAU,EAAE,cAAc,CAAC;QACxC,UAAU,CAAC,OAAO,IAAI,KAAK;QAC3B,UAAU,CAAC,UAAU,EACvB;QACE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AM,CAAC,SAAS,CAAC;SAC5D;QAED,OAAO,CAAC,wBAAwB,CAAC,KAAK,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;QAEhE,IAAI,KAAK,CAAC,cAAc,KAAK,WAAW,IAAI,KAAK,CAAC,MAAM,CAAC,SAAS,EAAE;YAChE,OAAO,CAAC,aAAa,GAAG,aAAa,CAAC;YACtC,OAAO,KAAK,CAAC,MAAM,CAAC,SAAS,CAAC;SACjC;IACL,CAAC,CAAC,CAAC;AACP,CAAC;AA3DD,sEA2DC;AAED;;;GAGG;AAEH,SAAgB,YAAY,CAAC,IAAY,EAAE,UAAkB;IACzD,IAAI,IAAI,CAAC,KAAK,CAAC,iBAAiB,CAAC,EAAE;QAC/B,IAAM,OAAO,GAAG,UAAU,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC;QAChD,IAAM,EAAE,GAAG,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC;QACzC,IAAI,GAAG,EAAE,GAAG,IAAI,GAAG,OAAO,CAAC;KAC9B;IACD,IAAI,IAAI,CAAC,KAAK,CAAC,iBAAiB,CAAC,EAAE;QAC/B,IAAM,UAAU,GAAG,UAAU,CAAC,KAAK,CAAC,gBAAgB,CAAC,CAAC;QACtD,IAAM,KAAK,GAAG,UAAU,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;QACrD,IAAI,GAAG,KAAK,GAAG,IAAI,GAAG,UAAU,CAAC;KACpC;IAED,OAAO,IAAI,CAAC;AAChB,CAAC;AAbD,oCAaC","sourcesContent":["import addParser from '../utils/addParser';\nimport { isNodeOfType, moveChildNodes } from 'roosterjs-content-model-dom';\nimport { setProcessor } from '../utils/setProcessor';\nimport type { TrustedHTMLHandler } from 'roosterjs-editor-types';\nimport type { ContentModelBeforePasteEvent } from 'roosterjs-content-model-types';\n\nconst LAST_TD_END_REGEX = /<\\/\\s*td\\s*>((?!<\\/\\s*tr\\s*>)[\\s\\S])*$/i;\nconst LAST_TR_END_REGEX = /<\\/\\s*tr\\s*>((?!<\\/\\s*table\\s*>)[\\s\\S])*$/i;\nconst LAST_TR_REGEX = /<tr[^>]*>[^<]*/i;\nconst LAST_TABLE_REGEX = /<table[^>]*>[^<]*/i;\nconst DEFAULT_BORDER_STYLE = 'solid 1px #d4d4d4';\n\n/**\n * @internal\n * Convert pasted content from Excel, add borders when source doc doesn't have a border\n * @param event The BeforePaste event\n */\n\nexport function processPastedContentFromExcel(\n event: ContentModelBeforePasteEvent,\n trustedHTMLHandler: TrustedHTMLHandler,\n allowExcelNoBorderTable?: boolean\n) {\n const { fragment, htmlBefore, clipboardData } = event;\n const html = clipboardData.html ? excelHandler(clipboardData.html, htmlBefore) : undefined;\n\n if (html && clipboardData.html != html) {\n const doc = new DOMParser().parseFromString(trustedHTMLHandler(html), 'text/html');\n moveChildNodes(fragment, doc?.body);\n }\n\n // For Excel Online\n const firstChild = fragment.firstChild;\n if (\n isNodeOfType(firstChild, 'ELEMENT_NODE') &&\n firstChild.tagName == 'div' &&\n firstChild.firstChild\n ) {\n const tableFound = Array.from(firstChild.childNodes).every((child: Node) => {\n // Tables pasted from Excel Online should be of the format: 0 to N META tags and 1 TABLE tag\n const tagName = isNodeOfType(child, 'ELEMENT_NODE') && child.tagName;\n\n return tagName == 'META'\n ? true\n : tagName == 'TABLE'\n ? child == firstChild.lastChild\n : false;\n });\n\n // Extract Table from Div\n if (tableFound && firstChild.lastChild) {\n event.fragment.replaceChildren(firstChild.lastChild);\n }\n }\n\n addParser(event.domToModelOption, 'tableCell', (format, element) => {\n if (!allowExcelNoBorderTable && element.style.borderStyle === 'none') {\n format.borderBottom = DEFAULT_BORDER_STYLE;\n format.borderLeft = DEFAULT_BORDER_STYLE;\n format.borderRight = DEFAULT_BORDER_STYLE;\n format.borderTop = DEFAULT_BORDER_STYLE;\n }\n });\n\n setProcessor(event.domToModelOption, 'child', (group, element, context) => {\n const segmentFormat = { ...context.segmentFormat };\n if (group.blockGroupType === 'TableCell' && group.format.textColor) {\n context.segmentFormat.textColor = group.format.textColor;\n }\n\n context.defaultElementProcessors.child(group, element, context);\n\n if (group.blockGroupType === 'TableCell' && group.format.textColor) {\n context.segmentFormat = segmentFormat;\n delete group.format.textColor;\n }\n });\n}\n\n/**\n * @internal Export for test only\n * @param html Source html\n */\n\nexport function excelHandler(html: string, htmlBefore: string): string {\n if (html.match(LAST_TD_END_REGEX)) {\n const trMatch = htmlBefore.match(LAST_TR_REGEX);\n const tr = trMatch ? trMatch[0] : '<TR>';\n html = tr + html + '</TR>';\n }\n if (html.match(LAST_TR_END_REGEX)) {\n const tableMatch = htmlBefore.match(LAST_TABLE_REGEX);\n const table = tableMatch ? tableMatch[0] : '<TABLE>';\n html = table + html + '</TABLE>';\n }\n\n return html;\n}\n"]}
1
+ {"version":3,"file":"processPastedContentFromExcel.js","sourceRoot":"","sources":["../../../../../packages-content-model/roosterjs-content-model-plugins/lib/paste/Excel/processPastedContentFromExcel.ts"],"names":[],"mappings":";;;;AAAA,gDAA2C;AAC3C,2EAA2E;AAC3E,sDAAqD;AAGrD,IAAM,iBAAiB,GAAG,yCAAyC,CAAC;AACpE,IAAM,iBAAiB,GAAG,4CAA4C,CAAC;AACvE,IAAM,aAAa,GAAG,iBAAiB,CAAC;AACxC,IAAM,gBAAgB,GAAG,oBAAoB,CAAC;AAC9C,IAAM,oBAAoB,GAAG,mBAAmB,CAAC;AAEjD;;;;GAIG;AAEH,SAAgB,6BAA6B,CACzC,KAAuB,EACvB,kBAAsC,EACtC,uBAAiC;IAEzB,IAAA,QAAQ,GAAgC,KAAK,SAArC,EAAE,UAAU,GAAoB,KAAK,WAAzB,EAAE,aAAa,GAAK,KAAK,cAAV,CAAW;IACtD,IAAM,IAAI,GAAG,aAAa,CAAC,IAAI,CAAC,CAAC,CAAC,YAAY,CAAC,aAAa,CAAC,IAAI,EAAE,UAAU,CAAC,CAAC,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C/B,IAAM,UAAU,GAAG,UAAU,CAAC,KAAK,CAAC,gBAAgB,CAAC,CAAC;QACtD,IAAM,KAAK,GAAG,UAAU,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;QACrD,IAAI,GAAG,KAAK,GAAG,IAAI,GAAG,UAAU,CAAC;KACpC;IAED,OAAO,IAAI,CAAC;AAChB,CAAC;AAbD,oCAaC","sourcesContent":["import addParser from '../utils/addParser';\nimport { isNodeOfType, moveChildNodes } from 'roosterjs-content-model-dom';\nimport { setProcessor } from '../utils/setProcessor';\nimport type { BeforePasteEvent, TrustedHTMLHandler } from 'roosterjs-content-model-types';\n\nconst LAST_TD_END_REGEX = /<\\/\\s*td\\s*>((?!<\\/\\s*tr\\s*>)[\\s\\S])*$/i;\nconst LAST_TR_END_REGEX = /<\\/\\s*tr\\s*>((?!<\\/\\s*table\\s*>)[\\s\\S])*$/i;\nconst LAST_TR_REGEX = /<tr[^>]*>[^<]*/i;\nconst LAST_TABLE_REGEX = /<table[^>]*>[^<]*/i;\nconst DEFAULT_BORDER_STYLE = 'solid 1px #d4d4d4';\n\n/**\n * @internal\n * Convert pasted content from Excel, add borders when source doc doesn't have a border\n * @param event The BeforePaste event\n */\n\nexport function processPastedContentFromExcel(\n event: BeforePasteEvent,\n trustedHTMLHandler: TrustedHTMLHandler,\n allowExcelNoBorderTable?: boolean\n) {\n const { fragment, htmlBefore, clipboardData } = event;\n const html = clipboardData.html ? excelHandler(clipboardData.html, htmlBefore) : undefined;\n\n if (html && clipboardData.html != html) {\n const doc = new DOMParser().parseFromString(trustedHTMLHandler(html), 'text/html');\n moveChildNodes(fragment, doc?.body);\n }\n\n // For Excel Online\n const firstChild = fragment.firstChild;\n if (\n isNodeOfType(firstChild, 'ELEMENT_NODE') &&\n firstChild.tagName == 'div' &&\n firstChild.firstChild\n ) {\n const tableFound = Array.from(firstChild.childNodes).every((child: Node) => {\n // Tables pasted from Excel Online should be of the format: 0 to N META tags and 1 TABLE tag\n const tagName = isNodeOfType(child, 'ELEMENT_NODE') && child.tagName;\n\n return tagName == 'META'\n ? true\n : tagName == 'TABLE'\n ? child == firstChild.lastChild\n : false;\n });\n\n // Extract Table from Div\n if (tableFound && firstChild.lastChild) {\n event.fragment.replaceChildren(firstChild.lastChild);\n }\n }\n\n addParser(event.domToModelOption, 'tableCell', (format, element) => {\n if (!allowExcelNoBorderTable && element.style.borderStyle === 'none') {\n format.borderBottom = DEFAULT_BORDER_STYLE;\n format.borderLeft = DEFAULT_BORDER_STYLE;\n format.borderRight = DEFAULT_BORDER_STYLE;\n format.borderTop = DEFAULT_BORDER_STYLE;\n }\n });\n\n setProcessor(event.domToModelOption, 'child', (group, element, context) => {\n const segmentFormat = { ...context.segmentFormat };\n if (group.blockGroupType === 'TableCell' && group.format.textColor) {\n context.segmentFormat.textColor = group.format.textColor;\n }\n\n context.defaultElementProcessors.child(group, element, context);\n\n if (group.blockGroupType === 'TableCell' && group.format.textColor) {\n context.segmentFormat = segmentFormat;\n delete group.format.textColor;\n }\n });\n}\n\n/**\n * @internal Export for test only\n * @param html Source html\n */\n\nexport function excelHandler(html: string, htmlBefore: string): string {\n if (html.match(LAST_TD_END_REGEX)) {\n const trMatch = htmlBefore.match(LAST_TR_REGEX);\n const tr = trMatch ? trMatch[0] : '<TR>';\n html = tr + html + '</TR>';\n }\n if (html.match(LAST_TR_END_REGEX)) {\n const tableMatch = htmlBefore.match(LAST_TABLE_REGEX);\n const table = tableMatch ? tableMatch[0] : '<TABLE>';\n html = table + html + '</TABLE>';\n }\n\n return html;\n}\n"]}
@@ -1,4 +1,4 @@
1
- import type { BeforePasteEvent, TrustedHTMLHandler } from 'roosterjs-editor-types';
1
+ import type { BeforePasteEvent, TrustedHTMLHandler } from 'roosterjs-content-model-types';
2
2
  /**
3
3
  * @internal
4
4
  * Convert pasted content from PowerPoint
@@ -1 +1 @@
1
- {"version":3,"file":"processPastedContentFromPowerPoint.js","sourceRoot":"","sources":["../../../../../packages-content-model/roosterjs-content-model-plugins/lib/paste/PowerPoint/processPastedContentFromPowerPoint.ts"],"names":[],"mappings":";;;AAAA,2EAA6D;AAG7D;;;;GAIG;AAEH,SAAgB,kCAAkC,CAC9C,KAAuB,EACvB,kBAAsC;IAE9B,IAAA,QAAQ,GAAoB,KAAK,SAAzB,EAAE,aAAa,GAAK,KAAK,cAAV,CAAW;IAE1C,IAAI,aAAa,CAAC,IAAI,IAAI,CAAC,aAAa,CAAC,IAAI,IAAI,aAAa,CAAC,KAAK,EAAE;QAClE,gFAAgF;QAChF,gCAAgC;QAChC,IAAM,GAAG,GAAG,IAAI,SAAS,EAAE,CAAC,eAAe,CACvC,kBAAkB,CAAC,aAAa,CAAC,IAAI,CAAC,EACtC,WAAW,CACd,CAAC;QAEF,IAAA,4CAAc,EAAC,QAAQ,EAAE,GAAG,aAAH,GAAG,uBAAH,GAAG,CAAE,IAAI,CAAC,CAAC;KACvC;AACL,CAAC;AAhBD,gFAgBC","sourcesContent":["import { moveChildNodes } from 'roosterjs-content-model-dom';\nimport type { BeforePasteEvent, TrustedHTMLHandler } from 'roosterjs-editor-types';\n\n/**\n * @internal\n * Convert pasted content from PowerPoint\n * @param event The BeforePaste event\n */\n\nexport function processPastedContentFromPowerPoint(\n event: BeforePasteEvent,\n trustedHTMLHandler: TrustedHTMLHandler\n) {\n const { fragment, clipboardData } = event;\n\n if (clipboardData.html && !clipboardData.text && clipboardData.image) {\n // It is possible that PowerPoint copied both image and HTML but not plain text.\n // We always prefer HTML if any.\n const doc = new DOMParser().parseFromString(\n trustedHTMLHandler(clipboardData.html),\n 'text/html'\n );\n\n moveChildNodes(fragment, doc?.body);\n }\n}\n"]}
1
+ {"version":3,"file":"processPastedContentFromPowerPoint.js","sourceRoot":"","sources":["../../../../../packages-content-model/roosterjs-content-model-plugins/lib/paste/PowerPoint/processPastedContentFromPowerPoint.ts"],"names":[],"mappings":";;;AAAA,2EAA6D;AAG7D;;;;GAIG;AAEH,SAAgB,kCAAkC,CAC9C,KAAuB,EACvB,kBAAsC;IAE9B,IAAA,QAAQ,GAAoB,KAAK,SAAzB,EAAE,aAAa,GAAK,KAAK,cAAV,CAAW;IAE1C,IAAI,aAAa,CAAC,IAAI,IAAI,CAAC,aAAa,CAAC,IAAI,IAAI,aAAa,CAAC,KAAK,EAAE;QAClE,gFAAgF;QAChF,gCAAgC;QAChC,IAAM,GAAG,GAAG,IAAI,SAAS,EAAE,CAAC,eAAe,CACvC,kBAAkB,CAAC,aAAa,CAAC,IAAI,CAAC,EACtC,WAAW,CACd,CAAC;QAEF,IAAA,4CAAc,EAAC,QAAQ,EAAE,GAAG,aAAH,GAAG,uBAAH,GAAG,CAAE,IAAI,CAAC,CAAC;KACvC;AACL,CAAC;AAhBD,gFAgBC","sourcesContent":["import { moveChildNodes } from 'roosterjs-content-model-dom';\nimport type { BeforePasteEvent, TrustedHTMLHandler } from 'roosterjs-content-model-types';\n\n/**\n * @internal\n * Convert pasted content from PowerPoint\n * @param event The BeforePaste event\n */\n\nexport function processPastedContentFromPowerPoint(\n event: BeforePasteEvent,\n trustedHTMLHandler: TrustedHTMLHandler\n) {\n const { fragment, clipboardData } = event;\n\n if (clipboardData.html && !clipboardData.text && clipboardData.image) {\n // It is possible that PowerPoint copied both image and HTML but not plain text.\n // We always prefer HTML if any.\n const doc = new DOMParser().parseFromString(\n trustedHTMLHandler(clipboardData.html),\n 'text/html'\n );\n\n moveChildNodes(fragment, doc?.body);\n }\n}\n"]}
@@ -1,4 +1,4 @@
1
- import type { ContentModelBeforePasteEvent } from 'roosterjs-content-model-types';
1
+ import type { BeforePasteEvent } from 'roosterjs-content-model-types';
2
2
  /**
3
3
  * @internal
4
4
  * Convert pasted content from Office Online
@@ -6,4 +6,4 @@ import type { ContentModelBeforePasteEvent } from 'roosterjs-content-model-types
6
6
  * We need to remove the display property and margin from all the list item
7
7
  * @param ev ContentModelBeforePasteEvent
8
8
  */
9
- export declare function processPastedContentWacComponents(ev: ContentModelBeforePasteEvent): void;
9
+ export declare function processPastedContentWacComponents(ev: BeforePasteEvent): void;