@floegence/floe-webapp-core 0.90.2 → 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,93 +1,98 @@
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) => {
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
7
  delete e.dataset.floeTabMotion, e.style.removeProperty("--floe-tab-offset");
8
8
  }, C = () => {
9
- for (const [e, t] of w)
9
+ for (const [e, t] of b)
10
10
  t.cancel(), A(e);
11
- w.clear();
12
- }, F = () => {
11
+ b.clear();
12
+ }, X = () => {
13
13
  const e = i.container();
14
14
  if (!e) return;
15
15
  const t = e.getBoundingClientRect();
16
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 }];
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 }];
21
21
  });
22
22
  }, E = () => {
23
- const e = i.container(), t = s.find((a) => a.id === g);
23
+ const e = i.container(), t = s.find((a) => a.id === p);
24
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 = () => {
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 = () => {
35
40
  l = 0;
36
41
  const e = i.container();
37
- if (!m() || !e) return;
42
+ if (!g() || !e) return;
38
43
  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);
44
+ n && (e.scrollLeft += Math.sign(n) * Math.min(12, Math.abs(n) / 3) / u), E(), l = requestAnimationFrame(B);
40
45
  }, L = (e) => {
41
46
  e.key === "Escape" && (e.preventDefault(), e.stopPropagation(), c?.stop({ commit: !1 }));
42
- }, V = (e) => {
43
- const t = !!m();
47
+ }, j = (e) => {
48
+ const t = !!g();
44
49
  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(() => {
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(() => {
49
54
  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)` },
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)` },
58
63
  { transform: "translate3d(0, 0, 0)" }
59
64
  ], { 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));
65
+ b.set(r, d), d.onfinish = () => {
66
+ b.get(r) === d && (b.delete(r), A(r));
62
67
  };
63
68
  }
64
- s = [], R = [];
65
- }, X = (e, t) => {
69
+ s = [], M = [];
70
+ }, S = (e, t) => {
66
71
  if (!i.onReorder() || t.disabled || e.button !== 0 || c || e.target?.closest('button, a, input, [contenteditable="true"]')) return;
67
- C(), k = e.clientX;
72
+ C(), R = e.clientX;
68
73
  const n = e.clientY;
69
- g = t.id, f = k, h = e.currentTarget.ownerDocument, h.defaultView?.addEventListener("keydown", L, !0), c = I({
74
+ p = t.id, f = R, w = e.currentTarget.ownerDocument, w.defaultView?.addEventListener("keydown", L, !0), c = _({
70
75
  pointerEvent: e,
71
76
  captureEl: e.currentTarget,
72
77
  capturePointer: !1,
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)));
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)));
75
80
  },
76
- onEnd: (r) => V(r.commit && (r.reason === "pointer_up" || r.reason === "buttons_released"))
81
+ onEnd: (o) => j(o.commit && (o.reason === "pointer_up" || o.reason === "buttons_released"))
77
82
  });
78
- }, j = (e, t) => {
83
+ }, K = (e, t) => {
79
84
  if (!i.onReorder() || t.disabled || !e.altKey || !e.shiftKey || !["ArrowLeft", "ArrowRight"].includes(e.key)) return !1;
80
85
  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;
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;
83
88
  };
84
- return Y(() => {
89
+ return q(() => {
85
90
  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 };
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 };
90
95
  }
91
96
  export {
92
- $ as createTabReorder
97
+ I as createTabReorder
93
98
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@floegence/floe-webapp-core",
3
- "version": "0.90.2",
3
+ "version": "0.90.3",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",