@nookuio/iframe 1.0.0 → 1.0.1-beta.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.
Files changed (50) hide show
  1. package/dist/constants.d.ts +9 -0
  2. package/dist/constants.js +11 -2
  3. package/dist/constants.mjs +9 -1
  4. package/dist/drag-drop/dragEnd.d.ts +2 -0
  5. package/dist/drag-drop/dragEnd.js +27 -0
  6. package/dist/drag-drop/dragEnd.mjs +23 -0
  7. package/dist/drag-drop/dragMove.d.ts +2 -0
  8. package/dist/drag-drop/dragMove.js +46 -0
  9. package/dist/drag-drop/dragMove.mjs +40 -0
  10. package/dist/drag-drop/dragReorder.d.ts +3 -0
  11. package/dist/drag-drop/dragReorder.js +60 -0
  12. package/dist/drag-drop/dragReorder.mjs +64 -0
  13. package/dist/drag-drop/dragStart.d.ts +9 -0
  14. package/dist/drag-drop/dragStart.js +60 -0
  15. package/dist/drag-drop/dragStart.mjs +55 -0
  16. package/dist/drag-drop/helpers.d.ts +42 -0
  17. package/dist/drag-drop/helpers.js +205 -0
  18. package/dist/drag-drop/helpers.mjs +188 -0
  19. package/dist/drag-drop/highlight.d.ts +16 -0
  20. package/dist/drag-drop/highlight.js +32 -0
  21. package/dist/drag-drop/highlight.mjs +22 -0
  22. package/dist/drag-drop/index.d.ts +24 -0
  23. package/dist/drag-drop/index.js +106 -0
  24. package/dist/drag-drop/index.mjs +83 -0
  25. package/dist/drag-drop/types.d.ts +123 -0
  26. package/dist/drag-drop/types.js +1 -0
  27. package/dist/drag-drop/types.mjs +0 -0
  28. package/dist/drag-drop backup/dragDropManager.d.ts +101 -0
  29. package/dist/drag-drop backup/dragDropManager.js +204 -0
  30. package/dist/drag-drop backup/dragDropManager.mjs +183 -0
  31. package/dist/drag-drop backup/index.d.ts +3 -0
  32. package/dist/drag-drop backup/index.js +38 -0
  33. package/dist/drag-drop backup/index.mjs +3 -0
  34. package/dist/drag-drop backup/types.d.ts +80 -0
  35. package/dist/drag-drop backup/types.js +1 -0
  36. package/dist/drag-drop backup/types.mjs +0 -0
  37. package/dist/drag-drop backup/utils.d.ts +41 -0
  38. package/dist/drag-drop backup/utils.js +93 -0
  39. package/dist/drag-drop backup/utils.mjs +68 -0
  40. package/dist/editor.d.ts +1 -7
  41. package/dist/editor.js +2 -2
  42. package/dist/editor.mjs +1 -1
  43. package/dist/iframe.d.ts +2 -8
  44. package/dist/iframe.js +46 -43
  45. package/dist/iframe.mjs +48 -46
  46. package/dist/types.d.ts +17 -3
  47. package/package.json +3 -2
  48. package/dist/createClient.d.ts +0 -51
  49. package/dist/createClient.js +0 -118
  50. package/dist/createClient.mjs +0 -114
