roosterjs-content-model-plugins 0.26.3 → 0.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 (190) hide show
  1. package/lib/autoFormat/AutoFormatPlugin.d.ts +2 -2
  2. package/lib/autoFormat/AutoFormatPlugin.js.map +1 -1
  3. package/lib/autoFormat/keyboardListTrigger.d.ts +2 -2
  4. package/lib/autoFormat/keyboardListTrigger.js.map +1 -1
  5. package/lib/edit/EditPlugin.d.ts +3 -3
  6. package/lib/edit/EditPlugin.js +1 -1
  7. package/lib/edit/EditPlugin.js.map +1 -1
  8. package/lib/edit/deleteSteps/deleteCollapsedSelection.js +20 -1
  9. package/lib/edit/deleteSteps/deleteCollapsedSelection.js.map +1 -1
  10. package/lib/edit/handleKeyboardEventCommon.d.ts +2 -2
  11. package/lib/edit/handleKeyboardEventCommon.js.map +1 -1
  12. package/lib/edit/inputSteps/handleEnterOnList.js +40 -10
  13. package/lib/edit/inputSteps/handleEnterOnList.js.map +1 -1
  14. package/lib/edit/keyboardDelete.d.ts +3 -3
  15. package/lib/edit/keyboardDelete.js +1 -1
  16. package/lib/edit/keyboardDelete.js.map +1 -1
  17. package/lib/edit/keyboardInput.d.ts +2 -2
  18. package/lib/edit/keyboardInput.js.map +1 -1
  19. package/lib/edit/keyboardTab.d.ts +2 -2
  20. package/lib/edit/keyboardTab.js +19 -11
  21. package/lib/edit/keyboardTab.js.map +1 -1
  22. package/lib/edit/tabUtils/handleTabOnList.d.ts +7 -0
  23. package/lib/edit/tabUtils/handleTabOnList.js +34 -0
  24. package/lib/edit/tabUtils/handleTabOnList.js.map +1 -0
  25. package/lib/edit/tabUtils/handleTabOnParagraph.d.ts +17 -0
  26. package/lib/edit/tabUtils/handleTabOnParagraph.js +81 -0
  27. package/lib/edit/tabUtils/handleTabOnParagraph.js.map +1 -0
  28. package/lib/index.d.ts +4 -0
  29. package/lib/index.js +18 -1
  30. package/lib/index.js.map +1 -1
  31. package/lib/paste/PastePlugin.d.ts +2 -3
  32. package/lib/paste/PastePlugin.js +0 -1
  33. package/lib/paste/PastePlugin.js.map +1 -1
  34. package/lib/shortcut/ShortcutCommand.d.ts +44 -0
  35. package/lib/shortcut/ShortcutCommand.js +3 -0
  36. package/lib/shortcut/ShortcutCommand.js.map +1 -0
  37. package/lib/shortcut/ShortcutPlugin.d.ts +51 -0
  38. package/lib/shortcut/ShortcutPlugin.js +118 -0
  39. package/lib/shortcut/ShortcutPlugin.js.map +1 -0
  40. package/lib/shortcut/shortcuts.d.ts +73 -0
  41. package/lib/shortcut/shortcuts.js +178 -0
  42. package/lib/shortcut/shortcuts.js.map +1 -0
  43. package/lib/tableEdit/TableEditPlugin.d.ts +47 -0
  44. package/lib/tableEdit/TableEditPlugin.js +156 -0
  45. package/lib/tableEdit/TableEditPlugin.js.map +1 -0
  46. package/lib/tableEdit/editors/TableEditor.d.ts +73 -0
  47. package/lib/tableEdit/editors/TableEditor.js +294 -0
  48. package/lib/tableEdit/editors/TableEditor.js.map +1 -0
  49. package/lib/tableEdit/editors/features/CellResizer.d.ts +6 -0
  50. package/lib/tableEdit/editors/features/CellResizer.js +169 -0
  51. package/lib/tableEdit/editors/features/CellResizer.js.map +1 -0
  52. package/lib/tableEdit/editors/features/TableEditorFeature.d.ts +13 -0
  53. package/lib/tableEdit/editors/features/TableEditorFeature.js +17 -0
  54. package/lib/tableEdit/editors/features/TableEditorFeature.js.map +1 -0
  55. package/lib/tableEdit/editors/features/TableInserter.d.ts +6 -0
  56. package/lib/tableEdit/editors/features/TableInserter.js +113 -0
  57. package/lib/tableEdit/editors/features/TableInserter.js.map +1 -0
  58. package/lib/tableEdit/editors/features/TableMover.d.ts +8 -0
  59. package/lib/tableEdit/editors/features/TableMover.js +83 -0
  60. package/lib/tableEdit/editors/features/TableMover.js.map +1 -0
  61. package/lib/tableEdit/editors/features/TableResizer.d.ts +6 -0
  62. package/lib/tableEdit/editors/features/TableResizer.js +163 -0
  63. package/lib/tableEdit/editors/features/TableResizer.js.map +1 -0
  64. package/lib-amd/autoFormat/AutoFormatPlugin.d.ts +2 -2
  65. package/lib-amd/autoFormat/AutoFormatPlugin.js.map +1 -1
  66. package/lib-amd/autoFormat/keyboardListTrigger.d.ts +2 -2
  67. package/lib-amd/autoFormat/keyboardListTrigger.js.map +1 -1
  68. package/lib-amd/edit/EditPlugin.d.ts +3 -3
  69. package/lib-amd/edit/EditPlugin.js +1 -1
  70. package/lib-amd/edit/EditPlugin.js.map +1 -1
  71. package/lib-amd/edit/deleteSteps/deleteCollapsedSelection.js +19 -1
  72. package/lib-amd/edit/deleteSteps/deleteCollapsedSelection.js.map +1 -1
  73. package/lib-amd/edit/handleKeyboardEventCommon.d.ts +2 -2
  74. package/lib-amd/edit/handleKeyboardEventCommon.js.map +1 -1
  75. package/lib-amd/edit/inputSteps/handleEnterOnList.js +40 -10
  76. package/lib-amd/edit/inputSteps/handleEnterOnList.js.map +1 -1
  77. package/lib-amd/edit/keyboardDelete.d.ts +3 -3
  78. package/lib-amd/edit/keyboardDelete.js +1 -1
  79. package/lib-amd/edit/keyboardDelete.js.map +1 -1
  80. package/lib-amd/edit/keyboardInput.d.ts +2 -2
  81. package/lib-amd/edit/keyboardInput.js.map +1 -1
  82. package/lib-amd/edit/keyboardTab.d.ts +2 -2
  83. package/lib-amd/edit/keyboardTab.js +18 -12
  84. package/lib-amd/edit/keyboardTab.js.map +1 -1
  85. package/lib-amd/edit/tabUtils/handleTabOnList.d.ts +7 -0
  86. package/lib-amd/edit/tabUtils/handleTabOnList.js +34 -0
  87. package/lib-amd/edit/tabUtils/handleTabOnList.js.map +1 -0
  88. package/lib-amd/edit/tabUtils/handleTabOnParagraph.d.ts +17 -0
  89. package/lib-amd/edit/tabUtils/handleTabOnParagraph.js +81 -0
  90. package/lib-amd/edit/tabUtils/handleTabOnParagraph.js.map +1 -0
  91. package/lib-amd/index.d.ts +4 -0
  92. package/lib-amd/index.js +16 -2
  93. package/lib-amd/index.js.map +1 -1
  94. package/lib-amd/paste/PastePlugin.d.ts +2 -3
  95. package/lib-amd/paste/PastePlugin.js +0 -1
  96. package/lib-amd/paste/PastePlugin.js.map +1 -1
  97. package/lib-amd/shortcut/ShortcutCommand.d.ts +44 -0
  98. package/lib-amd/shortcut/ShortcutCommand.js +5 -0
  99. package/lib-amd/shortcut/ShortcutCommand.js.map +1 -0
  100. package/lib-amd/shortcut/ShortcutPlugin.d.ts +51 -0
  101. package/lib-amd/shortcut/ShortcutPlugin.js +118 -0
  102. package/lib-amd/shortcut/ShortcutPlugin.js.map +1 -0
  103. package/lib-amd/shortcut/shortcuts.d.ts +73 -0
  104. package/lib-amd/shortcut/shortcuts.js +178 -0
  105. package/lib-amd/shortcut/shortcuts.js.map +1 -0
  106. package/lib-amd/tableEdit/TableEditPlugin.d.ts +47 -0
  107. package/lib-amd/tableEdit/TableEditPlugin.js +155 -0
  108. package/lib-amd/tableEdit/TableEditPlugin.js.map +1 -0
  109. package/lib-amd/tableEdit/editors/TableEditor.d.ts +73 -0
  110. package/lib-amd/tableEdit/editors/TableEditor.js +289 -0
  111. package/lib-amd/tableEdit/editors/TableEditor.js.map +1 -0
  112. package/lib-amd/tableEdit/editors/features/CellResizer.d.ts +6 -0
  113. package/lib-amd/tableEdit/editors/features/CellResizer.js +165 -0
  114. package/lib-amd/tableEdit/editors/features/CellResizer.js.map +1 -0
  115. package/lib-amd/tableEdit/editors/features/TableEditorFeature.d.ts +13 -0
  116. package/lib-amd/tableEdit/editors/features/TableEditorFeature.js +19 -0
  117. package/lib-amd/tableEdit/editors/features/TableEditorFeature.js.map +1 -0
  118. package/lib-amd/tableEdit/editors/features/TableInserter.d.ts +6 -0
  119. package/lib-amd/tableEdit/editors/features/TableInserter.js +110 -0
  120. package/lib-amd/tableEdit/editors/features/TableInserter.js.map +1 -0
  121. package/lib-amd/tableEdit/editors/features/TableMover.d.ts +8 -0
  122. package/lib-amd/tableEdit/editors/features/TableMover.js +80 -0
  123. package/lib-amd/tableEdit/editors/features/TableMover.js.map +1 -0
  124. package/lib-amd/tableEdit/editors/features/TableResizer.d.ts +6 -0
  125. package/lib-amd/tableEdit/editors/features/TableResizer.js +160 -0
  126. package/lib-amd/tableEdit/editors/features/TableResizer.js.map +1 -0
  127. package/lib-mjs/autoFormat/AutoFormatPlugin.d.ts +2 -2
  128. package/lib-mjs/autoFormat/AutoFormatPlugin.js.map +1 -1
  129. package/lib-mjs/autoFormat/keyboardListTrigger.d.ts +2 -2
  130. package/lib-mjs/autoFormat/keyboardListTrigger.js.map +1 -1
  131. package/lib-mjs/edit/EditPlugin.d.ts +3 -3
  132. package/lib-mjs/edit/EditPlugin.js +1 -1
  133. package/lib-mjs/edit/EditPlugin.js.map +1 -1
  134. package/lib-mjs/edit/deleteSteps/deleteCollapsedSelection.js +20 -1
  135. package/lib-mjs/edit/deleteSteps/deleteCollapsedSelection.js.map +1 -1
  136. package/lib-mjs/edit/handleKeyboardEventCommon.d.ts +2 -2
  137. package/lib-mjs/edit/handleKeyboardEventCommon.js.map +1 -1
  138. package/lib-mjs/edit/inputSteps/handleEnterOnList.js +42 -12
  139. package/lib-mjs/edit/inputSteps/handleEnterOnList.js.map +1 -1
  140. package/lib-mjs/edit/keyboardDelete.d.ts +3 -3
  141. package/lib-mjs/edit/keyboardDelete.js +1 -1
  142. package/lib-mjs/edit/keyboardDelete.js.map +1 -1
  143. package/lib-mjs/edit/keyboardInput.d.ts +2 -2
  144. package/lib-mjs/edit/keyboardInput.js.map +1 -1
  145. package/lib-mjs/edit/keyboardTab.d.ts +2 -2
  146. package/lib-mjs/edit/keyboardTab.js +19 -11
  147. package/lib-mjs/edit/keyboardTab.js.map +1 -1
  148. package/lib-mjs/edit/tabUtils/handleTabOnList.d.ts +7 -0
  149. package/lib-mjs/edit/tabUtils/handleTabOnList.js +30 -0
  150. package/lib-mjs/edit/tabUtils/handleTabOnList.js.map +1 -0
  151. package/lib-mjs/edit/tabUtils/handleTabOnParagraph.d.ts +17 -0
  152. package/lib-mjs/edit/tabUtils/handleTabOnParagraph.js +77 -0
  153. package/lib-mjs/edit/tabUtils/handleTabOnParagraph.js.map +1 -0
  154. package/lib-mjs/index.d.ts +4 -0
  155. package/lib-mjs/index.js +3 -0
  156. package/lib-mjs/index.js.map +1 -1
  157. package/lib-mjs/paste/PastePlugin.d.ts +2 -3
  158. package/lib-mjs/paste/PastePlugin.js +0 -1
  159. package/lib-mjs/paste/PastePlugin.js.map +1 -1
  160. package/lib-mjs/shortcut/ShortcutCommand.d.ts +44 -0
  161. package/lib-mjs/shortcut/ShortcutCommand.js +2 -0
  162. package/lib-mjs/shortcut/ShortcutCommand.js.map +1 -0
  163. package/lib-mjs/shortcut/ShortcutPlugin.d.ts +51 -0
  164. package/lib-mjs/shortcut/ShortcutPlugin.js +115 -0
  165. package/lib-mjs/shortcut/ShortcutPlugin.js.map +1 -0
  166. package/lib-mjs/shortcut/shortcuts.d.ts +73 -0
  167. package/lib-mjs/shortcut/shortcuts.js +175 -0
  168. package/lib-mjs/shortcut/shortcuts.js.map +1 -0
  169. package/lib-mjs/tableEdit/TableEditPlugin.d.ts +47 -0
  170. package/lib-mjs/tableEdit/TableEditPlugin.js +153 -0
  171. package/lib-mjs/tableEdit/TableEditPlugin.js.map +1 -0
  172. package/lib-mjs/tableEdit/editors/TableEditor.d.ts +73 -0
  173. package/lib-mjs/tableEdit/editors/TableEditor.js +292 -0
  174. package/lib-mjs/tableEdit/editors/TableEditor.js.map +1 -0
  175. package/lib-mjs/tableEdit/editors/features/CellResizer.d.ts +6 -0
  176. package/lib-mjs/tableEdit/editors/features/CellResizer.js +166 -0
  177. package/lib-mjs/tableEdit/editors/features/CellResizer.js.map +1 -0
  178. package/lib-mjs/tableEdit/editors/features/TableEditorFeature.d.ts +13 -0
  179. package/lib-mjs/tableEdit/editors/features/TableEditorFeature.js +13 -0
  180. package/lib-mjs/tableEdit/editors/features/TableEditorFeature.js.map +1 -0
  181. package/lib-mjs/tableEdit/editors/features/TableInserter.d.ts +6 -0
  182. package/lib-mjs/tableEdit/editors/features/TableInserter.js +110 -0
  183. package/lib-mjs/tableEdit/editors/features/TableInserter.js.map +1 -0
  184. package/lib-mjs/tableEdit/editors/features/TableMover.d.ts +8 -0
  185. package/lib-mjs/tableEdit/editors/features/TableMover.js +80 -0
  186. package/lib-mjs/tableEdit/editors/features/TableMover.js.map +1 -0
  187. package/lib-mjs/tableEdit/editors/features/TableResizer.d.ts +6 -0
  188. package/lib-mjs/tableEdit/editors/features/TableResizer.js +160 -0
  189. package/lib-mjs/tableEdit/editors/features/TableResizer.js.map +1 -0
  190. package/package.json +5 -5
