@overdoser/react-toolkit 0.11.0 → 0.13.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.
@@ -0,0 +1,181 @@
1
+ import { jsxs as i, jsx as l, Fragment as u } from "react/jsx-runtime";
2
+ import { forwardRef as T, isValidElement as C } from "react";
3
+ import n from "clsx";
4
+ import h from "./Timeline.module.scss.js";
5
+ import a from "./TraceTimeline.module.scss.js";
6
+ import { fmtISO as D, fmtDur as O } from "./timelineCore.js";
7
+ import { HighlightText as I } from "./TimelineShared.js";
8
+ import { isRequestEvent as Q, extraFieldsOf as z, routeOf as M, badgeOf as A, isInline as U, toText as b } from "./traceEvent.js";
9
+ import { CopyButton as E } from "../ActionButton/CopyButton.js";
10
+ function W({
11
+ event: o,
12
+ pending: d,
13
+ small: c
14
+ }) {
15
+ const e = A(o, d);
16
+ return e ? /* @__PURE__ */ l(
17
+ "span",
18
+ {
19
+ className: n(
20
+ a.statusBadge,
21
+ c && a.badgeSm,
22
+ e.tone === "pending" && a.statusPending,
23
+ e.tone === "warn" && a.statusWarn,
24
+ e.tone === "error" && a.statusError
25
+ ),
26
+ children: e.text
27
+ }
28
+ ) : null;
29
+ }
30
+ function f({
31
+ field: o,
32
+ query: d,
33
+ className: c
34
+ }) {
35
+ const { label: e, value: r, mono: g = !0, copy: k } = o, p = U(r) || r == null || C(r), v = /* @__PURE__ */ l(
36
+ E,
37
+ {
38
+ size: "sm",
39
+ className: a.payloadCopy,
40
+ value: () => b(r),
41
+ "aria-label": `Copy ${e}`
42
+ }
43
+ );
44
+ return /* @__PURE__ */ i("div", { className: n(a.field, !p && a.fieldBlock, c), children: [
45
+ k || !p ? /* @__PURE__ */ i("div", { className: a.bodyHead, children: [
46
+ /* @__PURE__ */ l("span", { className: a.fieldLabel, children: e }),
47
+ v
48
+ ] }) : /* @__PURE__ */ l("span", { className: a.fieldLabel, children: e }),
49
+ p ? /* @__PURE__ */ l("div", { className: n(a.fieldValue, g && a.fieldMono), children: C(r) ? r : r == null || r === "" ? "—" : /* @__PURE__ */ l(I, { text: String(r), query: d }) }) : /* @__PURE__ */ l("pre", { className: n(h.asideRaw, a.fieldPre), children: b(r) })
50
+ ] });
51
+ }
52
+ function R({
53
+ label: o,
54
+ value: d,
55
+ copyLabel: c,
56
+ section: e
57
+ }) {
58
+ return /* @__PURE__ */ i(u, { children: [
59
+ /* @__PURE__ */ i("div", { className: a.bodyHead, children: [
60
+ /* @__PURE__ */ l(
61
+ "span",
62
+ {
63
+ className: n(e ? a.drawerSection : h.asideSection, a.bodyLabel),
64
+ children: o
65
+ }
66
+ ),
67
+ d != null && /* @__PURE__ */ l(
68
+ E,
69
+ {
70
+ size: "sm",
71
+ className: a.payloadCopy,
72
+ value: () => b(d),
73
+ "aria-label": c
74
+ }
75
+ )
76
+ ] }),
77
+ /* @__PURE__ */ l("pre", { className: h.asideRaw, children: d != null ? b(d) : "(empty)" })
78
+ ] });
79
+ }
80
+ const H = (o) => Object.entries(o || {}).map(([d, c]) => ({ k: d, v: String(c) })), le = T(
81
+ function(d, c) {
82
+ const {
83
+ event: e,
84
+ now: r = Date.now(),
85
+ highlight: g,
86
+ showExtraFields: k = !0,
87
+ hiddenFields: p,
88
+ onClose: v,
89
+ classes: m,
90
+ className: F,
91
+ style: j
92
+ } = d, y = (g || "").trim(), q = e.end == null, B = Q(e), w = k ? z(e, p) : [], x = !!Object.keys(e.query || {}).length, L = !!Object.keys(e.reqHeaders || {}).length, V = !!Object.keys(e.resHeaders || {}).length, t = [], S = e.reqHeaders && e.reqHeaders["x-request-id"] || e.requestId;
93
+ e.op && t.push({ label: "Operation", value: e.op }), e.url ? t.push({ label: "URL", value: e.url }) : e.label && t.push({ label: "Label", value: e.label }), t.push({ label: "Event id", value: e.id }), S && t.push({ label: "Request id", value: S }), t.push({ label: "Started", value: D(e.start, !0) }), q ? t.push({ label: "Duration", value: O(r - e.start) + " so far" }) : e.end === e.start ? t.push({ label: "Duration", value: "instant" }) : (t.push({ label: "Ended", value: D(e.end, !0) }), t.push({ label: "Duration", value: O(e.end - e.start) }));
94
+ const K = !B && !e.message && !e.details?.length && e.payload == null && !w.length, N = (s) => /* @__PURE__ */ l("div", { className: n(a.drawerSection, m?.section), children: s });
95
+ return /* @__PURE__ */ i("div", { ref: c, className: n(m?.root, F), style: j, children: [
96
+ /* @__PURE__ */ l("div", { className: n(a.drawerHead, m?.head), children: /* @__PURE__ */ i("div", { className: a.drawerHeadRow, children: [
97
+ e.method && /* @__PURE__ */ l("span", { className: a.methodBadge, children: e.method }),
98
+ /* @__PURE__ */ l(W, { event: e, pending: q }),
99
+ /* @__PURE__ */ l("span", { className: a.drawerRoute, children: M(e) }),
100
+ /* @__PURE__ */ l("div", { className: a.drawerSpacer }),
101
+ v && /* @__PURE__ */ l(
102
+ "button",
103
+ {
104
+ type: "button",
105
+ className: h.asideClose,
106
+ "aria-label": "Close details",
107
+ onClick: v,
108
+ children: "✕"
109
+ }
110
+ )
111
+ ] }) }),
112
+ /* @__PURE__ */ i("div", { className: n(a.drawerBody, m?.body), children: [
113
+ /* @__PURE__ */ l("div", { className: n(a.fieldList, a.headFields), children: t.map((s) => /* @__PURE__ */ l(f, { field: s, query: y, className: m?.field }, s.label)) }),
114
+ e.message && /* @__PURE__ */ l("div", { className: a.fieldList, children: /* @__PURE__ */ l(
115
+ f,
116
+ {
117
+ field: { label: "Message", value: e.message, mono: !1 },
118
+ query: y,
119
+ className: m?.field
120
+ }
121
+ ) }),
122
+ !!e.details?.length && /* @__PURE__ */ i(u, { children: [
123
+ N("Details"),
124
+ /* @__PURE__ */ l("div", { className: a.fieldList, children: e.details.map((s, P) => /* @__PURE__ */ l(f, { field: s, query: y, className: m?.field }, s.label + P)) })
125
+ ] }),
126
+ e.payload != null && /* @__PURE__ */ l(R, { section: !0, label: "Payload", value: e.payload, copyLabel: "Copy payload" }),
127
+ B && /* @__PURE__ */ i(u, { children: [
128
+ N("Request"),
129
+ x && /* @__PURE__ */ i(u, { children: [
130
+ /* @__PURE__ */ l("div", { className: h.asideSection, children: "Query parameters" }),
131
+ H(e.query).map((s) => /* @__PURE__ */ i("div", { className: a.kvRow, children: [
132
+ /* @__PURE__ */ l("span", { className: n(a.kvKey, a.kvKeyQuery), children: s.k }),
133
+ /* @__PURE__ */ l("span", { className: a.kvVal, children: s.v })
134
+ ] }, s.k))
135
+ ] }),
136
+ L && /* @__PURE__ */ i(u, { children: [
137
+ /* @__PURE__ */ l("div", { className: h.asideSection, children: "Headers" }),
138
+ H(e.reqHeaders).map((s) => /* @__PURE__ */ i("div", { className: a.kvRow, children: [
139
+ /* @__PURE__ */ l("span", { className: a.kvKey, children: s.k }),
140
+ /* @__PURE__ */ l("span", { className: a.kvVal, children: s.v })
141
+ ] }, s.k))
142
+ ] }),
143
+ e.reqBody != null && /* @__PURE__ */ l(R, { label: "Body", value: e.reqBody, copyLabel: "Copy request payload" }),
144
+ !x && !L && e.reqBody == null && /* @__PURE__ */ l("div", { className: a.emptyNote, children: "No request data captured." }),
145
+ N("Response"),
146
+ q ? /* @__PURE__ */ i("div", { className: a.awaiting, children: [
147
+ /* @__PURE__ */ l("span", { className: n(h.pulseDot, a.awaitingDot) }),
148
+ "Awaiting response…"
149
+ ] }) : /* @__PURE__ */ i(u, { children: [
150
+ V && /* @__PURE__ */ i(u, { children: [
151
+ /* @__PURE__ */ l("div", { className: h.asideSection, children: "Headers" }),
152
+ H(e.resHeaders).map((s) => /* @__PURE__ */ i("div", { className: a.kvRow, children: [
153
+ /* @__PURE__ */ l("span", { className: a.kvKey, children: s.k }),
154
+ /* @__PURE__ */ l("span", { className: a.kvVal, children: s.v })
155
+ ] }, s.k))
156
+ ] }),
157
+ /* @__PURE__ */ l(
158
+ R,
159
+ {
160
+ label: "Body",
161
+ value: e.resBody,
162
+ copyLabel: "Copy response payload"
163
+ }
164
+ )
165
+ ] })
166
+ ] }),
167
+ !!w.length && /* @__PURE__ */ i(u, { children: [
168
+ N("Other fields"),
169
+ /* @__PURE__ */ l("div", { className: a.fieldList, children: w.map((s) => /* @__PURE__ */ l(f, { field: s, query: y, className: m?.field }, s.label)) })
170
+ ] }),
171
+ K && /* @__PURE__ */ l("div", { className: a.emptyNote, children: "No further details for this event." })
172
+ ] })
173
+ ] });
174
+ }
175
+ );
176
+ export {
177
+ W as EventBadge,
178
+ f as FieldRow,
179
+ R as PayloadBlock,
180
+ le as TraceEventDetails
181
+ };
@@ -1,47 +1,9 @@
1
1
  import { CSSProperties, ReactNode } from 'react';
