@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,64 +0,0 @@
1
- import { isElementInViewport as y, tryStartViewTransition as E } from "./helpers.mjs";
2
- import { DRAG_MOVE_CLASSNAME as x } from ".//index.mjs";
3
- import { setDropHighlight as m } from "./highlight.mjs";
4
- export const DRAG_REORDER_CLASSNAME = "__drag-mode--reorder";
5
- const c = 100;
6
- export function dragReorder(e) {
7
- if (!e || e.isTransitioning)
8
- return;
9
- if (e.mode === "insert") {
10
- e.mode = "reorder";
11
- const o = e.element.getBoundingClientRect();
12
- e.element.classList.add(DRAG_REORDER_CLASSNAME), e.element.classList.remove(x), e.initialContainer.insertBefore(e.element, e.initialNextSibling), e.repeatedNodes.forEach((r, l) => {
13
- r.style.setProperty("--drag-repeat-node-opacity", l < 3 ? "1" : "0");
14
- });
15
- const s = e.element.getBoundingClientRect();
16
- e.offset.x += s.left - o.left, e.offset.y += s.top - o.top, m(
17
- e.element,
18
- e.initialContainer,
19
- e.elementType === "component" ? "D946EF" : "2563EB"
20
- );
21
- }
22
- const f = T(e);
23
- if (f && e.element.nextElementSibling !== f.nextSibling) {
24
- e.isTransitioning = !0;
25
- const o = Array.from(e.initialContainer.childNodes);
26
- o.filter((t) => t instanceof HTMLElement).filter(y).forEach((t, i) => {
27
- t.style.setProperty("view-transition-name", "item-" + i);
28
- }), e.element.style.setProperty("view-transition-name", "__drag-item");
29
- const s = e.element.offsetLeft, r = e.element.offsetTop;
30
- E(() => {
31
- e && (e.initialContainer.insertBefore(e.element, f.nextSibling), e.offset.x += e.element.offsetLeft - s, e.offset.y += e.element.offsetTop - r, e?.element.style.setProperty(
32
- "translate",
33
- `${e.lastCursorPosition.x - e.offset.x}px ${e.lastCursorPosition.y - e.offset.y}px`
34
- ), m(
35
- e.element,
36
- e.initialContainer,
37
- e.elementType === "component" ? "D946EF" : "2563EB"
38
- ));
39
- }).finished.then(() => {
40
- o.forEach((t) => {
41
- t instanceof HTMLElement && t.style.removeProperty("view-transition-name");
42
- }), e && (e.isTransitioning = !1);
43
- }).catch(() => {
44
- });
45
- }
46
- }
47
- function T(e) {
48
- const { left: f, top: o, width: s, height: r } = e.element.getBoundingClientRect(), l = f + s / 2, t = o + r / 2;
49
- return e.reorderPermutations.reduce((i, n) => {
50
- if (Math.abs(n.rect.left + n.rect.width / 2 - l) < n.rect.width / 2 + c && Math.abs(n.rect.top + n.rect.height / 2 - t) < n.rect.height / 2 + c) {
51
- if (!i)
52
- return n;
53
- const p = Math.hypot(
54
- i.rect.left + i.rect.width / 2 - l,
55
- i.rect.top + i.rect.height / 2 - t
56
- ), h = Math.hypot(
57
- n.rect.left + n.rect.width / 2 - l,
58
- n.rect.top + n.rect.height / 2 - t
59
- );
60
- return p < h ? i : n;
61
- }
62
- return i;
63
- }, null);
64
- }
@@ -1,9 +0,0 @@
1
- import type { DragState, Point } from './types';
2
- export declare function dragStarted({ element, lastCursorPosition, repeatedNodes, asCopy, initialContainer, initialNextSibling }: {
3
- element: HTMLElement;
4
- lastCursorPosition: Point;
5
- repeatedNodes: HTMLElement[];
6
- asCopy: boolean;
7
- initialContainer?: HTMLElement;
8
- initialNextSibling?: Element | null;
9
- }): DragState;
@@ -1,60 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.dragStarted = dragStarted;
7
- var _ = require("./");
8
- var _highlight = require("./highlight");
9
- var _helpers = require("./helpers");
10
- var _constants = require("../constants");
11
- function dragStarted({
12
- element: i,
13
- lastCursorPosition: l,
14
- repeatedNodes: s,
15
- asCopy: g,
16
- initialContainer: y = i.parentElement,
17
- initialNextSibling: p
18
- }) {
19
- s.map(e => [e, e.getBoundingClientRect()]).forEach(([e, r], o) => {
20
- e.classList.add("drag-repeat-node"), e.style.setProperty("--drag-repeat-node-width", `${r.width}px`), e.style.setProperty("--drag-repeat-node-height", `${r.height}px`), e.style.setProperty("--drag-repeat-node-translate", `${r.left}px ${r.top}px`), e.style.setProperty("--drag-repeat-node-rotate", `${Math.random() * 9 - 4.5}deg`), e.style.setProperty("--drag-repeat-node-opacity", o < 3 ? "1" : "0");
21
- }), p ??= i.nextElementSibling;
22
- const t = {
23
- destroying: !1,
24
- elementPath: i.getAttribute(_constants.ATTRIBUTES.path),
25
- elementType: (0, _helpers.getNodeType)(i),
26
- element: i,
27
- offset: l,
28
- lastCursorPosition: l,
29
- initialContainer: y,
30
- initialNextSibling: p,
31
- initialRect: i.getBoundingClientRect(),
32
- reorderPermutations: [],
33
- isTransitioning: !1,
34
- repeatedNodes: s,
35
- mode: "reorder"
36
- };
37
- return g && (t.copy = i.cloneNode(!0), t.copy.style.setProperty("opacity", "0.5"), t.copy.classList.remove(_.DRAG_REORDER_CLASSNAME), t.copy.classList.remove(_.DRAG_MOVE_CLASSNAME), t.initialContainer.insertBefore(t.copy, t.initialNextSibling)), t.initialContainer.childNodes.forEach(e => {
38
- e instanceof Element && e.getAttribute(_constants.ATTRIBUTES.id) && e.getAttribute(_constants.ATTRIBUTES.path) === t.elementPath && s.every(r => r !== e) && (t?.initialContainer.insertBefore(i, e), t?.reorderPermutations.push({
39
- nextSibling: e,
40
- rect: i.getBoundingClientRect()
41
- }));
42
- }), t.initialContainer.hasAttribute(_constants.ATTRIBUTES.component) || (t.initialContainer.appendChild(i), t?.reorderPermutations.push({
43
- nextSibling: null,
44
- rect: i.getBoundingClientRect()
45
- })), t.initialContainer.insertBefore(i, t.initialNextSibling), function e() {
46
- if (t.destroying || !t.element.isConnected) return;
47
- const r = t.element.getBoundingClientRect();
48
- t.repeatedNodes.forEach(o => {
49
- o.style.setProperty("rotate", "0deg");
50
- const n = o.getBoundingClientRect();
51
- o.style.removeProperty("rotate");
52
- const m = r.left + r.width / 2 - n.width / 2,
53
- f = r.top + r.height / 2 - n.height / 2,
54
- d = .4,
55
- h = n.left + (m - n.left) * d,
56
- u = n.top + (f - n.top) * d;
57
- o.style.setProperty("--drag-repeat-node-translate", `${h}px ${u}px`);
58
- }), requestAnimationFrame(e);
59
- }(), i.classList.add(_.DRAG_REORDER_CLASSNAME), (0, _highlight.setDropHighlight)(t.element, t.initialContainer, t.elementType === "component" ? "D946EF" : "2563EB"), t;
60
- }
@@ -1,55 +0,0 @@
1
- import { DRAG_REORDER_CLASSNAME as c, DRAG_MOVE_CLASSNAME as E } from ".//index.mjs";
2
- import { setDropHighlight as C } from "./highlight.mjs";
3
- import { getNodeType as R } from "./helpers.mjs";
4
- import { ATTRIBUTES as a } from "../constants.mjs";
5
- export function dragStarted({
6
- element: i,
7
- lastCursorPosition: l,
8
- repeatedNodes: s,
9
- asCopy: g,
10
- initialContainer: y = i.parentElement,
11
- initialNextSibling: p
12
- }) {
13
- s.map((e) => [e, e.getBoundingClientRect()]).forEach(([e, r], o) => {
14
- e.classList.add("drag-repeat-node"), e.style.setProperty("--drag-repeat-node-width", `${r.width}px`), e.style.setProperty("--drag-repeat-node-height", `${r.height}px`), e.style.setProperty("--drag-repeat-node-translate", `${r.left}px ${r.top}px`), e.style.setProperty("--drag-repeat-node-rotate", `${Math.random() * 9 - 4.5}deg`), e.style.setProperty("--drag-repeat-node-opacity", o < 3 ? "1" : "0");
15
- }), p ??= i.nextElementSibling;
16
- const t = {
17
- destroying: !1,
18
- elementPath: i.getAttribute(a.path),
19
- elementType: R(i),
20
- element: i,
21
- offset: l,
22
- lastCursorPosition: l,
23
- initialContainer: y,
24
- initialNextSibling: p,
25
- initialRect: i.getBoundingClientRect(),
26
- reorderPermutations: [],
27
- isTransitioning: !1,
28
- repeatedNodes: s,
29
- mode: "reorder"
30
- };
31
- return g && (t.copy = i.cloneNode(!0), t.copy.style.setProperty("opacity", "0.5"), t.copy.classList.remove(c), t.copy.classList.remove(E), t.initialContainer.insertBefore(t.copy, t.initialNextSibling)), t.initialContainer.childNodes.forEach((e) => {
32
- e instanceof Element && e.getAttribute(a.id) && e.getAttribute(a.path) === t.elementPath && s.every((r) => r !== e) && (t?.initialContainer.insertBefore(i, e), t?.reorderPermutations.push({
33
- nextSibling: e,
34
- rect: i.getBoundingClientRect()
35
- }));
36
- }), t.initialContainer.hasAttribute(a.component) || (t.initialContainer.appendChild(i), t?.reorderPermutations.push({
37
- nextSibling: null,
38
- rect: i.getBoundingClientRect()
39
- })), t.initialContainer.insertBefore(i, t.initialNextSibling), (function e() {
40
- if (t.destroying || !t.element.isConnected)
41
- return;
42
- const r = t.element.getBoundingClientRect();
43
- t.repeatedNodes.forEach((o) => {
44
- o.style.setProperty("rotate", "0deg");
45
- const n = o.getBoundingClientRect();
46
- o.style.removeProperty("rotate");
47
- const m = r.left + r.width / 2 - n.width / 2, f = r.top + r.height / 2 - n.height / 2, d = 0.4, h = n.left + (m - n.left) * d, u = n.top + (f - n.top) * d;
48
- o.style.setProperty("--drag-repeat-node-translate", `${h}px ${u}px`);
49
- }), requestAnimationFrame(e);
50
- })(), i.classList.add(c), C(
51
- t.element,
52
- t.initialContainer,
53
- t.elementType === "component" ? "D946EF" : "2563EB"
54
- ), t;
55
- }
@@ -1,42 +0,0 @@
1
- import type { Line, Point } from './types';
2
- export declare function isElementInViewport(element: HTMLElement, thresholdPx?: number): boolean;
3
- export declare function rectHasPoint(rect: DOMRect, { x, y }: Point): boolean;
4
- export declare function tryStartViewTransition(updateCallback: () => void, options?: {
5
- skipPrefersReducedMotionCheck?: boolean;
6
- }): {
7
- finished: Promise<void>;
8
- };
9
- export declare function getDOMNodeFromNodeId(path: string, id: string): Element | null;
10
- export declare function getNodeType(element: HTMLElement): "element" | "component" | "text";
11
- /**
12
- * Somewhat convoluted function to calculate all possible drop insertion areas, as lines between elements.
13
- *
14
- * Drop locations follows the following rules:
15
- * - All lines for a single container are either horizontal or vertical (block or inline layout)
16
- * - If the next sibling of an element follows the expected layout (not wrapped) a line is drawn between the two (taking gap/margin into consideration),
17
- * - If the next sibling is wrapped, a line is drawn both after and before the next element. Both lines inserts the dragged element at the same index.
18
- */
19
- export declare function getInsertAreas(path: string): {
20
- point: {
21
- y: number;
22
- x: number;
23
- };
24
- layout: "block" | "inline";
25
- parent: Element;
26
- index: number;
27
- center: Point;
28
- size: number;
29
- direction: 1 | -1;
30
- }[];
31
- /**
32
- * Finds the nearest line to a given point from an array of lines.
33
- *
34
- * @param lines - An array of line segments defined by their endpoints.
35
- * @param point - The point to which the nearest line is to be found.
36
- * @returns The line segment nearest to the given point.
37
- */
38
- export declare function findNearestLine(lines: Line[], point: Point): {
39
- nearestLine: Line | null;
40
- dist: number;
41
- projectionPoint: number;
42
- };
@@ -1,205 +0,0 @@
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
- }
@@ -1,188 +0,0 @@
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
- }
@@ -1,16 +0,0 @@
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;
@@ -1,32 +0,0 @@
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
- }