@floegence/floe-webapp-core 0.90.1 → 0.90.2

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,55 +1,93 @@
1
- import { createSignal as p, createEffect as M, onCleanup as P } from "solid-js";
2
- import { startPointerSession as X } from "./pointerSession.js";
3
- function C(o) {
4
- const [d, w] = p(), [h, b] = p(), [A, k] = p();
5
- let a, l, c = 0, s = 0, u = !1, m, f;
6
- const E = (e, r) => {
7
- const t = o.items().map((n) => n.id).filter((n) => n !== e), i = r ? t.indexOf(r) : t.length;
8
- return t.splice(i < 0 ? t.length : i, 0, e), t;
9
- }, y = () => {
10
- const e = o.items().filter((t) => t.id !== l), r = e.find((t) => {
11
- const i = o.elements.get(t.id)?.getBoundingClientRect();
12
- return i && c < i.left + i.width / 2;
1
+ import { createSignal as K, createEffect as Y, onCleanup as q } from "solid-js";
2
+ import { startPointerSession as I } from "./pointerSession.js";
3
+ function $(i) {
4
+ const [m, D] = K();
5
+ let c, g, s = [], R = [], f = 0, k = 0, T = 0, u = 1, l = 0, x = !1, p, h;
6
+ const w = /* @__PURE__ */ new Map(), A = (e) => {
7
+ delete e.dataset.floeTabMotion, e.style.removeProperty("--floe-tab-offset");
8
+ }, C = () => {
9
+ for (const [e, t] of w)
10
+ t.cancel(), A(e);
11
+ w.clear();
12
+ }, F = () => {
13
+ const e = i.container();
14
+ if (!e) return;
15
+ const t = e.getBoundingClientRect();
16
+ u = e.offsetWidth > 0 && t.width > 0 ? t.width / e.offsetWidth : 1, T = e.scrollLeft, s = i.items().flatMap((n) => {
17
+ const r = i.elements.get(n.id);
18
+ if (!r) return [];
19
+ const o = r.getBoundingClientRect();
20
+ return [{ id: n.id, element: r, left: (o.left - t.left) / u + T, width: o.width / u }];
13
21
  });
14
- b(r?.id), k(r ? void 0 : e.at(-1)?.id);
15
- }, R = () => {
16
- s = 0;
17
- const e = o.container();
18
- if (!d() || !e) return;
19
- const r = e.getBoundingClientRect(), t = c < r.left + 28 ? c - r.left - 28 : c > r.right - 28 ? c - r.right + 28 : 0;
20
- t && (e.scrollLeft += Math.sign(t) * Math.min(12, Math.abs(t) / 3)), y(), s = requestAnimationFrame(R);
21
- }, g = (e) => {
22
- e.key === "Escape" && (e.preventDefault(), e.stopPropagation(), a?.stop({ commit: !1 }));
23
- }, D = (e) => {
24
- const r = l, t = !!d(), i = r && t ? E(r, h()) : void 0;
25
- s && cancelAnimationFrame(s), s = 0, f?.defaultView?.removeEventListener("keydown", g, !0), a = void 0, l = void 0, w(void 0), b(void 0), k(void 0), t && (u = !0, m = setTimeout(() => {
26
- u = !1;
27
- }, 0)), e && i && i.join("\0") !== o.items().map((n) => n.id).join("\0") && o.onReorder()?.(i);
28
- }, L = (e, r) => {
29
- if (!o.onReorder() || r.disabled || e.button !== 0 || a || e.target?.closest('button, a, input, [contenteditable="true"]')) return;
30
- const t = e.clientX, i = e.clientY;
31
- l = r.id, c = t, f = e.currentTarget.ownerDocument, f.defaultView?.addEventListener("keydown", g, !0), a = X({
22
+ }, E = () => {
23
+ const e = i.container(), t = s.find((a) => a.id === g);
24
+ if (!e || !t) return;
25
+ const n = s[0], r = s.at(-1), o = Math.max(n.left, Math.min(
26
+ r.left + r.width - t.width,
27
+ t.left + (f - k) / u + e.scrollLeft - T
28
+ )), b = o + t.width / 2, y = s.filter((a) => a !== t), M = y.findIndex((a) => b < a.left + a.width / 2), d = [...y];
29
+ d.splice(M < 0 ? y.length : M, 0, t), R = d.map((a) => a.id);
30
+ const S = s.length > 1 ? s[1].left - n.left - n.width : 0;
31
+ let B = n.left;
32
+ for (const a of d)
33
+ a.element.dataset.floeTabMotion = a === t ? "dragging" : "neighbor", a.element.style.setProperty("--floe-tab-offset", `${(a === t ? o : B) - a.left}px`), B += a.width + S;
34
+ }, P = () => {
35
+ l = 0;
36
+ const e = i.container();
37
+ if (!m() || !e) return;
38
+ const t = e.getBoundingClientRect(), n = f < t.left + 28 ? f - t.left - 28 : f > t.right - 28 ? f - t.right + 28 : 0;
39
+ n && (e.scrollLeft += Math.sign(n) * Math.min(12, Math.abs(n) / 3) / u), E(), l = requestAnimationFrame(P);
40
+ }, L = (e) => {
41
+ e.key === "Escape" && (e.preventDefault(), e.stopPropagation(), c?.stop({ commit: !1 }));
42
+ }, V = (e) => {
43
+ const t = !!m();
44
+ l && cancelAnimationFrame(l), l = 0, t && E();
45
+ const n = s.map((r) => ({ element: r.element, rect: r.element.getBoundingClientRect() }));
46
+ h?.defaultView?.removeEventListener("keydown", L, !0), c = void 0, g = void 0, D(void 0), e && t && R.join("\0") !== i.items().map((r) => r.id).join("\0") && i.onReorder()?.(R);
47
+ for (const { element: r } of n) A(r);
48
+ if (t && (x = !0, p !== void 0 && clearTimeout(p), p = setTimeout(() => {
49
+ x = !1;
50
+ }, 0), !h?.defaultView?.matchMedia?.("(prefers-reduced-motion: reduce)").matches))
51
+ for (const { element: o, rect: b } of n) {
52
+ if (!o.isConnected || typeof o.animate != "function") continue;
53
+ const y = o.getBoundingClientRect(), M = (b.left - y.left) / u;
54
+ if (Math.abs(M) < 0.5) continue;
55
+ o.dataset.floeTabMotion = "settling";
56
+ const d = o.animate([
57
+ { transform: `translate3d(${M}px, 0, 0)` },
58
+ { transform: "translate3d(0, 0, 0)" }
59
+ ], { duration: 180, easing: "cubic-bezier(0.22, 1, 0.36, 1)" });
60
+ w.set(o, d), d.onfinish = () => {
61
+ w.get(o) === d && (w.delete(o), A(o));
62
+ };
63
+ }
64
+ s = [], R = [];
65
+ }, X = (e, t) => {
66
+ if (!i.onReorder() || t.disabled || e.button !== 0 || c || e.target?.closest('button, a, input, [contenteditable="true"]')) return;
67
+ C(), k = e.clientX;
68
+ const n = e.clientY;
69
+ g = t.id, f = k, h = e.currentTarget.ownerDocument, h.defaultView?.addEventListener("keydown", L, !0), c = I({
32
70
  pointerEvent: e,
33
71
  captureEl: e.currentTarget,
34
72
  capturePointer: !1,
35
- onMove: (n) => {
36
- c = n.clientX, !(!d() && Math.hypot(n.clientX - t, n.clientY - i) < 5) && (d() || (w(r.id), a?.capturePointer()), n.preventDefault(), y(), s || (s = requestAnimationFrame(R)));
73
+ onMove: (r) => {
74
+ f = r.clientX, !(!m() && Math.hypot(r.clientX - k, r.clientY - n) < 5) && (m() || (F(), D(t.id), c?.capturePointer()), r.preventDefault(), E(), l || (l = requestAnimationFrame(P)));
37
75
  },
38
- onEnd: (n) => D(n.commit && (n.reason === "pointer_up" || n.reason === "buttons_released"))
76
+ onEnd: (r) => V(r.commit && (r.reason === "pointer_up" || r.reason === "buttons_released"))
39
77
  });
40
- }, T = (e, r) => {
41
- if (!o.onReorder() || r.disabled || !e.altKey || !e.shiftKey || !["ArrowLeft", "ArrowRight"].includes(e.key)) return !1;
42
- e.preventDefault(), e.stopPropagation();
43
- const t = o.items().map((F) => F.id), i = t.indexOf(r.id), n = i + (e.key === "ArrowLeft" ? -1 : 1);
44
- return n >= 0 && n < t.length && ([t[i], t[n]] = [t[n], t[i]], o.onReorder()?.(t), o.elements.get(r.id)?.focus({ preventScroll: !0 }), o.elements.get(r.id)?.scrollIntoView({ block: "nearest", inline: "nearest" })), !0;
78
+ }, j = (e, t) => {
79
+ if (!i.onReorder() || t.disabled || !e.altKey || !e.shiftKey || !["ArrowLeft", "ArrowRight"].includes(e.key)) return !1;
80
+ e.preventDefault(), e.stopPropagation(), C();
81
+ const n = i.items().map((b) => b.id), r = n.indexOf(t.id), o = r + (e.key === "ArrowLeft" ? -1 : 1);
82
+ return o >= 0 && o < n.length && ([n[r], n[o]] = [n[o], n[r]], i.onReorder()?.(n), i.elements.get(t.id)?.focus({ preventScroll: !0 }), i.elements.get(t.id)?.scrollIntoView({ block: "nearest", inline: "nearest" })), !0;
45
83
  };
46
- return M(() => {
47
- const e = o.items(), r = o.onReorder();
48
- l && (!r || !e.some((t) => t.id === l && !t.disabled)) && a?.stop({ commit: !1 });
49
- }), P(() => {
50
- a?.stop({ commit: !1 }), s && cancelAnimationFrame(s), m !== void 0 && clearTimeout(m), f?.defaultView?.removeEventListener("keydown", g, !0);
51
- }), { start: L, keyDown: T, dragging: d, before: h, after: A, suppressClick: () => u };
84
+ return Y(() => {
85
+ const e = i.items(), t = i.onReorder();
86
+ g && (!t || !e.some((n) => n.id === g && !n.disabled) || s.length && e.map((n) => n.id).join("\0") !== s.map((n) => n.id).join("\0")) && c?.stop({ commit: !1 });
87
+ }), q(() => {
88
+ c?.stop({ commit: !1 }), C(), l && cancelAnimationFrame(l), p !== void 0 && clearTimeout(p), h?.defaultView?.removeEventListener("keydown", L, !0);
89
+ }), { start: X, keyDown: j, dragging: m, suppressClick: () => x };
52
90
  }
53
91
  export {
54
- C as createTabReorder
92
+ $ as createTabReorder
55
93
  };