@nookuio/iframe 1.0.1-beta.0 → 1.0.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.
Files changed (46) hide show
  1. package/dist/constants.d.ts +0 -9
  2. package/dist/constants.js +2 -11
  3. package/dist/constants.mjs +1 -9
  4. package/dist/editor.js +41 -35
  5. package/dist/editor.mjs +42 -36
  6. package/dist/iframe.d.ts +1 -1
  7. package/dist/iframe.js +141 -126
  8. package/dist/iframe.mjs +150 -134
  9. package/dist/types.d.ts +7 -17
  10. package/package.json +2 -2
  11. package/dist/drag-drop/dragEnd.d.ts +0 -2
  12. package/dist/drag-drop/dragEnd.js +0 -27
  13. package/dist/drag-drop/dragEnd.mjs +0 -23
  14. package/dist/drag-drop/dragMove.d.ts +0 -2
  15. package/dist/drag-drop/dragMove.js +0 -46
  16. package/dist/drag-drop/dragMove.mjs +0 -40
  17. package/dist/drag-drop/dragReorder.d.ts +0 -3
  18. package/dist/drag-drop/dragReorder.js +0 -60
  19. package/dist/drag-drop/dragReorder.mjs +0 -64
  20. package/dist/drag-drop/dragStart.d.ts +0 -9
  21. package/dist/drag-drop/dragStart.js +0 -60
  22. package/dist/drag-drop/dragStart.mjs +0 -55
  23. package/dist/drag-drop/helpers.d.ts +0 -42
  24. package/dist/drag-drop/helpers.js +0 -205
  25. package/dist/drag-drop/helpers.mjs +0 -188
  26. package/dist/drag-drop/highlight.d.ts +0 -16
  27. package/dist/drag-drop/highlight.js +0 -32
  28. package/dist/drag-drop/highlight.mjs +0 -22
  29. package/dist/drag-drop/index.d.ts +0 -24
  30. package/dist/drag-drop/index.js +0 -106
  31. package/dist/drag-drop/index.mjs +0 -83
  32. package/dist/drag-drop/types.d.ts +0 -123
  33. package/dist/drag-drop/types.js +0 -1
  34. package/dist/drag-drop/types.mjs +0 -0
  35. package/dist/drag-drop backup/dragDropManager.d.ts +0 -101
  36. package/dist/drag-drop backup/dragDropManager.js +0 -204
  37. package/dist/drag-drop backup/dragDropManager.mjs +0 -183
  38. package/dist/drag-drop backup/index.d.ts +0 -3
  39. package/dist/drag-drop backup/index.js +0 -38
  40. package/dist/drag-drop backup/index.mjs +0 -3
  41. package/dist/drag-drop backup/types.d.ts +0 -80
  42. package/dist/drag-drop backup/types.js +0 -1
  43. package/dist/drag-drop backup/types.mjs +0 -0
  44. package/dist/drag-drop backup/utils.d.ts +0 -41
  45. package/dist/drag-drop backup/utils.js +0 -93
  46. package/dist/drag-drop backup/utils.mjs +0 -68