@@ -0,0 +1,115 @@
1
+ import { cacheGetEventData } from 'roosterjs-content-model-core';
2
+ import { ShortcutBold, ShortcutBullet, ShortcutClearFormat, ShortcutDecreaseFont, ShortcutIncreaseFont, ShortcutItalic, ShortcutNumbering, ShortcutRedo, ShortcutRedoMacOS, ShortcutUnderline, ShortcutUndo, ShortcutUndo2, } from './shortcuts';
3
+ var defaultShortcuts = [
4
+ ShortcutBold,
5
+ ShortcutItalic,
6
+ ShortcutUnderline,
7
+ ShortcutClearFormat,
8
+ ShortcutUndo,
9
+ ShortcutUndo2,
10
+ ShortcutRedo,
11
+ ShortcutRedoMacOS,
12
+ ShortcutBullet,
13
+ ShortcutNumbering,
14
+ ShortcutIncreaseFont,
15
+ ShortcutDecreaseFont,
16
+ ];
17
+ var CommandCacheKey = '__ShortcutCommandCache';
18
+ /**
19
+ * Shortcut plugin hook on the specified shortcut keys and trigger related format API
20
+ */
21
+ var ShortcutPlugin = /** @class */ (function () {
22
+ /**
23
+ * Create a new instance of ShortcutPlugin
24
+ * @param [shortcuts=defaultShortcuts] Allowed commands
25
+ */
26
+ function ShortcutPlugin(shortcuts) {
27
+ if (shortcuts === void 0) { shortcuts = defaultShortcuts; }
28
+ this.shortcuts = shortcuts;
29
+ this.editor = null;
30
+ this.isMac = false;
31
+ }
32
+ /**
33
+ * Get name of this plugin
34
+ */
35
+ ShortcutPlugin.prototype.getName = function () {
36
+ return 'Shortcut';
37
+ };
38
+ /**
39
+ * The first method that editor will call to a plugin when editor is initializing.
40
+ * It will pass in the editor instance, plugin should take this chance to save the
41
+ * editor reference so that it can call to any editor method or format API later.
42
+ * @param editor The editor object
43
+ */
44
+ ShortcutPlugin.prototype.initialize = function (editor) {
45
+ this.editor = editor;
46
+ this.isMac = !!this.editor.getEnvironment().isMac;
47
+ };
48
+ /**
49
+ * The last method that editor will call to a plugin before it is disposed.
50
+ * Plugin can take this chance to clear the reference to editor. After this method is
51
+ * called, plugin should not call to any editor method since it will result in error.
52
+ */
53
+ ShortcutPlugin.prototype.dispose = function () {
54
+ this.editor = null;
55
+ };
56
+ /**
57
+ * Check if the plugin should handle the given event exclusively.
58
+ * Handle an event exclusively means other plugin will not receive this event in
59
+ * onPluginEvent method.
60
+ * If two plugins will return true in willHandleEventExclusively() for the same event,
61
+ * the final result depends on the order of the plugins are added into editor
62
+ * @param event The event to check:
63
+ */
64
+ ShortcutPlugin.prototype.willHandleEventExclusively = function (event) {
65
+ return (event.eventType == 'keyDown' &&
66
+ (event.rawEvent.ctrlKey || event.rawEvent.altKey || event.rawEvent.metaKey) &&
67
+ !!this.cacheGetCommand(event));
68
+ };
69
+ /**
70
+ * Core method for a plugin. Once an event happens in editor, editor will call this
71
+ * method of each plugin to handle the event as long as the event is not handled
72
+ * exclusively by another plugin.
73
+ * @param event The event to handle:
74
+ */
75
+ ShortcutPlugin.prototype.onPluginEvent = function (event) {
76
+ if (this.editor && event.eventType == 'keyDown') {
77
+ var command = this.cacheGetCommand(event);
78
+ if (command) {
79
+ command.onClick(this.editor);
80
+ event.rawEvent.preventDefault();
81
+ }
82
+ }
83
+ };
84
+ ShortcutPlugin.prototype.cacheGetCommand = function (event) {
85
+ var _this = this;
86
+ return cacheGetEventData(event, CommandCacheKey, function (event) {
87
+ var editor = _this.editor;
88
+ return (editor &&
89
+ _this.shortcuts.filter(function (command) {
90
+ return _this.matchOS(command.environment) &&
91
+ _this.matchShortcut(command.shortcutKey, event.rawEvent);
92
+ })[0]);
93
+ });
94
+ };
95
+ ShortcutPlugin.prototype.matchOS = function (environment) {
96
+ switch (environment) {
97
+ case 'mac':
98
+ return this.isMac;
99
+ case 'nonMac':
100
+ return !this.isMac;
101
+ default:
102
+ return true;
103
+ }
104
+ };
105
+ ShortcutPlugin.prototype.matchShortcut = function (shortcutKey, event) {
106
+ var ctrlKey = event.ctrlKey, altKey = event.altKey, shiftKey = event.shiftKey, which = event.which, metaKey = event.metaKey;
107
+ var ctrlOrMeta = this.isMac ? metaKey : ctrlKey;
108
+ var matchModifier = (shortcutKey.modifierKey == 'ctrl' && ctrlOrMeta && !altKey) ||
109
+ (shortcutKey.modifierKey == 'alt' && altKey && !ctrlOrMeta);
110
+ return matchModifier && shiftKey == shortcutKey.shiftKey && shortcutKey.which == which;
111
+ };
112
+ return ShortcutPlugin;
113
+ }());
114
+ export { ShortcutPlugin };
115
+ //# sourceMappingURL=ShortcutPlugin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ShortcutPlugin.js","sourceRoot":"","sources":["../../../../packages-content-model/roosterjs-content-model-plugins/lib/shortcut/ShortcutPlugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AAEjE,OAAO,EACH,YAAY,EACZ,cAAc,EACd,mBAAmB,EACnB,oBAAoB,EACpB,oBAAoB,EACpB,cAAc,EACd,iBAAiB,EACjB,YAAY,EACZ,iBAAiB,EACjB,iBAAiB,EACjB,YAAY,EACZ,aAAa,GAChB,MAAM,aAAa,CAAC;AAQrB,IAAM,gBAAgB,GAAsB;IACxC,YAAY;IACZ,cAAc;IACd,iBAAiB;IACjB,mBAAmB;IACnB,YAAY;IACZ,aAAa;IACb,YAAY;IACZ,iBAAiB;IACjB,cAAc;IACd,iBAAiB;IACjB,oBAAoB;IACpB,oBAAoB;CACvB,CAAC;AACF,IAAM,eAAe,GAAG,wBAAwB,CAAC;AAEjD;;GAEG;A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CAAC;IACL,qBAAC;AAAD,CAAC,AA3GD,IA2GC","sourcesContent":["import { cacheGetEventData } from 'roosterjs-content-model-core';\nimport type { ShortcutCommand, ShortcutKeyDefinition } from './ShortcutCommand';\nimport {\n ShortcutBold,\n ShortcutBullet,\n ShortcutClearFormat,\n ShortcutDecreaseFont,\n ShortcutIncreaseFont,\n ShortcutItalic,\n ShortcutNumbering,\n ShortcutRedo,\n ShortcutRedoMacOS,\n ShortcutUnderline,\n ShortcutUndo,\n ShortcutUndo2,\n} from './shortcuts';\nimport type {\n EditorPlugin,\n IEditor,\n KeyDownEvent,\n PluginEvent,\n} from 'roosterjs-content-model-types';\n\nconst defaultShortcuts: ShortcutCommand[] = [\n ShortcutBold,\n ShortcutItalic,\n ShortcutUnderline,\n ShortcutClearFormat,\n ShortcutUndo,\n ShortcutUndo2,\n ShortcutRedo,\n ShortcutRedoMacOS,\n ShortcutBullet,\n ShortcutNumbering,\n ShortcutIncreaseFont,\n ShortcutDecreaseFont,\n];\nconst CommandCacheKey = '__ShortcutCommandCache';\n\n/**\n * Shortcut plugin hook on the specified shortcut keys and trigger related format API\n */\nexport class ShortcutPlugin implements EditorPlugin {\n private editor: IEditor | null = null;\n private isMac = false;\n\n /**\n * Create a new instance of ShortcutPlugin\n * @param [shortcuts=defaultShortcuts] Allowed commands\n */\n constructor(private shortcuts: ShortcutCommand[] = defaultShortcuts) {}\n\n /**\n * Get name of this plugin\n */\n getName() {\n return 'Shortcut';\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.isMac = !!this.editor.getEnvironment().isMac;\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 * 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 return (\n event.eventType == 'keyDown' &&\n (event.rawEvent.ctrlKey || event.rawEvent.altKey || event.rawEvent.metaKey) &&\n !!this.cacheGetCommand(event)\n );\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 == 'keyDown') {\n const command = this.cacheGetCommand(event);\n\n if (command) {\n command.onClick(this.editor);\n event.rawEvent.preventDefault();\n }\n }\n }\n\n private cacheGetCommand(event: KeyDownEvent) {\n return cacheGetEventData(event, CommandCacheKey, event => {\n const editor = this.editor;\n\n return (\n editor &&\n this.shortcuts.filter(\n command =>\n this.matchOS(command.environment) &&\n this.matchShortcut(command.shortcutKey, event.rawEvent)\n )[0]\n );\n });\n }\n\n private matchOS(environment?: 'all' | 'mac' | 'nonMac') {\n switch (environment) {\n case 'mac':\n return this.isMac;\n\n case 'nonMac':\n return !this.isMac;\n\n default:\n return true;\n }\n }\n\n private matchShortcut(shortcutKey: ShortcutKeyDefinition, event: KeyboardEvent) {\n const { ctrlKey, altKey, shiftKey, which, metaKey } = event;\n const ctrlOrMeta = this.isMac ? metaKey : ctrlKey;\n const matchModifier =\n (shortcutKey.modifierKey == 'ctrl' && ctrlOrMeta && !altKey) ||\n (shortcutKey.modifierKey == 'alt' && altKey && !ctrlOrMeta);\n\n return matchModifier && shiftKey == shortcutKey.shiftKey && shortcutKey.which == which;\n }\n}\n"]}
@@ -0,0 +1,73 @@
1
+ import type { ShortcutCommand } from './ShortcutCommand';
2
+ /**
3
+ * Shortcut command for Bold
4
+ * Windows: Ctrl + B
5
+ * MacOS: Meta + B
6
+ */
7
+ export declare const ShortcutBold: ShortcutCommand;
8
+ /**
9
+ * Shortcut command for Italic
10
+ * Windows: Ctrl + I
11
+ * MacOS: Meta + I
12
+ */
13
+ export declare const ShortcutItalic: ShortcutCommand;
14
+ /**
15
+ * Shortcut command for Underline
16
+ * Windows: Ctrl + U
17
+ * MacOS: Meta + U
18
+ */
19
+ export declare const ShortcutUnderline: ShortcutCommand;
20
+ /**
21
+ * Shortcut command for Clear Format
22
+ * Windows: Ctrl + Space
23
+ * MacOS: Meta + Space
24
+ */
25
+ export declare const ShortcutClearFormat: ShortcutCommand;
26
+ /**
27
+ * Shortcut command for Undo 1
28
+ * Windows: Ctrl + Z
29
+ * MacOS: Meta + Z
30
+ */
31
+ export declare const ShortcutUndo: ShortcutCommand;
32
+ /**
33
+ * Shortcut command for Undo 2
34
+ * Windows: Alt + Backspace
35
+ * MacOS: N/A
36
+ */
37
+ export declare const ShortcutUndo2: ShortcutCommand;
38
+ /**
39
+ * Shortcut command for Redo 1
40
+ * Windows: Ctrl + Y
41
+ * MacOS: N/A
42
+ */
43
+ export declare const ShortcutRedo: ShortcutCommand;
44
+ /**
45
+ * Shortcut command for Redo 2
46
+ * Windows: N/A
47
+ * MacOS: Meta + Shift + Z
48
+ */
49
+ export declare const ShortcutRedoMacOS: ShortcutCommand;
50
+ /**
51
+ * Shortcut command for Bullet List
52
+ * Windows: Ctrl + . (Period)
53
+ * MacOS: Meta + . (Period)
54
+ */
55
+ export declare const ShortcutBullet: ShortcutCommand;
56
+ /**
57
+ * Shortcut command for Numbering List
58
+ * Windows: Ctrl + / (Forward slash)
59
+ * MacOS: Meta + / (Forward slash)
60
+ */
61
+ export declare const ShortcutNumbering: ShortcutCommand;
62
+ /**
63
+ * Shortcut command for Increase Font
64
+ * Windows: Ctrl + Shift + . (Period)
65
+ * MacOS: Meta + Shift + . (Period)
66
+ */
67
+ export declare const ShortcutIncreaseFont: ShortcutCommand;
68
+ /**
69
+ * Shortcut command for Decrease Font
70
+ * Windows: Ctrl + Shift + , (Comma)
71
+ * MacOS: Meta + Shift + , (Comma)
72
+ */
73
+ export declare const ShortcutDecreaseFont: ShortcutCommand;
@@ -0,0 +1,175 @@
1
+ import { redo, undo } from 'roosterjs-content-model-core';
2
+ import { changeFontSize, clearFormat, toggleBold, toggleBullet, toggleItalic, toggleNumbering, toggleUnderline, } from 'roosterjs-content-model-api';
3
+ var Keys;
4
+ (function (Keys) {
5
+ Keys[Keys["BACKSPACE"] = 8] = "BACKSPACE";
6
+ Keys[Keys["SPACE"] = 32] = "SPACE";
7
+ Keys[Keys["B"] = 66] = "B";
8
+ Keys[Keys["I"] = 73] = "I";
9
+ Keys[Keys["U"] = 85] = "U";
10
+ Keys[Keys["Y"] = 89] = "Y";
11
+ Keys[Keys["Z"] = 90] = "Z";
12
+ Keys[Keys["COMMA"] = 188] = "COMMA";
13
+ Keys[Keys["PERIOD"] = 190] = "PERIOD";
14
+ Keys[Keys["FORWARD_SLASH"] = 191] = "FORWARD_SLASH";
15
+ })(Keys || (Keys = {}));
16
+ /**
17
+ * Shortcut command for Bold
18
+ * Windows: Ctrl + B
19
+ * MacOS: Meta + B
20
+ */
21
+ export var ShortcutBold = {
22
+ shortcutKey: {
23
+ modifierKey: 'ctrl',
24
+ shiftKey: false,
25
+ which: 66 /* B */,
26
+ },
27
+ onClick: function (editor) { return toggleBold(editor); },
28
+ };
29
+ /**
30
+ * Shortcut command for Italic
31
+ * Windows: Ctrl + I
32
+ * MacOS: Meta + I
33
+ */
34
+ export var ShortcutItalic = {
35
+ shortcutKey: {
36
+ modifierKey: 'ctrl',
37
+ shiftKey: false,
38
+ which: 73 /* I */,
39
+ },
40
+ onClick: function (editor) { return toggleItalic(editor); },
41
+ };
42
+ /**
43
+ * Shortcut command for Underline
44
+ * Windows: Ctrl + U
45
+ * MacOS: Meta + U
46
+ */
47
+ export var ShortcutUnderline = {
48
+ shortcutKey: {
49
+ modifierKey: 'ctrl',
50
+ shiftKey: false,
51
+ which: 85 /* U */,
52
+ },
53
+ onClick: function (editor) { return toggleUnderline(editor); },
54
+ };
55
+ /**
56
+ * Shortcut command for Clear Format
57
+ * Windows: Ctrl + Space
58
+ * MacOS: Meta + Space
59
+ */
60
+ export var ShortcutClearFormat = {
61
+ shortcutKey: {
62
+ modifierKey: 'ctrl',
63
+ shiftKey: false,
64
+ which: 32 /* SPACE */,
65
+ },
66
+ onClick: function (editor) { return clearFormat(editor); },
67
+ };
68
+ /**
69
+ * Shortcut command for Undo 1
70
+ * Windows: Ctrl + Z
71
+ * MacOS: Meta + Z
72
+ */
73
+ export var ShortcutUndo = {
74
+ shortcutKey: {
75
+ modifierKey: 'ctrl',
76
+ shiftKey: false,
77
+ which: 90 /* Z */,
78
+ },
79
+ onClick: function (editor) { return undo(editor); },
80
+ };
81
+ /**
82
+ * Shortcut command for Undo 2
83
+ * Windows: Alt + Backspace
84
+ * MacOS: N/A
85
+ */
86
+ export var ShortcutUndo2 = {
87
+ shortcutKey: {
88
+ modifierKey: 'alt',
89
+ shiftKey: false,
90
+ which: 8 /* BACKSPACE */,
91
+ },
92
+ onClick: function (editor) { return undo(editor); },
93
+ environment: 'nonMac',
94
+ };
95
+ /**
96
+ * Shortcut command for Redo 1
97
+ * Windows: Ctrl + Y
98
+ * MacOS: N/A
99
+ */
100
+ export var ShortcutRedo = {
101
+ shortcutKey: {
102
+ modifierKey: 'ctrl',
103
+ shiftKey: false,
104
+ which: 89 /* Y */,
105
+ },
106
+ onClick: function (editor) { return redo(editor); },
107
+ environment: 'nonMac',
108
+ };
109
+ /**
110
+ * Shortcut command for Redo 2
111
+ * Windows: N/A
112
+ * MacOS: Meta + Shift + Z
113
+ */
114
+ export var ShortcutRedoMacOS = {
115
+ shortcutKey: {
116
+ modifierKey: 'ctrl',
117
+ shiftKey: true,
118
+ which: 90 /* Z */,
119
+ },
120
+ onClick: function (editor) { return redo(editor); },
121
+ environment: 'mac',
122
+ };
123
+ /**
124
+ * Shortcut command for Bullet List
125
+ * Windows: Ctrl + . (Period)
126
+ * MacOS: Meta + . (Period)
127
+ */
128
+ export var ShortcutBullet = {
129
+ shortcutKey: {
130
+ modifierKey: 'ctrl',
131
+ shiftKey: false,
132
+ which: 190 /* PERIOD */,
133
+ },
134
+ onClick: function (editor) { return toggleBullet(editor); },
135
+ };
136
+ /**
137
+ * Shortcut command for Numbering List
138
+ * Windows: Ctrl + / (Forward slash)
139
+ * MacOS: Meta + / (Forward slash)
140
+ */
141
+ export var ShortcutNumbering = {
142
+ shortcutKey: {
143
+ modifierKey: 'ctrl',
144
+ shiftKey: false,
145
+ which: 191 /* FORWARD_SLASH */,
146
+ },
147
+ onClick: function (editor) { return toggleNumbering(editor); },
148
+ };
149
+ /**
150
+ * Shortcut command for Increase Font
151
+ * Windows: Ctrl + Shift + . (Period)
152
+ * MacOS: Meta + Shift + . (Period)
153
+ */
154
+ export var ShortcutIncreaseFont = {
155
+ shortcutKey: {
156
+ modifierKey: 'ctrl',
157
+ shiftKey: true,
158
+ which: 190 /* PERIOD */,
159
+ },
160
+ onClick: function (editor) { return changeFontSize(editor, 'increase'); },
161
+ };
162
+ /**
163
+ * Shortcut command for Decrease Font
164
+ * Windows: Ctrl + Shift + , (Comma)
165
+ * MacOS: Meta + Shift + , (Comma)
166
+ */
167
+ export var ShortcutDecreaseFont = {
168
+ shortcutKey: {
169
+ modifierKey: 'ctrl',
170
+ shiftKey: true,
171
+ which: 188 /* COMMA */,
172
+ },
173
+ onClick: function (editor) { return changeFontSize(editor, 'decrease'); },
174
+ };
175
+ //# sourceMappingURL=shortcuts.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shortcuts.js","sourceRoot":"","sources":["../../../../packages-content-model/roosterjs-content-model-plugins/lib/shortcut/shortcuts.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,8BAA8B,CAAC;AAC1D,OAAO,EACH,cAAc,EACd,WAAW,EACX,UAAU,EACV,YAAY,EACZ,YAAY,EACZ,eAAe,EACf,eAAe,GAClB,MAAM,6BA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AEF;;;;GAIG;AACH,MAAM,CAAC,IAAM,iBAAiB,GAAoB;IAC9C,WAAW,EAAE;QACT,WAAW,EAAE,MAAM;QACnB,QAAQ,EAAE,KAAK;QACf,KAAK,yBAAoB;KAC5B;IACD,OAAO,EAAE,UAAA,MAAM,IAAI,OAAA,eAAe,CAAC,MAAM,CAAC,EAAvB,CAAuB;CAC7C,CAAC;AAEF;;;;GAIG;AACH,MAAM,CAAC,IAAM,oBAAoB,GAAoB;IACjD,WAAW,EAAE;QACT,WAAW,EAAE,MAAM;QACnB,QAAQ,EAAE,IAAI;QACd,KAAK,kBAAa;KACrB;IACD,OAAO,EAAE,UAAA,MAAM,IAAI,OAAA,cAAc,CAAC,MAAM,EAAE,UAAU,CAAC,EAAlC,CAAkC;CACxD,CAAC;AAEF;;;;GAIG;AACH,MAAM,CAAC,IAAM,oBAAoB,GAAoB;IACjD,WAAW,EAAE;QACT,WAAW,EAAE,MAAM;QACnB,QAAQ,EAAE,IAAI;QACd,KAAK,iBAAY;KACpB;IACD,OAAO,EAAE,UAAA,MAAM,IAAI,OAAA,cAAc,CAAC,MAAM,EAAE,UAAU,CAAC,EAAlC,CAAkC;CACxD,CAAC","sourcesContent":["import { redo, undo } from 'roosterjs-content-model-core';\nimport {\n changeFontSize,\n clearFormat,\n toggleBold,\n toggleBullet,\n toggleItalic,\n toggleNumbering,\n toggleUnderline,\n} from 'roosterjs-content-model-api';\nimport type { ShortcutCommand } from './ShortcutCommand';\n\nconst enum Keys {\n BACKSPACE = 8,\n SPACE = 32,\n B = 66,\n I = 73,\n U = 85,\n Y = 89,\n Z = 90,\n COMMA = 188,\n PERIOD = 190,\n FORWARD_SLASH = 191,\n}\n\n/**\n * Shortcut command for Bold\n * Windows: Ctrl + B\n * MacOS: Meta + B\n */\nexport const ShortcutBold: ShortcutCommand = {\n shortcutKey: {\n modifierKey: 'ctrl',\n shiftKey: false,\n which: Keys.B,\n },\n onClick: editor => toggleBold(editor),\n};\n\n/**\n * Shortcut command for Italic\n * Windows: Ctrl + I\n * MacOS: Meta + I\n */\nexport const ShortcutItalic: ShortcutCommand = {\n shortcutKey: {\n modifierKey: 'ctrl',\n shiftKey: false,\n which: Keys.I,\n },\n onClick: editor => toggleItalic(editor),\n};\n\n/**\n * Shortcut command for Underline\n * Windows: Ctrl + U\n * MacOS: Meta + U\n */\nexport const ShortcutUnderline: ShortcutCommand = {\n shortcutKey: {\n modifierKey: 'ctrl',\n shiftKey: false,\n which: Keys.U,\n },\n onClick: editor => toggleUnderline(editor),\n};\n\n/**\n * Shortcut command for Clear Format\n * Windows: Ctrl + Space\n * MacOS: Meta + Space\n */\nexport const ShortcutClearFormat: ShortcutCommand = {\n shortcutKey: {\n modifierKey: 'ctrl',\n shiftKey: false,\n which: Keys.SPACE,\n },\n onClick: editor => clearFormat(editor),\n};\n\n/**\n * Shortcut command for Undo 1\n * Windows: Ctrl + Z\n * MacOS: Meta + Z\n */\nexport const ShortcutUndo: ShortcutCommand = {\n shortcutKey: {\n modifierKey: 'ctrl',\n shiftKey: false,\n which: Keys.Z,\n },\n onClick: editor => undo(editor),\n};\n\n/**\n * Shortcut command for Undo 2\n * Windows: Alt + Backspace\n * MacOS: N/A\n */\nexport const ShortcutUndo2: ShortcutCommand = {\n shortcutKey: {\n modifierKey: 'alt',\n shiftKey: false,\n which: Keys.BACKSPACE,\n },\n onClick: editor => undo(editor),\n environment: 'nonMac',\n};\n\n/**\n * Shortcut command for Redo 1\n * Windows: Ctrl + Y\n * MacOS: N/A\n */\nexport const ShortcutRedo: ShortcutCommand = {\n shortcutKey: {\n modifierKey: 'ctrl',\n shiftKey: false,\n which: Keys.Y,\n },\n onClick: editor => redo(editor),\n environment: 'nonMac',\n};\n\n/**\n * Shortcut command for Redo 2\n * Windows: N/A\n * MacOS: Meta + Shift + Z\n */\nexport const ShortcutRedoMacOS: ShortcutCommand = {\n shortcutKey: {\n modifierKey: 'ctrl',\n shiftKey: true,\n which: Keys.Z,\n },\n onClick: editor => redo(editor),\n environment: 'mac',\n};\n\n/**\n * Shortcut command for Bullet List\n * Windows: Ctrl + . (Period)\n * MacOS: Meta + . (Period)\n */\nexport const ShortcutBullet: ShortcutCommand = {\n shortcutKey: {\n modifierKey: 'ctrl',\n shiftKey: false,\n which: Keys.PERIOD,\n },\n onClick: editor => toggleBullet(editor),\n};\n\n/**\n * Shortcut command for Numbering List\n * Windows: Ctrl + / (Forward slash)\n * MacOS: Meta + / (Forward slash)\n */\nexport const ShortcutNumbering: ShortcutCommand = {\n shortcutKey: {\n modifierKey: 'ctrl',\n shiftKey: false,\n which: Keys.FORWARD_SLASH,\n },\n onClick: editor => toggleNumbering(editor),\n};\n\n/**\n * Shortcut command for Increase Font\n * Windows: Ctrl + Shift + . (Period)\n * MacOS: Meta + Shift + . (Period)\n */\nexport const ShortcutIncreaseFont: ShortcutCommand = {\n shortcutKey: {\n modifierKey: 'ctrl',\n shiftKey: true,\n which: Keys.PERIOD,\n },\n onClick: editor => changeFontSize(editor, 'increase'),\n};\n\n/**\n * Shortcut command for Decrease Font\n * Windows: Ctrl + Shift + , (Comma)\n * MacOS: Meta + Shift + , (Comma)\n */\nexport const ShortcutDecreaseFont: ShortcutCommand = {\n shortcutKey: {\n modifierKey: 'ctrl',\n shiftKey: true,\n which: Keys.COMMA,\n },\n onClick: editor => changeFontSize(editor, 'decrease'),\n};\n"]}
@@ -0,0 +1,47 @@
1
+ import type { EditorPlugin, IEditor, PluginEvent } from 'roosterjs-content-model-types';
2
+ /**
3
+ * TableEdit plugin, provides the ability to resize a table by drag-and-drop
4
+ */
5
+ export declare class TableEditPlugin implements EditorPlugin {
6
+ private anchorContainerSelector?;
7
+ private editor;
8
+ private onMouseMoveDisposer;
9
+ private tableRectMap;
10
+ private tableEditor;
11
+ /**
12
+ * Construct a new instance of TableResize plugin
13
+ * @param anchorContainerSelector An optional selector string to specify the container to host the plugin.
14
+ * The container must not be affected by transform: scale(), otherwise the position calculation will be wrong.
15
+ * If not specified, the plugin will be inserted in document.body
16
+ */
17
+ constructor(anchorContainerSelector?: string | undefined);
18
+ /**
19
+ * Get a friendly name of this plugin
20
+ */
21
+ getName(): string;
22
+ /**
23
+ * Initialize this plugin. This should only be called from Editor
24
+ * @param editor Editor instance
25
+ */
26
+ initialize(editor: IEditor): void;
27
+ private onMouseOut;
28
+ /**
29
+ * Dispose this plugin
30
+ */
31
+ dispose(): void;
32
+ /**
33
+ * Handle events triggered from editor
34
+ * @param event PluginEvent object
35
+ */
36
+ onPluginEvent(e: PluginEvent): void;
37
+ private onMouseMove;
38
+ /**
39
+ * @internal Public only for unit test
40
+ * @param table Table to use when setting the Editors
41
+ * @param event (Optional) Mouse event
42
+ */
43
+ setTableEditor(table: HTMLTableElement | null, event?: MouseEvent): void;
44
+ private invalidateTableRects;
45
+ private disposeTableEditor;
46
+ private ensureTableRects;
47
+ }
@@ -0,0 +1,153 @@
1
+ import normalizeRect from '../pluginUtils/Rect/normalizeRect';
2
+ import TableEditor from './editors/TableEditor';
3
+ import { isNodeOfType } from 'roosterjs-content-model-dom';
4
+ var TABLE_RESIZER_LENGTH = 12;
5
+ /**
6
+ * TableEdit plugin, provides the ability to resize a table by drag-and-drop
7
+ */
8
+ var TableEditPlugin = /** @class */ (function () {
9
+ /**
10
+ * Construct a new instance of TableResize plugin
11
+ * @param anchorContainerSelector An optional selector string to specify the container to host the plugin.
12
+ * The container must not be affected by transform: scale(), otherwise the position calculation will be wrong.
13
+ * If not specified, the plugin will be inserted in document.body
14
+ */
15
+ function TableEditPlugin(anchorContainerSelector) {
16
+ var _this = this;
17
+ this.anchorContainerSelector = anchorContainerSelector;
18
+ this.editor = null;
19
+ this.onMouseMoveDisposer = null;
20
+ this.tableRectMap = null;
21
+ this.tableEditor = null;
22
+ this.onMouseOut = function (_a) {
23
+ var relatedTarget = _a.relatedTarget, currentTarget = _a.currentTarget;
24
+ var relatedTargetNode = relatedTarget;
25
+ var currentTargetNode = currentTarget;
26
+ if (isNodeOfType(relatedTargetNode, 'ELEMENT_NODE') &&
27
+ isNodeOfType(currentTargetNode, 'ELEMENT_NODE') &&
28
+ _this.tableEditor &&
29
+ !_this.tableEditor.isOwnedElement(relatedTargetNode) &&
30
+ !currentTargetNode.contains(relatedTargetNode)) {
31
+ _this.setTableEditor(null);
32
+ }
33
+ };
34
+ this.onMouseMove = function (event) {
35
+ var _a;
36
+ var e = event;
37
+ if (e.buttons > 0 || !_this.editor) {
38
+ return;
39
+ }
40
+ _this.ensureTableRects();
41
+ var editorWindow = _this.editor.getDocument().defaultView || window;
42
+ var x = e.pageX - editorWindow.scrollX;
43
+ var y = e.pageY - editorWindow.scrollY;
44
+ var currentTable = null;
45
+ //Find table in range of mouse
46
+ if (_this.tableRectMap) {
47
+ for (var i = _this.tableRectMap.length - 1; i >= 0; i--) {
48
+ var _b = _this.tableRectMap[i], table = _b.table, rect = _b.rect;
49
+ if (x >= rect.left - TABLE_RESIZER_LENGTH &&
50
+ x <= rect.right + TABLE_RESIZER_LENGTH &&
51
+ y >= rect.top - TABLE_RESIZER_LENGTH &&
52
+ y <= rect.bottom + TABLE_RESIZER_LENGTH) {
53
+ currentTable = table;
54
+ break;
55
+ }
56
+ }
57
+ }
58
+ _this.setTableEditor(currentTable, e);
59
+ (_a = _this.tableEditor) === null || _a === void 0 ? void 0 : _a.onMouseMove(x, y);
60
+ };
61
+ this.invalidateTableRects = function () {
62
+ _this.tableRectMap = null;
63
+ };
64
+ }
65
+ /**
66
+ * Get a friendly name of this plugin
67
+ */
68
+ TableEditPlugin.prototype.getName = function () {
69
+ return 'TableEdit';
70
+ };
71
+ /**
72
+ * Initialize this plugin. This should only be called from Editor
73
+ * @param editor Editor instance
74
+ */
75
+ TableEditPlugin.prototype.initialize = function (editor) {
76
+ this.editor = editor;
77
+ this.onMouseMoveDisposer = this.editor.attachDomEvent({
78
+ mousemove: { beforeDispatch: this.onMouseMove },
79
+ });
80
+ var scrollContainer = this.editor.getScrollContainer();
81
+ scrollContainer.addEventListener('mouseout', this.onMouseOut);
82
+ };
83
+ /**
84
+ * Dispose this plugin
85
+ */
86
+ TableEditPlugin.prototype.dispose = function () {
87
+ var _a, _b;
88
+ var scrollContainer = (_a = this.editor) === null || _a === void 0 ? void 0 : _a.getScrollContainer();
89
+ scrollContainer === null || scrollContainer === void 0 ? void 0 : scrollContainer.removeEventListener('mouseout', this.onMouseOut);
90
+ (_b = this.onMouseMoveDisposer) === null || _b === void 0 ? void 0 : _b.call(this);
91
+ this.invalidateTableRects();
92
+ this.disposeTableEditor();
93
+ this.editor = null;
94
+ this.onMouseMoveDisposer = null;
95
+ };
96
+ /**
97
+ * Handle events triggered from editor
98
+ * @param event PluginEvent object
99
+ */
100
+ TableEditPlugin.prototype.onPluginEvent = function (e) {
101
+ switch (e.eventType) {
102
+ case 'input':
103
+ case 'contentChanged':
104
+ case 'scroll':
105
+ case 'zoomChanged':
106
+ this.setTableEditor(null);
107
+ this.invalidateTableRects();
108
+ break;
109
+ }
110
+ };
111
+ /**
112
+ * @internal Public only for unit test
113
+ * @param table Table to use when setting the Editors
114
+ * @param event (Optional) Mouse event
115
+ */
116
+ TableEditPlugin.prototype.setTableEditor = function (table, event) {
117
+ if (this.tableEditor && !this.tableEditor.isEditing() && table != this.tableEditor.table) {
118
+ this.disposeTableEditor();
119
+ }
120
+ if (!this.tableEditor && table && this.editor && table.rows.length > 0) {
121
+ var container = this.anchorContainerSelector
122
+ ? this.editor.getDOMHelper().queryElements(this.anchorContainerSelector)[0]
123
+ : undefined;
124
+ this.tableEditor = new TableEditor(this.editor, table, this.invalidateTableRects, isNodeOfType(container, 'ELEMENT_NODE') ? container : undefined, event === null || event === void 0 ? void 0 : event.currentTarget);
125
+ }
126
+ };
127
+ TableEditPlugin.prototype.disposeTableEditor = function () {
128
+ var _a;
129
+ (_a = this.tableEditor) === null || _a === void 0 ? void 0 : _a.dispose();
130
+ this.tableEditor = null;
131
+ };
132
+ TableEditPlugin.prototype.ensureTableRects = function () {
133
+ var _this = this;
134
+ if (!this.tableRectMap && this.editor) {
135
+ this.tableRectMap = [];
136
+ var tables = this.editor.getDOMHelper().queryElements('table');
137
+ tables.forEach(function (table) {
138
+ if (table.isContentEditable) {
139
+ var rect = normalizeRect(table.getBoundingClientRect());
140
+ if (rect && _this.tableRectMap) {
141
+ _this.tableRectMap.push({
142
+ table: table,
143
+ rect: rect,
144
+ });
145
+ }
146
+ }
147
+ });
148
+ }
149
+ };
150
+ return TableEditPlugin;
151
+ }());
152
+ export { TableEditPlugin };
153
+ //# sourceMappingURL=TableEditPlugin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TableEditPlugin.js","sourceRoot":"","sources":["../../../../packages-content-model/roosterjs-content-model-plugins/lib/tableEdit/TableEditPlugin.ts"],"names":[],"mappings":"AAAA,OAAO,aAAa,MAAM,mCAAmC,CAAC;AAC9D,OAAO,WAAW,MAAM,uBAAuB,CAAC;AAChD,OAAO,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAG3D,IAAM,oBAAoB,GAAG,EAAE,CAAC;AAEhC;;GAEG;AACH;IAMI;;;;;OAKG;IACH,yBAAoB,uBAAgC;QAApD,iBAAwD;QAApC,4BAAuB,GAAvB,uBAAuB,CAAS;QAX5C,WAAM,GAAmB,IAAI,CAAC;QAC9B,wBAAmB,GAAwB,IAAI,CAAC;QAChD,iBAAY,GAAqD,IAAI,CAAC;QACtE,gBAAW,GAAuB,IAAI,CAAC;QA8BvC,eAAU,GAAG,UAAC,EAA4C;gBAA1C,aAAa,mBAAA,EAAE,aAAa,mBAAA;YAChD,IAAM,iBAAiB,GAAG,aAAqB,CAAC;YAChD,IAAM,iBAAiB,GAAG,aAAqB,CAAC;YAChD,IACI,YAAY,CAAC,iBAAiB,EAAE,cAAc,CAAC;gBAC/C,YAAY,CAAC,iBAAiB,EAAE,cAAc,CAAC;gBAC/C,KAAI,CAAC,WAAW;gBAChB,CAAC,KAAI,CAAC,WAAW,CAAC,cAAc,CAAC,iBAAiB,CAAC;gBACnD,CAAC,iBAAiB,CAAC,QAAQ,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;YAEvB,IAAM,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,YAAY,EAAE,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC;YACjE,MAAM,CAAC,OAAO,CAAC,UAAA,KAAK;gBAChB,IAAI,KAAK,CAAC,iBAAiB,EAAE;oBACzB,IAAM,IAAI,GAAG,aAAa,CAAC,KAAK,CAAC,qBAAqB,EAAE,CAAC,CAAC;oBAC1D,IAAI,IAAI,IAAI,KAAI,CAAC,YAAY,EAAE;wBAC3B,KAAI,CAAC,YAAY,CAAC,IAAI,CAAC;4BACnB,KAAK,OAAA;4BACL,IAAI,MAAA;yBACP,CAAC,CAAC;qBACN;iBACJ;YACL,CAAC,CAAC,CAAC;SACN;IACL,CAAC;IACL,sBAAC;AAAD,CAAC,AApKD,IAoKC","sourcesContent":["import normalizeRect from '../pluginUtils/Rect/normalizeRect';\nimport TableEditor from './editors/TableEditor';\nimport { isNodeOfType } from 'roosterjs-content-model-dom';\nimport type { EditorPlugin, IEditor, PluginEvent, Rect } from 'roosterjs-content-model-types';\n\nconst TABLE_RESIZER_LENGTH = 12;\n\n/**\n * TableEdit plugin, provides the ability to resize a table by drag-and-drop\n */\nexport class TableEditPlugin implements EditorPlugin {\n private editor: IEditor | null = null;\n private onMouseMoveDisposer: (() => void) | null = null;\n private tableRectMap: { table: HTMLTableElement; rect: Rect }[] | null = null;\n private tableEditor: TableEditor | null = null;\n\n /**\n * Construct a new instance of TableResize plugin\n * @param anchorContainerSelector An optional selector string to specify the container to host the plugin.\n * The container must not be affected by transform: scale(), otherwise the position calculation will be wrong.\n * If not specified, the plugin will be inserted in document.body\n */\n constructor(private anchorContainerSelector?: string) {}\n\n /**\n * Get a friendly name of this plugin\n */\n getName() {\n return 'TableEdit';\n }\n\n /**\n * Initialize this plugin. This should only be called from Editor\n * @param editor Editor instance\n */\n initialize(editor: IEditor) {\n this.editor = editor;\n this.onMouseMoveDisposer = this.editor.attachDomEvent({\n mousemove: { beforeDispatch: this.onMouseMove },\n });\n const scrollContainer = this.editor.getScrollContainer();\n scrollContainer.addEventListener('mouseout', this.onMouseOut);\n }\n\n private onMouseOut = ({ relatedTarget, currentTarget }: MouseEvent) => {\n const relatedTargetNode = relatedTarget as Node;\n const currentTargetNode = currentTarget as Node;\n if (\n isNodeOfType(relatedTargetNode, 'ELEMENT_NODE') &&\n isNodeOfType(currentTargetNode, 'ELEMENT_NODE') &&\n this.tableEditor &&\n !this.tableEditor.isOwnedElement(relatedTargetNode) &&\n !currentTargetNode.contains(relatedTargetNode)\n ) {\n this.setTableEditor(null);\n }\n };\n\n /**\n * Dispose this plugin\n */\n dispose() {\n const scrollContainer = this.editor?.getScrollContainer();\n scrollContainer?.removeEventListener('mouseout', this.onMouseOut);\n this.onMouseMoveDisposer?.();\n this.invalidateTableRects();\n this.disposeTableEditor();\n this.editor = null;\n this.onMouseMoveDisposer = null;\n }\n\n /**\n * Handle events triggered from editor\n * @param event PluginEvent object\n */\n onPluginEvent(e: PluginEvent) {\n switch (e.eventType) {\n case 'input':\n case 'contentChanged':\n case 'scroll':\n case 'zoomChanged':\n this.setTableEditor(null);\n this.invalidateTableRects();\n break;\n }\n }\n\n private onMouseMove = (event: Event) => {\n const e = event as MouseEvent;\n\n if (e.buttons > 0 || !this.editor) {\n return;\n }\n\n this.ensureTableRects();\n\n const editorWindow = this.editor.getDocument().defaultView || window;\n const x = e.pageX - editorWindow.scrollX;\n const y = e.pageY - editorWindow.scrollY;\n let currentTable: HTMLTableElement | null = null;\n\n //Find table in range of mouse\n if (this.tableRectMap) {\n for (let i = this.tableRectMap.length - 1; i >= 0; i--) {\n const { table, rect } = this.tableRectMap[i];\n\n if (\n x >= rect.left - TABLE_RESIZER_LENGTH &&\n x <= rect.right + TABLE_RESIZER_LENGTH &&\n y >= rect.top - TABLE_RESIZER_LENGTH &&\n y <= rect.bottom + TABLE_RESIZER_LENGTH\n ) {\n currentTable = table;\n break;\n }\n }\n }\n\n this.setTableEditor(currentTable, e);\n this.tableEditor?.onMouseMove(x, y);\n };\n\n /**\n * @internal Public only for unit test\n * @param table Table to use when setting the Editors\n * @param event (Optional) Mouse event\n */\n public setTableEditor(table: HTMLTableElement | null, event?: MouseEvent) {\n if (this.tableEditor && !this.tableEditor.isEditing() && table != this.tableEditor.table) {\n this.disposeTableEditor();\n }\n\n if (!this.tableEditor && table && this.editor && table.rows.length > 0) {\n const container = this.anchorContainerSelector\n ? this.editor.getDOMHelper().queryElements(this.anchorContainerSelector)[0]\n : undefined;\n\n this.tableEditor = new TableEditor(\n this.editor,\n table,\n this.invalidateTableRects,\n isNodeOfType(container as Node, 'ELEMENT_NODE') ? container : undefined,\n event?.currentTarget\n );\n }\n }\n\n private invalidateTableRects = () => {\n this.tableRectMap = null;\n };\n\n private disposeTableEditor() {\n this.tableEditor?.dispose();\n this.tableEditor = null;\n }\n\n private ensureTableRects() {\n if (!this.tableRectMap && this.editor) {\n this.tableRectMap = [];\n\n const tables = this.editor.getDOMHelper().queryElements('table');\n tables.forEach(table => {\n if (table.isContentEditable) {\n const rect = normalizeRect(table.getBoundingClientRect());\n if (rect && this.tableRectMap) {\n this.tableRectMap.push({\n table,\n rect,\n });\n }\n }\n });\n }\n }\n}\n"]}