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.
@@ -1,16 +1,16 @@
1
1
  var x = Object.defineProperty;
2
- var z = (d, r, e) => r in d ? x(d, r, { enumerable: !0, configurable: !0, writable: !0, value: e }) : d[r] = e;
3
- var g = (d, r, e) => (z(d, typeof r != "symbol" ? r + "" : r, e), e);
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 v = ".disabled{opacity:.3}";
6
- class b extends D {
5
+ const w = ".disabled{opacity:.3}";
6
+ class E extends D {
7
7
  constructor() {
8
8
  super();
9
- g(this, "className", "ReorderHandle");
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 v;
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 i = this.getDropzone(t);
47
- this.getAttribute("dropzone") || this.setAttribute("dropzone", i.localName);
48
- const a = t.getBoundingClientRect(), A = e - a.left, y = s - a.top;
49
- let o = document.createElement("div");
50
- o.classList.add("sortable-item"), o.style.visibility = "hidden", o.style.height = `${a.height}px`, t.classList.add("dragging"), t.style.position = "fixed", t.style.zIndex = "1000", t.style.width = `${a.width}px`;
51
- const h = (n, c) => {
52
- t.style.left = `${n - A - document.documentElement.scrollLeft}px`, t.style.top = `${c - y - document.documentElement.scrollTop}px`;
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
- h(e, s);
55
- const m = (n) => {
56
- var f;
57
- h(n.pageX, n.pageY);
58
- const c = this.getClosestDropzone(n.clientX, n.clientY);
59
- if (!c)
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 E = Array.from(c.children).filter((l) => l !== t && l !== o);
62
- for (const l of E) {
63
- const u = l.getBoundingClientRect();
64
- if (!((f = l.children[0]) != null && f.hasAttribute("locked")) && n.clientY > u.top && n.clientY < u.bottom) {
65
- n.clientY < u.top + u.height / 2 ? c.insertBefore(o, l) : c.insertBefore(o, l.nextSibling);
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
- }, p = () => {
70
- document.removeEventListener("mousemove", m), document.removeEventListener("mouseup", p), t.classList.remove("dragging"), t.style.position = "", t.style.zIndex = "", t.style.left = "", t.style.top = "", t.style.width = "";
71
- const n = o.parentElement;
72
- n.insertBefore(t, o), n.removeChild(o), this.reIndexItems(n);
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", m), document.addEventListener("mouseup", p), i.insertBefore(o, t);
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 = document.elementsFromPoint(e, s);
87
- for (const i of t)
88
- if (i.matches(this.getAttribute("dropzone")))
89
- return i;
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((i) => {
96
- var a;
97
- (a = i.children[0]) != null && a.hasAttribute("locked"), i.dataset.index = t, t++;
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
- b.define("wje-reorder-handle", b);
112
+ E.define("wje-reorder-handle", E);
102
113
  export {
103
- b as default
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.34",
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",