awesome-timeline-react 0.14.0 → 0.15.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/README.md CHANGED
@@ -163,7 +163,11 @@ Set `selectable` to enable click selection. A selected event is **elevated**
163
163
  - **Click** an event → selects just that event.
164
164
  - **Cmd/Ctrl + click** → selects the whole *connected group*: every event
165
165
  sharing the clicked event's `props.groupId`. (An event with no `groupId`
166
- selects only itself.)
166
+ selects only itself.) On a Mac, Ctrl+click on an event selects too instead of
167
+ opening the browser's context menu.
168
+ - **Shift + click** → adds the event to the selection, or takes it out if it is
169
+ already in, across groups. **Shift + Cmd/Ctrl + click** does the same for the
170
+ whole group: added if any of it is missing, taken out if all of it is in.
167
171
  - **Background click** or **Escape** → clears the selection.
168
172
 
169
173
  Individual events can opt out with `props.isSelectable = false`: they can't be
@@ -174,7 +174,8 @@ export declare const default_alias_2: ({ windowTime, tick, contentWidth, scrollW
174
174
  * Hover tooltip for events. Positioned with @floating-ui/dom against the
175
175
  * hovered event's rect (viewport coordinates): preferred above the event,
176
176
  * flips below when there is no room, and shifts horizontally to stay
177
- * on-screen.
177
+ * on-screen. Placed only once the hovered event's template has rendered, so
178
+ * it is measured at its own size, not the previous event's.
178
179
  */
179
180
  export declare const default_alias_3: React_2.ForwardRefExoticComponent<EventPromptType & React_2.RefAttributes<EventPromptActionsType>>;
180
181
 
@@ -212,6 +213,7 @@ export declare const default_alias_9: ({ scene, rendererRef, dynamicCanvasRef, b
212
213
  handlePointerUp: (pointerEvent: React_2.PointerEvent<HTMLCanvasElement>) => void;
213
214
  handlePointerLeave: () => void;
214
215
  handlePointerCancel: (pointerEvent: React_2.PointerEvent<HTMLCanvasElement>) => void;
216
+ handleContextMenu: (mouseEvent: React_2.MouseEvent<HTMLCanvasElement>) => void;
215
217
  handleAuxClick: (pointerEvent: React_2.MouseEvent<HTMLCanvasElement>) => void;
216
218
  };
217
219
 
@@ -736,6 +738,13 @@ export { Rect as Rect_alias_2 }
736
738
 
737
739
  export declare const rectContains: (rect: Rect, x: number, y: number) => boolean;
738
740
 
741
+ /** A mouse moving with no button held has lost its release to something else (a context menu, an
742
+ * alert, another window), so the gesture it started must end. */
743
+ export declare const releaseLost: (pointer: {
744
+ pointerType: string;
745
+ buttons: number;
746
+ }) => boolean;
747
+
739
748
  export declare type RendererView = {
740
749
  windowTime: [number, number];
741
750
  tick: number | null;
@@ -1186,6 +1195,12 @@ export declare const TimelinePointerLine: () => React_2.JSX.Element;
1186
1195
 
1187
1196
  export declare const TimelinePrimary: () => React_2.JSX.Element;
1188
1197
 
1198
+ /**
1199
+ * Tooltips of different widths at the right edge. Hover a short bar, then a wide one: the wide
1200
+ * tooltip must stay whole inside the frame, never sized for the bar hovered before it.
1201
+ */
1202
+ export declare const TimelinePromptWidths: () => React_2.JSX.Element;
1203
+
1189
1204
  declare type TimelineProps = {
1190
1205
  rows: RowType[];
1191
1206
  events: EventType[];
@@ -1199,7 +1214,8 @@ declare type TimelineProps = {
1199
1214
  onEventClick?: (props: OnEventClickProps) => void;
1200
1215
  onEventHover?: (props: OnEventHoverProps) => void;
1201
1216
  /** enable click selection: click selects one event (elevated + others dimmed),
1202
- * Cmd/Ctrl+click selects its whole connected group (`props.groupId`),
1217
+ * Cmd/Ctrl+click selects its whole connected group (`props.groupId`), Shift+click
1218
+ * (or Shift+Cmd/Ctrl+click) adds it to or takes it out of the current selection,
1203
1219
  * background click / Escape clears. Default false (no selection). */
1204
1220
  selectable?: boolean;
1205
1221
  /** initial selection for the uncontrolled selection state */
@@ -1315,10 +1331,12 @@ export declare const TimelineSecondaryStrip: () => React_2.JSX.Element;
1315
1331
  /**
1316
1332
  * Selection: `selectable` turns on click selection. A plain click selects one
1317
1333
  * event (it lifts with a shadow while every other event dims); Cmd/Ctrl+click
1318
- * selects the whole connected group (`props.groupId`). Background click or
1319
- * Escape clears. The buttons drive the same state through the imperative
1320
- * handle (`setSelection`/`getSelection`). Dragging/resizing still operate on a
1321
- * single event regardless of how many are selected.
1334
+ * selects the whole connected group (`props.groupId`); Shift+click adds an event
1335
+ * to the selection or takes it out, across groups, and Shift+Cmd/Ctrl+click does
1336
+ * the same for a whole group. Background click or Escape clears. The buttons
1337
+ * drive the same state through the imperative handle (`setSelection`/
1338
+ * `getSelection`). Dragging/resizing still operate on a single event regardless
1339
+ * of how many are selected.
1322
1340
  */
1323
1341
  export declare const TimelineSelectable: () => React_2.JSX.Element;
1324
1342
 
@@ -1370,6 +1388,9 @@ export declare const timeToWidth: (startTime: number, endTime: number, tick: num
1370
1388
 
1371
1389
  export declare const timeToX: (time: number, windowStart: number, tick: number) => number;
1372
1390
 
1391
+ /** `current` with `picked` taken out if every one of them is in it, else added. */
1392
+ export declare const toggled: (current: string[], picked: string[]) => string[];
1393
+
1373
1394
  declare type UseCanvasInteractionsArgs = {
1374
1395
  scene: SceneStore;
1375
1396
  rendererRef: React_2.MutableRefObject<TimelineRenderer | null>;
@@ -174,7 +174,8 @@ export declare const default_alias_2: ({ windowTime, tick, contentWidth, scrollW
174
174
  * Hover tooltip for events. Positioned with @floating-ui/dom against the
175
175
  * hovered event's rect (viewport coordinates): preferred above the event,
176
176
  * flips below when there is no room, and shifts horizontally to stay
177
- * on-screen.
177
+ * on-screen. Placed only once the hovered event's template has rendered, so
178
+ * it is measured at its own size, not the previous event's.
178
179
  */
179
180
  export declare const default_alias_3: React_2.ForwardRefExoticComponent<EventPromptType & React_2.RefAttributes<EventPromptActionsType>>;
180
181
 
@@ -212,6 +213,7 @@ export declare const default_alias_9: ({ scene, rendererRef, dynamicCanvasRef, b
212
213
  handlePointerUp: (pointerEvent: React_2.PointerEvent<HTMLCanvasElement>) => void;
213
214
  handlePointerLeave: () => void;
214
215
  handlePointerCancel: (pointerEvent: React_2.PointerEvent<HTMLCanvasElement>) => void;
216
+ handleContextMenu: (mouseEvent: React_2.MouseEvent<HTMLCanvasElement>) => void;
215
217
  handleAuxClick: (pointerEvent: React_2.MouseEvent<HTMLCanvasElement>) => void;
216
218
  };
217
219
 
@@ -736,6 +738,13 @@ export { Rect as Rect_alias_2 }
736
738
 
737
739
  export declare const rectContains: (rect: Rect, x: number, y: number) => boolean;
738
740
 
741
+ /** A mouse moving with no button held has lost its release to something else (a context menu, an
742
+ * alert, another window), so the gesture it started must end. */
743
+ export declare const releaseLost: (pointer: {
744
+ pointerType: string;
745
+ buttons: number;
746
+ }) => boolean;
747
+
739
748
  export declare type RendererView = {
740
749
  windowTime: [number, number];
741
750
  tick: number | null;
@@ -1186,6 +1195,12 @@ export declare const TimelinePointerLine: () => React_2.JSX.Element;
1186
1195
 
1187
1196
  export declare const TimelinePrimary: () => React_2.JSX.Element;
1188
1197
 
1198
+ /**
1199
+ * Tooltips of different widths at the right edge. Hover a short bar, then a wide one: the wide
1200
+ * tooltip must stay whole inside the frame, never sized for the bar hovered before it.
1201
+ */
1202
+ export declare const TimelinePromptWidths: () => React_2.JSX.Element;
1203
+
1189
1204
  declare type TimelineProps = {
1190
1205
  rows: RowType[];
1191
1206
  events: EventType[];
@@ -1199,7 +1214,8 @@ declare type TimelineProps = {
1199
1214
  onEventClick?: (props: OnEventClickProps) => void;
1200
1215
  onEventHover?: (props: OnEventHoverProps) => void;
1201
1216
  /** enable click selection: click selects one event (elevated + others dimmed),
1202
- * Cmd/Ctrl+click selects its whole connected group (`props.groupId`),
1217
+ * Cmd/Ctrl+click selects its whole connected group (`props.groupId`), Shift+click
1218
+ * (or Shift+Cmd/Ctrl+click) adds it to or takes it out of the current selection,
1203
1219
  * background click / Escape clears. Default false (no selection). */
1204
1220
  selectable?: boolean;
1205
1221
  /** initial selection for the uncontrolled selection state */
@@ -1315,10 +1331,12 @@ export declare const TimelineSecondaryStrip: () => React_2.JSX.Element;
1315
1331
  /**
1316
1332
  * Selection: `selectable` turns on click selection. A plain click selects one
1317
1333
  * event (it lifts with a shadow while every other event dims); Cmd/Ctrl+click
1318
- * selects the whole connected group (`props.groupId`). Background click or
1319
- * Escape clears. The buttons drive the same state through the imperative
1320
- * handle (`setSelection`/`getSelection`). Dragging/resizing still operate on a
1321
- * single event regardless of how many are selected.
1334
+ * selects the whole connected group (`props.groupId`); Shift+click adds an event
1335
+ * to the selection or takes it out, across groups, and Shift+Cmd/Ctrl+click does
1336
+ * the same for a whole group. Background click or Escape clears. The buttons
1337
+ * drive the same state through the imperative handle (`setSelection`/
1338
+ * `getSelection`). Dragging/resizing still operate on a single event regardless
1339
+ * of how many are selected.
1322
1340
  */
1323
1341
  export declare const TimelineSelectable: () => React_2.JSX.Element;
1324
1342
 
@@ -1370,6 +1388,9 @@ export declare const timeToWidth: (startTime: number, endTime: number, tick: num
1370
1388
 
1371
1389
  export declare const timeToX: (time: number, windowStart: number, tick: number) => number;
1372
1390
 
1391
+ /** `current` with `picked` taken out if every one of them is in it, else added. */
1392
+ export declare const toggled: (current: string[], picked: string[]) => string[];
1393
+
1373
1394
  declare type UseCanvasInteractionsArgs = {
1374
1395
  scene: SceneStore;
1375
1396
  rendererRef: React_2.MutableRefObject<TimelineRenderer | null>;
package/dist/index.js CHANGED
@@ -214,42 +214,16 @@ var import_dom = require("@floating-ui/dom");
214
214
  var EventPrompt = (0, import_react3.forwardRef)(
215
215
  ({ template }, ref) => {
216
216
  const promptRef = (0, import_react3.useRef)(null);
217
- const [hoveredEvent, setHoveredEvent] = (0, import_react3.useState)();
217
+ const [shown, setShown] = (0, import_react3.useState)();
218
218
  const showSeqRef = (0, import_react3.useRef)(0);
219
219
  (0, import_react3.useImperativeHandle)(ref, () => {
220
220
  return {
221
221
  show(event, anchorRect) {
222
222
  const prompt = promptRef.current;
223
223
  if (!prompt) return;
224
- setHoveredEvent(event);
225
- const seq = ++showSeqRef.current;
226
- const virtualAnchor = {
227
- getBoundingClientRect: () => ({
228
- x: anchorRect.x,
229
- y: anchorRect.y,
230
- width: anchorRect.width,
231
- height: anchorRect.height,
232
- top: anchorRect.y,
233
- left: anchorRect.x,
234
- right: anchorRect.x + anchorRect.width,
235
- bottom: anchorRect.y + anchorRect.height
236
- })
237
- };
238
224
  prompt.style.display = "block";
239
225
  prompt.style.visibility = "hidden";
240
- (0, import_dom.computePosition)(virtualAnchor, prompt, {
241
- placement: "top",
242
- middleware: [
243
- (0, import_dom.offset)(8),
244
- (0, import_dom.flip)({ padding: 8 }),
245
- (0, import_dom.shift)({ padding: 8 })
246
- ]
247
- }).then(({ x, y }) => {
248
- if (seq !== showSeqRef.current || !promptRef.current) return;
249
- promptRef.current.style.left = `${x}px`;
250
- promptRef.current.style.top = `${y}px`;
251
- promptRef.current.style.visibility = "visible";
252
- });
226
+ setShown({ event, anchor: anchorRect, seq: ++showSeqRef.current });
253
227
  },
254
228
  hide() {
255
229
  showSeqRef.current++;
@@ -259,7 +233,37 @@ var EventPrompt = (0, import_react3.forwardRef)(
259
233
  }
260
234
  };
261
235
  });
262
- return /* @__PURE__ */ import_react3.default.createElement("div", { className: "event-prompt", ref: promptRef }, template && hoveredEvent && template(hoveredEvent));
236
+ (0, import_react3.useLayoutEffect)(() => {
237
+ const prompt = promptRef.current;
238
+ if (!shown || !prompt || shown.seq !== showSeqRef.current) return;
239
+ const { x, y, width, height } = shown.anchor;
240
+ const virtualAnchor = {
241
+ getBoundingClientRect: () => ({
242
+ x,
243
+ y,
244
+ width,
245
+ height,
246
+ top: y,
247
+ left: x,
248
+ right: x + width,
249
+ bottom: y + height
250
+ })
251
+ };
252
+ (0, import_dom.computePosition)(virtualAnchor, prompt, {
253
+ placement: "top",
254
+ middleware: [
255
+ (0, import_dom.offset)(8),
256
+ (0, import_dom.flip)({ padding: 8 }),
257
+ (0, import_dom.shift)({ padding: 8 })
258
+ ]
259
+ }).then((pos) => {
260
+ if (shown.seq !== showSeqRef.current || !promptRef.current) return;
261
+ promptRef.current.style.left = `${pos.x}px`;
262
+ promptRef.current.style.top = `${pos.y}px`;
263
+ promptRef.current.style.visibility = "visible";
264
+ });
265
+ }, [shown]);
266
+ return /* @__PURE__ */ import_react3.default.createElement("div", { className: "event-prompt", ref: promptRef }, template && shown && template(shown.event));
263
267
  }
264
268
  );
265
269
  var event_prompt_default = EventPrompt;
@@ -1534,6 +1538,11 @@ var hitTest = (scene, view, x, y) => {
1534
1538
  };
1535
1539
 
1536
1540
  // src/hooks/use-canvas-interactions.ts
1541
+ var toggled = (current, picked) => {
1542
+ const have = new Set(current);
1543
+ return picked.every((id) => have.has(id)) ? current.filter((id) => !picked.includes(id)) : [...current, ...picked.filter((id) => !have.has(id))];
1544
+ };
1545
+ var releaseLost = (pointer) => pointer.pointerType === "mouse" && pointer.buttons === 0;
1537
1546
  var DRAG_THRESHOLD_PX = 3;
1538
1547
  var RESIZE_HOT_ZONE_PX = 8;
1539
1548
  var DRAG_ZOOM_PX_PER_DOUBLING = 300;
@@ -1964,6 +1973,30 @@ var useCanvasInteractions = ({
1964
1973
  },
1965
1974
  [dynamicCanvasRef, rendererRef, scene]
1966
1975
  );
1976
+ const handlePointerCancel = (0, import_react5.useCallback)(
1977
+ (pointerEvent) => {
1978
+ var _a;
1979
+ pointersRef.current.delete(pointerEvent.pointerId);
1980
+ stateRef.current = { mode: "idle" };
1981
+ const canvas = dynamicCanvasRef.current;
1982
+ if (canvas == null ? void 0 : canvas.hasPointerCapture(pointerEvent.pointerId)) {
1983
+ canvas.releasePointerCapture(pointerEvent.pointerId);
1984
+ }
1985
+ if (canvas) canvas.style.cursor = "grab";
1986
+ if (ghostRef.current) ghostRef.current.style.display = "none";
1987
+ unlockCursor();
1988
+ (_a = rendererRef.current) == null ? void 0 : _a.setView({ draggedEventId: null, resizePreview: null });
1989
+ },
1990
+ [dynamicCanvasRef, ghostRef, rendererRef]
1991
+ );
1992
+ const handleContextMenu = (0, import_react5.useCallback)(
1993
+ (mouseEvent) => {
1994
+ if (mouseEvent.ctrlKey && stateRef.current.mode !== "idle") {
1995
+ mouseEvent.preventDefault();
1996
+ }
1997
+ },
1998
+ []
1999
+ );
1967
2000
  const handlePointerMove = (0, import_react5.useCallback)(
1968
2001
  (pointerEvent) => {
1969
2002
  var _a, _b, _c, _d;
@@ -1977,6 +2010,10 @@ var useCanvasInteractions = ({
1977
2010
  handleHover(pointerEvent);
1978
2011
  return;
1979
2012
  }
2013
+ if (releaseLost(pointerEvent)) {
2014
+ handlePointerCancel(pointerEvent);
2015
+ return;
2016
+ }
1980
2017
  if (state.mode === "pinch") {
1981
2018
  const pts = [...pointersRef.current.values()];
1982
2019
  if (pts.length < 2) return;
@@ -2045,7 +2082,8 @@ var useCanvasInteractions = ({
2045
2082
  scheduleContinuousZoom,
2046
2083
  bodyRef,
2047
2084
  resolveRowAtClientY,
2048
- dynamicCanvasRef
2085
+ dynamicCanvasRef,
2086
+ handlePointerCancel
2049
2087
  ]
2050
2088
  );
2051
2089
  const commitDrop = (0, import_react5.useCallback)(
@@ -2154,8 +2192,9 @@ var useCanvasInteractions = ({
2154
2192
  if (selectable) {
2155
2193
  const id = state.hit.event.id;
2156
2194
  if (scene.isEventSelectable(id)) {
2195
+ const picked = pointerEvent.ctrlKey || pointerEvent.metaKey ? scene.getConnectedEventIds(id) : [id];
2157
2196
  applySelection(
2158
- pointerEvent.ctrlKey || pointerEvent.metaKey ? scene.getConnectedEventIds(id) : [id]
2197
+ pointerEvent.shiftKey ? toggled(getSelection(), picked) : picked
2159
2198
  );
2160
2199
  }
2161
2200
  }
@@ -2185,20 +2224,6 @@ var useCanvasInteractions = ({
2185
2224
  reveal
2186
2225
  ]
2187
2226
  );
2188
- const handlePointerCancel = (0, import_react5.useCallback)(
2189
- (pointerEvent) => {
2190
- var _a;
2191
- pointersRef.current.delete(pointerEvent.pointerId);
2192
- stateRef.current = { mode: "idle" };
2193
- const canvas = dynamicCanvasRef.current;
2194
- if (canvas == null ? void 0 : canvas.hasPointerCapture(pointerEvent.pointerId)) {
2195
- canvas.releasePointerCapture(pointerEvent.pointerId);
2196
- }
2197
- if (ghostRef.current) ghostRef.current.style.display = "none";
2198
- (_a = rendererRef.current) == null ? void 0 : _a.setView({ draggedEventId: null });
2199
- },
2200
- [dynamicCanvasRef, ghostRef, rendererRef]
2201
- );
2202
2227
  const handlePointerLeave = (0, import_react5.useCallback)(() => {
2203
2228
  var _a, _b;
2204
2229
  if (stateRef.current.mode !== "idle") return;
@@ -2280,6 +2305,7 @@ var useCanvasInteractions = ({
2280
2305
  handlePointerUp,
2281
2306
  handlePointerLeave,
2282
2307
  handlePointerCancel,
2308
+ handleContextMenu,
2283
2309
  handleAuxClick
2284
2310
  };
2285
2311
  };
@@ -2479,6 +2505,7 @@ var CanvasBoard = (0, import_react6.forwardRef)(
2479
2505
  handlePointerUp,
2480
2506
  handlePointerLeave,
2481
2507
  handlePointerCancel,
2508
+ handleContextMenu,
2482
2509
  handleAuxClick
2483
2510
  } = use_canvas_interactions_default({
2484
2511
  scene,
@@ -2645,6 +2672,7 @@ var CanvasBoard = (0, import_react6.forwardRef)(
2645
2672
  onPointerUp: handlePointerUp,
2646
2673
  onPointerLeave: handlePointerLeave,
2647
2674
  onPointerCancel: handlePointerCancel,
2675
+ onContextMenu: handleContextMenu,
2648
2676
  onAuxClick: handleAuxClick
2649
2677
  }
2650
2678
  ), /* @__PURE__ */ import_react6.default.createElement(