wj-elements 0.1.34 → 0.1.35
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/wje-reorder-handle.js +49 -38
- package/package.json +1 -1
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
var x = Object.defineProperty;
|
|
2
|
-
var z = (
|
|
3
|
-
var
|
|
2
|
+
var z = (c, l, e) => l in c ? x(c, l, { enumerable: !0, configurable: !0, writable: !0, value: e }) : c[l] = e;
|
|
3
|
+
var A = (c, l, e) => (z(c, typeof l != "symbol" ? l + "" : l, e), e);
|
|
4
4
|
import D from "./wje-element.js";
|
|
5
|
-
const
|
|
6
|
-
class
|
|
5
|
+
const w = ".disabled{opacity:.3}";
|
|
6
|
+
class E extends D {
|
|
7
7
|
constructor() {
|
|
8
8
|
super();
|
|
9
|
-
|
|
9
|
+
A(this, "className", "ReorderHandle");
|
|
10
10
|
this.addEventListener("mousedown", this.startDrag.bind(this)), this.addEventListener("touchstart", this.startTouchDrag.bind(this));
|
|
11
11
|
}
|
|
12
12
|
static get cssStyleSheet() {
|
|
13
|
-
return
|
|
13
|
+
return w;
|
|
14
14
|
}
|
|
15
15
|
static get observedAttributes() {
|
|
16
16
|
return ["dropzone", "parent"];
|
|
@@ -43,35 +43,35 @@ class b extends D {
|
|
|
43
43
|
t = this.closest(n);
|
|
44
44
|
} else
|
|
45
45
|
t = this.parentElement;
|
|
46
|
-
const
|
|
47
|
-
this.getAttribute("dropzone") || this.setAttribute("dropzone",
|
|
48
|
-
const
|
|
49
|
-
let
|
|
50
|
-
|
|
51
|
-
const
|
|
52
|
-
t.style.left = `${n -
|
|
46
|
+
const o = this.getDropzone(t);
|
|
47
|
+
this.getAttribute("dropzone") || this.setAttribute("dropzone", o.localName);
|
|
48
|
+
const r = t.getBoundingClientRect(), h = e - r.left, u = s - r.top;
|
|
49
|
+
let i = document.createElement("div");
|
|
50
|
+
i.classList.add("sortable-item"), i.style.visibility = "hidden", i.style.height = `${r.height}px`, t.classList.add("dragging"), t.style.position = "fixed", t.style.zIndex = "1000", t.style.width = `${r.width}px`;
|
|
51
|
+
const p = (n, d) => {
|
|
52
|
+
t.style.left = `${n - h - document.documentElement.scrollLeft}px`, t.style.top = `${d - u - document.documentElement.scrollTop}px`;
|
|
53
53
|
};
|
|
54
|
-
|
|
55
|
-
const
|
|
56
|
-
var
|
|
57
|
-
|
|
58
|
-
const
|
|
59
|
-
if (!
|
|
54
|
+
p(e, s);
|
|
55
|
+
const f = (n) => {
|
|
56
|
+
var b;
|
|
57
|
+
p(n.pageX, n.pageY);
|
|
58
|
+
const d = this.getClosestDropzone(n.clientX, n.clientY);
|
|
59
|
+
if (!d)
|
|
60
60
|
return;
|
|
61
|
-
const
|
|
62
|
-
for (const
|
|
63
|
-
const
|
|
64
|
-
if (!((
|
|
65
|
-
n.clientY <
|
|
61
|
+
const y = Array.from(d.children).filter((a) => a !== t && a !== i);
|
|
62
|
+
for (const a of y) {
|
|
63
|
+
const m = a.getBoundingClientRect();
|
|
64
|
+
if (!((b = a.children[0]) != null && b.hasAttribute("locked")) && n.clientY > m.top && n.clientY < m.bottom) {
|
|
65
|
+
n.clientY < m.top + m.height / 2 ? d.insertBefore(i, a) : d.insertBefore(i, a.nextSibling);
|
|
66
66
|
break;
|
|
67
67
|
}
|
|
68
68
|
}
|
|
69
|
-
},
|
|
70
|
-
document.removeEventListener("mousemove",
|
|
71
|
-
const n =
|
|
72
|
-
n.insertBefore(t,
|
|
69
|
+
}, g = () => {
|
|
70
|
+
document.removeEventListener("mousemove", f), document.removeEventListener("mouseup", g), t.classList.remove("dragging"), t.style.position = "", t.style.zIndex = "", t.style.left = "", t.style.top = "", t.style.width = "";
|
|
71
|
+
const n = i.parentElement;
|
|
72
|
+
n.insertBefore(t, i), n.removeChild(i), this.reIndexItems(n);
|
|
73
73
|
};
|
|
74
|
-
document.addEventListener("mousemove",
|
|
74
|
+
document.addEventListener("mousemove", f), document.addEventListener("mouseup", g), o.insertBefore(i, t);
|
|
75
75
|
}
|
|
76
76
|
getDropzone(e) {
|
|
77
77
|
const s = this.getAttribute("dropzone");
|
|
@@ -83,22 +83,33 @@ class b extends D {
|
|
|
83
83
|
return e.parentElement;
|
|
84
84
|
}
|
|
85
85
|
getClosestDropzone(e, s) {
|
|
86
|
-
const t =
|
|
87
|
-
for (const
|
|
88
|
-
if (
|
|
89
|
-
return
|
|
86
|
+
const t = this.getElementsFromPointAll(e, s);
|
|
87
|
+
for (const o of t)
|
|
88
|
+
if (o.matches(this.getAttribute("dropzone")))
|
|
89
|
+
return o;
|
|
90
90
|
return null;
|
|
91
91
|
}
|
|
92
|
+
// Rekurzívne prechádza všetky shadow roots bez opakovania elementov
|
|
93
|
+
getElementsFromPointAll(e, s, t = document, o = /* @__PURE__ */ new Set()) {
|
|
94
|
+
if (o.has(t))
|
|
95
|
+
return [];
|
|
96
|
+
o.add(t);
|
|
97
|
+
const r = t.elementsFromPoint(e, s);
|
|
98
|
+
let h = [...r];
|
|
99
|
+
for (const u of r)
|
|
100
|
+
u.shadowRoot && !o.has(u.shadowRoot) && (h = h.concat(this.getElementsFromPointAll(e, s, u.shadowRoot, o)));
|
|
101
|
+
return h;
|
|
102
|
+
}
|
|
92
103
|
reIndexItems(e) {
|
|
93
104
|
const s = Array.from(e.children);
|
|
94
105
|
let t = 0;
|
|
95
|
-
s.forEach((
|
|
96
|
-
var
|
|
97
|
-
(
|
|
106
|
+
s.forEach((o) => {
|
|
107
|
+
var r;
|
|
108
|
+
(r = o.children[0]) != null && r.hasAttribute("locked"), o.dataset.index = t, t++;
|
|
98
109
|
});
|
|
99
110
|
}
|
|
100
111
|
}
|
|
101
|
-
|
|
112
|
+
E.define("wje-reorder-handle", E);
|
|
102
113
|
export {
|
|
103
|
-
|
|
114
|
+
E as default
|
|
104
115
|
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "wj-elements",
|
|
3
3
|
"description": "WebJET Elements is a modern set of user interface tools harnessing the power of web components designed to simplify web application development.",
|
|
4
|
-
"version": "0.1.
|
|
4
|
+
"version": "0.1.35",
|
|
5
5
|
"homepage": "https://github.com/lencys/wj-elements",
|
|
6
6
|
"author": "Lukáš Ondrejček <lukas.ondrejcek@gmail.com>",
|
|
7
7
|
"license": "MIT",
|