@tiptap/extension-drag-handle 3.23.5 → 3.24.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +36 -13
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +17 -1
- package/dist/index.d.ts +17 -1
- package/dist/index.js +36 -13
- package/dist/index.js.map +1 -1
- package/package.json +25 -26
- package/src/drag-handle-plugin.ts +17 -2
- package/src/drag-handle.ts +21 -1
- package/src/helpers/cloneElement.ts +16 -5
- package/src/helpers/dragHandler.ts +2 -1
- package/src/helpers/findNextElementFromCursor.ts +10 -2
- package/src/helpers/getDraggedBlockDir.ts +3 -1
- package/src/helpers/getInnerCoords.ts +10 -2
- package/src/helpers/normalizeOptions.ts +3 -1
|
@@ -1,7 +1,15 @@
|
|
|
1
|
-
function getCSSText(element: Element) {
|
|
2
|
-
let value = ''
|
|
1
|
+
function getCSSText(element: Element, properties?: string[]) {
|
|
3
2
|
const style = getComputedStyle(element)
|
|
4
3
|
|
|
4
|
+
if (properties) {
|
|
5
|
+
return properties
|
|
6
|
+
.filter(p => p.trim().length > 0)
|
|
7
|
+
.map(p => `${p}:${style.getPropertyValue(p)};`)
|
|
8
|
+
.join('')
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
let value = ''
|
|
12
|
+
|
|
5
13
|
for (let i = 0; i < style.length; i += 1) {
|
|
6
14
|
value += `${style[i]}:${style.getPropertyValue(style[i])};`
|
|
7
15
|
}
|
|
@@ -9,13 +17,16 @@ function getCSSText(element: Element) {
|
|
|
9
17
|
return value
|
|
10
18
|
}
|
|
11
19
|
|
|
12
|
-
export function cloneElement(node: HTMLElement) {
|
|
20
|
+
export function cloneElement(node: HTMLElement, properties?: string[]) {
|
|
13
21
|
const clonedNode = node.cloneNode(true) as HTMLElement
|
|
14
22
|
const sourceElements = [node, ...Array.from(node.getElementsByTagName('*'))] as HTMLElement[]
|
|
15
|
-
const targetElements = [
|
|
23
|
+
const targetElements = [
|
|
24
|
+
clonedNode,
|
|
25
|
+
...Array.from(clonedNode.getElementsByTagName('*')),
|
|
26
|
+
] as HTMLElement[]
|
|
16
27
|
|
|
17
28
|
sourceElements.forEach((sourceElement, index) => {
|
|
18
|
-
targetElements[index].style.cssText = getCSSText(sourceElement)
|
|
29
|
+
targetElements[index].style.cssText = getCSSText(sourceElement, properties)
|
|
19
30
|
})
|
|
20
31
|
|
|
21
32
|
return clonedNode
|
|
@@ -68,6 +68,7 @@ export function dragHandler(
|
|
|
68
68
|
editor: Editor,
|
|
69
69
|
nestedOptions?: NormalizedNestedOptions,
|
|
70
70
|
dragContext?: DragContext,
|
|
71
|
+
dragImageProperties?: string[],
|
|
71
72
|
) {
|
|
72
73
|
const { view } = editor
|
|
73
74
|
|
|
@@ -126,7 +127,7 @@ export function dragHandler(
|
|
|
126
127
|
return
|
|
127
128
|
}
|
|
128
129
|
|
|
129
|
-
const clonedElement = cloneElement(element)
|
|
130
|
+
const clonedElement = cloneElement(element, dragImageProperties)
|
|
130
131
|
|
|
131
132
|
clonedElement.style.margin = '0'
|
|
132
133
|
|
|
@@ -16,7 +16,10 @@ export type FindElementNextToCoords = {
|
|
|
16
16
|
/**
|
|
17
17
|
* Finds the draggable block element that is a direct child of view.dom
|
|
18
18
|
*/
|
|
19
|
-
export function findClosestTopLevelBlock(
|
|
19
|
+
export function findClosestTopLevelBlock(
|
|
20
|
+
element: Element,
|
|
21
|
+
view: EditorView,
|
|
22
|
+
): HTMLElement | undefined {
|
|
20
23
|
let current: Element | null = element
|
|
21
24
|
|
|
22
25
|
while (current?.parentElement && current.parentElement !== view.dom) {
|
|
@@ -43,7 +46,12 @@ function isValidRect(rect: DOMRect): boolean {
|
|
|
43
46
|
/**
|
|
44
47
|
* Clamps coordinates to content bounds with O(1) layout reads
|
|
45
48
|
*/
|
|
46
|
-
function clampToContent(
|
|
49
|
+
function clampToContent(
|
|
50
|
+
view: EditorView,
|
|
51
|
+
x: number,
|
|
52
|
+
y: number,
|
|
53
|
+
inset = 5,
|
|
54
|
+
): { x: number; y: number } | null {
|
|
47
55
|
// Validate input coordinates are finite numbers
|
|
48
56
|
if (!Number.isFinite(x) || !Number.isFinite(y)) {
|
|
49
57
|
return null
|
|
@@ -38,7 +38,9 @@ export function getDraggedBlockElement(view: EditorView, pos: number): Element |
|
|
|
38
38
|
export function getDraggedBlockDir(view: EditorView, pos: number): string {
|
|
39
39
|
const draggedDom = getDraggedBlockElement(view, pos)
|
|
40
40
|
|
|
41
|
-
const contentDir = draggedDom
|
|
41
|
+
const contentDir = draggedDom
|
|
42
|
+
? getComputedStyle(draggedDom).direction
|
|
43
|
+
: getComputedStyle(view.dom).direction
|
|
42
44
|
|
|
43
45
|
return contentDir || 'ltr'
|
|
44
46
|
}
|
|
@@ -3,14 +3,22 @@ import type { EditorView } from '@tiptap/pm/view'
|
|
|
3
3
|
import { getComputedStyle } from './getComputedStyle.js'
|
|
4
4
|
import { minMax } from './minMax.js'
|
|
5
5
|
|
|
6
|
-
export function getInnerCoords(
|
|
6
|
+
export function getInnerCoords(
|
|
7
|
+
view: EditorView,
|
|
8
|
+
x: number,
|
|
9
|
+
y: number,
|
|
10
|
+
): { left: number; top: number } {
|
|
7
11
|
const paddingLeft = parseInt(getComputedStyle(view.dom, 'paddingLeft'), 10)
|
|
8
12
|
const paddingRight = parseInt(getComputedStyle(view.dom, 'paddingRight'), 10)
|
|
9
13
|
const borderLeft = parseInt(getComputedStyle(view.dom, 'borderLeftWidth'), 10)
|
|
10
14
|
const borderRight = parseInt(getComputedStyle(view.dom, 'borderLeftWidth'), 10)
|
|
11
15
|
const bounds = view.dom.getBoundingClientRect()
|
|
12
16
|
const coords = {
|
|
13
|
-
left: minMax(
|
|
17
|
+
left: minMax(
|
|
18
|
+
x,
|
|
19
|
+
bounds.left + paddingLeft + borderLeft,
|
|
20
|
+
bounds.right - paddingRight - borderRight,
|
|
21
|
+
),
|
|
14
22
|
top: y,
|
|
15
23
|
}
|
|
16
24
|
|
|
@@ -17,7 +17,9 @@ import { normalizeEdgeDetection } from './edgeDetection.js'
|
|
|
17
17
|
* normalizeNestedOptions({ rules: [myRule], edgeDetection: 'none' })
|
|
18
18
|
* // Returns: { enabled: true, rules: [myRule], edgeDetection: { edges: [], ... } }
|
|
19
19
|
*/
|
|
20
|
-
export function normalizeNestedOptions(
|
|
20
|
+
export function normalizeNestedOptions(
|
|
21
|
+
input: boolean | NestedOptions | undefined,
|
|
22
|
+
): NormalizedNestedOptions {
|
|
21
23
|
if (input === false || input === undefined) {
|
|
22
24
|
return {
|
|
23
25
|
enabled: false,
|