@@ -0,0 +1,205 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.findNearestLine = findNearestLine;
7
+ exports.getDOMNodeFromNodeId = getDOMNodeFromNodeId;
8
+ exports.getInsertAreas = getInsertAreas;
9
+ exports.getNodeType = getNodeType;
10
+ exports.isElementInViewport = isElementInViewport;
11
+ exports.rectHasPoint = rectHasPoint;
12
+ exports.tryStartViewTransition = tryStartViewTransition;
13
+ var _constants = require("../constants");
14
+ function isElementInViewport(i, t = 0) {
15
+ const n = i.getBoundingClientRect(),
16
+ s = window.innerHeight || document.documentElement.clientHeight,
17
+ e = window.innerWidth || document.documentElement.clientWidth;
18
+ return n.top >= 0 - t && n.left >= 0 - t && n.bottom <= s + t && n.right <= e + t;
19
+ }
20
+ function rectHasPoint(i, {
21
+ x: t,
22
+ y: n
23
+ }) {
24
+ return t >= i.left && t <= i.right && n >= i.top && n <= i.bottom;
25
+ }
26
+ function tryStartViewTransition(i, t) {
27
+ const n = document.startViewTransition;
28
+ return !n || t?.skipPrefersReducedMotionCheck !== !0 && window.matchMedia("(prefers-reduced-motion: reduce)").matches ? (i(), {
29
+ finished: Promise.resolve()
30
+ }) : n.call(document, i);
31
+ }
32
+ function getDOMNodeFromNodeId(i, t) {
33
+ const n = `[${_constants.ATTRIBUTES.id}="${t}"][${_constants.ATTRIBUTES.path}="${i}"]`;
34
+ return document.querySelector(n);
35
+ }
36
+ function getNodeType(i) {
37
+ return i.getAttribute(_constants.ATTRIBUTES.type);
38
+ }
39
+ function getInsertAreas(i) {
40
+ const t = [];
41
+ return Array.from(document.querySelectorAll(`[${_constants.ATTRIBUTES.id}]:not([${_constants.ATTRIBUTES.id}=""]):not([${_constants.ATTRIBUTES.component}])[data-node-path="${i}"]`)).filter(n => !n.hasAttribute(_constants.ATTRIBUTES.index)).map(n => n.getAttribute(_constants.ATTRIBUTES.id)).forEach(n => {
42
+ const s = getDOMNodeFromNodeId(i, n);
43
+ if (!s) {
44
+ console.warn(`Element with path ${n} not found`);
45
+ return;
46
+ }
47
+ const e = s.getBoundingClientRect(),
48
+ o = s.parentElement;
49
+ if (!o) return;
50
+ const c = Array.from(o.children).filter(l => l.hasAttribute(_constants.ATTRIBUTES.id) && l.hasAttribute(_constants.ATTRIBUTES.path) && !l.hasAttribute(_constants.ATTRIBUTES.index)),
51
+ r = c.indexOf(s),
52
+ u = c[r + 1]?.getBoundingClientRect(),
53
+ h = c[r - 1]?.getBoundingClientRect();
54
+ c.length > 1 && c.map(l => l.getBoundingClientRect()).every((l, f, p) => f === 0 || l.width + l.height === 0 || p[f - 1].bottom <= l.top) ? (h ? h.bottom >= e.top && t.push({
55
+ layout: "block",
56
+ parent: o,
57
+ index: r,
58
+ center: {
59
+ x: e.left + e.width / 2,
60
+ y: e.top
61
+ },
62
+ size: e.width,
63
+ direction: -1
64
+ }) : c.length > 0 && t.push({
65
+ layout: "block",
66
+ parent: o,
67
+ index: r,
68
+ center: {
69
+ x: e.left + e.width / 2,
70
+ y: e.top
71
+ },
72
+ size: e.width,
73
+ direction: -1
74
+ }), u ? u.top > e.bottom ? t.push({
75
+ layout: "block",
76
+ parent: o,
77
+ index: r + 1,
78
+ center: {
79
+ x: e.left + e.width / 2,
80
+ y: (e.bottom + u.top) / 2
81
+ },
82
+ size: e.width,
83
+ direction: 1
84
+ }) : t.push({
85
+ layout: "block",
86
+ parent: o,
87
+ index: r + 1,
88
+ center: {
89
+ x: e.left + e.width / 2,
90
+ y: e.bottom
91
+ },
92
+ size: e.width,
93
+ direction: 1
94
+ }) : c.length > 0 && t.push({
95
+ layout: "block",
96
+ parent: o,
97
+ index: r + 1,
98
+ center: {
99
+ x: e.left + e.width / 2,
100
+ y: e.bottom
101
+ },
102
+ size: e.width,
103
+ direction: 1
104
+ })) : (h ? h.right >= e.left && t.push({
105
+ layout: "inline",
106
+ parent: o,
107
+ index: r,
108
+ center: {
109
+ x: e.left,
110
+ y: e.top + e.height / 2
111
+ },
112
+ size: e.height,
113
+ direction: -1
114
+ }) : c.length > 0 && t.push({
115
+ layout: "inline",
116
+ parent: o,
117
+ index: r,
118
+ center: {
119
+ x: e.left,
120
+ y: e.top + e.height / 2
121
+ },
122
+ size: e.height,
123
+ direction: -1
124
+ }), u ? u.left > e.right ? t.push({
125
+ layout: "inline",
126
+ parent: o,
127
+ index: r + 1,
128
+ center: {
129
+ x: (e.right + u.left) / 2,
130
+ y: u.top + u.height / 2
131
+ },
132
+ size: e.height,
133
+ direction: 1
134
+ }) : t.push({
135
+ layout: "inline",
136
+ parent: o,
137
+ index: r + 1,
138
+ center: {
139
+ x: e.right,
140
+ y: e.top + e.height / 2
141
+ },
142
+ size: e.height,
143
+ direction: 1
144
+ }) : c.length > 0 && t.push({
145
+ layout: "inline",
146
+ parent: o,
147
+ index: r + 1,
148
+ center: {
149
+ x: e.right,
150
+ y: e.top + e.height / 2
151
+ },
152
+ size: e.height,
153
+ direction: 1
154
+ }));
155
+ }), y(t);
156
+ }
157
+ function y(i) {
158
+ return i.map(t => t.layout === "block" ? {
159
+ ...t,
160
+ point: {
161
+ ...t.center,
162
+ y: t.center.y - i.filter(n => t.parent !== n.parent && n.layout === "block" && n.center.y === t.center.y && n.parent.contains(t.parent)).length * t.direction
163
+ }
164
+ } : {
165
+ ...t,
166
+ point: {
167
+ ...t.center,
168
+ x: t.center.x - i.filter(n => t.parent !== n.parent && n.layout === "inline" && n.center.x === t.center.x && n.parent.contains(t.parent)).length * t.direction
169
+ }
170
+ });
171
+ }
172
+ function findNearestLine(i, t) {
173
+ let n = 1 / 0,
174
+ s = null,
175
+ e = 0;
176
+ for (const o of i) {
177
+ const {
178
+ distSquared: c,
179
+ projectionPoint: r
180
+ } = m(t, o);
181
+ c < n && (n = c, s = o, e = r);
182
+ }
183
+ return {
184
+ nearestLine: s,
185
+ dist: Math.sqrt(n),
186
+ projectionPoint: e
187
+ };
188
+ }
189
+ function m(i, t) {
190
+ const n = t.x2 - t.x1,
191
+ s = t.y2 - t.y1,
192
+ e = n * n + s * s;
193
+ if (e === 0) return {
194
+ distSquared: (i.x - t.x1) * (i.x - t.x1) + (i.y - t.y1) * (i.y - t.y1),
195
+ projectionPoint: .5
196
+ };
197
+ let o = ((i.x - t.x1) * n + (i.y - t.y1) * s) / e;
198
+ o = Math.max(0, Math.min(1, o));
199
+ const c = t.x1 + o * n,
200
+ r = t.y1 + o * s;
201
+ return {
202
+ distSquared: (i.x - c) * (i.x - c) + (i.y - r) * (i.y - r),
203
+ projectionPoint: o
204
+ };
205
+ }
@@ -0,0 +1,188 @@
1
+ import { ATTRIBUTES as d } from "../constants.mjs";
2
+ export function isElementInViewport(i, t = 0) {
3
+ const n = i.getBoundingClientRect(), s = window.innerHeight || document.documentElement.clientHeight, e = window.innerWidth || document.documentElement.clientWidth;
4
+ return n.top >= 0 - t && n.left >= 0 - t && n.bottom <= s + t && n.right <= e + t;
5
+ }
6
+ export function rectHasPoint(i, { x: t, y: n }) {
7
+ return t >= i.left && t <= i.right && n >= i.top && n <= i.bottom;
8
+ }
9
+ export function tryStartViewTransition(i, t) {
10
+ const n = document.startViewTransition;
11
+ return !n || t?.skipPrefersReducedMotionCheck !== !0 && window.matchMedia("(prefers-reduced-motion: reduce)").matches ? (i(), {
12
+ finished: Promise.resolve()
13
+ }) : n.call(document, i);
14
+ }
15
+ export function getDOMNodeFromNodeId(i, t) {
16
+ const n = `[${d.id}="${t}"][${d.path}="${i}"]`;
17
+ return document.querySelector(n);
18
+ }
19
+ export function getNodeType(i) {
20
+ return i.getAttribute(d.type);
21
+ }
22
+ export function getInsertAreas(i) {
23
+ const t = [];
24
+ return Array.from(
25
+ document.querySelectorAll(
26
+ `[${d.id}]:not([${d.id}=""]):not([${d.component}])[data-node-path="${i}"]`
27
+ )
28
+ ).filter((n) => !n.hasAttribute(d.index)).map((n) => n.getAttribute(d.id)).forEach((n) => {
29
+ const s = getDOMNodeFromNodeId(i, n);
30
+ if (!s) {
31
+ console.warn(`Element with path ${n} not found`);
32
+ return;
33
+ }
34
+ const e = s.getBoundingClientRect(), o = s.parentElement;
35
+ if (!o)
36
+ return;
37
+ const c = Array.from(o.children).filter(
38
+ (l) => l.hasAttribute(d.id) && l.hasAttribute(d.path) && !l.hasAttribute(d.index)
39
+ ), r = c.indexOf(s), u = c[r + 1]?.getBoundingClientRect(), h = c[r - 1]?.getBoundingClientRect();
40
+ c.length > 1 && c.map((l) => l.getBoundingClientRect()).every((l, f, p) => f === 0 || l.width + l.height === 0 || p[f - 1].bottom <= l.top) ? (h ? h.bottom >= e.top && t.push({
41
+ layout: "block",
42
+ parent: o,
43
+ index: r,
44
+ center: {
45
+ x: e.left + e.width / 2,
46
+ y: e.top
47
+ },
48
+ size: e.width,
49
+ direction: -1
50
+ }) : c.length > 0 && t.push({
51
+ layout: "block",
52
+ parent: o,
53
+ index: r,
54
+ center: {
55
+ x: e.left + e.width / 2,
56
+ y: e.top
57
+ },
58
+ size: e.width,
59
+ direction: -1
60
+ }), u ? u.top > e.bottom ? t.push({
61
+ layout: "block",
62
+ parent: o,
63
+ index: r + 1,
64
+ center: {
65
+ x: e.left + e.width / 2,
66
+ y: (e.bottom + u.top) / 2
67
+ },
68
+ size: e.width,
69
+ direction: 1
70
+ }) : t.push({
71
+ layout: "block",
72
+ parent: o,
73
+ index: r + 1,
74
+ center: {
75
+ x: e.left + e.width / 2,
76
+ y: e.bottom
77
+ },
78
+ size: e.width,
79
+ direction: 1
80
+ }) : c.length > 0 && t.push({
81
+ layout: "block",
82
+ parent: o,
83
+ index: r + 1,
84
+ center: {
85
+ x: e.left + e.width / 2,
86
+ y: e.bottom
87
+ },
88
+ size: e.width,
89
+ direction: 1
90
+ })) : (h ? h.right >= e.left && t.push({
91
+ layout: "inline",
92
+ parent: o,
93
+ index: r,
94
+ center: {
95
+ x: e.left,
96
+ y: e.top + e.height / 2
97
+ },
98
+ size: e.height,
99
+ direction: -1
100
+ }) : c.length > 0 && t.push({
101
+ layout: "inline",
102
+ parent: o,
103
+ index: r,
104
+ center: {
105
+ x: e.left,
106
+ y: e.top + e.height / 2
107
+ },
108
+ size: e.height,
109
+ direction: -1
110
+ }), u ? u.left > e.right ? t.push({
111
+ layout: "inline",
112
+ parent: o,
113
+ index: r + 1,
114
+ center: {
115
+ x: (e.right + u.left) / 2,
116
+ y: u.top + u.height / 2
117
+ },
118
+ size: e.height,
119
+ direction: 1
120
+ }) : t.push({
121
+ layout: "inline",
122
+ parent: o,
123
+ index: r + 1,
124
+ center: {
125
+ x: e.right,
126
+ y: e.top + e.height / 2
127
+ },
128
+ size: e.height,
129
+ direction: 1
130
+ }) : c.length > 0 && t.push({
131
+ layout: "inline",
132
+ parent: o,
133
+ index: r + 1,
134
+ center: {
135
+ x: e.right,
136
+ y: e.top + e.height / 2
137
+ },
138
+ size: e.height,
139
+ direction: 1
140
+ }));
141
+ }), y(t);
142
+ }
143
+ function y(i) {
144
+ return i.map((t) => t.layout === "block" ? {
145
+ ...t,
146
+ point: {
147
+ ...t.center,
148
+ y: t.center.y - i.filter(
149
+ (n) => t.parent !== n.parent && n.layout === "block" && n.center.y === t.center.y && n.parent.contains(t.parent)
150
+ ).length * t.direction
151
+ }
152
+ } : {
153
+ ...t,
154
+ point: {
155
+ ...t.center,
156
+ x: t.center.x - i.filter(
157
+ (n) => t.parent !== n.parent && n.layout === "inline" && n.center.x === t.center.x && n.parent.contains(t.parent)
158
+ ).length * t.direction
159
+ }
160
+ });
161
+ }
162
+ export function findNearestLine(i, t) {
163
+ let n = 1 / 0, s = null, e = 0;
164
+ for (const o of i) {
165
+ const { distSquared: c, projectionPoint: r } = m(t, o);
166
+ c < n && (n = c, s = o, e = r);
167
+ }
168
+ return {
169
+ nearestLine: s,
170
+ dist: Math.sqrt(n),
171
+ projectionPoint: e
172
+ };
173
+ }
174
+ function m(i, t) {
175
+ const n = t.x2 - t.x1, s = t.y2 - t.y1, e = n * n + s * s;
176
+ if (e === 0)
177
+ return {
178
+ distSquared: (i.x - t.x1) * (i.x - t.x1) + (i.y - t.y1) * (i.y - t.y1),
179
+ projectionPoint: 0.5
180
+ };
181
+ let o = ((i.x - t.x1) * n + (i.y - t.y1) * s) / e;
182
+ o = Math.max(0, Math.min(1, o));
183
+ const c = t.x1 + o * n, r = t.y1 + o * s;
184
+ return {
185
+ distSquared: (i.x - c) * (i.x - c) + (i.y - r) * (i.y - r),
186
+ projectionPoint: o
187
+ };
188
+ }
@@ -0,0 +1,16 @@
1
+ import type { Point } from './types';
2
+ /**
3
+ * Visual representation of where a dragged node will be dropped.
4
+ */
5
+ export declare function setDropHighlight(element: HTMLElement, targetContainer: HTMLElement, color: string): void;
6
+ /**
7
+ * Visual representation of where a dragged node will be dropped outside of its own container.
8
+ */
9
+ export declare function setExternalDropHighlight({ layout, center, length, color, projectionPoint }: {
10
+ layout: 'block' | 'inline';
11
+ center: Point;
12
+ length: number;
13
+ color: string;
14
+ projectionPoint: number;
15
+ }): void;
16
+ export declare function removeDropHighlight(): void;
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.removeDropHighlight = removeDropHighlight;
7
+ exports.setDropHighlight = setDropHighlight;
8
+ exports.setExternalDropHighlight = setExternalDropHighlight;
9
+ let e = null;
10
+ function setDropHighlight(t, r, o) {
11
+ if (e?.remove(), !t || !r) return;
12
+ e = document.createElement("div"), e.classList.add("__drop-area");
13
+ const {
14
+ top: p,
15
+ left: s
16
+ } = r.getBoundingClientRect();
17
+ 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);
18
+ }
19
+ function setExternalDropHighlight({
20
+ layout: t,
21
+ center: r,
22
+ length: o,
23
+ color: p,
24
+ projectionPoint: s
25
+ }) {
26
+ 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%"));
27
+ const a = `radial-gradient(circle at ${s * 100}% ${s * 100}%, #${p} 0%, #${p}55 max(100%, 75px))`;
28
+ e.style.setProperty("--drop-area-background", a), document.body.appendChild(e);
29
+ }
30
+ function removeDropHighlight() {
31
+ e?.remove(), e = null;
32
+ }
@@ -0,0 +1,22 @@
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
+ }
@@ -0,0 +1,24 @@
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;
@@ -0,0 +1,106 @@
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
+ }
@@ -0,0 +1,83 @@
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
+ }