@payloadcms/richtext-lexical 3.0.0-beta.35 → 3.0.0-beta.36
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/dist/cell/index.d.ts +2 -0
- package/dist/cell/index.d.ts.map +1 -1
- package/dist/cell/index.js +24 -15
- package/dist/cell/index.js.map +1 -1
- package/dist/field/Field.d.ts.map +1 -1
- package/dist/field/Field.js +66 -47
- package/dist/field/Field.js.map +1 -1
- package/dist/field/features/blocks/component/BlockContent.js +62 -45
- package/dist/field/features/blocks/component/BlockContent.js.map +1 -1
- package/dist/field/features/blocks/component/index.js +38 -28
- package/dist/field/features/blocks/component/index.js.map +1 -1
- package/dist/field/features/blocks/drawer/index.js +2 -1
- package/dist/field/features/blocks/drawer/index.js.map +1 -1
- package/dist/field/features/blocks/nodes/BlocksNode.d.ts +1 -1
- package/dist/field/features/blocks/nodes/BlocksNode.d.ts.map +1 -1
- package/dist/field/features/blocks/nodes/BlocksNode.js +2 -1
- package/dist/field/features/blocks/nodes/BlocksNode.js.map +1 -1
- package/dist/field/features/blocks/plugin/index.js +2 -1
- package/dist/field/features/blocks/plugin/index.js.map +1 -1
- package/dist/field/features/debug/testRecorder/plugin/index.js +65 -39
- package/dist/field/features/debug/testRecorder/plugin/index.js.map +1 -1
- package/dist/field/features/debug/treeView/plugin/index.js +2 -1
- package/dist/field/features/debug/treeView/plugin/index.js.map +1 -1
- package/dist/field/features/horizontalRule/nodes/HorizontalRuleNode.js +2 -1
- package/dist/field/features/horizontalRule/nodes/HorizontalRuleNode.js.map +1 -1
- package/dist/field/features/link/drawer/index.js +30 -22
- package/dist/field/features/link/drawer/index.js.map +1 -1
- package/dist/field/features/link/plugins/clickableLink/index.js +2 -1
- package/dist/field/features/link/plugins/clickableLink/index.js.map +1 -1
- package/dist/field/features/link/plugins/floatingLinkEditor/LinkEditor/index.d.ts.map +1 -1
- package/dist/field/features/link/plugins/floatingLinkEditor/LinkEditor/index.js +88 -70
- package/dist/field/features/link/plugins/floatingLinkEditor/LinkEditor/index.js.map +1 -1
- package/dist/field/features/link/plugins/floatingLinkEditor/index.js +2 -1
- package/dist/field/features/link/plugins/floatingLinkEditor/index.js.map +1 -1
- package/dist/field/features/lists/checklist/plugin/index.js +2 -1
- package/dist/field/features/lists/checklist/plugin/index.js.map +1 -1
- package/dist/field/features/lists/plugin/index.js +2 -1
- package/dist/field/features/lists/plugin/index.js.map +1 -1
- package/dist/field/features/migrations/lexicalPluginToLexical/nodes/unknownConvertedNode/Component.js +9 -1
- package/dist/field/features/migrations/lexicalPluginToLexical/nodes/unknownConvertedNode/Component.js.map +1 -1
- package/dist/field/features/migrations/lexicalPluginToLexical/nodes/unknownConvertedNode/index.d.ts +1 -1
- package/dist/field/features/migrations/lexicalPluginToLexical/nodes/unknownConvertedNode/index.d.ts.map +1 -1
- package/dist/field/features/migrations/lexicalPluginToLexical/nodes/unknownConvertedNode/index.js +2 -1
- package/dist/field/features/migrations/lexicalPluginToLexical/nodes/unknownConvertedNode/index.js.map +1 -1
- package/dist/field/features/migrations/slateToLexical/nodes/unknownConvertedNode/Component.js +9 -1
- package/dist/field/features/migrations/slateToLexical/nodes/unknownConvertedNode/Component.js.map +1 -1
- package/dist/field/features/migrations/slateToLexical/nodes/unknownConvertedNode/index.d.ts +1 -1
- package/dist/field/features/migrations/slateToLexical/nodes/unknownConvertedNode/index.d.ts.map +1 -1
- package/dist/field/features/migrations/slateToLexical/nodes/unknownConvertedNode/index.js +2 -1
- package/dist/field/features/migrations/slateToLexical/nodes/unknownConvertedNode/index.js.map +1 -1
- package/dist/field/features/relationship/drawer/index.js +10 -2
- package/dist/field/features/relationship/drawer/index.js.map +1 -1
- package/dist/field/features/relationship/nodes/RelationshipNode.d.ts +1 -1
- package/dist/field/features/relationship/nodes/RelationshipNode.d.ts.map +1 -1
- package/dist/field/features/relationship/nodes/RelationshipNode.js +2 -1
- package/dist/field/features/relationship/nodes/RelationshipNode.js.map +1 -1
- package/dist/field/features/relationship/nodes/components/RelationshipComponent.js +64 -44
- package/dist/field/features/relationship/nodes/components/RelationshipComponent.js.map +1 -1
- package/dist/field/features/relationship/plugins/index.js +2 -1
- package/dist/field/features/relationship/plugins/index.js.map +1 -1
- package/dist/field/features/toolbars/fixed/Toolbar/index.js +60 -55
- package/dist/field/features/toolbars/fixed/Toolbar/index.js.map +1 -1
- package/dist/field/features/toolbars/fixed/Toolbar/index.scss +16 -2
- package/dist/field/features/toolbars/inline/Toolbar/index.js +57 -49
- package/dist/field/features/toolbars/inline/Toolbar/index.js.map +1 -1
- package/dist/field/features/toolbars/shared/ToolbarButton/index.d.ts +1 -1
- package/dist/field/features/toolbars/shared/ToolbarButton/index.d.ts.map +1 -1
- package/dist/field/features/toolbars/shared/ToolbarButton/index.js +5 -3
- package/dist/field/features/toolbars/shared/ToolbarButton/index.js.map +1 -1
- package/dist/field/features/toolbars/shared/ToolbarDropdown/DropDown.d.ts.map +1 -1
- package/dist/field/features/toolbars/shared/ToolbarDropdown/DropDown.js +54 -35
- package/dist/field/features/toolbars/shared/ToolbarDropdown/DropDown.js.map +1 -1
- package/dist/field/features/toolbars/shared/ToolbarDropdown/index.d.ts +1 -1
- package/dist/field/features/toolbars/shared/ToolbarDropdown/index.d.ts.map +1 -1
- package/dist/field/features/toolbars/shared/ToolbarDropdown/index.js +25 -22
- package/dist/field/features/toolbars/shared/ToolbarDropdown/index.js.map +1 -1
- package/dist/field/features/upload/component/ExtraFieldsDrawer/index.js +30 -22
- package/dist/field/features/upload/component/ExtraFieldsDrawer/index.js.map +1 -1
- package/dist/field/features/upload/component/index.js +104 -71
- package/dist/field/features/upload/component/index.js.map +1 -1
- package/dist/field/features/upload/drawer/index.js +8 -4
- package/dist/field/features/upload/drawer/index.js.map +1 -1
- package/dist/field/features/upload/nodes/UploadNode.d.ts +1 -1
- package/dist/field/features/upload/nodes/UploadNode.d.ts.map +1 -1
- package/dist/field/features/upload/nodes/UploadNode.js +2 -1
- package/dist/field/features/upload/nodes/UploadNode.js.map +1 -1
- package/dist/field/features/upload/plugin/index.js +2 -1
- package/dist/field/features/upload/plugin/index.js.map +1 -1
- package/dist/field/index.d.ts +2 -0
- package/dist/field/index.d.ts.map +1 -1
- package/dist/field/index.js +29 -21
- package/dist/field/index.js.map +1 -1
- package/dist/field/index.scss +0 -19
- package/dist/field/lexical/EditorFocusProvider.d.ts +1 -2
- package/dist/field/lexical/EditorFocusProvider.d.ts.map +1 -1
- package/dist/field/lexical/EditorFocusProvider.js +5 -3
- package/dist/field/lexical/EditorFocusProvider.js.map +1 -1
- package/dist/field/lexical/EditorPlugin.js +3 -2
- package/dist/field/lexical/EditorPlugin.js.map +1 -1
- package/dist/field/lexical/LexicalEditor.js +113 -81
- package/dist/field/lexical/LexicalEditor.js.map +1 -1
- package/dist/field/lexical/LexicalEditor.scss +10 -1
- package/dist/field/lexical/LexicalProvider.js +16 -10
- package/dist/field/lexical/LexicalProvider.js.map +1 -1
- package/dist/field/lexical/config/client/EditorConfigProvider.js +5 -3
- package/dist/field/lexical/config/client/EditorConfigProvider.js.map +1 -1
- package/dist/field/lexical/config/client/sanitize.d.ts +2 -1
- package/dist/field/lexical/config/client/sanitize.d.ts.map +1 -1
- package/dist/field/lexical/config/client/sanitize.js +2 -1
- package/dist/field/lexical/config/client/sanitize.js.map +1 -1
- package/dist/field/lexical/config/types.d.ts +2 -0
- package/dist/field/lexical/config/types.d.ts.map +1 -1
- package/dist/field/lexical/config/types.js.map +1 -1
- package/dist/field/lexical/plugins/MarkdownShortcut/index.js +2 -1
- package/dist/field/lexical/plugins/MarkdownShortcut/index.js.map +1 -1
- package/dist/field/lexical/plugins/SlashMenu/LexicalTypeaheadMenuPlugin/LexicalMenu.d.ts +1 -1
- package/dist/field/lexical/plugins/SlashMenu/LexicalTypeaheadMenuPlugin/LexicalMenu.d.ts.map +1 -1
- package/dist/field/lexical/plugins/SlashMenu/LexicalTypeaheadMenuPlugin/LexicalMenu.js.map +1 -1
- package/dist/field/lexical/plugins/SlashMenu/LexicalTypeaheadMenuPlugin/index.d.ts +1 -1
- package/dist/field/lexical/plugins/SlashMenu/LexicalTypeaheadMenuPlugin/index.d.ts.map +1 -1
- package/dist/field/lexical/plugins/SlashMenu/LexicalTypeaheadMenuPlugin/index.js +2 -1
- package/dist/field/lexical/plugins/SlashMenu/LexicalTypeaheadMenuPlugin/index.js.map +1 -1
- package/dist/field/lexical/plugins/SlashMenu/index.js +51 -40
- package/dist/field/lexical/plugins/SlashMenu/index.js.map +1 -1
- package/dist/field/lexical/plugins/handles/AddBlockHandlePlugin/index.d.ts +2 -2
- package/dist/field/lexical/plugins/handles/AddBlockHandlePlugin/index.d.ts.map +1 -1
- package/dist/field/lexical/plugins/handles/AddBlockHandlePlugin/index.js +38 -119
- package/dist/field/lexical/plugins/handles/AddBlockHandlePlugin/index.js.map +1 -1
- package/dist/field/lexical/plugins/handles/AddBlockHandlePlugin/index.scss +2 -2
- package/dist/field/lexical/plugins/handles/DraggableBlockPlugin/highlightElemOriginalPosition.d.ts +1 -1
- package/dist/field/lexical/plugins/handles/DraggableBlockPlugin/highlightElemOriginalPosition.d.ts.map +1 -1
- package/dist/field/lexical/plugins/handles/DraggableBlockPlugin/highlightElemOriginalPosition.js.map +1 -1
- package/dist/field/lexical/plugins/handles/DraggableBlockPlugin/index.d.ts +2 -2
- package/dist/field/lexical/plugins/handles/DraggableBlockPlugin/index.d.ts.map +1 -1
- package/dist/field/lexical/plugins/handles/DraggableBlockPlugin/index.js +102 -58
- package/dist/field/lexical/plugins/handles/DraggableBlockPlugin/index.js.map +1 -1
- package/dist/field/lexical/plugins/handles/DraggableBlockPlugin/index.scss +12 -3
- package/dist/field/lexical/plugins/handles/DraggableBlockPlugin/setTargetLine.d.ts +8 -1
- package/dist/field/lexical/plugins/handles/DraggableBlockPlugin/setTargetLine.d.ts.map +1 -1
- package/dist/field/lexical/plugins/handles/DraggableBlockPlugin/setTargetLine.js +73 -25
- package/dist/field/lexical/plugins/handles/DraggableBlockPlugin/setTargetLine.js.map +1 -1
- package/dist/field/lexical/plugins/handles/utils/calculateDistanceFromScrollerElem.d.ts +5 -0
- package/dist/field/lexical/plugins/handles/utils/calculateDistanceFromScrollerElem.d.ts.map +1 -0
- package/dist/field/lexical/plugins/handles/utils/calculateDistanceFromScrollerElem.js +21 -0
- package/dist/field/lexical/plugins/handles/utils/calculateDistanceFromScrollerElem.js.map +1 -0
- package/dist/field/lexical/plugins/handles/{DraggableBlockPlugin → utils}/getNodeCloseToPoint.d.ts +4 -0
- package/dist/field/lexical/plugins/handles/utils/getNodeCloseToPoint.d.ts.map +1 -0
- package/dist/field/lexical/plugins/handles/{DraggableBlockPlugin → utils}/getNodeCloseToPoint.js +2 -14
- package/dist/field/lexical/plugins/handles/utils/getNodeCloseToPoint.js.map +1 -0
- package/dist/field/lexical/plugins/handles/utils/setHandlePosition.d.ts.map +1 -1
- package/dist/field/lexical/plugins/handles/utils/setHandlePosition.js +4 -2
- package/dist/field/lexical/plugins/handles/utils/setHandlePosition.js.map +1 -1
- package/dist/field/lexical/theme/EditorTheme.scss +5 -0
- package/dist/field/lexical/ui/ContentEditable.d.ts +1 -1
- package/dist/field/lexical/ui/ContentEditable.d.ts.map +1 -1
- package/dist/field/lexical/ui/ContentEditable.js +2 -1
- package/dist/field/lexical/ui/ContentEditable.js.map +1 -1
- package/dist/field/lexical/ui/ContentEditable.scss +50 -2
- package/dist/field/lexical/ui/icons/AI/index.js +26 -17
- package/dist/field/lexical/ui/icons/AI/index.js.map +1 -1
- package/dist/field/lexical/ui/icons/Add/index.js +14 -9
- package/dist/field/lexical/ui/icons/Add/index.js.map +1 -1
- package/dist/field/lexical/ui/icons/Add/light.svg +4 -0
- package/dist/field/lexical/ui/icons/AlignCenter/index.js +21 -15
- package/dist/field/lexical/ui/icons/AlignCenter/index.js.map +1 -1
- package/dist/field/lexical/ui/icons/AlignJustify/index.js +21 -15
- package/dist/field/lexical/ui/icons/AlignJustify/index.js.map +1 -1
- package/dist/field/lexical/ui/icons/AlignLeft/index.js +21 -15
- package/dist/field/lexical/ui/icons/AlignLeft/index.js.map +1 -1
- package/dist/field/lexical/ui/icons/AlignRight/index.js +21 -15
- package/dist/field/lexical/ui/icons/AlignRight/index.js.map +1 -1
- package/dist/field/lexical/ui/icons/Block/index.js +30 -24
- package/dist/field/lexical/ui/icons/Block/index.js.map +1 -1
- package/dist/field/lexical/ui/icons/Blockquote/index.js +8 -6
- package/dist/field/lexical/ui/icons/Blockquote/index.js.map +1 -1
- package/dist/field/lexical/ui/icons/Bold/index.js +8 -6
- package/dist/field/lexical/ui/icons/Bold/index.js.map +1 -1
- package/dist/field/lexical/ui/icons/Checklist/index.js +19 -14
- package/dist/field/lexical/ui/icons/Checklist/index.js.map +1 -1
- package/dist/field/lexical/ui/icons/Code/index.js +14 -9
- package/dist/field/lexical/ui/icons/Code/index.js.map +1 -1
- package/dist/field/lexical/ui/icons/CodeBlock/index.js +14 -9
- package/dist/field/lexical/ui/icons/CodeBlock/index.js.map +1 -1
- package/dist/field/lexical/ui/icons/DraggableBlock/light.svg +9 -0
- package/dist/field/lexical/ui/icons/H1/index.js +8 -6
- package/dist/field/lexical/ui/icons/H1/index.js.map +1 -1
- package/dist/field/lexical/ui/icons/H2/index.js +8 -6
- package/dist/field/lexical/ui/icons/H2/index.js.map +1 -1
- package/dist/field/lexical/ui/icons/H3/index.js +8 -6
- package/dist/field/lexical/ui/icons/H3/index.js.map +1 -1
- package/dist/field/lexical/ui/icons/H4/index.js +8 -6
- package/dist/field/lexical/ui/icons/H4/index.js.map +1 -1
- package/dist/field/lexical/ui/icons/H5/index.js +8 -6
- package/dist/field/lexical/ui/icons/H5/index.js.map +1 -1
- package/dist/field/lexical/ui/icons/H6/index.js +8 -6
- package/dist/field/lexical/ui/icons/H6/index.js.map +1 -1
- package/dist/field/lexical/ui/icons/HorizontalRule/index.js +11 -9
- package/dist/field/lexical/ui/icons/HorizontalRule/index.js.map +1 -1
- package/dist/field/lexical/ui/icons/IndentDecrease/index.js +25 -18
- package/dist/field/lexical/ui/icons/IndentDecrease/index.js.map +1 -1
- package/dist/field/lexical/ui/icons/IndentIncrease/index.js +25 -18
- package/dist/field/lexical/ui/icons/IndentIncrease/index.js.map +1 -1
- package/dist/field/lexical/ui/icons/Italic/index.js +8 -6
- package/dist/field/lexical/ui/icons/Italic/index.js.map +1 -1
- package/dist/field/lexical/ui/icons/Link/index.js +26 -17
- package/dist/field/lexical/ui/icons/Link/index.js.map +1 -1
- package/dist/field/lexical/ui/icons/OrderedList/index.js +29 -21
- package/dist/field/lexical/ui/icons/OrderedList/index.js.map +1 -1
- package/dist/field/lexical/ui/icons/Relationship/index.js +26 -17
- package/dist/field/lexical/ui/icons/Relationship/index.js.map +1 -1
- package/dist/field/lexical/ui/icons/Strikethrough/index.js +14 -9
- package/dist/field/lexical/ui/icons/Strikethrough/index.js.map +1 -1
- package/dist/field/lexical/ui/icons/Subscript/index.js +8 -6
- package/dist/field/lexical/ui/icons/Subscript/index.js.map +1 -1
- package/dist/field/lexical/ui/icons/Superscript/index.js +8 -6
- package/dist/field/lexical/ui/icons/Superscript/index.js.map +1 -1
- package/dist/field/lexical/ui/icons/Text/index.js +8 -6
- package/dist/field/lexical/ui/icons/Text/index.js.map +1 -1
- package/dist/field/lexical/ui/icons/Underline/index.js +14 -9
- package/dist/field/lexical/ui/icons/Underline/index.js.map +1 -1
- package/dist/field/lexical/ui/icons/UnorderedList/index.js +45 -36
- package/dist/field/lexical/ui/icons/UnorderedList/index.js.map +1 -1
- package/dist/field/lexical/ui/icons/Upload/index.js +24 -18
- package/dist/field/lexical/ui/icons/Upload/index.js.map +1 -1
- package/dist/generateComponentMap.js +8 -8
- package/dist/generateComponentMap.js.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/types.d.ts +7 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/package.json +17 -13
- package/dist/field/lexical/plugins/handles/DraggableBlockPlugin/getNodeCloseToPoint.d.ts.map +0 -1
- package/dist/field/lexical/plugins/handles/DraggableBlockPlugin/getNodeCloseToPoint.js.map +0 -1
|
@@ -1,20 +1,22 @@
|
|
|
1
1
|
'use client';
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
3
|
import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext.js';
|
|
3
4
|
import { eventFiles } from '@lexical/rich-text';
|
|
4
5
|
import { $getNearestNodeFromDOMNode, $getNodeByKey } from 'lexical';
|
|
5
6
|
import * as React from 'react';
|
|
6
|
-
import {
|
|
7
|
+
import { useEffect, useRef, useState } from 'react';
|
|
7
8
|
import { createPortal } from 'react-dom';
|
|
9
|
+
import { useEditorConfigContext } from '../../../config/client/EditorConfigProvider.js';
|
|
8
10
|
import { isHTMLElement } from '../../../utils/guard.js';
|
|
9
11
|
import { Point } from '../../../utils/point.js';
|
|
12
|
+
import { calculateDistanceFromScrollerElem } from '../utils/calculateDistanceFromScrollerElem.js';
|
|
13
|
+
import { getNodeCloseToPoint } from '../utils/getNodeCloseToPoint.js';
|
|
10
14
|
import { getTopLevelNodeKeys } from '../utils/getTopLevelNodeKeys.js';
|
|
11
15
|
import { isOnHandleElement } from '../utils/isOnHandleElement.js';
|
|
12
16
|
import { setHandlePosition } from '../utils/setHandlePosition.js';
|
|
13
17
|
import { getBoundingClientRectWithoutTransform } from './getBoundingRectWithoutTransform.js';
|
|
14
|
-
import { getNodeCloseToPoint } from './getNodeCloseToPoint.js';
|
|
15
18
|
import './index.scss';
|
|
16
19
|
import { setTargetLine } from './setTargetLine.js';
|
|
17
|
-
const SPACE = -24;
|
|
18
20
|
const DRAGGABLE_BLOCK_MENU_CLASSNAME = 'draggable-block-menu';
|
|
19
21
|
const DRAG_DATA_FORMAT = 'application/x-lexical-drag-block';
|
|
20
22
|
let prevIndex = Infinity;
|
|
@@ -41,11 +43,10 @@ function hideTargetLine(targetLineElem, lastTargetBlockElem) {
|
|
|
41
43
|
}
|
|
42
44
|
if (lastTargetBlockElem) {
|
|
43
45
|
lastTargetBlockElem.style.opacity = '';
|
|
44
|
-
lastTargetBlockElem.style.transform = '';
|
|
45
46
|
// Delete marginBottom and marginTop values we set
|
|
46
47
|
lastTargetBlockElem.style.marginBottom = '';
|
|
47
48
|
lastTargetBlockElem.style.marginTop = '';
|
|
48
|
-
//
|
|
49
|
+
//lastTargetBlock.style.border = 'none'
|
|
49
50
|
}
|
|
50
51
|
}
|
|
51
52
|
function useDraggableBlockMenu(editor, anchorElem, isEditable) {
|
|
@@ -55,28 +56,9 @@ function useDraggableBlockMenu(editor, anchorElem, isEditable) {
|
|
|
55
56
|
const debugHighlightRef = useRef(null);
|
|
56
57
|
const isDraggingBlockRef = useRef(false);
|
|
57
58
|
const [draggableBlockElem, setDraggableBlockElem] = useState(null);
|
|
58
|
-
const [
|
|
59
|
-
const
|
|
60
|
-
|
|
61
|
-
// Calculate distance between scrollerElem and target if target is not in scrollerElem
|
|
62
|
-
if (scrollerElem && !scrollerElem.contains(target)) {
|
|
63
|
-
const { bottom, left, right, top } = scrollerElem.getBoundingClientRect();
|
|
64
|
-
const adjustedTop = top + window.scrollY;
|
|
65
|
-
const adjustedBottom = bottom + window.scrollY;
|
|
66
|
-
if (pageY < adjustedTop - verticalBuffer || pageY > adjustedBottom + verticalBuffer || pageX < left - horizontalBuffer || pageX > right + horizontalBuffer) {
|
|
67
|
-
setDraggableBlockElem(null);
|
|
68
|
-
return distanceFromScrollerElem;
|
|
69
|
-
}
|
|
70
|
-
// This is used to allow the _draggableBlockElem to be found when the mouse is in the
|
|
71
|
-
// buffer zone around the scrollerElem.
|
|
72
|
-
if (pageX < left || pageX > right) {
|
|
73
|
-
distanceFromScrollerElem = pageX < left ? pageX - left : pageX - right;
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
return distanceFromScrollerElem;
|
|
77
|
-
}, [
|
|
78
|
-
scrollerElem
|
|
79
|
-
]);
|
|
59
|
+
const [lastTargetBlock, setLastTargetBlock] = useState(null);
|
|
60
|
+
const { editorConfig } = useEditorConfigContext();
|
|
61
|
+
const blockHandleHorizontalOffset = editorConfig?.admin?.hideGutter ? -44 : -8;
|
|
80
62
|
useEffect(()=>{
|
|
81
63
|
/**
|
|
82
64
|
* Handles positioning of the drag handle
|
|
@@ -85,7 +67,11 @@ function useDraggableBlockMenu(editor, anchorElem, isEditable) {
|
|
|
85
67
|
if (!isHTMLElement(target)) {
|
|
86
68
|
return;
|
|
87
69
|
}
|
|
88
|
-
const distanceFromScrollerElem = calculateDistanceFromScrollerElem(event.pageX, event.pageY, target);
|
|
70
|
+
const distanceFromScrollerElem = calculateDistanceFromScrollerElem(scrollerElem, event.pageX, event.pageY, target);
|
|
71
|
+
if (distanceFromScrollerElem === -1) {
|
|
72
|
+
setDraggableBlockElem(null);
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
89
75
|
if (isOnHandleElement(target, DRAGGABLE_BLOCK_MENU_CLASSNAME)) {
|
|
90
76
|
return;
|
|
91
77
|
}
|
|
@@ -97,13 +83,14 @@ function useDraggableBlockMenu(editor, anchorElem, isEditable) {
|
|
|
97
83
|
horizontalOffset: -distanceFromScrollerElem,
|
|
98
84
|
point: new Point(event.x, event.y),
|
|
99
85
|
startIndex: getCurrentIndex(topLevelNodeKeys.length),
|
|
100
|
-
useEdgeAsDefault: false
|
|
86
|
+
useEdgeAsDefault: false,
|
|
87
|
+
verbose: false
|
|
101
88
|
});
|
|
89
|
+
prevIndex = foundAtIndex;
|
|
102
90
|
//if (DEBUG && _draggableBlockElem) {
|
|
103
91
|
//targetBlockElem.style.border = '3px solid red'
|
|
104
92
|
// highlightElemOriginalPosition(debugHighlightRef, _draggableBlockElem, anchorElem)
|
|
105
93
|
//}
|
|
106
|
-
prevIndex = foundAtIndex;
|
|
107
94
|
if (!_draggableBlockElem && !isFoundNodeEmptyParagraph) {
|
|
108
95
|
return;
|
|
109
96
|
}
|
|
@@ -112,7 +99,7 @@ function useDraggableBlockMenu(editor, anchorElem, isEditable) {
|
|
|
112
99
|
}
|
|
113
100
|
}
|
|
114
101
|
// Since the draggableBlockElem is outside the actual editor, we need to listen to the document
|
|
115
|
-
// to be able to detect when the mouse is outside the editor and respect a buffer around
|
|
102
|
+
// to be able to detect when the mouse is outside the editor and respect a buffer around
|
|
116
103
|
// the scrollerElem to avoid the draggableBlockElem disappearing too early.
|
|
117
104
|
document?.addEventListener('mousemove', onDocumentMouseMove);
|
|
118
105
|
return ()=>{
|
|
@@ -122,16 +109,16 @@ function useDraggableBlockMenu(editor, anchorElem, isEditable) {
|
|
|
122
109
|
scrollerElem,
|
|
123
110
|
anchorElem,
|
|
124
111
|
editor,
|
|
125
|
-
calculateDistanceFromScrollerElem,
|
|
126
112
|
draggableBlockElem
|
|
127
113
|
]);
|
|
128
114
|
useEffect(()=>{
|
|
129
115
|
if (menuRef.current) {
|
|
130
|
-
setHandlePosition(draggableBlockElem, menuRef.current, anchorElem,
|
|
116
|
+
setHandlePosition(draggableBlockElem, menuRef.current, anchorElem, blockHandleHorizontalOffset);
|
|
131
117
|
}
|
|
132
118
|
}, [
|
|
133
119
|
anchorElem,
|
|
134
|
-
draggableBlockElem
|
|
120
|
+
draggableBlockElem,
|
|
121
|
+
blockHandleHorizontalOffset
|
|
135
122
|
]);
|
|
136
123
|
useEffect(()=>{
|
|
137
124
|
function onDragover(event) {
|
|
@@ -146,7 +133,7 @@ function useDraggableBlockMenu(editor, anchorElem, isEditable) {
|
|
|
146
133
|
if (!isHTMLElement(target)) {
|
|
147
134
|
return false;
|
|
148
135
|
}
|
|
149
|
-
const distanceFromScrollerElem = calculateDistanceFromScrollerElem(event.pageX, event.pageY, target, 100, 50);
|
|
136
|
+
const distanceFromScrollerElem = calculateDistanceFromScrollerElem(scrollerElem, event.pageX, event.pageY, target, 100, 50);
|
|
150
137
|
const topLevelNodeKeys = getTopLevelNodeKeys(editor);
|
|
151
138
|
const { blockElem: targetBlockElem, foundAtIndex, isFoundNodeEmptyParagraph } = getNodeCloseToPoint({
|
|
152
139
|
anchorElem,
|
|
@@ -165,15 +152,26 @@ function useDraggableBlockMenu(editor, anchorElem, isEditable) {
|
|
|
165
152
|
return false;
|
|
166
153
|
}
|
|
167
154
|
if (draggableBlockElem !== targetBlockElem) {
|
|
168
|
-
setTargetLine(
|
|
155
|
+
const { isBelow, willStayInSamePosition } = setTargetLine(editorConfig?.admin?.hideGutter ? '0px' : '3rem', blockHandleHorizontalOffset + (editorConfig?.admin?.hideGutter ? menuRef?.current?.getBoundingClientRect()?.width ?? 0 : -menuRef?.current?.getBoundingClientRect()?.width ?? 0), targetLineElem, targetBlockElem, lastTargetBlock, pageY, anchorElem, event, debugHighlightRef, isFoundNodeEmptyParagraph);
|
|
169
156
|
// Prevent default event to be able to trigger onDrop events
|
|
170
157
|
// Calling preventDefault() adds the green plus icon to the cursor,
|
|
171
158
|
// indicating that the drop is allowed.
|
|
172
159
|
event.preventDefault();
|
|
160
|
+
if (!willStayInSamePosition) {
|
|
161
|
+
setLastTargetBlock({
|
|
162
|
+
boundingBox: targetBlockElem.getBoundingClientRect(),
|
|
163
|
+
elem: targetBlockElem,
|
|
164
|
+
isBelow
|
|
165
|
+
});
|
|
166
|
+
}
|
|
173
167
|
} else {
|
|
174
|
-
hideTargetLine(targetLineElem,
|
|
168
|
+
hideTargetLine(targetLineElem, lastTargetBlock?.elem);
|
|
169
|
+
setLastTargetBlock({
|
|
170
|
+
boundingBox: targetBlockElem.getBoundingClientRect(),
|
|
171
|
+
elem: targetBlockElem,
|
|
172
|
+
isBelow: false
|
|
173
|
+
});
|
|
175
174
|
}
|
|
176
|
-
setLastTargetBlockElem(targetBlockElem);
|
|
177
175
|
return true;
|
|
178
176
|
}
|
|
179
177
|
function onDrop(event) {
|
|
@@ -194,7 +192,7 @@ function useDraggableBlockMenu(editor, anchorElem, isEditable) {
|
|
|
194
192
|
if (!isHTMLElement(target)) {
|
|
195
193
|
return false;
|
|
196
194
|
}
|
|
197
|
-
const distanceFromScrollerElem = calculateDistanceFromScrollerElem(event.pageX, event.pageY, target, 100, 50);
|
|
195
|
+
const distanceFromScrollerElem = calculateDistanceFromScrollerElem(scrollerElem, event.pageX, event.pageY, target, 100, 50);
|
|
198
196
|
const { blockElem: targetBlockElem, isFoundNodeEmptyParagraph } = getNodeCloseToPoint({
|
|
199
197
|
anchorElem,
|
|
200
198
|
editor,
|
|
@@ -237,6 +235,43 @@ function useDraggableBlockMenu(editor, anchorElem, isEditable) {
|
|
|
237
235
|
}*/ if (draggableBlockElem !== null) {
|
|
238
236
|
setDraggableBlockElem(null);
|
|
239
237
|
}
|
|
238
|
+
// find all previous elements with lexical-block-highlighter class and remove them
|
|
239
|
+
const allPrevHighlighters = document.querySelectorAll('.lexical-block-highlighter');
|
|
240
|
+
allPrevHighlighters.forEach((highlighter)=>{
|
|
241
|
+
highlighter.remove();
|
|
242
|
+
});
|
|
243
|
+
const newInsertedElem = editor.getElementByKey(draggedNode.getKey());
|
|
244
|
+
setTimeout(()=>{
|
|
245
|
+
// add new temp html element to newInsertedElem with the same height and width and the class block-selected
|
|
246
|
+
// to highlight the new inserted element
|
|
247
|
+
const newInsertedElemRect = newInsertedElem.getBoundingClientRect();
|
|
248
|
+
const highlightElem = document.createElement('div');
|
|
249
|
+
highlightElem.className = 'lexical-block-highlighter';
|
|
250
|
+
// if html data-theme is dark, set the highlighter color to white
|
|
251
|
+
if (document.documentElement.getAttribute('data-theme') === 'dark') {
|
|
252
|
+
highlightElem.style.backgroundColor = 'white';
|
|
253
|
+
} else {
|
|
254
|
+
highlightElem.style.backgroundColor = 'black';
|
|
255
|
+
}
|
|
256
|
+
highlightElem.style.transition = 'opacity 0.1s ease-in-out';
|
|
257
|
+
highlightElem.style.zIndex = '1';
|
|
258
|
+
highlightElem.style.pointerEvents = 'none';
|
|
259
|
+
highlightElem.style.boxSizing = 'border-box';
|
|
260
|
+
highlightElem.style.borderRadius = '4px';
|
|
261
|
+
highlightElem.style.position = 'absolute';
|
|
262
|
+
document.body.appendChild(highlightElem);
|
|
263
|
+
highlightElem.style.opacity = '0.1';
|
|
264
|
+
highlightElem.style.height = `${newInsertedElemRect.height + 8}px`;
|
|
265
|
+
highlightElem.style.width = `${newInsertedElemRect.width + 8}px`;
|
|
266
|
+
highlightElem.style.top = `${newInsertedElemRect.top + window.scrollY - 4}px`;
|
|
267
|
+
highlightElem.style.left = `${newInsertedElemRect.left - 4}px`;
|
|
268
|
+
setTimeout(()=>{
|
|
269
|
+
highlightElem.style.opacity = '0';
|
|
270
|
+
setTimeout(()=>{
|
|
271
|
+
highlightElem.remove();
|
|
272
|
+
}, 1000);
|
|
273
|
+
}, 3000);
|
|
274
|
+
}, 120);
|
|
240
275
|
});
|
|
241
276
|
return true;
|
|
242
277
|
}
|
|
@@ -249,11 +284,13 @@ function useDraggableBlockMenu(editor, anchorElem, isEditable) {
|
|
|
249
284
|
document.removeEventListener('drop', onDrop);
|
|
250
285
|
};
|
|
251
286
|
}, [
|
|
287
|
+
scrollerElem,
|
|
288
|
+
blockHandleHorizontalOffset,
|
|
252
289
|
anchorElem,
|
|
253
290
|
editor,
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
291
|
+
lastTargetBlock,
|
|
292
|
+
draggableBlockElem,
|
|
293
|
+
editorConfig?.admin?.hideGutter
|
|
257
294
|
]);
|
|
258
295
|
function onDragStart(event) {
|
|
259
296
|
const dataTransfer = event.dataTransfer;
|
|
@@ -273,23 +310,30 @@ function useDraggableBlockMenu(editor, anchorElem, isEditable) {
|
|
|
273
310
|
}
|
|
274
311
|
function onDragEnd() {
|
|
275
312
|
isDraggingBlockRef.current = false;
|
|
276
|
-
hideTargetLine(targetLineRef.current,
|
|
313
|
+
hideTargetLine(targetLineRef.current, lastTargetBlock?.elem);
|
|
277
314
|
}
|
|
278
|
-
return /*#__PURE__*/ createPortal(/*#__PURE__*/
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
315
|
+
return /*#__PURE__*/ createPortal(/*#__PURE__*/ _jsxs(React.Fragment, {
|
|
316
|
+
children: [
|
|
317
|
+
/*#__PURE__*/ _jsx("div", {
|
|
318
|
+
className: "icon draggable-block-menu",
|
|
319
|
+
draggable: true,
|
|
320
|
+
onDragEnd: onDragEnd,
|
|
321
|
+
onDragStart: onDragStart,
|
|
322
|
+
ref: menuRef,
|
|
323
|
+
children: /*#__PURE__*/ _jsx("div", {
|
|
324
|
+
className: isEditable ? 'icon' : ''
|
|
325
|
+
})
|
|
326
|
+
}),
|
|
327
|
+
/*#__PURE__*/ _jsx("div", {
|
|
328
|
+
className: "draggable-block-target-line",
|
|
329
|
+
ref: targetLineRef
|
|
330
|
+
}),
|
|
331
|
+
/*#__PURE__*/ _jsx("div", {
|
|
332
|
+
className: "debug-highlight",
|
|
333
|
+
ref: debugHighlightRef
|
|
334
|
+
})
|
|
335
|
+
]
|
|
336
|
+
}), anchorElem);
|
|
293
337
|
}
|
|
294
338
|
export function DraggableBlockPlugin({ anchorElem = document.body }) {
|
|
295
339
|
const [editor] = useLexicalComposerContext();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../src/field/lexical/plugins/handles/DraggableBlockPlugin/index.tsx"],"sourcesContent":["'use client'\nimport type { LexicalEditor } from 'lexical'\nimport type { DragEvent as ReactDragEvent } from 'react'\n\nimport { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext.js'\nimport { eventFiles } from '@lexical/rich-text'\nimport { $getNearestNodeFromDOMNode, $getNodeByKey } from 'lexical'\nimport * as React from 'react'\nimport { useCallback, useEffect, useRef, useState } from 'react'\nimport { createPortal } from 'react-dom'\n\nimport { isHTMLElement } from '../../../utils/guard.js'\nimport { Point } from '../../../utils/point.js'\nimport { getTopLevelNodeKeys } from '../utils/getTopLevelNodeKeys.js'\nimport { isOnHandleElement } from '../utils/isOnHandleElement.js'\nimport { setHandlePosition } from '../utils/setHandlePosition.js'\nimport { getBoundingClientRectWithoutTransform } from './getBoundingRectWithoutTransform.js'\nimport { getNodeCloseToPoint } from './getNodeCloseToPoint.js'\nimport './index.scss'\nimport { setTargetLine } from './setTargetLine.js'\n\nconst SPACE = -24\nconst DRAGGABLE_BLOCK_MENU_CLASSNAME = 'draggable-block-menu'\nconst DRAG_DATA_FORMAT = 'application/x-lexical-drag-block'\n\nlet prevIndex = Infinity\n\nfunction getCurrentIndex(keysLength: number): number {\n if (keysLength === 0) {\n return Infinity\n }\n if (prevIndex >= 0 && prevIndex < keysLength) {\n return prevIndex\n }\n\n return Math.floor(keysLength / 2)\n}\n\nfunction setDragImage(dataTransfer: DataTransfer, draggableBlockElem: HTMLElement) {\n const { transform } = draggableBlockElem.style\n\n // Remove dragImage borders\n dataTransfer.setDragImage(draggableBlockElem, 0, 0)\n\n setTimeout(() => {\n draggableBlockElem.style.transform = transform\n })\n}\n\nfunction hideTargetLine(\n targetLineElem: HTMLElement | null,\n lastTargetBlockElem: HTMLElement | null,\n) {\n if (targetLineElem) {\n targetLineElem.style.opacity = '0'\n }\n if (lastTargetBlockElem) {\n lastTargetBlockElem.style.opacity = ''\n lastTargetBlockElem.style.transform = ''\n // Delete marginBottom and marginTop values we set\n lastTargetBlockElem.style.marginBottom = ''\n lastTargetBlockElem.style.marginTop = ''\n //lastTargetBlockElem.style.border = 'none'\n }\n}\n\nfunction useDraggableBlockMenu(\n editor: LexicalEditor,\n anchorElem: HTMLElement,\n isEditable: boolean,\n): JSX.Element {\n const scrollerElem = anchorElem.parentElement\n\n const menuRef = useRef<HTMLDivElement>(null)\n const targetLineRef = useRef<HTMLDivElement>(null)\n const debugHighlightRef = useRef<HTMLDivElement>(null)\n const isDraggingBlockRef = useRef<boolean>(false)\n const [draggableBlockElem, setDraggableBlockElem] = useState<HTMLElement | null>(null)\n const [lastTargetBlockElem, setLastTargetBlockElem] = useState<HTMLElement | null>(null)\n\n const calculateDistanceFromScrollerElem = useCallback(\n (\n pageX: number,\n pageY: number,\n target: HTMLElement,\n horizontalBuffer: number = 50,\n verticalBuffer: number = 25,\n ): number => {\n let distanceFromScrollerElem = 0\n // Calculate distance between scrollerElem and target if target is not in scrollerElem\n if (scrollerElem && !scrollerElem.contains(target)) {\n const { bottom, left, right, top } = scrollerElem.getBoundingClientRect()\n\n const adjustedTop = top + window.scrollY\n const adjustedBottom = bottom + window.scrollY\n\n if (\n pageY < adjustedTop - verticalBuffer ||\n pageY > adjustedBottom + verticalBuffer ||\n pageX < left - horizontalBuffer ||\n pageX > right + horizontalBuffer\n ) {\n setDraggableBlockElem(null)\n return distanceFromScrollerElem\n }\n\n // This is used to allow the _draggableBlockElem to be found when the mouse is in the\n // buffer zone around the scrollerElem.\n if (pageX < left || pageX > right) {\n distanceFromScrollerElem = pageX < left ? pageX - left : pageX - right\n }\n }\n return distanceFromScrollerElem\n },\n [scrollerElem],\n )\n\n useEffect(() => {\n /**\n * Handles positioning of the drag handle\n */\n function onDocumentMouseMove(event: MouseEvent) {\n const target = event.target\n if (!isHTMLElement(target)) {\n return\n }\n\n const distanceFromScrollerElem = calculateDistanceFromScrollerElem(\n event.pageX,\n event.pageY,\n target,\n )\n\n if (isOnHandleElement(target, DRAGGABLE_BLOCK_MENU_CLASSNAME)) {\n return\n }\n\n const topLevelNodeKeys = getTopLevelNodeKeys(editor)\n const {\n blockElem: _draggableBlockElem,\n foundAtIndex,\n isFoundNodeEmptyParagraph,\n } = getNodeCloseToPoint({\n anchorElem,\n cache_threshold: 0,\n editor,\n horizontalOffset: -distanceFromScrollerElem,\n point: new Point(event.x, event.y),\n startIndex: getCurrentIndex(topLevelNodeKeys.length),\n useEdgeAsDefault: false,\n })\n //if (DEBUG && _draggableBlockElem) {\n //targetBlockElem.style.border = '3px solid red'\n // highlightElemOriginalPosition(debugHighlightRef, _draggableBlockElem, anchorElem)\n //}\n prevIndex = foundAtIndex\n\n if (!_draggableBlockElem && !isFoundNodeEmptyParagraph) {\n return\n }\n\n if (draggableBlockElem !== _draggableBlockElem) {\n setDraggableBlockElem(_draggableBlockElem)\n }\n }\n\n // Since the draggableBlockElem is outside the actual editor, we need to listen to the document\n // to be able to detect when the mouse is outside the editor and respect a buffer around the\n // the scrollerElem to avoid the draggableBlockElem disappearing too early.\n document?.addEventListener('mousemove', onDocumentMouseMove)\n\n return () => {\n document?.removeEventListener('mousemove', onDocumentMouseMove)\n }\n }, [scrollerElem, anchorElem, editor, calculateDistanceFromScrollerElem, draggableBlockElem])\n\n useEffect(() => {\n if (menuRef.current) {\n setHandlePosition(draggableBlockElem, menuRef.current, anchorElem, SPACE)\n }\n }, [anchorElem, draggableBlockElem])\n\n useEffect(() => {\n function onDragover(event: DragEvent): boolean {\n if (!isDraggingBlockRef.current) {\n return false\n }\n const [isFileTransfer] = eventFiles(event)\n if (isFileTransfer) {\n return false\n }\n\n const { pageY, target } = event\n if (!isHTMLElement(target)) {\n return false\n }\n\n const distanceFromScrollerElem = calculateDistanceFromScrollerElem(\n event.pageX,\n event.pageY,\n target,\n 100,\n 50,\n )\n\n const topLevelNodeKeys = getTopLevelNodeKeys(editor)\n\n const {\n blockElem: targetBlockElem,\n foundAtIndex,\n isFoundNodeEmptyParagraph,\n } = getNodeCloseToPoint({\n anchorElem,\n editor,\n fuzzy: true,\n horizontalOffset: -distanceFromScrollerElem,\n point: new Point(event.x, event.y),\n startIndex: getCurrentIndex(topLevelNodeKeys.length),\n useEdgeAsDefault: true,\n verbose: true,\n })\n prevIndex = foundAtIndex\n\n const targetLineElem = targetLineRef.current\n // targetBlockElem === null shouldn't happen\n if (targetBlockElem === null || targetLineElem === null) {\n return false\n }\n\n if (draggableBlockElem !== targetBlockElem) {\n setTargetLine(\n SPACE,\n targetLineElem,\n targetBlockElem,\n lastTargetBlockElem,\n pageY,\n anchorElem,\n event,\n debugHighlightRef,\n isFoundNodeEmptyParagraph,\n )\n\n // Prevent default event to be able to trigger onDrop events\n // Calling preventDefault() adds the green plus icon to the cursor,\n // indicating that the drop is allowed.\n event.preventDefault()\n } else {\n hideTargetLine(targetLineElem, lastTargetBlockElem)\n }\n\n setLastTargetBlockElem(targetBlockElem)\n\n return true\n }\n\n function onDrop(event: DragEvent): boolean {\n if (!isDraggingBlockRef.current) {\n return false\n }\n const [isFileTransfer] = eventFiles(event)\n if (isFileTransfer) {\n return false\n }\n const { dataTransfer, pageY, target } = event\n const dragData = dataTransfer?.getData(DRAG_DATA_FORMAT) || ''\n\n editor.update(() => {\n const draggedNode = $getNodeByKey(dragData)\n if (!draggedNode) {\n return false\n }\n if (!isHTMLElement(target)) {\n return false\n }\n const distanceFromScrollerElem = calculateDistanceFromScrollerElem(\n event.pageX,\n event.pageY,\n target,\n 100,\n 50,\n )\n\n const { blockElem: targetBlockElem, isFoundNodeEmptyParagraph } = getNodeCloseToPoint({\n anchorElem,\n editor,\n fuzzy: true,\n horizontalOffset: -distanceFromScrollerElem,\n point: new Point(event.x, event.y),\n useEdgeAsDefault: true,\n })\n\n if (!targetBlockElem) {\n return false\n }\n const targetNode = $getNearestNodeFromDOMNode(targetBlockElem)\n if (!targetNode) {\n return false\n }\n if (targetNode === draggedNode) {\n return true\n }\n\n const { height: targetBlockElemHeight, top: targetBlockElemTop } =\n getBoundingClientRectWithoutTransform(targetBlockElem)\n\n const mouseY = pageY\n const isBelow = mouseY >= targetBlockElemTop + targetBlockElemHeight / 2 + window.scrollY\n\n if (!isFoundNodeEmptyParagraph) {\n if (isBelow) {\n // below targetBlockElem\n targetNode.insertAfter(draggedNode)\n } else {\n // above targetBlockElem\n targetNode.insertBefore(draggedNode)\n }\n } else {\n //\n targetNode.insertBefore(draggedNode)\n targetNode.remove()\n }\n\n /*\n if (pageY >= targetBlockElemTop + targetBlockElemHeight / 2) {\n targetNode.insertAfter(draggedNode)\n } else {\n targetNode.insertBefore(draggedNode)\n }*/\n if (draggableBlockElem !== null) {\n setDraggableBlockElem(null)\n }\n })\n\n return true\n }\n\n // register onDragover event listeners:\n document.addEventListener('dragover', onDragover)\n // register onDrop event listeners:\n document.addEventListener('drop', onDrop)\n\n return () => {\n document.removeEventListener('dragover', onDragover)\n document.removeEventListener('drop', onDrop)\n }\n }, [\n anchorElem,\n editor,\n lastTargetBlockElem,\n calculateDistanceFromScrollerElem,\n draggableBlockElem,\n ])\n\n function onDragStart(event: ReactDragEvent<HTMLDivElement>): void {\n const dataTransfer = event.dataTransfer\n if (!dataTransfer || !draggableBlockElem) {\n return\n }\n setDragImage(dataTransfer, draggableBlockElem)\n let nodeKey = ''\n editor.update(() => {\n const node = $getNearestNodeFromDOMNode(draggableBlockElem)\n if (node) {\n nodeKey = node.getKey()\n }\n })\n isDraggingBlockRef.current = true\n dataTransfer.setData(DRAG_DATA_FORMAT, nodeKey)\n }\n\n function onDragEnd(): void {\n isDraggingBlockRef.current = false\n hideTargetLine(targetLineRef.current, lastTargetBlockElem)\n }\n\n return createPortal(\n <React.Fragment>\n <div\n className=\"icon draggable-block-menu\"\n draggable\n onDragEnd={onDragEnd}\n onDragStart={onDragStart}\n ref={menuRef}\n >\n <div className={isEditable ? 'icon' : ''} />\n </div>\n <div className=\"draggable-block-target-line\" ref={targetLineRef} />\n <div className=\"debug-highlight\" ref={debugHighlightRef} />\n </React.Fragment>,\n anchorElem,\n )\n}\n\nexport function DraggableBlockPlugin({\n anchorElem = document.body,\n}: {\n anchorElem?: HTMLElement\n}): JSX.Element {\n const [editor] = useLexicalComposerContext()\n return useDraggableBlockMenu(editor, anchorElem, editor._editable)\n}\n"],"names":["useLexicalComposerContext","eventFiles","$getNearestNodeFromDOMNode","$getNodeByKey","React","useCallback","useEffect","useRef","useState","createPortal","isHTMLElement","Point","getTopLevelNodeKeys","isOnHandleElement","setHandlePosition","getBoundingClientRectWithoutTransform","getNodeCloseToPoint","setTargetLine","SPACE","DRAGGABLE_BLOCK_MENU_CLASSNAME","DRAG_DATA_FORMAT","prevIndex","Infinity","getCurrentIndex","keysLength","Math","floor","setDragImage","dataTransfer","draggableBlockElem","transform","style","setTimeout","hideTargetLine","targetLineElem","lastTargetBlockElem","opacity","marginBottom","marginTop","useDraggableBlockMenu","editor","anchorElem","isEditable","scrollerElem","parentElement","menuRef","targetLineRef","debugHighlightRef","isDraggingBlockRef","setDraggableBlockElem","setLastTargetBlockElem","calculateDistanceFromScrollerElem","pageX","pageY","target","horizontalBuffer","verticalBuffer","distanceFromScrollerElem","contains","bottom","left","right","top","getBoundingClientRect","adjustedTop","window","scrollY","adjustedBottom","onDocumentMouseMove","event","topLevelNodeKeys","blockElem","_draggableBlockElem","foundAtIndex","isFoundNodeEmptyParagraph","cache_threshold","horizontalOffset","point","x","y","startIndex","length","useEdgeAsDefault","document","addEventListener","removeEventListener","current","onDragover","isFileTransfer","targetBlockElem","fuzzy","verbose","preventDefault","onDrop","dragData","getData","update","draggedNode","targetNode","height","targetBlockElemHeight","targetBlockElemTop","mouseY","isBelow","insertAfter","insertBefore","remove","onDragStart","nodeKey","node","getKey","setData","onDragEnd","Fragment","div","className","draggable","ref","DraggableBlockPlugin","body","_editable"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA;AAIA,SAASA,yBAAyB,QAAQ,2CAA0C;AACpF,SAASC,UAAU,QAAQ,qBAAoB;AAC/C,SAASC,0BAA0B,EAAEC,aAAa,QAAQ,UAAS;AACnE,YAAYC,WAAW,QAAO;AAC9B,SAASC,WAAW,EAAEC,SA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IAAI,CAACA,gBAAgB,CAACC,oBAAoB;YACxC;QACF;QACAF,aAAaC,cAAcC;QAC3B,IAAI+E,UAAU;QACdpE,OAAOwD,MAAM,CAAC;YACZ,MAAMa,OAAO3G,2BAA2B2B;YACxC,IAAIgF,MAAM;gBACRD,UAAUC,KAAKC,MAAM;YACvB;QACF;QACA9D,mBAAmBsC,OAAO,GAAG;QAC7B1D,aAAamF,OAAO,CAAC3F,kBAAkBwF;IACzC;IAEA,SAASI;QACPhE,mBAAmBsC,OAAO,GAAG;QAC7BrD,eAAea,cAAcwC,OAAO,EAAEnD;IACxC;IAEA,qBAAO1B,2BACL,oBAACL,MAAM6G,QAAQ,sBACb,oBAACC;QACCC,WAAU;QACVC,WAAAA;QACAJ,WAAWA;QACXL,aAAaA;QACbU,KAAKxE;qBAEL,oBAACqE;QAAIC,WAAWzE,aAAa,SAAS;uBAExC,oBAACwE;QAAIC,WAAU;QAA8BE,KAAKvE;sBAClD,oBAACoE;QAAIC,WAAU;QAAkBE,KAAKtE;SAExCN;AAEJ;AAEA,OAAO,SAAS6E,qBAAqB,EACnC7E,aAAa0C,SAASoC,IAAI,EAG3B;IACC,MAAM,CAAC/E,OAAO,GAAGxC;IACjB,OAAOuC,sBAAsBC,QAAQC,YAAYD,OAAOgF,SAAS;AACnE"}
|
|
1
|
+
{"version":3,"sources":["../../../../../../src/field/lexical/plugins/handles/DraggableBlockPlugin/index.tsx"],"sourcesContent":["'use client'\nimport type { LexicalEditor } from 'lexical'\nimport type { JSX, DragEvent as ReactDragEvent } from 'react'\n\nimport { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext.js'\nimport { eventFiles } from '@lexical/rich-text'\nimport { $getNearestNodeFromDOMNode, $getNodeByKey } from 'lexical'\nimport * as React from 'react'\nimport { useEffect, useRef, useState } from 'react'\nimport { createPortal } from 'react-dom'\n\nimport { useEditorConfigContext } from '../../../config/client/EditorConfigProvider.js'\nimport { isHTMLElement } from '../../../utils/guard.js'\nimport { Point } from '../../../utils/point.js'\nimport { calculateDistanceFromScrollerElem } from '../utils/calculateDistanceFromScrollerElem.js'\nimport { getNodeCloseToPoint } from '../utils/getNodeCloseToPoint.js'\nimport { getTopLevelNodeKeys } from '../utils/getTopLevelNodeKeys.js'\nimport { isOnHandleElement } from '../utils/isOnHandleElement.js'\nimport { setHandlePosition } from '../utils/setHandlePosition.js'\nimport { getBoundingClientRectWithoutTransform } from './getBoundingRectWithoutTransform.js'\nimport './index.scss'\nimport { setTargetLine } from './setTargetLine.js'\n\nconst DRAGGABLE_BLOCK_MENU_CLASSNAME = 'draggable-block-menu'\nconst DRAG_DATA_FORMAT = 'application/x-lexical-drag-block'\n\nlet prevIndex = Infinity\n\nfunction getCurrentIndex(keysLength: number): number {\n if (keysLength === 0) {\n return Infinity\n }\n if (prevIndex >= 0 && prevIndex < keysLength) {\n return prevIndex\n }\n\n return Math.floor(keysLength / 2)\n}\n\nfunction setDragImage(dataTransfer: DataTransfer, draggableBlockElem: HTMLElement) {\n const { transform } = draggableBlockElem.style\n\n // Remove dragImage borders\n dataTransfer.setDragImage(draggableBlockElem, 0, 0)\n\n setTimeout(() => {\n draggableBlockElem.style.transform = transform\n })\n}\n\nfunction hideTargetLine(\n targetLineElem: HTMLElement | null,\n lastTargetBlockElem: HTMLElement | null,\n) {\n if (targetLineElem) {\n targetLineElem.style.opacity = '0'\n }\n if (lastTargetBlockElem) {\n lastTargetBlockElem.style.opacity = ''\n // Delete marginBottom and marginTop values we set\n lastTargetBlockElem.style.marginBottom = ''\n lastTargetBlockElem.style.marginTop = ''\n //lastTargetBlock.style.border = 'none'\n }\n}\n\nfunction useDraggableBlockMenu(\n editor: LexicalEditor,\n anchorElem: HTMLElement,\n isEditable: boolean,\n): React.ReactElement {\n const scrollerElem = anchorElem.parentElement\n\n const menuRef = useRef<HTMLDivElement>(null)\n const targetLineRef = useRef<HTMLDivElement>(null)\n const debugHighlightRef = useRef<HTMLDivElement>(null)\n const isDraggingBlockRef = useRef<boolean>(false)\n const [draggableBlockElem, setDraggableBlockElem] = useState<HTMLElement | null>(null)\n const [lastTargetBlock, setLastTargetBlock] = useState<{\n boundingBox?: DOMRect\n elem: HTMLElement | null\n isBelow: boolean\n }>(null)\n\n const { editorConfig } = useEditorConfigContext()\n\n const blockHandleHorizontalOffset = editorConfig?.admin?.hideGutter ? -44 : -8\n\n useEffect(() => {\n /**\n * Handles positioning of the drag handle\n */\n function onDocumentMouseMove(event: MouseEvent) {\n const target = event.target\n if (!isHTMLElement(target)) {\n return\n }\n\n const distanceFromScrollerElem = calculateDistanceFromScrollerElem(\n scrollerElem,\n event.pageX,\n event.pageY,\n target,\n )\n if (distanceFromScrollerElem === -1) {\n setDraggableBlockElem(null)\n return\n }\n\n if (isOnHandleElement(target, DRAGGABLE_BLOCK_MENU_CLASSNAME)) {\n return\n }\n\n const topLevelNodeKeys = getTopLevelNodeKeys(editor)\n\n const {\n blockElem: _draggableBlockElem,\n foundAtIndex,\n isFoundNodeEmptyParagraph,\n } = getNodeCloseToPoint({\n anchorElem,\n cache_threshold: 0,\n editor,\n horizontalOffset: -distanceFromScrollerElem,\n point: new Point(event.x, event.y),\n startIndex: getCurrentIndex(topLevelNodeKeys.length),\n useEdgeAsDefault: false,\n verbose: false,\n })\n\n prevIndex = foundAtIndex\n\n //if (DEBUG && _draggableBlockElem) {\n //targetBlockElem.style.border = '3px solid red'\n // highlightElemOriginalPosition(debugHighlightRef, _draggableBlockElem, anchorElem)\n //}\n\n if (!_draggableBlockElem && !isFoundNodeEmptyParagraph) {\n return\n }\n\n if (draggableBlockElem !== _draggableBlockElem) {\n setDraggableBlockElem(_draggableBlockElem)\n }\n }\n\n // Since the draggableBlockElem is outside the actual editor, we need to listen to the document\n // to be able to detect when the mouse is outside the editor and respect a buffer around\n // the scrollerElem to avoid the draggableBlockElem disappearing too early.\n document?.addEventListener('mousemove', onDocumentMouseMove)\n\n return () => {\n document?.removeEventListener('mousemove', onDocumentMouseMove)\n }\n }, [scrollerElem, anchorElem, editor, draggableBlockElem])\n\n useEffect(() => {\n if (menuRef.current) {\n setHandlePosition(\n draggableBlockElem,\n menuRef.current,\n anchorElem,\n blockHandleHorizontalOffset,\n )\n }\n }, [anchorElem, draggableBlockElem, blockHandleHorizontalOffset])\n\n useEffect(() => {\n function onDragover(event: DragEvent): boolean {\n if (!isDraggingBlockRef.current) {\n return false\n }\n const [isFileTransfer] = eventFiles(event)\n if (isFileTransfer) {\n return false\n }\n\n const { pageY, target } = event\n if (!isHTMLElement(target)) {\n return false\n }\n\n const distanceFromScrollerElem = calculateDistanceFromScrollerElem(\n scrollerElem,\n event.pageX,\n event.pageY,\n target,\n 100,\n 50,\n )\n\n const topLevelNodeKeys = getTopLevelNodeKeys(editor)\n\n const {\n blockElem: targetBlockElem,\n foundAtIndex,\n isFoundNodeEmptyParagraph,\n } = getNodeCloseToPoint({\n anchorElem,\n editor,\n fuzzy: true,\n horizontalOffset: -distanceFromScrollerElem,\n point: new Point(event.x, event.y),\n startIndex: getCurrentIndex(topLevelNodeKeys.length),\n useEdgeAsDefault: true,\n verbose: true,\n })\n\n prevIndex = foundAtIndex\n\n const targetLineElem = targetLineRef.current\n // targetBlockElem === null shouldn't happen\n if (targetBlockElem === null || targetLineElem === null) {\n return false\n }\n\n if (draggableBlockElem !== targetBlockElem) {\n const { isBelow, willStayInSamePosition } = setTargetLine(\n editorConfig?.admin?.hideGutter ? '0px' : '3rem',\n blockHandleHorizontalOffset +\n (editorConfig?.admin?.hideGutter\n ? menuRef?.current?.getBoundingClientRect()?.width ?? 0\n : -menuRef?.current?.getBoundingClientRect()?.width ?? 0),\n targetLineElem,\n targetBlockElem,\n lastTargetBlock,\n pageY,\n anchorElem,\n event,\n debugHighlightRef,\n isFoundNodeEmptyParagraph,\n )\n\n // Prevent default event to be able to trigger onDrop events\n // Calling preventDefault() adds the green plus icon to the cursor,\n // indicating that the drop is allowed.\n event.preventDefault()\n\n if (!willStayInSamePosition) {\n setLastTargetBlock({\n boundingBox: targetBlockElem.getBoundingClientRect(),\n elem: targetBlockElem,\n isBelow,\n })\n }\n } else {\n hideTargetLine(targetLineElem, lastTargetBlock?.elem)\n setLastTargetBlock({\n boundingBox: targetBlockElem.getBoundingClientRect(),\n elem: targetBlockElem,\n isBelow: false,\n })\n }\n\n return true\n }\n\n function onDrop(event: DragEvent): boolean {\n if (!isDraggingBlockRef.current) {\n return false\n }\n const [isFileTransfer] = eventFiles(event)\n if (isFileTransfer) {\n return false\n }\n const { dataTransfer, pageY, target } = event\n const dragData = dataTransfer?.getData(DRAG_DATA_FORMAT) || ''\n\n editor.update(() => {\n const draggedNode = $getNodeByKey(dragData)\n if (!draggedNode) {\n return false\n }\n if (!isHTMLElement(target)) {\n return false\n }\n const distanceFromScrollerElem = calculateDistanceFromScrollerElem(\n scrollerElem,\n event.pageX,\n event.pageY,\n target,\n 100,\n 50,\n )\n\n const { blockElem: targetBlockElem, isFoundNodeEmptyParagraph } = getNodeCloseToPoint({\n anchorElem,\n editor,\n fuzzy: true,\n horizontalOffset: -distanceFromScrollerElem,\n point: new Point(event.x, event.y),\n useEdgeAsDefault: true,\n })\n\n if (!targetBlockElem) {\n return false\n }\n const targetNode = $getNearestNodeFromDOMNode(targetBlockElem)\n if (!targetNode) {\n return false\n }\n if (targetNode === draggedNode) {\n return true\n }\n\n const { height: targetBlockElemHeight, top: targetBlockElemTop } =\n getBoundingClientRectWithoutTransform(targetBlockElem)\n\n const mouseY = pageY\n const isBelow = mouseY >= targetBlockElemTop + targetBlockElemHeight / 2 + window.scrollY\n\n if (!isFoundNodeEmptyParagraph) {\n if (isBelow) {\n // below targetBlockElem\n targetNode.insertAfter(draggedNode)\n } else {\n // above targetBlockElem\n targetNode.insertBefore(draggedNode)\n }\n } else {\n //\n targetNode.insertBefore(draggedNode)\n targetNode.remove()\n }\n\n /*\n if (pageY >= targetBlockElemTop + targetBlockElemHeight / 2) {\n targetNode.insertAfter(draggedNode)\n } else {\n targetNode.insertBefore(draggedNode)\n }*/\n if (draggableBlockElem !== null) {\n setDraggableBlockElem(null)\n }\n\n // find all previous elements with lexical-block-highlighter class and remove them\n const allPrevHighlighters = document.querySelectorAll('.lexical-block-highlighter')\n allPrevHighlighters.forEach((highlighter) => {\n highlighter.remove()\n })\n\n const newInsertedElem = editor.getElementByKey(draggedNode.getKey())\n setTimeout(() => {\n // add new temp html element to newInsertedElem with the same height and width and the class block-selected\n // to highlight the new inserted element\n const newInsertedElemRect = newInsertedElem.getBoundingClientRect()\n\n const highlightElem = document.createElement('div')\n highlightElem.className = 'lexical-block-highlighter'\n\n // if html data-theme is dark, set the highlighter color to white\n if (document.documentElement.getAttribute('data-theme') === 'dark') {\n highlightElem.style.backgroundColor = 'white'\n } else {\n highlightElem.style.backgroundColor = 'black'\n }\n\n highlightElem.style.transition = 'opacity 0.1s ease-in-out'\n highlightElem.style.zIndex = '1'\n highlightElem.style.pointerEvents = 'none'\n highlightElem.style.boxSizing = 'border-box'\n highlightElem.style.borderRadius = '4px'\n highlightElem.style.position = 'absolute'\n document.body.appendChild(highlightElem)\n\n highlightElem.style.opacity = '0.1'\n\n highlightElem.style.height = `${newInsertedElemRect.height + 8}px`\n highlightElem.style.width = `${newInsertedElemRect.width + 8}px`\n highlightElem.style.top = `${newInsertedElemRect.top + window.scrollY - 4}px`\n highlightElem.style.left = `${newInsertedElemRect.left - 4}px`\n\n setTimeout(() => {\n highlightElem.style.opacity = '0'\n setTimeout(() => {\n highlightElem.remove()\n }, 1000)\n }, 3000)\n }, 120)\n })\n\n return true\n }\n\n // register onDragover event listeners:\n document.addEventListener('dragover', onDragover)\n // register onDrop event listeners:\n document.addEventListener('drop', onDrop)\n\n return () => {\n document.removeEventListener('dragover', onDragover)\n document.removeEventListener('drop', onDrop)\n }\n }, [\n scrollerElem,\n blockHandleHorizontalOffset,\n anchorElem,\n editor,\n lastTargetBlock,\n draggableBlockElem,\n editorConfig?.admin?.hideGutter,\n ])\n\n function onDragStart(event: ReactDragEvent<HTMLDivElement>): void {\n const dataTransfer = event.dataTransfer\n if (!dataTransfer || !draggableBlockElem) {\n return\n }\n setDragImage(dataTransfer, draggableBlockElem)\n let nodeKey = ''\n editor.update(() => {\n const node = $getNearestNodeFromDOMNode(draggableBlockElem)\n if (node) {\n nodeKey = node.getKey()\n }\n })\n isDraggingBlockRef.current = true\n dataTransfer.setData(DRAG_DATA_FORMAT, nodeKey)\n }\n\n function onDragEnd(): void {\n isDraggingBlockRef.current = false\n hideTargetLine(targetLineRef.current, lastTargetBlock?.elem)\n }\n\n return createPortal(\n <React.Fragment>\n <div\n className=\"icon draggable-block-menu\"\n draggable\n onDragEnd={onDragEnd}\n onDragStart={onDragStart}\n ref={menuRef}\n >\n <div className={isEditable ? 'icon' : ''} />\n </div>\n <div className=\"draggable-block-target-line\" ref={targetLineRef} />\n <div className=\"debug-highlight\" ref={debugHighlightRef} />\n </React.Fragment>,\n anchorElem,\n )\n}\n\nexport function DraggableBlockPlugin({\n anchorElem = document.body,\n}: {\n anchorElem?: HTMLElement\n}): React.ReactElement {\n const [editor] = useLexicalComposerContext()\n return useDraggableBlockMenu(editor, anchorElem, editor._editable)\n}\n"],"names":["useLexicalComposerContext","eventFiles","$getNearestNodeFromDOMNode","$getNodeByKey","React","useEffect","useRef","useState","createPortal","useEditorConfigContext","isHTMLElement","Point","calculateDistanceFromScrollerElem","getNodeCloseToPoint","getTopLevelNodeKeys","isOnHandleElement","setHandlePosition","getBoundingClientRectWithoutTransform","setTargetLine","DRAGGABLE_BLOCK_MENU_CLASSNAME","DRAG_DATA_FORMAT","prevIndex","Infinity","getCurrentIndex","keysLength","Math","floor","setDragImage","dataTransfer","draggableBlockElem","transform","style","setTimeout","hideTargetLine","targetLineElem","lastTargetBlockElem","opacity","marginBottom","marginTop","useDraggableBlockMenu","editor","anchorElem","isEditable","scrollerElem","parentElement","menuRef","targetLineRef","debugHighlightRef","isDraggingBlockRef","setDraggableBlockElem","lastTargetBlock","setLastTargetBlock","editorConfig","blockHandleHorizontalOffset","admin","hideGutter","onDocumentMouseMove","event","target","distanceFromScrollerElem","pageX","pageY","topLevelNodeKeys","blockElem","_draggableBlockElem","foundAtIndex","isFoundNodeEmptyParagraph","cache_threshold","horizontalOffset","point","x","y","startIndex","length","useEdgeAsDefault","verbose","document","addEventListener","removeEventListener","current","onDragover","isFileTransfer","targetBlockElem","fuzzy","isBelow","willStayInSamePosition","getBoundingClientRect","width","preventDefault","boundingBox","elem","onDrop","dragData","getData","update","draggedNode","targetNode","height","targetBlockElemHeight","top","targetBlockElemTop","mouseY","window","scrollY","insertAfter","insertBefore","remove","allPrevHighlighters","querySelectorAll","forEach","highlighter","newInsertedElem","getElementByKey","getKey","newInsertedElemRect","highlightElem","createElement","className","documentElement","getAttribute","backgroundColor","transition","zIndex","pointerEvents","boxSizing","borderRadius","position","body","appendChild","left","onDragStart","nodeKey","node","setData","onDragEnd","Fragment","div","draggable","ref","DraggableBlockPlugin","_editable"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA;;AAIA,SAASA,yBAAyB,QAAQ,2CAA0C;AACpF,SAASC,UAAU,QAAQ,qBAAoB;AAC/C,SAASC,0BAA0B,EAAEC,aAAa,QAAQ,UAAS;AACnE,YAAYC,WAAW,QAAO;AAC9B,SAASC,SAAS,EAAEC,MAAM,EAAEC,QAAQ,QAAQ,QAAO;AACnD,SAASC,YAAY,QAAQ,YAAW;AAExC,SAASC,s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B,eAAe6B,MAAM7B,YAAY;QACvC,IAAI,CAACA,gBAAgB,CAACC,oBAAoB;YACxC;QACF;QACAF,aAAaC,cAAcC;QAC3B,IAAIsG,UAAU;QACd3F,OAAOsD,MAAM,CAAC;YACZ,MAAMsC,OAAOlI,2BAA2B2B;YACxC,IAAIuG,MAAM;gBACRD,UAAUC,KAAKnB,MAAM;YACvB;QACF;QACAjE,mBAAmB+B,OAAO,GAAG;QAC7BnD,aAAayG,OAAO,CAACjH,kBAAkB+G;IACzC;IAEA,SAASG;QACPtF,mBAAmB+B,OAAO,GAAG;QAC7B9C,eAAea,cAAciC,OAAO,EAAE7B,iBAAiBwC;IACzD;IAEA,qBAAOlF,2BACL,MAACJ,MAAMmI,QAAQ;;0BACb,KAACC;gBACCnB,WAAU;gBACVoB,SAAS;gBACTH,WAAWA;gBACXJ,aAAaA;gBACbQ,KAAK7F;0BAEL,cAAA,KAAC2F;oBAAInB,WAAW3E,aAAa,SAAS;;;0BAExC,KAAC8F;gBAAInB,WAAU;gBAA8BqB,KAAK5F;;0BAClD,KAAC0F;gBAAInB,WAAU;gBAAkBqB,KAAK3F;;;QAExCN;AAEJ;AAEA,OAAO,SAASkG,qBAAqB,EACnClG,aAAamC,SAASmD,IAAI,EAG3B;IACC,MAAM,CAACvF,OAAO,GAAGxC;IACjB,OAAOuC,sBAAsBC,QAAQC,YAAYD,OAAOoG,SAAS;AACnE"}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
@import '../../../../../scss/styles.scss';
|
|
2
|
+
|
|
1
3
|
.draggable-block-menu {
|
|
2
4
|
border-radius: 4px;
|
|
3
5
|
padding: 0;
|
|
@@ -7,13 +9,14 @@
|
|
|
7
9
|
left: 0;
|
|
8
10
|
top: 0;
|
|
9
11
|
will-change: transform;
|
|
12
|
+
background-color: var(--theme-bg);
|
|
10
13
|
|
|
11
14
|
&:active {
|
|
12
15
|
cursor: grabbing;
|
|
13
16
|
}
|
|
14
17
|
|
|
15
18
|
&:hover {
|
|
16
|
-
background:
|
|
19
|
+
background-color: var(--theme-elevation-100);
|
|
17
20
|
.icon {
|
|
18
21
|
opacity: 1;
|
|
19
22
|
}
|
|
@@ -28,15 +31,21 @@
|
|
|
28
31
|
|
|
29
32
|
html[data-theme='dark'] & {
|
|
30
33
|
.icon {
|
|
31
|
-
|
|
34
|
+
background-image: url(../../../ui/icons/DraggableBlock/light.svg);
|
|
32
35
|
}
|
|
33
36
|
}
|
|
34
37
|
}
|
|
35
38
|
|
|
39
|
+
.rich-text-lexical--show-gutter > .rich-text-lexical__wrap > .editor-container > .editor-scroller > .editor {
|
|
40
|
+
> .draggable-block-target-line {
|
|
41
|
+
left: 3rem;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
36
45
|
.draggable-block-target-line {
|
|
37
46
|
pointer-events: none;
|
|
38
47
|
background: var(--theme-elevation-200);
|
|
39
|
-
border: 1px solid var(--theme-elevation-650);
|
|
48
|
+
//border: 1px solid var(--theme-elevation-650);
|
|
40
49
|
border-radius: 4px;
|
|
41
50
|
height: 50px;
|
|
42
51
|
position: absolute;
|
|
@@ -1,3 +1,10 @@
|
|
|
1
1
|
/// <reference types="react" resolution-mode="require"/>
|
|
2
|
-
export declare function setTargetLine(
|
|
2
|
+
export declare function setTargetLine(offsetWidth: string, offsetLeft: number, targetLineElem: HTMLElement, targetBlockElem: HTMLElement, lastTargetBlock: {
|
|
3
|
+
boundingBox?: DOMRect;
|
|
4
|
+
elem: HTMLElement | null;
|
|
5
|
+
isBelow: boolean;
|
|
6
|
+
}, mouseY: number, anchorElem: HTMLElement, event: DragEvent, debugHighlightRef: React.RefObject<HTMLDivElement | null>, isFoundNodeEmptyParagraph?: boolean): {
|
|
7
|
+
isBelow: boolean;
|
|
8
|
+
willStayInSamePosition: boolean;
|
|
9
|
+
};
|
|
3
10
|
//# sourceMappingURL=setTargetLine.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"setTargetLine.d.ts","sourceRoot":"","sources":["../../../../../../src/field/lexical/plugins/handles/DraggableBlockPlugin/setTargetLine.ts"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"setTargetLine.d.ts","sourceRoot":"","sources":["../../../../../../src/field/lexical/plugins/handles/DraggableBlockPlugin/setTargetLine.ts"],"names":[],"mappings":";AASA,wBAAgB,aAAa,CAC3B,WAAW,EAAE,MAAM,EACnB,UAAU,EAAE,MAAM,EAClB,cAAc,EAAE,WAAW,EAC3B,eAAe,EAAE,WAAW,EAC5B,eAAe,EAAE;IACf,WAAW,CAAC,EAAE,OAAO,CAAA;IACrB,IAAI,EAAE,WAAW,GAAG,IAAI,CAAA;IACxB,OAAO,EAAE,OAAO,CAAA;CACjB,EACD,MAAM,EAAE,MAAM,EACd,UAAU,EAAE,WAAW,EACvB,KAAK,EAAE,SAAS,EAChB,iBAAiB,EAAE,KAAK,CAAC,SAAS,CAAC,cAAc,GAAG,IAAI,CAAC,EACzD,yBAAyB,GAAE,OAAe;;;EA4I3C"}
|
|
@@ -1,16 +1,54 @@
|
|
|
1
1
|
import { getCollapsedMargins } from '../utils/getCollapsedMargins.js';
|
|
2
|
-
import { getBoundingClientRectWithoutTransform } from './getBoundingRectWithoutTransform.js';
|
|
3
2
|
import { highlightElemOriginalPosition } from './highlightElemOriginalPosition.js';
|
|
4
3
|
const TARGET_LINE_HALF_HEIGHT = 25;
|
|
5
4
|
const TEXT_BOX_HORIZONTAL_PADDING = -24;
|
|
6
5
|
const DEBUG = false;
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
let animationTimer = 0;
|
|
7
|
+
export function setTargetLine(offsetWidth, offsetLeft, targetLineElem, targetBlockElem, lastTargetBlock, mouseY, anchorElem, event, debugHighlightRef, isFoundNodeEmptyParagraph = false) {
|
|
8
|
+
const { height: targetBlockElemHeight, top: targetBlockElemTop } = targetBlockElem.getBoundingClientRect() // used to be getBoundingClientRectWithoutTransform. Not sure what's better, but the normal getBoundingClientRect seems to work fine
|
|
9
|
+
;
|
|
9
10
|
const { top: anchorTop, width: anchorWidth } = anchorElem.getBoundingClientRect();
|
|
10
11
|
const { marginBottom, marginTop } = getCollapsedMargins(targetBlockElem);
|
|
11
12
|
let lineTop = targetBlockElemTop;
|
|
12
13
|
const isBelow = mouseY >= targetBlockElemTop + targetBlockElemHeight / 2 + window.scrollY;
|
|
13
|
-
|
|
14
|
+
let willStayInSamePosition = false;
|
|
15
|
+
/**
|
|
16
|
+
* Do not run any transform or changes if the actual new line position would be the same (even if it's now inserted BEFORE rather than AFTER - position would still be the same)
|
|
17
|
+
* This prevents unnecessary flickering.
|
|
18
|
+
*
|
|
19
|
+
* We still need to let it run even if the position (IGNORING the transform) would not change, as the transform animation is not finished yet. This is what animationTimer does. Otherwise, the positioning will be inaccurate
|
|
20
|
+
*/ if (lastTargetBlock?.elem) {
|
|
21
|
+
if (targetBlockElem !== lastTargetBlock?.elem) {
|
|
22
|
+
if (isBelow && lastTargetBlock?.elem && lastTargetBlock?.elem === targetBlockElem.nextElementSibling) {
|
|
23
|
+
animationTimer++;
|
|
24
|
+
if (animationTimer < 200) {
|
|
25
|
+
willStayInSamePosition = true;
|
|
26
|
+
}
|
|
27
|
+
} else if (!isBelow && lastTargetBlock?.elem && lastTargetBlock?.elem === targetBlockElem.previousElementSibling) {
|
|
28
|
+
animationTimer++;
|
|
29
|
+
if (animationTimer < 200) {
|
|
30
|
+
willStayInSamePosition = true;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
} else {
|
|
34
|
+
animationTimer++;
|
|
35
|
+
const lastBoundingBoxPosition = lastTargetBlock?.boundingBox?.y;
|
|
36
|
+
const currentBoundingBoxPosition = targetBlockElem.getBoundingClientRect().y;
|
|
37
|
+
if (isBelow === lastTargetBlock?.isBelow && lastBoundingBoxPosition === currentBoundingBoxPosition || animationTimer < 200) {
|
|
38
|
+
willStayInSamePosition = false;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
if (willStayInSamePosition) {
|
|
43
|
+
return {
|
|
44
|
+
isBelow,
|
|
45
|
+
willStayInSamePosition
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Paragraphs need no isBelow/above handling,
|
|
50
|
+
*/ if (!isFoundNodeEmptyParagraph) {
|
|
51
|
+
//if (!isFoundNodeEmptyParagraph) {
|
|
14
52
|
if (isBelow) {
|
|
15
53
|
// below targetBlockElem
|
|
16
54
|
lineTop += targetBlockElemHeight + marginBottom / 2;
|
|
@@ -21,7 +59,6 @@ export function setTargetLine(SPACE, targetLineElem, targetBlockElem, lastTarget
|
|
|
21
59
|
} else {
|
|
22
60
|
lineTop += targetBlockElemHeight / 2;
|
|
23
61
|
}
|
|
24
|
-
const targetElemTranslate = 0;
|
|
25
62
|
let targetElemTranslate2 = 0;
|
|
26
63
|
if (!isFoundNodeEmptyParagraph) {
|
|
27
64
|
if (isBelow) {
|
|
@@ -30,39 +67,50 @@ export function setTargetLine(SPACE, targetLineElem, targetBlockElem, lastTarget
|
|
|
30
67
|
targetElemTranslate2 = TARGET_LINE_HALF_HEIGHT;
|
|
31
68
|
}
|
|
32
69
|
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
}
|
|
37
|
-
const left = TEXT_BOX_HORIZONTAL_PADDING - SPACE;
|
|
38
|
-
targetLineElem.style.transform = `translate(${left}px, ${top}px)`;
|
|
39
|
-
targetLineElem.style.width = `${anchorWidth - (TEXT_BOX_HORIZONTAL_PADDING - SPACE) * 2}px`;
|
|
70
|
+
const top = lineTop - anchorTop + targetElemTranslate2;
|
|
71
|
+
const left = TEXT_BOX_HORIZONTAL_PADDING - offsetLeft;
|
|
72
|
+
targetLineElem.style.width = `calc(${anchorWidth}px - ${offsetWidth})`;
|
|
40
73
|
targetLineElem.style.opacity = '.4';
|
|
41
74
|
/**
|
|
42
|
-
* Move around element below or above the line (= the target / targetBlockElem)
|
|
75
|
+
* Move around element below or above the line (= the target / targetBlockElem). Creates "space" for the targetLineElem
|
|
76
|
+
*
|
|
77
|
+
* Not needed for empty paragraphs, as an empty paragraph is enough space for the targetLineElem anyways.
|
|
43
78
|
*/ //targetBlockElem.style.opacity = '0.4'
|
|
79
|
+
const buffer = 12 // creates more spacing/padding so target line is not directly next to the targetBlockElem
|
|
80
|
+
;
|
|
44
81
|
if (!isFoundNodeEmptyParagraph) {
|
|
45
|
-
// move lastTargetBlockElem down 50px to make space for targetLineElem (which is 50px height)
|
|
46
|
-
targetBlockElem.style.transform = `translate(0, ${targetElemTranslate}px)`;
|
|
47
82
|
if (isBelow) {
|
|
48
|
-
|
|
49
|
-
|
|
83
|
+
targetBlockElem.style.marginBottom = TARGET_LINE_HALF_HEIGHT * 2 + buffer + 'px';
|
|
84
|
+
targetLineElem.style.transform = `translate(${left}px, calc(${top}px - ${'0px'}))`;
|
|
50
85
|
} else {
|
|
51
|
-
targetBlockElem.style.marginTop = TARGET_LINE_HALF_HEIGHT * 2 + 'px';
|
|
86
|
+
targetBlockElem.style.marginTop = TARGET_LINE_HALF_HEIGHT * 2 + buffer + 'px';
|
|
87
|
+
targetLineElem.style.transform = `translate(${left}px, calc(${top - TARGET_LINE_HALF_HEIGHT * 2}px - ${'0px'}))`;
|
|
52
88
|
}
|
|
89
|
+
} else {
|
|
90
|
+
targetLineElem.style.transform = `translate(${left}px, ${top - TARGET_LINE_HALF_HEIGHT}px)`;
|
|
53
91
|
}
|
|
54
92
|
if (DEBUG) {
|
|
55
93
|
//targetBlockElem.style.border = '3px solid red'
|
|
56
94
|
highlightElemOriginalPosition(debugHighlightRef, targetBlockElem, anchorElem);
|
|
57
95
|
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
96
|
+
/**
|
|
97
|
+
* Properly reset previous targetBlockElem styles
|
|
98
|
+
*/ lastTargetBlock.elem.style.opacity = '';
|
|
99
|
+
if (lastTargetBlock?.elem === targetBlockElem) {
|
|
100
|
+
if (isBelow) {
|
|
101
|
+
lastTargetBlock.elem.style.marginTop = '';
|
|
102
|
+
} else {
|
|
103
|
+
lastTargetBlock.elem.style.marginBottom = '';
|
|
104
|
+
}
|
|
105
|
+
} else {
|
|
106
|
+
lastTargetBlock.elem.style.marginBottom = '';
|
|
107
|
+
lastTargetBlock.elem.style.marginTop = '';
|
|
65
108
|
}
|
|
109
|
+
animationTimer = 0;
|
|
110
|
+
return {
|
|
111
|
+
isBelow,
|
|
112
|
+
willStayInSamePosition
|
|
113
|
+
};
|
|
66
114
|
}
|
|
67
115
|
|
|
68
116
|
//# sourceMappingURL=setTargetLine.js.map
|