@overdoser/react-toolkit 0.8.3 → 0.9.0
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/AGENTS.md +6 -0
- package/CHANGELOG.md +35 -0
- package/components/Timeline/GanttTimeline.d.ts +144 -0
- package/components/Timeline/GanttTimeline.js +305 -0
- package/components/Timeline/GanttTimeline.module.scss.js +55 -0
- package/components/Timeline/HistoryTimeline.d.ts +184 -0
- package/components/Timeline/HistoryTimeline.js +445 -0
- package/components/Timeline/HistoryTimeline.module.scss.js +59 -0
- package/components/Timeline/Timeline.module.scss.js +111 -0
- package/components/Timeline/TimelineShared.d.ts +79 -0
- package/components/Timeline/TimelineShared.js +173 -0
- package/components/Timeline/TraceTimeline.d.ts +180 -0
- package/components/Timeline/TraceTimeline.js +511 -0
- package/components/Timeline/TraceTimeline.module.scss.js +105 -0
- package/components/Timeline/demoData.d.ts +42 -0
- package/components/Timeline/historyLayout.d.ts +82 -0
- package/components/Timeline/historyLayout.js +264 -0
- package/components/Timeline/index.d.ts +7 -0
- package/components/Timeline/timelineCore.d.ts +90 -0
- package/components/Timeline/timelineCore.js +135 -0
- package/components/Timeline/traceLayout.d.ts +72 -0
- package/components/Timeline/traceLayout.js +92 -0
- package/components/Timeline/useTimeline.d.ts +39 -0
- package/components/Timeline/useTimeline.js +81 -0
- package/index.css +1 -1
- package/index.d.ts +2 -0
- package/index.js +93 -87
- package/index.layered.css +1 -1
- package/llms.txt +113 -0
- package/manifest.json +323 -0
- package/package.json +1 -1
- package/recipes/live-timeline-feed.tsx +147 -0
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
function G(d, a = {}) {
|
|
2
|
+
const f = a.barH ?? 26, c = a.rowH ?? 66, x = a.chipH ?? 51, S = a.minH ?? 420, w = d.map((o) => ({
|
|
3
|
+
...o,
|
|
4
|
+
sub: 0,
|
|
5
|
+
row: -1,
|
|
6
|
+
labelX: o.left,
|
|
7
|
+
showLabel: !1,
|
|
8
|
+
barTop: 0,
|
|
9
|
+
labelTop: 0,
|
|
10
|
+
conn: !1,
|
|
11
|
+
connTop: 0,
|
|
12
|
+
connH: 0,
|
|
13
|
+
hconn: !1,
|
|
14
|
+
hconnLeft: 0,
|
|
15
|
+
hconnTop: 0,
|
|
16
|
+
hconnW: 0
|
|
17
|
+
})), t = w.slice().sort((o, n) => o.left - n.left || n.width - o.width), u = [];
|
|
18
|
+
t.forEach((o) => {
|
|
19
|
+
let n = 0;
|
|
20
|
+
for (; n < u.length && o.left < u[n] + 3; ) n++;
|
|
21
|
+
o.sub = n, u[n] = o.left + o.width;
|
|
22
|
+
});
|
|
23
|
+
const H = Math.max(1, u.length), T = [0, 4, 1, 5, 2, 6, 3, 7], E = [], W = [], g = (o, n, e, r) => {
|
|
24
|
+
const X = o < 4, v = X ? o + 1 : o - 3;
|
|
25
|
+
for (const l of E) {
|
|
26
|
+
const b = l.row < 4;
|
|
27
|
+
if (b !== X) continue;
|
|
28
|
+
if ((b ? l.row + 1 : l.row - 3) <= v && r >= l.x1 - 3 && r <= l.x2 + 3) return !0;
|
|
29
|
+
}
|
|
30
|
+
for (const l of W) {
|
|
31
|
+
const b = l.row < 4;
|
|
32
|
+
if (b !== X) continue;
|
|
33
|
+
if ((b ? l.row + 1 : l.row - 3) >= v && l.x >= n - 3 && l.x <= e + 3) return !0;
|
|
34
|
+
}
|
|
35
|
+
return !1;
|
|
36
|
+
}, s = [1e9, 1e9, 1e9, 1e9, 1e9, 1e9, 1e9, 1e9];
|
|
37
|
+
t.slice().reverse().forEach((o) => {
|
|
38
|
+
const n = o.labelW;
|
|
39
|
+
o.row = -1, o.labelX = o.left;
|
|
40
|
+
for (const e of T)
|
|
41
|
+
if (o.left + n <= s[e] - 14 && !g(e, o.left, o.left + n, o.left)) {
|
|
42
|
+
o.row = e, o.labelX = o.left;
|
|
43
|
+
break;
|
|
44
|
+
}
|
|
45
|
+
if (o.row < 0)
|
|
46
|
+
for (const e of T) {
|
|
47
|
+
const r = Math.min(o.left, s[e] - 14 - n);
|
|
48
|
+
if (r >= o.left - 140 && !g(e, r, r + n, o.left)) {
|
|
49
|
+
o.row = e, o.labelX = r;
|
|
50
|
+
break;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
if (o.row < 0)
|
|
54
|
+
for (const e of T) {
|
|
55
|
+
const r = Math.min(o.left, s[e] - 14 - n);
|
|
56
|
+
if (r >= o.left - 140) {
|
|
57
|
+
o.row = e, o.labelX = r;
|
|
58
|
+
break;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
o.row >= 0 && (s[o.row] = Math.min(s[o.row], o.labelX), E.push({ row: o.row, x1: o.labelX, x2: o.labelX + n }), W.push({ row: o.row, x: o.left })), o.showLabel = o.row >= 0;
|
|
62
|
+
});
|
|
63
|
+
const L = t.reduce(
|
|
64
|
+
(o, n) => n.row >= 0 && n.row < 4 ? Math.max(o, n.row + 1) : o,
|
|
65
|
+
1
|
|
66
|
+
), N = t.reduce((o, n) => n.row >= 4 ? Math.max(o, n.row - 3) : o, 0), h = H * (f + 4) - 4, k = 10 + L * c + h + N * c + 14, m = Math.max(S, k), p = Math.max(
|
|
67
|
+
10 + L * c,
|
|
68
|
+
Math.min(Math.round((m - h) / 2), m - h - N * c - 14)
|
|
69
|
+
);
|
|
70
|
+
w.forEach((o) => {
|
|
71
|
+
if (o.barTop = p + o.sub * (f + 4), o.row < 0) return;
|
|
72
|
+
const n = o.row < 4;
|
|
73
|
+
o.labelTop = n ? p - (o.row + 1) * c : p + h + 10 + (o.row - 4) * c, n ? (o.connTop = o.labelTop + x, o.connH = o.barTop - o.connTop - 1) : (o.connTop = o.barTop + f + 1, o.connH = o.labelTop - o.connTop + 2), o.conn = o.connH > 2, o.labelX > o.left + 2 ? (o.hconn = !0, o.hconnTop = o.labelTop + Math.round(x / 2), o.hconnLeft = o.left + 1, o.hconnW = Math.max(2, o.labelX - o.left - 3), o.conn = !0) : o.labelX + o.labelW < o.left - 2 && (o.hconn = !0, o.hconnTop = o.labelTop + Math.round(x / 2), o.hconnLeft = o.labelX + o.labelW - 1, o.hconnW = Math.max(2, o.left - (o.labelX + o.labelW) + 2), o.conn = !0);
|
|
74
|
+
});
|
|
75
|
+
let M = 0;
|
|
76
|
+
return w.forEach((o) => {
|
|
77
|
+
M = Math.max(M, o.left + o.width, o.showLabel ? o.labelX + o.labelW : 0);
|
|
78
|
+
}), {
|
|
79
|
+
items: w,
|
|
80
|
+
h: m,
|
|
81
|
+
axisY: p + Math.round(h / 2),
|
|
82
|
+
subRows: H,
|
|
83
|
+
maxExt: M
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
function U(d, a, f) {
|
|
87
|
+
return Math.max(String(d).length + String(a).length + 4, String(f).length, 23) * 6 + 20;
|
|
88
|
+
}
|
|
89
|
+
export {
|
|
90
|
+
G as layoutTraceBand,
|
|
91
|
+
U as traceChipWidth
|
|
92
|
+
};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { RefObject } from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* Drag-to-pan on a scroll container via pointer events. A 5px movement
|
|
4
|
+
* threshold flags the gesture as a drag so the click that ends it can be
|
|
5
|
+
* suppressed (check `wasDragSuppressed()` in click handlers).
|
|
6
|
+
*/
|
|
7
|
+
export declare function useTimelinePan(scrollerRef: RefObject<HTMLDivElement | null>): {
|
|
8
|
+
onPointerDown: (e: React.PointerEvent) => void;
|
|
9
|
+
onPointerMove: (e: React.PointerEvent) => void;
|
|
10
|
+
onPointerUp: () => void;
|
|
11
|
+
wasDragSuppressed: () => boolean;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Track the client width of the scroll container (fit mode re-derives layout
|
|
15
|
+
* from it, e.g. when the detail panel opens and the timeline area shrinks).
|
|
16
|
+
*/
|
|
17
|
+
export declare function useContainerWidth(ref: RefObject<HTMLDivElement | null>, fallback?: number): number;
|
|
18
|
+
/**
|
|
19
|
+
* Re-render on an interval while `active` (an event is in flight), so open
|
|
20
|
+
* bars/badges grow. Returns the current timestamp.
|
|
21
|
+
*/
|
|
22
|
+
export declare function useNowTicker(active: boolean, interval?: number): number;
|
|
23
|
+
/**
|
|
24
|
+
* Animate the element's scroll position to `target` with an ease-out-cubic
|
|
25
|
+
* (fast start, decelerating finish). A new call replaces a running animation;
|
|
26
|
+
* user input on the element (wheel, grabbing to pan) cancels it. Respects
|
|
27
|
+
* `prefers-reduced-motion` by jumping instantly.
|
|
28
|
+
*/
|
|
29
|
+
export declare function animateScrollTo(el: HTMLElement, target: {
|
|
30
|
+
left?: number;
|
|
31
|
+
top?: number;
|
|
32
|
+
}, duration?: number): void;
|
|
33
|
+
/**
|
|
34
|
+
* Attach a non-passive wheel listener (plain mouse wheel zooms; the default
|
|
35
|
+
* scroll must be preventable, which React's synthetic onWheel cannot do).
|
|
36
|
+
*/
|
|
37
|
+
export declare function useWheelZoom(ref: RefObject<HTMLDivElement | null>, onWheel: (e: WheelEvent) => void,
|
|
38
|
+
/** Re-attach when this changes (e.g. the scroller remounts on orientation switch). */
|
|
39
|
+
remountKey?: unknown): void;
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { useState as E, useEffect as v, useRef as h, useCallback as p } from "react";
|
|
2
|
+
function b(e) {
|
|
3
|
+
const n = h(null), o = h(!1), r = p(
|
|
4
|
+
(i) => {
|
|
5
|
+
const c = e.current;
|
|
6
|
+
c && (n.current = { x: i.clientX, y: i.clientY, l: c.scrollLeft, t: c.scrollTop, moved: !1 });
|
|
7
|
+
},
|
|
8
|
+
[e]
|
|
9
|
+
), t = p(
|
|
10
|
+
(i) => {
|
|
11
|
+
const c = n.current, l = e.current;
|
|
12
|
+
if (!c || !l) return;
|
|
13
|
+
const a = i.clientX - c.x, f = i.clientY - c.y;
|
|
14
|
+
Math.abs(a) + Math.abs(f) > 5 && (c.moved = !0), l.scrollLeft = c.l - a, l.scrollTop = c.t - f;
|
|
15
|
+
},
|
|
16
|
+
[e]
|
|
17
|
+
), s = p(() => {
|
|
18
|
+
n.current && n.current.moved && (o.current = !0, setTimeout(() => {
|
|
19
|
+
o.current = !1;
|
|
20
|
+
}, 60)), n.current = null;
|
|
21
|
+
}, []), u = p(() => o.current, []);
|
|
22
|
+
return { onPointerDown: r, onPointerMove: t, onPointerUp: s, wasDragSuppressed: u };
|
|
23
|
+
}
|
|
24
|
+
function y(e, n = 1100) {
|
|
25
|
+
const [o, r] = E(n);
|
|
26
|
+
return v(() => {
|
|
27
|
+
const t = e.current;
|
|
28
|
+
if (!t) return;
|
|
29
|
+
const s = new ResizeObserver(() => {
|
|
30
|
+
t.clientWidth && r(t.clientWidth);
|
|
31
|
+
});
|
|
32
|
+
return s.observe(t), t.clientWidth && r(t.clientWidth), () => s.disconnect();
|
|
33
|
+
}, [e]), o;
|
|
34
|
+
}
|
|
35
|
+
function D(e, n = 450) {
|
|
36
|
+
const [o, r] = E(() => Date.now());
|
|
37
|
+
return v(() => {
|
|
38
|
+
if (!e) return;
|
|
39
|
+
const t = setInterval(() => r(Date.now()), n);
|
|
40
|
+
return () => clearInterval(t);
|
|
41
|
+
}, [e, n]), e ? o : Date.now();
|
|
42
|
+
}
|
|
43
|
+
const m = /* @__PURE__ */ new WeakMap();
|
|
44
|
+
function x(e, n, o = 900) {
|
|
45
|
+
const r = m.get(e);
|
|
46
|
+
r != null && cancelAnimationFrame(r);
|
|
47
|
+
const t = e.scrollLeft, s = e.scrollTop, u = n.left != null ? n.left - t : 0, i = n.top != null ? n.top - s : 0;
|
|
48
|
+
if (!u && !i) return;
|
|
49
|
+
if (typeof window < "u" && typeof window.matchMedia == "function" && window.matchMedia("(prefers-reduced-motion: reduce)").matches || o <= 0) {
|
|
50
|
+
n.left != null && (e.scrollLeft = n.left), n.top != null && (e.scrollTop = n.top);
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
const l = performance.now(), a = (w) => 1 - Math.pow(1 - w, 3);
|
|
54
|
+
let f = !1;
|
|
55
|
+
const d = () => {
|
|
56
|
+
f = !0, e.removeEventListener("wheel", d), e.removeEventListener("pointerdown", d), m.delete(e);
|
|
57
|
+
};
|
|
58
|
+
e.addEventListener("wheel", d, { once: !0 }), e.addEventListener("pointerdown", d, { once: !0 });
|
|
59
|
+
const L = (w) => {
|
|
60
|
+
if (f) return;
|
|
61
|
+
const T = Math.min(1, (w - l) / o), M = a(T);
|
|
62
|
+
n.left != null && (e.scrollLeft = t + u * M), n.top != null && (e.scrollTop = s + i * M), T < 1 ? m.set(e, requestAnimationFrame(L)) : d();
|
|
63
|
+
};
|
|
64
|
+
m.set(e, requestAnimationFrame(L));
|
|
65
|
+
}
|
|
66
|
+
function A(e, n, o) {
|
|
67
|
+
const r = h(n);
|
|
68
|
+
r.current = n, v(() => {
|
|
69
|
+
const t = e.current;
|
|
70
|
+
if (!t) return;
|
|
71
|
+
const s = (u) => r.current(u);
|
|
72
|
+
return t.addEventListener("wheel", s, { passive: !1 }), () => t.removeEventListener("wheel", s);
|
|
73
|
+
}, [e, o]);
|
|
74
|
+
}
|
|
75
|
+
export {
|
|
76
|
+
x as animateScrollTo,
|
|
77
|
+
y as useContainerWidth,
|
|
78
|
+
D as useNowTicker,
|
|
79
|
+
b as useTimelinePan,
|
|
80
|
+
A as useWheelZoom
|
|
81
|
+
};
|