@nookuio/iframe 1.0.0 → 1.0.2-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.
- package/dist/constants.d.ts +9 -0
- package/dist/constants.js +11 -2
- package/dist/constants.mjs +9 -1
- package/dist/drag-drop/dragEnd.d.ts +2 -0
- package/dist/drag-drop/dragEnd.js +27 -0
- package/dist/drag-drop/dragEnd.mjs +23 -0
- package/dist/drag-drop/dragMove.d.ts +2 -0
- package/dist/drag-drop/dragMove.js +46 -0
- package/dist/drag-drop/dragMove.mjs +40 -0
- package/dist/drag-drop/dragReorder.d.ts +3 -0
- package/dist/drag-drop/dragReorder.js +60 -0
- package/dist/drag-drop/dragReorder.mjs +64 -0
- package/dist/drag-drop/dragStart.d.ts +9 -0
- package/dist/drag-drop/dragStart.js +60 -0
- package/dist/drag-drop/dragStart.mjs +55 -0
- package/dist/drag-drop/helpers.d.ts +42 -0
- package/dist/drag-drop/helpers.js +205 -0
- package/dist/drag-drop/helpers.mjs +188 -0
- package/dist/drag-drop/highlight.d.ts +19 -0
- package/dist/drag-drop/highlight.js +34 -0
- package/dist/drag-drop/highlight.mjs +21 -0
- package/dist/drag-drop/index.d.ts +24 -0
- package/dist/drag-drop/index.js +106 -0
- package/dist/drag-drop/index.mjs +83 -0
- package/dist/drag-drop/types.d.ts +123 -0
- package/dist/drag-drop/types.js +1 -0
- package/dist/drag-drop/types.mjs +0 -0
- package/dist/drag-drop backup/dragDropManager.d.ts +101 -0
- package/dist/drag-drop backup/dragDropManager.js +204 -0
- package/dist/drag-drop backup/dragDropManager.mjs +183 -0
- package/dist/drag-drop backup/index.d.ts +3 -0
- package/dist/drag-drop backup/index.js +38 -0
- package/dist/drag-drop backup/index.mjs +3 -0
- package/dist/drag-drop backup/types.d.ts +80 -0
- package/dist/drag-drop backup/types.js +1 -0
- package/dist/drag-drop backup/types.mjs +0 -0
- package/dist/drag-drop backup/utils.d.ts +41 -0
- package/dist/drag-drop backup/utils.js +93 -0
- package/dist/drag-drop backup/utils.mjs +68 -0
- package/dist/editor.d.ts +1 -7
- package/dist/editor.js +2 -2
- package/dist/editor.mjs +1 -1
- package/dist/iframe.d.ts +2 -8
- package/dist/iframe.js +46 -43
- package/dist/iframe.mjs +48 -46
- package/dist/types.d.ts +17 -3
- package/package.json +3 -2
- package/dist/createClient.d.ts +0 -51
- package/dist/createClient.js +0 -118
- package/dist/createClient.mjs +0 -114
package/dist/constants.d.ts
CHANGED
|
@@ -6,3 +6,12 @@ export declare const COMPONENT_PREVIEW_PAGE_PATH = "/__nooku__/component-preview
|
|
|
6
6
|
export declare const VIRTUAL_VUE_SFC_RENDERER_PAGE_PATH = "/__nooku__/virtual-sfc-editor";
|
|
7
7
|
export declare const IFRAME_SOURCE_NAME = "nooku-frame";
|
|
8
8
|
export declare const EDITOR_SOURCE_NAME = "nooku-editor";
|
|
9
|
+
export declare const ATTRIBUTES: {
|
|
10
|
+
id: string;
|
|
11
|
+
path: string;
|
|
12
|
+
type: string;
|
|
13
|
+
index: string;
|
|
14
|
+
component: string;
|
|
15
|
+
forceRender: string;
|
|
16
|
+
selected: string;
|
|
17
|
+
};
|
package/dist/constants.js
CHANGED
|
@@ -3,9 +3,18 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.VIRTUAL_VUE_SFC_RENDERER_PAGE_PATH = exports.IFRAME_SOURCE_NAME = exports.EDITOR_SOURCE_NAME = exports.EDITOR_PAGE_PATH = exports.COMPONENT_PREVIEW_PAGE_PATH = void 0;
|
|
6
|
+
exports.VIRTUAL_VUE_SFC_RENDERER_PAGE_PATH = exports.IFRAME_SOURCE_NAME = exports.EDITOR_SOURCE_NAME = exports.EDITOR_PAGE_PATH = exports.COMPONENT_PREVIEW_PAGE_PATH = exports.ATTRIBUTES = void 0;
|
|
7
7
|
const EDITOR_PAGE_PATH = exports.EDITOR_PAGE_PATH = "/__nooku__/editor",
|
|
8
8
|
COMPONENT_PREVIEW_PAGE_PATH = exports.COMPONENT_PREVIEW_PAGE_PATH = "/__nooku__/component-preview",
|
|
9
9
|
VIRTUAL_VUE_SFC_RENDERER_PAGE_PATH = exports.VIRTUAL_VUE_SFC_RENDERER_PAGE_PATH = "/__nooku__/virtual-sfc-editor",
|
|
10
10
|
IFRAME_SOURCE_NAME = exports.IFRAME_SOURCE_NAME = "nooku-frame",
|
|
11
|
-
EDITOR_SOURCE_NAME = exports.EDITOR_SOURCE_NAME = "nooku-editor"
|
|
11
|
+
EDITOR_SOURCE_NAME = exports.EDITOR_SOURCE_NAME = "nooku-editor",
|
|
12
|
+
ATTRIBUTES = exports.ATTRIBUTES = {
|
|
13
|
+
id: "data-node-id",
|
|
14
|
+
path: "data-node-path",
|
|
15
|
+
type: "data-node-type",
|
|
16
|
+
index: "data-node-index",
|
|
17
|
+
component: "data-node-component",
|
|
18
|
+
forceRender: "data-node-force-render",
|
|
19
|
+
selected: "data-node-selected"
|
|
20
|
+
};
|
package/dist/constants.mjs
CHANGED
|
@@ -1 +1,9 @@
|
|
|
1
|
-
export const EDITOR_PAGE_PATH = "/__nooku__/editor", COMPONENT_PREVIEW_PAGE_PATH = "/__nooku__/component-preview", VIRTUAL_VUE_SFC_RENDERER_PAGE_PATH = "/__nooku__/virtual-sfc-editor", IFRAME_SOURCE_NAME = "nooku-frame", EDITOR_SOURCE_NAME = "nooku-editor"
|
|
1
|
+
export const EDITOR_PAGE_PATH = "/__nooku__/editor", COMPONENT_PREVIEW_PAGE_PATH = "/__nooku__/component-preview", VIRTUAL_VUE_SFC_RENDERER_PAGE_PATH = "/__nooku__/virtual-sfc-editor", IFRAME_SOURCE_NAME = "nooku-frame", EDITOR_SOURCE_NAME = "nooku-editor", ATTRIBUTES = {
|
|
2
|
+
id: "data-node-id",
|
|
3
|
+
path: "data-node-path",
|
|
4
|
+
type: "data-node-type",
|
|
5
|
+
index: "data-node-index",
|
|
6
|
+
component: "data-node-component",
|
|
7
|
+
forceRender: "data-node-force-render",
|
|
8
|
+
selected: "data-node-selected"
|
|
9
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.dragEnded = dragEnded;
|
|
7
|
+
var _helpers = require("./helpers");
|
|
8
|
+
var _ = require("./");
|
|
9
|
+
var _highlight = require("./highlight");
|
|
10
|
+
async function dragEnded(e, o) {
|
|
11
|
+
e.destroying = !0;
|
|
12
|
+
const t = e.insertAreas?.[e.selectedInsertAreaIndex ?? -1],
|
|
13
|
+
n = (e.mode === "insert" && !o ? t?.parent : e.initialContainer)?.querySelectorAll(`[data-node-id][data-node-path="${e.elementPath}"]`) ?? [];
|
|
14
|
+
e.element.style.setProperty("view-transition-name", "dropped-item-self"), n.forEach((r, i) => {
|
|
15
|
+
r instanceof HTMLElement && (0, _helpers.isElementInViewport)(r) && r.style.setProperty("view-transition-name", "dropped-item-sibling-" + i);
|
|
16
|
+
}), e.repeatedNodes.filter(_helpers.isElementInViewport).forEach((r, i) => {
|
|
17
|
+
r.style.setProperty("view-transition-name", "dropped-item-repeated-" + i);
|
|
18
|
+
}), await (0, _helpers.tryStartViewTransition)(() => {
|
|
19
|
+
o ? (e.copy?.remove(), e.initialContainer.insertBefore(e.element, e.initialNextSibling)) : e.mode === "insert" && t?.parent.insertBefore(e.element, t.parent.childNodes[t.index]), e.element.classList.remove(_.DRAG_REORDER_CLASSNAME), e.element.classList.remove(_.DRAG_MOVE_CLASSNAME), e.element.style.removeProperty("translate"), e.repeatedNodes.toReversed().forEach(r => {
|
|
20
|
+
e.element.insertAdjacentElement("afterend", r), r.classList.remove("drag-repeat-node"), r.style.removeProperty("rotate"), r.style.removeProperty("--drag-repeat-node-width"), r.style.removeProperty("--drag-repeat-node-height"), r.style.removeProperty("--drag-repeat-node-translate"), r.style.removeProperty("--drag-repeat-node-rotate"), r.style.removeProperty("--drag-repeat-node-opacity");
|
|
21
|
+
}), (0, _highlight.removeDropHighlight)();
|
|
22
|
+
}).finished.then(() => {
|
|
23
|
+
e.element.style.removeProperty("view-transition-name"), n.forEach(r => {
|
|
24
|
+
r instanceof HTMLElement && r.style.removeProperty("view-transition-name");
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { isElementInViewport as s, tryStartViewTransition as l } from "./helpers.mjs";
|
|
2
|
+
import { DRAG_MOVE_CLASSNAME as m, DRAG_REORDER_CLASSNAME as p } from ".//index.mjs";
|
|
3
|
+
import { removeDropHighlight as a } from "./highlight.mjs";
|
|
4
|
+
export async function dragEnded(e, o) {
|
|
5
|
+
e.destroying = !0;
|
|
6
|
+
const t = e.insertAreas?.[e.selectedInsertAreaIndex ?? -1], n = (e.mode === "insert" && !o ? t?.parent : e.initialContainer)?.querySelectorAll(`[data-node-id][data-node-path="${e.elementPath}"]`) ?? [];
|
|
7
|
+
e.element.style.setProperty("view-transition-name", "dropped-item-self"), n.forEach((r, i) => {
|
|
8
|
+
r instanceof HTMLElement && s(r) && r.style.setProperty("view-transition-name", "dropped-item-sibling-" + i);
|
|
9
|
+
}), e.repeatedNodes.filter(s).forEach((r, i) => {
|
|
10
|
+
r.style.setProperty("view-transition-name", "dropped-item-repeated-" + i);
|
|
11
|
+
}), await l(() => {
|
|
12
|
+
o ? (e.copy?.remove(), e.initialContainer.insertBefore(e.element, e.initialNextSibling)) : e.mode === "insert" && t?.parent.insertBefore(
|
|
13
|
+
e.element,
|
|
14
|
+
t.parent.childNodes[t.index]
|
|
15
|
+
), e.element.classList.remove(p), e.element.classList.remove(m), e.element.style.removeProperty("translate"), e.repeatedNodes.toReversed().forEach((r) => {
|
|
16
|
+
e.element.insertAdjacentElement("afterend", r), r.classList.remove("drag-repeat-node"), r.style.removeProperty("rotate"), r.style.removeProperty("--drag-repeat-node-width"), r.style.removeProperty("--drag-repeat-node-height"), r.style.removeProperty("--drag-repeat-node-translate"), r.style.removeProperty("--drag-repeat-node-rotate"), r.style.removeProperty("--drag-repeat-node-opacity");
|
|
17
|
+
}), a();
|
|
18
|
+
}).finished.then(() => {
|
|
19
|
+
e.element.style.removeProperty("view-transition-name"), n.forEach((r) => {
|
|
20
|
+
r instanceof HTMLElement && r.style.removeProperty("view-transition-name");
|
|
21
|
+
});
|
|
22
|
+
});
|
|
23
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.dragMove = dragMove;
|
|
7
|
+
var _ = require("./");
|
|
8
|
+
var _highlight = require("./highlight");
|
|
9
|
+
var _helpers = require("./helpers");
|
|
10
|
+
function dragMove(e, m) {
|
|
11
|
+
if (!e) return;
|
|
12
|
+
if (e.mode === "reorder") {
|
|
13
|
+
e.mode = "insert", e.element.style.setProperty("display", "none"), e.insertAreas ??= (0, _helpers.getInsertAreas)(e.elementPath).filter(s => m.every(i => !i?.contains(s.parent) && i !== s.parent) && s.parent !== document.body), e.element.style.removeProperty("display");
|
|
14
|
+
const t = e.element.style.getPropertyValue("translate");
|
|
15
|
+
e.element.style.setProperty("translate", "0");
|
|
16
|
+
const n = e.element.getBoundingClientRect();
|
|
17
|
+
document.body.appendChild(e.element), e.element.classList.add(_.DRAG_MOVE_CLASSNAME), e.element.classList.remove(_.DRAG_REORDER_CLASSNAME), e.element.style.setProperty("--drag-mode--move-left", `${n.left}px`), e.element.style.setProperty("--drag-mode--move-top", `${n.top}px`), e.element.style.setProperty("--drag-mode--move-width", `${e.initialRect.width}px`), e.element.style.setProperty("translate", t);
|
|
18
|
+
}
|
|
19
|
+
e.repeatedNodes.forEach((t, n) => {
|
|
20
|
+
t.style.setProperty("--drag-repeat-node-opacity", n < 3 ? "0.2" : "0");
|
|
21
|
+
});
|
|
22
|
+
const o = e.insertAreas?.map(t => t.layout === "block" ? {
|
|
23
|
+
x1: t.center.x - t.size / 2,
|
|
24
|
+
y1: t.center.y,
|
|
25
|
+
x2: t.center.x + t.size / 2,
|
|
26
|
+
y2: t.center.y
|
|
27
|
+
} : {
|
|
28
|
+
x1: t.center.x,
|
|
29
|
+
y1: t.center.y - t.size / 2,
|
|
30
|
+
x2: t.center.x,
|
|
31
|
+
y2: t.center.y + t.size / 2
|
|
32
|
+
}),
|
|
33
|
+
{
|
|
34
|
+
nearestLine: l,
|
|
35
|
+
projectionPoint: p
|
|
36
|
+
} = (0, _helpers.findNearestLine)(o ?? [], e.lastCursorPosition);
|
|
37
|
+
if (!l || !e.insertAreas || !o) return;
|
|
38
|
+
const r = e.insertAreas.at(o.indexOf(l));
|
|
39
|
+
r ? (e.selectedInsertAreaIndex = e.insertAreas?.indexOf(r), (0, _highlight.setExternalDropHighlight)({
|
|
40
|
+
layout: r.layout,
|
|
41
|
+
center: r.center,
|
|
42
|
+
length: r.size,
|
|
43
|
+
color: e.elementType === "component" ? "D946EF" : "2563EB",
|
|
44
|
+
projectionPoint: p
|
|
45
|
+
})) : (0, _highlight.removeDropHighlight)();
|
|
46
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { DRAG_REORDER_CLASSNAME as y, DRAG_MOVE_CLASSNAME as c } from ".//index.mjs";
|
|
2
|
+
import { removeDropHighlight as f, setExternalDropHighlight as A } from "./highlight.mjs";
|
|
3
|
+
import { getInsertAreas as u, findNearestLine as x } from "./helpers.mjs";
|
|
4
|
+
export function dragMove(e, m) {
|
|
5
|
+
if (!e)
|
|
6
|
+
return;
|
|
7
|
+
if (e.mode === "reorder") {
|
|
8
|
+
e.mode = "insert", e.element.style.setProperty("display", "none"), e.insertAreas ??= u(e.elementPath).filter(
|
|
9
|
+
(s) => m.every((i) => !i?.contains(s.parent) && i !== s.parent) && s.parent !== document.body
|
|
10
|
+
), e.element.style.removeProperty("display");
|
|
11
|
+
const t = e.element.style.getPropertyValue("translate");
|
|
12
|
+
e.element.style.setProperty("translate", "0");
|
|
13
|
+
const n = e.element.getBoundingClientRect();
|
|
14
|
+
document.body.appendChild(e.element), e.element.classList.add(c), e.element.classList.remove(y), e.element.style.setProperty("--drag-mode--move-left", `${n.left}px`), e.element.style.setProperty("--drag-mode--move-top", `${n.top}px`), e.element.style.setProperty("--drag-mode--move-width", `${e.initialRect.width}px`), e.element.style.setProperty("translate", t);
|
|
15
|
+
}
|
|
16
|
+
e.repeatedNodes.forEach((t, n) => {
|
|
17
|
+
t.style.setProperty("--drag-repeat-node-opacity", n < 3 ? "0.2" : "0");
|
|
18
|
+
});
|
|
19
|
+
const o = e.insertAreas?.map((t) => t.layout === "block" ? {
|
|
20
|
+
x1: t.center.x - t.size / 2,
|
|
21
|
+
y1: t.center.y,
|
|
22
|
+
x2: t.center.x + t.size / 2,
|
|
23
|
+
y2: t.center.y
|
|
24
|
+
} : {
|
|
25
|
+
x1: t.center.x,
|
|
26
|
+
y1: t.center.y - t.size / 2,
|
|
27
|
+
x2: t.center.x,
|
|
28
|
+
y2: t.center.y + t.size / 2
|
|
29
|
+
}), { nearestLine: l, projectionPoint: p } = x(o ?? [], e.lastCursorPosition);
|
|
30
|
+
if (!l || !e.insertAreas || !o)
|
|
31
|
+
return;
|
|
32
|
+
const r = e.insertAreas.at(o.indexOf(l));
|
|
33
|
+
r ? (e.selectedInsertAreaIndex = e.insertAreas?.indexOf(r), A({
|
|
34
|
+
layout: r.layout,
|
|
35
|
+
center: r.center,
|
|
36
|
+
length: r.size,
|
|
37
|
+
color: e.elementType === "component" ? "D946EF" : "2563EB",
|
|
38
|
+
projectionPoint: p
|
|
39
|
+
})) : f();
|
|
40
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.DRAG_REORDER_CLASSNAME = void 0;
|
|
7
|
+
exports.dragReorder = dragReorder;
|
|
8
|
+
var _helpers = require("./helpers");
|
|
9
|
+
var _ = require("./");
|
|
10
|
+
var _highlight = require("./highlight");
|
|
11
|
+
const DRAG_REORDER_CLASSNAME = exports.DRAG_REORDER_CLASSNAME = "__drag-mode--reorder";
|
|
12
|
+
const c = 100;
|
|
13
|
+
function dragReorder(e) {
|
|
14
|
+
if (!e || e.isTransitioning) return;
|
|
15
|
+
if (e.mode === "insert") {
|
|
16
|
+
e.mode = "reorder";
|
|
17
|
+
const o = e.element.getBoundingClientRect();
|
|
18
|
+
e.element.classList.add(DRAG_REORDER_CLASSNAME), e.element.classList.remove(_.DRAG_MOVE_CLASSNAME), e.initialContainer.insertBefore(e.element, e.initialNextSibling), e.repeatedNodes.forEach((r, l) => {
|
|
19
|
+
r.style.setProperty("--drag-repeat-node-opacity", l < 3 ? "1" : "0");
|
|
20
|
+
});
|
|
21
|
+
const s = e.element.getBoundingClientRect();
|
|
22
|
+
e.offset.x += s.left - o.left, e.offset.y += s.top - o.top, (0, _highlight.setDropHighlight)(e.element, e.initialContainer, e.elementType === "component" ? "D946EF" : "2563EB");
|
|
23
|
+
}
|
|
24
|
+
const f = T(e);
|
|
25
|
+
if (f && e.element.nextElementSibling !== f.nextSibling) {
|
|
26
|
+
e.isTransitioning = !0;
|
|
27
|
+
const o = Array.from(e.initialContainer.childNodes);
|
|
28
|
+
o.filter(t => t instanceof HTMLElement).filter(_helpers.isElementInViewport).forEach((t, i) => {
|
|
29
|
+
t.style.setProperty("view-transition-name", "item-" + i);
|
|
30
|
+
}), e.element.style.setProperty("view-transition-name", "__drag-item");
|
|
31
|
+
const s = e.element.offsetLeft,
|
|
32
|
+
r = e.element.offsetTop;
|
|
33
|
+
(0, _helpers.tryStartViewTransition)(() => {
|
|
34
|
+
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("translate", `${e.lastCursorPosition.x - e.offset.x}px ${e.lastCursorPosition.y - e.offset.y}px`), (0, _highlight.setDropHighlight)(e.element, e.initialContainer, e.elementType === "component" ? "D946EF" : "2563EB"));
|
|
35
|
+
}).finished.then(() => {
|
|
36
|
+
o.forEach(t => {
|
|
37
|
+
t instanceof HTMLElement && t.style.removeProperty("view-transition-name");
|
|
38
|
+
}), e && (e.isTransitioning = !1);
|
|
39
|
+
}).catch(() => {});
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
function T(e) {
|
|
43
|
+
const {
|
|
44
|
+
left: f,
|
|
45
|
+
top: o,
|
|
46
|
+
width: s,
|
|
47
|
+
height: r
|
|
48
|
+
} = e.element.getBoundingClientRect(),
|
|
49
|
+
l = f + s / 2,
|
|
50
|
+
t = o + r / 2;
|
|
51
|
+
return e.reorderPermutations.reduce((i, n) => {
|
|
52
|
+
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) {
|
|
53
|
+
if (!i) return n;
|
|
54
|
+
const p = Math.hypot(i.rect.left + i.rect.width / 2 - l, i.rect.top + i.rect.height / 2 - t),
|
|
55
|
+
h = Math.hypot(n.rect.left + n.rect.width / 2 - l, n.rect.top + n.rect.height / 2 - t);
|
|
56
|
+
return p < h ? i : n;
|
|
57
|
+
}
|
|
58
|
+
return i;
|
|
59
|
+
}, null);
|
|
60
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
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;
|
|
@@ -0,0 +1,60 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
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
|
+
};
|