awesome-timeline-react 0.10.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.
package/dist/index.js CHANGED
@@ -47,12 +47,13 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
47
47
  // src/index.ts
48
48
  var index_exports = {};
49
49
  __export(index_exports, {
50
+ DEFAULT_TIME_BAR_LEVELS: () => DEFAULT_TIME_BAR_LEVELS,
50
51
  Timeline: () => Timeline
51
52
  });
52
53
  module.exports = __toCommonJS(index_exports);
53
54
 
54
55
  // src/timeline.tsx
55
- var import_react7 = __toESM(require("react"));
56
+ var import_react8 = __toESM(require("react"));
56
57
 
57
58
  // src/canvas/animator.ts
58
59
  var DEFAULT_LAYOUT_DURATION_MS = 200;
@@ -129,34 +130,40 @@ var LayoutAnimator = class {
129
130
 
130
131
  // src/hooks/use-resize-observer.ts
131
132
  var import_react = require("react");
133
+ var createWidthObserver = (getWindow, onScale) => {
134
+ let prevWidth = 0;
135
+ return new ResizeObserver((entries) => {
136
+ var _a;
137
+ for (const entry of entries) {
138
+ const width = (_a = entry.borderBoxSize) == null ? void 0 : _a[0].inlineSize;
139
+ if (typeof width === "number" && width !== prevWidth) {
140
+ prevWidth = width;
141
+ const [start, end] = getWindow();
142
+ const windowDuration = end - start;
143
+ onScale(
144
+ windowDuration / entry.contentRect.width,
145
+ entry.contentRect.width / (windowDuration / 3600)
146
+ );
147
+ }
148
+ }
149
+ });
150
+ };
132
151
  var useResizeObserver = ({
133
- windowTime,
152
+ windowTimeRef,
134
153
  setTick,
135
154
  setCellWidth,
136
155
  contentRef
137
156
  }) => {
138
- const prevWidthRef = (0, import_react.useRef)(0);
139
- const resizeObserver = (0, import_react.useMemo)(() => {
140
- return new ResizeObserver((entries) => {
141
- var _a;
142
- for (const entry of entries) {
143
- const width = (_a = entry.borderBoxSize) == null ? void 0 : _a[0].inlineSize;
144
- if (typeof width === "number" && width !== prevWidthRef.current) {
145
- prevWidthRef.current = width;
146
- const windowDuration = windowTime[1] - windowTime[0];
147
- const numberOfHourBlocks = windowDuration / 3600;
148
- setTick(windowDuration / entry.contentRect.width);
149
- setCellWidth(entry.contentRect.width / numberOfHourBlocks);
150
- }
151
- }
152
- });
153
- }, [windowTime]);
154
157
  (0, import_react.useEffect)(() => {
158
+ const observer = createWidthObserver(() => windowTimeRef.current, (tick, cellWidth) => {
159
+ setTick(tick);
160
+ setCellWidth(cellWidth);
161
+ });
155
162
  if (contentRef.current) {
156
- resizeObserver.observe(contentRef.current, { box: "border-box" });
163
+ observer.observe(contentRef.current, { box: "border-box" });
157
164
  }
158
- return () => resizeObserver.disconnect();
159
- }, [resizeObserver]);
165
+ return () => observer.disconnect();
166
+ }, [windowTimeRef, setTick, setCellWidth, contentRef]);
160
167
  };
161
168
  var use_resize_observer_default = useResizeObserver;
162
169
 
@@ -321,6 +328,15 @@ var hourLabel = (hour) => `${pad2(hour)}:00`;
321
328
  var dayLabel = (date) => `${get_week_day_name_default(date.getDay())} ${date.getDate()} ${get_month_name_default(
322
329
  date.getMonth()
323
330
  )}`;
