@overdoser/react-toolkit 0.10.1 → 0.12.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.
@@ -1,173 +1,286 @@
1
- import { jsxs as u, Fragment as N, jsx as n } from "react/jsx-runtime";
2
- import { useRef as C, useEffect as B } from "react";
3
- import m from "clsx";
1
+ import { jsxs as h, Fragment as L, jsx as t } from "react/jsx-runtime";
2
+ import { useRef as T, useState as D, useEffect as S } from "react";
3
+ import c from "clsx";
4
4
  import e from "./Timeline.module.scss.js";
5
- import { highlightParts as z } from "./timelineCore.js";
6
- import { Draggable as H } from "../Draggable/Draggable.js";
7
- function S({
8
- items: l,
5
+ import { highlightParts as Z } from "./timelineCore.js";
6
+ import { Draggable as E } from "../Draggable/Draggable.js";
7
+ function G({
8
+ items: o,
9
9
  className: s
10
10
  }) {
11
- return l.length ? /* @__PURE__ */ n("div", { className: m(e.legend, s), children: l.map((r) => /* @__PURE__ */ u("span", { className: e.legendItem, children: [
12
- /* @__PURE__ */ n("span", { className: e.legendDot, style: { background: r.color } }),
13
- r.name
14
- ] }, r.name)) }) : null;
11
+ return o.length ? /* @__PURE__ */ t("div", { className: c(e.legend, s), children: o.map((a) => /* @__PURE__ */ h("span", { className: e.legendItem, children: [
12
+ /* @__PURE__ */ t("span", { className: e.legendDot, style: { background: a.color } }),
13
+ a.name
14
+ ] }, a.name)) }) : null;
15
15
  }
16
- function V({
17
- zoomPct: l,
16
+ function J({
17
+ zoomPct: o,
18
18
  fitActive: s,
19
- onZoomIn: r,
20
- onZoomOut: t,
19
+ onZoomIn: a,
20
+ onZoomOut: r,
21
21
  onFit: i,
22
- hint: h,
23
- children: f,
24
- className: d
22
+ hint: p,
23
+ children: b,
24
+ className: f
25
25
  }) {
26
- return /* @__PURE__ */ u("div", { className: m(e.controls, d), children: [
27
- f,
28
- /* @__PURE__ */ n("button", { type: "button", className: e.zoomBtn, title: "Zoom out", onClick: t, children: "−" }),
29
- /* @__PURE__ */ n("span", { className: e.zoomPct, children: l }),
30
- /* @__PURE__ */ n("button", { type: "button", className: e.zoomBtn, title: "Zoom in", onClick: r, children: "+" }),
31
- /* @__PURE__ */ n(
26
+ return /* @__PURE__ */ h("div", { className: c(e.controls, f), children: [
27
+ b,
28
+ /* @__PURE__ */ t("button", { type: "button", className: e.zoomBtn, title: "Zoom out", onClick: r, children: "−" }),
29
+ /* @__PURE__ */ t("span", { className: e.zoomPct, children: o }),
30
+ /* @__PURE__ */ t("button", { type: "button", className: e.zoomBtn, title: "Zoom in", onClick: a, children: "+" }),
31
+ /* @__PURE__ */ t(
32
32
  "button",
33
33
  {
34
34
  type: "button",
35
- className: m(e.fitBtn, s && e.fitBtnActive),
35
+ className: c(e.fitBtn, s && e.fitBtnActive),
36
36
  onClick: i,
37
37
  children: "Fit"
38
38
  }
39
39
  ),
40
- h ? /* @__PURE__ */ n("span", { className: e.controlsHint, children: h }) : null
40
+ p ? /* @__PURE__ */ t("span", { className: e.controlsHint, children: p }) : null
41
41
  ] });
42
42
  }
43
- function A({
44
- value: l,
43
+ function Q({
44
+ value: o,
45
45
  options: s,
46
- onChange: r
46
+ onChange: a
47
47
  }) {
48
- return /* @__PURE__ */ n("div", { className: e.segmented, children: s.map((t) => /* @__PURE__ */ n(
48
+ return /* @__PURE__ */ t("div", { className: e.segmented, children: s.map((r) => /* @__PURE__ */ t(
49
49
  "button",
50
50
  {
51
51
  type: "button",
52
- title: t.title,
53
- className: m(e.segmentedBtn, t.value === l && e.segmentedBtnActive),
54
- onClick: () => r(t.value),
55
- children: t.label
52
+ title: r.title,
53
+ className: c(e.segmentedBtn, r.value === o && e.segmentedBtnActive),
54
+ onClick: () => a(r.value),
55
+ children: r.label
56
56
  },
57
- t.value
57
+ r.value
58
58
  )) });
59
59
  }
60
- function M({
61
- heading: l = "Events",
60
+ function j({
61
+ panel: o,
62
+ width: s,
63
+ min: a,
64
+ max: r,
65
+ onResize: i,
66
+ label: p,
67
+ className: b
68
+ }) {
69
+ const f = T(null), [y, B] = D(!1), g = T(s);
70
+ g.current = s;
71
+ const u = (l) => Math.min(r, Math.max(a, l));
72
+ return S(() => {
73
+ if (!y) return;
74
+ const l = (P) => {
75
+ const k = f.current;
76
+ if (!k) return;
77
+ const v = P.clientX - k.x;
78
+ i(Math.min(r, Math.max(a, k.w + (o === "left" ? v : -v))));
79
+ }, d = () => {
80
+ f.current = null, B(!1);
81
+ };
82
+ return window.addEventListener("pointermove", l), window.addEventListener("pointerup", d), () => {
83
+ window.removeEventListener("pointermove", l), window.removeEventListener("pointerup", d);
84
+ };
85
+ }, [y, o, a, r, i]), /* @__PURE__ */ t(
86
+ "div",
87
+ {
88
+ className: c(e.dockResizer, y && e.dockResizerActive, b),
89
+ role: "separator",
90
+ "aria-orientation": "vertical",
91
+ "aria-label": p,
92
+ tabIndex: 0,
93
+ onPointerDown: (l) => {
94
+ l.button > 0 || (l.preventDefault(), f.current = { x: l.clientX, w: g.current }, B(!0));
95
+ },
96
+ onKeyDown: (l) => {
97
+ const d = l.key === "ArrowLeft" ? -16 : l.key === "ArrowRight" ? 16 : 0;
98
+ d && (l.preventDefault(), i(u(g.current + (o === "left" ? d : -d))));
99
+ }
100
+ }
101
+ );
102
+ }
103
+ function Y({
104
+ heading: o = "Events",
62
105
  items: s,
63
- onPick: r,
64
- placement: t = "left",
106
+ onPick: a,
107
+ placement: r = "left",
65
108
  floatingDefaultPosition: i,
66
- className: h
109
+ bubbleGlyphColors: p,
110
+ className: b
67
111
  }) {
68
- const f = C(null), d = C(!1), p = t === "floating", b = t === "top" || t === "bottom";
69
- let c = -1, y = -1;
70
- s.forEach((a, o) => {
71
- a.inView && (c < 0 && (c = o), y = o);
112
+ const f = T(null), y = T(!1), [B, g] = D(!1), [u, l] = D(!1), [d, P] = D(262), [k, v] = D({ x: 0, y: 0 }), N = r === "bubble", H = r === "floating", z = H || N && !u, A = r === "top" || r === "bottom";
113
+ let w = -1, C = -1;
114
+ s.forEach((n, m) => {
115
+ n.inView && (w < 0 && (w = m), C = m);
72
116
  });
73
- const v = c === 0 && y === s.length - 1;
74
- B(() => {
75
- const a = f.current;
76
- if (!a || d.current || c < 0 || v) return;
77
- const o = a.querySelectorAll("[data-timeline-summary-row]"), k = o[c], g = o[y];
78
- if (!k || !g) return;
79
- const x = (k.offsetTop + g.offsetTop + g.offsetHeight) / 2;
80
- a.scrollTop = Math.max(0, x - a.clientHeight / 2);
81
- }, [c, y, v]);
82
- const w = /* @__PURE__ */ u(N, { children: [
83
- /* @__PURE__ */ u("span", { children: [
84
- p && /* @__PURE__ */ n("span", { className: e.summaryGrip, "aria-hidden": !0, children: "⠿" }),
85
- l
117
+ const M = w === 0 && C === s.length - 1;
118
+ S(() => {
119
+ const n = f.current;
120
+ if (!n || y.current || w < 0 || M) return;
121
+ const m = n.querySelectorAll("[data-timeline-summary-row]"), I = m[w], R = m[C];
122
+ if (!I || !R) return;
123
+ const V = (I.offsetTop + R.offsetTop + R.offsetHeight) / 2;
124
+ n.scrollTop = Math.max(0, V - n.clientHeight / 2);
125
+ }, [w, C, M]);
126
+ const F = /* @__PURE__ */ h(L, { children: [
127
+ /* @__PURE__ */ h("span", { children: [
128
+ z && /* @__PURE__ */ t("span", { className: e.summaryGrip, "aria-hidden": !0, children: "⠿" }),
129
+ o
86
130
  ] }),
87
- /* @__PURE__ */ n("span", { className: e.summaryCount, children: s.length })
88
- ] }), T = /* @__PURE__ */ u(
131
+ N ? /* @__PURE__ */ h("span", { className: e.summaryHeadTools, children: [
132
+ /* @__PURE__ */ t("span", { className: e.summaryCount, children: s.length }),
133
+ /* @__PURE__ */ t(
134
+ "button",
135
+ {
136
+ type: "button",
137
+ className: e.summaryDockBtn,
138
+ "aria-label": u ? "Undock event summary" : "Dock event summary",
139
+ title: u ? "Float the panel" : "Dock to the left edge",
140
+ onClick: (n) => {
141
+ n.stopPropagation(), l(!u), v({ x: 0, y: 0 });
142
+ },
143
+ onPointerDown: (n) => n.stopPropagation(),
144
+ children: u ? "⇱" : "⇤"
145
+ }
146
+ ),
147
+ /* @__PURE__ */ t(
148
+ "button",
149
+ {
150
+ type: "button",
151
+ className: e.summaryCollapse,
152
+ "aria-label": "Collapse event summary",
153
+ onClick: (n) => {
154
+ n.stopPropagation(), g(!1), v({ x: 0, y: 0 });
155
+ },
156
+ onPointerDown: (n) => n.stopPropagation(),
157
+ children: "×"
158
+ }
159
+ )
160
+ ] }) : /* @__PURE__ */ t("span", { className: e.summaryCount, children: s.length })
161
+ ] }), x = /* @__PURE__ */ h(
89
162
  "div",
90
163
  {
91
- className: m(
164
+ className: c(
92
165
  e.summary,
93
- b && e.summaryHorizontal,
94
- t === "top" && e.summaryTop,
95
- t === "bottom" && e.summaryBottom,
96
- p && e.summaryFloatingCard,
97
- h
166
+ A && e.summaryHorizontal,
167
+ r === "top" && e.summaryTop,
168
+ r === "bottom" && e.summaryBottom,
169
+ H && e.summaryFloatingCard,
170
+ N && e.summaryBubbleCard,
171
+ N && u && e.summaryDockCard,
172
+ b
98
173
  ),
99
174
  onMouseEnter: () => {
100
- d.current = !0;
175
+ y.current = !0;
101
176
  },
102
177
  onMouseLeave: () => {
103
- d.current = !1;
178
+ y.current = !1;
104
179
  },
105
180
  children: [
106
- p ? /* @__PURE__ */ n(H.Handle, { className: m(e.summaryHeader, e.summaryHandle), children: w }) : /* @__PURE__ */ n("div", { className: e.summaryHeader, children: w }),
107
- /* @__PURE__ */ n(
181
+ z ? /* @__PURE__ */ t(E.Handle, { className: c(e.summaryHeader, e.summaryHandle), children: F }) : /* @__PURE__ */ t("div", { className: e.summaryHeader, children: F }),
182
+ /* @__PURE__ */ t(
108
183
  "div",
109
184
  {
110
185
  ref: f,
111
- className: m(e.summaryList, b && e.summaryListGrid),
112
- children: s.map((a) => /* @__PURE__ */ u(
186
+ className: c(e.summaryList, A && e.summaryListGrid),
187
+ children: s.map((n) => /* @__PURE__ */ h(
113
188
  "div",
114
189
  {
115
190
  "data-timeline-summary-row": !0,
116
191
  role: "button",
117
192
  tabIndex: 0,
118
- className: m(
193
+ className: c(
119
194
  e.summaryRow,
120
- a.inView && e.summaryRowInView,
121
- a.selected && e.summaryRowSelected
195
+ n.inView && e.summaryRowInView,
196
+ n.selected && e.summaryRowSelected
122
197
  ),
123
- onClick: () => r(a.id),
124
- onKeyDown: (o) => {
125
- (o.key === "Enter" || o.key === " ") && (o.preventDefault(), r(a.id));
198
+ onClick: () => a(n.id),
199
+ onKeyDown: (m) => {
200
+ (m.key === "Enter" || m.key === " ") && (m.preventDefault(), a(n.id));
126
201
  },
127
202
  children: [
128
- /* @__PURE__ */ n("span", { className: e.summaryNum, children: a.number }),
129
- /* @__PURE__ */ n("span", { className: e.summaryDot, style: { background: a.color } }),
130
- /* @__PURE__ */ n("span", { className: e.summaryLabel, children: a.label }),
131
- a.time && /* @__PURE__ */ n("span", { className: e.summaryTime, children: a.time })
203
+ /* @__PURE__ */ t("span", { className: e.summaryNum, children: n.number }),
204
+ /* @__PURE__ */ t("span", { className: e.summaryDot, style: { background: n.color } }),
205
+ /* @__PURE__ */ t("span", { className: e.summaryLabel, children: n.label }),
206
+ n.time && /* @__PURE__ */ t("span", { className: e.summaryTime, children: n.time })
132
207
  ]
133
208
  },
134
- a.id
209
+ n.id
135
210
  ))
136
211
  }
137
- )
212
+ ),
213
+ N && /* @__PURE__ */ t("div", { className: e.summaryFootnote, children: "Tinted rows are in the viewport" })
138
214
  ]
139
215
  }
140
216
  );
141
- return p ? /* @__PURE__ */ n(
142
- H,
217
+ return N ? B ? u ? /* @__PURE__ */ h("div", { className: e.summaryDock, style: { flexBasis: d }, children: [
218
+ x,
219
+ /* @__PURE__ */ t(
220
+ j,
221
+ {
222
+ panel: "left",
223
+ width: d,
224
+ min: 200,
225
+ max: 520,
226
+ onResize: P,
227
+ label: "Resize event summary",
228
+ className: e.summaryDockResizer
229
+ }
230
+ )
231
+ ] }) : /* @__PURE__ */ t("div", { className: e.summaryBubbleAnchor, children: /* @__PURE__ */ t(
232
+ E,
233
+ {
234
+ className: e.summaryBubblePanel,
235
+ bounds: "viewport",
236
+ position: k,
237
+ onDrag: v,
238
+ children: x
239
+ }
240
+ ) }) : /* @__PURE__ */ t("div", { className: e.summaryBubbleAnchor, children: /* @__PURE__ */ h(
241
+ "button",
242
+ {
243
+ type: "button",
244
+ className: c(e.summaryBubble, b),
245
+ title: "Event summary",
246
+ onClick: () => g(!0),
247
+ children: [
248
+ /* @__PURE__ */ t("span", { className: e.summaryBubbleGlyph, "aria-hidden": !0, children: (p && p.length ? p : ["var(--crk-timeline-accent)"]).slice(0, 3).map((n, m) => /* @__PURE__ */ t("span", { style: { background: n } }, m)) }),
249
+ o,
250
+ /* @__PURE__ */ t("span", { className: e.summaryCount, children: s.length })
251
+ ]
252
+ }
253
+ ) }) : H ? /* @__PURE__ */ t(
254
+ E,
143
255
  {
144
256
  className: e.summaryFloating,
145
257
  bounds: "viewport",
146
258
  defaultPosition: i ?? { x: 0, y: 0 },
147
- children: T
259
+ children: x
148
260
  }
149
- ) : T;
261
+ ) : x;
150
262
  }
151
- function Z({
152
- x: l,
263
+ function _({
264
+ x: o,
153
265
  y: s,
154
- children: r,
155
- className: t,
266
+ children: a,
267
+ className: r,
156
268
  style: i
157
269
  }) {
158
- return /* @__PURE__ */ n("div", { className: m(e.tooltip, t), style: { left: l, top: s, ...i }, children: r });
270
+ return /* @__PURE__ */ t("div", { className: c(e.tooltip, r), style: { left: o, top: s, ...i }, children: a });
159
271
  }
160
- function j({ text: l, query: s }) {
161
- const r = z(l, s);
162
- return r.length === 1 && !r[0].hit ? /* @__PURE__ */ n(N, { children: r[0].t }) : /* @__PURE__ */ n(N, { children: r.map(
163
- (t, i) => t.hit ? /* @__PURE__ */ n("span", { className: e.mark, children: t.t }, i) : /* @__PURE__ */ n("span", { children: t.t }, i)
272
+ function $({ text: o, query: s }) {
273
+ const a = Z(o, s);
274
+ return a.length === 1 && !a[0].hit ? /* @__PURE__ */ t(L, { children: a[0].t }) : /* @__PURE__ */ t(L, { children: a.map(
275
+ (r, i) => r.hit ? /* @__PURE__ */ t("span", { className: e.mark, children: r.t }, i) : /* @__PURE__ */ t("span", { children: r.t }, i)
164
276
  ) });
165
277
  }
166
278
  export {
167
- j as HighlightText,
168
- S as TimelineLegend,
169
- A as TimelineSegmented,
170
- M as TimelineSummary,
171
- Z as TimelineTooltip,
172
- V as TimelineZoomControls
279
+ $ as HighlightText,
280
+ G as TimelineLegend,
281
+ j as TimelineResizer,
282
+ Q as TimelineSegmented,
283
+ Y as TimelineSummary,
284
+ _ as TimelineTooltip,
285
+ J as TimelineZoomControls
173
286
  };
@@ -1,6 +1,7 @@
1
1
  import { CSSProperties, ReactNode } from 'react';
2
2
  import { TimelineSummaryPlacement } from './TimelineShared';
3
3
  import { DraggablePosition } from '../Draggable';
4
+ import { TimelineWheelZoom } from './useTimeline';
4
5
  /**
5
6
  * One request/response (or custom) event on the trace. Only `id`, `service`
6
7
  * and `start` are required — everything else enriches the chip, tooltip and
@@ -54,9 +55,13 @@ export interface TraceTimelineClasses {
54
55
  summary: string;
55
56
  search: string;
56
57
  drawer: string;
58
+ log: string;
59
+ rail: string;
57
60
  tooltip: string;
58
61
  footnote: string;
59
62
  }
63
+ /** Which right-side drawer is docked open (`null` = none). */
64
+ export type TraceTimelineDock = 'details' | 'log' | null;
60
65
  /** Context handed to the TraceTimeline render-prop slots. */
61
66
  export interface TraceTimelineItemContext {
62
67
  /** Resolved service color. */
@@ -111,27 +116,58 @@ export interface TraceTimelineProps {
111
116
  showGridlines?: boolean;
112
117
  /** Toolbar row with the zoom −/%/+/Fit controls. @default true */
113
118
  showControls?: boolean;
119
+ /**
120
+ * How the mouse wheel / trackpad zooms the timeline: `'ctrl'` zooms only
121
+ * while Ctrl/Cmd is held (plain scrolling passes through to the page;
122
+ * trackpad pinch still zooms), `'free'` zooms on any scroll over the
123
+ * canvas, `'none'` disables wheel zoom entirely — the toolbar buttons
124
+ * still work.
125
+ * @default 'ctrl'
126
+ */
127
+ wheelZoom?: TimelineWheelZoom;
114
128
  /** Colored dot + name legend for the services present. @default true */
115
129
  showLegend?: boolean;
116
130
  /**
117
- * Dense one-line-per-event summary panel beside the timeline: all events
118
- * numbered chronologically from `01`, a highlight band over the events
119
- * currently visible in the viewport (auto-follows drag-panning), and
120
- * click-to-navigate — the timeline smooth-scrolls (~1s, decelerating) to
121
- * center the picked event. The panel scrolls independently.
122
- * @default false
131
+ * Dense one-line-per-event summary panel: all events numbered
132
+ * chronologically from `01`, a highlight band over the events currently
133
+ * visible in the viewport (auto-follows drag-panning), and
134
+ * click-to-navigate — picking a row selects the event and smooth-scrolls
135
+ * the timeline (~1s, decelerating) to center it (and scrolls the full-log
136
+ * drawer to its entry when that is open). The panel scrolls independently.
137
+ * @default true
123
138
  */
124
139
  showSummary?: boolean;
125
140
  /**
126
- * Where the summary panel sits: docked `'left'`/`'right'` of the timeline,
141
+ * Where the summary panel sits: `'bubble'` — a collapsed pill anchored
142
+ * bottom-left of the timeline that expands in place into a draggable panel
143
+ * (collapsing snaps it back to its corner) — docked `'left'`/`'right'`,
127
144
  * full-width `'top'`/`'bottom'`, or `'floating'` — a draggable palette over
128
- * the timeline, grabbed by its header. @default 'left'
145
+ * the timeline, grabbed by its header. @default 'bubble'
129
146
  */
130
147
  summaryPlacement?: TimelineSummaryPlacement;
131
148
  /** Floating summary: initial offset from the component's top-left corner. */
132
149
  summaryDefaultPosition?: DraggablePosition;
150
+ /**
151
+ * Sticky icon rail on the far right with two toggles docking a drawer
152
+ * beside the timeline: *Event details* (the request/response panel, with an
153
+ * empty state until an event is picked) and *Full log* (every event
154
+ * vertically with payloads and copy buttons). One drawer at a time; nothing
155
+ * is docked initially, but clicking an event opens the details drawer.
156
+ * With `false`, the rail and full log disappear and the details panel
157
+ * simply opens/closes with the selection. @default true
158
+ */
159
+ showDock?: boolean;
160
+ /** Drawer docked open initially (uncontrolled). @default null */
161
+ defaultDock?: TraceTimelineDock;
133
162
  /** Max height of the scrollable canvas. @default '80vh' */
134
163
  maxHeight?: number | string;
164
+ /**
165
+ * Minimum height of the event band, px (the sticky axis adds its 68px on
166
+ * top). Sparse traces stretch to it with the bar band kept vertically
167
+ * centered; dense traces still grow past it when their chip rows need
168
+ * more room. @default 420
169
+ */
170
+ minHeight?: number;
135
171
  /** Controlled id of the event open in the detail panel (`null` = closed). */
136
172
  selectedEventId?: string | null;
137
173
  /** Initially open event (uncontrolled). */
@@ -165,7 +201,12 @@ export interface TraceTimelineProps {
165
201
  * axis with cursor timestamp chip, day-change date labels and a sticky
166
202
  * current-date marker; wheel-zoom, drag-pan, fit-to-width; keyword
167
203
  * highlighting; in-flight events render dashed with a "now" line and grow
168
- * live; clicking opens a request/response detail side panel.
204
+ * live. A right-side icon rail docks one drawer at a time: *Event details*
205
+ * (the request/response panel, opened by clicking an event) or *Full log*
206
+ * (every event vertically with copy-to-clipboard payloads, kept in sync with
207
+ * timeline clicks both ways). An events-summary bubble sits bottom-left,
208
+ * expanding into a draggable panel that bands the events currently in view
209
+ * and navigates on click.
169
210
  *
170
211
  * @example
171
212
  * ```tsx