@@ -1,22 +0,0 @@
1
- let e = null;
2
- export function setDropHighlight(t, r, o) {
3
- if (e?.remove(), !t || !r)
4
- return;
5
- e = document.createElement("div"), e.classList.add("__drop-area");
6
- const { top: p, left: s } = r.getBoundingClientRect();
7
- e.style.setProperty("position", "fixed"), e.style.setProperty("--drop-area-left", `${t.offsetLeft + s}px`), e.style.setProperty("--drop-area-top", `${t.offsetTop + p}px`), e.style.setProperty("--drop-area-width", `${t.offsetWidth}px`), e.style.setProperty("--drop-area-height", `${t.offsetHeight}px`), e.style.setProperty("--drop-area-outline-color", `#${o}`), e.style.setProperty("--drop-area-border-radius", window.getComputedStyle(t).borderRadius), e.style.setProperty("--dashed-line-color", `color-mix(in srgb, #${o} 33%, transparent)`), document.body.append(e);
8
- }
9
- export function setExternalDropHighlight({
10
- layout: t,
11
- center: r,
12
- length: o,
13
- color: p,
14
- projectionPoint: s
15
- }) {
16
- e?.remove(), e = document.createElement("div"), e.classList.add("__drop-area-line"), e.style.setProperty("--drop-area-left", `${r.x}px`), e.style.setProperty("--drop-area-top", `${r.y}px`), t === "block" ? (e.style.setProperty("--drop-area-width", `${o}px`), e.style.setProperty("--drop-area-height", "4px"), e.style.setProperty("--drop-area-translate", "-50% -2px")) : (e.style.setProperty("--drop-area-width", "4px"), e.style.setProperty("--drop-area-height", `${o}px`), e.style.setProperty("--drop-area-translate", "-2px -50%"));
17
- const a = `radial-gradient(circle at ${s * 100}% ${s * 100}%, #${p} 0%, #${p}55 max(100%, 75px))`;
18
- e.style.setProperty("--drop-area-background", a), document.body.appendChild(e);
19
- }
20
- export function removeDropHighlight() {
21
- e?.remove(), e = null;
22
- }
@@ -1,24 +0,0 @@
1
- export declare const DRAG_MOVE_CLASSNAME = "__drag-mode--move";
2
- export declare const DRAG_REORDER_CLASSNAME = "__drag-mode--reorder";
3
- export interface DragDropContext {
4
- startDrag: (options: {
5
- elementId: string;
6
- path: string;
7
- x: number;
8
- y: number;
9
- altKey: boolean;
10
- }) => void;
11
- dragMove: (options: {
12
- x: number;
13
- y: number;
14
- metaKey: boolean;
15
- }) => void;
16
- endDrag: (options: {
17
- canceled?: boolean;
18
- }) => Promise<{
19
- copy: boolean;
20
- parent: string;
21
- index?: number;
22
- } | void>;
23
- }
24
- export declare function createDragDropContext(): DragDropContext;
@@ -1,106 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.DRAG_REORDER_CLASSNAME = exports.DRAG_MOVE_CLASSNAME = void 0;
7
- exports.createDragDropContext = createDragDropContext;
8
- var _constants = require("../constants");
9
- var _dragEnd = require("./dragEnd");
10
- var _dragMove = require("./dragMove");
11
- var _dragReorder = require("./dragReorder");
12
- var _dragStart = require("./dragStart");
13
- var _helpers = require("./helpers");
14
- const DRAG_MOVE_CLASSNAME = exports.DRAG_MOVE_CLASSNAME = "__drag-mode--move",
15
- DRAG_REORDER_CLASSNAME = exports.DRAG_REORDER_CLASSNAME = "__drag-mode--reorder";
16
- class u {
17
- state = null;
18
- startDrag({
19
- elementId: t,
20
- altKey: e,
21
- path: i,
22
- x: r,
23
- y: s
24
- }) {
25
- const n = (0, _helpers.getDOMNodeFromNodeId)(i, t);
26
- if (!n || !n.parentElement) return;
27
- const o = Array.from(n.parentElement.children).filter(a => a instanceof HTMLElement && a.getAttribute(_constants.ATTRIBUTES.id) === t && a.getAttribute(_constants.ATTRIBUTES.path) === i).slice(1);
28
- if (this.state = (0, _dragStart.dragStarted)({
29
- element: n,
30
- lastCursorPosition: {
31
- x: r,
32
- y: s
33
- },
34
- repeatedNodes: o,
35
- asCopy: e
36
- }), e) {
37
- const a = this.state.element.getBoundingClientRect();
38
- this.state.offset.x += a.left - this.state.initialRect.left, this.state.offset.y += a.top - this.state.initialRect.top;
39
- }
40
- }
41
- async endDrag({
42
- canceled: t
43
- }) {
44
- switch (this.state?.mode) {
45
- case "reorder":
46
- const e = this.state?.initialContainer.getAttribute(_constants.ATTRIBUTES.id);
47
- if (!e) return;
48
- const i = this.state?.element.nextElementSibling,
49
- r = parseInt(_constants.ATTRIBUTES.id);
50
- if (this.state?.element?.getBoundingClientRect() && !t && (i !== this.state?.initialNextSibling || this.state?.copy)) {
51
- await (0, _dragEnd.dragEnded)(this.state, !1);
52
- const o = {
53
- copy: !!this.state?.copy,
54
- parent: e,
55
- index: isNaN(r) ? void 0 : r
56
- };
57
- return this.state = null, o;
58
- } else await (0, _dragEnd.dragEnded)(this.state, !0), this.state = null;
59
- break;
60
- case "insert":
61
- const n = this.state?.insertAreas?.[this.state?.selectedInsertAreaIndex ?? -1];
62
- if (n && !t) {
63
- await (0, _dragEnd.dragEnded)(this.state, !1);
64
- const o = n?.parent.getAttribute(_constants.ATTRIBUTES.id);
65
- if (!o) return;
66
- const a = {
67
- copy: !!this.state?.copy,
68
- parent: o,
69
- index: n?.index
70
- };
71
- return this.state = null, a;
72
- } else await (0, _dragEnd.dragEnded)(this.state, !0), this.state = null;
73
- break;
74
- }
75
- }
76
- dragMove({
77
- x: t,
78
- y: e,
79
- metaKey: i
80
- }) {
81
- if (this.state && !this.state.destroying) {
82
- this.state.lastCursorPosition = {
83
- x: t,
84
- y: e
85
- };
86
- const r = (0, _helpers.rectHasPoint)(this.state.initialContainer.getBoundingClientRect(), {
87
- x: t,
88
- y: e
89
- }),
90
- s = this.state.element.getBoundingClientRect();
91
- (0, _helpers.rectHasPoint)(s, {
92
- x: t,
93
- y: e
94
- }) || (this.state.offset.x -= (t - (s.left + s.width / 2)) * .1, this.state.offset.y -= (e - (s.top + s.height / 2)) * .1), r && !i ? (0, _dragReorder.dragReorder)(this.state) : (0, _dragMove.dragMove)(this.state, i ? [this.state.element] : [this.state.element, this.state.initialContainer]), this.state.element.style.setProperty("translate", `${t - this.state.offset.x}px ${e - this.state.offset.y}px`);
95
- return;
96
- }
97
- }
98
- }
99
- function createDragDropContext() {
100
- const d = new u();
101
- return {
102
- startDrag: (...t) => d.startDrag(...t),
103
- dragMove: (...t) => d.dragMove(...t),
104
- endDrag: (...t) => d.endDrag(...t)
105
- };
106
- }
@@ -1,83 +0,0 @@
1
- import { ATTRIBUTES as l } from "../constants.mjs";
2
- import { dragEnded as g } from "./dragEnd.mjs";
3
- import { dragMove as c } from "./dragMove.mjs";
4
- import { dragReorder as h } from "./dragReorder.mjs";
5
- import { dragStarted as p } from "./dragStart.mjs";
6
- import { getDOMNodeFromNodeId as f, rectHasPoint as m } from "./helpers.mjs";
7
- export const DRAG_MOVE_CLASSNAME = "__drag-mode--move", DRAG_REORDER_CLASSNAME = "__drag-mode--reorder";
8
- class u {
9
- state = null;
10
- startDrag({
11
- elementId: t,
12
- altKey: e,
13
- path: i,
14
- x: r,
15
- y: s
16
- }) {
17
- const n = f(i, t);
18
- if (!n || !n.parentElement)
19
- return;
20
- const o = Array.from(n.parentElement.children).filter(
21
- (a) => a instanceof HTMLElement && a.getAttribute(l.id) === t && a.getAttribute(l.path) === i
22
- ).slice(1);
23
- if (this.state = p({
24
- element: n,
25
- lastCursorPosition: { x: r, y: s },
26
- repeatedNodes: o,
27
- asCopy: e
28
- }), e) {
29
- const a = this.state.element.getBoundingClientRect();
30
- this.state.offset.x += a.left - this.state.initialRect.left, this.state.offset.y += a.top - this.state.initialRect.top;
31
- }
32
- }
33
- async endDrag({ canceled: t }) {
34
- switch (this.state?.mode) {
35
- case "reorder":
36
- const e = this.state?.initialContainer.getAttribute(l.id);
37
- if (!e) return;
38
- const i = this.state?.element.nextElementSibling, r = parseInt(l.id);
39
- if (this.state?.element?.getBoundingClientRect() && !t && (i !== this.state?.initialNextSibling || this.state?.copy)) {
40
- await g(this.state, !1);
41
- const o = {
42
- copy: !!this.state?.copy,
43
- parent: e,
44
- index: isNaN(r) ? void 0 : r
45
- };
46
- return this.state = null, o;
47
- } else
48
- await g(this.state, !0), this.state = null;
49
- break;
50
- case "insert":
51
- const n = this.state?.insertAreas?.[this.state?.selectedInsertAreaIndex ?? -1];
52
- if (n && !t) {
53
- await g(this.state, !1);
54
- const o = n?.parent.getAttribute(l.id);
55
- if (!o) return;
56
- const a = {
57
- copy: !!this.state?.copy,
58
- parent: o,
59
- index: n?.index
60
- };
61
- return this.state = null, a;
62
- } else
63
- await g(this.state, !0), this.state = null;
64
- break;
65
- }
66
- }
67
- dragMove({ x: t, y: e, metaKey: i }) {
68
- if (this.state && !this.state.destroying) {
69
- this.state.lastCursorPosition = { x: t, y: e };
70
- const r = m(this.state.initialContainer.getBoundingClientRect(), { x: t, y: e }), s = this.state.element.getBoundingClientRect();
71
- m(s, { x: t, y: e }) || (this.state.offset.x -= (t - (s.left + s.width / 2)) * 0.1, this.state.offset.y -= (e - (s.top + s.height / 2)) * 0.1), r && !i ? h(this.state) : c(this.state, i ? [this.state.element] : [this.state.element, this.state.initialContainer]), this.state.element.style.setProperty("translate", `${t - this.state.offset.x}px ${e - this.state.offset.y}px`);
72
- return;
73
- }
74
- }
75
- }
76
- export function createDragDropContext() {
77
- const d = new u();
78
- return {
79
- startDrag: (...t) => d.startDrag(...t),
80
- dragMove: (...t) => d.dragMove(...t),
81
- endDrag: (...t) => d.endDrag(...t)
82
- };
83
- }
@@ -1,123 +0,0 @@
1
- export interface DragDropContext {
2
- /**
3
- * Start dragging an element
4
- */
5
- startDrag: (options: {
6
- elementId: string;
7
- path: string;
8
- x: number;
9
- y: number;
10
- }) => Promise<{
11
- dragId: string;
12
- }>;
13
- /**
14
- * Update drag position
15
- */
16
- updateDragPosition: (options: {
17
- dragId: string;
18
- x: number;
19
- y: number;
20
- }) => Promise<void>;
21
- /**
22
- * End drag operation
23
- */
24
- endDrag: (options: {
25
- dragId: string;
26
- canceled?: boolean;
27
- }) => Promise<{
28
- dropped: boolean;
29
- targetId?: string;
30
- targetPath?: string;
31
- insertIndex?: number;
32
- }>;
33
- /**
34
- * Get drop zones at current position
35
- */
36
- getDropZones: (options: {
37
- x: number;
38
- y: number;
39
- }) => Promise<Array<{
40
- elementId: string;
41
- path: string;
42
- rect: {
43
- top: number;
44
- left: number;
45
- width: number;
46
- height: number;
47
- };
48
- canDrop: boolean;
49
- }>>;
50
- /**
51
- * Highlight drop zone
52
- */
53
- highlightDropZone: (options: {
54
- elementId?: string;
55
- path?: string;
56
- clear?: boolean;
57
- }) => Promise<void>;
58
- }
59
- export interface DragDropEvents {
60
- 'drag-start': (data: {
61
- elementId: string;
62
- path: string;
63
- }) => void;
64
- 'drag-move': (data: {
65
- x: number;
66
- y: number;
67
- }) => void;
68
- 'drag-end': (data: {
69
- dropped: boolean;
70
- targetId?: string;
71
- }) => void;
72
- 'drop-zone-enter': (data: {
73
- elementId: string;
74
- path: string;
75
- }) => void;
76
- 'drop-zone-leave': (data: {
77
- elementId: string;
78
- path: string;
79
- }) => void;
80
- }
81
- export type DragState = {
82
- /**
83
- * Dragging elements within the initial container is a reorder operation while dragging elements outside the initial container is an insert operation.
84
- * While they share some common properties, we need to differentiate between the two to handle them differently.
85
- */
86
- mode: 'reorder' | 'insert';
87
- elementPath: string;
88
- elementType: 'element' | 'component' | 'text';
89
- copy?: HTMLElement;
90
- element: HTMLElement;
91
- repeatedNodes: HTMLElement[];
92
- offset: Point;
93
- lastCursorPosition: Point;
94
- initialContainer: HTMLElement;
95
- initialNextSibling: Element | null;
96
- initialRect: DOMRect;
97
- reorderPermutations: Array<{
98
- nextSibling: Node | null;
99
- rect: DOMRect;
100
- }>;
101
- isTransitioning: boolean;
102
- selectedInsertAreaIndex?: number;
103
- insertAreas?: Array<InsertArea>;
104
- destroying: boolean;
105
- };
106
- export type InsertArea = {
107
- layout: 'block' | 'inline';
108
- parent: Element;
109
- index: number;
110
- center: Point;
111
- size: number;
112
- direction: 1 | -1;
113
- };
114
- export type Point = {
115
- x: number;
116
- y: number;
117
- };
118
- export type Line = {
119
- x1: number;
120
- y1: number;
121
- x2: number;
122
- y2: number;
123
- };
@@ -1 +0,0 @@
1
- "use strict";
File without changes
@@ -1,101 +0,0 @@
1
- import type { DragDropContext } from './types';
2
- /**
3
- * Drag and drop manager for iframe
4
- * Manages drag state and provides methods for RPC communication
5
- */
6
- export declare class DragDropManager {
7
- private activeDrags;
8
- private dropIndicator;
9
- private onDragStartCallback?;
10
- private onDragEndCallback?;
11
- constructor();
12
- /**
13
- * Set event callbacks
14
- */
15
- setCallbacks(callbacks: {
16
- onDragStart?: (data: {
17
- elementId: string;
18
- path: string;
19
- }) => void;
20
- onDragEnd?: (data: {
21
- dropped: boolean;
22
- targetId?: string;
23
- }) => void;
24
- }): void;
25
- /**
26
- * Start dragging an element
27
- */
28
- startDrag(options: {
29
- elementId: string;
30
- path: string;
31
- x: number;
32
- y: number;
33
- }): Promise<{
34
- dragId: string;
35
- }>;
36
- /**
37
- * Update drag position
38
- */
39
- updateDragPosition(options: {
40
- dragId: string;
41
- x: number;
42
- y: number;
43
- }): Promise<void>;
44
- /**
45
- * End drag operation
46
- */
47
- endDrag(options: {
48
- dragId: string;
49
- canceled?: boolean;
50
- }): Promise<{
51
- dropped: boolean;
52
- targetId?: string;
53
- targetPath?: string;
54
- insertIndex?: number;
55
- }>;
56
- /**
57
- * Get drop zones at position
58
- */
59
- getDropZones(options: {
60
- x: number;
61
- y: number;
62
- }): Promise<Array<{
63
- elementId: string;
64
- path: string;
65
- rect: {
66
- top: number;
67
- left: number;
68
- width: number;
69
- height: number;
70
- };
71
- canDrop: boolean;
72
- }>>;
73
- /**
74
- * Highlight drop zone
75
- */
76
- highlightDropZone(options: {
77
- elementId?: string;
78
- path?: string;
79
- clear?: boolean;
80
- }): Promise<void>;
81
- /**
82
- * Find drop zone at position
83
- */
84
- private findDropZoneAtPosition;
85
- /**
86
- * Show drop indicator
87
- */
88
- private showDropIndicator;
89
- /**
90
- * Hide drop indicator
91
- */
92
- private hideDropIndicator;
93
- /**
94
- * Clean up
95
- */
96
- destroy(): void;
97
- }
98
- /**
99
- * Create drag-drop context for iframe client
100
- */
101
- export declare function createDragDropContext(): DragDropContext;
@@ -1,204 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.DragDropManager = void 0;
7
- exports.createDragDropContext = createDragDropContext;
8
- var _utils = require("./utils");
9
- class DragDropManager {
10
- activeDrags = new Map();
11
- dropIndicator = null;
12
- onDragStartCallback;
13
- onDragEndCallback;
14
- constructor() {
15
- this.dropIndicator = (0, _utils.createDropIndicator)();
16
- }
17
- setCallbacks(r) {
18
- this.onDragStartCallback = r.onDragStart, this.onDragEndCallback = r.onDragEnd;
19
- }
20
- async startDrag(r) {
21
- const {
22
- elementId: a,
23
- path: i,
24
- x: e,
25
- y: t
26
- } = r,
27
- o = (0, _utils.getElement)(a, i);
28
- if (!o) throw new Error(`Element not found: ${a} at ${i}`);
29
- const d = `drag-${Date.now()}-${Math.random()}`,
30
- n = o.getBoundingClientRect(),
31
- s = o.cloneNode(!0);
32
- s.classList.add("__nooku-drag-clone"), s.style.cssText = `
33
- position: fixed;
34
- left: ${n.left}px;
35
- top: ${n.top}px;
36
- width: ${n.width}px;
37
- height: ${n.height}px;
38
- pointer-events: none;
39
- z-index: 10000;
40
- opacity: 0.8;
41
- transition: none;
42
- `, document.body.appendChild(s), o.style.opacity = "0.3", o.classList.add("__nooku-dragging");
43
- const c = (0, _utils.getParentContainer)(o),
44
- I = {
45
- dragId: d,
46
- elementId: a,
47
- path: i,
48
- startX: e,
49
- startY: t,
50
- currentX: e,
51
- currentY: t,
52
- element: o,
53
- clone: s,
54
- initialRect: n,
55
- currentDropZone: c || void 0,
56
- mode: "reorder"
57
- };
58
- return this.activeDrags.set(d, I), this.onDragStartCallback?.({
59
- elementId: a,
60
- path: i
61
- }), {
62
- dragId: d
63
- };
64
- }
65
- async updateDragPosition(r) {
66
- const {
67
- dragId: a,
68
- x: i,
69
- y: e
70
- } = r,
71
- t = this.activeDrags.get(a);
72
- if (!t) throw new Error(`Drag not found: ${a}`);
73
- const o = i - t.startX,
74
- d = e - t.startY;
75
- t.currentX = i, t.currentY = e, t.clone.style.left = `${t.initialRect.left + o}px`, t.clone.style.top = `${t.initialRect.top + d}px`;
76
- const n = this.findDropZoneAtPosition(i, e, t.path),
77
- s = (0, _utils.getParentContainer)(t.element);
78
- n === s ? t.mode = "reorder" : n && (t.mode = "move"), n !== t.currentDropZone ? (t.currentDropZone && t.currentDropZone.classList.remove("__nooku-drop-zone-active"), t.currentDropZone = n, n ? (n.classList.add("__nooku-drop-zone-active"), this.showDropIndicator(n, i, e, t)) : this.hideDropIndicator()) : n && this.showDropIndicator(n, i, e, t);
79
- }
80
- async endDrag(r) {
81
- const {
82
- dragId: a,
83
- canceled: i = !1
84
- } = r,
85
- e = this.activeDrags.get(a);
86
- if (!e) throw new Error(`Drag not found: ${a}`);
87
- e.element.classList.remove("__nooku-dragging"), e.element.style.opacity = "", e.clone.remove(), e.currentDropZone && e.currentDropZone.classList.remove("__nooku-drop-zone-active"), this.hideDropIndicator();
88
- let t;
89
- if (i || !e.currentDropZone) t = {
90
- dropped: !1
91
- };else {
92
- const o = e.currentDropZone.getAttribute("data-node-id") || void 0,
93
- d = e.currentDropZone.getAttribute("data-node-path") || void 0,
94
- {
95
- index: n
96
- } = (0, _utils.calculateInsertIndex)(e.currentDropZone, e.currentX, e.currentY, e.element);
97
- t = {
98
- dropped: !0,
99
- targetId: o,
100
- targetPath: d,
101
- insertIndex: n
102
- };
103
- }
104
- return this.activeDrags.delete(a), this.onDragEndCallback?.(t), t;
105
- }
106
- async getDropZones(r) {
107
- const {
108
- x: a,
109
- y: i
110
- } = r;
111
- return (0, _utils.getDropZones)().map(t => {
112
- const o = t.getBoundingClientRect(),
113
- d = t.getAttribute("data-node-id") || "",
114
- n = t.getAttribute("data-node-path") || "",
115
- s = a >= o.left && a <= o.right && i >= o.top && i <= o.bottom;
116
- return {
117
- elementId: d,
118
- path: n,
119
- rect: {
120
- top: o.top,
121
- left: o.left,
122
- width: o.width,
123
- height: o.height
124
- },
125
- canDrop: s && (0, _utils.canAcceptDrop)(t)
126
- };
127
- }).filter(t => t.canDrop);
128
- }
129
- async highlightDropZone(r) {
130
- const {
131
- elementId: a,
132
- path: i,
133
- clear: e = !1
134
- } = r;
135
- if (document.querySelectorAll(".__nooku-drop-zone-highlight").forEach(o => {
136
- o.classList.remove("__nooku-drop-zone-highlight");
137
- }), e || !a || !i) {
138
- this.hideDropIndicator();
139
- return;
140
- }
141
- const t = (0, _utils.getElement)(a, i);
142
- t && t.classList.add("__nooku-drop-zone-highlight");
143
- }
144
- findDropZoneAtPosition(r, a, i) {
145
- const e = (0, _utils.getElementAtPosition)(r, a, i);
146
- if (!e) return;
147
- let t = e;
148
- for (; t;) {
149
- if (t.hasAttribute("data-node-id") && (0, _utils.canAcceptDrop)(t)) return t;
150
- t = t.parentElement;
151
- }
152
- }
153
- showDropIndicator(r, a, i, e) {
154
- this.dropIndicator || (this.dropIndicator = (0, _utils.createDropIndicator)()), this.dropIndicator.parentElement || document.body.appendChild(this.dropIndicator);
155
- const {
156
- index: t,
157
- before: o,
158
- layout: d
159
- } = (0, _utils.calculateInsertIndex)(r, a, i, e.element),
160
- n = Array.from(r.children).filter(s => s.hasAttribute("data-node-id") && s !== e.element && !s.classList.contains("__nooku-drag-clone"));
161
- if (e.currentInsertIndex = t, n.length === 0) {
162
- const s = r.getBoundingClientRect();
163
- (0, _utils.positionDropIndicator)(this.dropIndicator, s, d);
164
- } else if (t < n.length) {
165
- const c = n[t].getBoundingClientRect();
166
- d === "block" ? (0, _utils.positionDropIndicator)(this.dropIndicator, {
167
- ...c,
168
- height: 2
169
- }, d) : (0, _utils.positionDropIndicator)(this.dropIndicator, {
170
- ...c,
171
- width: 2
172
- }, d);
173
- } else {
174
- const c = n[n.length - 1].getBoundingClientRect();
175
- d === "block" ? (0, _utils.positionDropIndicator)(this.dropIndicator, {
176
- ...c,
177
- top: c.bottom,
178
- height: 2
179
- }, d) : (0, _utils.positionDropIndicator)(this.dropIndicator, {
180
- ...c,
181
- left: c.right,
182
- width: 2
183
- }, d);
184
- }
185
- this.dropIndicator.style.display = "block";
186
- }
187
- hideDropIndicator() {
188
- this.dropIndicator && (this.dropIndicator.style.display = "none");
189
- }
190
- destroy() {
191
- this.activeDrags.clear(), this.dropIndicator?.remove(), this.dropIndicator = null;
192
- }
193
- }
194
- exports.DragDropManager = DragDropManager;
195
- function createDragDropContext() {
196
- const l = new DragDropManager();
197
- return {
198
- startDrag: r => l.startDrag(r),
199
- updateDragPosition: r => l.updateDragPosition(r),
200
- endDrag: r => l.endDrag(r),
201
- getDropZones: r => l.getDropZones(r),
202
- highlightDropZone: r => l.highlightDropZone(r)
203
- };
204
- }