331
+ var isoWeek = (date) => {
332
+ const thursday = new Date(
333
+ date.getFullYear(),
334
+ date.getMonth(),
335
+ date.getDate() + 3 - (date.getDay() + 6) % 7
336
+ );
337
+ const jan1 = new Date(thursday.getFullYear(), 0, 1);
338
+ return 1 + Math.floor(Math.round((thursday.getTime() - jan1.getTime()) / 864e5) / 7);
339
+ };
324
340
  var defaultFormat = (unit) => {
325
341
  if (typeof unit === "object") {
326
342
  return (d) => `${pad2(d.getHours())}:${pad2(d.getMinutes())}`;
@@ -330,6 +346,8 @@ var defaultFormat = (unit) => {
330
346
  return (d) => hourLabel(d.getHours());
331
347
  case "month":
332
348
  return (d) => `${get_month_name_default(d.getMonth())} ${d.getFullYear()}`;
349
+ case "year":
350
+ return (d) => `${d.getFullYear()}`;
333
351
  case "day":
334
352
  case "week":
335
353
  default:
@@ -356,6 +374,8 @@ var floorToUnit = (date, unit, anchorSec) => {
356
374
  }
357
375
  case "month":
358
376
  return new Date(y, mo, 1);
377
+ case "year":
378
+ return new Date(y, 0, 1);
359
379
  }
360
380
  };
361
381
  var nextBoundary = (blockStart, unit) => {
@@ -374,7 +394,35 @@ var nextBoundary = (blockStart, unit) => {
374
394
  return new Date(y, mo, d + 7);
375
395
  case "month":
376
396
  return new Date(y, mo + 1, 1);
397
+ case "year":
398
+ return new Date(y + 1, 0, 1);
399
+ }
400
+ };
401
+ var blockSpans = (unit, windowStart, windowEnd, limit = 1e5) => {
402
+ const spans = [];
403
+ if (typeof unit === "object" && "boundaries" in unit) {
404
+ const edges = unit.boundaries(windowStart, windowEnd);
405
+ for (let i = 0; i + 1 < edges.length; i++) {
406
+ const [start, end] = [edges[i], edges[i + 1]];
407
+ if (end <= windowStart || start >= windowEnd || end <= start) continue;
408
+ if (spans.length >= limit) return null;
409
+ spans.push([start, end]);
410
+ }
411
+ return spans;
412
+ }
413
+ const day = new Date(windowStart * 1e3);
414
+ const anchorSec = new Date(day.getFullYear(), day.getMonth(), day.getDate()).getTime() / 1e3;
415
+ let cursorSec = windowStart;
416
+ while (cursorSec < windowEnd) {
417
+ const blockStart = floorToUnit(new Date(cursorSec * 1e3), unit, anchorSec);
418
+ const startSec = blockStart.getTime() / 1e3;
419
+ const endSec = nextBoundary(blockStart, unit).getTime() / 1e3;
420
+ if (endSec <= startSec) break;
421
+ if (spans.length >= limit) return null;
422
+ spans.push([startSec, endSec]);
423
+ cursorSec = endSec;
377
424
  }
425
+ return spans;
378
426
  };
379
427
  var generateUnitBlocks = ({
380
428
  unit,
@@ -383,33 +431,55 @@ var generateUnitBlocks = ({
383
431
  windowEnd,
384
432
  tick
385
433
  }) => {
386
- const blocks = [];
434
+ var _a;
435
+ if (tick === null || tick <= 0 || windowEnd <= windowStart) return [];
387
436
  const resolvedUnit = unit != null ? unit : "hour";
388
- if (tick === null || tick <= 0 || windowEnd <= windowStart) return blocks;
389
437
  const label = format != null ? format : defaultFormat(resolvedUnit);
390
- const anchorSec = new Date(
391
- new Date(windowStart * 1e3).getFullYear(),
392
- new Date(windowStart * 1e3).getMonth(),
393
- new Date(windowStart * 1e3).getDate()
394
- ).getTime() / 1e3;
395
- let cursorSec = windowStart;
396
- let guard = 0;
397
- while (cursorSec < windowEnd && guard++ < 1e5) {
398
- const blockStart = floorToUnit(new Date(cursorSec * 1e3), resolvedUnit, anchorSec);
399
- const blockEnd = nextBoundary(blockStart, resolvedUnit);
400
- const startSec = blockStart.getTime() / 1e3;
401
- const endSec = blockEnd.getTime() / 1e3;
402
- if (endSec <= startSec) break;
403
- const visibleStart = Math.max(startSec, windowStart);
404
- const visibleEnd = Math.min(endSec, windowEnd);
405
- blocks.push({
406
- label: label(blockStart, blockEnd),
407
- x: (visibleStart - windowStart) / tick,
408
- width: (visibleEnd - visibleStart) / tick
409
- });
410
- cursorSec = endSec;
438
+ return ((_a = blockSpans(resolvedUnit, windowStart, windowEnd)) != null ? _a : []).map(
439
+ ([startSec, endSec]) => {
440
+ const visibleStart = Math.max(startSec, windowStart);
441
+ const visibleEnd = Math.min(endSec, windowEnd);
442
+ return {
443
+ label: label(new Date(startSec * 1e3), new Date(endSec * 1e3)),
444
+ x: (visibleStart - windowStart) / tick,
445
+ width: (visibleEnd - visibleStart) / tick
446
+ };
447
+ }
448
+ );
449
+ };
450
+ var shortDay = (d) => `${get_week_day_name_default(d.getDay())} ${d.getDate()}`;
451
+ var DEFAULT_TIME_BAR_LEVELS = [
452
+ { topRow: { unit: "day" }, bottomRow: { unit: "hour" } },
453
+ { topRow: { unit: "day" }, bottomRow: { unit: { stepSeconds: 6 * 3600 } } },
454
+ {
455
+ topRow: {
456
+ unit: "week",
457
+ format: (d) => `W${isoWeek(d)} \xB7 ${d.getDate()} ${get_month_name_default(d.getMonth())}`
458
+ },
459
+ bottomRow: { unit: "day", format: shortDay }
460
+ },
461
+ { topRow: { unit: "month" }, bottomRow: { unit: "week", format: (d) => `W${isoWeek(d)}` } },
462
+ { topRow: { unit: "year" }, bottomRow: { unit: "month", format: (d) => get_month_name_default(d.getMonth()) } }
463
+ ];
464
+ var DEFAULT_MIN_BLOCK_WIDTH = 40;
465
+ var resolveTimeBar = (timeBar, windowStart, windowEnd, tick) => {
466
+ var _a, _b, _c;
467
+ if (!(timeBar == null ? void 0 : timeBar.auto)) {
468
+ return {
469
+ topRow: (_a = timeBar == null ? void 0 : timeBar.topRow) != null ? _a : { unit: "day" },
470
+ bottomRow: (_b = timeBar == null ? void 0 : timeBar.bottomRow) != null ? _b : { unit: "hour" }
471
+ };
411
472
  }
412
- return blocks;
473
+ const { levels = DEFAULT_TIME_BAR_LEVELS, minBlockWidth = DEFAULT_MIN_BLOCK_WIDTH } = timeBar.auto === true ? {} : timeBar.auto;
474
+ const levelsOrDefault = levels.length > 0 ? levels : DEFAULT_TIME_BAR_LEVELS;
475
+ if (tick === null || tick <= 0 || windowEnd <= windowStart) return levelsOrDefault[0];
476
+ const minSecs = minBlockWidth * tick;
477
+ const limit = Math.ceil((windowEnd - windowStart) / minSecs) + 2;
478
+ return (_c = levelsOrDefault.find((level) => {
479
+ var _a2;
480
+ const spans = blockSpans((_a2 = level.bottomRow.unit) != null ? _a2 : "hour", windowStart, windowEnd, limit);
481
+ return spans !== null && spans.every(([start, end]) => end - start >= minSecs);
482
+ })) != null ? _c : levelsOrDefault[levelsOrDefault.length - 1];
413
483
  };
414
484
 
415
485
  // src/canvas/dpr.ts
@@ -469,7 +539,9 @@ var DEFAULT_THEME = {
469
539
  barRadius: 5,
470
540
  minHitWidth: 0,
471
541
  groupChildBackground: "rgba(0,0,0,0.05)",
472
- groupShadowColor: "rgba(0,0,0,0.22)"
542
+ groupShadowColor: "rgba(0,0,0,0.22)",
543
+ pointerLineColor: "rgba(15,23,42,0.7)",
544
+ pointerLabelColor: "#ffffff"
473
545
  };
474
546
  var resolveTheme = (theme) => __spreadValues(__spreadValues({}, DEFAULT_THEME), theme);
475
547
 
@@ -497,6 +569,24 @@ var drawGridLines = (ctx, {
497
569
  }
498
570
  ctx.stroke();
499
571
  };
572
+ var drawBlockGridLines = (ctx, {
573
+ width,
574
+ height,
575
+ blocks,
576
+ color = DEFAULT_THEME.gridColor
577
+ }) => {
578
+ ctx.strokeStyle = color;
579
+ ctx.lineWidth = 1;
580
+ ctx.beginPath();
581
+ for (let i = 0; i < blocks.length - 1; i++) {
582
+ const x = blocks[i].x + blocks[i].width;
583
+ if (x < 1 || width - x < 1) continue;
584
+ const crisp = Math.round(x) - 0.5;
585
+ ctx.moveTo(crisp, 0);
586
+ ctx.lineTo(crisp, height);
587
+ }
588
+ ctx.stroke();
589
+ };
500
590
  var drawTimeBar = (ctx, {
501
591
  width,
502
592
  height,
@@ -549,7 +639,8 @@ var drawTimeBar = (ctx, {
549
639
  };
550
640
 
551
641
  // src/components/canvas-time-bar.tsx
552
- var TIME_BAR_INNER_HEIGHT = 48;
642
+ var TIME_BAR_HEIGHT = 50;
643
+ var TIME_BAR_INNER_HEIGHT = TIME_BAR_HEIGHT - 2;
553
644
  var CanvasTimeBar = ({
554
645
  windowTime,
555
646
  tick,
@@ -558,11 +649,9 @@ var CanvasTimeBar = ({
558
649
  theme,
559
650
  timeBar
560
651
  }) => {
561
- var _a, _b, _c;
652
+ var _a;
562
653
  const canvasRef = (0, import_react4.useRef)(null);
563
654
  const header = theme != null ? theme : DEFAULT_THEME;
564
- const topRow = (_a = timeBar == null ? void 0 : timeBar.topRow) != null ? _a : { unit: "day" };
565
- const bottomRow = (_b = timeBar == null ? void 0 : timeBar.bottomRow) != null ? _b : { unit: "hour" };
566
655
  (0, import_react4.useEffect)(() => {
567
656
  var _a2;
568
657
  const canvas = canvasRef.current;
@@ -575,6 +664,7 @@ var CanvasTimeBar = ({
575
664
  );
576
665
  if (!ctx) return;
577
666
  const [windowStart, windowEnd] = windowTime;
667
+ const { topRow, bottomRow } = resolveTimeBar(timeBar, windowStart, windowEnd, tick);
578
668
  drawTimeBar(ctx, {
579
669
  width: contentWidth,
580
670
  height: TIME_BAR_INNER_HEIGHT,
@@ -611,7 +701,7 @@ var CanvasTimeBar = ({
611
701
  width: scrollWidth,
612
702
  height: "100%",
613
703
  boxSizing: "border-box",
614
- borderLeft: `1px solid ${(_c = header.headerBorderColor) != null ? _c : "yellow"}`
704
+ borderLeft: `1px solid ${(_a = header.headerBorderColor) != null ? _a : "yellow"}`
615
705
  }
616
706
  }
617
707
  ) : null
@@ -1186,6 +1276,28 @@ var TimelineRenderer = class {
1186
1276
  this.font = getComputedStyle(this.dynamicCanvas).font || this.font;
1187
1277
  }
1188
1278
  }
1279
+ drawGrid(ctx, tick) {
1280
+ const { width, height, windowTime, timeBar, theme } = this.view;
1281
+ if (timeBar == null ? void 0 : timeBar.auto) {
1282
+ const [windowStart, windowEnd] = windowTime;
1283
+ const { bottomRow } = resolveTimeBar(timeBar, windowStart, windowEnd, tick);
1284
+ drawBlockGridLines(ctx, {
1285
+ width,
1286
+ height,
1287
+ blocks: generateUnitBlocks(__spreadProps(__spreadValues({}, bottomRow), { windowStart, windowEnd, tick })),
1288
+ color: theme.gridColor
1289
+ });
1290
+ return;
1291
+ }
1292
+ drawGridLines(ctx, {
1293
+ width,
1294
+ height,
1295
+ cellWidth: this.view.cellWidth,
1296
+ windowStart: windowTime[0],
1297
+ tick,
1298
+ color: theme.gridColor
1299
+ });
1300
+ }
1189
1301
  drawFrame(dirty) {
1190
1302
  if (this.view.tick === null) return;
1191
1303
  this.animator.beginFrame(performance.now());
@@ -1194,14 +1306,7 @@ var TimelineRenderer = class {
1194
1306
  if (ctx) {
1195
1307
  ctx.clearRect(0, 0, this.view.width, this.view.height);
1196
1308
  drawGroupShading(ctx, this.view, this.scene);
1197
- drawGridLines(ctx, {
1198
- width: this.view.width,
1199
- height: this.view.height,
1200
- cellWidth: this.view.cellWidth,
1201
- windowStart: this.view.windowTime[0],
1202
- tick: this.view.tick,
1203
- color: this.view.theme.gridColor
1204
- });
1309
+ this.drawGrid(ctx, this.view.tick);
1205
1310
  drawRowDividers(ctx, this.view, this.scene);
1206
1311
  }
1207
1312
  }
@@ -2010,6 +2115,7 @@ var CanvasBoard = (0, import_react6.forwardRef)(
2010
2115
  onEventHover,
2011
2116
  eventsResize,
2012
2117
  stripeOverlap,
2118
+ timeBar,
2013
2119
  panZoom,
2014
2120
  animations,
2015
2121
  selectable,
@@ -2051,7 +2157,8 @@ var CanvasBoard = (0, import_react6.forwardRef)(
2051
2157
  theme,
2052
2158
  drawEvent,
2053
2159
  eventsResize,
2054
- stripeOverlap
2160
+ stripeOverlap,
2161
+ timeBar
2055
2162
  });
2056
2163
  }, [
2057
2164
  windowTime,
@@ -2061,6 +2168,7 @@ var CanvasBoard = (0, import_react6.forwardRef)(
2061
2168
  drawEvent,
2062
2169
  eventsResize,
2063
2170
  stripeOverlap,
2171
+ timeBar,
2064
2172
  animations,
2065
2173
  rendererRef
2066
2174
  ]);
@@ -2358,6 +2466,43 @@ var CanvasBoard = (0, import_react6.forwardRef)(
2358
2466
  );
2359
2467
  var canvas_board_default = CanvasBoard;
2360
2468
 
2469
+ // src/components/pointer-line.tsx
2470
+ var import_react7 = __toESM(require("react"));
2471
+ var PointerLine = (0, import_react7.forwardRef)(({ contentRef, mainRef, top, color, labelColor, font }, ref) => {
2472
+ const lineRef = (0, import_react7.useRef)(null);
2473
+ const labelRef = (0, import_react7.useRef)(null);
2474
+ (0, import_react7.useImperativeHandle)(ref, () => ({
2475
+ show: (x, label) => {
2476
+ var _a, _b;
2477
+ const line = lineRef.current, tag = labelRef.current;
2478
+ const content = contentRef.current, main = mainRef.current;
2479
+ if (!line || !tag || !content || !main) return;
2480
+ const box = content.getBoundingClientRect();
2481
+ const frame = main.getBoundingClientRect();
2482
+ const left = box.left - frame.left;
2483
+ const bottom = Math.min(box.bottom, (_b = (_a = content.parentElement) == null ? void 0 : _a.getBoundingClientRect().bottom) != null ? _b : box.bottom);
2484
+ line.style.height = `${Math.max(bottom - frame.top - top, 0)}px`;
2485
+ line.style.display = "block";
2486
+ line.style.transform = `translateX(${Math.round(left + x)}px)`;
2487
+ if (label === null) {
2488
+ tag.style.display = "none";
2489
+ return;
2490
+ }
2491
+ tag.textContent = label;
2492
+ tag.style.display = "block";
2493
+ const w = tag.offsetWidth;
2494
+ const at = Math.min(Math.max(x - w / 2, 0), Math.max(box.width - w, 0));
2495
+ tag.style.transform = `translateX(${Math.round(left + at)}px)`;
2496
+ },
2497
+ hide: () => {
2498
+ if (lineRef.current) lineRef.current.style.display = "none";
2499
+ if (labelRef.current) labelRef.current.style.display = "none";
2500
+ }
2501
+ }), [contentRef, mainRef, top]);
2502
+ return /* @__PURE__ */ import_react7.default.createElement(import_react7.default.Fragment, null, /* @__PURE__ */ import_react7.default.createElement("div", { ref: lineRef, className: "pointer-line", style: { top, borderLeftColor: color } }), /* @__PURE__ */ import_react7.default.createElement("div", { ref: labelRef, className: "pointer-label", style: { background: color, color: labelColor, font } }));
2503
+ });
2504
+ var pointer_line_default = PointerLine;
2505
+
2361
2506
  // src/core/scene.ts
2362
2507
  var binaryInsertIndex = (events, event) => {
2363
2508
  let lo = 0;
@@ -2817,7 +2962,8 @@ var SceneStore = class {
2817
2962
  };
2818
2963
 
2819
2964
  // src/timeline.tsx
2820
- var Timeline = (0, import_react7.forwardRef)(
2965
+ var defaultPointerFormat = (time) => new Date(time * 1e3).toLocaleString();
2966
+ var Timeline = (0, import_react8.forwardRef)(
2821
2967
  ({
2822
2968
  rows,
2823
2969
  events,
@@ -2845,9 +2991,12 @@ var Timeline = (0, import_react7.forwardRef)(
2845
2991
  panZoom,
2846
2992
  timeBar,
2847
2993
  showTimeBar = true,
2994
+ showPointerLine = false,
2995
+ formatPointerTime,
2996
+ onPointerTime,
2848
2997
  animations = true
2849
2998
  }, handleRef) => {
2850
- const [windowTime, setWindowTime] = (0, import_react7.useState)([
2999
+ const [windowTime, setWindowTime] = (0, import_react8.useState)([
2851
3000
  new Date(
2852
3001
  startDate.getFullYear(),
2853
3002
  startDate.getMonth(),
@@ -2865,25 +3014,25 @@ var Timeline = (0, import_react7.forwardRef)(
2865
3014
  0
2866
3015
  ).getTime() / 1e3
2867
3016
  ]);
2868
- const [cellWidth, setCellWidth] = (0, import_react7.useState)(0);
2869
- const contentRef = (0, import_react7.useRef)(null);
2870
- const mainRef = (0, import_react7.useRef)(null);
2871
- const bodyRef = (0, import_react7.useRef)(null);
2872
- const [tick, setTick] = (0, import_react7.useState)(null);
2873
- const [scrollWidth, setScrollWidth] = (0, import_react7.useState)(0);
2874
- const eventPromptRef = (0, import_react7.useRef)(null);
2875
- const rendererRef = (0, import_react7.useRef)(null);
2876
- const sceneRef = (0, import_react7.useRef)(null);
3017
+ const [cellWidth, setCellWidth] = (0, import_react8.useState)(0);
3018
+ const contentRef = (0, import_react8.useRef)(null);
3019
+ const mainRef = (0, import_react8.useRef)(null);
3020
+ const bodyRef = (0, import_react8.useRef)(null);
3021
+ const [tick, setTick] = (0, import_react8.useState)(null);
3022
+ const [scrollWidth, setScrollWidth] = (0, import_react8.useState)(0);
3023
+ const eventPromptRef = (0, import_react8.useRef)(null);
3024
+ const rendererRef = (0, import_react8.useRef)(null);
3025
+ const sceneRef = (0, import_react8.useRef)(null);
2877
3026
  if (sceneRef.current === null) {
2878
3027
  sceneRef.current = new SceneStore();
2879
3028
  }
2880
3029
  const scene = sceneRef.current;
2881
- const selectionRef = (0, import_react7.useRef)(
3030
+ const selectionRef = (0, import_react8.useRef)(
2882
3031
  new Set(defaultSelectedEventIds != null ? defaultSelectedEventIds : [])
2883
3032
  );
2884
- const onSelectionChangeRef = (0, import_react7.useRef)(onSelectionChange);
3033
+ const onSelectionChangeRef = (0, import_react8.useRef)(onSelectionChange);
2885
3034
  onSelectionChangeRef.current = onSelectionChange;
2886
- const applySelection = (0, import_react7.useCallback)(
3035
+ const applySelection = (0, import_react8.useCallback)(
2887
3036
  (ids) => {
2888
3037
  var _a, _b;
2889
3038
  const expanded = [];
@@ -2903,13 +3052,13 @@ var Timeline = (0, import_react7.forwardRef)(
2903
3052
  },
2904
3053
  [scene]
2905
3054
  );
2906
- const getSelection = (0, import_react7.useCallback)(() => [...selectionRef.current], []);
2907
- (0, import_react7.useEffect)(() => {
3055
+ const getSelection = (0, import_react8.useCallback)(() => [...selectionRef.current], []);
3056
+ (0, import_react8.useEffect)(() => {
2908
3057
  var _a;
2909
3058
  scene.setRows(rows);
2910
3059
  (_a = rendererRef.current) == null ? void 0 : _a.animator.reset();
2911
3060
  }, [scene, rows]);
2912
- (0, import_react7.useEffect)(() => {
3061
+ (0, import_react8.useEffect)(() => {
2913
3062
  var _a, _b, _c;
2914
3063
  scene.setEvents([...events].sort(sort_events_default));
2915
3064
  (_a = rendererRef.current) == null ? void 0 : _a.animator.reset();
@@ -2922,26 +3071,89 @@ var Timeline = (0, import_react7.forwardRef)(
2922
3071
  (_c = onSelectionChangeRef.current) == null ? void 0 : _c.call(onSelectionChangeRef, survivors);
2923
3072
  }
2924
3073
  }, [scene, events]);
2925
- (0, import_react7.useEffect)(() => {
3074
+ (0, import_react8.useEffect)(() => {
2926
3075
  scene.setStaticEvents(staticEvents ? [...staticEvents] : []);
2927
3076
  }, [scene, staticEvents]);
2928
- const seededCollapseRef = (0, import_react7.useRef)(false);
2929
- (0, import_react7.useEffect)(() => {
3077
+ const seededCollapseRef = (0, import_react8.useRef)(false);
3078
+ (0, import_react8.useEffect)(() => {
2930
3079
  if (seededCollapseRef.current) return;
2931
3080
  seededCollapseRef.current = true;
2932
3081
  for (const id of defaultCollapsedRowIds != null ? defaultCollapsedRowIds : []) {
2933
3082
  scene.setCollapsed(id, true);
2934
3083
  }
2935
3084
  }, [scene, defaultCollapsedRowIds]);
2936
- const windowTimeRef = (0, import_react7.useRef)(windowTime);
3085
+ const windowTimeRef = (0, import_react8.useRef)(windowTime);
2937
3086
  windowTimeRef.current = windowTime;
2938
- const onWindowChangeRef = (0, import_react7.useRef)(onWindowChange);
3087
+ const onWindowChangeRef = (0, import_react8.useRef)(onWindowChange);
2939
3088
  onWindowChangeRef.current = onWindowChange;
2940
- (0, import_react7.useEffect)(() => {
3089
+ (0, import_react8.useEffect)(() => {
2941
3090
  var _a;
2942
3091
  (_a = onWindowChangeRef.current) == null ? void 0 : _a.call(onWindowChangeRef, { startTime: windowTime[0], endTime: windowTime[1] });
2943
3092
  }, [windowTime[0], windowTime[1]]);
2944
- (0, import_react7.useImperativeHandle)(
3093
+ const tickRef = (0, import_react8.useRef)(tick);
3094
+ tickRef.current = tick;
3095
+ const pointerLineRef = (0, import_react8.useRef)(null);
3096
+ const pointerRef = (0, import_react8.useRef)(null);
3097
+ const pointerOpts = (0, import_react8.useRef)({ showPointerLine, showTimeBar, formatPointerTime, onPointerTime });
3098
+ pointerOpts.current = { showPointerLine, showTimeBar, formatPointerTime, onPointerTime };
3099
+ const drawPointer = (0, import_react8.useCallback)(() => {
3100
+ var _a, _b, _c;
3101
+ const line = pointerLineRef.current;
3102
+ const p = pointerRef.current;
3103
+ const t = tickRef.current;
3104
+ if (!line) return;
3105
+ if (!p || !t) return line.hide();
3106
+ if ("x" in p && ((_a = rendererRef.current) == null ? void 0 : _a.getView().hoveredEventId)) return line.hide();
3107
+ const start = windowTimeRef.current[0];
3108
+ const time = "x" in p ? start + p.x * t : p.time;
3109
+ const x = "x" in p ? p.x : (p.time - start) / t;
3110
+ const width = (_c = (_b = contentRef.current) == null ? void 0 : _b.getBoundingClientRect().width) != null ? _c : 0;
3111
+ if (x < 0 || x > width) return line.hide();
3112
+ const { showTimeBar: labelled, formatPointerTime: format } = pointerOpts.current;
3113
+ line.show(x, labelled ? (format != null ? format : defaultPointerFormat)(time) : null);
3114
+ }, []);
3115
+ (0, import_react8.useEffect)(() => {
3116
+ const column = contentRef.current;
3117
+ if (!column) return;
3118
+ const move = (e) => {
3119
+ var _a, _b;
3120
+ const t = tickRef.current;
3121
+ if (!t) return;
3122
+ const x = e.clientX - column.getBoundingClientRect().left;
3123
+ (_b = (_a = pointerOpts.current).onPointerTime) == null ? void 0 : _b.call(_a, windowTimeRef.current[0] + x * t);
3124
+ if (!pointerOpts.current.showPointerLine) return;
3125
+ pointerRef.current = { x };
3126
+ drawPointer();
3127
+ };
3128
+ const leave = () => {
3129
+ var _a, _b;
3130
+ (_b = (_a = pointerOpts.current).onPointerTime) == null ? void 0 : _b.call(_a, null);
3131
+ if (pointerRef.current && "x" in pointerRef.current) {
3132
+ pointerRef.current = null;
3133
+ drawPointer();
3134
+ }
3135
+ };
3136
+ column.addEventListener("pointermove", move);
3137
+ column.addEventListener("pointerleave", leave);
3138
+ return () => {
3139
+ column.removeEventListener("pointermove", move);
3140
+ column.removeEventListener("pointerleave", leave);
3141
+ };
3142
+ }, [drawPointer]);
3143
+ (0, import_react8.useEffect)(() => {
3144
+ var _a, _b;
3145
+ const p = pointerRef.current;
3146
+ if (p && "x" in p && tick) (_b = (_a = pointerOpts.current).onPointerTime) == null ? void 0 : _b.call(_a, windowTime[0] + p.x * tick);
3147
+ drawPointer();
3148
+ }, [windowTime[0], windowTime[1], tick, drawPointer]);
3149
+ const onEventHoverRef = (0, import_react8.useRef)(onEventHover);
3150
+ onEventHoverRef.current = onEventHover;
3151
+ const handleEventHover = (0, import_react8.useCallback)((hover) => {
3152
+ var _a;
3153
+ drawPointer();
3154
+ (_a = onEventHoverRef.current) == null ? void 0 : _a.call(onEventHoverRef, hover);
3155
+ }, [drawPointer]);
3156
+ (0, import_react8.useImperativeHandle)(
2945
3157
  handleRef,
2946
3158
  () => ({
2947
3159
  setEvents: (next) => scene.setEvents([...next].sort(sort_events_default)),
@@ -2959,6 +3171,7 @@ var Timeline = (0, import_react7.forwardRef)(
2959
3171
  // the scale follows the window, or a zoom applied from outside draws and pans at the old one
2960
3172
  setWindow: (startTime, endTime) => {
2961
3173
  var _a;
3174
+ windowTimeRef.current = [startTime, endTime];
2962
3175
  setWindowTime([startTime, endTime]);
2963
3176
  const width = (_a = contentRef.current) == null ? void 0 : _a.getBoundingClientRect().width;
2964
3177
  if (width && endTime > startTime) {
@@ -2970,6 +3183,10 @@ var Timeline = (0, import_react7.forwardRef)(
2970
3183
  startTime: windowTimeRef.current[0],
2971
3184
  endTime: windowTimeRef.current[1]
2972
3185
  }),
3186
+ setPointerTime: (time) => {
3187
+ pointerRef.current = time === null ? null : { time };
3188
+ drawPointer();
3189
+ },
2973
3190
  setSelection: (ids) => applySelection(ids),
2974
3191
  getSelection,
2975
3192
  toggleRow: (rowId) => scene.toggleCollapsed(rowId),
@@ -2979,9 +3196,9 @@ var Timeline = (0, import_react7.forwardRef)(
2979
3196
  return (_a = rendererRef.current) == null ? void 0 : _a.invalidate("all");
2980
3197
  }
2981
3198
  }),
2982
- [scene, applySelection, getSelection]
3199
+ [scene, applySelection, getSelection, drawPointer]
2983
3200
  );
2984
- (0, import_react7.useEffect)(() => {
3201
+ (0, import_react8.useEffect)(() => {
2985
3202
  if (contentRef.current) {
2986
3203
  const windowDuration = windowTime[1] - windowTime[0];
2987
3204
  const numberOfHourBlocks = windowDuration / 3600;
@@ -3009,8 +3226,8 @@ var Timeline = (0, import_react7.forwardRef)(
3009
3226
  0,
3010
3227
  0
3011
3228
  ).getTime() / 1e3;
3012
- const lastFitRef = (0, import_react7.useRef)([fitStart, fitEnd]);
3013
- (0, import_react7.useEffect)(() => {
3229
+ const lastFitRef = (0, import_react8.useRef)([fitStart, fitEnd]);
3230
+ (0, import_react8.useEffect)(() => {
3014
3231
  var _a;
3015
3232
  if (lastFitRef.current[0] === fitStart && lastFitRef.current[1] === fitEnd) {
3016
3233
  return;
@@ -3024,23 +3241,23 @@ var Timeline = (0, import_react7.forwardRef)(
3024
3241
  setCellWidth(width / (windowDuration / 3600));
3025
3242
  }
3026
3243
  }, [fitStart, fitEnd]);
3027
- (0, import_react7.useEffect)(() => {
3244
+ (0, import_react8.useEffect)(() => {
3028
3245
  if (bodyRef.current) {
3029
3246
  setScrollWidth(
3030
3247
  bodyRef.current.getBoundingClientRect().width - bodyRef.current.scrollWidth
3031
3248
  );
3032
3249
  }
3033
3250
  }, []);
3034
- use_resize_observer_default({ contentRef, setCellWidth, setTick, windowTime });
3035
- const resolvedTheme = (0, import_react7.useMemo)(() => resolveTheme(theme), [theme]);
3036
- const geometry = (0, import_react7.useMemo)(
3251
+ use_resize_observer_default({ contentRef, setCellWidth, setTick, windowTimeRef });
3252
+ const resolvedTheme = (0, import_react8.useMemo)(() => resolveTheme(theme), [theme]);
3253
+ const geometry = (0, import_react8.useMemo)(
3037
3254
  () => geometryFromTheme(resolvedTheme),
3038
3255
  [resolvedTheme]
3039
3256
  );
3040
- (0, import_react7.useEffect)(() => {
3257
+ (0, import_react8.useEffect)(() => {
3041
3258
  scene.setGeometry(geometry);
3042
3259
  }, [scene, geometry]);
3043
- const resolvedAnimations = (0, import_react7.useMemo)(() => {
3260
+ const resolvedAnimations = (0, import_react8.useMemo)(() => {
3044
3261
  var _a, _b;
3045
3262
  if (animations === false) return { layoutMs: 0, fadeMs: 0 };
3046
3263
  if (animations === true) {
@@ -3054,8 +3271,8 @@ var Timeline = (0, import_react7.forwardRef)(
3054
3271
  fadeMs: (_b = animations.fadeMs) != null ? _b : DEFAULT_FADE_DURATION_MS
3055
3272
  };
3056
3273
  }, [animations]);
3057
- const eventPrompt = (0, import_react7.useMemo)(
3058
- () => /* @__PURE__ */ import_react7.default.createElement(
3274
+ const eventPrompt = (0, import_react8.useMemo)(
3275
+ () => /* @__PURE__ */ import_react8.default.createElement(
3059
3276
  event_prompt_default,
3060
3277
  {
3061
3278
  ref: eventPromptRef,
@@ -3064,7 +3281,7 @@ var Timeline = (0, import_react7.forwardRef)(
3064
3281
  ),
3065
3282
  [eventPromptTemplate]
3066
3283
  );
3067
- return /* @__PURE__ */ import_react7.default.createElement("div", { className: "main-wrapper", ref: mainRef }, showRTIndicator && /* @__PURE__ */ import_react7.default.createElement(rt_indicator_default, { tick, windowTime }), showTimeBar && /* @__PURE__ */ import_react7.default.createElement(
3284
+ return /* @__PURE__ */ import_react8.default.createElement("div", { className: "main-wrapper", ref: mainRef }, showRTIndicator && /* @__PURE__ */ import_react8.default.createElement(rt_indicator_default, { tick, windowTime }), showTimeBar && /* @__PURE__ */ import_react8.default.createElement(
3068
3285
  canvas_time_bar_default,
3069
3286
  {
3070
3287
  windowTime,
@@ -3074,7 +3291,7 @@ var Timeline = (0, import_react7.forwardRef)(
3074
3291
  theme: resolvedTheme,
3075
3292
  timeBar
3076
3293
  }
3077
- ), /* @__PURE__ */ import_react7.default.createElement("div", { className: "body-wrapper", ref: bodyRef, style: { borderColor: resolvedTheme.borderColor } }, /* @__PURE__ */ import_react7.default.createElement(
3294
+ ), /* @__PURE__ */ import_react8.default.createElement("div", { className: "body-wrapper", ref: bodyRef, style: { borderColor: resolvedTheme.borderColor } }, /* @__PURE__ */ import_react8.default.createElement(
3078
3295
  canvas_board_default,
3079
3296
  {
3080
3297
  scene,
@@ -3095,9 +3312,10 @@ var Timeline = (0, import_react7.forwardRef)(
3095
3312
  onDrop,
3096
3313
  onResize,
3097
3314
  onEventClick,
3098
- onEventHover,
3315
+ onEventHover: handleEventHover,
3099
3316
  eventsResize,
3100
3317
  stripeOverlap,
3318
+ timeBar,
3101
3319
  panZoom,
3102
3320
  animations: resolvedAnimations,
3103
3321
  selectable,
@@ -3105,11 +3323,23 @@ var Timeline = (0, import_react7.forwardRef)(
3105
3323
  getSelection,
3106
3324
  ref: contentRef
3107
3325
  }
3108
- ), showEventPrompt && eventPrompt));
3326
+ ), showEventPrompt && eventPrompt), /* @__PURE__ */ import_react8.default.createElement(
3327
+ pointer_line_default,
3328
+ {
3329
+ ref: pointerLineRef,
3330
+ contentRef,
3331
+ mainRef,
3332
+ top: showTimeBar ? TIME_BAR_HEIGHT : 0,
3333
+ color: resolvedTheme.pointerLineColor,
3334
+ labelColor: resolvedTheme.pointerLabelColor,
3335
+ font: resolvedTheme.font
3336
+ }
3337
+ ));
3109
3338
  }
3110
3339
  );
3111
3340
  // Annotate the CommonJS export names for ESM import in node:
3112
3341
  0 && (module.exports = {
3342
+ DEFAULT_TIME_BAR_LEVELS,
3113
3343
  Timeline
3114
3344
  });
3115
3345
  //# sourceMappingURL=index.js.map