roosterjs-content-model-plugins 0.20.0 → 0.21.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 (43) hide show
  1. package/lib/edit/ContentModelEditPlugin.js +5 -0
  2. package/lib/edit/ContentModelEditPlugin.js.map +1 -1
  3. package/lib/edit/keyboardDelete.d.ts +1 -2
  4. package/lib/edit/keyboardDelete.js +15 -11
  5. package/lib/edit/keyboardDelete.js.map +1 -1
  6. package/lib/edit/keyboardInput.d.ts +5 -0
  7. package/lib/edit/keyboardInput.js +48 -0
  8. package/lib/edit/keyboardInput.js.map +1 -0
  9. package/lib/entityDelimiter/EntityDelimiterPlugin.d.ts +35 -0
  10. package/lib/entityDelimiter/EntityDelimiterPlugin.js +255 -0
  11. package/lib/entityDelimiter/EntityDelimiterPlugin.js.map +1 -0
  12. package/lib/index.d.ts +1 -0
  13. package/lib/index.js +3 -1
  14. package/lib/index.js.map +1 -1
  15. package/lib-amd/edit/ContentModelEditPlugin.js +5 -1
  16. package/lib-amd/edit/ContentModelEditPlugin.js.map +1 -1
  17. package/lib-amd/edit/keyboardDelete.d.ts +1 -2
  18. package/lib-amd/edit/keyboardDelete.js +15 -11
  19. package/lib-amd/edit/keyboardDelete.js.map +1 -1
  20. package/lib-amd/edit/keyboardInput.d.ts +5 -0
  21. package/lib-amd/edit/keyboardInput.js +49 -0
  22. package/lib-amd/edit/keyboardInput.js.map +1 -0
  23. package/lib-amd/entityDelimiter/EntityDelimiterPlugin.d.ts +35 -0
  24. package/lib-amd/entityDelimiter/EntityDelimiterPlugin.js +254 -0
  25. package/lib-amd/entityDelimiter/EntityDelimiterPlugin.js.map +1 -0
  26. package/lib-amd/index.d.ts +1 -0
  27. package/lib-amd/index.js +3 -2
  28. package/lib-amd/index.js.map +1 -1
  29. package/lib-mjs/edit/ContentModelEditPlugin.js +5 -0
  30. package/lib-mjs/edit/ContentModelEditPlugin.js.map +1 -1
  31. package/lib-mjs/edit/keyboardDelete.d.ts +1 -2
  32. package/lib-mjs/edit/keyboardDelete.js +15 -11
  33. package/lib-mjs/edit/keyboardDelete.js.map +1 -1
  34. package/lib-mjs/edit/keyboardInput.d.ts +5 -0
  35. package/lib-mjs/edit/keyboardInput.js +44 -0
  36. package/lib-mjs/edit/keyboardInput.js.map +1 -0
  37. package/lib-mjs/entityDelimiter/EntityDelimiterPlugin.d.ts +35 -0
  38. package/lib-mjs/entityDelimiter/EntityDelimiterPlugin.js +251 -0
  39. package/lib-mjs/entityDelimiter/EntityDelimiterPlugin.js.map +1 -0
  40. package/lib-mjs/index.d.ts +1 -0
  41. package/lib-mjs/index.js +1 -0
  42. package/lib-mjs/index.js.map +1 -1
  43. package/package.json +5 -5
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ContentModelEditPlugin = void 0;
4
4
  var keyboardDelete_1 = require("./keyboardDelete");
5
+ var keyboardInput_1 = require("./keyboardInput");
5
6
  /**
6
7
  * ContentModel edit plugins helps editor to do editing operation on top of content model.
7
8
  * This includes:
@@ -62,6 +63,10 @@ var ContentModelEditPlugin = /** @class */ (function () {
62
63
  // 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
63
64
  (0, keyboardDelete_1.keyboardDelete)(editor, rawEvent);
64
65
  break;
66
+ case 'Enter':
67
+ default:
68
+ (0, keyboardInput_1.keyboardInput)(editor, rawEvent);
69
+ break;
65
70
  }
66
71
  }
67
72
  };
@@ -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;AAUlD;;;;;GAKG;AACH;IAAA;QACY,WAAM,GAA+B,IAAI,CAAC;IA4DtD,CAAC;IA1DG;;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;aACb;SACJ;IACL,CAAC;IACL,6BAAC;AAAD,CAAC,AA7DD,IA6DC;AA7DY,wDAAsB","sourcesContent":["import { keyboardDelete } from './keyboardDelete';\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 }\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;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"]}
@@ -4,6 +4,5 @@ import type { IContentModelEditor } from 'roosterjs-content-model-editor';
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
- * @returns True if the event is handled with this function, otherwise false
8
7
  */
