roosterjs-content-model-plugins 0.25.0 → 0.26.1
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-mjs/autoFormat/ContentModelAutoFormatPlugin.d.ts → lib/autoFormat/AutoFormatPlugin.d.ts} +1 -1
- package/lib/autoFormat/{ContentModelAutoFormatPlugin.js → AutoFormatPlugin.js} +12 -12
- package/lib/autoFormat/AutoFormatPlugin.js.map +1 -0
- package/lib/autoFormat/keyboardListTrigger.js.map +1 -1
- package/lib/autoFormat/utils/getListTypeStyle.js +26 -18
- package/lib/autoFormat/utils/getListTypeStyle.js.map +1 -1
- package/lib/autoFormat/utils/getNumberingListStyle.js +10 -9
- package/lib/autoFormat/utils/getNumberingListStyle.js.map +1 -1
- package/{lib-amd/edit/ContentModelEditPlugin.d.ts → lib/edit/EditPlugin.d.ts} +5 -1
- package/lib/edit/EditPlugin.js +129 -0
- package/lib/edit/EditPlugin.js.map +1 -0
- package/lib/edit/handleKeyboardEventCommon.d.ts +2 -2
- package/lib/edit/handleKeyboardEventCommon.js.map +1 -1
- package/lib/edit/inputSteps/handleEnterOnList.d.ts +5 -0
- package/lib/edit/inputSteps/handleEnterOnList.js +68 -0
- package/lib/edit/inputSteps/handleEnterOnList.js.map +1 -0
- package/lib/edit/keyboardDelete.d.ts +2 -1
- package/lib/edit/keyboardDelete.js +6 -9
- package/lib/edit/keyboardDelete.js.map +1 -1
- package/lib/edit/keyboardInput.js +12 -4
- package/lib/edit/keyboardInput.js.map +1 -1
- package/lib/edit/keyboardTab.d.ts +5 -0
- package/lib/edit/keyboardTab.js +35 -0
- package/lib/edit/keyboardTab.js.map +1 -0
- package/lib/index.d.ts +3 -3
- package/lib/index.js +7 -7
- package/lib/index.js.map +1 -1
- package/{lib-amd/paste/ContentModelPastePlugin.d.ts → lib/paste/PastePlugin.d.ts} +1 -1
- package/lib/paste/{ContentModelPastePlugin.js → PastePlugin.js} +11 -11
- package/lib/paste/PastePlugin.js.map +1 -0
- package/lib/paste/WacComponents/processPastedContentWacComponents.d.ts +1 -1
- package/lib/paste/WacComponents/processPastedContentWacComponents.js +1 -1
- package/lib/paste/WacComponents/processPastedContentWacComponents.js.map +1 -1
- package/lib/paste/WordDesktop/processPastedContentFromWordDesktop.d.ts +1 -1
- package/lib/paste/WordDesktop/processPastedContentFromWordDesktop.js +1 -1
- package/lib/paste/WordDesktop/processPastedContentFromWordDesktop.js.map +1 -1
- package/lib/pluginUtils/CreateElement/CreateElementData.d.ts +35 -0
- package/lib/pluginUtils/CreateElement/CreateElementData.js +3 -0
- package/lib/pluginUtils/CreateElement/CreateElementData.js.map +1 -0
- package/lib/pluginUtils/CreateElement/createElement.d.ts +9 -0
- package/lib/pluginUtils/CreateElement/createElement.js +51 -0
- package/lib/pluginUtils/CreateElement/createElement.js.map +1 -0
- package/lib/pluginUtils/Disposable.d.ts +10 -0
- package/lib/pluginUtils/Disposable.js +3 -0
- package/lib/pluginUtils/Disposable.js.map +1 -0
- package/lib/pluginUtils/DragAndDrop/DragAndDropHandler.d.ts +45 -0
- package/lib/pluginUtils/DragAndDrop/DragAndDropHandler.js +3 -0
- package/lib/pluginUtils/DragAndDrop/DragAndDropHandler.js.map +1 -0
- package/lib/pluginUtils/DragAndDrop/DragAndDropHelper.d.ts +39 -0
- package/lib/pluginUtils/DragAndDrop/DragAndDropHelper.js +120 -0
- package/lib/pluginUtils/DragAndDrop/DragAndDropHelper.js.map +1 -0
- package/lib/pluginUtils/Rect/getIntersectedRect.d.ts +27 -0
- package/lib/pluginUtils/Rect/getIntersectedRect.js +45 -0
- package/lib/pluginUtils/Rect/getIntersectedRect.js.map +1 -0
- package/lib/pluginUtils/Rect/normalizeRect.d.ts +7 -0
- package/lib/pluginUtils/Rect/normalizeRect.js +20 -0
- package/lib/pluginUtils/Rect/normalizeRect.js.map +1 -0
- package/lib-amd/autoFormat/{ContentModelAutoFormatPlugin.d.ts → AutoFormatPlugin.d.ts} +1 -1
- package/lib-amd/autoFormat/{ContentModelAutoFormatPlugin.js → AutoFormatPlugin.js} +12 -12
- package/lib-amd/autoFormat/AutoFormatPlugin.js.map +1 -0
- package/lib-amd/autoFormat/keyboardListTrigger.js.map +1 -1
- package/lib-amd/autoFormat/utils/getListTypeStyle.js +26 -18
- package/lib-amd/autoFormat/utils/getListTypeStyle.js.map +1 -1
- package/lib-amd/autoFormat/utils/getNumberingListStyle.js +10 -9
- package/lib-amd/autoFormat/utils/getNumberingListStyle.js.map +1 -1
- package/{lib-mjs/edit/ContentModelEditPlugin.d.ts → lib-amd/edit/EditPlugin.d.ts} +5 -1
- package/lib-amd/edit/EditPlugin.js +128 -0
- package/lib-amd/edit/EditPlugin.js.map +1 -0
- package/lib-amd/edit/handleKeyboardEventCommon.d.ts +2 -2
- package/lib-amd/edit/handleKeyboardEventCommon.js.map +1 -1
- package/lib-amd/edit/inputSteps/handleEnterOnList.d.ts +5 -0
- package/lib-amd/edit/inputSteps/handleEnterOnList.js +67 -0
- package/lib-amd/edit/inputSteps/handleEnterOnList.js.map +1 -0
- package/lib-amd/edit/keyboardDelete.d.ts +2 -1
- package/lib-amd/edit/keyboardDelete.js +6 -9
- package/lib-amd/edit/keyboardDelete.js.map +1 -1
- package/lib-amd/edit/keyboardInput.js +12 -5
- package/lib-amd/edit/keyboardInput.js.map +1 -1
- package/lib-amd/edit/keyboardTab.d.ts +5 -0
- package/lib-amd/edit/keyboardTab.js +35 -0
- package/lib-amd/edit/keyboardTab.js.map +1 -0
- package/lib-amd/index.d.ts +3 -3
- package/lib-amd/index.js +5 -5
- package/lib-amd/index.js.map +1 -1
- package/{lib/paste/ContentModelPastePlugin.d.ts → lib-amd/paste/PastePlugin.d.ts} +1 -1
- package/lib-amd/paste/{ContentModelPastePlugin.js → PastePlugin.js} +11 -11
- package/lib-amd/paste/PastePlugin.js.map +1 -0
- package/lib-amd/paste/WacComponents/processPastedContentWacComponents.d.ts +1 -1
- package/lib-amd/paste/WacComponents/processPastedContentWacComponents.js +1 -1
- package/lib-amd/paste/WacComponents/processPastedContentWacComponents.js.map +1 -1
- package/lib-amd/paste/WordDesktop/processPastedContentFromWordDesktop.d.ts +1 -1
- package/lib-amd/paste/WordDesktop/processPastedContentFromWordDesktop.js +1 -1
- package/lib-amd/paste/WordDesktop/processPastedContentFromWordDesktop.js.map +1 -1
- package/lib-amd/pluginUtils/CreateElement/CreateElementData.d.ts +35 -0
- package/lib-amd/pluginUtils/CreateElement/CreateElementData.js +5 -0
- package/lib-amd/pluginUtils/CreateElement/CreateElementData.js.map +1 -0
- package/lib-amd/pluginUtils/CreateElement/createElement.d.ts +9 -0
- package/lib-amd/pluginUtils/CreateElement/createElement.js +52 -0
- package/lib-amd/pluginUtils/CreateElement/createElement.js.map +1 -0
- package/lib-amd/pluginUtils/Disposable.d.ts +10 -0
- package/lib-amd/pluginUtils/Disposable.js +5 -0
- package/lib-amd/pluginUtils/Disposable.js.map +1 -0
- package/lib-amd/pluginUtils/DragAndDrop/DragAndDropHandler.d.ts +45 -0
- package/lib-amd/pluginUtils/DragAndDrop/DragAndDropHandler.js +5 -0
- package/lib-amd/pluginUtils/DragAndDrop/DragAndDropHandler.js.map +1 -0
- package/lib-amd/pluginUtils/DragAndDrop/DragAndDropHelper.d.ts +39 -0
- package/lib-amd/pluginUtils/DragAndDrop/DragAndDropHelper.js +121 -0
- package/lib-amd/pluginUtils/DragAndDrop/DragAndDropHelper.js.map +1 -0
- package/lib-amd/pluginUtils/Rect/getIntersectedRect.d.ts +27 -0
- package/lib-amd/pluginUtils/Rect/getIntersectedRect.js +45 -0
- package/lib-amd/pluginUtils/Rect/getIntersectedRect.js.map +1 -0
- package/lib-amd/pluginUtils/Rect/normalizeRect.d.ts +7 -0
- package/lib-amd/pluginUtils/Rect/normalizeRect.js +22 -0
- package/lib-amd/pluginUtils/Rect/normalizeRect.js.map +1 -0
- package/{lib/autoFormat/ContentModelAutoFormatPlugin.d.ts → lib-mjs/autoFormat/AutoFormatPlugin.d.ts} +1 -1
- package/lib-mjs/autoFormat/{ContentModelAutoFormatPlugin.js → AutoFormatPlugin.js} +11 -11
- package/lib-mjs/autoFormat/AutoFormatPlugin.js.map +1 -0
- package/lib-mjs/autoFormat/keyboardListTrigger.js.map +1 -1
- package/lib-mjs/autoFormat/utils/getListTypeStyle.js +26 -18
- package/lib-mjs/autoFormat/utils/getListTypeStyle.js.map +1 -1
- package/lib-mjs/autoFormat/utils/getNumberingListStyle.js +10 -9
- package/lib-mjs/autoFormat/utils/getNumberingListStyle.js.map +1 -1
- package/{lib/edit/ContentModelEditPlugin.d.ts → lib-mjs/edit/EditPlugin.d.ts} +5 -1
- package/lib-mjs/edit/EditPlugin.js +126 -0
- package/lib-mjs/edit/EditPlugin.js.map +1 -0
- package/lib-mjs/edit/handleKeyboardEventCommon.d.ts +2 -2
- package/lib-mjs/edit/handleKeyboardEventCommon.js.map +1 -1
- package/lib-mjs/edit/inputSteps/handleEnterOnList.d.ts +5 -0
- package/lib-mjs/edit/inputSteps/handleEnterOnList.js +64 -0
- package/lib-mjs/edit/inputSteps/handleEnterOnList.js.map +1 -0
- package/lib-mjs/edit/keyboardDelete.d.ts +2 -1
- package/lib-mjs/edit/keyboardDelete.js +6 -9
- package/lib-mjs/edit/keyboardDelete.js.map +1 -1
- package/lib-mjs/edit/keyboardInput.js +12 -4
- package/lib-mjs/edit/keyboardInput.js.map +1 -1
- package/lib-mjs/edit/keyboardTab.d.ts +5 -0
- package/lib-mjs/edit/keyboardTab.js +31 -0
- package/lib-mjs/edit/keyboardTab.js.map +1 -0
- package/lib-mjs/index.d.ts +3 -3
- package/lib-mjs/index.js +3 -3
- package/lib-mjs/index.js.map +1 -1
- package/lib-mjs/paste/{ContentModelPastePlugin.d.ts → PastePlugin.d.ts} +1 -1
- package/lib-mjs/paste/{ContentModelPastePlugin.js → PastePlugin.js} +10 -10
- package/lib-mjs/paste/PastePlugin.js.map +1 -0
- package/lib-mjs/paste/WacComponents/processPastedContentWacComponents.d.ts +1 -1
- package/lib-mjs/paste/WacComponents/processPastedContentWacComponents.js +1 -1
- package/lib-mjs/paste/WacComponents/processPastedContentWacComponents.js.map +1 -1
- package/lib-mjs/paste/WordDesktop/processPastedContentFromWordDesktop.d.ts +1 -1
- package/lib-mjs/paste/WordDesktop/processPastedContentFromWordDesktop.js +1 -1
- package/lib-mjs/paste/WordDesktop/processPastedContentFromWordDesktop.js.map +1 -1
- package/lib-mjs/pluginUtils/CreateElement/CreateElementData.d.ts +35 -0
- package/lib-mjs/pluginUtils/CreateElement/CreateElementData.js +2 -0
- package/lib-mjs/pluginUtils/CreateElement/CreateElementData.js.map +1 -0
- package/lib-mjs/pluginUtils/CreateElement/createElement.d.ts +9 -0
- package/lib-mjs/pluginUtils/CreateElement/createElement.js +48 -0
- package/lib-mjs/pluginUtils/CreateElement/createElement.js.map +1 -0
- package/lib-mjs/pluginUtils/Disposable.d.ts +10 -0
- package/lib-mjs/pluginUtils/Disposable.js +2 -0
- package/lib-mjs/pluginUtils/Disposable.js.map +1 -0
- package/lib-mjs/pluginUtils/DragAndDrop/DragAndDropHandler.d.ts +45 -0
- package/lib-mjs/pluginUtils/DragAndDrop/DragAndDropHandler.js +2 -0
- package/lib-mjs/pluginUtils/DragAndDrop/DragAndDropHandler.js.map +1 -0
- package/lib-mjs/pluginUtils/DragAndDrop/DragAndDropHelper.d.ts +39 -0
- package/lib-mjs/pluginUtils/DragAndDrop/DragAndDropHelper.js +118 -0
- package/lib-mjs/pluginUtils/DragAndDrop/DragAndDropHelper.js.map +1 -0
- package/lib-mjs/pluginUtils/Rect/getIntersectedRect.d.ts +27 -0
- package/lib-mjs/pluginUtils/Rect/getIntersectedRect.js +42 -0
- package/lib-mjs/pluginUtils/Rect/getIntersectedRect.js.map +1 -0
- package/lib-mjs/pluginUtils/Rect/normalizeRect.d.ts +7 -0
- package/lib-mjs/pluginUtils/Rect/normalizeRect.js +17 -0
- package/lib-mjs/pluginUtils/Rect/normalizeRect.js.map +1 -0
- package/package.json +5 -5
- package/lib/autoFormat/ContentModelAutoFormatPlugin.js.map +0 -1
- package/lib/edit/ContentModelEditPlugin.js +0 -74
- package/lib/edit/ContentModelEditPlugin.js.map +0 -1
- package/lib/paste/ContentModelPastePlugin.js.map +0 -1
- package/lib-amd/autoFormat/ContentModelAutoFormatPlugin.js.map +0 -1
- package/lib-amd/edit/ContentModelEditPlugin.js +0 -74
- package/lib-amd/edit/ContentModelEditPlugin.js.map +0 -1
- package/lib-amd/paste/ContentModelPastePlugin.js.map +0 -1
- package/lib-mjs/autoFormat/ContentModelAutoFormatPlugin.js.map +0 -1
- package/lib-mjs/edit/ContentModelEditPlugin.js +0 -71
- package/lib-mjs/edit/ContentModelEditPlugin.js.map +0 -1
- package/lib-mjs/paste/ContentModelPastePlugin.js.map +0 -1
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @internal
|
|
3
|
+
* Drag and drop handler interface, used for implementing a handler object and pass into DragAndDropHelper class
|
|
4
|
+
*/
|
|
5
|
+
export default interface DragAndDropHandler<TContext, TInitValue> {
|
|
6
|
+
/**
|
|
7
|
+
* A callback that will be called when user starts to drag (mouse down event from the trigger element)
|
|
8
|
+
* @param context The context object that was passed into DragAndDropHelper from its constructor. We can use
|
|
9
|
+
* this object to communicate between caller code and this handler
|
|
10
|
+
* @param event The mouse event that triggers this callback
|
|
11
|
+
* @returns An optional object, which will be passed into onDragging and onDragEnd callback. It normally used
|
|
12
|
+
* for passing an initial state of the target object
|
|
13
|
+
*/
|
|
14
|
+
onDragStart?: (context: TContext, event: MouseEvent) => TInitValue;
|
|
15
|
+
/**
|
|
16
|
+
* A callback that will be called when user moves mouse and drag the trigger element.
|
|
17
|
+
* @param context The context object that was passed into DragAndDropHelper from its constructor. We can use
|
|
18
|
+
* this object to communicate between caller code and this handler.If an object is used as context, here it will
|
|
19
|
+
* be the same object that passed into constructor of DragAndDropHelper class. Inside this callback you can change
|
|
20
|
+
* its sub value so that caller can get the changed result.
|
|
21
|
+
* @param event The mouse event that triggers this callback
|
|
22
|
+
* @param initValue The initial value that is returned from onDragStart callback. It normally used
|
|
23
|
+
* for passing an initial state of the target object
|
|
24
|
+
* @param deltaX x delta value. It equals to current event.pageX - initial pageX (captured when mousedown happens)
|
|
25
|
+
* @param deltaY y delta value. It equals to current event.pageY - initial pageY (captured when mousedown happens)
|
|
26
|
+
* @returns Whether the onSubmit callback passed into constructor of DragAndDropHelper class should be invoked.
|
|
27
|
+
* Returns true will invoke the onSubmit callback, it means this is a meaningful dragging action, something (mostly
|
|
28
|
+
* under context object) has been changed, and caller should handle this change. Otherwise, return false.
|
|
29
|
+
*/
|
|
30
|
+
onDragging?: (context: TContext, event: MouseEvent, initValue: TInitValue, deltaX: number, deltaY: number) => boolean;
|
|
31
|
+
/**
|
|
32
|
+
* A callback that will be called when user stops dragging the trigger element.
|
|
33
|
+
* @param context The context object that was passed into DragAndDropHelper from its constructor. We can use
|
|
34
|
+
* this object to communicate between caller code and this handler.If an object is used as context, here it will
|
|
35
|
+
* be the same object that passed into constructor of DragAndDropHelper class. Inside this callback you can change
|
|
36
|
+
* its sub value so that caller can get the changed result.
|
|
37
|
+
* @param event The mouse event that triggers this callback
|
|
38
|
+
* @param initValue The initial value that is returned from onDragStart callback. It normally used
|
|
39
|
+
* for passing an initial state of the target object
|
|
40
|
+
* @returns Whether the onSubmit callback passed into constructor of DragAndDropHelper class should be invoked.
|
|
41
|
+
* Returns true will invoke the onSubmit callback, it means this is a meaningful dragging action, something (mostly
|
|
42
|
+
* under context object) has been changed, and caller should handle this change. Otherwise, return false.
|
|
43
|
+
*/
|
|
44
|
+
onDragEnd?: (context: TContext, event: MouseEvent, initValue: TInitValue | undefined) => boolean;
|
|
45
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DragAndDropHandler.js","sourceRoot":"","sources":["../../../../../packages-content-model/roosterjs-content-model-plugins/lib/pluginUtils/DragAndDrop/DragAndDropHandler.ts"],"names":[],"mappings":"","sourcesContent":["/**\n * @internal\n * Drag and drop handler interface, used for implementing a handler object and pass into DragAndDropHelper class\n */\nexport default interface DragAndDropHandler<TContext, TInitValue> {\n /**\n * A callback that will be called when user starts to drag (mouse down event from the trigger element)\n * @param context The context object that was passed into DragAndDropHelper from its constructor. We can use\n * this object to communicate between caller code and this handler\n * @param event The mouse event that triggers this callback\n * @returns An optional object, which will be passed into onDragging and onDragEnd callback. It normally used\n * for passing an initial state of the target object\n */\n onDragStart?: (context: TContext, event: MouseEvent) => TInitValue;\n\n /**\n * A callback that will be called when user moves mouse and drag the trigger element.\n * @param context The context object that was passed into DragAndDropHelper from its constructor. We can use\n * this object to communicate between caller code and this handler.If an object is used as context, here it will\n * be the same object that passed into constructor of DragAndDropHelper class. Inside this callback you can change\n * its sub value so that caller can get the changed result.\n * @param event The mouse event that triggers this callback\n * @param initValue The initial value that is returned from onDragStart callback. It normally used\n * for passing an initial state of the target object\n * @param deltaX x delta value. It equals to current event.pageX - initial pageX (captured when mousedown happens)\n * @param deltaY y delta value. It equals to current event.pageY - initial pageY (captured when mousedown happens)\n * @returns Whether the onSubmit callback passed into constructor of DragAndDropHelper class should be invoked.\n * Returns true will invoke the onSubmit callback, it means this is a meaningful dragging action, something (mostly\n * under context object) has been changed, and caller should handle this change. Otherwise, return false.\n */\n onDragging?: (\n context: TContext,\n event: MouseEvent,\n initValue: TInitValue,\n deltaX: number,\n deltaY: number\n ) => boolean;\n\n /**\n * A callback that will be called when user stops dragging the trigger element.\n * @param context The context object that was passed into DragAndDropHelper from its constructor. We can use\n * this object to communicate between caller code and this handler.If an object is used as context, here it will\n * be the same object that passed into constructor of DragAndDropHelper class. Inside this callback you can change\n * its sub value so that caller can get the changed result.\n * @param event The mouse event that triggers this callback\n * @param initValue The initial value that is returned from onDragStart callback. It normally used\n * for passing an initial state of the target object\n * @returns Whether the onSubmit callback passed into constructor of DragAndDropHelper class should be invoked.\n * Returns true will invoke the onSubmit callback, it means this is a meaningful dragging action, something (mostly\n * under context object) has been changed, and caller should handle this change. Otherwise, return false.\n */\n onDragEnd?: (\n context: TContext,\n event: MouseEvent,\n initValue: TInitValue | undefined\n ) => boolean;\n}\n"]}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type Disposable from '../Disposable';
|
|
2
|
+
import type DragAndDropHandler from './DragAndDropHandler';
|
|
3
|
+
/**
|
|
4
|
+
* @internal
|
|
5
|
+
* A helper class to help manage drag and drop to an HTML element
|
|
6
|
+
*/
|
|
7
|
+
export default class DragAndDropHelper<TContext, TInitValue> implements Disposable {
|
|
8
|
+
private trigger;
|
|
9
|
+
private context;
|
|
10
|
+
private onSubmit;
|
|
11
|
+
private handler;
|
|
12
|
+
private zoomScale;
|
|
13
|
+
private initX;
|
|
14
|
+
private initY;
|
|
15
|
+
private initValue;
|
|
16
|
+
private dndMouse;
|
|
17
|
+
/**
|
|
18
|
+
* Create a new instance of DragAndDropHelper class
|
|
19
|
+
* @param trigger The trigger element. When user start drag on this element,
|
|
20
|
+
* events will be fired to the handler object
|
|
21
|
+
* @param context Context object that will be passed to handler function when event is fired,
|
|
22
|
+
* so that the handler object knows which element it is triggered from.
|
|
23
|
+
* @param onSubmit A callback that will be invoked when event handler in handler object returns true
|
|
24
|
+
* @param handler The event handler object, see DragAndDropHandler interface for more information
|
|
25
|
+
* @param zoomScale The zoom scale of the editor
|
|
26
|
+
* @param forceMobile A boolean to force the use of touch controls for the helper
|
|
27
|
+
*/
|
|
28
|
+
constructor(trigger: HTMLElement, context: TContext, onSubmit: (context: TContext, trigger: HTMLElement) => void, handler: DragAndDropHandler<TContext, TInitValue>, zoomScale: number, forceMobile?: boolean);
|
|
29
|
+
/**
|
|
30
|
+
* Dispose this object, remove all event listeners that has been attached
|
|
31
|
+
*/
|
|
32
|
+
dispose(): void;
|
|
33
|
+
get mouseType(): string;
|
|
34
|
+
private addDocumentEvents;
|
|
35
|
+
private removeDocumentEvents;
|
|
36
|
+
private onMouseDown;
|
|
37
|
+
private onMouseMove;
|
|
38
|
+
private onMouseUp;
|
|
39
|
+
}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
define(["require", "exports", "tslib"], function (require, exports, tslib_1) {
|
|
2
|
+
"use strict";
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
/**
|
|
5
|
+
* Generate event names and getXY function based on different platforms to be compatible with desktop and mobile browsers
|
|
6
|
+
*/
|
|
7
|
+
var MOUSE_EVENT_INFO_DESKTOP = (function () {
|
|
8
|
+
return {
|
|
9
|
+
MOUSEDOWN: 'mousedown',
|
|
10
|
+
MOUSEMOVE: 'mousemove',
|
|
11
|
+
MOUSEUP: 'mouseup',
|
|
12
|
+
getPageXY: getMouseEventPageXY,
|
|
13
|
+
};
|
|
14
|
+
})();
|
|
15
|
+
var MOUSE_EVENT_INFO_MOBILE = (function () {
|
|
16
|
+
return {
|
|
17
|
+
MOUSEDOWN: 'touchstart',
|
|
18
|
+
MOUSEMOVE: 'touchmove',
|
|
19
|
+
MOUSEUP: 'touchend',
|
|
20
|
+
getPageXY: getTouchEventPageXY,
|
|
21
|
+
};
|
|
22
|
+
})();
|
|
23
|
+
function getMouseEventPageXY(e) {
|
|
24
|
+
return [e.pageX, e.pageY];
|
|
25
|
+
}
|
|
26
|
+
function getTouchEventPageXY(e) {
|
|
27
|
+
var pageX = 0;
|
|
28
|
+
var pageY = 0;
|
|
29
|
+
if (e.targetTouches && e.targetTouches.length > 0) {
|
|
30
|
+
var touch = e.targetTouches[0];
|
|
31
|
+
pageX = touch.pageX;
|
|
32
|
+
pageY = touch.pageY;
|
|
33
|
+
}
|
|
34
|
+
return [pageX, pageY];
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* @internal
|
|
38
|
+
* A helper class to help manage drag and drop to an HTML element
|
|
39
|
+
*/
|
|
40
|
+
var DragAndDropHelper = /** @class */ (function () {
|
|
41
|
+
/**
|
|
42
|
+
* Create a new instance of DragAndDropHelper class
|
|
43
|
+
* @param trigger The trigger element. When user start drag on this element,
|
|
44
|
+
* events will be fired to the handler object
|
|
45
|
+
* @param context Context object that will be passed to handler function when event is fired,
|
|
46
|
+
* so that the handler object knows which element it is triggered from.
|
|
47
|
+
* @param onSubmit A callback that will be invoked when event handler in handler object returns true
|
|
48
|
+
* @param handler The event handler object, see DragAndDropHandler interface for more information
|
|
49
|
+
* @param zoomScale The zoom scale of the editor
|
|
50
|
+
* @param forceMobile A boolean to force the use of touch controls for the helper
|
|
51
|
+
*/
|
|
52
|
+
function DragAndDropHelper(trigger, context, onSubmit, handler, zoomScale, forceMobile) {
|
|
53
|
+
var _this = this;
|
|
54
|
+
this.trigger = trigger;
|
|
55
|
+
this.context = context;
|
|
56
|
+
this.onSubmit = onSubmit;
|
|
57
|
+
this.handler = handler;
|
|
58
|
+
this.zoomScale = zoomScale;
|
|
59
|
+
this.initX = 0;
|
|
60
|
+
this.initY = 0;
|
|
61
|
+
this.initValue = undefined;
|
|
62
|
+
this.onMouseDown = function (e) {
|
|
63
|
+
var _a;
|
|
64
|
+
var _b, _c;
|
|
65
|
+
e.preventDefault();
|
|
66
|
+
e.stopPropagation();
|
|
67
|
+
_this.addDocumentEvents();
|
|
68
|
+
_a = (0, tslib_1.__read)(_this.dndMouse.getPageXY(e), 2), _this.initX = _a[0], _this.initY = _a[1];
|
|
69
|
+
_this.initValue = (_c = (_b = _this.handler).onDragStart) === null || _c === void 0 ? void 0 : _c.call(_b, _this.context, e);
|
|
70
|
+
};
|
|
71
|
+
this.onMouseMove = function (e) {
|
|
72
|
+
var _a, _b, _c;
|
|
73
|
+
e.preventDefault();
|
|
74
|
+
var _d = (0, tslib_1.__read)(_this.dndMouse.getPageXY(e), 2), pageX = _d[0], pageY = _d[1];
|
|
75
|
+
var deltaX = (pageX - _this.initX) / _this.zoomScale;
|
|
76
|
+
var deltaY = (pageY - _this.initY) / _this.zoomScale;
|
|
77
|
+
if (_this.initValue &&
|
|
78
|
+
((_b = (_a = _this.handler).onDragging) === null || _b === void 0 ? void 0 : _b.call(_a, _this.context, e, _this.initValue, deltaX, deltaY))) {
|
|
79
|
+
(_c = _this.onSubmit) === null || _c === void 0 ? void 0 : _c.call(_this, _this.context, _this.trigger);
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
this.onMouseUp = function (e) {
|
|
83
|
+
var _a, _b, _c;
|
|
84
|
+
e.preventDefault();
|
|
85
|
+
_this.removeDocumentEvents();
|
|
86
|
+
if ((_b = (_a = _this.handler).onDragEnd) === null || _b === void 0 ? void 0 : _b.call(_a, _this.context, e, _this.initValue)) {
|
|
87
|
+
(_c = _this.onSubmit) === null || _c === void 0 ? void 0 : _c.call(_this, _this.context, _this.trigger);
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
this.dndMouse = forceMobile ? MOUSE_EVENT_INFO_MOBILE : MOUSE_EVENT_INFO_DESKTOP;
|
|
91
|
+
trigger.addEventListener(this.dndMouse.MOUSEDOWN, this.onMouseDown);
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Dispose this object, remove all event listeners that has been attached
|
|
95
|
+
*/
|
|
96
|
+
DragAndDropHelper.prototype.dispose = function () {
|
|
97
|
+
this.trigger.removeEventListener(this.dndMouse.MOUSEDOWN, this.onMouseDown);
|
|
98
|
+
this.removeDocumentEvents();
|
|
99
|
+
};
|
|
100
|
+
Object.defineProperty(DragAndDropHelper.prototype, "mouseType", {
|
|
101
|
+
get: function () {
|
|
102
|
+
return this.dndMouse == MOUSE_EVENT_INFO_MOBILE ? 'touch' : 'mouse';
|
|
103
|
+
},
|
|
104
|
+
enumerable: false,
|
|
105
|
+
configurable: true
|
|
106
|
+
});
|
|
107
|
+
DragAndDropHelper.prototype.addDocumentEvents = function () {
|
|
108
|
+
var doc = this.trigger.ownerDocument;
|
|
109
|
+
doc.addEventListener(this.dndMouse.MOUSEMOVE, this.onMouseMove, true /*useCapture*/);
|
|
110
|
+
doc.addEventListener(this.dndMouse.MOUSEUP, this.onMouseUp, true /*useCapture*/);
|
|
111
|
+
};
|
|
112
|
+
DragAndDropHelper.prototype.removeDocumentEvents = function () {
|
|
113
|
+
var doc = this.trigger.ownerDocument;
|
|
114
|
+
doc.removeEventListener(this.dndMouse.MOUSEMOVE, this.onMouseMove, true /*useCapture*/);
|
|
115
|
+
doc.removeEventListener(this.dndMouse.MOUSEUP, this.onMouseUp, true /*useCapture*/);
|
|
116
|
+
};
|
|
117
|
+
return DragAndDropHelper;
|
|
118
|
+
}());
|
|
119
|
+
exports.default = DragAndDropHelper;
|
|
120
|
+
});
|
|
121
|
+
//# sourceMappingURL=DragAndDropHelper.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DragAndDropHelper.js","sourceRoot":"","sources":["../../../../../packages-content-model/roosterjs-content-model-plugins/lib/pluginUtils/DragAndDrop/DragAndDropHelper.ts"],"names":[],"mappings":";;;IA2BA;;OAEG;IACH,IAAM,wBAAwB,GAAmB,CAAC;QAC9C,OAAO;YACH,SAAS,EAAE,WAAW;YACtB,SAAS,EAAE,WAAW;YACtB,OAAO,EAAE,SAAS;YAClB,SAAS,EAAE,mBAAmB;SACjC,CAAC;IACN,CAAC,CAAC,EAAE,CAAC;IAEL,IAAM,uBAAuB,GAAmB,CAAC;QAC7C,OAAO;YACH,SAAS,EAAE,YAAY;YACvB,SAAS,EAAE,WAAW;YACtB,OAAO,EAAE,UAAU;YACnB,SAAS,EAAE,mBAAmB;SACjC,CAAC;IACN,CAAC,CAAC,EAAE,CAAC;IAEL,SAAS,mBAAmB,CAAC,CAAa;QACtC,OAAO,CAAC,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC;IAC9B,CAAC;IAED,SAAS,mBAAmB,CAAC,CAAa;QACtC,IAAI,KAAK,GAAG,CAAC,CAAC;QACd,IAAI,KAAK,GAAG,CAAC,CAAC;QACd,IAAI,CAAC,CAAC,aAAa,IAAI,CAAC,CAAC,aAAa,CAAC,MAAM,GAAG,CAAC,EAAE;YAC/C,IAAM,KAAK,GAAG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,CAAC,oBAAoB,EAAE,CAAC;QAChC,CAAC;QAED,sBAAW,wCAAS;iBAApB;gBACI,OAAO,IAAI,CAAC,QAAQ,IAAI,uBAAuB,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC;YACxE,CAAC;;;WAAA;QAEO,6CAAiB,GAAzB;YACI,IAAM,GAAG,GAAG,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC;YACvC,GAAG,CAAC,gBAAgB,CAAC,IAAI,CAAC,QAAQ,CAAC,SAAS,EAAE,IAAI,CAAC,WAAW,EAAE,IAAI,CAAC,cAAc,CAAC,CAAC;YACrF,GAAG,CAAC,gBAAgB,CAAC,IAAI,CAAC,QAAQ,CAAC,OAAO,EAAE,IAAI,CAAC,SAAS,EAAE,IAAI,CAAC,cAAc,CAAC,CAAC;QACrF,CAAC;QAEO,gDAAoB,GAA5B;YACI,IAAM,GAAG,GAAG,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC;YACvC,GAAG,CAAC,mBAAmB,CAAC,IAAI,CAAC,QAAQ,CAAC,SAAS,EAAE,IAAI,CAAC,WAAW,EAAE,IAAI,CAAC,cAAc,CAAC,CAAC;YACxF,GAAG,CAAC,mBAAmB,CAAC,IAAI,CAAC,QAAQ,CAAC,OAAO,EAAE,IAAI,CAAC,SAAS,EAAE,IAAI,CAAC,cAAc,CAAC,CAAC;QACxF,CAAC;QA8BL,wBAAC;IAAD,CAAC,AAjFD,IAiFC","sourcesContent":["import type Disposable from '../Disposable';\nimport type DragAndDropHandler from './DragAndDropHandler';\n\n/**\n * @internal\n */\ninterface MouseEventMoves {\n MOUSEDOWN: string;\n MOUSEMOVE: string;\n MOUSEUP: string;\n}\n\n/**\n * @internal\n */\ninterface MouseEventInfo extends MouseEventMoves {\n getPageXY: (e: MouseEvent) => number[];\n}\n\n/**\n * @internal\n * Compatible mouse event names for different platform\n */\ninterface TouchEventInfo extends MouseEventMoves {\n getPageXY: (e: TouchEvent) => number[];\n}\n\n/**\n * Generate event names and getXY function based on different platforms to be compatible with desktop and mobile browsers\n */\nconst MOUSE_EVENT_INFO_DESKTOP: MouseEventInfo = (() => {\n return {\n MOUSEDOWN: 'mousedown',\n MOUSEMOVE: 'mousemove',\n MOUSEUP: 'mouseup',\n getPageXY: getMouseEventPageXY,\n };\n})();\n\nconst MOUSE_EVENT_INFO_MOBILE: TouchEventInfo = (() => {\n return {\n MOUSEDOWN: 'touchstart',\n MOUSEMOVE: 'touchmove',\n MOUSEUP: 'touchend',\n getPageXY: getTouchEventPageXY,\n };\n})();\n\nfunction getMouseEventPageXY(e: MouseEvent): [number, number] {\n return [e.pageX, e.pageY];\n}\n\nfunction getTouchEventPageXY(e: TouchEvent): [number, number] {\n let pageX = 0;\n let pageY = 0;\n if (e.targetTouches && e.targetTouches.length > 0) {\n const touch = e.targetTouches[0];\n pageX = touch.pageX;\n pageY = touch.pageY;\n }\n return [pageX, pageY];\n}\n\n/**\n * @internal\n * A helper class to help manage drag and drop to an HTML element\n */\nexport default class DragAndDropHelper<TContext, TInitValue> implements Disposable {\n private initX: number = 0;\n private initY: number = 0;\n private initValue: TInitValue | undefined = undefined;\n private dndMouse: MouseEventInfo | TouchEventInfo;\n\n /**\n * Create a new instance of DragAndDropHelper class\n * @param trigger The trigger element. When user start drag on this element,\n * events will be fired to the handler object\n * @param context Context object that will be passed to handler function when event is fired,\n * so that the handler object knows which element it is triggered from.\n * @param onSubmit A callback that will be invoked when event handler in handler object returns true\n * @param handler The event handler object, see DragAndDropHandler interface for more information\n * @param zoomScale The zoom scale of the editor\n * @param forceMobile A boolean to force the use of touch controls for the helper\n */\n constructor(\n private trigger: HTMLElement,\n private context: TContext,\n private onSubmit: (context: TContext, trigger: HTMLElement) => void,\n private handler: DragAndDropHandler<TContext, TInitValue>,\n private zoomScale: number,\n forceMobile?: boolean\n ) {\n this.dndMouse = forceMobile ? MOUSE_EVENT_INFO_MOBILE : MOUSE_EVENT_INFO_DESKTOP;\n trigger.addEventListener(this.dndMouse.MOUSEDOWN, this.onMouseDown);\n }\n\n /**\n * Dispose this object, remove all event listeners that has been attached\n */\n dispose() {\n this.trigger.removeEventListener(this.dndMouse.MOUSEDOWN, this.onMouseDown);\n this.removeDocumentEvents();\n }\n\n public get mouseType(): string {\n return this.dndMouse == MOUSE_EVENT_INFO_MOBILE ? 'touch' : 'mouse';\n }\n\n private addDocumentEvents() {\n const doc = this.trigger.ownerDocument;\n doc.addEventListener(this.dndMouse.MOUSEMOVE, this.onMouseMove, true /*useCapture*/);\n doc.addEventListener(this.dndMouse.MOUSEUP, this.onMouseUp, true /*useCapture*/);\n }\n\n private removeDocumentEvents() {\n const doc = this.trigger.ownerDocument;\n doc.removeEventListener(this.dndMouse.MOUSEMOVE, this.onMouseMove, true /*useCapture*/);\n doc.removeEventListener(this.dndMouse.MOUSEUP, this.onMouseUp, true /*useCapture*/);\n }\n\n private onMouseDown = (e: Event) => {\n e.preventDefault();\n e.stopPropagation();\n this.addDocumentEvents();\n [this.initX, this.initY] = this.dndMouse.getPageXY(e as MouseEvent & TouchEvent);\n this.initValue = this.handler.onDragStart?.(this.context, e as MouseEvent);\n };\n\n private onMouseMove = (e: Event) => {\n e.preventDefault();\n const [pageX, pageY] = this.dndMouse.getPageXY(e as MouseEvent & TouchEvent);\n const deltaX = (pageX - this.initX) / this.zoomScale;\n const deltaY = (pageY - this.initY) / this.zoomScale;\n if (\n this.initValue &&\n this.handler.onDragging?.(this.context, e as MouseEvent, this.initValue, deltaX, deltaY)\n ) {\n this.onSubmit?.(this.context, this.trigger);\n }\n };\n\n private onMouseUp = (e: Event) => {\n e.preventDefault();\n this.removeDocumentEvents();\n if (this.handler.onDragEnd?.(this.context, e as MouseEvent, this.initValue)) {\n this.onSubmit?.(this.context, this.trigger);\n }\n };\n}\n"]}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { Rect } from 'roosterjs-content-model-types';
|
|
2
|
+
/**
|
|
3
|
+
* Get the intersected Rect of elements provided
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* The result of the following Elements Rects would be:
|
|
7
|
+
{
|
|
8
|
+
top: Element2.top,
|
|
9
|
+
bottom: Element1.bottom,
|
|
10
|
+
left: Element2.left,
|
|
11
|
+
right: Element2.right
|
|
12
|
+
}
|
|
13
|
+
+-------------------------+
|
|
14
|
+
| Element 1 |
|
|
15
|
+
| +-----------------+ |
|
|
16
|
+
| | Element2 | |
|
|
17
|
+
| | | |
|
|
18
|
+
| | | |
|
|
19
|
+
+-------------------------+
|
|
20
|
+
| |
|
|
21
|
+
+-----------------+
|
|
22
|
+
* @internal
|
|
23
|
+
* @param elements Elements to use.
|
|
24
|
+
* @param additionalRects additional rects to use
|
|
25
|
+
* @returns If the Rect is valid return the rect, if not, return null.
|
|
26
|
+
*/
|
|
27
|
+
export default function getIntersectedRect(elements: HTMLElement[], additionalRects?: Rect[]): Rect | null;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
define(["require", "exports", "tslib", "./normalizeRect"], function (require, exports, tslib_1, normalizeRect_1) {
|
|
2
|
+
"use strict";
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
/**
|
|
5
|
+
* Get the intersected Rect of elements provided
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* The result of the following Elements Rects would be:
|
|
9
|
+
{
|
|
10
|
+
top: Element2.top,
|
|
11
|
+
bottom: Element1.bottom,
|
|
12
|
+
left: Element2.left,
|
|
13
|
+
right: Element2.right
|
|
14
|
+
}
|
|
15
|
+
+-------------------------+
|
|
16
|
+
| Element 1 |
|
|
17
|
+
| +-----------------+ |
|
|
18
|
+
| | Element2 | |
|
|
19
|
+
| | | |
|
|
20
|
+
| | | |
|
|
21
|
+
+-------------------------+
|
|
22
|
+
| |
|
|
23
|
+
+-----------------+
|
|
24
|
+
* @internal
|
|
25
|
+
* @param elements Elements to use.
|
|
26
|
+
* @param additionalRects additional rects to use
|
|
27
|
+
* @returns If the Rect is valid return the rect, if not, return null.
|
|
28
|
+
*/
|
|
29
|
+
function getIntersectedRect(elements, additionalRects) {
|
|
30
|
+
if (additionalRects === void 0) { additionalRects = []; }
|
|
31
|
+
var rects = elements
|
|
32
|
+
.map(function (element) { return (0, normalizeRect_1.default)(element.getBoundingClientRect()); })
|
|
33
|
+
.concat(additionalRects)
|
|
34
|
+
.filter(function (element) { return !!element; });
|
|
35
|
+
var result = {
|
|
36
|
+
top: Math.max.apply(Math, (0, tslib_1.__spreadArray)([], (0, tslib_1.__read)(rects.map(function (r) { return r.top; })), false)),
|
|
37
|
+
bottom: Math.min.apply(Math, (0, tslib_1.__spreadArray)([], (0, tslib_1.__read)(rects.map(function (r) { return r.bottom; })), false)),
|
|
38
|
+
left: Math.max.apply(Math, (0, tslib_1.__spreadArray)([], (0, tslib_1.__read)(rects.map(function (r) { return r.left; })), false)),
|
|
39
|
+
right: Math.min.apply(Math, (0, tslib_1.__spreadArray)([], (0, tslib_1.__read)(rects.map(function (r) { return r.right; })), false)),
|
|
40
|
+
};
|
|
41
|
+
return result.top < result.bottom && result.left < result.right ? result : null;
|
|
42
|
+
}
|
|
43
|
+
exports.default = getIntersectedRect;
|
|
44
|
+
});
|
|
45
|
+
//# sourceMappingURL=getIntersectedRect.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getIntersectedRect.js","sourceRoot":"","sources":["../../../../../packages-content-model/roosterjs-content-model-plugins/lib/pluginUtils/Rect/getIntersectedRect.ts"],"names":[],"mappings":";;;IAGA;;;;;;;;;;;;;;;;;;;;;;;;OAwBG;IACH,SAAwB,kBAAkB,CACtC,QAAuB,EACvB,eAA4B;QAA5B,gCAAA,EAAA,oBAA4B;QAE5B,IAAM,KAAK,GAAG,QAAQ;aACjB,GAAG,CAAC,UAAA,OAAO,IAAI,OAAA,IAAA,uBAAa,EAAC,OAAO,CAAC,qBAAqB,EAAE,CAAC,EAA9C,CAA8C,CAAC;aAC9D,MAAM,CAAC,eAAe,CAAC;aACvB,MAAM,CAAC,UAAA,OAAO,IAAI,OAAA,CAAC,CAAC,OAAO,EAAT,CAAS,CAAW,CAAC;QAE5C,IAAM,MAAM,GAAS;YACjB,GAAG,EAAE,IAAI,CAAC,GAAG,OAAR,IAAI,qDAAQ,KAAK,CAAC,GAAG,CAAC,UAAA,CAAC,IAAI,OAAA,CAAC,CAAC,GAAG,EAAL,CAAK,CAAC,UAAC;YACvC,MAAM,EAAE,IAAI,CAAC,GAAG,OAAR,IAAI,qDAAQ,KAAK,CAAC,GAAG,CAAC,UAAA,CAAC,IAAI,OAAA,CAAC,CAAC,MAAM,EAAR,CAAQ,CAAC,UAAC;YAC7C,IAAI,EAAE,IAAI,CAAC,GAAG,OAAR,IAAI,qDAAQ,KAAK,CAAC,GAAG,CAAC,UAAA,CAAC,IAAI,OAAA,CAAC,CAAC,IAAI,EAAN,CAAM,CAAC,UAAC;YACzC,KAAK,EAAE,IAAI,CAAC,GAAG,OAAR,IAAI,qDAAQ,KAAK,CAAC,GAAG,CAAC,UAAA,CAAC,IAAI,OAAA,CAAC,CAAC,KAAK,EAAP,CAAO,CAAC,UAAC;SAC9C,CAAC;QAEF,OAAO,MAAM,CAAC,GAAG,GAAG,MAAM,CAAC,MAAM,IAAI,MAAM,CAAC,IAAI,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC;IACpF,CAAC;IAjBD,qCAiBC","sourcesContent":["import normalizeRect from './normalizeRect';\nimport type { Rect } from 'roosterjs-content-model-types';\n\n/**\n * Get the intersected Rect of elements provided\n *\n * @example\n * The result of the following Elements Rects would be:\n {\n top: Element2.top,\n bottom: Element1.bottom,\n left: Element2.left,\n right: Element2.right\n }\n +-------------------------+\n | Element 1 |\n | +-----------------+ |\n | | Element2 | |\n | | | |\n | | | |\n +-------------------------+\n | |\n +-----------------+\n * @internal\n * @param elements Elements to use.\n * @param additionalRects additional rects to use\n * @returns If the Rect is valid return the rect, if not, return null.\n */\nexport default function getIntersectedRect(\n elements: HTMLElement[],\n additionalRects: Rect[] = []\n): Rect | null {\n const rects = elements\n .map(element => normalizeRect(element.getBoundingClientRect()))\n .concat(additionalRects)\n .filter(element => !!element) as Rect[];\n\n const result: Rect = {\n top: Math.max(...rects.map(r => r.top)),\n bottom: Math.min(...rects.map(r => r.bottom)),\n left: Math.max(...rects.map(r => r.left)),\n right: Math.min(...rects.map(r => r.right)),\n };\n\n return result.top < result.bottom && result.left < result.right ? result : null;\n}\n"]}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { Rect } from 'roosterjs-content-model-types';
|
|
2
|
+
/**
|
|
3
|
+
* @internal
|
|
4
|
+
* A ClientRect of all 0 is possible. i.e. chrome returns a ClientRect of 0 when the cursor is on an empty p
|
|
5
|
+
* We validate that and only return a rect when the passed in ClientRect is valid
|
|
6
|
+
*/
|
|
7
|
+
export default function normalizeRect(clientRect: DOMRect): Rect | null;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
define(["require", "exports"], function (require, exports) {
|
|
2
|
+
"use strict";
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
/**
|
|
5
|
+
* @internal
|
|
6
|
+
* A ClientRect of all 0 is possible. i.e. chrome returns a ClientRect of 0 when the cursor is on an empty p
|
|
7
|
+
* We validate that and only return a rect when the passed in ClientRect is valid
|
|
8
|
+
*/
|
|
9
|
+
function normalizeRect(clientRect) {
|
|
10
|
+
var _a = clientRect || { left: 0, right: 0, top: 0, bottom: 0 }, left = _a.left, right = _a.right, top = _a.top, bottom = _a.bottom;
|
|
11
|
+
return left === 0 && right === 0 && top === 0 && bottom === 0
|
|
12
|
+
? null
|
|
13
|
+
: {
|
|
14
|
+
left: Math.round(left),
|
|
15
|
+
right: Math.round(right),
|
|
16
|
+
top: Math.round(top),
|
|
17
|
+
bottom: Math.round(bottom),
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
exports.default = normalizeRect;
|
|
21
|
+
});
|
|
22
|
+
//# sourceMappingURL=normalizeRect.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"normalizeRect.js","sourceRoot":"","sources":["../../../../../packages-content-model/roosterjs-content-model-plugins/lib/pluginUtils/Rect/normalizeRect.ts"],"names":[],"mappings":";;;IAEA;;;;OAIG;IACH,SAAwB,aAAa,CAAC,UAAmB;QAC/C,IAAA,KACF,UAAU,IAAa,EAAE,IAAI,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,EAD3D,IAAI,UAAA,EAAE,KAAK,WAAA,EAAE,GAAG,SAAA,EAAE,MAAM,YACmC,CAAC;QACpE,OAAO,IAAI,KAAK,CAAC,IAAI,KAAK,KAAK,CAAC,IAAI,GAAG,KAAK,CAAC,IAAI,MAAM,KAAK,CAAC;YACzD,CAAC,CAAC,IAAI;YACN,CAAC,CAAC;gBACI,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC;gBACtB,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC;gBACxB,GAAG,EAAE,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC;gBACpB,MAAM,EAAE,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC;aAC7B,CAAC;IACZ,CAAC;IAXD,gCAWC","sourcesContent":["import type { Rect } from 'roosterjs-content-model-types';\n\n/**\n * @internal\n * A ClientRect of all 0 is possible. i.e. chrome returns a ClientRect of 0 when the cursor is on an empty p\n * We validate that and only return a rect when the passed in ClientRect is valid\n */\nexport default function normalizeRect(clientRect: DOMRect): Rect | null {\n const { left, right, top, bottom } =\n clientRect || <DOMRect>{ left: 0, right: 0, top: 0, bottom: 0 };\n return left === 0 && right === 0 && top === 0 && bottom === 0\n ? null\n : {\n left: Math.round(left),\n right: Math.round(right),\n top: Math.round(top),\n bottom: Math.round(bottom),\n };\n}\n"]}
|
|
@@ -16,7 +16,7 @@ export declare type AutoFormatOptions = {
|
|
|
16
16
|
* Auto Format plugin handles auto formatting, such as transforming * characters into a bullet list.
|
|
17
17
|
* It can be customized with options to enable or disable auto list features.
|
|
18
18
|
*/
|
|
19
|
-
export declare class
|
|
19
|
+
export declare class AutoFormatPlugin implements EditorPlugin {
|
|
20
20
|
private options;
|
|
21
21
|
private editor;
|
|
22
22
|
/**
|
|
@@ -10,13 +10,13 @@ var DefaultOptions = {
|
|
|
10
10
|
* Auto Format plugin handles auto formatting, such as transforming * characters into a bullet list.
|
|
11
11
|
* It can be customized with options to enable or disable auto list features.
|
|
12
12
|
*/
|
|
13
|
-
var
|
|
13
|
+
var AutoFormatPlugin = /** @class */ (function () {
|
|
14
14
|
/**
|
|
15
15
|
* @param options An optional parameter that takes in an object of type AutoFormatOptions, which includes the following properties:
|
|
16
16
|
* - autoBullet: A boolean that enables or disables automatic bullet list formatting. Defaults to true.
|
|
17
17
|
* - autoNumbering: A boolean that enables or disables automatic numbering formatting. Defaults to true.
|
|
18
18
|
*/
|
|
19
|
-
function
|
|
19
|
+
function AutoFormatPlugin(options) {
|
|
20
20
|
if (options === void 0) { options = DefaultOptions; }
|
|
21
21
|
this.options = options;
|
|
22
22
|
this.editor = null;
|
|
@@ -24,8 +24,8 @@ var ContentModelAutoFormatPlugin = /** @class */ (function () {
|
|
|
24
24
|
/**
|
|
25
25
|
* Get name of this plugin
|
|
26
26
|
*/
|
|
27
|
-
|
|
28
|
-
return '
|
|
27
|
+
AutoFormatPlugin.prototype.getName = function () {
|
|
28
|
+
return 'AutoFormat';
|
|
29
29
|
};
|
|
30
30
|
/**
|
|
31
31
|
* The first method that editor will call to a plugin when editor is initializing.
|
|
@@ -33,7 +33,7 @@ var ContentModelAutoFormatPlugin = /** @class */ (function () {
|
|
|
33
33
|
* editor reference so that it can call to any editor method or format API later.
|
|
34
34
|
* @param editor The editor object
|
|
35
35
|
*/
|
|
36
|
-
|
|
36
|
+
AutoFormatPlugin.prototype.initialize = function (editor) {
|
|
37
37
|
this.editor = editor;
|
|
38
38
|
};
|
|
39
39
|
/**
|
|
@@ -41,7 +41,7 @@ var ContentModelAutoFormatPlugin = /** @class */ (function () {
|
|
|
41
41
|
* Plugin can take this chance to clear the reference to editor. After this method is
|
|
42
42
|
* called, plugin should not call to any editor method since it will result in error.
|
|
43
43
|
*/
|
|
44
|
-
|
|
44
|
+
AutoFormatPlugin.prototype.dispose = function () {
|
|
45
45
|
this.editor = null;
|
|
46
46
|
};
|
|
47
47
|
/**
|
|
@@ -50,7 +50,7 @@ var ContentModelAutoFormatPlugin = /** @class */ (function () {
|
|
|
50
50
|
* exclusively by another plugin.
|
|
51
51
|
* @param event The event to handle:
|
|
52
52
|
*/
|
|
53
|
-
|
|
53
|
+
AutoFormatPlugin.prototype.onPluginEvent = function (event) {
|
|
54
54
|
if (this.editor) {
|
|
55
55
|
switch (event.eventType) {
|
|
56
56
|
case 'keyDown':
|
|
@@ -59,7 +59,7 @@ var ContentModelAutoFormatPlugin = /** @class */ (function () {
|
|
|
59
59
|
}
|
|
60
60
|
}
|
|
61
61
|
};
|
|
62
|
-
|
|
62
|
+
AutoFormatPlugin.prototype.handleKeyDownEvent = function (editor, event) {
|
|
63
63
|
var rawEvent = event.rawEvent;
|
|
64
64
|
if (!rawEvent.defaultPrevented && !event.handledByEditFeature) {
|
|
65
65
|
switch (rawEvent.key) {
|
|
@@ -72,7 +72,7 @@ var ContentModelAutoFormatPlugin = /** @class */ (function () {
|
|
|
72
72
|
}
|
|
73
73
|
}
|
|
74
74
|
};
|
|
75
|
-
return
|
|
75
|
+
return AutoFormatPlugin;
|
|
76
76
|
}());
|
|
77
|
-
export {
|
|
78
|
-
//# sourceMappingURL=
|
|
77
|
+
export { AutoFormatPlugin };
|
|
78
|
+
//# sourceMappingURL=AutoFormatPlugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AutoFormatPlugin.js","sourceRoot":"","sources":["../../../../packages-content-model/roosterjs-content-model-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,mBAAmB,CAAC,MAAM,EAAE,QAAQ,EAAE,UAAU,EAAE,aAAa,CAAC,CAAC;qBACpE;oBACD,MAAM;aACb;SACJ;IACL,CAAC;IACL,uBAAC;AAAD,CAAC,AAjED,IAiEC","sourcesContent":["import { keyboardListTrigger } from './keyboardListTrigger';\nimport type {\n EditorPlugin,\n IStandaloneEditor,\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: IStandaloneEditor | 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: IStandaloneEditor) {\n this.editor = editor;\n }\n\n /**\n * The last method that editor will call to a plugin before it is disposed.\n * Plugin can take this chance to clear the reference to editor. After this method is\n * called, plugin should not call to any editor method since it will result in error.\n */\n dispose() {\n this.editor = null;\n }\n\n /**\n * Core method for a plugin. Once an event happens in editor, editor will call this\n * method of each plugin to handle the event as long as the event is not handled\n * exclusively by another plugin.\n * @param event The event to handle:\n */\n onPluginEvent(event: PluginEvent) {\n if (this.editor) {\n switch (event.eventType) {\n case 'keyDown':\n this.handleKeyDownEvent(this.editor, event);\n break;\n }\n }\n }\n\n private handleKeyDownEvent(editor: IStandaloneEditor, event: KeyDownEvent) {\n const rawEvent = event.rawEvent;\n 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 +1 @@
|
|
|
1
|
-
{"version":3,"file":"keyboardListTrigger.js","sourceRoot":"","sources":["../../../../packages-content-model/roosterjs-content-model-plugins/lib/autoFormat/keyboardListTrigger.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAC5D,OAAO,EAAE,gCAAgC,EAAE,MAAM,8BAA8B,CAAC;AAChF,OAAO,EAAE,qBAAqB,EAAE,MAAM,6BAA6B,CAAC;AACpE,OAAO,EAAE,kBAAkB,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;
|
|
1
|
+
{"version":3,"file":"keyboardListTrigger.js","sourceRoot":"","sources":["../../../../packages-content-model/roosterjs-content-model-plugins/lib/autoFormat/keyboardListTrigger.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAC5D,OAAO,EAAE,gCAAgC,EAAE,MAAM,8BAA8B,CAAC;AAChF,OAAO,EAAE,qBAAqB,EAAE,MAAM,6BAA6B,CAAC;AACpE,OAAO,EAAE,kBAAkB,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAI5F;;GAEG;AACH,MAAM,UAAU,mBAAmB,CAC/B,MAAyB,EACzB,QA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,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';\n\nimport type { ContentModelDocument, IStandaloneEditor } from 'roosterjs-content-model-types';\n\n/**\n * @internal\n */\nexport function keyboardListTrigger(\n editor: IStandaloneEditor,\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: IStandaloneEditor,\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"]}
|
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { findListItemsInSameThread } from 'roosterjs-content-model-api';
|
|
2
2
|
import { getNumberingListStyle } from './getNumberingListStyle';
|
|
3
3
|
import { BulletListType, isBlockGroupOfType, updateListMetadata, getOperationalBlocks, getSelectedSegmentsAndParagraphs, } from 'roosterjs-content-model-core';
|
|
4
4
|
/**
|
|
5
5
|
* @internal
|
|
6
6
|
*/
|
|
7
7
|
export function getListTypeStyle(model, shouldSearchForBullet, shouldSearchForNumbering) {
|
|
8
|
-
var _a, _b;
|
|
9
8
|
if (shouldSearchForBullet === void 0) { shouldSearchForBullet = true; }
|
|
10
9
|
if (shouldSearchForNumbering === void 0) { shouldSearchForNumbering = true; }
|
|
11
10
|
var selectedSegmentsAndParagraphs = getSelectedSegmentsAndParagraphs(model, true);
|
|
@@ -23,35 +22,39 @@ export function getListTypeStyle(model, shouldSearchForBullet, shouldSearchForNu
|
|
|
23
22
|
}
|
|
24
23
|
else if (shouldSearchForNumbering) {
|
|
25
24
|
var previousList = getPreviousListLevel(model, paragraph);
|
|
25
|
+
var previousIndex = getPreviousListIndex(model, previousList);
|
|
26
26
|
var previousListStyle = getPreviousListStyle(previousList);
|
|
27
|
-
var numberingType = getNumberingListStyle(listMarker,
|
|
28
|
-
? getIndex(previousList.format.listStyleType)
|
|
29
|
-
: undefined, previousListStyle);
|
|
27
|
+
var numberingType = getNumberingListStyle(listMarker, previousIndex, previousListStyle);
|
|
30
28
|
if (numberingType) {
|
|
31
29
|
return {
|
|
32
30
|
listType: 'OL',
|
|
33
31
|
styleType: numberingType,
|
|
34
|
-
index: (
|
|
32
|
+
index: !isNewList(listMarker) &&
|
|
33
|
+
previousListStyle === numberingType &&
|
|
34
|
+
previousIndex
|
|
35
|
+
? previousIndex + 1
|
|
36
|
+
: undefined,
|
|
35
37
|
};
|
|
36
38
|
}
|
|
37
39
|
}
|
|
38
40
|
}
|
|
39
41
|
return undefined;
|
|
40
42
|
}
|
|
43
|
+
var getPreviousListIndex = function (model, previousListItem) {
|
|
44
|
+
return previousListItem ? findListItemsInSameThread(model, previousListItem).length : undefined;
|
|
45
|
+
};
|
|
41
46
|
var getPreviousListLevel = function (model, paragraph) {
|
|
42
|
-
var blocks = getOperationalBlocks(model, ['ListItem'], ['TableCell']);
|
|
47
|
+
var blocks = getOperationalBlocks(model, ['ListItem'], ['TableCell'])[0];
|
|
43
48
|
var listItem = undefined;
|
|
44
|
-
|
|
45
|
-
var
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
listItem = item;
|
|
54
|
-
break;
|
|
49
|
+
if (blocks) {
|
|
50
|
+
var listBlockIndex = blocks.parent.blocks.indexOf(paragraph);
|
|
51
|
+
if (listBlockIndex > -1) {
|
|
52
|
+
for (var i = listBlockIndex - 1; i > -1; i--) {
|
|
53
|
+
var item = blocks.parent.blocks[i];
|
|
54
|
+
if (isBlockGroupOfType(item, 'ListItem')) {
|
|
55
|
+
listItem = item;
|
|
56
|
+
break;
|
|
57
|
+
}
|
|
55
58
|
}
|
|
56
59
|
}
|
|
57
60
|
}
|
|
@@ -73,4 +76,9 @@ var bulletListType = {
|
|
|
73
76
|
'>': BulletListType.ShortArrow,
|
|
74
77
|
'—': BulletListType.Hyphen,
|
|
75
78
|
};
|
|
79
|
+
var isNewList = function (listMarker) {
|
|
80
|
+
var marker = listMarker.replace(/[^\w\s]/g, '');
|
|
81
|
+
var pattern = /^[1aAiI]$/;
|
|
82
|
+
return pattern.test(marker);
|
|
83
|
+
};
|
|
76
84
|
//# sourceMappingURL=getListTypeStyle.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getListTypeStyle.js","sourceRoot":"","sources":["../../../../../packages-content-model/roosterjs-content-model-plugins/lib/autoFormat/utils/getListTypeStyle.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"getListTypeStyle.js","sourceRoot":"","sources":["../../../../../packages-content-model/roosterjs-content-model-plugins/lib/autoFormat/utils/getListTypeStyle.ts"],"names":[],"mappings":"AAA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ACT;aACJ;SACJ;KACJ;IAED,OAAO,QAAQ,CAAC;AACpB,CAAC,CAAC;AAEF,IAAM,oBAAoB,GAAG,UAAC,IAA2B;;IACrD,IAAI,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,MAAM,CAAC,CAAC,EAAE,OAAO,EAAE;QACzB,OAAO,MAAA,kBAAkB,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,0CAAE,gBAAgB,CAAC;KAC/D;AACL,CAAC,CAAC;AAEF,IAAM,cAAc,GAA2B;IAC3C,GAAG,EAAE,cAAc,CAAC,IAAI;IACxB,GAAG,EAAE,cAAc,CAAC,IAAI;IACxB,IAAI,EAAE,cAAc,CAAC,MAAM;IAC3B,IAAI,EAAE,cAAc,CAAC,SAAS;IAC9B,KAAK,EAAE,cAAc,CAAC,eAAe;IACrC,IAAI,EAAE,cAAc,CAAC,aAAa;IAClC,GAAG,EAAE,cAAc,CAAC,UAAU;IAC9B,GAAG,EAAE,cAAc,CAAC,MAAM;CAC7B,CAAC;AAEF,IAAM,SAAS,GAAG,UAAC,UAAkB;IACjC,IAAM,MAAM,GAAG,UAAU,CAAC,OAAO,CAAC,UAAU,EAAE,EAAE,CAAC,CAAC;IAClD,IAAM,OAAO,GAAG,WAAW,CAAC;IAC5B,OAAO,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;AAChC,CAAC,CAAC","sourcesContent":["import { findListItemsInSameThread } from 'roosterjs-content-model-api';\nimport { getNumberingListStyle } from './getNumberingListStyle';\nimport type {\n ContentModelDocument,\n ContentModelListItem,\n ContentModelParagraph,\n} from 'roosterjs-content-model-types';\nimport {\n BulletListType,\n isBlockGroupOfType,\n updateListMetadata,\n getOperationalBlocks,\n getSelectedSegmentsAndParagraphs,\n} from 'roosterjs-content-model-core';\n\n/**\n * @internal\n */\ninterface ListTypeStyle {\n listType: 'UL' | 'OL';\n styleType: number;\n index?: number;\n}\n\n/**\n * @internal\n */\nexport function getListTypeStyle(\n model: ContentModelDocument,\n shouldSearchForBullet: boolean = true,\n shouldSearchForNumbering: boolean = true\n): ListTypeStyle | undefined {\n const selectedSegmentsAndParagraphs = getSelectedSegmentsAndParagraphs(model, true);\n const marker = selectedSegmentsAndParagraphs[0][0];\n const paragraph = selectedSegmentsAndParagraphs[0][1];\n const listMarkerSegment = paragraph?.segments[0];\n\n if (\n marker &&\n marker.segmentType == 'SelectionMarker' &&\n listMarkerSegment &&\n listMarkerSegment.segmentType == 'Text'\n ) {\n const listMarker = listMarkerSegment.text;\n const bulletType = bulletListType[listMarker];\n\n if (bulletType && shouldSearchForBullet) {\n return { listType: 'UL', styleType: bulletType };\n } else if (shouldSearchForNumbering) {\n const previousList = getPreviousListLevel(model, paragraph);\n const previousIndex = getPreviousListIndex(model, previousList);\n const previousListStyle = getPreviousListStyle(previousList);\n const numberingType = getNumberingListStyle(\n listMarker,\n previousIndex,\n previousListStyle\n );\n if (numberingType) {\n return {\n listType: 'OL',\n styleType: numberingType,\n index:\n !isNewList(listMarker) &&\n previousListStyle === numberingType &&\n previousIndex\n ? previousIndex + 1\n : undefined,\n };\n }\n }\n }\n return undefined;\n}\n\nconst getPreviousListIndex = (\n model: ContentModelDocument,\n previousListItem?: ContentModelListItem\n) => {\n return previousListItem ? findListItemsInSameThread(model, previousListItem).length : undefined;\n};\n\nconst getPreviousListLevel = (model: ContentModelDocument, paragraph: ContentModelParagraph) => {\n const blocks = getOperationalBlocks<ContentModelListItem>(\n model,\n ['ListItem'],\n ['TableCell']\n )[0];\n let listItem: ContentModelListItem | undefined = undefined;\n if (blocks) {\n const listBlockIndex = blocks.parent.blocks.indexOf(paragraph);\n\n if (listBlockIndex > -1) {\n for (let i = listBlockIndex - 1; i > -1; i--) {\n const item = blocks.parent.blocks[i];\n if (isBlockGroupOfType<ContentModelListItem>(item, 'ListItem')) {\n listItem = item;\n break;\n }\n }\n }\n }\n\n return listItem;\n};\n\nconst getPreviousListStyle = (list?: ContentModelListItem) => {\n if (list?.levels[0].dataset) {\n return updateListMetadata(list.levels[0])?.orderedStyleType;\n }\n};\n\nconst bulletListType: Record<string, number> = {\n '*': BulletListType.Disc,\n '-': BulletListType.Dash,\n '--': BulletListType.Square,\n '->': BulletListType.LongArrow,\n '-->': BulletListType.DoubleLongArrow,\n '=>': BulletListType.UnfilledArrow,\n '>': BulletListType.ShortArrow,\n '—': BulletListType.Hyphen,\n};\n\nconst isNewList = (listMarker: string) => {\n const marker = listMarker.replace(/[^\\w\\s]/g, '');\n const pattern = /^[1aAiI]$/;\n return pattern.test(marker);\n};\n"]}
|