@floegence/floe-webapp-core 0.90.1 → 0.90.3

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