9
- export declare function keyboardDelete(editor: IContentModelEditor, rawEvent: KeyboardEvent): boolean;
8
+ export declare function keyboardDelete(editor: IContentModelEditor, rawEvent: KeyboardEvent): true | undefined;
@@ -12,16 +12,12 @@ var deleteCollapsedSelection_1 = require("./deleteSteps/deleteCollapsedSelection
12
12
  * Do keyboard event handling for DELETE/BACKSPACE key
13
13
  * @param editor The Content Model Editor
14
14
  * @param rawEvent DOM keyboard event
15
- * @returns True if the event is handled with this function, otherwise false
16
15
  */
17
16
  function keyboardDelete(editor, rawEvent) {
18
17
  var selection = editor.getDOMSelection();
19
- var range = (selection === null || selection === void 0 ? void 0 : selection.type) == 'range' ? selection.range : null;
20
- var isDeleted = false;
21
- if (shouldDeleteWithContentModel(range, rawEvent)) {
18
+ if (shouldDeleteWithContentModel(selection, rawEvent)) {
22
19
  editor.formatContentModel(function (model, context) {
23
20
  var result = (0, roosterjs_content_model_core_1.deleteSelection)(model, getDeleteSteps(rawEvent, !!editor.getEnvironment().isMac), context).deleteResult;
24
- isDeleted = result != 'notDeleted';
25
21
  return (0, handleKeyboardEventCommon_1.handleKeyboardEventResult)(editor, model, rawEvent, result, context);
26
22
  }, {
27
23
  rawEvent: rawEvent,
@@ -31,7 +27,6 @@ function keyboardDelete(editor, rawEvent) {
31
27
  });
32
28
  return true;
33
29
  }
34
- return isDeleted;
35
30
  }
36
31
  exports.keyboardDelete = keyboardDelete;
37
32
  function getDeleteSteps(rawEvent, isMac) {
@@ -47,11 +42,20 @@ function getDeleteSteps(rawEvent, isMac) {
47
42
  : deleteCollapsedSelection_1.backwardDeleteCollapsedSelection;
48
43
  return [deleteAllSegmentBeforeStep, deleteWordSelection, deleteCollapsedSelection];
49
44
  }
50
- function shouldDeleteWithContentModel(range, rawEvent) {
51
- return !((range === null || range === void 0 ? void 0 : range.collapsed) &&
52
- (0, roosterjs_content_model_dom_1.isNodeOfType)(range.startContainer, 'TEXT_NODE') &&
53
- !(0, roosterjs_content_model_core_1.isModifierKey)(rawEvent) &&
54
- (canDeleteBefore(rawEvent, range) || canDeleteAfter(rawEvent, range)));
45
+ function shouldDeleteWithContentModel(selection, rawEvent) {
46
+ if (!selection) {
47
+ return false; // Nothing to delete
48
+ }
49
+ else if (selection.type != 'range' || !selection.range.collapsed) {
50
+ return true; // Selection is not collapsed, need to delete all selections
51
+ }
52
+ else {
53
+ var range = selection.range;
54
+ // When selection is collapsed and is in middle of text node, no need to use Content Model to delete
55
+ return !((0, roosterjs_content_model_dom_1.isNodeOfType)(range.startContainer, 'TEXT_NODE') &&
56
+ !(0, roosterjs_content_model_core_1.isModifierKey)(rawEvent) &&
57
+ (canDeleteBefore(rawEvent, range) || canDeleteAfter(rawEvent, range)));
58
+ }
55
59
  }
56
60
  function canDeleteBefore(rawEvent, range) {
57
61
  return rawEvent.key == 'Backspace' && range.startOffset > 1;
@@ -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;;;;;;GAMG;AACH,SAAgB,cAAc,CAAC,MAA2B,EAAE,QAAuB;IAC/E,IAAM,SAAS,GAAG,MAAM,CAAC,eAAe,EAAE,CAAC;IAC3C,IAAM,KAAK,GAAG,CAAA,SAAS,aAAT,SAAS,uBAAT,SAAS,CAAE,IAAI,KAAI,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC;IAClE,IAAI,SAAS,GAAG,KAAK,CAAC;IAEtB,IAAI,4BAA4B,CAAC,KAAK,EAAE,QAAQ,CAAC,EAAE;QAC/C,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,CA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C,cAAc,EAAE,WAAW,CAAC;QAC/C,CAAC,IAAA,4CAAa,EAAC,QAAQ,CAAC;QACxB,CAAC,eAAe,CAAC,QAAQ,EAAE,KAAK,CAAC,IAAI,cAAc,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC,CACxE,CAAC;AACN,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 { 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 { 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 * @returns True if the event is handled with this function, otherwise false\n */\nexport function keyboardDelete(editor: IContentModelEditor, rawEvent: KeyboardEvent): boolean {\n const selection = editor.getDOMSelection();\n const range = selection?.type == 'range' ? selection.range : null;\n let isDeleted = false;\n\n if (shouldDeleteWithContentModel(range, 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 isDeleted = result != 'notDeleted';\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 return isDeleted;\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(range: Range | null, rawEvent: KeyboardEvent) {\n return !(\n range?.collapsed &&\n isNodeOfType(range.startContainer, 'TEXT_NODE') &&\n !isModifierKey(rawEvent) &&\n (canDeleteBefore(rawEvent, range) || canDeleteAfter(rawEvent, range))\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/keyboardDel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C;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"]}
@@ -0,0 +1,5 @@
1
+ import type { IContentModelEditor } from 'roosterjs-content-model-editor';
2
+ /**
3
+ * @internal
4
+ */
5
+ export declare function keyboardInput(editor: IContentModelEditor, rawEvent: KeyboardEvent): true | undefined;
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.keyboardInput = void 0;
4
+ var roosterjs_content_model_core_1 = require("roosterjs-content-model-core");
5
+ /**
6
+ * @internal
7
+ */
8
+ function keyboardInput(editor, rawEvent) {
9
+ var selection = editor.getDOMSelection();
10
+ if (shouldInputWithContentModel(selection, rawEvent)) {
11
+ editor.addUndoSnapshot();
12
+ editor.formatContentModel(function (model, context) {
13
+ var _a;
14
+ var result = (0, roosterjs_content_model_core_1.deleteSelection)(model, [], context);
15
+ // We have deleted selection then we will let browser to handle the input.
16
+ // With this combined operation, we don't wan to mass up the cached model so clear it
17
+ context.clearModelCache = true;
18
+ // 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
19
+ context.skipUndoSnapshot = true;
20
+ if (result.deleteResult == 'range') {
21
+ // We have deleted something, next input should inherit the segment format from deleted content, so set pending format here
22
+ context.newPendingFormat = (_a = result.insertPoint) === null || _a === void 0 ? void 0 : _a.marker.format;
23
+ // Do not preventDefault since we still want browser to handle the final input for now
24
+ return true;
25
+ }
26
+ else {
27
+ return false;
28
+ }
29
+ }, {
30
+ rawEvent: rawEvent,
31
+ });
32
+ return true;
33
+ }
34
+ }
35
+ exports.keyboardInput = keyboardInput;
36
+ function shouldInputWithContentModel(selection, rawEvent) {
37
+ if (!selection) {
38
+ return false; // Nothing to delete
39
+ }
40
+ else if (!(0, roosterjs_content_model_core_1.isModifierKey)(rawEvent) &&
41
+ (rawEvent.key == 'Enter' || rawEvent.key == 'Space' || rawEvent.key.length == 1)) {
42
+ return selection.type != 'range' || !selection.range.collapsed; // TODO: Also handle Enter key even selection is collapsed
43
+ }
44
+ else {
45
+ return false;
46
+ }
47
+ }
48
+ //# sourceMappingURL=keyboardInput.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"keyboardInput.js","sourceRoot":"","sources":["../../../../packages-content-model/roosterjs-content-model-plugins/lib/edit/keyboardInput.ts"],"names":[],"mappings":";;;AAAA,6EAA8E;AAI9E;;GAEG;AACH,SAAgB,aAAa,CAAC,MAA2B,EAAE,QAAuB;IAC9E,IAAM,SAAS,GAAG,MAAM,CAAC,eAAe,EAAE,CAAC;IAE3C,IAAI,2BAA2B,CAAC,SAAS,EAAE,QAAQ,CAAC,EAAE;QAClD,MAAM,CAAC,eAAe,EAAE,CAAC;QAEzB,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,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;AAlCD,sCAkCC;AAED,SAAS,2BAA2B,CAAC,SAA8B,EAAE,QAAuB;IACxF,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,SAAS,CAAC,IAAI,IAAI,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,0DAA0D;KAC7H;SAAM;QACH,OAAO,KAAK,CAAC;KAChB;AACL,CAAC","sourcesContent":["import { deleteSelection, isModifierKey } from 'roosterjs-content-model-core';\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)) {\n editor.addUndoSnapshot();\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 // 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(selection: DOMSelection | null, rawEvent: KeyboardEvent) {\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 selection.type != 'range' || !selection.range.collapsed; // TODO: Also handle Enter key even selection is collapsed\n } else {\n return false;\n }\n}\n"]}
@@ -0,0 +1,35 @@
1
+ import type { EditorPlugin, IEditor, PluginEvent } from 'roosterjs-editor-types';
2
+ /**
3
+ * Entity delimiter plugin helps maintain delimiter elements around an entity so that user can put focus before/after an entity
4
+ */
5
+ export declare class EntityDelimiterPlugin implements EditorPlugin {
6
+ private editor;
7
+ /**
8
+ * Get a friendly name of this plugin
9
+ */
10
+ getName(): string;
11
+ /**
12
+ * The first method that editor will call to a plugin when editor is initializing.
13
+ * It will pass in the editor instance, plugin should take this chance to save the
14
+ * editor reference so that it can call to any editor method or format API later.
15
+ * @param editor The editor object
16
+ */
17
+ initialize(editor: IEditor): void;
18
+ /**
19
+ * The last method that editor will call to a plugin before it is disposed.
20
+ * Plugin can take this chance to clear the reference to editor. After this method is
21
+ * called, plugin should not call to any editor method since it will result in error.
22
+ */
23
+ dispose(): void;
24
+ /**
25
+ * Core method for a plugin. Once an event happens in editor, editor will call this
26
+ * method of each plugin to handle the event as long as the event is not handled
27
+ * exclusively by another plugin.
28
+ * @param event The event to handle:
29
+ */
30
+ onPluginEvent(event: PluginEvent): void;
31
+ }
32
+ /**
33
+ * @internal
34
+ */
35
+ export declare function normalizeDelimitersInEditor(editor: IEditor): void;
@@ -0,0 +1,255 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.normalizeDelimitersInEditor = exports.EntityDelimiterPlugin = void 0;
4
+ var roosterjs_content_model_core_1 = require("roosterjs-content-model-core");
5
+ var roosterjs_content_model_dom_1 = require("roosterjs-content-model-dom");
6
+ var roosterjs_editor_dom_1 = require("roosterjs-editor-dom");
7
+ var DELIMITER_SELECTOR = '.' + "entityDelimiterAfter" /* DELIMITER_AFTER */ + ',.' + "entityDelimiterBefore" /* DELIMITER_BEFORE */;
8
+ var ZERO_WIDTH_SPACE = '\u200B';
9
+ var INLINE_ENTITY_SELECTOR = 'span' + (0, roosterjs_editor_dom_1.getEntitySelector)();
10
+ /**
11
+ * Entity delimiter plugin helps maintain delimiter elements around an entity so that user can put focus before/after an entity
12
+ */
13
+ var EntityDelimiterPlugin = /** @class */ (function () {
14
+ function EntityDelimiterPlugin() {
15
+ this.editor = null;
16
+ }
17
+ /**
18
+ * Get a friendly name of this plugin
19
+ */
20
+ EntityDelimiterPlugin.prototype.getName = function () {
21
+ return 'EntityDelimiter';
22
+ };
23
+ /**
24
+ * The first method that editor will call to a plugin when editor is initializing.
25
+ * It will pass in the editor instance, plugin should take this chance to save the
26
+ * editor reference so that it can call to any editor method or format API later.
27
+ * @param editor The editor object
28
+ */
29
+ EntityDelimiterPlugin.prototype.initialize = function (editor) {
30
+ this.editor = editor;
31
+ };
32
+ /**
33
+ * The last method that editor will call to a plugin before it is disposed.
34
+ * Plugin can take this chance to clear the reference to editor. After this method is
35
+ * called, plugin should not call to any editor method since it will result in error.
36
+ */
37
+ EntityDelimiterPlugin.prototype.dispose = function () {
38
+ this.editor = null;
39
+ };
40
+ /**
41
+ * Core method for a plugin. Once an event happens in editor, editor will call this
42
+ * method of each plugin to handle the event as long as the event is not handled
43
+ * exclusively by another plugin.
44
+ * @param event The event to handle:
45
+ */
46
+ EntityDelimiterPlugin.prototype.onPluginEvent = function (event) {
47
+ if (this.editor) {
48
+ switch (event.eventType) {
49
+ case 7 /* ContentChanged */:
50
+ case 11 /* EditorReady */:
51
+ normalizeDelimitersInEditor(this.editor);
52
+ break;
53
+ case 10 /* BeforePaste */:
54
+ var fragment = event.fragment;
55
+ addDelimitersIfNeeded(fragment.querySelectorAll(INLINE_ENTITY_SELECTOR));
56
+ break;
57
+ case 8 /* ExtractContentWithDom */:
58
+ case 9 /* BeforeCutCopy */:
59
+ event.clonedRoot.querySelectorAll(DELIMITER_SELECTOR).forEach(function (node) {
60
+ if ((0, roosterjs_editor_dom_1.getDelimiterFromElement)(node)) {
61
+ removeNode(node);
62
+ }
63
+ else {
64
+ removeDelimiterAttr(node);
65
+ }
66
+ });
67
+ break;
68
+ case 0 /* KeyDown */:
69
+ handleKeyDownEvent(this.editor, event);
70
+ break;
71
+ }
72
+ }
73
+ };
74
+ return EntityDelimiterPlugin;
75
+ }());
76
+ exports.EntityDelimiterPlugin = EntityDelimiterPlugin;
77
+ function preventTypeInDelimiter(delimiter) {
78
+ var _a, _b, _c, _d;
79
+ delimiter.normalize();
80
+ var textNode = delimiter.firstChild;
81
+ var index = (_b = (_a = textNode.nodeValue) === null || _a === void 0 ? void 0 : _a.indexOf(ZERO_WIDTH_SPACE)) !== null && _b !== void 0 ? _b : -1;
82
+ if (index >= 0) {
83
+ (0, roosterjs_editor_dom_1.splitTextNode)(textNode, index == 0 ? 1 : index, false /* returnFirstPart */);
84
+ var nodeToMove_1;
85
+ delimiter.childNodes.forEach(function (node) {
86
+ if (node.nodeValue !== ZERO_WIDTH_SPACE) {
87
+ nodeToMove_1 = node;
88
+ }
89
+ });
90
+ if (nodeToMove_1) {
91
+ (_c = delimiter.parentElement) === null || _c === void 0 ? void 0 : _c.insertBefore(nodeToMove_1, delimiter.className == "entityDelimiterBefore" /* DELIMITER_BEFORE */
92
+ ? delimiter
93
+ : delimiter.nextSibling);
94
+ var selection = (_d = nodeToMove_1.ownerDocument) === null || _d === void 0 ? void 0 : _d.getSelection();
95
+ if (selection) {
96
+ selection.setPosition(nodeToMove_1, new roosterjs_editor_dom_1.Position(nodeToMove_1, -1 /* End */).offset);
97
+ }
98
+ }
99
+ }
100
+ }
101
+ /**
102
+ * @internal
103
+ */
104
+ function normalizeDelimitersInEditor(editor) {
105
+ removeInvalidDelimiters(editor.queryElements(DELIMITER_SELECTOR));
106
+ addDelimitersIfNeeded(editor.queryElements(INLINE_ENTITY_SELECTOR));
107
+ }
108
+ exports.normalizeDelimitersInEditor = normalizeDelimitersInEditor;
109
+ function addDelimitersIfNeeded(nodes) {
110
+ nodes.forEach(function (node) {
111
+ if ((0, roosterjs_content_model_dom_1.isEntityElement)(node)) {
112
+ (0, roosterjs_content_model_dom_1.addDelimiters)(node.ownerDocument, node);
113
+ }
114
+ });
115
+ }
116
+ function removeNode(el) {
117
+ var _a;
118
+ (_a = el === null || el === void 0 ? void 0 : el.parentElement) === null || _a === void 0 ? void 0 : _a.removeChild(el);
119
+ }
120
+ function removeInvalidDelimiters(nodes) {
121
+ nodes.forEach(function (node) {
122
+ if ((0, roosterjs_editor_dom_1.getDelimiterFromElement)(node)) {
123
+ var sibling = node.classList.contains("entityDelimiterBefore" /* DELIMITER_BEFORE */)
124
+ ? node.nextElementSibling
125
+ : node.previousElementSibling;
126
+ if (!((0, roosterjs_content_model_dom_1.isNodeOfType)(sibling, 'ELEMENT_NODE') && (0, roosterjs_editor_dom_1.getEntityFromElement)(sibling))) {
127
+ removeNode(node);
128
+ }
129
+ }
130
+ else {
131
+ removeDelimiterAttr(node);
132
+ }
133
+ });
134
+ }
135
+ function removeDelimiterAttr(node, checkEntity) {
136
+ if (checkEntity === void 0) { checkEntity = true; }
137
+ if (!node) {
138
+ return;
139
+ }
140
+ var isAfter = node.classList.contains("entityDelimiterAfter" /* DELIMITER_AFTER */);
141
+ var entitySibling = isAfter ? node.previousElementSibling : node.nextElementSibling;
142
+ if (checkEntity && entitySibling && (0, roosterjs_content_model_dom_1.isEntityElement)(entitySibling)) {
143
+ return;
144
+ }
145
+ node.classList.remove("entityDelimiterAfter" /* DELIMITER_AFTER */, "entityDelimiterBefore" /* DELIMITER_BEFORE */);
146
+ node.normalize();
147
+ node.childNodes.forEach(function (cn) {
148
+ var _a, _b, _c;
149
+ var index = (_b = (_a = cn.textContent) === null || _a === void 0 ? void 0 : _a.indexOf(ZERO_WIDTH_SPACE)) !== null && _b !== void 0 ? _b : -1;
150
+ if (index >= 0) {
151
+ (_c = (0, roosterjs_editor_dom_1.createRange)(cn, index, cn, index + 1)) === null || _c === void 0 ? void 0 : _c.deleteContents();
152
+ }
153
+ });
154
+ }
155
+ function handleCollapsedEnter(editor, delimiter) {
156
+ var isAfter = delimiter.classList.contains("entityDelimiterAfter" /* DELIMITER_AFTER */);
157
+ var entity = !isAfter ? delimiter.nextSibling : delimiter.previousSibling;
158
+ var block = getBlock(editor, delimiter);
159
+ editor.runAsync(function () {
160
+ if (!block) {
161
+ return;
162
+ }
163
+ var blockToCheck = isAfter ? block.nextSibling : block.previousSibling;
164
+ if (blockToCheck && (0, roosterjs_content_model_dom_1.isNodeOfType)(blockToCheck, 'ELEMENT_NODE')) {
165
+ var delimiters = blockToCheck.querySelectorAll(DELIMITER_SELECTOR);
166
+ // Check if the last or first delimiter still contain the delimiter class and remove it.
167
+ var delimiterToCheck = delimiters.item(isAfter ? 0 : delimiters.length - 1);
168
+ removeDelimiterAttr(delimiterToCheck);
169
+ }
170
+ if (entity && (0, roosterjs_content_model_dom_1.isEntityElement)(entity)) {
171
+ var entityElement = entity;
172
+ var nextElementSibling = entityElement.nextElementSibling, previousElementSibling = entityElement.previousElementSibling;
173
+ [nextElementSibling, previousElementSibling].forEach(function (el) {
174
+ // Check if after Enter the ZWS got removed but we still have a element with the class
175
+ // Remove the attributes of the element if it is invalid now.
176
+ if (el && (0, roosterjs_editor_dom_1.matchesSelector)(el, DELIMITER_SELECTOR) && !(0, roosterjs_editor_dom_1.getDelimiterFromElement)(el)) {
177
+ removeDelimiterAttr(el, false /* checkEntity */);
178
+ }
179
+ });
180
+ // Add delimiters to the entity if needed because on Enter we can sometimes lose the ZWS of the element.
181
+ (0, roosterjs_content_model_dom_1.addDelimiters)(entityElement.ownerDocument, entityElement);
182
+ }
183
+ });
184
+ }
185
+ var getPosition = function (container) {
186
+ if (container && (0, roosterjs_editor_dom_1.getDelimiterFromElement)(container)) {
187
+ var isAfter = container.classList.contains("entityDelimiterAfter" /* DELIMITER_AFTER */);
188
+ return new roosterjs_editor_dom_1.Position(container, isAfter ? -3 /* After */ : -2 /* Before */);
189
+ }
190
+ return undefined;
191
+ };
192
+ function getBlock(editor, element) {
193
+ var _a;
194
+ if (!element) {
195
+ return undefined;
196
+ }
197
+ var block = (_a = editor.getBlockElementAtNode(element)) === null || _a === void 0 ? void 0 : _a.getStartNode();
198
+ while (block && (!(0, roosterjs_content_model_dom_1.isNodeOfType)(block, 'ELEMENT_NODE') || !(0, roosterjs_content_model_dom_1.isBlockElement)(block))) {
199
+ block = editor.contains(block.parentElement) ? block.parentElement : undefined;
200
+ }
201
+ return block;
202
+ }
203
+ function handleSelectionNotCollapsed(editor, range, event) {
204
+ var startContainer = range.startContainer, endContainer = range.endContainer, startOffset = range.startOffset, endOffset = range.endOffset;
205
+ var startElement = editor.getElementAtCursor(DELIMITER_SELECTOR, startContainer);
206
+ var endElement = editor.getElementAtCursor(DELIMITER_SELECTOR, endContainer);
207
+ var startUpdate = getPosition(startElement);
208
+ var endUpdate = getPosition(endElement);
209
+ if (startUpdate || endUpdate) {
210
+ editor.select(startUpdate !== null && startUpdate !== void 0 ? startUpdate : new roosterjs_editor_dom_1.Position(startContainer, startOffset), endUpdate !== null && endUpdate !== void 0 ? endUpdate : new roosterjs_editor_dom_1.Position(endContainer, endOffset));
211
+ }
212
+ editor.runAsync(function (aEditor) {
213
+ var delimiter = aEditor.getElementAtCursor(DELIMITER_SELECTOR);
214
+ if (delimiter) {
215
+ preventTypeInDelimiter(delimiter);
216
+ if (event.which === 13 /* ENTER */) {
217
+ removeDelimiterAttr(delimiter);
218
+ }
219
+ }
220
+ });
221
+ }
222
+ function handleKeyDownEvent(editor, event) {
223
+ var _a, _b;
224
+ var range = editor.getSelectionRangeEx();
225
+ var rawEvent = event.rawEvent;
226
+ if (range.type != 0 /* Normal */) {
227
+ return;
228
+ }
229
+ if (range.areAllCollapsed && ((0, roosterjs_content_model_core_1.isCharacterValue)(rawEvent) || rawEvent.which === 13 /* ENTER */)) {
230
+ var position = (_a = editor.getFocusedPosition()) === null || _a === void 0 ? void 0 : _a.normalize();
231
+ if (!position) {
232
+ return;
233
+ }
234
+ var element = position.element, node = position.node;
235
+ var refNode = element == node ? element.childNodes.item(position.offset) : element;
236
+ var delimiter_1 = editor.getElementAtCursor(DELIMITER_SELECTOR, refNode);
237
+ if (!delimiter_1) {
238
+ return;
239
+ }
240
+ if (rawEvent.which === 13 /* ENTER */) {
241
+ handleCollapsedEnter(editor, delimiter_1);
242
+ }
243
+ else if (((_b = delimiter_1.firstChild) === null || _b === void 0 ? void 0 : _b.nodeType) == 3 /* Text */) {
244
+ editor.runAsync(function () { return preventTypeInDelimiter(delimiter_1); });
245
+ }
246
+ }
247
+ else if (!range.areAllCollapsed && !rawEvent.shiftKey && rawEvent.which != 16 /* SHIFT */) {
248
+ var currentRange = range.ranges[0];
249
+ if (!currentRange) {
250
+ return;
251
+ }
252
+ handleSelectionNotCollapsed(editor, currentRange, rawEvent);
253
+ }
254
+ }
255
+ //# sourceMappingURL=EntityDelimiterPlugin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"EntityDelimiterPlugin.js","sourceRoot":"","sources":["../../../../packages-content-model/roosterjs-content-model-plugins/lib/entityDelimiter/EntityDelimiterPlugin.ts"],"names":[],"mappings":";;;AAAA,6EAAgE;AAChE,2EAKqC;AASrC,6DAQ8B;AAS9B,IAAM,kBAAkB,GACpB,GAAG,+CAAmC,GAAG,IAAI,iDAAoC,CAAC;AACtF,IAAM,gB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KAAK,CAAC,eAAe,IAAI,CAAC,QAAQ,CAAC,QAAQ,IAAI,QAAQ,CAAC,KAAK,kBAAc,EAAE;QACrF,IAAM,YAAY,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;QACrC,IAAI,CAAC,YAAY,EAAE;YACf,OAAO;SACV;QACD,2BAA2B,CAAC,MAAM,EAAE,YAAY,EAAE,QAAQ,CAAC,CAAC;KAC/D;AACL,CAAC","sourcesContent":["import { isCharacterValue } from 'roosterjs-content-model-core';\nimport {\n addDelimiters,\n isBlockElement,\n isEntityElement,\n isNodeOfType,\n} from 'roosterjs-content-model-dom';\nimport {\n DelimiterClasses,\n Keys,\n NodeType,\n PluginEventType,\n PositionType,\n SelectionRangeTypes,\n} from 'roosterjs-editor-types';\nimport {\n Position,\n createRange,\n getDelimiterFromElement,\n getEntityFromElement,\n getEntitySelector,\n matchesSelector,\n splitTextNode,\n} from 'roosterjs-editor-dom';\nimport type {\n EditorPlugin,\n IEditor,\n PluginEvent,\n PluginKeyDownEvent,\n} from 'roosterjs-editor-types';\nimport type { IContentModelEditor } from 'roosterjs-content-model-editor';\n\nconst DELIMITER_SELECTOR =\n '.' + DelimiterClasses.DELIMITER_AFTER + ',.' + DelimiterClasses.DELIMITER_BEFORE;\nconst ZERO_WIDTH_SPACE = '\\u200B';\nconst INLINE_ENTITY_SELECTOR = 'span' + getEntitySelector();\n\n/**\n * Entity delimiter plugin helps maintain delimiter elements around an entity so that user can put focus before/after an entity\n */\nexport class EntityDelimiterPlugin implements EditorPlugin {\n private editor: IContentModelEditor | null = null;\n\n /**\n * Get a friendly name of this plugin\n */\n getName() {\n return 'EntityDelimiter';\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 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.ContentChanged:\n case PluginEventType.EditorReady:\n normalizeDelimitersInEditor(this.editor);\n break;\n\n case PluginEventType.BeforePaste:\n const { fragment } = event;\n addDelimitersIfNeeded(fragment.querySelectorAll(INLINE_ENTITY_SELECTOR));\n\n break;\n\n case PluginEventType.ExtractContentWithDom:\n case PluginEventType.BeforeCutCopy:\n event.clonedRoot.querySelectorAll(DELIMITER_SELECTOR).forEach(node => {\n if (getDelimiterFromElement(node)) {\n removeNode(node);\n } else {\n removeDelimiterAttr(node);\n }\n });\n break;\n\n case PluginEventType.KeyDown:\n handleKeyDownEvent(this.editor, event);\n break;\n }\n }\n }\n}\n\nfunction preventTypeInDelimiter(delimiter: HTMLElement) {\n delimiter.normalize();\n const textNode = delimiter.firstChild as Node;\n const index = textNode.nodeValue?.indexOf(ZERO_WIDTH_SPACE) ?? -1;\n if (index >= 0) {\n splitTextNode(<Text>textNode, index == 0 ? 1 : index, false /* returnFirstPart */);\n let nodeToMove: Node | undefined;\n delimiter.childNodes.forEach(node => {\n if (node.nodeValue !== ZERO_WIDTH_SPACE) {\n nodeToMove = node;\n }\n });\n if (nodeToMove) {\n delimiter.parentElement?.insertBefore(\n nodeToMove,\n delimiter.className == DelimiterClasses.DELIMITER_BEFORE\n ? delimiter\n : delimiter.nextSibling\n );\n const selection = nodeToMove.ownerDocument?.getSelection();\n\n if (selection) {\n selection.setPosition(\n nodeToMove,\n new Position(nodeToMove, PositionType.End).offset\n );\n }\n }\n }\n}\n\n/**\n * @internal\n */\nexport function normalizeDelimitersInEditor(editor: IEditor) {\n removeInvalidDelimiters(editor.queryElements(DELIMITER_SELECTOR));\n addDelimitersIfNeeded(editor.queryElements(INLINE_ENTITY_SELECTOR));\n}\n\nfunction addDelimitersIfNeeded(nodes: Element[] | NodeListOf<Element>) {\n nodes.forEach(node => {\n if (isEntityElement(node)) {\n addDelimiters(node.ownerDocument, node as HTMLElement);\n }\n });\n}\n\nfunction removeNode(el: Node | undefined | null) {\n el?.parentElement?.removeChild(el);\n}\n\nfunction removeInvalidDelimiters(nodes: Element[] | NodeListOf<Element>) {\n nodes.forEach(node => {\n if (getDelimiterFromElement(node)) {\n const sibling = node.classList.contains(DelimiterClasses.DELIMITER_BEFORE)\n ? node.nextElementSibling\n : node.previousElementSibling;\n if (!(isNodeOfType(sibling, 'ELEMENT_NODE') && getEntityFromElement(sibling))) {\n removeNode(node);\n }\n } else {\n removeDelimiterAttr(node);\n }\n });\n}\n\nfunction removeDelimiterAttr(node: Element | undefined | null, checkEntity: boolean = true) {\n if (!node) {\n return;\n }\n\n const isAfter = node.classList.contains(DelimiterClasses.DELIMITER_AFTER);\n const entitySibling = isAfter ? node.previousElementSibling : node.nextElementSibling;\n if (checkEntity && entitySibling && isEntityElement(entitySibling)) {\n return;\n }\n\n node.classList.remove(DelimiterClasses.DELIMITER_AFTER, DelimiterClasses.DELIMITER_BEFORE);\n\n node.normalize();\n node.childNodes.forEach(cn => {\n const index = cn.textContent?.indexOf(ZERO_WIDTH_SPACE) ?? -1;\n if (index >= 0) {\n createRange(cn, index, cn, index + 1)?.deleteContents();\n }\n });\n}\n\nfunction handleCollapsedEnter(editor: IEditor, delimiter: HTMLElement) {\n const isAfter = delimiter.classList.contains(DelimiterClasses.DELIMITER_AFTER);\n const entity = !isAfter ? delimiter.nextSibling : delimiter.previousSibling;\n const block = getBlock(editor, delimiter);\n\n editor.runAsync(() => {\n if (!block) {\n return;\n }\n const blockToCheck = isAfter ? block.nextSibling : block.previousSibling;\n if (blockToCheck && isNodeOfType(blockToCheck, 'ELEMENT_NODE')) {\n const delimiters = blockToCheck.querySelectorAll(DELIMITER_SELECTOR);\n // Check if the last or first delimiter still contain the delimiter class and remove it.\n const delimiterToCheck = delimiters.item(isAfter ? 0 : delimiters.length - 1);\n removeDelimiterAttr(delimiterToCheck);\n }\n\n if (entity && isEntityElement(entity)) {\n const entityElement = entity as HTMLElement;\n const { nextElementSibling, previousElementSibling } = entityElement;\n [nextElementSibling, previousElementSibling].forEach(el => {\n // Check if after Enter the ZWS got removed but we still have a element with the class\n // Remove the attributes of the element if it is invalid now.\n if (el && matchesSelector(el, DELIMITER_SELECTOR) && !getDelimiterFromElement(el)) {\n removeDelimiterAttr(el, false /* checkEntity */);\n }\n });\n\n // Add delimiters to the entity if needed because on Enter we can sometimes lose the ZWS of the element.\n addDelimiters(entityElement.ownerDocument, entityElement);\n }\n });\n}\n\nconst getPosition = (container: HTMLElement | null) => {\n if (container && getDelimiterFromElement(container)) {\n const isAfter = container.classList.contains(DelimiterClasses.DELIMITER_AFTER);\n return new Position(container, isAfter ? PositionType.After : PositionType.Before);\n }\n return undefined;\n};\n\nfunction getBlock(editor: IEditor, element: Node | undefined) {\n if (!element) {\n return undefined;\n }\n\n let block = editor.getBlockElementAtNode(element)?.getStartNode();\n\n while (block && (!isNodeOfType(block, 'ELEMENT_NODE') || !isBlockElement(block))) {\n block = editor.contains(block.parentElement) ? block.parentElement! : undefined;\n }\n\n return block;\n}\n\nfunction handleSelectionNotCollapsed(editor: IEditor, range: Range, event: KeyboardEvent) {\n const { startContainer, endContainer, startOffset, endOffset } = range;\n\n const startElement = editor.getElementAtCursor(DELIMITER_SELECTOR, startContainer);\n const endElement = editor.getElementAtCursor(DELIMITER_SELECTOR, endContainer);\n\n const startUpdate = getPosition(startElement);\n const endUpdate = getPosition(endElement);\n\n if (startUpdate || endUpdate) {\n editor.select(\n startUpdate ?? new Position(startContainer, startOffset),\n endUpdate ?? new Position(endContainer, endOffset)\n );\n }\n editor.runAsync(aEditor => {\n const delimiter = aEditor.getElementAtCursor(DELIMITER_SELECTOR);\n if (delimiter) {\n preventTypeInDelimiter(delimiter);\n if (event.which === Keys.ENTER) {\n removeDelimiterAttr(delimiter);\n }\n }\n });\n}\n\nfunction handleKeyDownEvent(editor: IEditor, event: PluginKeyDownEvent) {\n const range = editor.getSelectionRangeEx();\n const { rawEvent } = event;\n if (range.type != SelectionRangeTypes.Normal) {\n return;\n }\n\n if (range.areAllCollapsed && (isCharacterValue(rawEvent) || rawEvent.which === Keys.ENTER)) {\n const position = editor.getFocusedPosition()?.normalize();\n if (!position) {\n return;\n }\n\n const { element, node } = position;\n const refNode = element == node ? element.childNodes.item(position.offset) : element;\n\n const delimiter = editor.getElementAtCursor(DELIMITER_SELECTOR, refNode);\n if (!delimiter) {\n return;\n }\n\n if (rawEvent.which === Keys.ENTER) {\n handleCollapsedEnter(editor, delimiter);\n } else if (delimiter.firstChild?.nodeType == NodeType.Text) {\n editor.runAsync(() => preventTypeInDelimiter(delimiter));\n }\n } else if (!range.areAllCollapsed && !rawEvent.shiftKey && rawEvent.which != Keys.SHIFT) {\n const currentRange = range.ranges[0];\n if (!currentRange) {\n return;\n }\n handleSelectionNotCollapsed(editor, currentRange, rawEvent);\n }\n}\n"]}
package/lib/index.d.ts CHANGED
@@ -1,2 +1,3 @@
1
1
  export { ContentModelPastePlugin } from './paste/ContentModelPastePlugin';
2
2
  export { ContentModelEditPlugin } from './edit/ContentModelEditPlugin';
3
+ export { EntityDelimiterPlugin } from './entityDelimiter/EntityDelimiterPlugin';
package/lib/index.js CHANGED
@@ -1,8 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ContentModelEditPlugin = exports.ContentModelPastePlugin = void 0;
3
+ exports.EntityDelimiterPlugin = exports.ContentModelEditPlugin = exports.ContentModelPastePlugin = void 0;
4
4
  var ContentModelPastePlugin_1 = require("./paste/ContentModelPastePlugin");
5
5
  Object.defineProperty(exports, "ContentModelPastePlugin", { enumerable: true, get: function () { return ContentModelPastePlugin_1.ContentModelPastePlugin; } });
6
6
  var ContentModelEditPlugin_1 = require("./edit/ContentModelEditPlugin");
7
7
  Object.defineProperty(exports, "ContentModelEditPlugin", { enumerable: true, get: function () { return ContentModelEditPlugin_1.ContentModelEditPlugin; } });
8
+ var EntityDelimiterPlugin_1 = require("./entityDelimiter/EntityDelimiterPlugin");
9
+ Object.defineProperty(exports, "EntityDelimiterPlugin", { enumerable: true, get: function () { return EntityDelimiterPlugin_1.EntityDelimiterPlugin; } });
8
10
  //# sourceMappingURL=index.js.map
package/lib/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../packages-content-model/roosterjs-content-model-plugins/lib/index.ts"],"names":[],"mappings":";;;AAAA,2EAA0E;AAAjE,kIAAA,uBAAuB,OAAA;AAChC,wEAAuE;AAA9D,gIAAA,sBAAsB,OAAA","sourcesContent":["export { ContentModelPastePlugin } from './paste/ContentModelPastePlugin';\nexport { ContentModelEditPlugin } from './edit/ContentModelEditPlugin';\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../packages-content-model/roosterjs-content-model-plugins/lib/index.ts"],"names":[],"mappings":";;;AAAA,2EAA0E;AAAjE,kIAAA,uBAAuB,OAAA;AAChC,wEAAuE;AAA9D,gIAAA,sBAAsB,OAAA;AAC/B,iFAAgF;AAAvE,8HAAA,qBAAqB,OAAA","sourcesContent":["export { ContentModelPastePlugin } from './paste/ContentModelPastePlugin';\nexport { ContentModelEditPlugin } from './edit/ContentModelEditPlugin';\nexport { EntityDelimiterPlugin } from './entityDelimiter/EntityDelimiterPlugin';\n"]}
@@ -1,4 +1,4 @@
1
- define(["require", "exports", "./keyboardDelete"], function (require, exports, keyboardDelete_1) {
1
+ define(["require", "exports", "./keyboardDelete", "./keyboardInput"], function (require, exports, keyboardDelete_1, keyboardInput_1) {
2
2
  "use strict";
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.ContentModelEditPlugin = void 0;
@@ -62,6 +62,10 @@ define(["require", "exports", "./keyboardDelete"], function (require, exports, k
62
62
  // 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
63
63
  (0, keyboardDelete_1.keyboardDelete)(editor, rawEvent);
64
64
  break;
65
+ case 'Enter':
66
+ default:
67
+ (0, keyboardInput_1.keyboardInput)(editor, rawEvent);
68
+ break;
65
69
  }
66
70
  }
67
71
  };
@@ -1 +1 @@
1
- {"version":3,"file":"ContentModelEditPlugin.js","sourceRoot":"","sources":["../../../../packages-content-model/roosterjs-content-model-plugins/lib/edit/ContentModelEditPlugin.ts"],"names":[],"mappings":";;;;IAUA;;;;;OAKG;IACH;QAAA;YACY,WAAM,GAA+B,IAAI,CAAC;QA4DtD,CAAC;QA1DG;;WAEG;QACH,wCAAO,GAAP;YACI,OAAO,kBAAkB,CAAC;QAC9B,CAAC;QAED;;;;;WAKG;QACH,2CAAU,GAAV,UAAW,MAAe;YACtB,gFAAgF;YAChF,IAAI,CAAC,MAAM,GAAG,MAA6B,CAAC;QAChD,CAAC;QAED;;;;WAIG;QACH,wCAAO,GAAP;YACI,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC;QACvB,CAAC;QAED;;;;;WAKG;QACH,8CAAa,GAAb,UAAc,KAAkB;YAC5B,IAAI,IAAI,CAAC,MAAM,EAAE;gBACb,QAAQ,KAAK,CAAC,SAAS,EAAE;oBACrB;wBACI,IAAI,CAAC,kBAAkB,CAAC,IAAI,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;wBAC5C,MAAM;iBACb;aACJ;QACL,CAAC;QAEO,mDAAkB,GAA1B,UAA2B,MAA2B,EAAE,KAAyB;YAC7E,IAAM,QAAQ,GAAG,KAAK,CAAC,QAAQ,CAAC;YAEhC,IAAI,CAAC,QAAQ,CAAC,gBAAgB,IAAI,CAAC,KAAK,CAAC,oBAAoB,EAAE;gBAC3D,qHAAqH;gBACrH,QAAQ,QAAQ,CAAC,GAAG,EAAE;oBAClB,KAAK,WAAW,CAAC;oBACjB,KAAK,QAAQ;wBACT,8CAA8C;wBAC9C,qIAAqI;wBACrI,IAAA,+BAAc,EAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;wBACjC,MAAM;iBACb;aACJ;QACL,CAAC;QACL,6BAAC;IAAD,CAAC,AA7DD,IA6DC;IA7DY,wDAAsB","sourcesContent":["import { keyboardDelete } from './keyboardDelete';\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 }\n }\n}\n"]}
1
+ {"version":3,"file":"ContentModelEditPlugin.js","sourceRoot":"","sources":["../../../../packages-content-model/roosterjs-content-model-plugins/lib/edit/ContentModelEditPlugin.ts"],"names":[],"mappings":";;;;IAWA;;;;;OAKG;IACH;QAAA;YACY,WAAM,GAA+B,IAAI,CAAC;QAiEtD,CAAC;QA/DG;;WAEG;QACH,wCAAO,GAAP;YACI,OAAO,kBAAkB,CAAC;QAC9B,CAAC;QAED;;;;;WAKG;QACH,2CAAU,GAAV,UAAW,MAAe;YACtB,gFAAgF;YAChF,IAAI,CAAC,MAAM,GAAG,MAA6B,CAAC;QAChD,CAAC;QAED;;;;WAIG;QACH,wCAAO,GAAP;YACI,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC;QACvB,CAAC;QAED;;;;;WAKG;QACH,8CAAa,GAAb,UAAc,KAAkB;YAC5B,IAAI,IAAI,CAAC,MAAM,EAAE;gBACb,QAAQ,KAAK,CAAC,SAAS,EAAE;oBACrB;wBACI,IAAI,CAAC,kBAAkB,CAAC,IAAI,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;wBAC5C,MAAM;iBACb;aACJ;QACL,CAAC;QAEO,mDAAkB,GAA1B,UAA2B,MAA2B,EAAE,KAAyB;YAC7E,IAAM,QAAQ,GAAG,KAAK,CAAC,QAAQ,CAAC;YAEhC,IAAI,CAAC,QAAQ,CAAC,gBAAgB,IAAI,CAAC,KAAK,CAAC,oBAAoB,EAAE;gBAC3D,qHAAqH;gBACrH,QAAQ,QAAQ,CAAC,GAAG,EAAE;oBAClB,KAAK,WAAW,CAAC;oBACjB,KAAK,QAAQ;wBACT,8CAA8C;wBAC9C,qIAAqI;wBACrI,IAAA,+BAAc,EAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;wBACjC,MAAM;oBAEV,KAAK,OAAO,CAAC;oBACb;wBACI,IAAA,6BAAa,EAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;wBAChC,MAAM;iBACb;aACJ;QACL,CAAC;QACL,6BAAC;IAAD,CAAC,AAlED,IAkEC;IAlEY,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"]}
@@ -4,6 +4,5 @@ import type { IContentModelEditor } from 'roosterjs-content-model-editor';
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
- * @returns True if the event is handled with this function, otherwise false
8
7
  */
9
- export declare function keyboardDelete(editor: IContentModelEditor, rawEvent: KeyboardEvent): boolean;
8
+ export declare function keyboardDelete(editor: IContentModelEditor, rawEvent: KeyboardEvent): true | undefined;