@overdoser/react-toolkit 0.11.0 → 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,213 +1,286 @@
1
- import { jsxs as c, Fragment as B, jsx as n } from "react/jsx-runtime";
2
- import { useRef as D, useState as E, useEffect as L } 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 R } from "./timelineCore.js";
6
- import { Draggable as w } from "../Draggable/Draggable.js";
7
- function O({
8
- items: l,
9
- className: r
5
+ import { highlightParts as Z } from "./timelineCore.js";
6
+ import { Draggable as E } from "../Draggable/Draggable.js";
7
+ function G({
8
+ items: o,
9
+ className: s
10
10
  }) {
11
- return l.length ? /* @__PURE__ */ n("div", { className: m(e.legend, r), children: l.map((s) => /* @__PURE__ */ c("span", { className: e.legendItem, children: [
12
- /* @__PURE__ */ n("span", { className: e.legendDot, style: { background: s.color } }),
13
- s.name
14
- ] }, s.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 q({
17
- zoomPct: l,
18
- fitActive: r,
19
- onZoomIn: s,
20
- onZoomOut: a,
16
+ function J({
17
+ zoomPct: o,
18
+ fitActive: s,
19
+ onZoomIn: a,
20
+ onZoomOut: r,
21
21
  onFit: i,
22
- hint: u,
23
- children: p,
24
- className: y
22
+ hint: p,
23
+ children: b,
24
+ className: f
25
25
  }) {
26
- return /* @__PURE__ */ c("div", { className: m(e.controls, y), children: [
27
- p,
28
- /* @__PURE__ */ n("button", { type: "button", className: e.zoomBtn, title: "Zoom out", onClick: a, children: "−" }),
29
- /* @__PURE__ */ n("span", { className: e.zoomPct, children: l }),
30
- /* @__PURE__ */ n("button", { type: "button", className: e.zoomBtn, title: "Zoom in", onClick: s, 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, r && e.fitBtnActive),
35
+ className: c(e.fitBtn, s && e.fitBtnActive),
36
36
  onClick: i,
37
37
  children: "Fit"
38
38
  }
39
39
  ),
40
- u ? /* @__PURE__ */ n("span", { className: e.controlsHint, children: u }) : null
40
+ p ? /* @__PURE__ */ t("span", { className: e.controlsHint, children: p }) : null
41
41
  ] });
42
42
  }
43
- function G({
44
- value: l,
45
- options: r,
46
- onChange: s
43
+ function Q({
44
+ value: o,
45
+ options: s,
46
+ onChange: a
47
47
  }) {
48
- return /* @__PURE__ */ n("div", { className: e.segmented, children: r.map((a) => /* @__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: a.title,
53
- className: m(e.segmentedBtn, a.value === l && e.segmentedBtnActive),
54
- onClick: () => s(a.value),
55
- children: a.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
- a.value
57
+ r.value
58
58
  )) });
59
59
  }
60
- function K({
61
- heading: l = "Events",
62
- items: r,
63
- onPick: s,
64
- placement: a = "left",
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",
105
+ items: s,
106
+ onPick: a,
107
+ placement: r = "left",
65
108
  floatingDefaultPosition: i,
66
- bubbleGlyphColors: u,
67
- className: p
109
+ bubbleGlyphColors: p,
110
+ className: b
68
111
  }) {
69
- const y = D(null), N = D(!1), [z, C] = E(!1), [A, T] = E({ x: 0, y: 0 }), d = a === "bubble", b = a === "floating", k = a === "top" || a === "bottom";
70
- let h = -1, f = -1;
71
- r.forEach((t, o) => {
72
- t.inView && (h < 0 && (h = o), f = 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);
73
116
  });
74
- const H = h === 0 && f === r.length - 1;
75
- L(() => {
76
- const t = y.current;
77
- if (!t || N.current || h < 0 || H) return;
78
- const o = t.querySelectorAll("[data-timeline-summary-row]"), P = o[h], v = o[f];
79
- if (!P || !v) return;
80
- const F = (P.offsetTop + v.offsetTop + v.offsetHeight) / 2;
81
- t.scrollTop = Math.max(0, F - t.clientHeight / 2);
82
- }, [h, f, H]);
83
- const x = /* @__PURE__ */ c(B, { children: [
84
- /* @__PURE__ */ c("span", { children: [
85
- (b || d) && /* @__PURE__ */ n("span", { className: e.summaryGrip, "aria-hidden": !0, children: "⠿" }),
86
- 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
87
130
  ] }),
88
- d ? /* @__PURE__ */ c("span", { className: e.summaryHeadTools, children: [
89
- /* @__PURE__ */ n("span", { className: e.summaryCount, children: r.length }),
90
- /* @__PURE__ */ n(
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(
91
148
  "button",
92
149
  {
93
150
  type: "button",
94
151
  className: e.summaryCollapse,
95
152
  "aria-label": "Collapse event summary",
96
- onClick: (t) => {
97
- t.stopPropagation(), C(!1), T({ x: 0, y: 0 });
153
+ onClick: (n) => {
154
+ n.stopPropagation(), g(!1), v({ x: 0, y: 0 });
98
155
  },
99
- onPointerDown: (t) => t.stopPropagation(),
156
+ onPointerDown: (n) => n.stopPropagation(),
100
157
  children: "×"
101
158
  }
102
159
  )
103
- ] }) : /* @__PURE__ */ n("span", { className: e.summaryCount, children: r.length })
104
- ] }), g = /* @__PURE__ */ c(
160
+ ] }) : /* @__PURE__ */ t("span", { className: e.summaryCount, children: s.length })
161
+ ] }), x = /* @__PURE__ */ h(
105
162
  "div",
106
163
  {
107
- className: m(
164
+ className: c(
108
165
  e.summary,
109
- k && e.summaryHorizontal,
110
- a === "top" && e.summaryTop,
111
- a === "bottom" && e.summaryBottom,
112
- b && e.summaryFloatingCard,
113
- d && e.summaryBubbleCard,
114
- p
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
115
173
  ),
116
174
  onMouseEnter: () => {
117
- N.current = !0;
175
+ y.current = !0;
118
176
  },
119
177
  onMouseLeave: () => {
120
- N.current = !1;
178
+ y.current = !1;
121
179
  },
122
180
  children: [
123
- b || d ? /* @__PURE__ */ n(w.Handle, { className: m(e.summaryHeader, e.summaryHandle), children: x }) : /* @__PURE__ */ n("div", { className: e.summaryHeader, children: x }),
124
- /* @__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(
125
183
  "div",
126
184
  {
127
- ref: y,
128
- className: m(e.summaryList, k && e.summaryListGrid),
129
- children: r.map((t) => /* @__PURE__ */ c(
185
+ ref: f,
186
+ className: c(e.summaryList, A && e.summaryListGrid),
187
+ children: s.map((n) => /* @__PURE__ */ h(
130
188
  "div",
131
189
  {
132
190
  "data-timeline-summary-row": !0,
133
191
  role: "button",
134
192
  tabIndex: 0,
135
- className: m(
193
+ className: c(
136
194
  e.summaryRow,
137
- t.inView && e.summaryRowInView,
138
- t.selected && e.summaryRowSelected
195
+ n.inView && e.summaryRowInView,
196
+ n.selected && e.summaryRowSelected
139
197
  ),
140
- onClick: () => s(t.id),
141
- onKeyDown: (o) => {
142
- (o.key === "Enter" || o.key === " ") && (o.preventDefault(), s(t.id));
198
+ onClick: () => a(n.id),
199
+ onKeyDown: (m) => {
200
+ (m.key === "Enter" || m.key === " ") && (m.preventDefault(), a(n.id));
143
201
  },
144
202
  children: [
145
- /* @__PURE__ */ n("span", { className: e.summaryNum, children: t.number }),
146
- /* @__PURE__ */ n("span", { className: e.summaryDot, style: { background: t.color } }),
147
- /* @__PURE__ */ n("span", { className: e.summaryLabel, children: t.label }),
148
- t.time && /* @__PURE__ */ n("span", { className: e.summaryTime, children: t.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 })
149
207
  ]
150
208
  },
151
- t.id
209
+ n.id
152
210
  ))
153
211
  }
154
212
  ),
155
- d && /* @__PURE__ */ n("div", { className: e.summaryFootnote, children: "Tinted rows are in the viewport" })
213
+ N && /* @__PURE__ */ t("div", { className: e.summaryFootnote, children: "Tinted rows are in the viewport" })
156
214
  ]
157
215
  }
158
216
  );
159
- return d ? z ? /* @__PURE__ */ n("div", { className: e.summaryBubbleAnchor, children: /* @__PURE__ */ n(
160
- w,
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,
161
233
  {
162
234
  className: e.summaryBubblePanel,
163
235
  bounds: "viewport",
164
- position: A,
165
- onDrag: T,
166
- children: g
236
+ position: k,
237
+ onDrag: v,
238
+ children: x
167
239
  }
168
- ) }) : /* @__PURE__ */ n("div", { className: e.summaryBubbleAnchor, children: /* @__PURE__ */ c(
240
+ ) }) : /* @__PURE__ */ t("div", { className: e.summaryBubbleAnchor, children: /* @__PURE__ */ h(
169
241
  "button",
170
242
  {
171
243
  type: "button",
172
- className: m(e.summaryBubble, p),
244
+ className: c(e.summaryBubble, b),
173
245
  title: "Event summary",
174
- onClick: () => C(!0),
246
+ onClick: () => g(!0),
175
247
  children: [
176
- /* @__PURE__ */ n("span", { className: e.summaryBubbleGlyph, "aria-hidden": !0, children: (u && u.length ? u : ["var(--crk-timeline-accent)"]).slice(0, 3).map((t, o) => /* @__PURE__ */ n("span", { style: { background: t } }, o)) }),
177
- l,
178
- /* @__PURE__ */ n("span", { className: e.summaryCount, children: r.length })
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 })
179
251
  ]
180
252
  }
181
- ) }) : b ? /* @__PURE__ */ n(
182
- w,
253
+ ) }) : H ? /* @__PURE__ */ t(
254
+ E,
183
255
  {
184
256
  className: e.summaryFloating,
185
257
  bounds: "viewport",
186
258
  defaultPosition: i ?? { x: 0, y: 0 },
187
- children: g
259
+ children: x
188
260
  }
189
- ) : g;
261
+ ) : x;
190
262
  }
191
- function J({
192
- x: l,
193
- y: r,
194
- children: s,
195
- className: a,
263
+ function _({
264
+ x: o,
265
+ y: s,
266
+ children: a,
267
+ className: r,
196
268
  style: i
197
269
  }) {
198
- return /* @__PURE__ */ n("div", { className: m(e.tooltip, a), style: { left: l, top: r, ...i }, children: s });
270
+ return /* @__PURE__ */ t("div", { className: c(e.tooltip, r), style: { left: o, top: s, ...i }, children: a });
199
271
  }
200
- function Q({ text: l, query: r }) {
201
- const s = R(l, r);
202
- return s.length === 1 && !s[0].hit ? /* @__PURE__ */ n(B, { children: s[0].t }) : /* @__PURE__ */ n(B, { children: s.map(
203
- (a, i) => a.hit ? /* @__PURE__ */ n("span", { className: e.mark, children: a.t }, i) : /* @__PURE__ */ n("span", { children: a.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)
204
276
  ) });
205
277
  }
206
278
  export {
207
- Q as HighlightText,
208
- O as TimelineLegend,
209
- G as TimelineSegmented,
210
- K as TimelineSummary,
211
- J as TimelineTooltip,
212
- q 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
213
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
@@ -115,6 +116,15 @@ export interface TraceTimelineProps {
115
116
  showGridlines?: boolean;
116
117
  /** Toolbar row with the zoom −/%/+/Fit controls. @default true */
117
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;
118
128
  /** Colored dot + name legend for the services present. @default true */
119
129
  showLegend?: boolean;
120
130
  /**