2
2
  import { TimelineSummaryPlacement } from './TimelineShared';
3
3
  import { DraggablePosition } from '../Draggable';
4
- /**
5
- * One request/response (or custom) event on the trace. Only `id`, `service`
6
- * and `start` are required — everything else enriches the chip, tooltip and
7
- * detail panel when present. Extra fields are allowed and participate in
8
- * keyword matching.
9
- */
10
- export interface TraceTimelineEvent {
11
- /** Stable identifier. */
12
- id: string;
13
- /** Target component/service the event belongs to (colors the bar). */
14
- service: string;
15
- /** Caller shown as the chip's origin badge. @default 'client' */
16
- source?: string;
17
- /** Friendly operation id, bold in the chip (e.g. `create_manifest`). */
18
- op?: string;
19
- /** Technical request id (fallback chip label; shown in the detail panel). */
20
- requestId?: string;
21
- /** HTTP method for the detail panel badge. */
22
- method?: string;
23
- /** Full URL (detail panel + tooltip). */
24
- url?: string;
25
- /** Short label for the tooltip. Defaults to `method + path`. */
26
- label?: string;
27
- /** Query parameters (detail panel). */
28
- query?: Record<string, string>;
29
- /** Request headers (detail panel; `x-request-id` is surfaced). */
30
- reqHeaders?: Record<string, string>;
31
- /** Request body, pretty-printed as JSON in the detail panel. */
32
- reqBody?: unknown;
33
- /** Response status; `>= 400` renders as an error badge. */
34
- status?: number;
35
- /** Response headers (detail panel). */
36
- resHeaders?: Record<string, string>;
37
- /** Response body, pretty-printed as JSON in the detail panel. */
38
- resBody?: unknown;
39
- /** Start time, epoch ms (UTC display). */
40
- start: number;
41
- /** End time, epoch ms. `null`/`undefined` while in flight (bar grows live). */
42
- end?: number | null;
43
- [extra: string]: unknown;
44
- }
4
+ import { TraceTimelineEvent } from './traceEvent';
5
+ import { TimelineWheelZoom } from './useTimeline';
6
+ export type { TraceTimelineEvent, TraceTimelineField, TraceTimelineLevel, } from './traceEvent';
45
7
  export interface TraceTimelineClasses {
46
8
  root: string;
47
9
  toolbar: string;
@@ -115,6 +77,15 @@ export interface TraceTimelineProps {
115
77
  showGridlines?: boolean;
116
78
  /** Toolbar row with the zoom −/%/+/Fit controls. @default true */
117
79
  showControls?: boolean;
80
+ /**
81
+ * How the mouse wheel / trackpad zooms the timeline: `'ctrl'` zooms only
82
+ * while Ctrl/Cmd is held (plain scrolling passes through to the page;
83
+ * trackpad pinch still zooms), `'free'` zooms on any scroll over the
84
+ * canvas, `'none'` disables wheel zoom entirely — the toolbar buttons
85
+ * still work.
86
+ * @default 'ctrl'
87
+ */
88
+ wheelZoom?: TimelineWheelZoom;
118
89
  /** Colored dot + name legend for the services present. @default true */
119
90
  showLegend?: boolean;
120
91
  /**
@@ -139,8 +110,8 @@ export interface TraceTimelineProps {
139
110
  summaryDefaultPosition?: DraggablePosition;
140
111
  /**
141
112
  * Sticky icon rail on the far right with two toggles docking a drawer
142
- * beside the timeline: *Event details* (the request/response panel, with an
143
- * empty state until an event is picked) and *Full log* (every event
113
+ * beside the timeline: *Event details* (the `TraceEventDetails` panel, with
114
+ * an empty state until an event is picked) and *Full log* (every event
144
115
  * vertically with payloads and copy buttons). One drawer at a time; nothing
145
116
  * is docked initially, but clicking an event opens the details drawer.
146
117
  * With `false`, the rail and full log disappear and the details panel
@@ -149,6 +120,19 @@ export interface TraceTimelineProps {
149
120
  showDock?: boolean;
150
121
  /** Drawer docked open initially (uncontrolled). @default null */
151
122
  defaultDock?: TraceTimelineDock;
123
+ /**
124
+ * List event keys the panel doesn't render itself (anything outside the
125
+ * documented ones) under an *Other fields* section in the details drawer.
126
+ * @default true
127
+ */
128
+ showExtraFields?: boolean;
129
+ /**
130
+ * Extra event keys to hide from the details drawer's *Other fields* section
131
+ * and exclude from keyword matching — for plumbing values (tenant ids,
132
+ * ingestion timestamps, …) that ride along on every event and would
133
+ * otherwise clutter the drawer or light up the whole trace when searched.
134
+ */
135
+ hiddenFields?: string[];
152
136
  /** Max height of the scrollable canvas. @default '80vh' */
153
137
  maxHeight?: number | string;
154
138
  /**
@@ -172,7 +156,7 @@ export interface TraceTimelineProps {
172
156
  renderChip?: (event: TraceTimelineEvent, ctx: TraceTimelineItemContext) => ReactNode;
173
157
  /** Replace the tooltip content. Return `null` to suppress it for that event. */
174
158
  renderTooltip?: (event: TraceTimelineEvent, ctx: TraceTimelineItemContext) => ReactNode;
175
- /** Replace the request/response detail panel content; the panel shell is kept. */
159
+ /** Replace the detail panel content entirely; the panel shell is kept. */
176
160
  renderDetails?: (event: TraceTimelineEvent, api: {
177
161
  close: () => void;
178
162
  pending: boolean;
@@ -192,9 +176,12 @@ export interface TraceTimelineProps {
192
176
  * current-date marker; wheel-zoom, drag-pan, fit-to-width; keyword
193
177
  * highlighting; in-flight events render dashed with a "now" line and grow
194
178
  * live. A right-side icon rail docks one drawer at a time: *Event details*
195
- * (the request/response panel, opened by clicking an event) or *Full log*
196
- * (every event vertically with copy-to-clipboard payloads, kept in sync with
197
- * timeline clicks both ways). An events-summary bubble sits bottom-left,
179
+ * (opened by clicking an event) or *Full log* (every event vertically with
180
+ * copy-to-clipboard payloads, kept in sync with timeline clicks both ways).
181
+ * Both adapt to the event: every value is introduced by its own label above
182
+ * it, and only the sections an event actually has are rendered — HTTP calls
183
+ * get Request/Response, plain events get Message/Payload/Details, unknown
184
+ * keys land under *Other fields*. An events-summary bubble sits bottom-left,
198
185
  * expanding into a draggable panel that bands the events currently in view
199
186
  * and navigates on click.
200
187
  *