awesome-timeline-react 0.3.0 → 0.4.1

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.mjs CHANGED
@@ -21,6 +21,7 @@ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
21
21
  // src/timeline.tsx
22
22
  import React6, {
23
23
  forwardRef as forwardRef3,
24
+ useCallback as useCallback3,
24
25
  useEffect as useEffect6,
25
26
  useImperativeHandle as useImperativeHandle2,
26
27
  useMemo as useMemo3,
@@ -34,7 +35,6 @@ var DEFAULT_FADE_DURATION_MS = 120;
34
35
  var ease = (t) => t * t * (3 - 2 * t);
35
36
  var LayoutAnimator = class {
36
37
  constructor() {
37
- this.rowHeights = /* @__PURE__ */ new Map();
38
38
  this.eventTops = /* @__PURE__ */ new Map();
39
39
  this.handleAlphas = /* @__PURE__ */ new Map();
40
40
  this.now = 0;
@@ -49,9 +49,6 @@ var LayoutAnimator = class {
49
49
  beginFrame(now) {
50
50
  this.now = now;
51
51
  }
52
- rowHeight(rowId, target) {
53
- return this.value(this.rowHeights, rowId, target, this.layoutDuration);
54
- }
55
52
  eventTop(eventId, target) {
56
53
  return this.value(this.eventTops, eventId, target, this.layoutDuration);
57
54
  }
@@ -72,7 +69,6 @@ var LayoutAnimator = class {
72
69
  }
73
70
  /** Drop all state, e.g. when the scene is reset wholesale. */
74
71
  reset() {
75
- this.rowHeights.clear();
76
72
  this.eventTops.clear();
77
73
  this.handleAlphas.clear();
78
74
  this.activeUntil = 0;
@@ -441,11 +437,17 @@ var DEFAULT_THEME = {
441
437
  gridColor: "#e4dcdc",
442
438
  timeBarBorder: "yellow",
443
439
  timeBarTextColor: "white",
440
+ dimmedOpacity: 0.35,
441
+ selectionShadowColor: "rgba(0,0,0,0.35)",
442
+ selectionShadowBlur: 8,
443
+ selectionElevation: 2,
444
444
  font: void 0,
445
445
  barHeight: 20,
446
446
  laneGap: 2,
447
447
  rowPaddingY: 10,
448
- barRadius: 5
448
+ barRadius: 5,
449
+ groupChildBackground: "rgba(0,0,0,0.05)",
450
+ groupShadowColor: "rgba(0,0,0,0.22)"
449
451
  };
450
452
  var resolveTheme = (theme) => __spreadValues(__spreadValues({}, DEFAULT_THEME), theme);
451
453
 
@@ -590,6 +592,7 @@ import React5, {
590
592
  forwardRef as forwardRef2,
591
593
  useCallback as useCallback2,
592
594
  useEffect as useEffect5,
595
+ useLayoutEffect,
593
596
  useRef as useRef6,
594
597
  useState as useState3,
595
598
  useSyncExternalStore
@@ -747,9 +750,10 @@ var computeResizeTimes = (event, deltaPx, tick, direction) => {
747
750
  return null;
748
751
  };
749
752
  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);
753
+ var _a, _b, _c, _d, _e;
754
+ 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
755
  };
756
+ var isRowDroppable = (droppableRowIds, targetRowId) => droppableRowIds === void 0 || droppableRowIds.includes(targetRowId);
753
757
  var stepCellWidth = (cellWidth, deltaY, tick) => {
754
758
  const pixelsToCalculate = 900 / tick;
755
759
  const next = deltaY > 0 ? cellWidth + pixelsToCalculate : cellWidth - pixelsToCalculate;
@@ -797,18 +801,75 @@ var roundedRect = (ctx, x, y, width, height, radius) => {
797
801
  ctx.closePath();
798
802
  }
799
803
  };
800
- var drawRowDividers = (ctx, view, scene, animator) => {
804
+ var drawGroupShading = (ctx, view, scene) => {
805
+ var _a;
801
806
  const [windowStart, windowEnd] = view.windowTime;
802
- const rowIds = scene.getRowIds();
807
+ const visible = scene.getVisibleRowIds();
808
+ const regions = [];
809
+ let y = 0;
810
+ let runParent = null;
811
+ let runTop = 0;
812
+ let runBottom = 0;
813
+ const flush = () => {
814
+ if (runParent !== null) regions.push({ top: runTop, bottom: runBottom });
815
+ runParent = null;
816
+ };
817
+ for (const rowId of visible) {
818
+ const height = scene.getRowHeight(rowId, windowStart, windowEnd);
819
+ const parentId = (_a = scene.getRow(rowId)) == null ? void 0 : _a.parentId;
820
+ if (parentId !== void 0) {
821
+ if (runParent === parentId) {
822
+ runBottom = y + height;
823
+ } else {
824
+ flush();
825
+ runParent = parentId;
826
+ runTop = y;
827
+ runBottom = y + height;
828
+ }
829
+ } else {
830
+ flush();
831
+ }
832
+ y += height;
833
+ }
834
+ flush();
835
+ if (regions.length === 0) return;
836
+ ctx.save();
837
+ for (const { top, bottom } of regions) {
838
+ const sTop = top - view.scrollTop;
839
+ const sBottom = bottom - view.scrollTop;
840
+ if (sBottom < 0 || sTop > view.height) continue;
841
+ const regionHeight = sBottom - sTop;
842
+ ctx.fillStyle = view.theme.groupChildBackground;
843
+ ctx.fillRect(0, sTop, view.width, regionHeight);
844
+ const depth = Math.min(12, regionHeight / 2);
845
+ const topGrad = ctx.createLinearGradient(0, sTop, 0, sTop + depth);
846
+ topGrad.addColorStop(0, view.theme.groupShadowColor);
847
+ topGrad.addColorStop(1, "rgba(0,0,0,0)");
848
+ ctx.fillStyle = topGrad;
849
+ ctx.fillRect(0, sTop, view.width, depth);
850
+ const botGrad = ctx.createLinearGradient(0, sBottom - depth, 0, sBottom);
851
+ botGrad.addColorStop(0, "rgba(0,0,0,0)");
852
+ botGrad.addColorStop(1, view.theme.groupShadowColor);
853
+ ctx.fillStyle = botGrad;
854
+ ctx.fillRect(0, sBottom - depth, view.width, depth);
855
+ const leftShadow = 10;
856
+ const hGrad = ctx.createLinearGradient(0, 0, leftShadow, 0);
857
+ hGrad.addColorStop(0, view.theme.groupShadowColor);
858
+ hGrad.addColorStop(1, "rgba(0,0,0,0)");
859
+ ctx.fillStyle = hGrad;
860
+ ctx.fillRect(0, sTop, leftShadow, regionHeight);
861
+ }
862
+ ctx.restore();
863
+ };
864
+ var drawRowDividers = (ctx, view, scene) => {
865
+ const [windowStart, windowEnd] = view.windowTime;
866
+ const rowIds = scene.getVisibleRowIds();
803
867
  ctx.strokeStyle = view.theme.gridColor;
804
868
  ctx.lineWidth = 1;
805
869
  ctx.beginPath();
806
870
  let y = 0;
807
871
  for (let i = 0; i < rowIds.length; i++) {
808
- y += animator.rowHeight(
809
- rowIds[i],
810
- scene.getRowHeight(rowIds[i], windowStart, windowEnd)
811
- );
872
+ y += scene.getRowHeight(rowIds[i], windowStart, windowEnd);
812
873
  if (i === rowIds.length - 1) break;
813
874
  const screenY = y - view.scrollTop;
814
875
  if (screenY < 0) continue;
@@ -884,7 +945,7 @@ var defaultDrawEvent = (ctx, event, rect, view, font, barRadius) => {
884
945
  }
885
946
  };
886
947
  var drawEvents = (ctx, view, scene, font, animator) => {
887
- var _a, _b, _c, _d, _e, _f;
948
+ var _a;
888
949
  if (view.tick === null) return;
889
950
  const [windowStart, windowEnd] = view.windowTime;
890
951
  const tick = view.tick;
@@ -892,12 +953,45 @@ var drawEvents = (ctx, view, scene, font, animator) => {
892
953
  ctx.font = (_a = view.theme.font) != null ? _a : font;
893
954
  ctx.textBaseline = "middle";
894
955
  ctx.textAlign = "left";
956
+ const selectedIds = view.selectedEventIds;
957
+ const hasSelection = selectedIds.size > 0;
958
+ const deferred = [];
959
+ const paintEvent = (event, rect, state, opts) => {
960
+ var _a2, _b, _c, _d, _e;
961
+ ctx.save();
962
+ if (opts.elevate) {
963
+ ctx.translate(0, -view.theme.selectionElevation);
964
+ ctx.shadowColor = view.theme.selectionShadowColor;
965
+ ctx.shadowBlur = view.theme.selectionShadowBlur;
966
+ ctx.shadowOffsetY = view.theme.selectionElevation;
967
+ }
968
+ if (state.dragging) ctx.globalAlpha = 0.5;
969
+ else if (opts.dim) ctx.globalAlpha *= view.theme.dimmedOpacity;
970
+ const custom = (_b = (_a2 = event.props) == null ? void 0 : _a2.drawEvent) != null ? _b : view.drawEvent;
971
+ const drawn = custom !== void 0 && custom(ctx, event, rect, state, view.theme) !== false;
972
+ if (!drawn) {
973
+ defaultDrawEvent(ctx, event, rect, view, font, geometry.barRadius);
974
+ }
975
+ if (canResizeEvent(event, view.eventsResize)) {
976
+ const alpha = animator.handleAlpha(
977
+ event.id,
978
+ state.hovered || state.resizing ? 1 : 0
979
+ );
980
+ if (alpha > 0.01) {
981
+ ctx.shadowColor = "transparent";
982
+ drawResizeHandles(
983
+ ctx,
984
+ rect,
985
+ alpha,
986
+ (_e = (_d = (_c = event.props) == null ? void 0 : _c.style) == null ? void 0 : _d.stroke) != null ? _e : view.theme.eventStroke
987
+ );
988
+ }
989
+ }
990
+ ctx.restore();
991
+ };
895
992
  let rowTop = 0;
896
- for (const rowId of scene.getRowIds()) {
897
- const rowHeight = animator.rowHeight(
898
- rowId,
899
- scene.getRowHeight(rowId, windowStart, windowEnd)
900
- );
993
+ for (const rowId of scene.getVisibleRowIds()) {
994
+ const rowHeight = scene.getRowHeight(rowId, windowStart, windowEnd);
901
995
  const rowY = rowTop - view.scrollTop;
902
996
  rowTop += rowHeight;
903
997
  if (rowY + rowHeight < 0) continue;
@@ -943,36 +1037,23 @@ var drawEvents = (ctx, view, scene, font, animator) => {
943
1037
  }
944
1038
  }
945
1039
  const rect = { x, y, width, height: geometry.barHeight };
1040
+ const selected = selectedIds.has(event.id);
946
1041
  const state = {
947
1042
  hovered: view.hoveredEventId === event.id,
948
1043
  dragging: view.draggedEventId === event.id,
949
1044
  resizing,
950
- selected: false
1045
+ selected
951
1046
  };
952
- ctx.save();
953
- if (state.dragging) ctx.globalAlpha = 0.5;
954
- const custom = (_c = (_b = event.props) == null ? void 0 : _b.drawEvent) != null ? _c : view.drawEvent;
955
- const drawn = custom !== void 0 && custom(ctx, event, rect, state, view.theme) !== false;
956
- if (!drawn) {
957
- defaultDrawEvent(ctx, event, rect, view, font, geometry.barRadius);
958
- }
959
- if (canResizeEvent(event, view.eventsResize)) {
960
- const alpha = animator.handleAlpha(
961
- event.id,
962
- state.hovered || state.resizing ? 1 : 0
1047
+ if (selected) {
1048
+ deferred.push(
1049
+ () => paintEvent(event, rect, state, { dim: false, elevate: true })
963
1050
  );
964
- if (alpha > 0.01) {
965
- drawResizeHandles(
966
- ctx,
967
- rect,
968
- alpha,
969
- (_f = (_e = (_d = event.props) == null ? void 0 : _d.style) == null ? void 0 : _e.stroke) != null ? _f : view.theme.eventStroke
970
- );
971
- }
1051
+ } else {
1052
+ paintEvent(event, rect, state, { dim: hasSelection, elevate: false });
972
1053
  }
973
- ctx.restore();
974
1054
  }
975
1055
  }
1056
+ for (const paint of deferred) paint();
976
1057
  };
977
1058
 
978
1059
  // src/canvas/renderer.ts
@@ -993,7 +1074,8 @@ var TimelineRenderer = class {
993
1074
  eventsResize: true,
994
1075
  hoveredEventId: null,
995
1076
  draggedEventId: null,
996
- resizePreview: null
1077
+ resizePreview: null,
1078
+ selectedEventIds: /* @__PURE__ */ new Set()
997
1079
  };
998
1080
  this.animator = new LayoutAnimator();
999
1081
  this.dpr = typeof window !== "undefined" ? window.devicePixelRatio : 1;
@@ -1004,6 +1086,7 @@ var TimelineRenderer = class {
1004
1086
  this.dpr = dpr;
1005
1087
  this.resizeCanvases();
1006
1088
  this.invalidate("all");
1089
+ this.scheduler.flush();
1007
1090
  });
1008
1091
  }
1009
1092
  getView() {
@@ -1015,6 +1098,7 @@ var TimelineRenderer = class {
1015
1098
  if (sizeChanged) {
1016
1099
  this.resizeCanvases();
1017
1100
  this.invalidate("all");
1101
+ this.scheduler.flush();
1018
1102
  return;
1019
1103
  }
1020
1104
  this.invalidate("all");
@@ -1045,6 +1129,7 @@ var TimelineRenderer = class {
1045
1129
  const ctx = this.staticCanvas.getContext("2d");
1046
1130
  if (ctx) {
1047
1131
  ctx.clearRect(0, 0, this.view.width, this.view.height);
1132
+ drawGroupShading(ctx, this.view, this.scene);
1048
1133
  drawGridLines(ctx, {
1049
1134
  width: this.view.width,
1050
1135
  height: this.view.height,
@@ -1053,7 +1138,7 @@ var TimelineRenderer = class {
1053
1138
  tick: this.view.tick,
1054
1139
  color: this.view.theme.gridColor
1055
1140
  });
1056
- drawRowDividers(ctx, this.view, this.scene, this.animator);
1141
+ drawRowDividers(ctx, this.view, this.scene);
1057
1142
  }
1058
1143
  }
1059
1144
  if (dirty.dynamic) {
@@ -1082,7 +1167,7 @@ var hitTest = (scene, view, x, y) => {
1082
1167
  const yContent = y + scrollTop;
1083
1168
  let rowTop = 0;
1084
1169
  let rowId = null;
1085
- for (const id of scene.getRowIds()) {
1170
+ for (const id of scene.getVisibleRowIds()) {
1086
1171
  const height = scene.getRowHeight(id, windowStart, windowEnd);
1087
1172
  if (yContent >= rowTop && yContent < rowTop + height) {
1088
1173
  rowId = id;
@@ -1159,7 +1244,10 @@ var useCanvasInteractions = ({
1159
1244
  onEventClick,
1160
1245
  onEventHover,
1161
1246
  eventsResize,
1162
- panZoom
1247
+ panZoom,
1248
+ selectable,
1249
+ applySelection,
1250
+ getSelection
1163
1251
  }) => {
1164
1252
  const stateRef = useRef5({ mode: "idle" });
1165
1253
  const changeGridRef = useRef5(false);
@@ -1303,14 +1391,22 @@ var useCanvasInteractions = ({
1303
1391
  }, [rendererRef, setWindowTime]);
1304
1392
  const updateGhost = useCallback(
1305
1393
  (state, clientX, clientY) => {
1394
+ var _a;
1306
1395
  const ghost = ghostRef.current;
1307
1396
  if (!ghost) return;
1397
+ const rawLeft = state.hit.rect.x + (clientX - state.startClientX);
1398
+ const rawTop = state.hit.rect.y + (clientY - state.startClientY);
1399
+ const view = (_a = rendererRef.current) == null ? void 0 : _a.getView();
1400
+ const ghostWidth = state.hit.rect.width;
1401
+ const ghostHeight = state.hit.rect.height;
1402
+ const left = view ? Math.max(0, Math.min(rawLeft, Math.max(0, view.width - ghostWidth))) : rawLeft;
1403
+ const top = view ? Math.max(0, Math.min(rawTop, Math.max(0, view.height - ghostHeight))) : rawTop;
1308
1404
  ghost.style.display = "flex";
1309
- ghost.style.left = `${state.hit.rect.x + (clientX - state.startClientX)}px`;
1310
- ghost.style.top = `${state.hit.rect.y + (clientY - state.startClientY)}px`;
1311
- ghost.style.width = `${state.hit.rect.width}px`;
1405
+ ghost.style.left = `${left}px`;
1406
+ ghost.style.top = `${top}px`;
1407
+ ghost.style.width = `${ghostWidth}px`;
1312
1408
  },
1313
- [ghostRef]
1409
+ [ghostRef, rendererRef]
1314
1410
  );
1315
1411
  const styleGhost = useCallback(
1316
1412
  (event) => {
@@ -1403,9 +1499,20 @@ var useCanvasInteractions = ({
1403
1499
  mode: "pan",
1404
1500
  lastClientX: pointerEvent.clientX,
1405
1501
  lastClientY: pointerEvent.clientY,
1502
+ startClientX: pointerEvent.clientX,
1503
+ startClientY: pointerEvent.clientY,
1406
1504
  touch: isTouch
1407
1505
  };
1408
1506
  canvas.style.cursor = "grabbing";
1507
+ } else if (selectable && !hit) {
1508
+ stateRef.current = {
1509
+ mode: "pan",
1510
+ lastClientX: pointerEvent.clientX,
1511
+ lastClientY: pointerEvent.clientY,
1512
+ startClientX: pointerEvent.clientX,
1513
+ startClientY: pointerEvent.clientY,
1514
+ touch: isTouch
1515
+ };
1409
1516
  } else {
1410
1517
  return;
1411
1518
  }
@@ -1421,7 +1528,8 @@ var useCanvasInteractions = ({
1421
1528
  snapshotView,
1422
1529
  ghostRef,
1423
1530
  rendererRef,
1424
- styleGhost
1531
+ styleGhost,
1532
+ selectable
1425
1533
  ]
1426
1534
  );
1427
1535
  const handleHover = useCallback(
@@ -1479,9 +1587,31 @@ var useCanvasInteractions = ({
1479
1587
  onEventHover
1480
1588
  ]
1481
1589
  );
1590
+ const resolveRowAtClientY = useCallback(
1591
+ (clientY) => {
1592
+ const canvas = dynamicCanvasRef.current;
1593
+ const renderer = rendererRef.current;
1594
+ if (!canvas || !renderer) return null;
1595
+ const view = renderer.getView();
1596
+ if (view.tick === null) return null;
1597
+ const yContent = clientY - canvas.getBoundingClientRect().top + view.scrollTop;
1598
+ let rowTop = 0;
1599
+ for (const id of scene.getVisibleRowIds()) {
1600
+ const height = scene.getRowHeight(
1601
+ id,
1602
+ view.windowTime[0],
1603
+ view.windowTime[1]
1604
+ );
1605
+ if (yContent >= rowTop && yContent < rowTop + height) return id;
1606
+ rowTop += height;
1607
+ }
1608
+ return null;
1609
+ },
1610
+ [dynamicCanvasRef, rendererRef, scene]
1611
+ );
1482
1612
  const handlePointerMove = useCallback(
1483
1613
  (pointerEvent) => {
1484
- var _a, _b;
1614
+ var _a, _b, _c, _d;
1485
1615
  const tracked = pointersRef.current.get(pointerEvent.pointerId);
1486
1616
  if (tracked) {
1487
1617
  tracked.x = pointerEvent.clientX;
@@ -1525,17 +1655,25 @@ var useCanvasInteractions = ({
1525
1655
  return;
1526
1656
  }
1527
1657
  if (state.mode === "drag") {
1658
+ if ((_a = state.hit.event.props) == null ? void 0 : _a.isGroupParent) return;
1528
1659
  if (!state.active && Math.abs(pointerEvent.clientX - state.startClientX) + Math.abs(pointerEvent.clientY - state.startClientY) > DRAG_THRESHOLD_PX) {
1529
1660
  state.active = true;
1530
- (_a = rendererRef.current) == null ? void 0 : _a.setView({ draggedEventId: state.hit.event.id });
1661
+ (_b = rendererRef.current) == null ? void 0 : _b.setView({ draggedEventId: state.hit.event.id });
1531
1662
  }
1532
1663
  if (state.active) {
1533
1664
  updateGhost(state, pointerEvent.clientX, pointerEvent.clientY);
1665
+ const allowed = (_c = state.hit.event.props) == null ? void 0 : _c.droppableRowIds;
1666
+ if (allowed) {
1667
+ const row = resolveRowAtClientY(pointerEvent.clientY);
1668
+ const ok = row !== null && isRowDroppable(allowed, row);
1669
+ const canvas = dynamicCanvasRef.current;
1670
+ if (canvas) canvas.style.cursor = ok ? "grabbing" : "not-allowed";
1671
+ }
1534
1672
  }
1535
1673
  return;
1536
1674
  }
1537
1675
  state.deltaPx = pointerEvent.clientX - state.startClientX;
1538
- (_b = rendererRef.current) == null ? void 0 : _b.setView({
1676
+ (_d = rendererRef.current) == null ? void 0 : _d.setView({
1539
1677
  resizePreview: {
1540
1678
  eventId: state.event.id,
1541
1679
  deltaPx: state.deltaPx,
@@ -1549,35 +1687,28 @@ var useCanvasInteractions = ({
1549
1687
  updateGhost,
1550
1688
  rendererRef,
1551
1689
  scheduleContinuousZoom,
1552
- bodyRef
1690
+ bodyRef,
1691
+ resolveRowAtClientY,
1692
+ dynamicCanvasRef
1553
1693
  ]
1554
1694
  );
1555
1695
  const commitDrop = useCallback(
1556
1696
  (state, clientX, clientY) => {
1697
+ var _a;
1557
1698
  const canvas = dynamicCanvasRef.current;
1558
1699
  const renderer = rendererRef.current;
1559
1700
  if (!canvas || !renderer) return;
1560
1701
  const view = renderer.getView();
1561
1702
  if (view.tick === null || view.cellWidth <= 0) return;
1562
1703
  const canvasRect = canvas.getBoundingClientRect();
1563
- const yContent = clientY - canvasRect.top + view.scrollTop;
1564
- let rowTop = 0;
1565
- let targetRowId = null;
1566
- for (const id of scene.getRowIds()) {
1567
- const height = scene.getRowHeight(
1568
- id,
1569
- view.windowTime[0],
1570
- view.windowTime[1]
1571
- );
1572
- if (yContent >= rowTop && yContent < rowTop + height) {
1573
- targetRowId = id;
1574
- break;
1575
- }
1576
- rowTop += height;
1577
- }
1704
+ const targetRowId = resolveRowAtClientY(clientY);
1578
1705
  if (targetRowId === null) return;
1579
1706
  const liveEvent = scene.getEvent(state.hit.event.id);
1580
1707
  if (!liveEvent) return;
1708
+ if (!isRowDroppable((_a = liveEvent.props) == null ? void 0 : _a.droppableRowIds, targetRowId)) {
1709
+ renderer.animator.snapEventTop(liveEvent.id);
1710
+ return;
1711
+ }
1581
1712
  const { startTime, endTime } = computeDropTimes({
1582
1713
  pointerX: clientX - canvasRect.left,
1583
1714
  cellWidth: view.cellWidth,
@@ -1603,7 +1734,7 @@ var useCanvasInteractions = ({
1603
1734
  }
1604
1735
  ]);
1605
1736
  },
1606
- [scene, dynamicCanvasRef, rendererRef, onDrop]
1737
+ [scene, dynamicCanvasRef, rendererRef, onDrop, resolveRowAtClientY]
1607
1738
  );
1608
1739
  const commitResize = useCallback(
1609
1740
  (state) => {
@@ -1664,6 +1795,19 @@ var useCanvasInteractions = ({
1664
1795
  }
1665
1796
  });
1666
1797
  }
1798
+ if (selectable) {
1799
+ const id = state.hit.event.id;
1800
+ if (scene.isEventSelectable(id)) {
1801
+ applySelection(
1802
+ pointerEvent.ctrlKey || pointerEvent.metaKey ? scene.getConnectedEventIds(id) : [id]
1803
+ );
1804
+ }
1805
+ }
1806
+ } else if (state.mode === "pan") {
1807
+ const moved = Math.abs(pointerEvent.clientX - state.startClientX) + Math.abs(pointerEvent.clientY - state.startClientY) > DRAG_THRESHOLD_PX;
1808
+ if (selectable && !moved && getSelection().length > 0) {
1809
+ applySelection([]);
1810
+ }
1667
1811
  } else if (state.mode === "resize") {
1668
1812
  commitResize(state);
1669
1813
  }
@@ -1674,7 +1818,11 @@ var useCanvasInteractions = ({
1674
1818
  rendererRef,
1675
1819
  commitDrop,
1676
1820
  commitResize,
1677
- onEventClick
1821
+ onEventClick,
1822
+ selectable,
1823
+ applySelection,
1824
+ getSelection,
1825
+ scene
1678
1826
  ]
1679
1827
  );
1680
1828
  const handlePointerCancel = useCallback(
@@ -1756,6 +1904,16 @@ var useCanvasInteractions = ({
1756
1904
  return () => canvas.removeEventListener("wheel", handleWheel);
1757
1905
  }, [dynamicCanvasRef, rendererRef, setCellWidth, applyZoom, config]);
1758
1906
  useEffect4(() => unlockCursor, []);
1907
+ useEffect4(() => {
1908
+ if (!selectable) return;
1909
+ const handleKeyDown = (keyEvent) => {
1910
+ if (keyEvent.key === "Escape" && getSelection().length > 0) {
1911
+ applySelection([]);
1912
+ }
1913
+ };
1914
+ window.addEventListener("keydown", handleKeyDown);
1915
+ return () => window.removeEventListener("keydown", handleKeyDown);
1916
+ }, [selectable, getSelection, applySelection]);
1759
1917
  return {
1760
1918
  handlePointerDown,
1761
1919
  handlePointerMove,
@@ -1790,11 +1948,16 @@ var CanvasBoard = forwardRef2(
1790
1948
  onEventHover,
1791
1949
  eventsResize,
1792
1950
  panZoom,
1793
- animations
1951
+ animations,
1952
+ selectable,
1953
+ applySelection,
1954
+ getSelection
1794
1955
  }, contentRef) => {
1795
1956
  const staticCanvasRef = useRef6(null);
1796
1957
  const dynamicCanvasRef = useRef6(null);
1797
1958
  const ghostRef = useRef6(null);
1959
+ const headerWrapperRef = useRef6(null);
1960
+ const totalHeightRef = useRef6(0);
1798
1961
  const [scrollTop, setScrollTop] = useState3(0);
1799
1962
  const [viewportHeight, setViewportHeight] = useState3(0);
1800
1963
  useEffect5(() => {
@@ -1834,25 +1997,29 @@ var CanvasBoard = forwardRef2(
1834
1997
  animations,
1835
1998
  rendererRef
1836
1999
  ]);
2000
+ const measureViewport = useCallback2(() => {
2001
+ var _a;
2002
+ const column = contentRef && "current" in contentRef ? contentRef.current : null;
2003
+ const body = bodyRef.current;
2004
+ if (!column || !body) return;
2005
+ const cap = totalHeightRef.current > 0 ? totalHeightRef.current : Infinity;
2006
+ const height = Math.min(body.clientHeight, cap, window.innerHeight);
2007
+ setViewportHeight(height);
2008
+ (_a = rendererRef.current) == null ? void 0 : _a.setView({
2009
+ width: column.getBoundingClientRect().width,
2010
+ height
2011
+ });
2012
+ }, [bodyRef, contentRef, rendererRef]);
1837
2013
  useEffect5(() => {
1838
2014
  const column = contentRef && "current" in contentRef ? contentRef.current : null;
1839
2015
  const body = bodyRef.current;
1840
2016
  if (!column || !body) return;
1841
- const measure = () => {
1842
- var _a;
1843
- const height = Math.min(body.clientHeight, window.innerHeight);
1844
- setViewportHeight(height);
1845
- (_a = rendererRef.current) == null ? void 0 : _a.setView({
1846
- width: column.getBoundingClientRect().width,
1847
- height
1848
- });
1849
- };
1850
- measure();
1851
- const observer = new ResizeObserver(measure);
2017
+ measureViewport();
2018
+ const observer = new ResizeObserver(measureViewport);
1852
2019
  observer.observe(column);
1853
2020
  observer.observe(body);
1854
2021
  return () => observer.disconnect();
1855
- }, [bodyRef, contentRef, rendererRef]);
2022
+ }, [bodyRef, contentRef, measureViewport]);
1856
2023
  useEffect5(() => {
1857
2024
  const body = bodyRef.current;
1858
2025
  if (!body) return;
@@ -1868,6 +2035,43 @@ var CanvasBoard = forwardRef2(
1868
2035
  useCallback2((listener) => scene.subscribe(listener), [scene]),
1869
2036
  () => scene.version
1870
2037
  );
2038
+ useLayoutEffect(() => {
2039
+ const wrapper = headerWrapperRef.current;
2040
+ if (!wrapper) return;
2041
+ const measurer = document.createElement("div");
2042
+ measurer.className = "row-header-label";
2043
+ measurer.setAttribute("aria-hidden", "true");
2044
+ measurer.style.position = "absolute";
2045
+ measurer.style.left = "-9999px";
2046
+ measurer.style.top = "0";
2047
+ measurer.style.visibility = "hidden";
2048
+ measurer.style.height = "auto";
2049
+ wrapper.appendChild(measurer);
2050
+ let lastWidth = -1;
2051
+ const measure = () => {
2052
+ var _a;
2053
+ const width = wrapper.clientWidth;
2054
+ if (width === 0 || width === lastWidth) return;
2055
+ lastWidth = width;
2056
+ measurer.style.width = `${width}px`;
2057
+ const heights = /* @__PURE__ */ new Map();
2058
+ for (const row of rows) {
2059
+ measurer.textContent = (_a = row.name) != null ? _a : "";
2060
+ heights.set(
2061
+ row.id,
2062
+ Math.ceil(measurer.offsetHeight) + 2 * theme.rowPaddingY
2063
+ );
2064
+ }
2065
+ scene.setLabelMinHeights(heights);
2066
+ };
2067
+ measure();
2068
+ const observer = new ResizeObserver(measure);
2069
+ observer.observe(wrapper);
2070
+ return () => {
2071
+ observer.disconnect();
2072
+ wrapper.removeChild(measurer);
2073
+ };
2074
+ }, [rows, scene, theme.rowPaddingY, rowsHeaderClassName]);
1871
2075
  const {
1872
2076
  handlePointerDown,
1873
2077
  handlePointerMove,
@@ -1890,19 +2094,46 @@ var CanvasBoard = forwardRef2(
1890
2094
  onEventClick,
1891
2095
  onEventHover,
1892
2096
  eventsResize,
1893
- panZoom
2097
+ panZoom,
2098
+ selectable,
2099
+ applySelection,
2100
+ getSelection
1894
2101
  });
2102
+ useEffect5(() => {
2103
+ var _a;
2104
+ (_a = rendererRef.current) == null ? void 0 : _a.setView({
2105
+ selectedEventIds: new Set(getSelection())
2106
+ });
2107
+ }, [getSelection, rendererRef]);
1895
2108
  const { offsetOf, totalHeight } = scene.getRowOffsets(
1896
2109
  windowTime[0],
1897
2110
  windowTime[1]
1898
2111
  );
2112
+ totalHeightRef.current = totalHeight;
2113
+ useLayoutEffect(() => {
2114
+ measureViewport();
2115
+ }, [totalHeight, measureViewport]);
2116
+ const lastChildOf = /* @__PURE__ */ new Map();
2117
+ for (const row of rows) {
2118
+ if (row.parentId !== void 0) lastChildOf.set(row.parentId, row.id);
2119
+ }
2120
+ const connectorColor = theme.gridColor;
2121
+ const SPINE_X = 11;
1899
2122
  const visibleHeaders = [];
1900
2123
  for (let i = 0; i < rows.length; i++) {
1901
2124
  const row = rows[i];
2125
+ if (scene.isRowHidden(row.id)) continue;
1902
2126
  const top = offsetOf.get(row.id);
2127
+ if (top === void 0) continue;
1903
2128
  const height = scene.getRowHeight(row.id, windowTime[0], windowTime[1]);
1904
2129
  if (top + height < scrollTop) continue;
1905
2130
  if (top > scrollTop + viewportHeight) break;
2131
+ const isParent = scene.isRowParent(row.id);
2132
+ const parentId = row.parentId;
2133
+ const isChild = parentId !== void 0;
2134
+ const isLastChild = parentId !== void 0 && lastChildOf.get(parentId) === row.id;
2135
+ const collapsed = scene.isRowCollapsed(row.id);
2136
+ const grouped = isParent || isChild;
1906
2137
  visibleHeaders.push(
1907
2138
  /* @__PURE__ */ React5.createElement(
1908
2139
  "div",
@@ -1913,16 +2144,79 @@ var CanvasBoard = forwardRef2(
1913
2144
  top,
1914
2145
  height,
1915
2146
  borderBottom: i === rows.length - 1 ? "none" : "1px solid yellow",
1916
- // keeps the DOM header in step with the canvas layout tween
1917
- transition: animations.layoutMs > 0 ? `top ${animations.layoutMs}ms ease-in-out, height ${animations.layoutMs}ms ease-in-out` : "none"
2147
+ // Row heights/positions apply instantly (no layout tween) so the
2148
+ // header snaps in lockstep with its canvas row — see draw-events.
2149
+ // Grouped rows left-align so the caret + tree spine line up; plain
2150
+ // rows keep the centered default.
2151
+ justifyContent: grouped ? "flex-start" : void 0,
2152
+ paddingLeft: isChild ? 24 : isParent ? 6 : void 0
1918
2153
  }
1919
2154
  },
1920
- row.name
2155
+ isChild && // tree connector: a vertical spine + a horizontal tick at the row's
2156
+ // vertical center. The spine runs the full height for a mid child
2157
+ // (├─) and stops at the center for the last child (└─), so stacked
2158
+ // children form one continuous spine descending from the parent.
2159
+ /* @__PURE__ */ React5.createElement(React5.Fragment, null, /* @__PURE__ */ React5.createElement(
2160
+ "span",
2161
+ {
2162
+ "aria-hidden": true,
2163
+ style: {
2164
+ position: "absolute",
2165
+ left: SPINE_X,
2166
+ top: 0,
2167
+ width: 1,
2168
+ height: isLastChild ? "50%" : "100%",
2169
+ backgroundColor: connectorColor,
2170
+ pointerEvents: "none"
2171
+ }
2172
+ }
2173
+ ), /* @__PURE__ */ React5.createElement(
2174
+ "span",
2175
+ {
2176
+ "aria-hidden": true,
2177
+ style: {
2178
+ position: "absolute",
2179
+ left: SPINE_X,
2180
+ top: "50%",
2181
+ width: 9,
2182
+ height: 1,
2183
+ backgroundColor: connectorColor,
2184
+ pointerEvents: "none"
2185
+ }
2186
+ }
2187
+ )),
2188
+ isParent && /* @__PURE__ */ React5.createElement(
2189
+ "span",
2190
+ {
2191
+ className: "row-header-caret",
2192
+ role: "button",
2193
+ "aria-label": collapsed ? "Expand group" : "Collapse group",
2194
+ onClick: () => scene.toggleCollapsed(row.id),
2195
+ style: { cursor: "pointer", marginRight: 4, userSelect: "none" }
2196
+ },
2197
+ collapsed ? "\u25B8" : "\u25BE"
2198
+ ),
2199
+ /* @__PURE__ */ React5.createElement(
2200
+ "span",
2201
+ {
2202
+ className: "row-header-label",
2203
+ style: grouped ? { textAlign: "left" } : void 0
2204
+ },
2205
+ row.name
2206
+ )
1921
2207
  )
1922
2208
  );
1923
2209
  }
1924
2210
  const headerClassNames = rowsHeaderClassName ? `rows-header-wrapper canvas-rows-header ${rowsHeaderClassName}` : "rows-header-wrapper canvas-rows-header";
1925
- return /* @__PURE__ */ React5.createElement(React5.Fragment, null, /* @__PURE__ */ React5.createElement("div", { className: headerClassNames, style: { height: totalHeight } }, visibleHeaders), /* @__PURE__ */ React5.createElement("div", { className: "canvas-content-column", ref: contentRef }, /* @__PURE__ */ React5.createElement("div", { className: "canvas-sticky" }, /* @__PURE__ */ React5.createElement("canvas", { ref: staticCanvasRef }), /* @__PURE__ */ React5.createElement(
2211
+ return /* @__PURE__ */ React5.createElement(React5.Fragment, null, /* @__PURE__ */ React5.createElement(
2212
+ "div",
2213
+ {
2214
+ ref: headerWrapperRef,
2215
+ className: headerClassNames,
2216
+ style: { height: totalHeight }
2217
+ },
2218
+ visibleHeaders
2219
+ ), /* @__PURE__ */ React5.createElement("div", { className: "canvas-content-column", ref: contentRef }, /* @__PURE__ */ React5.createElement("div", { className: "canvas-sticky" }, /* @__PURE__ */ React5.createElement("canvas", { ref: staticCanvasRef }), /* @__PURE__ */ React5.createElement(
1926
2220
  "canvas",
1927
2221
  {
1928
2222
  ref: dynamicCanvasRef,
@@ -1970,11 +2264,39 @@ var SceneStore = class {
1970
2264
  this.rowIndexes = /* @__PURE__ */ new Map();
1971
2265
  this.rowOrder = [];
1972
2266
  this.eventRow = /* @__PURE__ */ new Map();
2267
+ // Group index for tag-based "connected" selection. eventGroup: eventId ->
2268
+ // groupId; groupMembers: groupId -> set of eventIds. Maintained alongside
2269
+ // eventRow so Cmd/Ctrl+click resolves the whole group in O(group size)
2270
+ // without scanning all rows.
2271
+ this.eventGroup = /* @__PURE__ */ new Map();
2272
+ this.groupMembers = /* @__PURE__ */ new Map();
2273
+ // Row hierarchy for grouped (collapsible) rows. parentOf: childRowId ->
2274
+ // parentRowId; childRowsOf: parentRowId -> ordered child row ids. Rebuilt in
2275
+ // setRows from `row.parentId`. One level of nesting only in v1.
2276
+ this.parentOf = /* @__PURE__ */ new Map();
2277
+ this.childRowsOf = /* @__PURE__ */ new Map();
2278
+ // Rows the user has collapsed. Lives only here so it survives every data
2279
+ // update (setEvents / applyPatches / events-prop reset); setRows only prunes
2280
+ // entries for rows that no longer exist.
2281
+ this.collapsedRows = /* @__PURE__ */ new Set();
2282
+ // Parent↔child EVENT index (distinct from the row hierarchy above).
2283
+ // childrenOf: parentEventId -> child event ids; parentEventOf: childEventId ->
2284
+ // parentEventId. Driven by props.parentEventId / props.isGroupParent. A parent
2285
+ // event's [startTime,endTime] is derived lazily from its children; any child
2286
+ // mutation marks the parent dirty and the span is recomputed on the next query
2287
+ // of the parent's row (flushParentSpans) — off-screen groups cost nothing.
2288
+ this.childrenOf = /* @__PURE__ */ new Map();
2289
+ this.parentEventOf = /* @__PURE__ */ new Map();
2290
+ this.parentSpanDirty = /* @__PURE__ */ new Set();
1973
2291
  this.listeners = /* @__PURE__ */ new Set();
1974
2292
  // Themeable vertical layout. Lanes are geometry-free (pure time logic), so a
1975
2293
  // geometry change only affects heights/offsets — the cached lanes stay valid
1976
2294
  // and we just bump to trigger a redraw.
1977
2295
  this.geometry = DEFAULT_GEOMETRY;
2296
+ // Per-row minimum height demanded by the (DOM-measured) row label when it
2297
+ // wraps to multiple lines. Measured in the shell and fed back here so the
2298
+ // canvas grid/dividers, hit-testing and the DOM header all agree on height.
2299
+ this.labelMinHeights = /* @__PURE__ */ new Map();
1978
2300
  this.version = 0;
1979
2301
  }
1980
2302
  setGeometry(geometry) {
@@ -2002,23 +2324,53 @@ var SceneStore = class {
2002
2324
  );
2003
2325
  }
2004
2326
  for (const [id, rowId] of this.eventRow) {
2005
- if (!next.has(rowId)) this.eventRow.delete(id);
2327
+ if (!next.has(rowId)) {
2328
+ this.eventRow.delete(id);
2329
+ this.removeFromGroup(id);
2330
+ }
2006
2331
  }
2007
2332
  this.rowIndexes = next;
2008
2333
  this.rowOrder = rows.map((row) => row.id);
2334
+ this.parentOf = /* @__PURE__ */ new Map();
2335
+ this.childRowsOf = /* @__PURE__ */ new Map();
2336
+ for (const row of rows) {
2337
+ if (row.parentId === void 0) continue;
2338
+ this.parentOf.set(row.id, row.parentId);
2339
+ let children = this.childRowsOf.get(row.parentId);
2340
+ if (!children) {
2341
+ children = [];
2342
+ this.childRowsOf.set(row.parentId, children);
2343
+ }
2344
+ children.push(row.id);
2345
+ }
2346
+ if (this.collapsedRows.size > 0) {
2347
+ const rowIds = new Set(this.rowOrder);
2348
+ for (const id of [...this.collapsedRows]) {
2349
+ if (!rowIds.has(id)) this.collapsedRows.delete(id);
2350
+ }
2351
+ }
2009
2352
  this.bump();
2010
2353
  }
2011
2354
  setEvents(events) {
2355
+ var _a;
2012
2356
  for (const index of this.rowIndexes.values()) {
2013
2357
  index.events = [];
2014
2358
  index.lanesDirty = true;
2015
2359
  }
2016
2360
  this.eventRow.clear();
2361
+ this.eventGroup.clear();
2362
+ this.groupMembers.clear();
2363
+ this.childrenOf.clear();
2364
+ this.parentEventOf.clear();
2365
+ this.parentSpanDirty.clear();
2017
2366
  for (const event of events) {
2018
2367
  const index = this.rowIndexes.get(event.rowId);
2019
2368
  if (!index) continue;
2020
2369
  index.events.push(event);
2021
2370
  this.eventRow.set(event.id, event.rowId);
2371
+ this.addToGroup(event.id, (_a = event.props) == null ? void 0 : _a.groupId);
2372
+ this.addToParentIndex(event);
2373
+ this.validateDroppable(event);
2022
2374
  }
2023
2375
  for (const index of this.rowIndexes.values()) {
2024
2376
  index.events.sort(sort_events_default);
@@ -2061,15 +2413,88 @@ var SceneStore = class {
2061
2413
  if (rowId === void 0) return void 0;
2062
2414
  return (_a = this.rowIndexes.get(rowId)) == null ? void 0 : _a.events.find((event) => event.id === id);
2063
2415
  }
2416
+ /**
2417
+ * Event ids "connected" to the given event via a shared `props.groupId`.
2418
+ * Returns every member of the group (including the event itself), or just
2419
+ * `[eventId]` when the event has no group / no other members / is unknown.
2420
+ */
2421
+ getConnectedEventIds(eventId) {
2422
+ const groupId = this.eventGroup.get(eventId);
2423
+ if (groupId === void 0) return [eventId];
2424
+ const members = this.groupMembers.get(groupId);
2425
+ if (!members || members.size === 0) return [eventId];
2426
+ return [...members];
2427
+ }
2428
+ /**
2429
+ * Whether an event may enter the selection. False only when the event is
2430
+ * present and explicitly opted out (`props.isSelectable === false`); unknown
2431
+ * ids are treated as selectable so a selection can be set before data loads
2432
+ * and survives streaming.
2433
+ */
2434
+ isEventSelectable(id) {
2435
+ var _a;
2436
+ const event = this.getEvent(id);
2437
+ return event === void 0 || ((_a = event.props) == null ? void 0 : _a.isSelectable) !== false;
2438
+ }
2064
2439
  getRowIds() {
2065
2440
  return this.rowOrder;
2066
2441
  }
2442
+ /**
2443
+ * Row ids in display order, minus rows hidden inside a collapsed parent.
2444
+ * Drives offsets, drawing and hit-testing. The header still walks
2445
+ * `getRowIds()` so it can draw the carets and decide which rows to skip.
2446
+ */
2447
+ getVisibleRowIds() {
2448
+ if (this.collapsedRows.size === 0) return this.rowOrder;
2449
+ const visible = [];
2450
+ for (const rowId of this.rowOrder) {
2451
+ const parent = this.parentOf.get(rowId);
2452
+ if (parent !== void 0 && this.collapsedRows.has(parent)) continue;
2453
+ visible.push(rowId);
2454
+ }
2455
+ return visible;
2456
+ }
2457
+ /** whether a row is a parent (owns at least one child row) */
2458
+ isRowParent(rowId) {
2459
+ var _a, _b;
2460
+ return ((_b = (_a = this.childRowsOf.get(rowId)) == null ? void 0 : _a.length) != null ? _b : 0) > 0;
2461
+ }
2462
+ /** whether a row is hidden because its parent row is collapsed */
2463
+ isRowHidden(rowId) {
2464
+ const parent = this.parentOf.get(rowId);
2465
+ return parent !== void 0 && this.collapsedRows.has(parent);
2466
+ }
2467
+ isRowCollapsed(rowId) {
2468
+ return this.collapsedRows.has(rowId);
2469
+ }
2470
+ getCollapsedRowIds() {
2471
+ return [...this.collapsedRows];
2472
+ }
2473
+ setCollapsed(rowId, collapsed) {
2474
+ const has = this.collapsedRows.has(rowId);
2475
+ if (collapsed && !has) {
2476
+ this.collapsedRows.add(rowId);
2477
+ this.bump();
2478
+ } else if (!collapsed && has) {
2479
+ this.collapsedRows.delete(rowId);
2480
+ this.bump();
2481
+ }
2482
+ }
2483
+ toggleCollapsed(rowId) {
2484
+ this.setCollapsed(rowId, !this.collapsedRows.has(rowId));
2485
+ }
2486
+ /** child event ids of a parent (summary) event; empty if it has none */
2487
+ getChildEventIds(parentEventId) {
2488
+ const children = this.childrenOf.get(parentEventId);
2489
+ return children ? [...children] : [];
2490
+ }
2067
2491
  getRow(rowId) {
2068
2492
  var _a;
2069
2493
  return (_a = this.rowIndexes.get(rowId)) == null ? void 0 : _a.row;
2070
2494
  }
2071
2495
  getRowEvents(rowId) {
2072
2496
  var _a, _b;
2497
+ this.flushParentSpans(rowId);
2073
2498
  return (_b = (_a = this.rowIndexes.get(rowId)) == null ? void 0 : _a.events) != null ? _b : [];
2074
2499
  }
2075
2500
  getRowStaticEvents(rowId) {
@@ -2077,6 +2502,7 @@ var SceneStore = class {
2077
2502
  return (_b = (_a = this.rowIndexes.get(rowId)) == null ? void 0 : _a.staticEvents) != null ? _b : [];
2078
2503
  }
2079
2504
  getLanes(rowId, windowStart, windowEnd) {
2505
+ this.flushParentSpans(rowId);
2080
2506
  const index = this.rowIndexes.get(rowId);
2081
2507
  if (!index) return { laneOf: /* @__PURE__ */ new Map(), highestLane: 0 };
2082
2508
  if (index.lanesDirty || index.lanes === null || index.laneWindowStart !== windowStart || index.laneWindowEnd !== windowEnd) {
@@ -2087,11 +2513,35 @@ var SceneStore = class {
2087
2513
  }
2088
2514
  return index.lanes;
2089
2515
  }
2516
+ /**
2517
+ * Report the per-row label heights measured against the live DOM header
2518
+ * (key: rowId, value: the minimum row height the wrapped label needs,
2519
+ * already including vertical padding). Replaces the previous map wholesale
2520
+ * and only bumps when a value actually changed, so re-measuring identical
2521
+ * labels is a no-op and can't feed back into an infinite render loop.
2522
+ */
2523
+ setLabelMinHeights(heights) {
2524
+ let changed = heights.size !== this.labelMinHeights.size;
2525
+ if (!changed) {
2526
+ for (const [id, h] of heights) {
2527
+ if (this.labelMinHeights.get(id) !== h) {
2528
+ changed = true;
2529
+ break;
2530
+ }
2531
+ }
2532
+ }
2533
+ if (!changed) return;
2534
+ this.labelMinHeights = heights;
2535
+ this.bump();
2536
+ }
2090
2537
  getRowHeight(rowId, windowStart, windowEnd) {
2091
- return rowMinHeight(
2538
+ var _a;
2539
+ const laneHeight = rowMinHeight(
2092
2540
  this.getLanes(rowId, windowStart, windowEnd).highestLane,
2093
2541
  this.geometry
2094
2542
  );
2543
+ const labelHeight = (_a = this.labelMinHeights.get(rowId)) != null ? _a : 0;
2544
+ return Math.max(laneHeight, labelHeight);
2095
2545
  }
2096
2546
  /**
2097
2547
  * y offset of each row's top edge (content coordinates, before scroll) plus
@@ -2100,7 +2550,7 @@ var SceneStore = class {
2100
2550
  getRowOffsets(windowStart, windowEnd) {
2101
2551
  const offsetOf = /* @__PURE__ */ new Map();
2102
2552
  let y = 0;
2103
- for (const rowId of this.rowOrder) {
2553
+ for (const rowId of this.getVisibleRowIds()) {
2104
2554
  offsetOf.set(rowId, y);
2105
2555
  y += this.getRowHeight(rowId, windowStart, windowEnd);
2106
2556
  }
@@ -2111,11 +2561,15 @@ var SceneStore = class {
2111
2561
  return () => this.listeners.delete(listener);
2112
2562
  }
2113
2563
  insert(event) {
2564
+ var _a;
2114
2565
  const index = this.rowIndexes.get(event.rowId);
2115
2566
  if (!index) return;
2116
2567
  index.events.splice(binaryInsertIndex(index.events, event), 0, event);
2117
2568
  index.lanesDirty = true;
2118
2569
  this.eventRow.set(event.id, event.rowId);
2570
+ this.addToGroup(event.id, (_a = event.props) == null ? void 0 : _a.groupId);
2571
+ this.addToParentIndex(event);
2572
+ this.validateDroppable(event);
2119
2573
  }
2120
2574
  remove(id) {
2121
2575
  const rowId = this.eventRow.get(id);
@@ -2127,6 +2581,117 @@ var SceneStore = class {
2127
2581
  index.lanesDirty = true;
2128
2582
  }
2129
2583
  this.eventRow.delete(id);
2584
+ this.removeFromGroup(id);
2585
+ this.removeFromParentIndex(id);
2586
+ }
2587
+ addToGroup(eventId, groupId) {
2588
+ if (groupId === void 0) return;
2589
+ this.eventGroup.set(eventId, groupId);
2590
+ let members = this.groupMembers.get(groupId);
2591
+ if (!members) {
2592
+ members = /* @__PURE__ */ new Set();
2593
+ this.groupMembers.set(groupId, members);
2594
+ }
2595
+ members.add(eventId);
2596
+ }
2597
+ removeFromGroup(eventId) {
2598
+ const groupId = this.eventGroup.get(eventId);
2599
+ if (groupId === void 0) return;
2600
+ this.eventGroup.delete(eventId);
2601
+ const members = this.groupMembers.get(groupId);
2602
+ if (members) {
2603
+ members.delete(eventId);
2604
+ if (members.size === 0) this.groupMembers.delete(groupId);
2605
+ }
2606
+ }
2607
+ /**
2608
+ * Enforce the authoring contract for `props.droppableRowIds`: if the event's
2609
+ * current row is not among its allowed rows, record a `droppableError` on
2610
+ * `props.metadata` (merged non-destructively); otherwise clear any stale one.
2611
+ * Cheap no-op for events without `droppableRowIds` and no prior error.
2612
+ */
2613
+ validateDroppable(event) {
2614
+ var _a, _b;
2615
+ const allowed = (_a = event.props) == null ? void 0 : _a.droppableRowIds;
2616
+ const meta = (_b = event.props) == null ? void 0 : _b.metadata;
2617
+ const metaObj = typeof meta === "object" && meta !== null ? meta : void 0;
2618
+ const hadError = metaObj !== void 0 && "droppableError" in metaObj;
2619
+ const needsError = allowed !== void 0 && !allowed.includes(event.rowId);
2620
+ if (!needsError && !hadError) return;
2621
+ if (!event.props) return;
2622
+ if (needsError) {
2623
+ event.props.metadata = __spreadProps(__spreadValues({}, metaObj != null ? metaObj : {}), {
2624
+ droppableError: {
2625
+ rowId: event.rowId,
2626
+ droppableRowIds: allowed
2627
+ }
2628
+ });
2629
+ } else {
2630
+ const rest = __spreadValues({}, metaObj);
2631
+ delete rest.droppableError;
2632
+ event.props.metadata = Object.keys(rest).length > 0 ? rest : void 0;
2633
+ }
2634
+ }
2635
+ addToParentIndex(event) {
2636
+ var _a;
2637
+ const parentId = (_a = event.props) == null ? void 0 : _a.parentEventId;
2638
+ if (parentId === void 0) return;
2639
+ this.parentEventOf.set(event.id, parentId);
2640
+ let children = this.childrenOf.get(parentId);
2641
+ if (!children) {
2642
+ children = /* @__PURE__ */ new Set();
2643
+ this.childrenOf.set(parentId, children);
2644
+ }
2645
+ children.add(event.id);
2646
+ this.parentSpanDirty.add(parentId);
2647
+ }
2648
+ removeFromParentIndex(eventId) {
2649
+ const parentId = this.parentEventOf.get(eventId);
2650
+ if (parentId === void 0) return;
2651
+ this.parentEventOf.delete(eventId);
2652
+ const children = this.childrenOf.get(parentId);
2653
+ if (children) {
2654
+ children.delete(eventId);
2655
+ if (children.size === 0) this.childrenOf.delete(parentId);
2656
+ }
2657
+ this.parentSpanDirty.add(parentId);
2658
+ }
2659
+ /**
2660
+ * Recompute the derived span of any dirty parent event living on `rowId`
2661
+ * (earliest child start → latest child end), write it back into the parent
2662
+ * event, and re-sort the row so the sorted-array invariant holds. Cheap no-op
2663
+ * when nothing is dirty (the common no-groups case never touches this).
2664
+ */
2665
+ flushParentSpans(rowId) {
2666
+ var _a;
2667
+ if (this.parentSpanDirty.size === 0) return;
2668
+ const index = this.rowIndexes.get(rowId);
2669
+ if (!index) return;
2670
+ let changed = false;
2671
+ for (const event of index.events) {
2672
+ if (!((_a = event.props) == null ? void 0 : _a.isGroupParent)) continue;
2673
+ if (!this.parentSpanDirty.has(event.id)) continue;
2674
+ this.parentSpanDirty.delete(event.id);
2675
+ const children = this.childrenOf.get(event.id);
2676
+ if (!children || children.size === 0) continue;
2677
+ let minStart = Infinity;
2678
+ let maxEnd = -Infinity;
2679
+ for (const childId of children) {
2680
+ const child = this.getEvent(childId);
2681
+ if (!child) continue;
2682
+ if (child.startTime < minStart) minStart = child.startTime;
2683
+ if (child.endTime > maxEnd) maxEnd = child.endTime;
2684
+ }
2685
+ if (minStart !== Infinity && (event.startTime !== minStart || event.endTime !== maxEnd)) {
2686
+ event.startTime = minStart;
2687
+ event.endTime = maxEnd;
2688
+ changed = true;
2689
+ }
2690
+ }
2691
+ if (changed) {
2692
+ index.events.sort(sort_events_default);
2693
+ index.lanesDirty = true;
2694
+ }
2130
2695
  }
2131
2696
  bump() {
2132
2697
  this.version++;
@@ -2144,6 +2709,10 @@ var Timeline = forwardRef3(
2144
2709
  onResize,
2145
2710
  onEventClick,
2146
2711
  onEventHover,
2712
+ selectable = false,
2713
+ defaultSelectedEventIds,
2714
+ onSelectionChange,
2715
+ defaultCollapsedRowIds,
2147
2716
  startDate,
2148
2717
  endDate,
2149
2718
  theme,
@@ -2188,15 +2757,53 @@ var Timeline = forwardRef3(
2188
2757
  sceneRef.current = new SceneStore();
2189
2758
  }
2190
2759
  const scene = sceneRef.current;
2760
+ const selectionRef = useRef7(
2761
+ new Set(defaultSelectedEventIds != null ? defaultSelectedEventIds : [])
2762
+ );
2763
+ const onSelectionChangeRef = useRef7(onSelectionChange);
2764
+ onSelectionChangeRef.current = onSelectionChange;
2765
+ const applySelection = useCallback3(
2766
+ (ids) => {
2767
+ var _a, _b;
2768
+ const expanded = [];
2769
+ for (const id of ids) {
2770
+ expanded.push(id);
2771
+ for (const childId of scene.getChildEventIds(id)) {
2772
+ expanded.push(childId);
2773
+ }
2774
+ }
2775
+ selectionRef.current = new Set(
2776
+ expanded.filter((id) => scene.isEventSelectable(id))
2777
+ );
2778
+ (_a = rendererRef.current) == null ? void 0 : _a.setView({
2779
+ selectedEventIds: selectionRef.current
2780
+ });
2781
+ (_b = onSelectionChangeRef.current) == null ? void 0 : _b.call(onSelectionChangeRef, [...selectionRef.current]);
2782
+ },
2783
+ [scene]
2784
+ );
2785
+ const getSelection = useCallback3(() => [...selectionRef.current], []);
2191
2786
  useEffect6(() => {
2787
+ var _a;
2192
2788
  scene.setRows(rows);
2789
+ (_a = rendererRef.current) == null ? void 0 : _a.animator.reset();
2193
2790
  }, [scene, rows]);
2194
2791
  useEffect6(() => {
2792
+ var _a;
2195
2793
  scene.setEvents([...events].sort(sort_events_default));
2794
+ (_a = rendererRef.current) == null ? void 0 : _a.animator.reset();
2196
2795
  }, [scene, events]);
2197
2796
  useEffect6(() => {
2198
2797
  scene.setStaticEvents(staticEvents ? [...staticEvents] : []);
2199
2798
  }, [scene, staticEvents]);
2799
+ const seededCollapseRef = useRef7(false);
2800
+ useEffect6(() => {
2801
+ if (seededCollapseRef.current) return;
2802
+ seededCollapseRef.current = true;
2803
+ for (const id of defaultCollapsedRowIds != null ? defaultCollapsedRowIds : []) {
2804
+ scene.setCollapsed(id, true);
2805
+ }
2806
+ }, [scene, defaultCollapsedRowIds]);
2200
2807
  const windowTimeRef = useRef7(windowTime);
2201
2808
  windowTimeRef.current = windowTime;
2202
2809
  useImperativeHandle2(
@@ -2220,12 +2827,16 @@ var Timeline = forwardRef3(
2220
2827
  startTime: windowTimeRef.current[0],
2221
2828
  endTime: windowTimeRef.current[1]
2222
2829
  }),
2830
+ setSelection: (ids) => applySelection(ids),
2831
+ getSelection,
2832
+ toggleRow: (rowId) => scene.toggleCollapsed(rowId),
2833
+ setCollapsed: (rowId, collapsed) => scene.setCollapsed(rowId, collapsed),
2223
2834
  redraw: () => {
2224
2835
  var _a;
2225
2836
  return (_a = rendererRef.current) == null ? void 0 : _a.invalidate("all");
2226
2837
  }
2227
2838
  }),
2228
- [scene]
2839
+ [scene, applySelection, getSelection]
2229
2840
  );
2230
2841
  useEffect6(() => {
2231
2842
  if (contentRef.current) {
@@ -2313,6 +2924,9 @@ var Timeline = forwardRef3(
2313
2924
  eventsResize,
2314
2925
  panZoom,
2315
2926
  animations: resolvedAnimations,
2927
+ selectable,
2928
+ applySelection,
2929
+ getSelection,
2316
2930
  ref: contentRef
2317
2931
  }
2318
2932
  ), showEventPrompt && eventPrompt));