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/dist/index.mjs CHANGED
@@ -186,6 +186,7 @@ var rt_indicator_default = RTIndicator;
186
186
  import React2, {
187
187
  forwardRef,
188
188
  useImperativeHandle,
189
+ useLayoutEffect,
189
190
  useRef as useRef2,
190
191
  useState as useState2
191
192
  } from "react";
@@ -193,42 +194,16 @@ import { computePosition, flip, offset, shift } from "@floating-ui/dom";
193
194
  var EventPrompt = forwardRef(
194
195
  ({ template }, ref) => {
195
196
  const promptRef = useRef2(null);
196
- const [hoveredEvent, setHoveredEvent] = useState2();
197
+ const [shown, setShown] = useState2();
197
198
  const showSeqRef = useRef2(0);
198
199
  useImperativeHandle(ref, () => {
199
200
  return {
200
201
  show(event, anchorRect) {
201
202
  const prompt = promptRef.current;
202
203
  if (!prompt) return;
203
- setHoveredEvent(event);
204
- const seq = ++showSeqRef.current;
205
- const virtualAnchor = {
206
- getBoundingClientRect: () => ({
207
- x: anchorRect.x,
208
- y: anchorRect.y,
209
- width: anchorRect.width,
210
- height: anchorRect.height,
211
- top: anchorRect.y,
212
- left: anchorRect.x,
213
- right: anchorRect.x + anchorRect.width,
214
- bottom: anchorRect.y + anchorRect.height
215
- })
216
- };
217
204
  prompt.style.display = "block";
218
205
  prompt.style.visibility = "hidden";
219
- computePosition(virtualAnchor, prompt, {
220
- placement: "top",
221
- middleware: [
222
- offset(8),
223
- flip({ padding: 8 }),
224
- shift({ padding: 8 })
225
- ]
226
- }).then(({ x, y }) => {
227
- if (seq !== showSeqRef.current || !promptRef.current) return;
228
- promptRef.current.style.left = `${x}px`;
229
- promptRef.current.style.top = `${y}px`;
230
- promptRef.current.style.visibility = "visible";
231
- });
206
+ setShown({ event, anchor: anchorRect, seq: ++showSeqRef.current });
232
207
  },
233
208
  hide() {
234
209
  showSeqRef.current++;
@@ -238,7 +213,37 @@ var EventPrompt = forwardRef(
238
213
  }
239
214
  };
240
215
  });
241
- return /* @__PURE__ */ React2.createElement("div", { className: "event-prompt", ref: promptRef }, template && hoveredEvent && template(hoveredEvent));
216
+ useLayoutEffect(() => {
217
+ const prompt = promptRef.current;
218
+ if (!shown || !prompt || shown.seq !== showSeqRef.current) return;
219
+ const { x, y, width, height } = shown.anchor;
220
+ const virtualAnchor = {
221
+ getBoundingClientRect: () => ({
222
+ x,
223
+ y,
224
+ width,
225
+ height,
226
+ top: y,
227
+ left: x,
228
+ right: x + width,
229
+ bottom: y + height
230
+ })
231
+ };
232
+ computePosition(virtualAnchor, prompt, {
233
+ placement: "top",
234
+ middleware: [
235
+ offset(8),
236
+ flip({ padding: 8 }),
237
+ shift({ padding: 8 })
238
+ ]
239
+ }).then((pos) => {
240
+ if (shown.seq !== showSeqRef.current || !promptRef.current) return;
241
+ promptRef.current.style.left = `${pos.x}px`;
242
+ promptRef.current.style.top = `${pos.y}px`;
243
+ promptRef.current.style.visibility = "visible";
244
+ });
245
+ }, [shown]);
246
+ return /* @__PURE__ */ React2.createElement("div", { className: "event-prompt", ref: promptRef }, template && shown && template(shown.event));
242
247
  }
243
248
  );
244
249
  var event_prompt_default = EventPrompt;
@@ -711,7 +716,7 @@ import React5, {
711
716
  forwardRef as forwardRef2,
712
717
  useCallback as useCallback2,
713
718
  useEffect as useEffect5,
714
- useLayoutEffect,
719
+ useLayoutEffect as useLayoutEffect2,
715
720
  useRef as useRef5,
716
721
  useState as useState3,
717
722
  useSyncExternalStore
@@ -1521,6 +1526,11 @@ var hitTest = (scene, view, x, y) => {
1521
1526
  };
1522
1527
 
1523
1528
  // src/hooks/use-canvas-interactions.ts
1529
+ var toggled = (current, picked) => {
1530
+ const have = new Set(current);
1531
+ return picked.every((id) => have.has(id)) ? current.filter((id) => !picked.includes(id)) : [...current, ...picked.filter((id) => !have.has(id))];
1532
+ };
1533
+ var releaseLost = (pointer) => pointer.pointerType === "mouse" && pointer.buttons === 0;
1524
1534
  var DRAG_THRESHOLD_PX = 3;
1525
1535
  var RESIZE_HOT_ZONE_PX = 8;
1526
1536
  var DRAG_ZOOM_PX_PER_DOUBLING = 300;
@@ -1951,6 +1961,30 @@ var useCanvasInteractions = ({
1951
1961
  },
1952
1962
  [dynamicCanvasRef, rendererRef, scene]
1953
1963
  );
1964
+ const handlePointerCancel = useCallback(
1965
+ (pointerEvent) => {
1966
+ var _a;
1967
+ pointersRef.current.delete(pointerEvent.pointerId);
1968
+ stateRef.current = { mode: "idle" };
1969
+ const canvas = dynamicCanvasRef.current;
1970
+ if (canvas == null ? void 0 : canvas.hasPointerCapture(pointerEvent.pointerId)) {
1971
+ canvas.releasePointerCapture(pointerEvent.pointerId);
1972
+ }
1973
+ if (canvas) canvas.style.cursor = "grab";
1974
+ if (ghostRef.current) ghostRef.current.style.display = "none";
1975
+ unlockCursor();
1976
+ (_a = rendererRef.current) == null ? void 0 : _a.setView({ draggedEventId: null, resizePreview: null });
1977
+ },
1978
+ [dynamicCanvasRef, ghostRef, rendererRef]
1979
+ );
1980
+ const handleContextMenu = useCallback(
1981
+ (mouseEvent) => {
1982
+ if (mouseEvent.ctrlKey && stateRef.current.mode !== "idle") {
1983
+ mouseEvent.preventDefault();
1984
+ }
1985
+ },
1986
+ []
1987
+ );
1954
1988
  const handlePointerMove = useCallback(
1955
1989
  (pointerEvent) => {
1956
1990
  var _a, _b, _c, _d;
@@ -1964,6 +1998,10 @@ var useCanvasInteractions = ({
1964
1998
  handleHover(pointerEvent);
1965
1999
  return;
1966
2000
  }
2001
+ if (releaseLost(pointerEvent)) {
2002
+ handlePointerCancel(pointerEvent);
2003
+ return;
2004
+ }
1967
2005
  if (state.mode === "pinch") {
1968
2006
  const pts = [...pointersRef.current.values()];
1969
2007
  if (pts.length < 2) return;
@@ -2032,7 +2070,8 @@ var useCanvasInteractions = ({
2032
2070
  scheduleContinuousZoom,
2033
2071
  bodyRef,
2034
2072
  resolveRowAtClientY,
2035
- dynamicCanvasRef
2073
+ dynamicCanvasRef,
2074
+ handlePointerCancel
2036
2075
  ]
2037
2076
  );
2038
2077
  const commitDrop = useCallback(
@@ -2141,8 +2180,9 @@ var useCanvasInteractions = ({
2141
2180
  if (selectable) {
2142
2181
  const id = state.hit.event.id;
2143
2182
  if (scene.isEventSelectable(id)) {
2183
+ const picked = pointerEvent.ctrlKey || pointerEvent.metaKey ? scene.getConnectedEventIds(id) : [id];
2144
2184
  applySelection(
2145
- pointerEvent.ctrlKey || pointerEvent.metaKey ? scene.getConnectedEventIds(id) : [id]
2185
+ pointerEvent.shiftKey ? toggled(getSelection(), picked) : picked
2146
2186
  );
2147
2187
  }
2148
2188
  }
@@ -2172,20 +2212,6 @@ var useCanvasInteractions = ({
2172
2212
  reveal
2173
2213
  ]
2174
2214
  );
2175
- const handlePointerCancel = useCallback(
2176
- (pointerEvent) => {
2177
- var _a;
2178
- pointersRef.current.delete(pointerEvent.pointerId);
2179
- stateRef.current = { mode: "idle" };
2180
- const canvas = dynamicCanvasRef.current;
2181
- if (canvas == null ? void 0 : canvas.hasPointerCapture(pointerEvent.pointerId)) {
2182
- canvas.releasePointerCapture(pointerEvent.pointerId);
2183
- }
2184
- if (ghostRef.current) ghostRef.current.style.display = "none";
2185
- (_a = rendererRef.current) == null ? void 0 : _a.setView({ draggedEventId: null });
2186
- },
2187
- [dynamicCanvasRef, ghostRef, rendererRef]
2188
- );
2189
2215
  const handlePointerLeave = useCallback(() => {
2190
2216
  var _a, _b;
2191
2217
  if (stateRef.current.mode !== "idle") return;
@@ -2267,6 +2293,7 @@ var useCanvasInteractions = ({
2267
2293
  handlePointerUp,
2268
2294
  handlePointerLeave,
2269
2295
  handlePointerCancel,
2296
+ handleContextMenu,
2270
2297
  handleAuxClick
2271
2298
  };
2272
2299
  };
@@ -2395,7 +2422,7 @@ var CanvasBoard = forwardRef2(
2395
2422
  useCallback2((listener) => scene.subscribe(listener), [scene]),
2396
2423
  () => scene.version
2397
2424
  );
2398
- useLayoutEffect(() => {
2425
+ useLayoutEffect2(() => {
2399
2426
  if (renderRowLabel) return;
2400
2427
  const wrapper = headerWrapperRef.current;
2401
2428
  if (!wrapper) return;
@@ -2433,7 +2460,7 @@ var CanvasBoard = forwardRef2(
2433
2460
  wrapper.removeChild(measurer);
2434
2461
  };
2435
2462
  }, [rows, scene, theme.rowPaddingY, rowsHeaderClassName, renderRowLabel]);
2436
- useLayoutEffect(() => {
2463
+ useLayoutEffect2(() => {
2437
2464
  if (!renderRowLabel) return;
2438
2465
  const layer = measureLayerRef.current;
2439
2466
  const wrapper = headerWrapperRef.current;
@@ -2466,6 +2493,7 @@ var CanvasBoard = forwardRef2(
2466
2493
  handlePointerUp,
2467
2494
  handlePointerLeave,
2468
2495
  handlePointerCancel,
2496
+ handleContextMenu,
2469
2497
  handleAuxClick
2470
2498
  } = use_canvas_interactions_default({
2471
2499
  scene,
@@ -2496,7 +2524,7 @@ var CanvasBoard = forwardRef2(
2496
2524
  }, [getSelection, rendererRef]);
2497
2525
  const { offsetOf, totalHeight } = scene.getRowOffsets();
2498
2526
  totalHeightRef.current = totalHeight;
2499
- useLayoutEffect(() => {
2527
+ useLayoutEffect2(() => {
2500
2528
  measureViewport();
2501
2529
  }, [totalHeight, measureViewport]);
2502
2530
  const lastChildOf = /* @__PURE__ */ new Map();
@@ -2632,6 +2660,7 @@ var CanvasBoard = forwardRef2(
2632
2660
  onPointerUp: handlePointerUp,
2633
2661
  onPointerLeave: handlePointerLeave,
2634
2662
  onPointerCancel: handlePointerCancel,
2663
+ onContextMenu: handleContextMenu,
2635
2664
  onAuxClick: handleAuxClick
2636
2665
  }
2637
2666
  ), /* @__PURE__ */ React5.createElement(