awesome-timeline-react 0.2.0 → 0.4.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
@@ -52,7 +52,7 @@ __export(index_exports, {
52
52
  module.exports = __toCommonJS(index_exports);
53
53
 
54
54
  // src/timeline.tsx
55
- var import_react8 = __toESM(require("react"));
55
+ var import_react7 = __toESM(require("react"));
56
56
 
57
57
  // src/canvas/animator.ts
58
58
  var DEFAULT_LAYOUT_DURATION_MS = 200;
@@ -60,7 +60,6 @@ var DEFAULT_FADE_DURATION_MS = 120;
60
60
  var ease = (t) => t * t * (3 - 2 * t);
61
61
  var LayoutAnimator = class {
62
62
  constructor() {
63
- this.rowHeights = /* @__PURE__ */ new Map();
64
63
  this.eventTops = /* @__PURE__ */ new Map();
65
64
  this.handleAlphas = /* @__PURE__ */ new Map();
66
65
  this.now = 0;
@@ -75,9 +74,6 @@ var LayoutAnimator = class {
75
74
  beginFrame(now) {
76
75
  this.now = now;
77
76
  }
78
- rowHeight(rowId, target) {
79
- return this.value(this.rowHeights, rowId, target, this.layoutDuration);
80
- }
81
77
  eventTop(eventId, target) {
82
78
  return this.value(this.eventTops, eventId, target, this.layoutDuration);
83
79
  }
@@ -98,7 +94,6 @@ var LayoutAnimator = class {
98
94
  }
99
95
  /** Drop all state, e.g. when the scene is reset wholesale. */
100
96
  reset() {
101
- this.rowHeights.clear();
102
97
  this.eventTops.clear();
103
98
  this.handleAlphas.clear();
104
99
  this.activeUntil = 0;
@@ -263,22 +258,7 @@ var EventPrompt = (0, import_react3.forwardRef)(
263
258
  var event_prompt_default = EventPrompt;
264
259
 
265
260
  // src/components/canvas-time-bar.tsx
266
- var import_react5 = __toESM(require("react"));
267
-
268
- // src/hooks/use-get-block-properties.ts
269
- var import_react4 = require("react");
270
- var useGetBlockProperties = ({
271
- windowTime,
272
- contentWidth
273
- }) => {
274
- const numberOfHourBlocks = (0, import_react4.useMemo)(
275
- () => (windowTime[1] - windowTime[0]) / 3600,
276
- [windowTime]
277
- );
278
- const blockWidth = contentWidth ? contentWidth / numberOfHourBlocks : 0;
279
- return { numberOfHourBlocks, blockWidth };
280
- };
281
- var use_get_block_properties_default = useGetBlockProperties;
261
+ var import_react4 = __toESM(require("react"));
282
262
 
283
263
  // src/helpers/get-month-name.ts
284
264
  var getMonthName = (monthIndex) => {
@@ -328,106 +308,108 @@ var getMonthName = (monthIndex) => {
328
308
  var get_month_name_default = getMonthName;
329
309
 
330
310
  // src/helpers/get-week-day-name.ts
311
+ var WEEKDAY_NAMES = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
331
312
  var getWeekDayName = (dayIndex) => {
332
- let dayName = null;
333
- switch (dayIndex) {
334
- case 0:
335
- dayName = "Mon";
336
- break;
337
- case 1:
338
- dayName = "Tue";
339
- break;
340
- case 2:
341
- dayName = "Wed";
342
- break;
343
- case 3:
344
- dayName = "Thu";
345
- break;
346
- case 4:
347
- dayName = "Fri";
348
- break;
349
- case 5:
350
- dayName = "Sat";
351
- break;
352
- case 6:
353
- dayName = "Sun";
354
- break;
355
- default:
356
- dayName = "Mon";
357
- }
358
- return dayName;
313
+ var _a;
314
+ return (_a = WEEKDAY_NAMES[dayIndex]) != null ? _a : "Sun";
359
315
  };
360
316
  var get_week_day_name_default = getWeekDayName;
361
317
 
362
318
  // src/core/time-blocks.ts
363
- var hourLabel = (hour) => hour < 10 ? `0${hour}:00` : `${hour}:00`;
319
+ var pad2 = (n) => n < 10 ? `0${n}` : `${n}`;
320
+ var hourLabel = (hour) => `${pad2(hour)}:00`;
364
321
  var dayLabel = (date) => `${get_week_day_name_default(date.getDay())} ${date.getDate()} ${get_month_name_default(
365
322
  date.getMonth()
366
323
  )}`;
367
- var generateTimeBlocks = ({
324
+ var defaultFormat = (unit) => {
325
+ if (typeof unit === "object") {
326
+ return (d) => `${pad2(d.getHours())}:${pad2(d.getMinutes())}`;
327
+ }
328
+ switch (unit) {
329
+ case "hour":
330
+ return (d) => hourLabel(d.getHours());
331
+ case "month":
332
+ return (d) => `${get_month_name_default(d.getMonth())} ${d.getFullYear()}`;
333
+ case "day":
334
+ case "week":
335
+ default:
336
+ return (d) => dayLabel(d);
337
+ }
338
+ };
339
+ var floorToUnit = (date, unit, anchorSec) => {
340
+ if (typeof unit === "object") {
341
+ const t = date.getTime() / 1e3;
342
+ const step = unit.stepSeconds;
343
+ return new Date((anchorSec + Math.floor((t - anchorSec) / step) * step) * 1e3);
344
+ }
345
+ const y = date.getFullYear();
346
+ const mo = date.getMonth();
347
+ const d = date.getDate();
348
+ switch (unit) {
349
+ case "hour":
350
+ return new Date(y, mo, d, date.getHours());
351
+ case "day":
352
+ return new Date(y, mo, d);
353
+ case "week": {
354
+ const dow = (date.getDay() + 6) % 7;
355
+ return new Date(y, mo, d - dow);
356
+ }
357
+ case "month":
358
+ return new Date(y, mo, 1);
359
+ }
360
+ };
361
+ var nextBoundary = (blockStart, unit) => {
362
+ if (typeof unit === "object") {
363
+ return new Date(blockStart.getTime() + unit.stepSeconds * 1e3);
364
+ }
365
+ const y = blockStart.getFullYear();
366
+ const mo = blockStart.getMonth();
367
+ const d = blockStart.getDate();
368
+ switch (unit) {
369
+ case "hour":
370
+ return new Date(y, mo, d, blockStart.getHours() + 1);
371
+ case "day":
372
+ return new Date(y, mo, d + 1);
373
+ case "week":
374
+ return new Date(y, mo, d + 7);
375
+ case "month":
376
+ return new Date(y, mo + 1, 1);
377
+ }
378
+ };
379
+ var generateUnitBlocks = ({
380
+ unit,
381
+ format,
368
382
  windowStart,
369
- tick,
370
- contentWidth,
371
- blockWidth
383
+ windowEnd,
384
+ tick
372
385
  }) => {
373
- const dayBlocks = [];
374
- const hourBlocks = [];
375
- if (tick === null || contentWidth === null || blockWidth <= 0) {
376
- return { dayBlocks, hourBlocks };
377
- }
378
- let timePoint = windowStart;
379
- let widthLeft = contentWidth;
380
- let prevNumBlocks = 1;
381
- while (1) {
382
- const datePoint = new Date(timePoint * 1e3);
383
- const endDatePoint = new Date(
384
- datePoint.getFullYear(),
385
- datePoint.getMonth(),
386
- datePoint.getDate(),
387
- 23,
388
- 59,
389
- 59
390
- );
391
- const dateDuration = endDatePoint.getTime() - datePoint.getTime();
392
- const dateWidth = dateDuration / 1e3 / tick;
393
- widthLeft -= dateWidth;
394
- if (Math.round(widthLeft) < 0) {
395
- const numBlocks2 = Math.round((dateWidth + widthLeft) / blockWidth);
396
- for (let i = 0; i < numBlocks2; i++) {
397
- hourBlocks.push({
398
- label: hourLabel(i),
399
- x: hourBlocks.length * blockWidth,
400
- width: blockWidth
401
- });
402
- }
403
- dayBlocks.push({
404
- label: dayLabel(datePoint),
405
- x: (prevNumBlocks - 1) * blockWidth,
406
- width: numBlocks2 * blockWidth
407
- });
408
- prevNumBlocks += numBlocks2;
409
- break;
410
- }
411
- const numBlocks = Math.round(dateWidth / blockWidth);
412
- for (let i = 24 - numBlocks; i < 24; i++) {
413
- hourBlocks.push({
414
- label: hourLabel(i),
415
- x: hourBlocks.length * blockWidth,
416
- width: blockWidth
417
- });
418
- }
419
- dayBlocks.push({
420
- label: dayLabel(datePoint),
421
- x: (prevNumBlocks - 1) * blockWidth,
422
- width: numBlocks * blockWidth
386
+ const blocks = [];
387
+ const resolvedUnit = unit != null ? unit : "hour";
388
+ if (tick === null || tick <= 0 || windowEnd <= windowStart) return blocks;
389
+ 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
423
409
  });
424
- prevNumBlocks += numBlocks;
425
- if (Math.round(widthLeft) === 0) {
426
- break;
427
- }
428
- timePoint = (endDatePoint.getTime() + 1e3) / 1e3;
410
+ cursorSec = endSec;
429
411
  }
430
- return { dayBlocks, hourBlocks };
412
+ return blocks;
431
413
  };
432
414
 
433
415
  // src/canvas/dpr.ts
@@ -475,7 +457,17 @@ var DEFAULT_THEME = {
475
457
  gridColor: "#e4dcdc",
476
458
  timeBarBorder: "yellow",
477
459
  timeBarTextColor: "white",
478
- font: void 0
460
+ dimmedOpacity: 0.35,
461
+ selectionShadowColor: "rgba(0,0,0,0.35)",
462
+ selectionShadowBlur: 8,
463
+ selectionElevation: 2,
464
+ font: void 0,
465
+ barHeight: 20,
466
+ laneGap: 2,
467
+ rowPaddingY: 10,
468
+ barRadius: 5,
469
+ groupChildBackground: "rgba(0,0,0,0.05)",
470
+ groupShadowColor: "rgba(0,0,0,0.22)"
479
471
  };
480
472
  var resolveTheme = (theme) => __spreadValues(__spreadValues({}, DEFAULT_THEME), theme);
481
473
 
@@ -484,14 +476,19 @@ var drawGridLines = (ctx, {
484
476
  width,
485
477
  height,
486
478
  cellWidth,
479
+ windowStart,
480
+ tick,
487
481
  color = DEFAULT_THEME.gridColor
488
482
  }) => {
489
- if (cellWidth <= 0) return;
483
+ if (cellWidth <= 0 || tick <= 0) return;
484
+ const cellTime = cellWidth * tick;
490
485
  ctx.strokeStyle = color;
491
486
  ctx.lineWidth = 1;
492
487
  ctx.beginPath();
493
- for (let x = cellWidth; x < width; x += cellWidth) {
494
- if (width - x < 1) break;
488
+ for (let t = Math.floor(windowStart / cellTime) * cellTime + cellTime; ; t += cellTime) {
489
+ const x = (t - windowStart) / tick;
490
+ if (x >= width || width - x < 1) break;
491
+ if (x < 1) continue;
495
492
  const crisp = Math.round(x) - 0.5;
496
493
  ctx.moveTo(crisp, 0);
497
494
  ctx.lineTo(crisp, height);
@@ -501,8 +498,8 @@ var drawGridLines = (ctx, {
501
498
  var drawTimeBar = (ctx, {
502
499
  width,
503
500
  height,
504
- dayBlocks,
505
- hourBlocks,
501
+ topBlocks,
502
+ bottomBlocks,
506
503
  font,
507
504
  borderColor = DEFAULT_THEME.timeBarBorder,
508
505
  textColor = DEFAULT_THEME.timeBarTextColor
@@ -515,13 +512,13 @@ var drawTimeBar = (ctx, {
515
512
  ctx.lineTo(width, Math.round(mid) - 0.5);
516
513
  ctx.stroke();
517
514
  ctx.beginPath();
518
- for (let i = 0; i < dayBlocks.length - 1; i++) {
519
- const edge = Math.round(dayBlocks[i].x + dayBlocks[i].width) - 0.5;
515
+ for (let i = 0; i < topBlocks.length - 1; i++) {
516
+ const edge = Math.round(topBlocks[i].x + topBlocks[i].width) - 0.5;
520
517
  ctx.moveTo(edge, 0);
521
518
  ctx.lineTo(edge, mid);
522
519
  }
523
- for (let i = 0; i < hourBlocks.length - 1; i++) {
524
- const edge = Math.round(hourBlocks[i].x + hourBlocks[i].width) - 0.5;
520
+ for (let i = 0; i < bottomBlocks.length - 1; i++) {
521
+ const edge = Math.round(bottomBlocks[i].x + bottomBlocks[i].width) - 0.5;
525
522
  ctx.moveTo(edge, mid);
526
523
  ctx.lineTo(edge, height);
527
524
  }
@@ -531,7 +528,7 @@ var drawTimeBar = (ctx, {
531
528
  ctx.textBaseline = "middle";
532
529
  ctx.textAlign = "center";
533
530
  const inset = 4;
534
- for (const block of dayBlocks) {
531
+ for (const block of topBlocks) {
535
532
  ctx.fillText(
536
533
  block.label,
537
534
  block.x + block.width / 2,
@@ -539,7 +536,7 @@ var drawTimeBar = (ctx, {
539
536
  block.width - inset
540
537
  );
541
538
  }
542
- for (const block of hourBlocks) {
539
+ for (const block of bottomBlocks) {
543
540
  ctx.fillText(
544
541
  block.label,
545
542
  block.x + block.width / 2,
@@ -556,15 +553,15 @@ var CanvasTimeBar = ({
556
553
  tick,
557
554
  contentWidth,
558
555
  scrollWidth,
559
- theme
556
+ theme,
557
+ timeBar
560
558
  }) => {
561
- const canvasRef = (0, import_react5.useRef)(null);
562
- const { blockWidth } = use_get_block_properties_default({
563
- windowTime,
564
- contentWidth
565
- });
566
- (0, import_react5.useEffect)(() => {
567
- var _a;
559
+ var _a, _b;
560
+ const canvasRef = (0, import_react4.useRef)(null);
561
+ const topRow = (_a = timeBar == null ? void 0 : timeBar.topRow) != null ? _a : { unit: "day" };
562
+ const bottomRow = (_b = timeBar == null ? void 0 : timeBar.bottomRow) != null ? _b : { unit: "hour" };
563
+ (0, import_react4.useEffect)(() => {
564
+ var _a2;
568
565
  const canvas = canvasRef.current;
569
566
  if (!canvas || !contentWidth) return;
570
567
  const ctx = sizeCanvas(
@@ -573,29 +570,30 @@ var CanvasTimeBar = ({
573
570
  TIME_BAR_INNER_HEIGHT,
574
571
  window.devicePixelRatio
575
572
  );
576
- if (ctx) {
577
- drawTimeBar(ctx, __spreadValues({
578
- width: contentWidth,
579
- height: TIME_BAR_INNER_HEIGHT,
580
- font: (_a = theme == null ? void 0 : theme.font) != null ? _a : getComputedStyle(canvas).font,
581
- borderColor: theme == null ? void 0 : theme.timeBarBorder,
582
- textColor: theme == null ? void 0 : theme.timeBarTextColor
583
- }, generateTimeBlocks({
584
- windowStart: windowTime[0],
585
- tick,
586
- contentWidth,
587
- blockWidth
588
- })));
589
- }
590
- }, [windowTime, tick, contentWidth, blockWidth, theme]);
591
- return /* @__PURE__ */ import_react5.default.createElement("div", { className: "time-bar" }, /* @__PURE__ */ import_react5.default.createElement("div", { className: "empty-block" }), /* @__PURE__ */ import_react5.default.createElement(
573
+ if (!ctx) return;
574
+ const [windowStart, windowEnd] = windowTime;
575
+ drawTimeBar(ctx, {
576
+ width: contentWidth,
577
+ height: TIME_BAR_INNER_HEIGHT,
578
+ font: (_a2 = theme == null ? void 0 : theme.font) != null ? _a2 : getComputedStyle(canvas).font,
579
+ borderColor: theme == null ? void 0 : theme.timeBarBorder,
580
+ textColor: theme == null ? void 0 : theme.timeBarTextColor,
581
+ topBlocks: generateUnitBlocks(__spreadProps(__spreadValues({}, topRow), { windowStart, windowEnd, tick })),
582
+ bottomBlocks: generateUnitBlocks(__spreadProps(__spreadValues({}, bottomRow), {
583
+ windowStart,
584
+ windowEnd,
585
+ tick
586
+ }))
587
+ });
588
+ }, [windowTime, tick, contentWidth, theme, timeBar]);
589
+ return /* @__PURE__ */ import_react4.default.createElement("div", { className: "time-bar" }, /* @__PURE__ */ import_react4.default.createElement("div", { className: "empty-block" }), /* @__PURE__ */ import_react4.default.createElement(
592
590
  "canvas",
593
591
  {
594
592
  ref: canvasRef,
595
593
  className: "canvas-time-bar",
596
594
  style: { minWidth: contentWidth ? contentWidth : 0 }
597
595
  }
598
- ), scrollWidth ? /* @__PURE__ */ import_react5.default.createElement(
596
+ ), scrollWidth ? /* @__PURE__ */ import_react4.default.createElement(
599
597
  "div",
600
598
  {
601
599
  style: {
@@ -610,7 +608,7 @@ var CanvasTimeBar = ({
610
608
  var canvas_time_bar_default = CanvasTimeBar;
611
609
 
612
610
  // src/components/canvas-board.tsx
613
- var import_react7 = __toESM(require("react"));
611
+ var import_react6 = __toESM(require("react"));
614
612
 
615
613
  // src/canvas/frame-scheduler.ts
616
614
  var FrameScheduler = class {
@@ -677,15 +675,32 @@ var timeToX = (time, windowStart, tick) => (time - windowStart) / tick;
677
675
  var timeToWidth = (startTime, endTime, tick) => (endTime - startTime) / tick;
678
676
  var intersectsWindow = (event, windowStart, windowEnd) => event.endTime >= windowStart && event.startTime <= windowEnd;
679
677
 
678
+ // src/core/geometry.ts
679
+ var DEFAULT_GEOMETRY = {
680
+ barHeight: 20,
681
+ laneHeight: 22,
682
+ laneTopOffset: 10,
683
+ rowBaseHeight: 40,
684
+ staticEventBaseHeight: 20,
685
+ barRadius: 5
686
+ };
687
+ var geometryFromTheme = (theme) => {
688
+ const barHeight = theme.barHeight;
689
+ const rowPaddingY = theme.rowPaddingY;
690
+ return {
691
+ barHeight,
692
+ laneHeight: barHeight + theme.laneGap,
693
+ laneTopOffset: rowPaddingY,
694
+ rowBaseHeight: barHeight + 2 * rowPaddingY,
695
+ staticEventBaseHeight: barHeight,
696
+ barRadius: theme.barRadius
697
+ };
698
+ };
699
+
680
700
  // src/core/lanes.ts
681
- var LANE_HEIGHT = 22;
682
- var LANE_TOP_OFFSET = 10;
683
- var ROW_BASE_HEIGHT = 40;
684
- var STATIC_EVENT_BASE_HEIGHT = 20;
685
- var EVENT_BAR_HEIGHT = 20;
686
- var laneTop = (lane) => LANE_TOP_OFFSET + LANE_HEIGHT * lane;
687
- var rowMinHeight = (highestLane) => ROW_BASE_HEIGHT + highestLane * LANE_HEIGHT;
688
- var staticEventHeight = (highestLane) => STATIC_EVENT_BASE_HEIGHT + highestLane * LANE_HEIGHT;
701
+ var laneTop = (lane, g = DEFAULT_GEOMETRY) => g.laneTopOffset + g.laneHeight * lane;
702
+ var rowMinHeight = (highestLane, g = DEFAULT_GEOMETRY) => g.rowBaseHeight + highestLane * g.laneHeight;
703
+ var staticEventHeight = (highestLane, g = DEFAULT_GEOMETRY) => g.staticEventBaseHeight + highestLane * g.laneHeight;
689
704
  var assignLanes = (rowEvents, windowStart, windowEnd) => {
690
705
  let eventOrder = 0;
691
706
  const prevEvent = [];
@@ -727,9 +742,9 @@ var computeDropTimes = ({
727
742
  windowStart,
728
743
  duration
729
744
  }) => {
730
- const closestCell = Math.round(pointerX / cellWidth);
731
- const newPosition = cellWidth * closestCell;
732
- const startTime = windowStart + newPosition * tick;
745
+ const cellTime = cellWidth * tick;
746
+ const pointerTime = windowStart + pointerX * tick;
747
+ const startTime = Math.round(pointerTime / cellTime) * cellTime;
733
748
  return { startTime, endTime: startTime + duration };
734
749
  };
735
750
  var computeResizeTimes = (event, deltaPx, tick, direction) => {
@@ -747,9 +762,10 @@ var computeResizeTimes = (event, deltaPx, tick, direction) => {
747
762
  return null;
748
763
  };
749
764
  var canResizeEvent = (event, eventsResize) => {
750
- var _a, _b, _c, _d;
751
- return !((_a = event.props) == null ? void 0 : _a.isLocked) && (eventsResize && (((_b = event.props) == null ? void 0 : _b.isResizable) === true || ((_c = event.props) == null ? void 0 : _c.isResizable) === void 0) || !eventsResize && ((_d = event.props) == null ? void 0 : _d.isResizable) === true);
765
+ var _a, _b, _c, _d, _e;
766
+ return !((_a = event.props) == null ? void 0 : _a.isLocked) && !((_b = event.props) == null ? void 0 : _b.isGroupParent) && (eventsResize && (((_c = event.props) == null ? void 0 : _c.isResizable) === true || ((_d = event.props) == null ? void 0 : _d.isResizable) === void 0) || !eventsResize && ((_e = event.props) == null ? void 0 : _e.isResizable) === true);
752
767
  };
768
+ var isRowDroppable = (droppableRowIds, targetRowId) => droppableRowIds === void 0 || droppableRowIds.includes(targetRowId);
753
769
  var stepCellWidth = (cellWidth, deltaY, tick) => {
754
770
  const pixelsToCalculate = 900 / tick;
755
771
  const next = deltaY > 0 ? cellWidth + pixelsToCalculate : cellWidth - pixelsToCalculate;
@@ -758,9 +774,26 @@ var stepCellWidth = (cellWidth, deltaY, tick) => {
758
774
  }
759
775
  return next;
760
776
  };
777
+ var computeZoom = (windowTime, tick, cellWidth, anchorX, factor, contentWidth, { minWindowSeconds, maxWindowSeconds }) => {
778
+ const [start, end] = windowTime;
779
+ const oldDuration = end - start;
780
+ const newDuration = Math.min(
781
+ Math.max(oldDuration * factor, minWindowSeconds),
782
+ maxWindowSeconds
783
+ );
784
+ const cellTime = cellWidth * tick;
785
+ const tAnchor = start + anchorX * tick;
786
+ const newStart = Math.round(tAnchor - anchorX / contentWidth * newDuration);
787
+ const newEnd = newStart + Math.round(newDuration);
788
+ const newTick = (newEnd - newStart) / contentWidth;
789
+ return {
790
+ windowTime: [newStart, newEnd],
791
+ tick: newTick,
792
+ cellWidth: cellTime / newTick
793
+ };
794
+ };
761
795
 
762
796
  // src/canvas/draw-events.ts
763
- var EVENT_RADIUS = 5;
764
797
  var EVENT_TEXT_INSET = 13;
765
798
  var HANDLE_INSET = 4;
766
799
  var HANDLE_BAR_WIDTH = 3;
@@ -780,18 +813,75 @@ var roundedRect = (ctx, x, y, width, height, radius) => {
780
813
  ctx.closePath();
781
814
  }
782
815
  };
783
- var drawRowDividers = (ctx, view, scene, animator) => {
816
+ var drawGroupShading = (ctx, view, scene) => {
817
+ var _a;
784
818
  const [windowStart, windowEnd] = view.windowTime;
785
- const rowIds = scene.getRowIds();
819
+ const visible = scene.getVisibleRowIds();
820
+ const regions = [];
821
+ let y = 0;
822
+ let runParent = null;
823
+ let runTop = 0;
824
+ let runBottom = 0;
825
+ const flush = () => {
826
+ if (runParent !== null) regions.push({ top: runTop, bottom: runBottom });
827
+ runParent = null;
828
+ };
829
+ for (const rowId of visible) {
830
+ const height = scene.getRowHeight(rowId, windowStart, windowEnd);
831
+ const parentId = (_a = scene.getRow(rowId)) == null ? void 0 : _a.parentId;
832
+ if (parentId !== void 0) {
833
+ if (runParent === parentId) {
834
+ runBottom = y + height;
835
+ } else {
836
+ flush();
837
+ runParent = parentId;
838
+ runTop = y;
839
+ runBottom = y + height;
840
+ }
841
+ } else {
842
+ flush();
843
+ }
844
+ y += height;
845
+ }
846
+ flush();
847
+ if (regions.length === 0) return;
848
+ ctx.save();
849
+ for (const { top, bottom } of regions) {
850
+ const sTop = top - view.scrollTop;
851
+ const sBottom = bottom - view.scrollTop;
852
+ if (sBottom < 0 || sTop > view.height) continue;
853
+ const regionHeight = sBottom - sTop;
854
+ ctx.fillStyle = view.theme.groupChildBackground;
855
+ ctx.fillRect(0, sTop, view.width, regionHeight);
856
+ const depth = Math.min(12, regionHeight / 2);
857
+ const topGrad = ctx.createLinearGradient(0, sTop, 0, sTop + depth);
858
+ topGrad.addColorStop(0, view.theme.groupShadowColor);
859
+ topGrad.addColorStop(1, "rgba(0,0,0,0)");
860
+ ctx.fillStyle = topGrad;
861
+ ctx.fillRect(0, sTop, view.width, depth);
862
+ const botGrad = ctx.createLinearGradient(0, sBottom - depth, 0, sBottom);
863
+ botGrad.addColorStop(0, "rgba(0,0,0,0)");
864
+ botGrad.addColorStop(1, view.theme.groupShadowColor);
865
+ ctx.fillStyle = botGrad;
866
+ ctx.fillRect(0, sBottom - depth, view.width, depth);
867
+ const leftShadow = 10;
868
+ const hGrad = ctx.createLinearGradient(0, 0, leftShadow, 0);
869
+ hGrad.addColorStop(0, view.theme.groupShadowColor);
870
+ hGrad.addColorStop(1, "rgba(0,0,0,0)");
871
+ ctx.fillStyle = hGrad;
872
+ ctx.fillRect(0, sTop, leftShadow, regionHeight);
873
+ }
874
+ ctx.restore();
875
+ };
876
+ var drawRowDividers = (ctx, view, scene) => {
877
+ const [windowStart, windowEnd] = view.windowTime;
878
+ const rowIds = scene.getVisibleRowIds();
786
879
  ctx.strokeStyle = view.theme.gridColor;
787
880
  ctx.lineWidth = 1;
788
881
  ctx.beginPath();
789
882
  let y = 0;
790
883
  for (let i = 0; i < rowIds.length; i++) {
791
- y += animator.rowHeight(
792
- rowIds[i],
793
- scene.getRowHeight(rowIds[i], windowStart, windowEnd)
794
- );
884
+ y += scene.getRowHeight(rowIds[i], windowStart, windowEnd);
795
885
  if (i === rowIds.length - 1) break;
796
886
  const screenY = y - view.scrollTop;
797
887
  if (screenY < 0) continue;
@@ -831,7 +921,7 @@ var drawResizeHandles = (ctx, rect, alpha, strokeColor) => {
831
921
  }
832
922
  ctx.restore();
833
923
  };
834
- var defaultDrawEvent = (ctx, event, rect, view, font) => {
924
+ var defaultDrawEvent = (ctx, event, rect, view, font, barRadius) => {
835
925
  var _a, _b, _c, _d, _e, _f, _g, _h, _i;
836
926
  const theme = view.theme;
837
927
  const style = (_a = event.props) == null ? void 0 : _a.style;
@@ -845,7 +935,7 @@ var defaultDrawEvent = (ctx, event, rect, view, font) => {
845
935
  rect.y + 0.5,
846
936
  rect.width - 1,
847
937
  rect.height - 1,
848
- (_e = style == null ? void 0 : style.borderRadius) != null ? _e : EVENT_RADIUS
938
+ (_e = style == null ? void 0 : style.borderRadius) != null ? _e : barRadius
849
939
  );
850
940
  ctx.fill();
851
941
  ctx.stroke();
@@ -867,19 +957,53 @@ var defaultDrawEvent = (ctx, event, rect, view, font) => {
867
957
  }
868
958
  };
869
959
  var drawEvents = (ctx, view, scene, font, animator) => {
870
- var _a, _b, _c, _d, _e, _f;
960
+ var _a;
871
961
  if (view.tick === null) return;
872
962
  const [windowStart, windowEnd] = view.windowTime;
873
963
  const tick = view.tick;
964
+ const geometry = scene.getGeometry();
874
965
  ctx.font = (_a = view.theme.font) != null ? _a : font;
875
966
  ctx.textBaseline = "middle";
876
967
  ctx.textAlign = "left";
968
+ const selectedIds = view.selectedEventIds;
969
+ const hasSelection = selectedIds.size > 0;
970
+ const deferred = [];
971
+ const paintEvent = (event, rect, state, opts) => {
972
+ var _a2, _b, _c, _d, _e;
973
+ ctx.save();
974
+ if (opts.elevate) {
975
+ ctx.translate(0, -view.theme.selectionElevation);
976
+ ctx.shadowColor = view.theme.selectionShadowColor;
977
+ ctx.shadowBlur = view.theme.selectionShadowBlur;
978
+ ctx.shadowOffsetY = view.theme.selectionElevation;
979
+ }
980
+ if (state.dragging) ctx.globalAlpha = 0.5;
981
+ else if (opts.dim) ctx.globalAlpha *= view.theme.dimmedOpacity;
982
+ const custom = (_b = (_a2 = event.props) == null ? void 0 : _a2.drawEvent) != null ? _b : view.drawEvent;
983
+ const drawn = custom !== void 0 && custom(ctx, event, rect, state, view.theme) !== false;
984
+ if (!drawn) {
985
+ defaultDrawEvent(ctx, event, rect, view, font, geometry.barRadius);
986
+ }
987
+ if (canResizeEvent(event, view.eventsResize)) {
988
+ const alpha = animator.handleAlpha(
989
+ event.id,
990
+ state.hovered || state.resizing ? 1 : 0
991
+ );
992
+ if (alpha > 0.01) {
993
+ ctx.shadowColor = "transparent";
994
+ drawResizeHandles(
995
+ ctx,
996
+ rect,
997
+ alpha,
998
+ (_e = (_d = (_c = event.props) == null ? void 0 : _c.style) == null ? void 0 : _d.stroke) != null ? _e : view.theme.eventStroke
999
+ );
1000
+ }
1001
+ }
1002
+ ctx.restore();
1003
+ };
877
1004
  let rowTop = 0;
878
- for (const rowId of scene.getRowIds()) {
879
- const rowHeight = animator.rowHeight(
880
- rowId,
881
- scene.getRowHeight(rowId, windowStart, windowEnd)
882
- );
1005
+ for (const rowId of scene.getVisibleRowIds()) {
1006
+ const rowHeight = scene.getRowHeight(rowId, windowStart, windowEnd);
883
1007
  const rowY = rowTop - view.scrollTop;
884
1008
  rowTop += rowHeight;
885
1009
  if (rowY + rowHeight < 0) continue;
@@ -896,10 +1020,10 @@ var drawEvents = (ctx, view, scene, font, animator) => {
896
1020
  roundedRect(
897
1021
  ctx,
898
1022
  x,
899
- rowY + LANE_TOP_OFFSET,
1023
+ rowY + geometry.laneTopOffset,
900
1024
  width,
901
- staticEventHeight(lanes.highestLane),
902
- EVENT_RADIUS
1025
+ staticEventHeight(lanes.highestLane, geometry),
1026
+ geometry.barRadius
903
1027
  );
904
1028
  ctx.fill();
905
1029
  }
@@ -912,7 +1036,7 @@ var drawEvents = (ctx, view, scene, font, animator) => {
912
1036
  let width = timeToWidth(event.startTime, event.endTime, tick);
913
1037
  const y = rowY + animator.eventTop(
914
1038
  event.id,
915
- laneTop(lanes.laneOf.get(event.id))
1039
+ laneTop(lanes.laneOf.get(event.id), geometry)
916
1040
  );
917
1041
  const resize = view.resizePreview;
918
1042
  const resizing = resize !== null && resize.eventId === event.id;
@@ -924,37 +1048,24 @@ var drawEvents = (ctx, view, scene, font, animator) => {
924
1048
  width += resize.deltaPx;
925
1049
  }
926
1050
  }
927
- const rect = { x, y, width, height: EVENT_BAR_HEIGHT };
1051
+ const rect = { x, y, width, height: geometry.barHeight };
1052
+ const selected = selectedIds.has(event.id);
928
1053
  const state = {
929
1054
  hovered: view.hoveredEventId === event.id,
930
1055
  dragging: view.draggedEventId === event.id,
931
1056
  resizing,
932
- selected: false
1057
+ selected
933
1058
  };
934
- ctx.save();
935
- if (state.dragging) ctx.globalAlpha = 0.5;
936
- const custom = (_c = (_b = event.props) == null ? void 0 : _b.drawEvent) != null ? _c : view.drawEvent;
937
- const drawn = custom !== void 0 && custom(ctx, event, rect, state, view.theme) !== false;
938
- if (!drawn) {
939
- defaultDrawEvent(ctx, event, rect, view, font);
940
- }
941
- if (canResizeEvent(event, view.eventsResize)) {
942
- const alpha = animator.handleAlpha(
943
- event.id,
944
- state.hovered || state.resizing ? 1 : 0
1059
+ if (selected) {
1060
+ deferred.push(
1061
+ () => paintEvent(event, rect, state, { dim: false, elevate: true })
945
1062
  );
946
- if (alpha > 0.01) {
947
- drawResizeHandles(
948
- ctx,
949
- rect,
950
- alpha,
951
- (_f = (_e = (_d = event.props) == null ? void 0 : _d.style) == null ? void 0 : _e.stroke) != null ? _f : view.theme.eventStroke
952
- );
953
- }
1063
+ } else {
1064
+ paintEvent(event, rect, state, { dim: hasSelection, elevate: false });
954
1065
  }
955
- ctx.restore();
956
1066
  }
957
1067
  }
1068
+ for (const paint of deferred) paint();
958
1069
  };
959
1070
 
960
1071
  // src/canvas/renderer.ts
@@ -975,7 +1086,8 @@ var TimelineRenderer = class {
975
1086
  eventsResize: true,
976
1087
  hoveredEventId: null,
977
1088
  draggedEventId: null,
978
- resizePreview: null
1089
+ resizePreview: null,
1090
+ selectedEventIds: /* @__PURE__ */ new Set()
979
1091
  };
980
1092
  this.animator = new LayoutAnimator();
981
1093
  this.dpr = typeof window !== "undefined" ? window.devicePixelRatio : 1;
@@ -986,6 +1098,7 @@ var TimelineRenderer = class {
986
1098
  this.dpr = dpr;
987
1099
  this.resizeCanvases();
988
1100
  this.invalidate("all");
1101
+ this.scheduler.flush();
989
1102
  });
990
1103
  }
991
1104
  getView() {
@@ -997,6 +1110,7 @@ var TimelineRenderer = class {
997
1110
  if (sizeChanged) {
998
1111
  this.resizeCanvases();
999
1112
  this.invalidate("all");
1113
+ this.scheduler.flush();
1000
1114
  return;
1001
1115
  }
1002
1116
  this.invalidate("all");
@@ -1027,13 +1141,16 @@ var TimelineRenderer = class {
1027
1141
  const ctx = this.staticCanvas.getContext("2d");
1028
1142
  if (ctx) {
1029
1143
  ctx.clearRect(0, 0, this.view.width, this.view.height);
1144
+ drawGroupShading(ctx, this.view, this.scene);
1030
1145
  drawGridLines(ctx, {
1031
1146
  width: this.view.width,
1032
1147
  height: this.view.height,
1033
1148
  cellWidth: this.view.cellWidth,
1149
+ windowStart: this.view.windowTime[0],
1150
+ tick: this.view.tick,
1034
1151
  color: this.view.theme.gridColor
1035
1152
  });
1036
- drawRowDividers(ctx, this.view, this.scene, this.animator);
1153
+ drawRowDividers(ctx, this.view, this.scene);
1037
1154
  }
1038
1155
  }
1039
1156
  if (dirty.dynamic) {
@@ -1050,7 +1167,7 @@ var TimelineRenderer = class {
1050
1167
  };
1051
1168
 
1052
1169
  // src/hooks/use-canvas-interactions.ts
1053
- var import_react6 = require("react");
1170
+ var import_react5 = require("react");
1054
1171
 
1055
1172
  // src/core/types.ts
1056
1173
  var rectContains = (rect, x, y) => x >= rect.x && x <= rect.x + rect.width && y >= rect.y && y <= rect.y + rect.height;
@@ -1058,10 +1175,11 @@ var rectContains = (rect, x, y) => x >= rect.x && x <= rect.x + rect.width && y
1058
1175
  // src/core/hit-test.ts
1059
1176
  var hitTest = (scene, view, x, y) => {
1060
1177
  const { windowStart, windowEnd, tick, scrollTop } = view;
1178
+ const geometry = scene.getGeometry();
1061
1179
  const yContent = y + scrollTop;
1062
1180
  let rowTop = 0;
1063
1181
  let rowId = null;
1064
- for (const id of scene.getRowIds()) {
1182
+ for (const id of scene.getVisibleRowIds()) {
1065
1183
  const height = scene.getRowHeight(id, windowStart, windowEnd);
1066
1184
  if (yContent >= rowTop && yContent < rowTop + height) {
1067
1185
  rowId = id;
@@ -1081,9 +1199,9 @@ var hitTest = (scene, view, x, y) => {
1081
1199
  const event = events[i];
1082
1200
  const rect = {
1083
1201
  x: timeToX(event.startTime, windowStart, tick),
1084
- y: rowY + laneTop(lanes.laneOf.get(event.id)),
1202
+ y: rowY + laneTop(lanes.laneOf.get(event.id), geometry),
1085
1203
  width: timeToWidth(event.startTime, event.endTime, tick),
1086
- height: EVENT_BAR_HEIGHT
1204
+ height: geometry.barHeight
1087
1205
  };
1088
1206
  if (rectContains(rect, x, y)) {
1089
1207
  return { kind: "event", event, rowId, rect };
@@ -1098,9 +1216,9 @@ var hitTest = (scene, view, x, y) => {
1098
1216
  const event = statics[i];
1099
1217
  const rect = {
1100
1218
  x: timeToX(event.startTime, windowStart, tick),
1101
- y: rowY + LANE_TOP_OFFSET,
1219
+ y: rowY + geometry.laneTopOffset,
1102
1220
  width: timeToWidth(event.startTime, event.endTime, tick),
1103
- height: staticEventHeight(lanes.highestLane)
1221
+ height: staticEventHeight(lanes.highestLane, geometry)
1104
1222
  };
1105
1223
  if (rectContains(rect, x, y)) {
1106
1224
  return { kind: "static", event, rowId, rect };
@@ -1112,6 +1230,7 @@ var hitTest = (scene, view, x, y) => {
1112
1230
  // src/hooks/use-canvas-interactions.ts
1113
1231
  var DRAG_THRESHOLD_PX = 3;
1114
1232
  var RESIZE_HOT_ZONE_PX = 8;
1233
+ var DRAG_ZOOM_PX_PER_DOUBLING = 300;
1115
1234
  var lockCursor = (cursor) => {
1116
1235
  const style = document.createElement("style");
1117
1236
  style.id = "lock-cursor";
@@ -1131,35 +1250,104 @@ var useCanvasInteractions = ({
1131
1250
  eventPromptRef,
1132
1251
  setWindowTime,
1133
1252
  setCellWidth,
1253
+ setTick,
1134
1254
  onDrop,
1135
1255
  onResize,
1136
1256
  onEventClick,
1137
1257
  onEventHover,
1138
1258
  eventsResize,
1139
- panZoom
1259
+ panZoom,
1260
+ selectable,
1261
+ applySelection,
1262
+ getSelection
1140
1263
  }) => {
1141
- const stateRef = (0, import_react6.useRef)({ mode: "idle" });
1142
- const changeGridRef = (0, import_react6.useRef)(false);
1143
- const panFrameRef = (0, import_react6.useRef)(null);
1144
- const panPendingDxRef = (0, import_react6.useRef)(0);
1145
- const hoveredRef = (0, import_react6.useRef)(null);
1146
- const config = (0, import_react6.useMemo)(
1264
+ const stateRef = (0, import_react5.useRef)({ mode: "idle" });
1265
+ const changeGridRef = (0, import_react5.useRef)(false);
1266
+ const panFrameRef = (0, import_react5.useRef)(null);
1267
+ const panPendingDxRef = (0, import_react5.useRef)(0);
1268
+ const hoveredRef = (0, import_react5.useRef)(null);
1269
+ const pointersRef = (0, import_react5.useRef)(/* @__PURE__ */ new Map());
1270
+ const zoomFrameRef = (0, import_react5.useRef)(null);
1271
+ const zoomPendingRef = (0, import_react5.useRef)(null);
1272
+ const config = (0, import_react5.useMemo)(
1147
1273
  () => {
1148
- var _a, _b, _c, _d;
1274
+ var _a, _b, _c, _d, _e, _f, _g;
1149
1275
  return {
1150
1276
  panOnDragBackground: (_a = panZoom == null ? void 0 : panZoom.panOnDragBackground) != null ? _a : true,
1151
1277
  ctrlWheelZoom: (_b = panZoom == null ? void 0 : panZoom.ctrlWheelZoom) != null ? _b : true,
1152
- middleClickGranularity: (_c = panZoom == null ? void 0 : panZoom.middleClickGranularity) != null ? _c : true,
1153
- zoomStepSeconds: (_d = panZoom == null ? void 0 : panZoom.zoomStepSeconds) != null ? _d : 900
1278
+ pinchZoom: (_c = panZoom == null ? void 0 : panZoom.pinchZoom) != null ? _c : true,
1279
+ dragZoom: (_d = panZoom == null ? void 0 : panZoom.dragZoom) != null ? _d : true,
1280
+ zoomWheelFactor: (_e = panZoom == null ? void 0 : panZoom.zoomWheelFactor) != null ? _e : 1.15,
1281
+ middleClickGranularity: (_f = panZoom == null ? void 0 : panZoom.middleClickGranularity) != null ? _f : true,
1282
+ zoomStepSeconds: (_g = panZoom == null ? void 0 : panZoom.zoomStepSeconds) != null ? _g : 900
1154
1283
  };
1155
1284
  },
1156
1285
  [panZoom]
1157
1286
  );
1158
- const hidePrompt = (0, import_react6.useCallback)(() => {
1287
+ const limits = (0, import_react5.useMemo)(
1288
+ () => {
1289
+ var _a, _b;
1290
+ return {
1291
+ minWindowSeconds: (_a = panZoom == null ? void 0 : panZoom.minWindowSeconds) != null ? _a : 900,
1292
+ maxWindowSeconds: (_b = panZoom == null ? void 0 : panZoom.maxWindowSeconds) != null ? _b : 30 * 24 * 3600
1293
+ };
1294
+ },
1295
+ [panZoom]
1296
+ );
1297
+ const applyZoom = (0, import_react5.useCallback)(
1298
+ (base, anchorX, factor, contentWidth) => {
1299
+ var _a;
1300
+ if (contentWidth <= 0) return;
1301
+ const next = computeZoom(
1302
+ base.windowTime,
1303
+ base.tick,
1304
+ base.cellWidth,
1305
+ anchorX,
1306
+ factor,
1307
+ contentWidth,
1308
+ limits
1309
+ );
1310
+ (_a = rendererRef.current) == null ? void 0 : _a.setView({
1311
+ windowTime: next.windowTime,
1312
+ tick: next.tick,
1313
+ cellWidth: next.cellWidth
1314
+ });
1315
+ setWindowTime(next.windowTime);
1316
+ setTick(next.tick);
1317
+ setCellWidth(next.cellWidth);
1318
+ },
1319
+ [rendererRef, setWindowTime, setTick, setCellWidth, limits]
1320
+ );
1321
+ const scheduleContinuousZoom = (0, import_react5.useCallback)(() => {
1322
+ if (zoomFrameRef.current !== null) return;
1323
+ zoomFrameRef.current = requestAnimationFrame(() => {
1324
+ zoomFrameRef.current = null;
1325
+ const pending = zoomPendingRef.current;
1326
+ const state = stateRef.current;
1327
+ if (!pending || state.mode !== "pinch" && state.mode !== "zoom") return;
1328
+ applyZoom(state.snapshot, pending.anchorX, pending.factor, state.contentWidth);
1329
+ });
1330
+ }, [applyZoom]);
1331
+ const snapshotView = (0, import_react5.useCallback)(() => {
1332
+ const renderer = rendererRef.current;
1333
+ const canvas = dynamicCanvasRef.current;
1334
+ if (!renderer || !canvas) return null;
1335
+ const view = renderer.getView();
1336
+ if (view.tick === null) return null;
1337
+ return {
1338
+ base: {
1339
+ windowTime: [view.windowTime[0], view.windowTime[1]],
1340
+ tick: view.tick,
1341
+ cellWidth: view.cellWidth
1342
+ },
1343
+ contentWidth: canvas.getBoundingClientRect().width
1344
+ };
1345
+ }, [rendererRef, dynamicCanvasRef]);
1346
+ const hidePrompt = (0, import_react5.useCallback)(() => {
1159
1347
  var _a;
1160
1348
  (_a = eventPromptRef.current) == null ? void 0 : _a.hide();
1161
1349
  }, [eventPromptRef]);
1162
- const currentHit = (0, import_react6.useCallback)(
1350
+ const currentHit = (0, import_react5.useCallback)(
1163
1351
  (clientX, clientY) => {
1164
1352
  const canvas = dynamicCanvasRef.current;
1165
1353
  const renderer = rendererRef.current;
@@ -1181,7 +1369,7 @@ var useCanvasInteractions = ({
1181
1369
  },
1182
1370
  [scene, dynamicCanvasRef, rendererRef]
1183
1371
  );
1184
- const resizeDirectionAt = (0, import_react6.useCallback)(
1372
+ const resizeDirectionAt = (0, import_react5.useCallback)(
1185
1373
  (hit, clientX) => {
1186
1374
  if (hit.kind !== "event" || !canResizeEvent(hit.event, eventsResize)) {
1187
1375
  return null;
@@ -1196,7 +1384,7 @@ var useCanvasInteractions = ({
1196
1384
  },
1197
1385
  [dynamicCanvasRef, eventsResize]
1198
1386
  );
1199
- const schedulePan = (0, import_react6.useCallback)(() => {
1387
+ const schedulePan = (0, import_react5.useCallback)(() => {
1200
1388
  if (panFrameRef.current !== null) return;
1201
1389
  panFrameRef.current = requestAnimationFrame(() => {
1202
1390
  panFrameRef.current = null;
@@ -1213,25 +1401,80 @@ var useCanvasInteractions = ({
1213
1401
  setWindowTime((prev) => [prev[0] - dt, prev[1] - dt]);
1214
1402
  });
1215
1403
  }, [rendererRef, setWindowTime]);
1216
- const updateGhost = (0, import_react6.useCallback)(
1404
+ const updateGhost = (0, import_react5.useCallback)(
1217
1405
  (state, clientX, clientY) => {
1406
+ var _a;
1218
1407
  const ghost = ghostRef.current;
1219
1408
  if (!ghost) return;
1409
+ const rawLeft = state.hit.rect.x + (clientX - state.startClientX);
1410
+ const rawTop = state.hit.rect.y + (clientY - state.startClientY);
1411
+ const view = (_a = rendererRef.current) == null ? void 0 : _a.getView();
1412
+ const ghostWidth = state.hit.rect.width;
1413
+ const ghostHeight = state.hit.rect.height;
1414
+ const left = view ? Math.max(0, Math.min(rawLeft, Math.max(0, view.width - ghostWidth))) : rawLeft;
1415
+ const top = view ? Math.max(0, Math.min(rawTop, Math.max(0, view.height - ghostHeight))) : rawTop;
1220
1416
  ghost.style.display = "flex";
1221
- ghost.style.left = `${state.hit.rect.x + (clientX - state.startClientX)}px`;
1222
- ghost.style.top = `${state.hit.rect.y + (clientY - state.startClientY)}px`;
1223
- ghost.style.width = `${state.hit.rect.width}px`;
1417
+ ghost.style.left = `${left}px`;
1418
+ ghost.style.top = `${top}px`;
1419
+ ghost.style.width = `${ghostWidth}px`;
1224
1420
  },
1225
- [ghostRef]
1421
+ [ghostRef, rendererRef]
1226
1422
  );
1227
- const handlePointerDown = (0, import_react6.useCallback)(
1423
+ const styleGhost = (0, import_react5.useCallback)(
1424
+ (event) => {
1425
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
1426
+ const ghost = ghostRef.current;
1427
+ const theme = (_a = rendererRef.current) == null ? void 0 : _a.getView().theme;
1428
+ if (!ghost || !theme) return;
1429
+ const style = (_b = event.props) == null ? void 0 : _b.style;
1430
+ ghost.style.backgroundColor = (_c = style == null ? void 0 : style.fill) != null ? _c : theme.eventFill;
1431
+ ghost.style.border = `${(_d = style == null ? void 0 : style.strokeWidth) != null ? _d : 1}px solid ${(_e = style == null ? void 0 : style.stroke) != null ? _e : theme.eventStroke}`;
1432
+ ghost.style.borderRadius = `${(_f = style == null ? void 0 : style.borderRadius) != null ? _f : theme.barRadius}px`;
1433
+ ghost.style.color = (_g = style == null ? void 0 : style.textColor) != null ? _g : theme.eventTextColor;
1434
+ ghost.style.font = (_i = (_h = style == null ? void 0 : style.font) != null ? _h : theme.font) != null ? _i : "";
1435
+ ghost.style.justifyContent = "flex-start";
1436
+ ghost.style.alignItems = "center";
1437
+ ghost.style.paddingInline = "13px";
1438
+ ghost.style.overflow = "hidden";
1439
+ ghost.style.whiteSpace = "nowrap";
1440
+ ghost.textContent = (_k = (_j = event.props) == null ? void 0 : _j.label) != null ? _k : "";
1441
+ },
1442
+ [ghostRef, rendererRef]
1443
+ );
1444
+ const handlePointerDown = (0, import_react5.useCallback)(
1228
1445
  (pointerEvent) => {
1229
- var _a;
1230
- if (pointerEvent.button !== 0) return;
1446
+ var _a, _b;
1231
1447
  const canvas = dynamicCanvasRef.current;
1232
1448
  if (!canvas) return;
1449
+ const isTouch = pointerEvent.pointerType === "touch";
1450
+ pointersRef.current.set(pointerEvent.pointerId, {
1451
+ x: pointerEvent.clientX,
1452
+ y: pointerEvent.clientY,
1453
+ touch: isTouch
1454
+ });
1455
+ if (config.pinchZoom && isTouch && pointersRef.current.size === 2) {
1456
+ const snap = snapshotView();
1457
+ if (snap) {
1458
+ if (ghostRef.current) ghostRef.current.style.display = "none";
1459
+ (_a = rendererRef.current) == null ? void 0 : _a.setView({ draggedEventId: null });
1460
+ const pts = [...pointersRef.current.values()];
1461
+ const startDist = Math.hypot(pts[0].x - pts[1].x, pts[0].y - pts[1].y) || 1;
1462
+ const rect = canvas.getBoundingClientRect();
1463
+ stateRef.current = {
1464
+ mode: "pinch",
1465
+ startDist,
1466
+ anchorX: (pts[0].x + pts[1].x) / 2 - rect.left,
1467
+ contentWidth: snap.contentWidth,
1468
+ snapshot: snap.base
1469
+ };
1470
+ canvas.setPointerCapture(pointerEvent.pointerId);
1471
+ hidePrompt();
1472
+ }
1473
+ return;
1474
+ }
1475
+ if (pointerEvent.button !== 0) return;
1233
1476
  const hit = currentHit(pointerEvent.clientX, pointerEvent.clientY);
1234
- if ((hit == null ? void 0 : hit.kind) === "event" && !((_a = hit.event.props) == null ? void 0 : _a.isLocked)) {
1477
+ if ((hit == null ? void 0 : hit.kind) === "event" && !((_b = hit.event.props) == null ? void 0 : _b.isLocked)) {
1235
1478
  const direction = resizeDirectionAt(hit, pointerEvent.clientX);
1236
1479
  if (direction) {
1237
1480
  stateRef.current = {
@@ -1250,19 +1493,58 @@ var useCanvasInteractions = ({
1250
1493
  startClientY: pointerEvent.clientY,
1251
1494
  active: false
1252
1495
  };
1496
+ styleGhost(hit.event);
1253
1497
  }
1498
+ } else if (config.dragZoom && (pointerEvent.ctrlKey || pointerEvent.metaKey) && !isTouch) {
1499
+ const snap = snapshotView();
1500
+ if (!snap) return;
1501
+ const rect = canvas.getBoundingClientRect();
1502
+ stateRef.current = {
1503
+ mode: "zoom",
1504
+ startClientX: pointerEvent.clientX,
1505
+ anchorX: pointerEvent.clientX - rect.left,
1506
+ contentWidth: snap.contentWidth,
1507
+ snapshot: snap.base
1508
+ };
1254
1509
  } else if (config.panOnDragBackground) {
1255
- stateRef.current = { mode: "pan", lastClientX: pointerEvent.clientX };
1510
+ stateRef.current = {
1511
+ mode: "pan",
1512
+ lastClientX: pointerEvent.clientX,
1513
+ lastClientY: pointerEvent.clientY,
1514
+ startClientX: pointerEvent.clientX,
1515
+ startClientY: pointerEvent.clientY,
1516
+ touch: isTouch
1517
+ };
1256
1518
  canvas.style.cursor = "grabbing";
1519
+ } else if (selectable && !hit) {
1520
+ stateRef.current = {
1521
+ mode: "pan",
1522
+ lastClientX: pointerEvent.clientX,
1523
+ lastClientY: pointerEvent.clientY,
1524
+ startClientX: pointerEvent.clientX,
1525
+ startClientY: pointerEvent.clientY,
1526
+ touch: isTouch
1527
+ };
1257
1528
  } else {
1258
1529
  return;
1259
1530
  }
1260
1531
  hidePrompt();
1261
1532
  canvas.setPointerCapture(pointerEvent.pointerId);
1262
1533
  },
1263
- [currentHit, resizeDirectionAt, dynamicCanvasRef, hidePrompt, config]
1534
+ [
1535
+ currentHit,
1536
+ resizeDirectionAt,
1537
+ dynamicCanvasRef,
1538
+ hidePrompt,
1539
+ config,
1540
+ snapshotView,
1541
+ ghostRef,
1542
+ rendererRef,
1543
+ styleGhost,
1544
+ selectable
1545
+ ]
1264
1546
  );
1265
- const handleHover = (0, import_react6.useCallback)(
1547
+ const handleHover = (0, import_react5.useCallback)(
1266
1548
  (pointerEvent) => {
1267
1549
  var _a, _b, _c, _d;
1268
1550
  const canvas = dynamicCanvasRef.current;
@@ -1317,32 +1599,93 @@ var useCanvasInteractions = ({
1317
1599
  onEventHover
1318
1600
  ]
1319
1601
  );
1320
- const handlePointerMove = (0, import_react6.useCallback)(
1602
+ const resolveRowAtClientY = (0, import_react5.useCallback)(
1603
+ (clientY) => {
1604
+ const canvas = dynamicCanvasRef.current;
1605
+ const renderer = rendererRef.current;
1606
+ if (!canvas || !renderer) return null;
1607
+ const view = renderer.getView();
1608
+ if (view.tick === null) return null;
1609
+ const yContent = clientY - canvas.getBoundingClientRect().top + view.scrollTop;
1610
+ let rowTop = 0;
1611
+ for (const id of scene.getVisibleRowIds()) {
1612
+ const height = scene.getRowHeight(
1613
+ id,
1614
+ view.windowTime[0],
1615
+ view.windowTime[1]
1616
+ );
1617
+ if (yContent >= rowTop && yContent < rowTop + height) return id;
1618
+ rowTop += height;
1619
+ }
1620
+ return null;
1621
+ },
1622
+ [dynamicCanvasRef, rendererRef, scene]
1623
+ );
1624
+ const handlePointerMove = (0, import_react5.useCallback)(
1321
1625
  (pointerEvent) => {
1322
- var _a, _b;
1626
+ var _a, _b, _c, _d;
1627
+ const tracked = pointersRef.current.get(pointerEvent.pointerId);
1628
+ if (tracked) {
1629
+ tracked.x = pointerEvent.clientX;
1630
+ tracked.y = pointerEvent.clientY;
1631
+ }
1323
1632
  const state = stateRef.current;
1324
1633
  if (state.mode === "idle") {
1325
1634
  handleHover(pointerEvent);
1326
1635
  return;
1327
1636
  }
1637
+ if (state.mode === "pinch") {
1638
+ const pts = [...pointersRef.current.values()];
1639
+ if (pts.length < 2) return;
1640
+ const dist = Math.hypot(pts[0].x - pts[1].x, pts[0].y - pts[1].y) || 1;
1641
+ zoomPendingRef.current = {
1642
+ anchorX: state.anchorX,
1643
+ factor: state.startDist / dist
1644
+ // fingers apart -> factor<1 -> zoom in
1645
+ };
1646
+ scheduleContinuousZoom();
1647
+ return;
1648
+ }
1649
+ if (state.mode === "zoom") {
1650
+ const dx = pointerEvent.clientX - state.startClientX;
1651
+ zoomPendingRef.current = {
1652
+ anchorX: state.anchorX,
1653
+ factor: Math.pow(2, -dx / DRAG_ZOOM_PX_PER_DOUBLING)
1654
+ // right -> zoom in
1655
+ };
1656
+ scheduleContinuousZoom();
1657
+ return;
1658
+ }
1328
1659
  if (state.mode === "pan") {
1329
1660
  panPendingDxRef.current += pointerEvent.clientX - state.lastClientX;
1661
+ if (state.touch && bodyRef.current) {
1662
+ bodyRef.current.scrollTop -= pointerEvent.clientY - state.lastClientY;
1663
+ }
1330
1664
  state.lastClientX = pointerEvent.clientX;
1665
+ state.lastClientY = pointerEvent.clientY;
1331
1666
  schedulePan();
1332
1667
  return;
1333
1668
  }
1334
1669
  if (state.mode === "drag") {
1670
+ if ((_a = state.hit.event.props) == null ? void 0 : _a.isGroupParent) return;
1335
1671
  if (!state.active && Math.abs(pointerEvent.clientX - state.startClientX) + Math.abs(pointerEvent.clientY - state.startClientY) > DRAG_THRESHOLD_PX) {
1336
1672
  state.active = true;
1337
- (_a = rendererRef.current) == null ? void 0 : _a.setView({ draggedEventId: state.hit.event.id });
1673
+ (_b = rendererRef.current) == null ? void 0 : _b.setView({ draggedEventId: state.hit.event.id });
1338
1674
  }
1339
1675
  if (state.active) {
1340
1676
  updateGhost(state, pointerEvent.clientX, pointerEvent.clientY);
1677
+ const allowed = (_c = state.hit.event.props) == null ? void 0 : _c.droppableRowIds;
1678
+ if (allowed) {
1679
+ const row = resolveRowAtClientY(pointerEvent.clientY);
1680
+ const ok = row !== null && isRowDroppable(allowed, row);
1681
+ const canvas = dynamicCanvasRef.current;
1682
+ if (canvas) canvas.style.cursor = ok ? "grabbing" : "not-allowed";
1683
+ }
1341
1684
  }
1342
1685
  return;
1343
1686
  }
1344
1687
  state.deltaPx = pointerEvent.clientX - state.startClientX;
1345
- (_b = rendererRef.current) == null ? void 0 : _b.setView({
1688
+ (_d = rendererRef.current) == null ? void 0 : _d.setView({
1346
1689
  resizePreview: {
1347
1690
  eventId: state.event.id,
1348
1691
  deltaPx: state.deltaPx,
@@ -1350,34 +1693,34 @@ var useCanvasInteractions = ({
1350
1693
  }
1351
1694
  });
1352
1695
  },
1353
- [handleHover, schedulePan, updateGhost, rendererRef]
1696
+ [
1697
+ handleHover,
1698
+ schedulePan,
1699
+ updateGhost,
1700
+ rendererRef,
1701
+ scheduleContinuousZoom,
1702
+ bodyRef,
1703
+ resolveRowAtClientY,
1704
+ dynamicCanvasRef
1705
+ ]
1354
1706
  );
1355
- const commitDrop = (0, import_react6.useCallback)(
1707
+ const commitDrop = (0, import_react5.useCallback)(
1356
1708
  (state, clientX, clientY) => {
1709
+ var _a;
1357
1710
  const canvas = dynamicCanvasRef.current;
1358
1711
  const renderer = rendererRef.current;
1359
1712
  if (!canvas || !renderer) return;
1360
1713
  const view = renderer.getView();
1361
1714
  if (view.tick === null || view.cellWidth <= 0) return;
1362
1715
  const canvasRect = canvas.getBoundingClientRect();
1363
- const yContent = clientY - canvasRect.top + view.scrollTop;
1364
- let rowTop = 0;
1365
- let targetRowId = null;
1366
- for (const id of scene.getRowIds()) {
1367
- const height = scene.getRowHeight(
1368
- id,
1369
- view.windowTime[0],
1370
- view.windowTime[1]
1371
- );
1372
- if (yContent >= rowTop && yContent < rowTop + height) {
1373
- targetRowId = id;
1374
- break;
1375
- }
1376
- rowTop += height;
1377
- }
1716
+ const targetRowId = resolveRowAtClientY(clientY);
1378
1717
  if (targetRowId === null) return;
1379
1718
  const liveEvent = scene.getEvent(state.hit.event.id);
1380
1719
  if (!liveEvent) return;
1720
+ if (!isRowDroppable((_a = liveEvent.props) == null ? void 0 : _a.droppableRowIds, targetRowId)) {
1721
+ renderer.animator.snapEventTop(liveEvent.id);
1722
+ return;
1723
+ }
1381
1724
  const { startTime, endTime } = computeDropTimes({
1382
1725
  pointerX: clientX - canvasRect.left,
1383
1726
  cellWidth: view.cellWidth,
@@ -1403,9 +1746,9 @@ var useCanvasInteractions = ({
1403
1746
  }
1404
1747
  ]);
1405
1748
  },
1406
- [scene, dynamicCanvasRef, rendererRef, onDrop]
1749
+ [scene, dynamicCanvasRef, rendererRef, onDrop, resolveRowAtClientY]
1407
1750
  );
1408
- const commitResize = (0, import_react6.useCallback)(
1751
+ const commitResize = (0, import_react5.useCallback)(
1409
1752
  (state) => {
1410
1753
  const renderer = rendererRef.current;
1411
1754
  const tick = renderer == null ? void 0 : renderer.getView().tick;
@@ -1435,11 +1778,12 @@ var useCanvasInteractions = ({
1435
1778
  },
1436
1779
  [scene, rendererRef, onResize]
1437
1780
  );
1438
- const handlePointerUp = (0, import_react6.useCallback)(
1781
+ const handlePointerUp = (0, import_react5.useCallback)(
1439
1782
  (pointerEvent) => {
1440
1783
  var _a;
1441
1784
  const canvas = dynamicCanvasRef.current;
1442
1785
  const state = stateRef.current;
1786
+ pointersRef.current.delete(pointerEvent.pointerId);
1443
1787
  stateRef.current = { mode: "idle" };
1444
1788
  if (canvas == null ? void 0 : canvas.hasPointerCapture(pointerEvent.pointerId)) {
1445
1789
  canvas.releasePointerCapture(pointerEvent.pointerId);
@@ -1463,6 +1807,19 @@ var useCanvasInteractions = ({
1463
1807
  }
1464
1808
  });
1465
1809
  }
1810
+ if (selectable) {
1811
+ const id = state.hit.event.id;
1812
+ if (scene.isEventSelectable(id)) {
1813
+ applySelection(
1814
+ pointerEvent.ctrlKey || pointerEvent.metaKey ? scene.getConnectedEventIds(id) : [id]
1815
+ );
1816
+ }
1817
+ }
1818
+ } else if (state.mode === "pan") {
1819
+ const moved = Math.abs(pointerEvent.clientX - state.startClientX) + Math.abs(pointerEvent.clientY - state.startClientY) > DRAG_THRESHOLD_PX;
1820
+ if (selectable && !moved && getSelection().length > 0) {
1821
+ applySelection([]);
1822
+ }
1466
1823
  } else if (state.mode === "resize") {
1467
1824
  commitResize(state);
1468
1825
  }
@@ -1473,10 +1830,28 @@ var useCanvasInteractions = ({
1473
1830
  rendererRef,
1474
1831
  commitDrop,
1475
1832
  commitResize,
1476
- onEventClick
1833
+ onEventClick,
1834
+ selectable,
1835
+ applySelection,
1836
+ getSelection,
1837
+ scene
1477
1838
  ]
1478
1839
  );
1479
- const handlePointerLeave = (0, import_react6.useCallback)(() => {
1840
+ const handlePointerCancel = (0, import_react5.useCallback)(
1841
+ (pointerEvent) => {
1842
+ var _a;
1843
+ pointersRef.current.delete(pointerEvent.pointerId);
1844
+ stateRef.current = { mode: "idle" };
1845
+ const canvas = dynamicCanvasRef.current;
1846
+ if (canvas == null ? void 0 : canvas.hasPointerCapture(pointerEvent.pointerId)) {
1847
+ canvas.releasePointerCapture(pointerEvent.pointerId);
1848
+ }
1849
+ if (ghostRef.current) ghostRef.current.style.display = "none";
1850
+ (_a = rendererRef.current) == null ? void 0 : _a.setView({ draggedEventId: null });
1851
+ },
1852
+ [dynamicCanvasRef, ghostRef, rendererRef]
1853
+ );
1854
+ const handlePointerLeave = (0, import_react5.useCallback)(() => {
1480
1855
  var _a, _b;
1481
1856
  if (stateRef.current.mode !== "idle") return;
1482
1857
  if (((_a = hoveredRef.current) == null ? void 0 : _a.kind) === "event") {
@@ -1489,7 +1864,7 @@ var useCanvasInteractions = ({
1489
1864
  }
1490
1865
  hidePrompt();
1491
1866
  }, [dynamicCanvasRef, rendererRef, hidePrompt, onEventHover]);
1492
- const handleAuxClick = (0, import_react6.useCallback)(
1867
+ const handleAuxClick = (0, import_react5.useCallback)(
1493
1868
  (pointerEvent) => {
1494
1869
  pointerEvent.preventDefault();
1495
1870
  if (pointerEvent.button === 1 && config.middleClickGranularity) {
@@ -1501,40 +1876,69 @@ var useCanvasInteractions = ({
1501
1876
  },
1502
1877
  [bodyRef, config]
1503
1878
  );
1504
- (0, import_react6.useEffect)(() => {
1879
+ (0, import_react5.useEffect)(() => {
1505
1880
  const canvas = dynamicCanvasRef.current;
1506
1881
  if (!canvas) return;
1507
1882
  const handleWheel = (wheelEvent) => {
1508
1883
  var _a;
1509
- const viaCtrl = (wheelEvent.ctrlKey || wheelEvent.metaKey) && config.ctrlWheelZoom;
1510
- if (!changeGridRef.current && !viaCtrl) return;
1511
- wheelEvent.preventDefault();
1512
- const tick = (_a = rendererRef.current) == null ? void 0 : _a.getView().tick;
1513
- if (!tick) return;
1514
- setCellWidth(
1515
- (cellWidth) => stepCellWidth(
1516
- cellWidth,
1517
- wheelEvent.deltaY,
1518
- tick * 900 / config.zoomStepSeconds
1519
- )
1520
- );
1884
+ const view = (_a = rendererRef.current) == null ? void 0 : _a.getView();
1885
+ if (!view || view.tick === null) return;
1886
+ const tick = view.tick;
1887
+ if (changeGridRef.current) {
1888
+ wheelEvent.preventDefault();
1889
+ setCellWidth(
1890
+ (cellWidth) => stepCellWidth(
1891
+ cellWidth,
1892
+ wheelEvent.deltaY,
1893
+ tick * 900 / config.zoomStepSeconds
1894
+ )
1895
+ );
1896
+ return;
1897
+ }
1898
+ if ((wheelEvent.ctrlKey || wheelEvent.metaKey) && config.ctrlWheelZoom) {
1899
+ wheelEvent.preventDefault();
1900
+ const rect = canvas.getBoundingClientRect();
1901
+ const factor = wheelEvent.deltaY > 0 ? config.zoomWheelFactor : 1 / config.zoomWheelFactor;
1902
+ applyZoom(
1903
+ {
1904
+ windowTime: [view.windowTime[0], view.windowTime[1]],
1905
+ tick,
1906
+ cellWidth: view.cellWidth
1907
+ },
1908
+ wheelEvent.clientX - rect.left,
1909
+ factor,
1910
+ rect.width
1911
+ );
1912
+ return;
1913
+ }
1521
1914
  };
1522
1915
  canvas.addEventListener("wheel", handleWheel, { passive: false });
1523
1916
  return () => canvas.removeEventListener("wheel", handleWheel);
1524
- }, [dynamicCanvasRef, rendererRef, setCellWidth, config]);
1525
- (0, import_react6.useEffect)(() => unlockCursor, []);
1917
+ }, [dynamicCanvasRef, rendererRef, setCellWidth, applyZoom, config]);
1918
+ (0, import_react5.useEffect)(() => unlockCursor, []);
1919
+ (0, import_react5.useEffect)(() => {
1920
+ if (!selectable) return;
1921
+ const handleKeyDown = (keyEvent) => {
1922
+ if (keyEvent.key === "Escape" && getSelection().length > 0) {
1923
+ applySelection([]);
1924
+ }
1925
+ };
1926
+ window.addEventListener("keydown", handleKeyDown);
1927
+ return () => window.removeEventListener("keydown", handleKeyDown);
1928
+ }, [selectable, getSelection, applySelection]);
1526
1929
  return {
1527
1930
  handlePointerDown,
1528
1931
  handlePointerMove,
1529
1932
  handlePointerUp,
1530
1933
  handlePointerLeave,
1934
+ handlePointerCancel,
1531
1935
  handleAuxClick
1532
1936
  };
1533
1937
  };
1534
1938
  var use_canvas_interactions_default = useCanvasInteractions;
1535
1939
 
1536
1940
  // src/components/canvas-board.tsx
1537
- var CanvasBoard = (0, import_react7.forwardRef)(
1941
+ var CanvasBoard = (0, import_react6.forwardRef)(
1538
1942
  ({
1539
1943
  scene,
1540
1944
  rows,
@@ -1549,20 +1953,26 @@ var CanvasBoard = (0, import_react7.forwardRef)(
1549
1953
  rowsHeaderClassName,
1550
1954
  setWindowTime,
1551
1955
  setCellWidth,
1956
+ setTick,
1552
1957
  onDrop,
1553
1958
  onResize,
1554
1959
  onEventClick,
1555
1960
  onEventHover,
1556
1961
  eventsResize,
1557
1962
  panZoom,
1558
- animations
1963
+ animations,
1964
+ selectable,
1965
+ applySelection,
1966
+ getSelection
1559
1967
  }, contentRef) => {
1560
- const staticCanvasRef = (0, import_react7.useRef)(null);
1561
- const dynamicCanvasRef = (0, import_react7.useRef)(null);
1562
- const ghostRef = (0, import_react7.useRef)(null);
1563
- const [scrollTop, setScrollTop] = (0, import_react7.useState)(0);
1564
- const [viewportHeight, setViewportHeight] = (0, import_react7.useState)(0);
1565
- (0, import_react7.useEffect)(() => {
1968
+ const staticCanvasRef = (0, import_react6.useRef)(null);
1969
+ const dynamicCanvasRef = (0, import_react6.useRef)(null);
1970
+ const ghostRef = (0, import_react6.useRef)(null);
1971
+ const headerWrapperRef = (0, import_react6.useRef)(null);
1972
+ const totalHeightRef = (0, import_react6.useRef)(0);
1973
+ const [scrollTop, setScrollTop] = (0, import_react6.useState)(0);
1974
+ const [viewportHeight, setViewportHeight] = (0, import_react6.useState)(0);
1975
+ (0, import_react6.useEffect)(() => {
1566
1976
  if (!staticCanvasRef.current || !dynamicCanvasRef.current) return;
1567
1977
  const renderer = new TimelineRenderer(
1568
1978
  staticCanvasRef.current,
@@ -1575,7 +1985,7 @@ var CanvasBoard = (0, import_react7.forwardRef)(
1575
1985
  rendererRef.current = null;
1576
1986
  };
1577
1987
  }, [scene, rendererRef]);
1578
- (0, import_react7.useEffect)(() => {
1988
+ (0, import_react6.useEffect)(() => {
1579
1989
  var _a, _b;
1580
1990
  (_a = rendererRef.current) == null ? void 0 : _a.animator.setDurations(
1581
1991
  animations.layoutMs,
@@ -1599,26 +2009,30 @@ var CanvasBoard = (0, import_react7.forwardRef)(
1599
2009
  animations,
1600
2010
  rendererRef
1601
2011
  ]);
1602
- (0, import_react7.useEffect)(() => {
2012
+ const measureViewport = (0, import_react6.useCallback)(() => {
2013
+ var _a;
1603
2014
  const column = contentRef && "current" in contentRef ? contentRef.current : null;
1604
2015
  const body = bodyRef.current;
1605
2016
  if (!column || !body) return;
1606
- const measure = () => {
1607
- var _a;
1608
- const height = Math.min(body.clientHeight, window.innerHeight);
1609
- setViewportHeight(height);
1610
- (_a = rendererRef.current) == null ? void 0 : _a.setView({
1611
- width: column.getBoundingClientRect().width,
1612
- height
1613
- });
1614
- };
1615
- measure();
1616
- const observer = new ResizeObserver(measure);
2017
+ const cap = totalHeightRef.current > 0 ? totalHeightRef.current : Infinity;
2018
+ const height = Math.min(body.clientHeight, cap, window.innerHeight);
2019
+ setViewportHeight(height);
2020
+ (_a = rendererRef.current) == null ? void 0 : _a.setView({
2021
+ width: column.getBoundingClientRect().width,
2022
+ height
2023
+ });
2024
+ }, [bodyRef, contentRef, rendererRef]);
2025
+ (0, import_react6.useEffect)(() => {
2026
+ const column = contentRef && "current" in contentRef ? contentRef.current : null;
2027
+ const body = bodyRef.current;
2028
+ if (!column || !body) return;
2029
+ measureViewport();
2030
+ const observer = new ResizeObserver(measureViewport);
1617
2031
  observer.observe(column);
1618
2032
  observer.observe(body);
1619
2033
  return () => observer.disconnect();
1620
- }, [bodyRef, contentRef, rendererRef]);
1621
- (0, import_react7.useEffect)(() => {
2034
+ }, [bodyRef, contentRef, measureViewport]);
2035
+ (0, import_react6.useEffect)(() => {
1622
2036
  const body = bodyRef.current;
1623
2037
  if (!body) return;
1624
2038
  const handleScroll = () => {
@@ -1629,15 +2043,53 @@ var CanvasBoard = (0, import_react7.forwardRef)(
1629
2043
  body.addEventListener("scroll", handleScroll, { passive: true });
1630
2044
  return () => body.removeEventListener("scroll", handleScroll);
1631
2045
  }, [bodyRef, rendererRef]);
1632
- (0, import_react7.useSyncExternalStore)(
1633
- (0, import_react7.useCallback)((listener) => scene.subscribe(listener), [scene]),
2046
+ (0, import_react6.useSyncExternalStore)(
2047
+ (0, import_react6.useCallback)((listener) => scene.subscribe(listener), [scene]),
1634
2048
  () => scene.version
1635
2049
  );
2050
+ (0, import_react6.useLayoutEffect)(() => {
2051
+ const wrapper = headerWrapperRef.current;
2052
+ if (!wrapper) return;
2053
+ const measurer = document.createElement("div");
2054
+ measurer.className = "row-header-label";
2055
+ measurer.setAttribute("aria-hidden", "true");
2056
+ measurer.style.position = "absolute";
2057
+ measurer.style.left = "-9999px";
2058
+ measurer.style.top = "0";
2059
+ measurer.style.visibility = "hidden";
2060
+ measurer.style.height = "auto";
2061
+ wrapper.appendChild(measurer);
2062
+ let lastWidth = -1;
2063
+ const measure = () => {
2064
+ var _a;
2065
+ const width = wrapper.clientWidth;
2066
+ if (width === 0 || width === lastWidth) return;
2067
+ lastWidth = width;
2068
+ measurer.style.width = `${width}px`;
2069
+ const heights = /* @__PURE__ */ new Map();
2070
+ for (const row of rows) {
2071
+ measurer.textContent = (_a = row.name) != null ? _a : "";
2072
+ heights.set(
2073
+ row.id,
2074
+ Math.ceil(measurer.offsetHeight) + 2 * theme.rowPaddingY
2075
+ );
2076
+ }
2077
+ scene.setLabelMinHeights(heights);
2078
+ };
2079
+ measure();
2080
+ const observer = new ResizeObserver(measure);
2081
+ observer.observe(wrapper);
2082
+ return () => {
2083
+ observer.disconnect();
2084
+ wrapper.removeChild(measurer);
2085
+ };
2086
+ }, [rows, scene, theme.rowPaddingY, rowsHeaderClassName]);
1636
2087
  const {
1637
2088
  handlePointerDown,
1638
2089
  handlePointerMove,
1639
2090
  handlePointerUp,
1640
2091
  handlePointerLeave,
2092
+ handlePointerCancel,
1641
2093
  handleAuxClick
1642
2094
  } = use_canvas_interactions_default({
1643
2095
  scene,
@@ -1648,26 +2100,54 @@ var CanvasBoard = (0, import_react7.forwardRef)(
1648
2100
  eventPromptRef,
1649
2101
  setWindowTime,
1650
2102
  setCellWidth,
2103
+ setTick,
1651
2104
  onDrop,
1652
2105
  onResize,
1653
2106
  onEventClick,
1654
2107
  onEventHover,
1655
2108
  eventsResize,
1656
- panZoom
2109
+ panZoom,
2110
+ selectable,
2111
+ applySelection,
2112
+ getSelection
1657
2113
  });
2114
+ (0, import_react6.useEffect)(() => {
2115
+ var _a;
2116
+ (_a = rendererRef.current) == null ? void 0 : _a.setView({
2117
+ selectedEventIds: new Set(getSelection())
2118
+ });
2119
+ }, [getSelection, rendererRef]);
1658
2120
  const { offsetOf, totalHeight } = scene.getRowOffsets(
1659
2121
  windowTime[0],
1660
2122
  windowTime[1]
1661
2123
  );
2124
+ totalHeightRef.current = totalHeight;
2125
+ (0, import_react6.useLayoutEffect)(() => {
2126
+ measureViewport();
2127
+ }, [totalHeight, measureViewport]);
2128
+ const lastChildOf = /* @__PURE__ */ new Map();
2129
+ for (const row of rows) {
2130
+ if (row.parentId !== void 0) lastChildOf.set(row.parentId, row.id);
2131
+ }
2132
+ const connectorColor = theme.gridColor;
2133
+ const SPINE_X = 11;
1662
2134
  const visibleHeaders = [];
1663
2135
  for (let i = 0; i < rows.length; i++) {
1664
2136
  const row = rows[i];
2137
+ if (scene.isRowHidden(row.id)) continue;
1665
2138
  const top = offsetOf.get(row.id);
2139
+ if (top === void 0) continue;
1666
2140
  const height = scene.getRowHeight(row.id, windowTime[0], windowTime[1]);
1667
2141
  if (top + height < scrollTop) continue;
1668
2142
  if (top > scrollTop + viewportHeight) break;
2143
+ const isParent = scene.isRowParent(row.id);
2144
+ const parentId = row.parentId;
2145
+ const isChild = parentId !== void 0;
2146
+ const isLastChild = parentId !== void 0 && lastChildOf.get(parentId) === row.id;
2147
+ const collapsed = scene.isRowCollapsed(row.id);
2148
+ const grouped = isParent || isChild;
1669
2149
  visibleHeaders.push(
1670
- /* @__PURE__ */ import_react7.default.createElement(
2150
+ /* @__PURE__ */ import_react6.default.createElement(
1671
2151
  "div",
1672
2152
  {
1673
2153
  key: `row_header_${row.id}`,
@@ -1676,16 +2156,79 @@ var CanvasBoard = (0, import_react7.forwardRef)(
1676
2156
  top,
1677
2157
  height,
1678
2158
  borderBottom: i === rows.length - 1 ? "none" : "1px solid yellow",
1679
- // keeps the DOM header in step with the canvas layout tween
1680
- transition: animations.layoutMs > 0 ? `top ${animations.layoutMs}ms ease-in-out, height ${animations.layoutMs}ms ease-in-out` : "none"
2159
+ // Row heights/positions apply instantly (no layout tween) so the
2160
+ // header snaps in lockstep with its canvas row — see draw-events.
2161
+ // Grouped rows left-align so the caret + tree spine line up; plain
2162
+ // rows keep the centered default.
2163
+ justifyContent: grouped ? "flex-start" : void 0,
2164
+ paddingLeft: isChild ? 24 : isParent ? 6 : void 0
1681
2165
  }
1682
2166
  },
1683
- row.name
2167
+ isChild && // tree connector: a vertical spine + a horizontal tick at the row's
2168
+ // vertical center. The spine runs the full height for a mid child
2169
+ // (├─) and stops at the center for the last child (└─), so stacked
2170
+ // children form one continuous spine descending from the parent.
2171
+ /* @__PURE__ */ import_react6.default.createElement(import_react6.default.Fragment, null, /* @__PURE__ */ import_react6.default.createElement(
2172
+ "span",
2173
+ {
2174
+ "aria-hidden": true,
2175
+ style: {
2176
+ position: "absolute",
2177
+ left: SPINE_X,
2178
+ top: 0,
2179
+ width: 1,
2180
+ height: isLastChild ? "50%" : "100%",
2181
+ backgroundColor: connectorColor,
2182
+ pointerEvents: "none"
2183
+ }
2184
+ }
2185
+ ), /* @__PURE__ */ import_react6.default.createElement(
2186
+ "span",
2187
+ {
2188
+ "aria-hidden": true,
2189
+ style: {
2190
+ position: "absolute",
2191
+ left: SPINE_X,
2192
+ top: "50%",
2193
+ width: 9,
2194
+ height: 1,
2195
+ backgroundColor: connectorColor,
2196
+ pointerEvents: "none"
2197
+ }
2198
+ }
2199
+ )),
2200
+ isParent && /* @__PURE__ */ import_react6.default.createElement(
2201
+ "span",
2202
+ {
2203
+ className: "row-header-caret",
2204
+ role: "button",
2205
+ "aria-label": collapsed ? "Expand group" : "Collapse group",
2206
+ onClick: () => scene.toggleCollapsed(row.id),
2207
+ style: { cursor: "pointer", marginRight: 4, userSelect: "none" }
2208
+ },
2209
+ collapsed ? "\u25B8" : "\u25BE"
2210
+ ),
2211
+ /* @__PURE__ */ import_react6.default.createElement(
2212
+ "span",
2213
+ {
2214
+ className: "row-header-label",
2215
+ style: grouped ? { textAlign: "left" } : void 0
2216
+ },
2217
+ row.name
2218
+ )
1684
2219
  )
1685
2220
  );
1686
2221
  }
1687
2222
  const headerClassNames = rowsHeaderClassName ? `rows-header-wrapper canvas-rows-header ${rowsHeaderClassName}` : "rows-header-wrapper canvas-rows-header";
1688
- return /* @__PURE__ */ import_react7.default.createElement(import_react7.default.Fragment, null, /* @__PURE__ */ import_react7.default.createElement("div", { className: headerClassNames, style: { height: totalHeight } }, visibleHeaders), /* @__PURE__ */ import_react7.default.createElement("div", { className: "canvas-content-column", ref: contentRef }, /* @__PURE__ */ import_react7.default.createElement("div", { className: "canvas-sticky" }, /* @__PURE__ */ import_react7.default.createElement("canvas", { ref: staticCanvasRef }), /* @__PURE__ */ import_react7.default.createElement(
2223
+ return /* @__PURE__ */ import_react6.default.createElement(import_react6.default.Fragment, null, /* @__PURE__ */ import_react6.default.createElement(
2224
+ "div",
2225
+ {
2226
+ ref: headerWrapperRef,
2227
+ className: headerClassNames,
2228
+ style: { height: totalHeight }
2229
+ },
2230
+ visibleHeaders
2231
+ ), /* @__PURE__ */ import_react6.default.createElement("div", { className: "canvas-content-column", ref: contentRef }, /* @__PURE__ */ import_react6.default.createElement("div", { className: "canvas-sticky" }, /* @__PURE__ */ import_react6.default.createElement("canvas", { ref: staticCanvasRef }), /* @__PURE__ */ import_react6.default.createElement(
1689
2232
  "canvas",
1690
2233
  {
1691
2234
  ref: dynamicCanvasRef,
@@ -1693,9 +2236,17 @@ var CanvasBoard = (0, import_react7.forwardRef)(
1693
2236
  onPointerMove: handlePointerMove,
1694
2237
  onPointerUp: handlePointerUp,
1695
2238
  onPointerLeave: handlePointerLeave,
2239
+ onPointerCancel: handlePointerCancel,
1696
2240
  onAuxClick: handleAuxClick
1697
2241
  }
1698
- ), /* @__PURE__ */ import_react7.default.createElement("div", { ref: ghostRef, className: "event canvas-drag-ghost" })), /* @__PURE__ */ import_react7.default.createElement(
2242
+ ), /* @__PURE__ */ import_react6.default.createElement(
2243
+ "div",
2244
+ {
2245
+ ref: ghostRef,
2246
+ className: "event canvas-drag-ghost",
2247
+ style: { height: scene.getGeometry().barHeight }
2248
+ }
2249
+ )), /* @__PURE__ */ import_react6.default.createElement(
1699
2250
  "div",
1700
2251
  {
1701
2252
  className: "canvas-scroll-spacer",
@@ -1725,9 +2276,48 @@ var SceneStore = class {
1725
2276
  this.rowIndexes = /* @__PURE__ */ new Map();
1726
2277
  this.rowOrder = [];
1727
2278
  this.eventRow = /* @__PURE__ */ new Map();
2279
+ // Group index for tag-based "connected" selection. eventGroup: eventId ->
2280
+ // groupId; groupMembers: groupId -> set of eventIds. Maintained alongside
2281
+ // eventRow so Cmd/Ctrl+click resolves the whole group in O(group size)
2282
+ // without scanning all rows.
2283
+ this.eventGroup = /* @__PURE__ */ new Map();
2284
+ this.groupMembers = /* @__PURE__ */ new Map();
2285
+ // Row hierarchy for grouped (collapsible) rows. parentOf: childRowId ->
2286
+ // parentRowId; childRowsOf: parentRowId -> ordered child row ids. Rebuilt in
2287
+ // setRows from `row.parentId`. One level of nesting only in v1.
2288
+ this.parentOf = /* @__PURE__ */ new Map();
2289
+ this.childRowsOf = /* @__PURE__ */ new Map();
2290
+ // Rows the user has collapsed. Lives only here so it survives every data
2291
+ // update (setEvents / applyPatches / events-prop reset); setRows only prunes
2292
+ // entries for rows that no longer exist.
2293
+ this.collapsedRows = /* @__PURE__ */ new Set();
2294
+ // Parent↔child EVENT index (distinct from the row hierarchy above).
2295
+ // childrenOf: parentEventId -> child event ids; parentEventOf: childEventId ->
2296
+ // parentEventId. Driven by props.parentEventId / props.isGroupParent. A parent
2297
+ // event's [startTime,endTime] is derived lazily from its children; any child
2298
+ // mutation marks the parent dirty and the span is recomputed on the next query
2299
+ // of the parent's row (flushParentSpans) — off-screen groups cost nothing.
2300
+ this.childrenOf = /* @__PURE__ */ new Map();
2301
+ this.parentEventOf = /* @__PURE__ */ new Map();
2302
+ this.parentSpanDirty = /* @__PURE__ */ new Set();
1728
2303
  this.listeners = /* @__PURE__ */ new Set();
2304
+ // Themeable vertical layout. Lanes are geometry-free (pure time logic), so a
2305
+ // geometry change only affects heights/offsets — the cached lanes stay valid
2306
+ // and we just bump to trigger a redraw.
2307
+ this.geometry = DEFAULT_GEOMETRY;
2308
+ // Per-row minimum height demanded by the (DOM-measured) row label when it
2309
+ // wraps to multiple lines. Measured in the shell and fed back here so the
2310
+ // canvas grid/dividers, hit-testing and the DOM header all agree on height.
2311
+ this.labelMinHeights = /* @__PURE__ */ new Map();
1729
2312
  this.version = 0;
1730
2313
  }
2314
+ setGeometry(geometry) {
2315
+ this.geometry = geometry;
2316
+ this.bump();
2317
+ }
2318
+ getGeometry() {
2319
+ return this.geometry;
2320
+ }
1731
2321
  setRows(rows) {
1732
2322
  const next = /* @__PURE__ */ new Map();
1733
2323
  for (const row of rows) {
@@ -1746,23 +2336,53 @@ var SceneStore = class {
1746
2336
  );
1747
2337
  }
1748
2338
  for (const [id, rowId] of this.eventRow) {
1749
- if (!next.has(rowId)) this.eventRow.delete(id);
2339
+ if (!next.has(rowId)) {
2340
+ this.eventRow.delete(id);
2341
+ this.removeFromGroup(id);
2342
+ }
1750
2343
  }
1751
2344
  this.rowIndexes = next;
1752
2345
  this.rowOrder = rows.map((row) => row.id);
2346
+ this.parentOf = /* @__PURE__ */ new Map();
2347
+ this.childRowsOf = /* @__PURE__ */ new Map();
2348
+ for (const row of rows) {
2349
+ if (row.parentId === void 0) continue;
2350
+ this.parentOf.set(row.id, row.parentId);
2351
+ let children = this.childRowsOf.get(row.parentId);
2352
+ if (!children) {
2353
+ children = [];
2354
+ this.childRowsOf.set(row.parentId, children);
2355
+ }
2356
+ children.push(row.id);
2357
+ }
2358
+ if (this.collapsedRows.size > 0) {
2359
+ const rowIds = new Set(this.rowOrder);
2360
+ for (const id of [...this.collapsedRows]) {
2361
+ if (!rowIds.has(id)) this.collapsedRows.delete(id);
2362
+ }
2363
+ }
1753
2364
  this.bump();
1754
2365
  }
1755
2366
  setEvents(events) {
2367
+ var _a;
1756
2368
  for (const index of this.rowIndexes.values()) {
1757
2369
  index.events = [];
1758
2370
  index.lanesDirty = true;
1759
2371
  }
1760
2372
  this.eventRow.clear();
2373
+ this.eventGroup.clear();
2374
+ this.groupMembers.clear();
2375
+ this.childrenOf.clear();
2376
+ this.parentEventOf.clear();
2377
+ this.parentSpanDirty.clear();
1761
2378
  for (const event of events) {
1762
2379
  const index = this.rowIndexes.get(event.rowId);
1763
2380
  if (!index) continue;
1764
2381
  index.events.push(event);
1765
2382
  this.eventRow.set(event.id, event.rowId);
2383
+ this.addToGroup(event.id, (_a = event.props) == null ? void 0 : _a.groupId);
2384
+ this.addToParentIndex(event);
2385
+ this.validateDroppable(event);
1766
2386
  }
1767
2387
  for (const index of this.rowIndexes.values()) {
1768
2388
  index.events.sort(sort_events_default);
@@ -1805,15 +2425,88 @@ var SceneStore = class {
1805
2425
  if (rowId === void 0) return void 0;
1806
2426
  return (_a = this.rowIndexes.get(rowId)) == null ? void 0 : _a.events.find((event) => event.id === id);
1807
2427
  }
2428
+ /**
2429
+ * Event ids "connected" to the given event via a shared `props.groupId`.
2430
+ * Returns every member of the group (including the event itself), or just
2431
+ * `[eventId]` when the event has no group / no other members / is unknown.
2432
+ */
2433
+ getConnectedEventIds(eventId) {
2434
+ const groupId = this.eventGroup.get(eventId);
2435
+ if (groupId === void 0) return [eventId];
2436
+ const members = this.groupMembers.get(groupId);
2437
+ if (!members || members.size === 0) return [eventId];
2438
+ return [...members];
2439
+ }
2440
+ /**
2441
+ * Whether an event may enter the selection. False only when the event is
2442
+ * present and explicitly opted out (`props.isSelectable === false`); unknown
2443
+ * ids are treated as selectable so a selection can be set before data loads
2444
+ * and survives streaming.
2445
+ */
2446
+ isEventSelectable(id) {
2447
+ var _a;
2448
+ const event = this.getEvent(id);
2449
+ return event === void 0 || ((_a = event.props) == null ? void 0 : _a.isSelectable) !== false;
2450
+ }
1808
2451
  getRowIds() {
1809
2452
  return this.rowOrder;
1810
2453
  }
2454
+ /**
2455
+ * Row ids in display order, minus rows hidden inside a collapsed parent.
2456
+ * Drives offsets, drawing and hit-testing. The header still walks
2457
+ * `getRowIds()` so it can draw the carets and decide which rows to skip.
2458
+ */
2459
+ getVisibleRowIds() {
2460
+ if (this.collapsedRows.size === 0) return this.rowOrder;
2461
+ const visible = [];
2462
+ for (const rowId of this.rowOrder) {
2463
+ const parent = this.parentOf.get(rowId);
2464
+ if (parent !== void 0 && this.collapsedRows.has(parent)) continue;
2465
+ visible.push(rowId);
2466
+ }
2467
+ return visible;
2468
+ }
2469
+ /** whether a row is a parent (owns at least one child row) */
2470
+ isRowParent(rowId) {
2471
+ var _a, _b;
2472
+ return ((_b = (_a = this.childRowsOf.get(rowId)) == null ? void 0 : _a.length) != null ? _b : 0) > 0;
2473
+ }
2474
+ /** whether a row is hidden because its parent row is collapsed */
2475
+ isRowHidden(rowId) {
2476
+ const parent = this.parentOf.get(rowId);
2477
+ return parent !== void 0 && this.collapsedRows.has(parent);
2478
+ }
2479
+ isRowCollapsed(rowId) {
2480
+ return this.collapsedRows.has(rowId);
2481
+ }
2482
+ getCollapsedRowIds() {
2483
+ return [...this.collapsedRows];
2484
+ }
2485
+ setCollapsed(rowId, collapsed) {
2486
+ const has = this.collapsedRows.has(rowId);
2487
+ if (collapsed && !has) {
2488
+ this.collapsedRows.add(rowId);
2489
+ this.bump();
2490
+ } else if (!collapsed && has) {
2491
+ this.collapsedRows.delete(rowId);
2492
+ this.bump();
2493
+ }
2494
+ }
2495
+ toggleCollapsed(rowId) {
2496
+ this.setCollapsed(rowId, !this.collapsedRows.has(rowId));
2497
+ }
2498
+ /** child event ids of a parent (summary) event; empty if it has none */
2499
+ getChildEventIds(parentEventId) {
2500
+ const children = this.childrenOf.get(parentEventId);
2501
+ return children ? [...children] : [];
2502
+ }
1811
2503
  getRow(rowId) {
1812
2504
  var _a;
1813
2505
  return (_a = this.rowIndexes.get(rowId)) == null ? void 0 : _a.row;
1814
2506
  }
1815
2507
  getRowEvents(rowId) {
1816
2508
  var _a, _b;
2509
+ this.flushParentSpans(rowId);
1817
2510
  return (_b = (_a = this.rowIndexes.get(rowId)) == null ? void 0 : _a.events) != null ? _b : [];
1818
2511
  }
1819
2512
  getRowStaticEvents(rowId) {
@@ -1821,6 +2514,7 @@ var SceneStore = class {
1821
2514
  return (_b = (_a = this.rowIndexes.get(rowId)) == null ? void 0 : _a.staticEvents) != null ? _b : [];
1822
2515
  }
1823
2516
  getLanes(rowId, windowStart, windowEnd) {
2517
+ this.flushParentSpans(rowId);
1824
2518
  const index = this.rowIndexes.get(rowId);
1825
2519
  if (!index) return { laneOf: /* @__PURE__ */ new Map(), highestLane: 0 };
1826
2520
  if (index.lanesDirty || index.lanes === null || index.laneWindowStart !== windowStart || index.laneWindowEnd !== windowEnd) {
@@ -1831,8 +2525,35 @@ var SceneStore = class {
1831
2525
  }
1832
2526
  return index.lanes;
1833
2527
  }
2528
+ /**
2529
+ * Report the per-row label heights measured against the live DOM header
2530
+ * (key: rowId, value: the minimum row height the wrapped label needs,
2531
+ * already including vertical padding). Replaces the previous map wholesale
2532
+ * and only bumps when a value actually changed, so re-measuring identical
2533
+ * labels is a no-op and can't feed back into an infinite render loop.
2534
+ */
2535
+ setLabelMinHeights(heights) {
2536
+ let changed = heights.size !== this.labelMinHeights.size;
2537
+ if (!changed) {
2538
+ for (const [id, h] of heights) {
2539
+ if (this.labelMinHeights.get(id) !== h) {
2540
+ changed = true;
2541
+ break;
2542
+ }
2543
+ }
2544
+ }
2545
+ if (!changed) return;
2546
+ this.labelMinHeights = heights;
2547
+ this.bump();
2548
+ }
1834
2549
  getRowHeight(rowId, windowStart, windowEnd) {
1835
- return rowMinHeight(this.getLanes(rowId, windowStart, windowEnd).highestLane);
2550
+ var _a;
2551
+ const laneHeight = rowMinHeight(
2552
+ this.getLanes(rowId, windowStart, windowEnd).highestLane,
2553
+ this.geometry
2554
+ );
2555
+ const labelHeight = (_a = this.labelMinHeights.get(rowId)) != null ? _a : 0;
2556
+ return Math.max(laneHeight, labelHeight);
1836
2557
  }
1837
2558
  /**
1838
2559
  * y offset of each row's top edge (content coordinates, before scroll) plus
@@ -1841,7 +2562,7 @@ var SceneStore = class {
1841
2562
  getRowOffsets(windowStart, windowEnd) {
1842
2563
  const offsetOf = /* @__PURE__ */ new Map();
1843
2564
  let y = 0;
1844
- for (const rowId of this.rowOrder) {
2565
+ for (const rowId of this.getVisibleRowIds()) {
1845
2566
  offsetOf.set(rowId, y);
1846
2567
  y += this.getRowHeight(rowId, windowStart, windowEnd);
1847
2568
  }
@@ -1852,11 +2573,15 @@ var SceneStore = class {
1852
2573
  return () => this.listeners.delete(listener);
1853
2574
  }
1854
2575
  insert(event) {
2576
+ var _a;
1855
2577
  const index = this.rowIndexes.get(event.rowId);
1856
2578
  if (!index) return;
1857
2579
  index.events.splice(binaryInsertIndex(index.events, event), 0, event);
1858
2580
  index.lanesDirty = true;
1859
2581
  this.eventRow.set(event.id, event.rowId);
2582
+ this.addToGroup(event.id, (_a = event.props) == null ? void 0 : _a.groupId);
2583
+ this.addToParentIndex(event);
2584
+ this.validateDroppable(event);
1860
2585
  }
1861
2586
  remove(id) {
1862
2587
  const rowId = this.eventRow.get(id);
@@ -1868,6 +2593,117 @@ var SceneStore = class {
1868
2593
  index.lanesDirty = true;
1869
2594
  }
1870
2595
  this.eventRow.delete(id);
2596
+ this.removeFromGroup(id);
2597
+ this.removeFromParentIndex(id);
2598
+ }
2599
+ addToGroup(eventId, groupId) {
2600
+ if (groupId === void 0) return;
2601
+ this.eventGroup.set(eventId, groupId);
2602
+ let members = this.groupMembers.get(groupId);
2603
+ if (!members) {
2604
+ members = /* @__PURE__ */ new Set();
2605
+ this.groupMembers.set(groupId, members);
2606
+ }
2607
+ members.add(eventId);
2608
+ }
2609
+ removeFromGroup(eventId) {
2610
+ const groupId = this.eventGroup.get(eventId);
2611
+ if (groupId === void 0) return;
2612
+ this.eventGroup.delete(eventId);
2613
+ const members = this.groupMembers.get(groupId);
2614
+ if (members) {
2615
+ members.delete(eventId);
2616
+ if (members.size === 0) this.groupMembers.delete(groupId);
2617
+ }
2618
+ }
2619
+ /**
2620
+ * Enforce the authoring contract for `props.droppableRowIds`: if the event's
2621
+ * current row is not among its allowed rows, record a `droppableError` on
2622
+ * `props.metadata` (merged non-destructively); otherwise clear any stale one.
2623
+ * Cheap no-op for events without `droppableRowIds` and no prior error.
2624
+ */
2625
+ validateDroppable(event) {
2626
+ var _a, _b;
2627
+ const allowed = (_a = event.props) == null ? void 0 : _a.droppableRowIds;
2628
+ const meta = (_b = event.props) == null ? void 0 : _b.metadata;
2629
+ const metaObj = typeof meta === "object" && meta !== null ? meta : void 0;
2630
+ const hadError = metaObj !== void 0 && "droppableError" in metaObj;
2631
+ const needsError = allowed !== void 0 && !allowed.includes(event.rowId);
2632
+ if (!needsError && !hadError) return;
2633
+ if (!event.props) return;
2634
+ if (needsError) {
2635
+ event.props.metadata = __spreadProps(__spreadValues({}, metaObj != null ? metaObj : {}), {
2636
+ droppableError: {
2637
+ rowId: event.rowId,
2638
+ droppableRowIds: allowed
2639
+ }
2640
+ });
2641
+ } else {
2642
+ const rest = __spreadValues({}, metaObj);
2643
+ delete rest.droppableError;
2644
+ event.props.metadata = Object.keys(rest).length > 0 ? rest : void 0;
2645
+ }
2646
+ }
2647
+ addToParentIndex(event) {
2648
+ var _a;
2649
+ const parentId = (_a = event.props) == null ? void 0 : _a.parentEventId;
2650
+ if (parentId === void 0) return;
2651
+ this.parentEventOf.set(event.id, parentId);
2652
+ let children = this.childrenOf.get(parentId);
2653
+ if (!children) {
2654
+ children = /* @__PURE__ */ new Set();
2655
+ this.childrenOf.set(parentId, children);
2656
+ }
2657
+ children.add(event.id);
2658
+ this.parentSpanDirty.add(parentId);
2659
+ }
2660
+ removeFromParentIndex(eventId) {
2661
+ const parentId = this.parentEventOf.get(eventId);
2662
+ if (parentId === void 0) return;
2663
+ this.parentEventOf.delete(eventId);
2664
+ const children = this.childrenOf.get(parentId);
2665
+ if (children) {
2666
+ children.delete(eventId);
2667
+ if (children.size === 0) this.childrenOf.delete(parentId);
2668
+ }
2669
+ this.parentSpanDirty.add(parentId);
2670
+ }
2671
+ /**
2672
+ * Recompute the derived span of any dirty parent event living on `rowId`
2673
+ * (earliest child start → latest child end), write it back into the parent
2674
+ * event, and re-sort the row so the sorted-array invariant holds. Cheap no-op
2675
+ * when nothing is dirty (the common no-groups case never touches this).
2676
+ */
2677
+ flushParentSpans(rowId) {
2678
+ var _a;
2679
+ if (this.parentSpanDirty.size === 0) return;
2680
+ const index = this.rowIndexes.get(rowId);
2681
+ if (!index) return;
2682
+ let changed = false;
2683
+ for (const event of index.events) {
2684
+ if (!((_a = event.props) == null ? void 0 : _a.isGroupParent)) continue;
2685
+ if (!this.parentSpanDirty.has(event.id)) continue;
2686
+ this.parentSpanDirty.delete(event.id);
2687
+ const children = this.childrenOf.get(event.id);
2688
+ if (!children || children.size === 0) continue;
2689
+ let minStart = Infinity;
2690
+ let maxEnd = -Infinity;
2691
+ for (const childId of children) {
2692
+ const child = this.getEvent(childId);
2693
+ if (!child) continue;
2694
+ if (child.startTime < minStart) minStart = child.startTime;
2695
+ if (child.endTime > maxEnd) maxEnd = child.endTime;
2696
+ }
2697
+ if (minStart !== Infinity && (event.startTime !== minStart || event.endTime !== maxEnd)) {
2698
+ event.startTime = minStart;
2699
+ event.endTime = maxEnd;
2700
+ changed = true;
2701
+ }
2702
+ }
2703
+ if (changed) {
2704
+ index.events.sort(sort_events_default);
2705
+ index.lanesDirty = true;
2706
+ }
1871
2707
  }
1872
2708
  bump() {
1873
2709
  this.version++;
@@ -1876,7 +2712,7 @@ var SceneStore = class {
1876
2712
  };
1877
2713
 
1878
2714
  // src/timeline.tsx
1879
- var Timeline = (0, import_react8.forwardRef)(
2715
+ var Timeline = (0, import_react7.forwardRef)(
1880
2716
  ({
1881
2717
  rows,
1882
2718
  events,
@@ -1885,6 +2721,10 @@ var Timeline = (0, import_react8.forwardRef)(
1885
2721
  onResize,
1886
2722
  onEventClick,
1887
2723
  onEventHover,
2724
+ selectable = false,
2725
+ defaultSelectedEventIds,
2726
+ onSelectionChange,
2727
+ defaultCollapsedRowIds,
1888
2728
  startDate,
1889
2729
  endDate,
1890
2730
  theme,
@@ -1895,9 +2735,10 @@ var Timeline = (0, import_react8.forwardRef)(
1895
2735
  eventPromptTemplate,
1896
2736
  showEventPrompt = true,
1897
2737
  panZoom,
2738
+ timeBar,
1898
2739
  animations = true
1899
2740
  }, handleRef) => {
1900
- const [windowTime, setWindowTime] = (0, import_react8.useState)([
2741
+ const [windowTime, setWindowTime] = (0, import_react7.useState)([
1901
2742
  new Date(
1902
2743
  startDate.getFullYear(),
1903
2744
  startDate.getMonth(),
@@ -1915,31 +2756,69 @@ var Timeline = (0, import_react8.forwardRef)(
1915
2756
  0
1916
2757
  ).getTime() / 1e3
1917
2758
  ]);
1918
- const [cellWidth, setCellWidth] = (0, import_react8.useState)(0);
1919
- const contentRef = (0, import_react8.useRef)(null);
1920
- const mainRef = (0, import_react8.useRef)(null);
1921
- const bodyRef = (0, import_react8.useRef)(null);
1922
- const [tick, setTick] = (0, import_react8.useState)(null);
1923
- const [scrollWidth, setScrollWidth] = (0, import_react8.useState)(0);
1924
- const eventPromptRef = (0, import_react8.useRef)(null);
1925
- const rendererRef = (0, import_react8.useRef)(null);
1926
- const sceneRef = (0, import_react8.useRef)(null);
2759
+ const [cellWidth, setCellWidth] = (0, import_react7.useState)(0);
2760
+ const contentRef = (0, import_react7.useRef)(null);
2761
+ const mainRef = (0, import_react7.useRef)(null);
2762
+ const bodyRef = (0, import_react7.useRef)(null);
2763
+ const [tick, setTick] = (0, import_react7.useState)(null);
2764
+ const [scrollWidth, setScrollWidth] = (0, import_react7.useState)(0);
2765
+ const eventPromptRef = (0, import_react7.useRef)(null);
2766
+ const rendererRef = (0, import_react7.useRef)(null);
2767
+ const sceneRef = (0, import_react7.useRef)(null);
1927
2768
  if (sceneRef.current === null) {
1928
2769
  sceneRef.current = new SceneStore();
1929
2770
  }
1930
2771
  const scene = sceneRef.current;
1931
- (0, import_react8.useEffect)(() => {
2772
+ const selectionRef = (0, import_react7.useRef)(
2773
+ new Set(defaultSelectedEventIds != null ? defaultSelectedEventIds : [])
2774
+ );
2775
+ const onSelectionChangeRef = (0, import_react7.useRef)(onSelectionChange);
2776
+ onSelectionChangeRef.current = onSelectionChange;
2777
+ const applySelection = (0, import_react7.useCallback)(
2778
+ (ids) => {
2779
+ var _a, _b;
2780
+ const expanded = [];
2781
+ for (const id of ids) {
2782
+ expanded.push(id);
2783
+ for (const childId of scene.getChildEventIds(id)) {
2784
+ expanded.push(childId);
2785
+ }
2786
+ }
2787
+ selectionRef.current = new Set(
2788
+ expanded.filter((id) => scene.isEventSelectable(id))
2789
+ );
2790
+ (_a = rendererRef.current) == null ? void 0 : _a.setView({
2791
+ selectedEventIds: selectionRef.current
2792
+ });
2793
+ (_b = onSelectionChangeRef.current) == null ? void 0 : _b.call(onSelectionChangeRef, [...selectionRef.current]);
2794
+ },
2795
+ [scene]
2796
+ );
2797
+ const getSelection = (0, import_react7.useCallback)(() => [...selectionRef.current], []);
2798
+ (0, import_react7.useEffect)(() => {
2799
+ var _a;
1932
2800
  scene.setRows(rows);
2801
+ (_a = rendererRef.current) == null ? void 0 : _a.animator.reset();
1933
2802
  }, [scene, rows]);
1934
- (0, import_react8.useEffect)(() => {
2803
+ (0, import_react7.useEffect)(() => {
2804
+ var _a;
1935
2805
  scene.setEvents([...events].sort(sort_events_default));
2806
+ (_a = rendererRef.current) == null ? void 0 : _a.animator.reset();
1936
2807
  }, [scene, events]);
1937
- (0, import_react8.useEffect)(() => {
2808
+ (0, import_react7.useEffect)(() => {
1938
2809
  scene.setStaticEvents(staticEvents ? [...staticEvents] : []);
1939
2810
  }, [scene, staticEvents]);
1940
- const windowTimeRef = (0, import_react8.useRef)(windowTime);
2811
+ const seededCollapseRef = (0, import_react7.useRef)(false);
2812
+ (0, import_react7.useEffect)(() => {
2813
+ if (seededCollapseRef.current) return;
2814
+ seededCollapseRef.current = true;
2815
+ for (const id of defaultCollapsedRowIds != null ? defaultCollapsedRowIds : []) {
2816
+ scene.setCollapsed(id, true);
2817
+ }
2818
+ }, [scene, defaultCollapsedRowIds]);
2819
+ const windowTimeRef = (0, import_react7.useRef)(windowTime);
1941
2820
  windowTimeRef.current = windowTime;
1942
- (0, import_react8.useImperativeHandle)(
2821
+ (0, import_react7.useImperativeHandle)(
1943
2822
  handleRef,
1944
2823
  () => ({
1945
2824
  setEvents: (next) => scene.setEvents([...next].sort(sort_events_default)),
@@ -1960,14 +2839,18 @@ var Timeline = (0, import_react8.forwardRef)(
1960
2839
  startTime: windowTimeRef.current[0],
1961
2840
  endTime: windowTimeRef.current[1]
1962
2841
  }),
2842
+ setSelection: (ids) => applySelection(ids),
2843
+ getSelection,
2844
+ toggleRow: (rowId) => scene.toggleCollapsed(rowId),
2845
+ setCollapsed: (rowId, collapsed) => scene.setCollapsed(rowId, collapsed),
1963
2846
  redraw: () => {
1964
2847
  var _a;
1965
2848
  return (_a = rendererRef.current) == null ? void 0 : _a.invalidate("all");
1966
2849
  }
1967
2850
  }),
1968
- [scene]
2851
+ [scene, applySelection, getSelection]
1969
2852
  );
1970
- (0, import_react8.useEffect)(() => {
2853
+ (0, import_react7.useEffect)(() => {
1971
2854
  if (contentRef.current) {
1972
2855
  const windowDuration = windowTime[1] - windowTime[0];
1973
2856
  const numberOfHourBlocks = windowDuration / 3600;
@@ -1979,7 +2862,7 @@ var Timeline = (0, import_react8.forwardRef)(
1979
2862
  );
1980
2863
  }
1981
2864
  }, []);
1982
- (0, import_react8.useEffect)(() => {
2865
+ (0, import_react7.useEffect)(() => {
1983
2866
  if (bodyRef.current) {
1984
2867
  setScrollWidth(
1985
2868
  bodyRef.current.getBoundingClientRect().width - bodyRef.current.scrollWidth
@@ -1987,8 +2870,15 @@ var Timeline = (0, import_react8.forwardRef)(
1987
2870
  }
1988
2871
  }, []);
1989
2872
  use_resize_observer_default({ contentRef, setCellWidth, setTick, windowTime });
1990
- const resolvedTheme = (0, import_react8.useMemo)(() => resolveTheme(theme), [theme]);
1991
- const resolvedAnimations = (0, import_react8.useMemo)(() => {
2873
+ const resolvedTheme = (0, import_react7.useMemo)(() => resolveTheme(theme), [theme]);
2874
+ const geometry = (0, import_react7.useMemo)(
2875
+ () => geometryFromTheme(resolvedTheme),
2876
+ [resolvedTheme]
2877
+ );
2878
+ (0, import_react7.useEffect)(() => {
2879
+ scene.setGeometry(geometry);
2880
+ }, [scene, geometry]);
2881
+ const resolvedAnimations = (0, import_react7.useMemo)(() => {
1992
2882
  var _a, _b;
1993
2883
  if (animations === false) return { layoutMs: 0, fadeMs: 0 };
1994
2884
  if (animations === true) {
@@ -2002,8 +2892,8 @@ var Timeline = (0, import_react8.forwardRef)(
2002
2892
  fadeMs: (_b = animations.fadeMs) != null ? _b : DEFAULT_FADE_DURATION_MS
2003
2893
  };
2004
2894
  }, [animations]);
2005
- const eventPrompt = (0, import_react8.useMemo)(
2006
- () => /* @__PURE__ */ import_react8.default.createElement(
2895
+ const eventPrompt = (0, import_react7.useMemo)(
2896
+ () => /* @__PURE__ */ import_react7.default.createElement(
2007
2897
  event_prompt_default,
2008
2898
  {
2009
2899
  ref: eventPromptRef,
@@ -2012,16 +2902,17 @@ var Timeline = (0, import_react8.forwardRef)(
2012
2902
  ),
2013
2903
  [eventPromptTemplate]
2014
2904
  );
2015
- return /* @__PURE__ */ import_react8.default.createElement("div", { className: "main-wrapper", ref: mainRef }, showRTIndicator && /* @__PURE__ */ import_react8.default.createElement(rt_indicator_default, { tick, windowTime }), /* @__PURE__ */ import_react8.default.createElement(
2905
+ return /* @__PURE__ */ import_react7.default.createElement("div", { className: "main-wrapper", ref: mainRef }, showRTIndicator && /* @__PURE__ */ import_react7.default.createElement(rt_indicator_default, { tick, windowTime }), /* @__PURE__ */ import_react7.default.createElement(
2016
2906
  canvas_time_bar_default,
2017
2907
  {
2018
2908
  windowTime,
2019
2909
  tick,
2020
2910
  contentWidth: contentRef.current ? contentRef.current.getBoundingClientRect().width : null,
2021
2911
  scrollWidth,
2022
- theme: resolvedTheme
2912
+ theme: resolvedTheme,
2913
+ timeBar
2023
2914
  }
2024
- ), /* @__PURE__ */ import_react8.default.createElement("div", { className: "body-wrapper", ref: bodyRef }, /* @__PURE__ */ import_react8.default.createElement(
2915
+ ), /* @__PURE__ */ import_react7.default.createElement("div", { className: "body-wrapper", ref: bodyRef }, /* @__PURE__ */ import_react7.default.createElement(
2025
2916
  canvas_board_default,
2026
2917
  {
2027
2918
  scene,
@@ -2037,6 +2928,7 @@ var Timeline = (0, import_react8.forwardRef)(
2037
2928
  rowsHeaderClassName: additionalClassNames == null ? void 0 : additionalClassNames.rowsHeader,
2038
2929
  setWindowTime,
2039
2930
  setCellWidth,
2931
+ setTick,
2040
2932
  onDrop,
2041
2933
  onResize,
2042
2934
  onEventClick,
@@ -2044,6 +2936,9 @@ var Timeline = (0, import_react8.forwardRef)(
2044
2936
  eventsResize,
2045
2937
  panZoom,
2046
2938
  animations: resolvedAnimations,
2939
+ selectable,
2940
+ applySelection,
2941
+ getSelection,
2047
2942
  ref: contentRef
2048
2943
  }
2049
2944
  ), showEventPrompt && eventPrompt));