roosterjs-content-model-plugins 0.26.4 → 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.
- package/lib/autoFormat/AutoFormatPlugin.d.ts +2 -2
- package/lib/autoFormat/AutoFormatPlugin.js.map +1 -1
- package/lib/autoFormat/keyboardListTrigger.d.ts +2 -2
- package/lib/autoFormat/keyboardListTrigger.js.map +1 -1
- package/lib/edit/EditPlugin.d.ts +3 -3
- package/lib/edit/EditPlugin.js +1 -1
- package/lib/edit/EditPlugin.js.map +1 -1
- package/lib/edit/deleteSteps/deleteCollapsedSelection.js +20 -1
- package/lib/edit/deleteSteps/deleteCollapsedSelection.js.map +1 -1
- package/lib/edit/handleKeyboardEventCommon.d.ts +2 -2
- package/lib/edit/handleKeyboardEventCommon.js.map +1 -1
- package/lib/edit/inputSteps/handleEnterOnList.js +40 -10
- package/lib/edit/inputSteps/handleEnterOnList.js.map +1 -1
- package/lib/edit/keyboardDelete.d.ts +3 -3
- package/lib/edit/keyboardDelete.js +1 -1
- package/lib/edit/keyboardDelete.js.map +1 -1
- package/lib/edit/keyboardInput.d.ts +2 -2
- package/lib/edit/keyboardInput.js.map +1 -1
- package/lib/edit/keyboardTab.d.ts +2 -2
- package/lib/edit/keyboardTab.js +19 -11
- package/lib/edit/keyboardTab.js.map +1 -1
- package/lib/edit/tabUtils/handleTabOnList.d.ts +7 -0
- package/lib/edit/tabUtils/handleTabOnList.js +34 -0
- package/lib/edit/tabUtils/handleTabOnList.js.map +1 -0
- package/lib/edit/tabUtils/handleTabOnParagraph.d.ts +17 -0
- package/lib/edit/tabUtils/handleTabOnParagraph.js +81 -0
- package/lib/edit/tabUtils/handleTabOnParagraph.js.map +1 -0
- package/lib/index.d.ts +4 -0
- package/lib/index.js +18 -1
- package/lib/index.js.map +1 -1
- package/lib/paste/PastePlugin.d.ts +2 -3
- package/lib/paste/PastePlugin.js +0 -1
- package/lib/paste/PastePlugin.js.map +1 -1
- package/lib/shortcut/ShortcutCommand.d.ts +44 -0
- package/lib/shortcut/ShortcutCommand.js +3 -0
- package/lib/shortcut/ShortcutCommand.js.map +1 -0
- package/lib/shortcut/ShortcutPlugin.d.ts +51 -0
- package/lib/shortcut/ShortcutPlugin.js +118 -0
- package/lib/shortcut/ShortcutPlugin.js.map +1 -0
- package/lib/shortcut/shortcuts.d.ts +73 -0
- package/lib/shortcut/shortcuts.js +178 -0
- package/lib/shortcut/shortcuts.js.map +1 -0
- package/lib/tableEdit/TableEditPlugin.d.ts +47 -0
- package/lib/tableEdit/TableEditPlugin.js +156 -0
- package/lib/tableEdit/TableEditPlugin.js.map +1 -0
- package/lib/tableEdit/editors/TableEditor.d.ts +73 -0
- package/lib/tableEdit/editors/TableEditor.js +294 -0
- package/lib/tableEdit/editors/TableEditor.js.map +1 -0
- package/lib/tableEdit/editors/features/CellResizer.d.ts +6 -0
- package/lib/tableEdit/editors/features/CellResizer.js +169 -0
- package/lib/tableEdit/editors/features/CellResizer.js.map +1 -0
- package/lib/tableEdit/editors/features/TableEditorFeature.d.ts +13 -0
- package/lib/tableEdit/editors/features/TableEditorFeature.js +17 -0
- package/lib/tableEdit/editors/features/TableEditorFeature.js.map +1 -0
- package/lib/tableEdit/editors/features/TableInserter.d.ts +6 -0
- package/lib/tableEdit/editors/features/TableInserter.js +113 -0
- package/lib/tableEdit/editors/features/TableInserter.js.map +1 -0
- package/lib/tableEdit/editors/features/TableMover.d.ts +8 -0
- package/lib/tableEdit/editors/features/TableMover.js +83 -0
- package/lib/tableEdit/editors/features/TableMover.js.map +1 -0
- package/lib/tableEdit/editors/features/TableResizer.d.ts +6 -0
- package/lib/tableEdit/editors/features/TableResizer.js +163 -0
- package/lib/tableEdit/editors/features/TableResizer.js.map +1 -0
- package/lib-amd/autoFormat/AutoFormatPlugin.d.ts +2 -2
- package/lib-amd/autoFormat/AutoFormatPlugin.js.map +1 -1
- package/lib-amd/autoFormat/keyboardListTrigger.d.ts +2 -2
- package/lib-amd/autoFormat/keyboardListTrigger.js.map +1 -1
- package/lib-amd/edit/EditPlugin.d.ts +3 -3
- package/lib-amd/edit/EditPlugin.js +1 -1
- package/lib-amd/edit/EditPlugin.js.map +1 -1
- package/lib-amd/edit/deleteSteps/deleteCollapsedSelection.js +19 -1
- package/lib-amd/edit/deleteSteps/deleteCollapsedSelection.js.map +1 -1
- package/lib-amd/edit/handleKeyboardEventCommon.d.ts +2 -2
- package/lib-amd/edit/handleKeyboardEventCommon.js.map +1 -1
- package/lib-amd/edit/inputSteps/handleEnterOnList.js +40 -10
- package/lib-amd/edit/inputSteps/handleEnterOnList.js.map +1 -1
- package/lib-amd/edit/keyboardDelete.d.ts +3 -3
- package/lib-amd/edit/keyboardDelete.js +1 -1
- package/lib-amd/edit/keyboardDelete.js.map +1 -1
- package/lib-amd/edit/keyboardInput.d.ts +2 -2
- package/lib-amd/edit/keyboardInput.js.map +1 -1
- package/lib-amd/edit/keyboardTab.d.ts +2 -2
- package/lib-amd/edit/keyboardTab.js +18 -12
- package/lib-amd/edit/keyboardTab.js.map +1 -1
- package/lib-amd/edit/tabUtils/handleTabOnList.d.ts +7 -0
- package/lib-amd/edit/tabUtils/handleTabOnList.js +34 -0
- package/lib-amd/edit/tabUtils/handleTabOnList.js.map +1 -0
- package/lib-amd/edit/tabUtils/handleTabOnParagraph.d.ts +17 -0
- package/lib-amd/edit/tabUtils/handleTabOnParagraph.js +81 -0
- package/lib-amd/edit/tabUtils/handleTabOnParagraph.js.map +1 -0
- package/lib-amd/index.d.ts +4 -0
- package/lib-amd/index.js +16 -2
- package/lib-amd/index.js.map +1 -1
- package/lib-amd/paste/PastePlugin.d.ts +2 -3
- package/lib-amd/paste/PastePlugin.js +0 -1
- package/lib-amd/paste/PastePlugin.js.map +1 -1
- package/lib-amd/shortcut/ShortcutCommand.d.ts +44 -0
- package/lib-amd/shortcut/ShortcutCommand.js +5 -0
- package/lib-amd/shortcut/ShortcutCommand.js.map +1 -0
- package/lib-amd/shortcut/ShortcutPlugin.d.ts +51 -0
- package/lib-amd/shortcut/ShortcutPlugin.js +118 -0
- package/lib-amd/shortcut/ShortcutPlugin.js.map +1 -0
- package/lib-amd/shortcut/shortcuts.d.ts +73 -0
- package/lib-amd/shortcut/shortcuts.js +178 -0
- package/lib-amd/shortcut/shortcuts.js.map +1 -0
- package/lib-amd/tableEdit/TableEditPlugin.d.ts +47 -0
- package/lib-amd/tableEdit/TableEditPlugin.js +155 -0
- package/lib-amd/tableEdit/TableEditPlugin.js.map +1 -0
- package/lib-amd/tableEdit/editors/TableEditor.d.ts +73 -0
- package/lib-amd/tableEdit/editors/TableEditor.js +289 -0
- package/lib-amd/tableEdit/editors/TableEditor.js.map +1 -0
- package/lib-amd/tableEdit/editors/features/CellResizer.d.ts +6 -0
- package/lib-amd/tableEdit/editors/features/CellResizer.js +165 -0
- package/lib-amd/tableEdit/editors/features/CellResizer.js.map +1 -0
- package/lib-amd/tableEdit/editors/features/TableEditorFeature.d.ts +13 -0
- package/lib-amd/tableEdit/editors/features/TableEditorFeature.js +19 -0
- package/lib-amd/tableEdit/editors/features/TableEditorFeature.js.map +1 -0
- package/lib-amd/tableEdit/editors/features/TableInserter.d.ts +6 -0
- package/lib-amd/tableEdit/editors/features/TableInserter.js +110 -0
- package/lib-amd/tableEdit/editors/features/TableInserter.js.map +1 -0
- package/lib-amd/tableEdit/editors/features/TableMover.d.ts +8 -0
- package/lib-amd/tableEdit/editors/features/TableMover.js +80 -0
- package/lib-amd/tableEdit/editors/features/TableMover.js.map +1 -0
- package/lib-amd/tableEdit/editors/features/TableResizer.d.ts +6 -0
- package/lib-amd/tableEdit/editors/features/TableResizer.js +160 -0
- package/lib-amd/tableEdit/editors/features/TableResizer.js.map +1 -0
- package/lib-mjs/autoFormat/AutoFormatPlugin.d.ts +2 -2
- package/lib-mjs/autoFormat/AutoFormatPlugin.js.map +1 -1
- package/lib-mjs/autoFormat/keyboardListTrigger.d.ts +2 -2
- package/lib-mjs/autoFormat/keyboardListTrigger.js.map +1 -1
- package/lib-mjs/edit/EditPlugin.d.ts +3 -3
- package/lib-mjs/edit/EditPlugin.js +1 -1
- package/lib-mjs/edit/EditPlugin.js.map +1 -1
- package/lib-mjs/edit/deleteSteps/deleteCollapsedSelection.js +20 -1
- package/lib-mjs/edit/deleteSteps/deleteCollapsedSelection.js.map +1 -1
- package/lib-mjs/edit/handleKeyboardEventCommon.d.ts +2 -2
- package/lib-mjs/edit/handleKeyboardEventCommon.js.map +1 -1
- package/lib-mjs/edit/inputSteps/handleEnterOnList.js +42 -12
- package/lib-mjs/edit/inputSteps/handleEnterOnList.js.map +1 -1
- package/lib-mjs/edit/keyboardDelete.d.ts +3 -3
- package/lib-mjs/edit/keyboardDelete.js +1 -1
- package/lib-mjs/edit/keyboardDelete.js.map +1 -1
- package/lib-mjs/edit/keyboardInput.d.ts +2 -2
- package/lib-mjs/edit/keyboardInput.js.map +1 -1
- package/lib-mjs/edit/keyboardTab.d.ts +2 -2
- package/lib-mjs/edit/keyboardTab.js +19 -11
- package/lib-mjs/edit/keyboardTab.js.map +1 -1
- package/lib-mjs/edit/tabUtils/handleTabOnList.d.ts +7 -0
- package/lib-mjs/edit/tabUtils/handleTabOnList.js +30 -0
- package/lib-mjs/edit/tabUtils/handleTabOnList.js.map +1 -0
- package/lib-mjs/edit/tabUtils/handleTabOnParagraph.d.ts +17 -0
- package/lib-mjs/edit/tabUtils/handleTabOnParagraph.js +77 -0
- package/lib-mjs/edit/tabUtils/handleTabOnParagraph.js.map +1 -0
- package/lib-mjs/index.d.ts +4 -0
- package/lib-mjs/index.js +3 -0
- package/lib-mjs/index.js.map +1 -1
- package/lib-mjs/paste/PastePlugin.d.ts +2 -3
- package/lib-mjs/paste/PastePlugin.js +0 -1
- package/lib-mjs/paste/PastePlugin.js.map +1 -1
- package/lib-mjs/shortcut/ShortcutCommand.d.ts +44 -0
- package/lib-mjs/shortcut/ShortcutCommand.js +2 -0
- package/lib-mjs/shortcut/ShortcutCommand.js.map +1 -0
- package/lib-mjs/shortcut/ShortcutPlugin.d.ts +51 -0
- package/lib-mjs/shortcut/ShortcutPlugin.js +115 -0
- package/lib-mjs/shortcut/ShortcutPlugin.js.map +1 -0
- package/lib-mjs/shortcut/shortcuts.d.ts +73 -0
- package/lib-mjs/shortcut/shortcuts.js +175 -0
- package/lib-mjs/shortcut/shortcuts.js.map +1 -0
- package/lib-mjs/tableEdit/TableEditPlugin.d.ts +47 -0
- package/lib-mjs/tableEdit/TableEditPlugin.js +153 -0
- package/lib-mjs/tableEdit/TableEditPlugin.js.map +1 -0
- package/lib-mjs/tableEdit/editors/TableEditor.d.ts +73 -0
- package/lib-mjs/tableEdit/editors/TableEditor.js +292 -0
- package/lib-mjs/tableEdit/editors/TableEditor.js.map +1 -0
- package/lib-mjs/tableEdit/editors/features/CellResizer.d.ts +6 -0
- package/lib-mjs/tableEdit/editors/features/CellResizer.js +166 -0
- package/lib-mjs/tableEdit/editors/features/CellResizer.js.map +1 -0
- package/lib-mjs/tableEdit/editors/features/TableEditorFeature.d.ts +13 -0
- package/lib-mjs/tableEdit/editors/features/TableEditorFeature.js +13 -0
- package/lib-mjs/tableEdit/editors/features/TableEditorFeature.js.map +1 -0
- package/lib-mjs/tableEdit/editors/features/TableInserter.d.ts +6 -0
- package/lib-mjs/tableEdit/editors/features/TableInserter.js +110 -0
- package/lib-mjs/tableEdit/editors/features/TableInserter.js.map +1 -0
- package/lib-mjs/tableEdit/editors/features/TableMover.d.ts +8 -0
- package/lib-mjs/tableEdit/editors/features/TableMover.js +80 -0
- package/lib-mjs/tableEdit/editors/features/TableMover.js.map +1 -0
- package/lib-mjs/tableEdit/editors/features/TableResizer.d.ts +6 -0
- package/lib-mjs/tableEdit/editors/features/TableResizer.js +160 -0
- package/lib-mjs/tableEdit/editors/features/TableResizer.js.map +1 -0
- package/package.json +5 -5
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { EditorPlugin,
|
|
1
|
+
import type { EditorPlugin, IEditor, PluginEvent } from 'roosterjs-content-model-types';
|
|
2
2
|
/**
|
|
3
3
|
* Options to customize the Content Model Auto Format Plugin
|
|
4
4
|
*/
|
|
@@ -35,7 +35,7 @@ export declare class AutoFormatPlugin implements EditorPlugin {
|
|
|
35
35
|
* editor reference so that it can call to any editor method or format API later.
|
|
36
36
|
* @param editor The editor object
|
|
37
37
|
*/
|
|
38
|
-
initialize(editor:
|
|
38
|
+
initialize(editor: IEditor): void;
|
|
39
39
|
/**
|
|
40
40
|
* The last method that editor will call to a plugin before it is disposed.
|
|
41
41
|
* Plugin can take this chance to clear the reference to editor. After this method is
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AutoFormatPlugin.js","sourceRoot":"","sources":["../../../../packages-content-model/roosterjs-content-model-plugins/lib/autoFormat/AutoFormatPlugin.ts"],"names":[],"mappings":";;;AAAA,6DAA4D;AAuB5D;;GAEG;AACH,IAAM,cAAc,GAAgC;IAChD,UAAU,EAAE,IAAI;IAChB,aAAa,EAAE,IAAI;CACtB,CAAC;AAEF;;;GAGG;AACH;IAGI;;;;OAIG;IACH,0BAAoB,OAA2C;QAA3C,wBAAA,EAAA,wBAA2C;QAA3C,YAAO,GAAP,OAAO,CAAoC;QAPvD,WAAM,
|
|
1
|
+
{"version":3,"file":"AutoFormatPlugin.js","sourceRoot":"","sources":["../../../../packages-content-model/roosterjs-content-model-plugins/lib/autoFormat/AutoFormatPlugin.ts"],"names":[],"mappings":";;;AAAA,6DAA4D;AAuB5D;;GAEG;AACH,IAAM,cAAc,GAAgC;IAChD,UAAU,EAAE,IAAI;IAChB,aAAa,EAAE,IAAI;CACtB,CAAC;AAEF;;;GAGG;AACH;IAGI;;;;OAIG;IACH,0BAAoB,OAA2C;QAA3C,wBAAA,EAAA,wBAA2C;QAA3C,YAAO,GAAP,OAAO,CAAoC;QAPvD,WAAM,GAAmB,IAAI,CAAC;IAO4B,CAAC;IAEnE;;OAEG;IACH,kCAAO,GAAP;QACI,OAAO,YAAY,CAAC;IACxB,CAAC;IAED;;;;;OAKG;IACH,qCAAU,GAAV,UAAW,MAAe;QACtB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACzB,CAAC;IAED;;;;OAIG;IACH,kCAAO,GAAP;QACI,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC;IACvB,CAAC;IAED;;;;;OAKG;IACH,wCAAa,GAAb,UAAc,KAAkB;QAC5B,IAAI,IAAI,CAAC,MAAM,EAAE;YACb,QAAQ,KAAK,CAAC,SAAS,EAAE;gBACrB,KAAK,SAAS;oBACV,IAAI,CAAC,kBAAkB,CAAC,IAAI,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;oBAC5C,MAAM;aACb;SACJ;IACL,CAAC;IAEO,6CAAkB,GAA1B,UAA2B,MAAe,EAAE,KAAmB;QAC3D,IAAM,QAAQ,GAAG,KAAK,CAAC,QAAQ,CAAC;QAChC,IAAI,CAAC,QAAQ,CAAC,gBAAgB,IAAI,CAAC,KAAK,CAAC,oBAAoB,EAAE;YAC3D,QAAQ,QAAQ,CAAC,GAAG,EAAE;gBAClB,KAAK,GAAG;oBACE,IAAA,KAAgC,IAAI,CAAC,OAAO,EAA1C,UAAU,gBAAA,EAAE,aAAa,mBAAiB,CAAC;oBACnD,IAAI,UAAU,IAAI,aAAa,EAAE;wBAC7B,IAAA,yCAAmB,EAAC,MAAM,EAAE,QAAQ,EAAE,UAAU,EAAE,aAAa,CAAC,CAAC;qBACpE;oBACD,MAAM;aACb;SACJ;IACL,CAAC;IACL,uBAAC;AAAD,CAAC,AAjED,IAiEC;AAjEY,4CAAgB","sourcesContent":["import { keyboardListTrigger } from './keyboardListTrigger';\nimport type {\n EditorPlugin,\n IEditor,\n KeyDownEvent,\n PluginEvent,\n} from 'roosterjs-content-model-types';\n\n/**\n * Options to customize the Content Model Auto Format Plugin\n */\nexport type AutoFormatOptions = {\n /**\n * When true, after type *, ->, -, --, => , —, > and space key a type of bullet list will be triggered. @default true\n */\n autoBullet: boolean;\n\n /**\n * When true, after type 1, A, a, i, I followed by ., ), - or between () and space key a type of numbering list will be triggered. @default true\n */\n autoNumbering: boolean;\n};\n\n/**\n * @internal\n */\nconst DefaultOptions: Required<AutoFormatOptions> = {\n autoBullet: true,\n autoNumbering: true,\n};\n\n/**\n * Auto Format plugin handles auto formatting, such as transforming * characters into a bullet list.\n * It can be customized with options to enable or disable auto list features.\n */\nexport class AutoFormatPlugin implements EditorPlugin {\n private editor: IEditor | null = null;\n\n /**\n * @param options An optional parameter that takes in an object of type AutoFormatOptions, which includes the following properties:\n * - autoBullet: A boolean that enables or disables automatic bullet list formatting. Defaults to true.\n * - autoNumbering: A boolean that enables or disables automatic numbering formatting. Defaults to true.\n */\n constructor(private options: AutoFormatOptions = DefaultOptions) {}\n\n /**\n * Get name of this plugin\n */\n getName() {\n return 'AutoFormat';\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 }\n\n /**\n * The last method that editor will call to a plugin before it is disposed.\n * Plugin can take this chance to clear the reference to editor. After this method is\n * called, plugin should not call to any editor method since it will result in error.\n */\n dispose() {\n this.editor = null;\n }\n\n /**\n * Core method for a plugin. Once an event happens in editor, editor will call this\n * method of each plugin to handle the event as long as the event is not handled\n * exclusively by another plugin.\n * @param event The event to handle:\n */\n onPluginEvent(event: PluginEvent) {\n if (this.editor) {\n switch (event.eventType) {\n case 'keyDown':\n this.handleKeyDownEvent(this.editor, event);\n break;\n }\n }\n }\n\n private handleKeyDownEvent(editor: IEditor, event: KeyDownEvent) {\n const rawEvent = event.rawEvent;\n if (!rawEvent.defaultPrevented && !event.handledByEditFeature) {\n switch (rawEvent.key) {\n case ' ':\n const { autoBullet, autoNumbering } = this.options;\n if (autoBullet || autoNumbering) {\n keyboardListTrigger(editor, rawEvent, autoBullet, autoNumbering);\n }\n break;\n }\n }\n }\n}\n"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { IEditor } from 'roosterjs-content-model-types';
|
|
2
2
|
/**
|
|
3
3
|
* @internal
|
|
4
4
|
*/
|
|
5
|
-
export declare function keyboardListTrigger(editor:
|
|
5
|
+
export declare function keyboardListTrigger(editor: IEditor, rawEvent: KeyboardEvent, shouldSearchForBullet?: boolean, shouldSearchForNumbering?: boolean): void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"keyboardListTrigger.js","sourceRoot":"","sources":["../../../../packages-content-model/roosterjs-content-model-plugins/lib/autoFormat/keyboardListTrigger.ts"],"names":[],"mappings":";;;AAAA,6DAA4D;AAC5D,6EAAgF;AAChF,2EAAoE;AACpE,2EAA4F;
|
|
1
|
+
{"version":3,"file":"keyboardListTrigger.js","sourceRoot":"","sources":["../../../../packages-content-model/roosterjs-content-model-plugins/lib/autoFormat/keyboardListTrigger.ts"],"names":[],"mappings":";;;AAAA,6DAA4D;AAC5D,6EAAgF;AAChF,2EAAoE;AACpE,2EAA4F;AAG5F;;GAEG;AACH,SAAgB,mBAAmB,CAC/B,MAAe,EACf,QAAuB,EACvB,qBAAqC,EACrC,wBAAwC;IADxC,sCAAA,EAAA,4BAAqC;IACrC,yCAAA,EAAA,+BAAwC;IAExC,MAAM,CAAC,kBAAkB,CAAC,UAAC,KAAK,EAAE,QAAQ;QACtC,IAAM,aAAa,GAAG,IAAA,mCAAgB,EAClC,KAAK,EACL,qBAAqB,EACrB,wBAAwB,CAC3B,CAAC;QACF,IAAI,aAAa,EAAE;YACf,IAAM,qBAAqB,GAAG,IAAA,+DAAgC,EAAC,KAAK,EAAE,KAAK,CAAC,CAAC;YAC7E,IAAI,qBAAqB,CAAC,CAAC,CAAC,IAAI,qBAAqB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE;gBACzD,qBAAqB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;aACrD;YACO,IAAA,QAAQ,GAAuB,aAAa,SAApC,EAAE,SAAS,GAAY,aAAa,UAAzB,EAAE,KAAK,GAAK,aAAa,MAAlB,CAAmB;YACrD,WAAW,CAAC,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,KAAK,CAAC,CAAC;YACvD,QAAQ,CAAC,cAAc,EAAE,CAAC;YAC1B,IAAA,mDAAqB,EAAC,KAAK,CAAC,CAAC;YAE7B,OAAO,IAAI,CAAC;SACf;QACD,OAAO,KAAK,CAAC;IACjB,CAAC,CAAC,CAAC;AACP,CAAC;AA1BD,kDA0BC;AAED,IAAM,WAAW,GAAG,UAChB,MAAe,EACf,KAA2B,EAC3B,QAAqB,EACrB,SAAiB,EACjB,KAAc;IAEd,IAAA,yCAAW,EAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;IAC7B,IAAM,aAAa,GAAG,QAAQ,IAAI,IAAI,CAAC;IACvC,mGAAmG;IACnG,IAAI,KAAK,IAAI,KAAK,GAAG,CAAC,IAAI,aAAa,EAAE;QACrC,IAAA,gDAAkB,EAAC,MAAM,EAAE,KAAK,CAAC,CAAC;KACrC;IACD,IAAA,0CAAY,EACR,MAAM,EACN,aAAa;QACT,CAAC,CAAC;YACI,gBAAgB,EAAE,SAAS;SAC9B;QACH,CAAC,CAAC;YACI,kBAAkB,EAAE,SAAS;SAChC,CACV,CAAC;AACN,CAAC,CAAC","sourcesContent":["import { getListTypeStyle } from './utils/getListTypeStyle';\nimport { getSelectedSegmentsAndParagraphs } from 'roosterjs-content-model-core';\nimport { normalizeContentModel } from 'roosterjs-content-model-dom';\nimport { setListStartNumber, setListStyle, setListType } from 'roosterjs-content-model-api';\nimport type { ContentModelDocument, IEditor } from 'roosterjs-content-model-types';\n\n/**\n * @internal\n */\nexport function keyboardListTrigger(\n editor: IEditor,\n rawEvent: KeyboardEvent,\n shouldSearchForBullet: boolean = true,\n shouldSearchForNumbering: boolean = true\n) {\n editor.formatContentModel((model, _context) => {\n const listStyleType = getListTypeStyle(\n model,\n shouldSearchForBullet,\n shouldSearchForNumbering\n );\n if (listStyleType) {\n const segmentsAndParagraphs = getSelectedSegmentsAndParagraphs(model, false);\n if (segmentsAndParagraphs[0] && segmentsAndParagraphs[0][1]) {\n segmentsAndParagraphs[0][1].segments.splice(0, 1);\n }\n const { listType, styleType, index } = listStyleType;\n triggerList(editor, model, listType, styleType, index);\n rawEvent.preventDefault();\n normalizeContentModel(model);\n\n return true;\n }\n return false;\n });\n}\n\nconst triggerList = (\n editor: IEditor,\n model: ContentModelDocument,\n listType: 'OL' | 'UL',\n styleType: number,\n index?: number\n) => {\n setListType(model, listType);\n const isOrderedList = listType == 'OL';\n // If the index < 1, it is a new list, so it will be starting by 1, then no need to set startNumber\n if (index && index > 1 && isOrderedList) {\n setListStartNumber(editor, index);\n }\n setListStyle(\n editor,\n isOrderedList\n ? {\n orderedStyleType: styleType,\n }\n : {\n unorderedStyleType: styleType,\n }\n );\n};\n"]}
|
package/lib/edit/EditPlugin.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { EditorPlugin,
|
|
1
|
+
import type { EditorPlugin, IEditor, PluginEvent } from 'roosterjs-content-model-types';
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
3
|
+
* Edit plugins helps editor to do editing operation on top of content model.
|
|
4
4
|
* This includes:
|
|
5
5
|
* 1. Delete Key
|
|
6
6
|
* 2. Backspace Key
|
|
@@ -20,7 +20,7 @@ export declare class EditPlugin implements EditorPlugin {
|
|
|
20
20
|
* editor reference so that it can call to any editor method or format API later.
|
|
21
21
|
* @param editor The editor object
|
|
22
22
|
*/
|
|
23
|
-
initialize(editor:
|
|
23
|
+
initialize(editor: IEditor): void;
|
|
24
24
|
/**
|
|
25
25
|
* The last method that editor will call to a plugin before it is disposed.
|
|
26
26
|
* Plugin can take this chance to clear the reference to editor. After this method is
|
package/lib/edit/EditPlugin.js
CHANGED
|
@@ -7,7 +7,7 @@ var keyboardTab_1 = require("./keyboardTab");
|
|
|
7
7
|
var BACKSPACE_KEY = 8;
|
|
8
8
|
var DELETE_KEY = 46;
|
|
9
9
|
/**
|
|
10
|
-
*
|
|
10
|
+
* Edit plugins helps editor to do editing operation on top of content model.
|
|
11
11
|
* This includes:
|
|
12
12
|
* 1. Delete Key
|
|
13
13
|
* 2. Backspace Key
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EditPlugin.js","sourceRoot":"","sources":["../../../../packages-content-model/roosterjs-content-model-plugins/lib/edit/EditPlugin.ts"],"names":[],"mappings":";;;AAAA,mDAAkD;AAClD,iDAAgD;AAChD,6CAA4C;AAQ5C,IAAM,aAAa,GAAG,CAAC,CAAC;AACxB,IAAM,UAAU,GAAG,EAAE,CAAC;AAEtB;;;;;;GAMG;AACH;IAAA;QACY,WAAM,
|
|
1
|
+
{"version":3,"file":"EditPlugin.js","sourceRoot":"","sources":["../../../../packages-content-model/roosterjs-content-model-plugins/lib/edit/EditPlugin.ts"],"names":[],"mappings":";;;AAAA,mDAAkD;AAClD,iDAAgD;AAChD,6CAA4C;AAQ5C,IAAM,aAAa,GAAG,CAAC,CAAC;AACxB,IAAM,UAAU,GAAG,EAAE,CAAC;AAEtB;;;;;;GAMG;AACH;IAAA;QACY,WAAM,GAAmB,IAAI,CAAC;QAC9B,aAAQ,GAAwB,IAAI,CAAC;QACrC,+BAA0B,GAAG,KAAK,CAAC;IA0H/C,CAAC;IAxHG;;OAEG;IACH,4BAAO,GAAP;QACI,OAAO,MAAM,CAAC;IAClB,CAAC;IAED;;;;;OAKG;IACH,+BAAU,GAAV,UAAW,MAAe;QAA1B,iBASC;QARG,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,MAAM,CAAC,cAAc,EAAE,CAAC,SAAS,EAAE;YACnC,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,MAAM,CAAC,cAAc,CAAC;gBACvC,WAAW,EAAE;oBACT,cAAc,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EAAE,QAAQ,CAAC,CAAC;oBAChC,MAAM;aACb;SACJ;IACL,CAAC;IAEO,2CAAsB,GAA9B,UAA+B,MAAe,EAAE,QAAe;QAC3D,gFAAgF;QAChF,uGAAuG;QACvG,IACI,CAAC,IAAI,CAAC,0BAA0B;YAChC,CAAC,CAAC,QAAQ,YAAY,UAAU,CAAC;YACjC,QAAQ,CAAC,gBAAgB,EAC3B;YACE,OAAO;SACV;QACD,IAAI,CAAC,0BAA0B,GAAG,KAAK,CAAC;QAExC,IAAI,OAAO,GAAG,KAAK,CAAC;QACpB,QAAQ,QAAQ,CAAC,SAAS,EAAE;YACxB,KAAK,uBAAuB;gBACxB,OAAO,GAAG,IAAA,+BAAc,EACpB,MAAM,EACN,IAAI,aAAa,CAAC,SAAS,EAAE;oBACzB,GAAG,EAAE,WAAW;oBAChB,OAAO,EAAE,aAAa;oBACtB,KAAK,EAAE,aAAa;iBACvB,CAAC,CACL,CAAC;gBACF,MAAM;YACV,KAAK,sBAAsB;gBACvB,OAAO,GAAG,IAAA,+BAAc,EACpB,MAAM,EACN,IAAI,aAAa,CAAC,SAAS,EAAE;oBACzB,GAAG,EAAE,QAAQ;oBACb,OAAO,EAAE,UAAU;oBACnB,KAAK,EAAE,UAAU;iBACpB,CAAC,CACL,CAAC;gBACF,MAAM;SACb;QAED,IAAI,OAAO,EAAE;YACT,QAAQ,CAAC,cAAc,EAAE,CAAC;SAC7B;IACL,CAAC;IACL,iBAAC;AAAD,CAAC,AA7HD,IA6HC;AA7HY,gCAAU","sourcesContent":["import { keyboardDelete } from './keyboardDelete';\nimport { keyboardInput } from './keyboardInput';\nimport { keyboardTab } from './keyboardTab';\nimport type {\n EditorPlugin,\n IEditor,\n KeyDownEvent,\n PluginEvent,\n} from 'roosterjs-content-model-types';\n\nconst BACKSPACE_KEY = 8;\nconst DELETE_KEY = 46;\n\n/**\n * Edit plugins helps editor to do editing operation on top of content model.\n * This includes:\n * 1. Delete Key\n * 2. Backspace Key\n * 3. Tab Key\n */\nexport class EditPlugin implements EditorPlugin {\n private editor: IEditor | null = null;\n private disposer: (() => void) | null = null;\n private shouldHandleNextInputEvent = false;\n\n /**\n * Get name of this plugin\n */\n getName() {\n return 'Edit';\n }\n\n /**\n * The first method that editor will call to a plugin when editor is initializing.\n * It will pass in the editor instance, plugin should take this chance to save the\n * editor reference so that it can call to any editor method or format API later.\n * @param editor The editor object\n */\n initialize(editor: IEditor) {\n this.editor = editor;\n if (editor.getEnvironment().isAndroid) {\n this.disposer = this.editor.attachDomEvent({\n beforeinput: {\n beforeDispatch: e => this.handleBeforeInputEvent(editor, e),\n },\n });\n }\n }\n\n /**\n * The last method that editor will call to a plugin before it is disposed.\n * Plugin can take this chance to clear the reference to editor. After this method is\n * called, plugin should not call to any editor method since it will result in error.\n */\n dispose() {\n this.editor = null;\n this.disposer?.();\n this.disposer = null;\n }\n\n /**\n * Core method for a plugin. Once an event happens in editor, editor will call this\n * method of each plugin to handle the event as long as the event is not handled\n * exclusively by another plugin.\n * @param event The event to handle:\n */\n onPluginEvent(event: PluginEvent) {\n if (this.editor) {\n switch (event.eventType) {\n case 'keyDown':\n this.handleKeyDownEvent(this.editor, event);\n break;\n }\n }\n }\n\n private handleKeyDownEvent(editor: IEditor, event: KeyDownEvent) {\n const rawEvent = event.rawEvent;\n\n if (!rawEvent.defaultPrevented && !event.handledByEditFeature) {\n switch (rawEvent.key) {\n case 'Backspace':\n 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 'Tab':\n keyboardTab(editor, rawEvent);\n break;\n case 'Unidentified':\n if (editor.getEnvironment().isAndroid) {\n this.shouldHandleNextInputEvent = true;\n }\n break;\n\n case 'Enter':\n default:\n keyboardInput(editor, rawEvent);\n break;\n }\n }\n }\n\n private handleBeforeInputEvent(editor: IEditor, rawEvent: Event) {\n // Some Android IMEs doesn't fire correct keydown event for BACKSPACE/DELETE key\n // Here we translate input event to BACKSPACE/DELETE keydown event to be compatible with existing logic\n if (\n !this.shouldHandleNextInputEvent ||\n !(rawEvent instanceof InputEvent) ||\n rawEvent.defaultPrevented\n ) {\n return;\n }\n this.shouldHandleNextInputEvent = false;\n\n let handled = false;\n switch (rawEvent.inputType) {\n case 'deleteContentBackward':\n handled = keyboardDelete(\n editor,\n new KeyboardEvent('keydown', {\n key: 'Backspace',\n keyCode: BACKSPACE_KEY,\n which: BACKSPACE_KEY,\n })\n );\n break;\n case 'deleteContentForward':\n handled = keyboardDelete(\n editor,\n new KeyboardEvent('keydown', {\n key: 'Delete',\n keyCode: DELETE_KEY,\n which: DELETE_KEY,\n })\n );\n break;\n }\n\n if (handled) {\n rawEvent.preventDefault();\n }\n }\n}\n"]}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.backwardDeleteCollapsedSelection = exports.forwardDeleteCollapsedSelection = void 0;
|
|
4
|
-
var roosterjs_content_model_core_1 = require("roosterjs-content-model-core");
|
|
5
4
|
var getLeafSiblingBlock_1 = require("../utils/getLeafSiblingBlock");
|
|
5
|
+
var roosterjs_content_model_api_1 = require("roosterjs-content-model-api");
|
|
6
6
|
var roosterjs_content_model_dom_1 = require("roosterjs-content-model-dom");
|
|
7
|
+
var roosterjs_content_model_core_1 = require("roosterjs-content-model-core");
|
|
7
8
|
function getDeleteCollapsedSelection(direction) {
|
|
8
9
|
return function (context) {
|
|
9
10
|
var _a;
|
|
@@ -17,6 +18,7 @@ function getDeleteCollapsedSelection(direction) {
|
|
|
17
18
|
var index = segments.indexOf(marker) + (isForward ? 1 : -1);
|
|
18
19
|
var segmentToDelete = segments[index];
|
|
19
20
|
var blockToDelete;
|
|
21
|
+
var root;
|
|
20
22
|
if (segmentToDelete) {
|
|
21
23
|
if ((0, roosterjs_content_model_core_1.deleteSegment)(paragraph, segmentToDelete, context.formatContext, direction)) {
|
|
22
24
|
context.deleteResult = 'singleChar';
|
|
@@ -25,6 +27,11 @@ function getDeleteCollapsedSelection(direction) {
|
|
|
25
27
|
(0, roosterjs_content_model_dom_1.setParagraphNotImplicit)(paragraph);
|
|
26
28
|
}
|
|
27
29
|
}
|
|
30
|
+
else if (shouldOutdentParagraph(isForward, segments, paragraph, path) &&
|
|
31
|
+
(root = getRoot(path))) {
|
|
32
|
+
(0, roosterjs_content_model_api_1.setModelIndentation)(root, 'outdent');
|
|
33
|
+
context.deleteResult = 'range';
|
|
34
|
+
}
|
|
28
35
|
else if ((blockToDelete = (0, getLeafSiblingBlock_1.getLeafSiblingBlock)(path, paragraph, isForward))) {
|
|
29
36
|
var block = blockToDelete.block, path_1 = blockToDelete.path, siblingSegment = blockToDelete.siblingSegment;
|
|
30
37
|
if (block.blockType == 'Paragraph') {
|
|
@@ -70,6 +77,18 @@ function getDeleteCollapsedSelection(direction) {
|
|
|
70
77
|
}
|
|
71
78
|
};
|
|
72
79
|
}
|
|
80
|
+
function getRoot(path) {
|
|
81
|
+
var lastInPath = path[path.length - 1];
|
|
82
|
+
return lastInPath.blockGroupType == 'Document' ? lastInPath : null;
|
|
83
|
+
}
|
|
84
|
+
function shouldOutdentParagraph(isForward, segments, paragraph, path) {
|
|
85
|
+
return (!isForward &&
|
|
86
|
+
segments.length == 1 &&
|
|
87
|
+
segments[0].segmentType == 'SelectionMarker' &&
|
|
88
|
+
paragraph.format.marginLeft &&
|
|
89
|
+
parseInt(paragraph.format.marginLeft) &&
|
|
90
|
+
(0, roosterjs_content_model_core_1.getClosestAncestorBlockGroupIndex)(path, ['Document', 'TableCell'], ['ListItem']) > -1);
|
|
91
|
+
}
|
|
73
92
|
/**
|
|
74
93
|
* If the last segment is BR, remove it for now. We may add it back later when normalize model.
|
|
75
94
|
* So that if this is an empty paragraph, it will start to delete next block
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"deleteCollapsedSelection.js","sourceRoot":"","sources":["../../../../../packages-content-model/roosterjs-content-model-plugins/lib/edit/deleteSteps/deleteCollapsedSelection.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"deleteCollapsedSelection.js","sourceRoot":"","sources":["../../../../../packages-content-model/roosterjs-content-model-plugins/lib/edit/deleteSteps/deleteCollapsedSelection.ts"],"names":[],"mappings":";;;AAAA,oEAAmE;AACnE,2EAAkE;AAClE,2EAAsE;AACtE,6EAIsC;AAUtC,SAAS,2BAA2B,CAAC,SAAiC;IAClE,OAAO,UAAA,OAAO;;QACV,IAAI,OAAO,CAAC,YAAY,IAAI,YAAY,EAAE;YACtC,OAAO;SACV;QAED,IAAM,SAAS,GAAG,SAAS,IAAI,SAAS,CAAC;QACnC,IAAA,KAA4C,OAAO,CAAC,WAAW,EAA7D,SAAS,eAAA,EAAE,MAAM,YAAA,EAAE,IAAI,UAAA,EAAE,YAAY,kBAAwB,CAAC;QACtE,IAAM,QAAQ,GAAG,SAAS,CAAC,QAAQ,CAAC;QAEpC,OAAO,CAAC,QAAQ,CAAC,CAAC;QAElB,IAAM,KAAK,GAAG,QAAQ,CAAC,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QAC9D,IAAM,eAAe,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC;QACxC,IAAI,aAAkC,CAAC;QACvC,IAAI,IAAiC,CAAC;QAEtC,IAAI,eAAe,EAAE;YACjB,IAAI,IAAA,4CAAa,EAAC,SAAS,EAAE,eAAe,EAAE,OAAO,CAAC,aAAa,EAAE,SAAS,CAAC,EAAE;gBAC7E,OAAO,CAAC,YAAY,GAAG,YAAY,CAAC;gBAEpC,4GAA4G;gBAC5G,qFAAqF;gBACrF,IAAA,qDAAuB,EAAC,SAAS,CAAC,CAAC;aACtC;SACJ;aAAM,IACH,sBAAsB,CAAC,SAAS,EAAE,QAAQ,EAAE,SAAS,EAA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AAC,WAAW,IAAI,iBAAiB,EAAlC,CAAkC,CAAC,CAAC;QAEnF,IAAI,CAAA,MAAA,iBAAiB,CAAC,iBAAiB,CAAC,MAAM,GAAG,CAAC,CAAC,0CAAE,WAAW,KAAI,IAAI,EAAE;YACtE,QAAQ,CAAC,GAAG,EAAE,CAAC;SAClB;KACJ;AACL,CAAC;AAED;;GAEG;AACU,QAAA,+BAA+B,GAAG,2BAA2B,CAAC,SAAS,CAAC,CAAC;AAEtF;;GAEG;AACU,QAAA,gCAAgC,GAAG,2BAA2B,CAAC,UAAU,CAAC,CAAC","sourcesContent":["import { getLeafSiblingBlock } from '../utils/getLeafSiblingBlock';\nimport { setModelIndentation } from 'roosterjs-content-model-api';\nimport { setParagraphNotImplicit } from 'roosterjs-content-model-dom';\nimport {\n deleteBlock,\n deleteSegment,\n getClosestAncestorBlockGroupIndex,\n} from 'roosterjs-content-model-core';\nimport type { BlockAndPath } from '../utils/getLeafSiblingBlock';\nimport type {\n ContentModelBlockGroup,\n ContentModelDocument,\n ContentModelParagraph,\n ContentModelSegment,\n DeleteSelectionStep,\n} from 'roosterjs-content-model-types';\n\nfunction getDeleteCollapsedSelection(direction: 'forward' | 'backward'): DeleteSelectionStep {\n return context => {\n if (context.deleteResult != 'notDeleted') {\n return;\n }\n\n const isForward = direction == 'forward';\n const { paragraph, marker, path, tableContext } = context.insertPoint;\n const segments = paragraph.segments;\n\n fixupBr(segments);\n\n const index = segments.indexOf(marker) + (isForward ? 1 : -1);\n const segmentToDelete = segments[index];\n let blockToDelete: BlockAndPath | null;\n let root: ContentModelDocument | null;\n\n if (segmentToDelete) {\n if (deleteSegment(paragraph, segmentToDelete, context.formatContext, direction)) {\n context.deleteResult = 'singleChar';\n\n // It is possible that we have deleted everything from this paragraph, so we need to mark it as not implicit\n // to avoid losing its format. See https://github.com/microsoft/roosterjs/issues/1953\n setParagraphNotImplicit(paragraph);\n }\n } else if (\n shouldOutdentParagraph(isForward, segments, paragraph, path) &&\n (root = getRoot(path))\n ) {\n setModelIndentation(root, 'outdent');\n context.deleteResult = 'range';\n } else if ((blockToDelete = getLeafSiblingBlock(path, paragraph, isForward))) {\n const { block, path, siblingSegment } = blockToDelete;\n\n if (block.blockType == 'Paragraph') {\n if (siblingSegment) {\n // When selection is under general segment, need to check if it has a sibling sibling, and delete from it\n if (deleteSegment(block, siblingSegment, context.formatContext, direction)) {\n context.deleteResult = 'range';\n }\n } else {\n if (isForward) {\n context.lastParagraph = block;\n } else {\n if (block.segments[block.segments.length - 1]?.segmentType == 'Br') {\n block.segments.pop();\n }\n\n context.insertPoint = {\n marker,\n paragraph: block,\n path,\n tableContext,\n };\n context.lastParagraph = paragraph;\n delete block.cachedElement;\n }\n\n context.deleteResult = 'range';\n }\n\n // When go across table, getLeafSiblingBlock will return null, when we are here, we must be in the same table context\n context.lastTableContext = tableContext;\n } else {\n if (\n deleteBlock(\n path[0].blocks,\n block,\n undefined /*replacement*/,\n context.formatContext,\n direction\n )\n ) {\n context.deleteResult = 'range';\n }\n }\n } else {\n // We have nothing to delete, in this case we don't want browser handle it as well.\n // Because when Backspace on an empty document, it will also delete the only DIV and SPAN element, causes\n // editor is really empty. We don't want that happen. So the handling should stop here.\n context.deleteResult = 'nothingToDelete';\n }\n };\n}\n\nfunction getRoot(path: ContentModelBlockGroup[]): ContentModelDocument | null {\n const lastInPath = path[path.length - 1];\n return lastInPath.blockGroupType == 'Document' ? lastInPath : null;\n}\n\nfunction shouldOutdentParagraph(\n isForward: boolean,\n segments: ContentModelSegment[],\n paragraph: ContentModelParagraph,\n path: ContentModelBlockGroup[]\n) {\n return (\n !isForward &&\n segments.length == 1 &&\n segments[0].segmentType == 'SelectionMarker' &&\n paragraph.format.marginLeft &&\n parseInt(paragraph.format.marginLeft) &&\n getClosestAncestorBlockGroupIndex(path, ['Document', 'TableCell'], ['ListItem']) > -1\n );\n}\n\n/**\n * If the last segment is BR, remove it for now. We may add it back later when normalize model.\n * So that if this is an empty paragraph, it will start to delete next block\n */\nfunction fixupBr(segments: ContentModelSegment[]) {\n if (segments[segments.length - 1]?.segmentType == 'Br') {\n const segmentsWithoutBr = segments.filter(x => x.segmentType != 'SelectionMarker');\n\n if (segmentsWithoutBr[segmentsWithoutBr.length - 2]?.segmentType != 'Br') {\n segments.pop();\n }\n }\n}\n\n/**\n * @internal if we didn't delete anything, and we want to delete forward, now perform it\n */\nexport const forwardDeleteCollapsedSelection = getDeleteCollapsedSelection('forward');\n\n/**\n * @internal if we didn't delete anything, and we want to delete backward, now perform it\n */\nexport const backwardDeleteCollapsedSelection = getDeleteCollapsedSelection('backward');\n"]}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import type { ContentModelDocument, DeleteResult, FormatContentModelContext,
|
|
1
|
+
import type { ContentModelDocument, DeleteResult, FormatContentModelContext, IEditor } from 'roosterjs-content-model-types';
|
|
2
2
|
/**
|
|
3
3
|
* @internal
|
|
4
4
|
* @return True means content is changed, so need to rewrite content model to editor. Otherwise false
|
|
5
5
|
*/
|
|
6
|
-
export declare function handleKeyboardEventResult(editor:
|
|
6
|
+
export declare function handleKeyboardEventResult(editor: IEditor, model: ContentModelDocument, rawEvent: KeyboardEvent, result: DeleteResult, context: FormatContentModelContext): boolean;
|
|
7
7
|
/**
|
|
8
8
|
* @internal
|
|
9
9
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handleKeyboardEventCommon.js","sourceRoot":"","sources":["../../../../packages-content-model/roosterjs-content-model-plugins/lib/edit/handleKeyboardEventCommon.ts"],"names":[],"mappings":";;;AAAA,2EAAoE;AAQpE;;;GAGG;AACH,SAAgB,yBAAyB,CACrC,
|
|
1
|
+
{"version":3,"file":"handleKeyboardEventCommon.js","sourceRoot":"","sources":["../../../../packages-content-model/roosterjs-content-model-plugins/lib/edit/handleKeyboardEventCommon.ts"],"names":[],"mappings":";;;AAAA,2EAAoE;AAQpE;;;GAGG;AACH,SAAgB,yBAAyB,CACrC,MAAe,EACf,KAA2B,EAC3B,QA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ContentModelDocument,\n DeleteResult,\n FormatContentModelContext,\n IEditor,\n} from 'roosterjs-content-model-types';\n\n/**\n * @internal\n * @return True means content is changed, so need to rewrite content model to editor. Otherwise false\n */\nexport function handleKeyboardEventResult(\n editor: IEditor,\n model: ContentModelDocument,\n rawEvent: KeyboardEvent,\n result: DeleteResult,\n context: FormatContentModelContext\n): boolean {\n context.skipUndoSnapshot = true;\n context.clearModelCache = false;\n\n switch (result) {\n case 'notDeleted':\n // We have not delete anything, we will let browser handle this event, so that current cached model may be invalid\n context.clearModelCache = true;\n\n // Return false here since we didn't do any change to Content Model, so no need to rewrite with Content Model\n return false;\n\n case 'nothingToDelete':\n // We known there is nothing to delete, no need to let browser keep handling the event\n rawEvent.preventDefault();\n return false;\n\n case 'range':\n case 'singleChar':\n // We have deleted what we need from content model, no need to let browser keep handling the event\n rawEvent.preventDefault();\n normalizeContentModel(model);\n\n if (result == 'range') {\n // A range is about to be deleted, so add an undo snapshot immediately\n context.skipUndoSnapshot = false;\n }\n\n // Trigger an event to let plugins know the content is about to be changed by Content Model keyboard editing.\n // So plugins can do proper handling. e.g. UndoPlugin can decide whether take a snapshot before this change happens.\n editor.triggerEvent('beforeKeyboardEditing', {\n rawEvent,\n });\n\n return true;\n }\n}\n\n/**\n * @internal\n */\nexport function shouldDeleteWord(rawEvent: KeyboardEvent, isMac: boolean) {\n return (\n (isMac && rawEvent.altKey && !rawEvent.metaKey) ||\n (!isMac && rawEvent.ctrlKey && !rawEvent.altKey)\n );\n}\n\n/**\n * @internal\n */\nexport function shouldDeleteAllSegmentsBefore(rawEvent: KeyboardEvent) {\n return rawEvent.metaKey && !rawEvent.altKey;\n}\n"]}
|
|
@@ -8,21 +8,49 @@ var roosterjs_content_model_dom_1 = require("roosterjs-content-model-dom");
|
|
|
8
8
|
* @internal
|
|
9
9
|
*/
|
|
10
10
|
var handleEnterOnList = function (context) {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
var deleteResult = context.deleteResult;
|
|
12
|
+
if (deleteResult == 'nothingToDelete' ||
|
|
13
|
+
deleteResult == 'notDeleted' ||
|
|
14
|
+
deleteResult == 'range') {
|
|
14
15
|
var insertPoint = context.insertPoint, formatContext = context.formatContext;
|
|
15
16
|
var path = insertPoint.path;
|
|
16
17
|
var rawEvent = formatContext === null || formatContext === void 0 ? void 0 : formatContext.rawEvent;
|
|
17
18
|
var index = (0, roosterjs_content_model_core_1.getClosestAncestorBlockGroupIndex)(path, ['ListItem'], ['TableCell']);
|
|
18
|
-
var
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
19
|
+
var listItem_1 = path[index];
|
|
20
|
+
var listParent = path[index + 1];
|
|
21
|
+
if (listItem_1 && listItem_1.blockGroupType === 'ListItem') {
|
|
22
|
+
var listIndex = listParent.blocks.indexOf(listItem_1);
|
|
23
|
+
var nextBlock = listParent.blocks[listIndex + 1];
|
|
24
|
+
if (deleteResult == 'range' && nextBlock) {
|
|
25
|
+
(0, roosterjs_content_model_dom_1.normalizeContentModel)(listParent);
|
|
26
|
+
var nextListItem = listParent.blocks[listIndex + 1];
|
|
27
|
+
if ((0, roosterjs_content_model_core_1.isBlockGroupOfType)(nextListItem, 'ListItem') &&
|
|
28
|
+
nextListItem.levels[0]) {
|
|
29
|
+
nextListItem.levels.forEach(function (level, index) {
|
|
30
|
+
level.format.startNumberOverride = undefined;
|
|
31
|
+
level.dataset = listItem_1.levels[index]
|
|
32
|
+
? listItem_1.levels[index].dataset
|
|
33
|
+
: {};
|
|
34
|
+
});
|
|
35
|
+
var lastParagraph = listItem_1.blocks[listItem_1.blocks.length - 1];
|
|
36
|
+
var nextParagraph = nextListItem.blocks[0];
|
|
37
|
+
if (nextParagraph.blockType === 'Paragraph' &&
|
|
38
|
+
lastParagraph.blockType === 'Paragraph' &&
|
|
39
|
+
lastParagraph.segments[lastParagraph.segments.length - 1].segmentType ===
|
|
40
|
+
'SelectionMarker') {
|
|
41
|
+
lastParagraph.segments.pop();
|
|
42
|
+
nextParagraph.segments.unshift((0, roosterjs_content_model_dom_1.createSelectionMarker)(insertPoint.marker.format));
|
|
43
|
+
}
|
|
44
|
+
context.lastParagraph = undefined;
|
|
45
|
+
}
|
|
23
46
|
}
|
|
24
|
-
else {
|
|
25
|
-
|
|
47
|
+
else if (deleteResult !== 'range') {
|
|
48
|
+
if (isEmptyListItem(listItem_1)) {
|
|
49
|
+
listItem_1.levels.pop();
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
createNewListItem(context, listItem_1, listParent);
|
|
53
|
+
}
|
|
26
54
|
}
|
|
27
55
|
rawEvent === null || rawEvent === void 0 ? void 0 : rawEvent.preventDefault();
|
|
28
56
|
context.deleteResult = 'range';
|
|
@@ -44,6 +72,8 @@ var createNewListItem = function (context, listItem, listParent) {
|
|
|
44
72
|
var levels = createNewListLevel(listItem);
|
|
45
73
|
var newListItem = (0, roosterjs_content_model_dom_1.createListItem)(levels, insertPoint.marker.format);
|
|
46
74
|
newListItem.blocks.push(newParagraph);
|
|
75
|
+
insertPoint.paragraph = newParagraph;
|
|
76
|
+
context.lastParagraph = newParagraph;
|
|
47
77
|
listParent.blocks.splice(listIndex + 1, 0, newListItem);
|
|
48
78
|
};
|
|
49
79
|
var createNewListLevel = function (listItem) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handleEnterOnList.js","sourceRoot":"","sources":["../../../../../packages-content-model/roosterjs-content-model-plugins/lib/edit/inputSteps/handleEnterOnList.ts"],"names":[],"mappings":";;;;AAAA,
|
|
1
|
+
{"version":3,"file":"handleEnterOnList.js","sourceRoot":"","sources":["../../../../../packages-content-model/roosterjs-content-model-plugins/lib/edit/inputSteps/handleEnterOnList.ts"],"names":[],"mappings":";;;;AAAA,6EAGsC;AACtC,2EASqC;AASrC;;GAEG;AACI,IAAM,iBAAiB,GAAwB,UAAA,OAAO;IACjD,IAAA,YAAY,GAAK,OAAO,aAAZ,CAAa;IACjC,IACI,YAAY,IAAI,i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CAAC;AACP,CAAC,CAAC;AAEF,IAAM,kBAAkB,GAAG,UAAC,WAAwB;;IACxC,IAAA,SAAS,GAAa,WAAW,UAAxB,EAAE,MAAM,GAAK,WAAW,OAAhB,CAAiB;IAC1C,IAAM,YAAY,GAAG,IAAA,6CAAe,EAChC,KAAK,CAAC,cAAc,EACpB,SAAS,CAAC,MAAM,EAChB,SAAS,CAAC,aAAa,CAC1B,CAAC;IAEF,IAAM,WAAW,GAAG,SAAS,CAAC,QAAQ,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;IACvD,IAAM,QAAQ,GAAG,SAAS,CAAC,QAAQ,CAAC,MAAM,CACtC,WAAW,EACX,SAAS,CAAC,QAAQ,CAAC,MAAM,GAAG,WAAW,CAC1C,CAAC;IAEF,CAAA,KAAA,YAAY,CAAC,QAAQ,CAAA,CAAC,IAAI,8DAAI,QAAQ,WAAE;IAExC,IAAA,qDAAuB,EAAC,SAAS,CAAC,CAAC;IAEnC,IAAI,SAAS,CAAC,QAAQ,CAAC,KAAK,CAAC,UAAA,CAAC,IAAI,OAAA,CAAC,CAAC,WAAW,IAAI,iBAAiB,EAAlC,CAAkC,CAAC,EAAE;QACnE,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAA,sCAAQ,EAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC;KACpD;IAED,IAAA,gDAAkB,EAAC,YAAY,CAAC,CAAC;IAEjC,OAAO,YAAY,CAAC;AACxB,CAAC,CAAC","sourcesContent":["import {\n getClosestAncestorBlockGroupIndex,\n isBlockGroupOfType,\n} from 'roosterjs-content-model-core';\nimport {\n createBr,\n createListItem,\n createListLevel,\n createParagraph,\n createSelectionMarker,\n normalizeContentModel,\n normalizeParagraph,\n setParagraphNotImplicit,\n} from 'roosterjs-content-model-dom';\nimport type {\n ContentModelBlockGroup,\n ContentModelListItem,\n DeleteSelectionStep,\n InsertPoint,\n ValidDeleteSelectionContext,\n} from 'roosterjs-content-model-types';\n\n/**\n * @internal\n */\nexport const handleEnterOnList: DeleteSelectionStep = context => {\n const { deleteResult } = context;\n if (\n deleteResult == 'nothingToDelete' ||\n deleteResult == 'notDeleted' ||\n deleteResult == 'range'\n ) {\n const { insertPoint, formatContext } = context;\n const { path } = insertPoint;\n const rawEvent = formatContext?.rawEvent;\n const index = getClosestAncestorBlockGroupIndex(path, ['ListItem'], ['TableCell']);\n\n const listItem = path[index];\n const listParent = path[index + 1];\n\n if (listItem && listItem.blockGroupType === 'ListItem') {\n const listIndex = listParent.blocks.indexOf(listItem);\n const nextBlock = listParent.blocks[listIndex + 1];\n if (deleteResult == 'range' && nextBlock) {\n normalizeContentModel(listParent);\n const nextListItem = listParent.blocks[listIndex + 1];\n if (\n isBlockGroupOfType<ContentModelListItem>(nextListItem, 'ListItem') &&\n nextListItem.levels[0]\n ) {\n nextListItem.levels.forEach((level, index) => {\n level.format.startNumberOverride = undefined;\n level.dataset = listItem.levels[index]\n ? listItem.levels[index].dataset\n : {};\n });\n const lastParagraph = listItem.blocks[listItem.blocks.length - 1];\n const nextParagraph = nextListItem.blocks[0];\n if (\n nextParagraph.blockType === 'Paragraph' &&\n lastParagraph.blockType === 'Paragraph' &&\n lastParagraph.segments[lastParagraph.segments.length - 1].segmentType ===\n 'SelectionMarker'\n ) {\n lastParagraph.segments.pop();\n\n nextParagraph.segments.unshift(\n createSelectionMarker(insertPoint.marker.format)\n );\n }\n context.lastParagraph = undefined;\n }\n } else if (deleteResult !== 'range') {\n if (isEmptyListItem(listItem)) {\n listItem.levels.pop();\n } else {\n createNewListItem(context, listItem, listParent);\n }\n }\n rawEvent?.preventDefault();\n context.deleteResult = 'range';\n }\n }\n};\n\nconst isEmptyListItem = (listItem: ContentModelListItem) => {\n return (\n listItem.blocks.length === 1 &&\n listItem.blocks[0].blockType === 'Paragraph' &&\n listItem.blocks[0].segments.length === 2 &&\n listItem.blocks[0].segments[0].segmentType === 'SelectionMarker' &&\n listItem.blocks[0].segments[1].segmentType === 'Br'\n );\n};\n\nconst createNewListItem = (\n context: ValidDeleteSelectionContext,\n listItem: ContentModelListItem,\n listParent: ContentModelBlockGroup\n) => {\n const { insertPoint } = context;\n const listIndex = listParent.blocks.indexOf(listItem);\n const newParagraph = createNewParagraph(insertPoint);\n\n const levels = createNewListLevel(listItem);\n const newListItem = createListItem(levels, insertPoint.marker.format);\n newListItem.blocks.push(newParagraph);\n insertPoint.paragraph = newParagraph;\n context.lastParagraph = newParagraph;\n listParent.blocks.splice(listIndex + 1, 0, newListItem);\n};\n\nconst createNewListLevel = (listItem: ContentModelListItem) => {\n return listItem.levels.map(level => {\n return createListLevel(\n level.listType,\n {\n ...level.format,\n startNumberOverride: undefined,\n },\n level.dataset\n );\n });\n};\n\nconst createNewParagraph = (insertPoint: InsertPoint) => {\n const { paragraph, marker } = insertPoint;\n const newParagraph = createParagraph(\n false /*isImplicit*/,\n paragraph.format,\n paragraph.segmentFormat\n );\n\n const markerIndex = paragraph.segments.indexOf(marker);\n const segments = paragraph.segments.splice(\n markerIndex,\n paragraph.segments.length - markerIndex\n );\n\n newParagraph.segments.push(...segments);\n\n setParagraphNotImplicit(paragraph);\n\n if (paragraph.segments.every(x => x.segmentType == 'SelectionMarker')) {\n paragraph.segments.push(createBr(marker.format));\n }\n\n normalizeParagraph(newParagraph);\n\n return newParagraph;\n};\n"]}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { IEditor } from 'roosterjs-content-model-types';
|
|
2
2
|
/**
|
|
3
3
|
* @internal
|
|
4
4
|
* Do keyboard event handling for DELETE/BACKSPACE key
|
|
5
|
-
* @param editor The
|
|
5
|
+
* @param editor The editor object
|
|
6
6
|
* @param rawEvent DOM keyboard event
|
|
7
7
|
* @returns True if the event is handled by content model, otherwise false
|
|
8
8
|
*/
|
|
9
|
-
export declare function keyboardDelete(editor:
|
|
9
|
+
export declare function keyboardDelete(editor: IEditor, rawEvent: KeyboardEvent): boolean;
|
|
@@ -11,7 +11,7 @@ var deleteCollapsedSelection_1 = require("./deleteSteps/deleteCollapsedSelection
|
|
|
11
11
|
/**
|
|
12
12
|
* @internal
|
|
13
13
|
* Do keyboard event handling for DELETE/BACKSPACE key
|
|
14
|
-
* @param editor The
|
|
14
|
+
* @param editor The editor object
|
|
15
15
|
* @param rawEvent DOM keyboard event
|
|
16
16
|
* @returns True if the event is handled by content model, otherwise false
|
|
17
17
|
*/
|
|
@@ -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,uDAAsD;AACtD,2EAA2D;AAC3D,yEAIqC;AACrC,yEAG2C;AAC3C,mFAGgD;
|
|
1
|
+
{"version":3,"file":"keyboardDelete.js","sourceRoot":"","sources":["../../../../packages-content-model/roosterjs-content-model-plugins/lib/edit/keyboardDelete.ts"],"names":[],"mappings":";;;AAAA,6EAA4F;AAC5F,+EAA8E;AAC9E,uDAAsD;AACtD,2EAA2D;AAC3D,yEAIqC;AACrC,yEAG2C;AAC3C,mFAGgD;AAGhD;;;;;;GAMG;AACH,SAAgB,cAAc,CAAC,MAAe,EAAE,QAAuB;IACnE,IAAI,OAAO,GAAG,KAAK,CAAC;IACpB,IAAM,SAAS,GAAG,MAAM,CAAC,eAAe,EAAE,CAAC;IAE3C,IAAI,4BAA4B,CAAC,SAAS,EAAE,QAAQ,CAAC,EAAE;QACnD,MAAM,CAAC,kBAAkB,CACrB,UAAC,KAAK,EAAE,OAAO;YACX,IAAM,MAAM,GAAG,IAAA,8CAAe,EAC1B,KAAK,EACL,cAAc,CAAC,QAAQ,EAAE,CAAC,CAAC,MAAM,CAAC,cAAc,EAAE,CAAC,KAAK,CAAC,EACzD,OAAO,CACV,CAAC,YAAY,CAAC;YAEf,OAAO,GAAG,IAAA,qDAAyB,EAAC,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAE,MA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;QACH,IAAM,KAAK,GAAG,SAAS,CAAC,KAAK,CAAC;QAE9B,oGAAoG;QACpG,OAAO,CAAC,CACJ,IAAA,0CAAY,EAAC,KAAK,CAAC,cAAc,EAAE,WAAW,CAAC;YAC/C,CAAC,IAAA,4CAAa,EAAC,QAAQ,CAAC;YACxB,CAAC,eAAe,CAAC,QAAQ,EAAE,KAAK,CAAC,IAAI,cAAc,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC,CACxE,CAAC;KACL;AACL,CAAC;AAED,SAAS,eAAe,CAAC,QAAuB,EAAE,KAAY;IAC1D,OAAO,QAAQ,CAAC,GAAG,IAAI,WAAW,IAAI,KAAK,CAAC,WAAW,GAAG,CAAC,CAAC;AAChE,CAAC;AAED,SAAS,cAAc,CAAC,QAAuB,EAAE,KAAY;;IACzD,OAAO,CACH,QAAQ,CAAC,GAAG,IAAI,QAAQ;QACxB,KAAK,CAAC,WAAW,GAAG,CAAC,MAAA,MAAA,KAAK,CAAC,cAAc,CAAC,SAAS,0CAAE,MAAM,mCAAI,CAAC,CAAC,GAAG,CAAC,CACxE,CAAC;AACN,CAAC","sourcesContent":["import { ChangeSource, deleteSelection, isModifierKey } from 'roosterjs-content-model-core';\nimport { deleteAllSegmentBefore } from './deleteSteps/deleteAllSegmentBefore';\nimport { deleteList } from './deleteSteps/deleteList';\nimport { isNodeOfType } from 'roosterjs-content-model-dom';\nimport {\n handleKeyboardEventResult,\n shouldDeleteAllSegmentsBefore,\n shouldDeleteWord,\n} from './handleKeyboardEventCommon';\nimport {\n backwardDeleteWordSelection,\n forwardDeleteWordSelection,\n} from './deleteSteps/deleteWordSelection';\nimport {\n backwardDeleteCollapsedSelection,\n forwardDeleteCollapsedSelection,\n} from './deleteSteps/deleteCollapsedSelection';\nimport type { DOMSelection, DeleteSelectionStep, IEditor } from 'roosterjs-content-model-types';\n\n/**\n * @internal\n * Do keyboard event handling for DELETE/BACKSPACE key\n * @param editor The editor object\n * @param rawEvent DOM keyboard event\n * @returns True if the event is handled by content model, otherwise false\n */\nexport function keyboardDelete(editor: IEditor, rawEvent: KeyboardEvent) {\n let handled = false;\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 handled = handleKeyboardEventResult(editor, model, rawEvent, result, context);\n return handled;\n },\n {\n rawEvent,\n changeSource: ChangeSource.Keyboard,\n getChangeData: () => rawEvent.which,\n apiName: rawEvent.key == 'Delete' ? 'handleDeleteKey' : 'handleBackspaceKey',\n }\n );\n }\n\n return handled;\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, deleteList];\n}\n\nfunction shouldDeleteWithContentModel(selection: DOMSelection | null, rawEvent: KeyboardEvent) {\n if (!selection) {\n return false; // Nothing to delete\n } else if (selection.type != 'range' || !selection.range.collapsed) {\n return true; // Selection is not collapsed, need to delete all selections\n } else {\n const range = selection.range;\n\n // When selection is collapsed and is in middle of text node, no need to use Content Model to delete\n return !(\n isNodeOfType(range.startContainer, 'TEXT_NODE') &&\n !isModifierKey(rawEvent) &&\n (canDeleteBefore(rawEvent, range) || canDeleteAfter(rawEvent, range))\n );\n }\n}\n\nfunction canDeleteBefore(rawEvent: KeyboardEvent, range: Range) {\n return rawEvent.key == 'Backspace' && range.startOffset > 1;\n}\n\nfunction canDeleteAfter(rawEvent: KeyboardEvent, range: Range) {\n return (\n rawEvent.key == 'Delete' &&\n range.startOffset < (range.startContainer.nodeValue?.length ?? 0) - 1\n );\n}\n"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { IEditor } from 'roosterjs-content-model-types';
|
|
2
2
|
/**
|
|
3
3
|
* @internal
|
|
4
4
|
*/
|
|
5
|
-
export declare function keyboardInput(editor:
|
|
5
|
+
export declare function keyboardInput(editor: IEditor, rawEvent: KeyboardEvent): true | undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"keyboardInput.js","sourceRoot":"","sources":["../../../../packages-content-model/roosterjs-content-model-plugins/lib/edit/keyboardInput.ts"],"names":[],"mappings":";;;AAAA,6EAA8E;AAC9E,oEAAmE;AACnE,2EAAoE;AAGpE;;GAEG;AACH,SAAgB,aAAa,CAAC,
|
|
1
|
+
{"version":3,"file":"keyboardInput.js","sourceRoot":"","sources":["../../../../packages-content-model/roosterjs-content-model-plugins/lib/edit/keyboardInput.ts"],"names":[],"mappings":";;;AAAA,6EAA8E;AAC9E,oEAAmE;AACnE,2EAAoE;AAGpE;;GAEG;AACH,SAAgB,aAAa,CAAC,MAAe,EAAE,QAAuB;IAClE,IAAM,SAAS,GAAG,MAAM,CAAC,eAAe,EAAE,CAAC;IAE3C,IAAI,2BAA2B,CAAC,SAAS,EAAE,QAAQ,CAAC,EAAE;QAClD,MAAM,CAAC,YAAY,EAAE,CAAC;QAEtB,MAAM,CAAC,kBAAkB,CACrB,UAAC,KAAK,EAAE,OAAO;;YACX,IAAM,MAAM,GAAG,IAAA,8CAAe,EAAC,KAAK,EAAE,aAAa,CAAC,SAAS,EAAE,QAAQ,CAAC,EAAE,OAAO,CAAC,CAAC;YAEnF,0EAA0E;YAC1E,qFAAqF;YACrF,OAAO,CAAC,eAAe,GAAG,IAAI,CAAC;YAE/B,oJAAoJ;YACpJ,OAAO,CAAC,gBAAgB,GAAG,IA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AAI,CAAC,QAAQ,CAAC,QAAQ,CAAC;AACnG,CAAC,CAAC","sourcesContent":["import { deleteSelection, isModifierKey } from 'roosterjs-content-model-core';\nimport { handleEnterOnList } from './inputSteps/handleEnterOnList';\nimport { normalizeContentModel } from 'roosterjs-content-model-dom';\nimport type { DOMSelection, IEditor } from 'roosterjs-content-model-types';\n\n/**\n * @internal\n */\nexport function keyboardInput(editor: IEditor, rawEvent: KeyboardEvent) {\n const selection = editor.getDOMSelection();\n\n if (shouldInputWithContentModel(selection, rawEvent)) {\n editor.takeSnapshot();\n\n editor.formatContentModel(\n (model, context) => {\n const result = deleteSelection(model, getInputSteps(selection, rawEvent), context);\n\n // We have deleted selection then we will let browser to handle the input.\n // With this combined operation, we don't wan to mass up the cached model so clear it\n context.clearModelCache = true;\n\n // Skip undo snapshot here and add undo snapshot before the operation so that we don't add another undo snapshot in middle of this replace operation\n context.skipUndoSnapshot = true;\n\n if (result.deleteResult == 'range') {\n // We have deleted something, next input should inherit the segment format from deleted content, so set pending format here\n context.newPendingFormat = result.insertPoint?.marker.format;\n\n normalizeContentModel(model);\n\n // Do not preventDefault since we still want browser to handle the final input for now\n return true;\n } else {\n return false;\n }\n },\n {\n rawEvent,\n }\n );\n\n return true;\n }\n}\n\nfunction getInputSteps(selection: DOMSelection | null, rawEvent: KeyboardEvent) {\n return shouldHandleEnterKey(selection, rawEvent) ? [handleEnterOnList] : [];\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 (\n selection.type != 'range' ||\n !selection.range.collapsed ||\n shouldHandleEnterKey(selection, rawEvent)\n );\n } else {\n return false;\n }\n}\n\nconst shouldHandleEnterKey = (selection: DOMSelection | null, rawEvent: KeyboardEvent) => {\n return selection && selection.type == 'range' && rawEvent.key == 'Enter' && !rawEvent.shiftKey;\n};\n"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { IEditor } from 'roosterjs-content-model-types';
|
|
2
2
|
/**
|
|
3
3
|
* @internal
|
|
4
4
|
*/
|
|
5
|
-
export declare function keyboardTab(editor:
|
|
5
|
+
export declare function keyboardTab(editor: IEditor, rawEvent: KeyboardEvent): true | undefined;
|
package/lib/edit/keyboardTab.js
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.keyboardTab = void 0;
|
|
4
4
|
var roosterjs_content_model_core_1 = require("roosterjs-content-model-core");
|
|
5
|
+
var handleTabOnList_1 = require("./tabUtils/handleTabOnList");
|
|
6
|
+
var handleTabOnParagraph_1 = require("./tabUtils/handleTabOnParagraph");
|
|
5
7
|
var roosterjs_content_model_api_1 = require("roosterjs-content-model-api");
|
|
6
8
|
/**
|
|
7
9
|
* @internal
|
|
@@ -9,27 +11,33 @@ var roosterjs_content_model_api_1 = require("roosterjs-content-model-api");
|
|
|
9
11
|
function keyboardTab(editor, rawEvent) {
|
|
10
12
|
var selection = editor.getDOMSelection();
|
|
11
13
|
if ((selection === null || selection === void 0 ? void 0 : selection.type) == 'range') {
|
|
12
|
-
editor.
|
|
13
|
-
|
|
14
|
-
|
|
14
|
+
editor.formatContentModel(function (model) {
|
|
15
|
+
return handleTab(model, rawEvent);
|
|
16
|
+
}, {
|
|
17
|
+
apiName: 'handleTabKey',
|
|
15
18
|
});
|
|
16
19
|
return true;
|
|
17
20
|
}
|
|
18
21
|
}
|
|
19
22
|
exports.keyboardTab = keyboardTab;
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
function
|
|
23
|
+
/**
|
|
24
|
+
* If multiple blocks are selected, indent or outdent the selected blocks with setModelIndentation.
|
|
25
|
+
* If only one block is selected, call handleTabOnParagraph or handleTabOnList to handle the tab key.
|
|
26
|
+
*/
|
|
27
|
+
function handleTab(model, rawEvent) {
|
|
25
28
|
var blocks = (0, roosterjs_content_model_core_1.getOperationalBlocks)(model, ['ListItem'], ['TableCell']);
|
|
26
|
-
var
|
|
27
|
-
if (
|
|
28
|
-
isMarkerAtStartOfBlock(listItem)) {
|
|
29
|
+
var block = blocks.length > 0 ? blocks[0].block : undefined;
|
|
30
|
+
if (blocks.length > 1) {
|
|
29
31
|
(0, roosterjs_content_model_api_1.setModelIndentation)(model, rawEvent.shiftKey ? 'outdent' : 'indent');
|
|
30
32
|
rawEvent.preventDefault();
|
|
31
33
|
return true;
|
|
32
34
|
}
|
|
35
|
+
else if ((block === null || block === void 0 ? void 0 : block.blockType) === 'Paragraph') {
|
|
36
|
+
return (0, handleTabOnParagraph_1.handleTabOnParagraph)(model, block, rawEvent);
|
|
37
|
+
}
|
|
38
|
+
else if ((0, roosterjs_content_model_core_1.isBlockGroupOfType)(block, 'ListItem')) {
|
|
39
|
+
return (0, handleTabOnList_1.handleTabOnList)(model, block, rawEvent);
|
|
40
|
+
}
|
|
33
41
|
return false;
|
|
34
42
|
}
|
|
35
43
|
//# sourceMappingURL=keyboardTab.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"keyboardTab.js","sourceRoot":"","sources":["../../../../packages-content-model/roosterjs-content-model-plugins/lib/edit/keyboardTab.ts"],"names":[],"mappings":";;;AAAA,6EAAwF;AACxF,2EAAkE;AAOlE;;GAEG;AACH,SAAgB,WAAW,CAAC,
|
|
1
|
+
{"version":3,"file":"keyboardTab.js","sourceRoot":"","sources":["../../../../packages-content-model/roosterjs-content-model-plugins/lib/edit/keyboardTab.ts"],"names":[],"mappings":";;;AAAA,6EAAwF;AACxF,8DAA6D;AAC7D,wEAAuE;AACvE,2EAAkE;AAOlE;;GAEG;AACH,SAAgB,WAAW,CAAC,MAAe,EAAE,QAAuB;IAChE,IAAM,SAAS,GAAG,MAAM,CAAC,eAAe,EAAE,CAAC;IAE3C,IAAI,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nList } from './tabUtils/handleTabOnList';\nimport { handleTabOnParagraph } from './tabUtils/handleTabOnParagraph';\nimport { setModelIndentation } from 'roosterjs-content-model-api';\nimport type {\n ContentModelDocument,\n ContentModelListItem,\n IEditor,\n} from 'roosterjs-content-model-types';\n\n/**\n * @internal\n */\nexport function keyboardTab(editor: IEditor, rawEvent: KeyboardEvent) {\n const selection = editor.getDOMSelection();\n\n if (selection?.type == 'range') {\n editor.formatContentModel(\n model => {\n return handleTab(model, rawEvent);\n },\n {\n apiName: 'handleTabKey',\n }\n );\n\n return true;\n }\n}\n\n/**\n * If multiple blocks are selected, indent or outdent the selected blocks with setModelIndentation.\n * If only one block is selected, call handleTabOnParagraph or handleTabOnList to handle the tab key.\n */\nfunction handleTab(model: ContentModelDocument, rawEvent: KeyboardEvent) {\n const blocks = getOperationalBlocks<ContentModelListItem>(model, ['ListItem'], ['TableCell']);\n const block = blocks.length > 0 ? blocks[0].block : undefined;\n if (blocks.length > 1) {\n setModelIndentation(model, rawEvent.shiftKey ? 'outdent' : 'indent');\n rawEvent.preventDefault();\n return true;\n } else if (block?.blockType === 'Paragraph') {\n return handleTabOnParagraph(model, block, rawEvent);\n } else if (isBlockGroupOfType<ContentModelListItem>(block, 'ListItem')) {\n return handleTabOnList(model, block, rawEvent);\n }\n return false;\n}\n"]}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { ContentModelDocument, ContentModelListItem } from 'roosterjs-content-model-types';
|
|
2
|
+
/**
|
|
3
|
+
* 1. When the selection is collapsed and the cursor is at start of a list item, call setModelIndentation.
|
|
4
|
+
* 2. Otherwise call handleTabOnParagraph.
|
|
5
|
+
* @internal
|
|
6
|
+
*/
|
|
7
|
+
export declare function handleTabOnList(model: ContentModelDocument, listItem: ContentModelListItem, rawEvent: KeyboardEvent): boolean;
|