@helpwave/hightide 0.12.1 → 0.12.3

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
@@ -14709,7 +14709,7 @@ var AppPage = ({ children, headerActions, sidebarProps, ...props }) => {
14709
14709
  const toNavigationItems = useCallback28((items) => {
14710
14710
  return items?.map((item) => ({
14711
14711
  id: item.id,
14712
- label: /* @__PURE__ */ jsxs24("span", { className: clsx15("flex-row-2 items-center", { "text-primary": item.isActive }), children: [
14712
+ label: /* @__PURE__ */ jsxs24("span", { className: "app-page-navigation-item-label", "data-acitve": item.isActive ? "" : void 0, children: [
14713
14713
  item.icon && /* @__PURE__ */ jsx43("span", { className: "size-5", children: item.icon }),
14714
14714
  item.label
14715
14715
  ] }),
@@ -23441,8 +23441,203 @@ var useRerender = () => {
23441
23441
  return useReducer2(() => ({}), {})[1];
23442
23442
  };
23443
23443
 
23444
+ // src/hooks/useSwipeGesture.ts
23445
+ import { useEffect as useEffect61, useRef as useRef48 } from "react";
23446
+ var useSwipeGesture = ({
23447
+ elementRef,
23448
+ inputMode = "touch",
23449
+ onSwipe,
23450
+ startRegion,
23451
+ threshold = 50,
23452
+ crossAxisThreshold = 100,
23453
+ maxSwipeTime = 100
23454
+ }) => {
23455
+ const onSwipeRef = useRef48(onSwipe);
23456
+ const startRegionRef = useRef48(startRegion);
23457
+ const thresholdRef = useRef48(threshold);
23458
+ const crossAxisThresholdRef = useRef48(crossAxisThreshold);
23459
+ const maxSwipeTimeRef = useRef48(maxSwipeTime);
23460
+ const gestureStartRef = useRef48(null);
23461
+ const gestureEndRef = useRef48(null);
23462
+ const isScrollingRef = useRef48(false);
23463
+ const isMouseDownRef = useRef48(false);
23464
+ useEffect61(() => {
23465
+ onSwipeRef.current = onSwipe;
23466
+ startRegionRef.current = startRegion;
23467
+ thresholdRef.current = threshold;
23468
+ crossAxisThresholdRef.current = crossAxisThreshold;
23469
+ maxSwipeTimeRef.current = maxSwipeTime;
23470
+ }, [onSwipe, startRegion, threshold, crossAxisThreshold, maxSwipeTime]);
23471
+ const isWithinStartRegion = (x, y) => {
23472
+ const region = startRegionRef.current;
23473
+ if (!region) return true;
23474
+ if (region.minX !== void 0 && x < region.minX) return false;
23475
+ if (region.maxX !== void 0 && x > region.maxX) return false;
23476
+ if (region.minY !== void 0 && y < region.minY) return false;
23477
+ if (region.maxY !== void 0 && y > region.maxY) return false;
23478
+ return true;
23479
+ };
23480
+ const findScrollableParent = (element) => {
23481
+ if (!element) return null;
23482
+ const table = element.closest("table") || element.closest('[role="table"]');
23483
+ if (table) {
23484
+ let parent = table.parentElement;
23485
+ while (parent) {
23486
+ const style = window.getComputedStyle(parent);
23487
+ if (style.overflow === "auto" || style.overflow === "scroll" || style.overflowY === "auto" || style.overflowY === "scroll" || style.overflowX === "auto" || style.overflowX === "scroll") {
23488
+ return parent;
23489
+ }
23490
+ parent = parent.parentElement;
23491
+ }
23492
+ return table;
23493
+ }
23494
+ let current = element;
23495
+ while (current) {
23496
+ const style = window.getComputedStyle(current);
23497
+ if (style.overflow === "auto" || style.overflow === "scroll" || style.overflowY === "auto" || style.overflowY === "scroll" || style.overflowX === "auto" || style.overflowX === "scroll") {
23498
+ return current;
23499
+ }
23500
+ current = current.parentElement;
23501
+ }
23502
+ return null;
23503
+ };
23504
+ useEffect61(() => {
23505
+ const element = elementRef?.current ?? null;
23506
+ const target = element ?? window;
23507
+ const listenTouch = inputMode === "touch" || inputMode === "both";
23508
+ const listenMouse = inputMode === "mouse" || inputMode === "both";
23509
+ const onGestureStart = (x, y, eventTarget) => {
23510
+ console.log("onGestureStart", x, y);
23511
+ if (!isWithinStartRegion(x, y)) return;
23512
+ const scrollableParent = findScrollableParent(eventTarget);
23513
+ gestureEndRef.current = null;
23514
+ gestureStartRef.current = {
23515
+ x,
23516
+ y,
23517
+ scrollY: scrollableParent?.scrollTop ?? window.scrollY,
23518
+ time: performance.now()
23519
+ };
23520
+ isScrollingRef.current = !!scrollableParent;
23521
+ };
23522
+ const onGestureMove = (x, y, eventTarget) => {
23523
+ console.log("onGestureMove", x, y);
23524
+ const scrollableParent = findScrollableParent(eventTarget);
23525
+ const currentScrollY = scrollableParent?.scrollTop ?? window.scrollY;
23526
+ gestureEndRef.current = {
23527
+ x,
23528
+ y,
23529
+ scrollY: currentScrollY,
23530
+ time: performance.now()
23531
+ };
23532
+ if (gestureStartRef.current && Math.abs(currentScrollY - gestureStartRef.current.scrollY) > 5) {
23533
+ isScrollingRef.current = true;
23534
+ }
23535
+ };
23536
+ const resolveSwipeDirection = (start, end) => {
23537
+ const deltaX = end.x - start.x;
23538
+ const deltaY = end.y - start.y;
23539
+ const absX = Math.abs(deltaX);
23540
+ const absY = Math.abs(deltaY);
23541
+ const minDistance = thresholdRef.current;
23542
+ const maxCrossAxis = crossAxisThresholdRef.current;
23543
+ if (absX < minDistance && absY < minDistance) {
23544
+ return null;
23545
+ }
23546
+ if (absX >= absY && absX >= minDistance && absY <= maxCrossAxis) {
23547
+ return deltaX > 0 ? "leftToRight" : "rightToLeft";
23548
+ }
23549
+ if (absY > absX && absY >= minDistance && absX <= maxCrossAxis) {
23550
+ return deltaY > 0 ? "topToBottom" : "bottomToTop";
23551
+ }
23552
+ return null;
23553
+ };
23554
+ const onGestureEnd = () => {
23555
+ const start = gestureStartRef.current;
23556
+ const end = gestureEndRef.current;
23557
+ if (!start || !end) {
23558
+ gestureStartRef.current = null;
23559
+ gestureEndRef.current = null;
23560
+ isScrollingRef.current = false;
23561
+ return;
23562
+ }
23563
+ if (isScrollingRef.current || Math.abs(start.scrollY - end.scrollY) > 5) {
23564
+ gestureStartRef.current = null;
23565
+ gestureEndRef.current = null;
23566
+ isScrollingRef.current = false;
23567
+ return;
23568
+ }
23569
+ const maxSwipeTime2 = maxSwipeTimeRef.current;
23570
+ if (maxSwipeTime2 !== void 0 && end.time - start.time > maxSwipeTime2) {
23571
+ gestureStartRef.current = null;
23572
+ gestureEndRef.current = null;
23573
+ isScrollingRef.current = false;
23574
+ return;
23575
+ }
23576
+ const direction = resolveSwipeDirection(start, end);
23577
+ if (direction && onSwipeRef.current) {
23578
+ onSwipeRef.current({ direction });
23579
+ }
23580
+ gestureStartRef.current = null;
23581
+ gestureEndRef.current = null;
23582
+ isScrollingRef.current = false;
23583
+ };
23584
+ const onTouchStart = (e) => {
23585
+ if (!e.touches[0]) return;
23586
+ onGestureStart(e.touches[0].clientX, e.touches[0].clientY, e.target);
23587
+ };
23588
+ const onTouchMove = (e) => {
23589
+ if (!e.touches[0]) return;
23590
+ onGestureMove(e.touches[0].clientX, e.touches[0].clientY, e.target);
23591
+ };
23592
+ const onTouchEnd = () => {
23593
+ onGestureEnd();
23594
+ };
23595
+ const onMouseMove = (e) => {
23596
+ if (!isMouseDownRef.current) return;
23597
+ onGestureMove(e.clientX, e.clientY, e.target);
23598
+ };
23599
+ const onMouseUp = () => {
23600
+ if (!isMouseDownRef.current) return;
23601
+ isMouseDownRef.current = false;
23602
+ window.removeEventListener("mousemove", onMouseMove);
23603
+ window.removeEventListener("mouseup", onMouseUp);
23604
+ onGestureEnd();
23605
+ };
23606
+ const onMouseDown = (e) => {
23607
+ if (e.button !== 0) return;
23608
+ if (!isWithinStartRegion(e.clientX, e.clientY)) return;
23609
+ isMouseDownRef.current = true;
23610
+ onGestureStart(e.clientX, e.clientY, e.target);
23611
+ window.addEventListener("mousemove", onMouseMove);
23612
+ window.addEventListener("mouseup", onMouseUp);
23613
+ };
23614
+ const passiveOptions = { passive: true };
23615
+ if (listenTouch) {
23616
+ target.addEventListener("touchstart", onTouchStart, passiveOptions);
23617
+ target.addEventListener("touchmove", onTouchMove, passiveOptions);
23618
+ target.addEventListener("touchend", onTouchEnd, passiveOptions);
23619
+ }
23620
+ if (listenMouse) {
23621
+ target.addEventListener("mousedown", onMouseDown);
23622
+ }
23623
+ return () => {
23624
+ if (listenTouch) {
23625
+ target.removeEventListener("touchstart", onTouchStart);
23626
+ target.removeEventListener("touchmove", onTouchMove);
23627
+ target.removeEventListener("touchend", onTouchEnd);
23628
+ }
23629
+ if (listenMouse) {
23630
+ target.removeEventListener("mousedown", onMouseDown);
23631
+ window.removeEventListener("mousemove", onMouseMove);
23632
+ window.removeEventListener("mouseup", onMouseUp);
23633
+ }
23634
+ };
23635
+ }, [elementRef, inputMode]);
23636
+ return elementRef;
23637
+ };
23638
+
23444
23639
  // src/hooks/useUpdatingDateString.ts
23445
- import { useEffect as useEffect61, useState as useState51 } from "react";
23640
+ import { useEffect as useEffect62, useState as useState51 } from "react";
23446
23641
  var useUpdatingDateString = ({ absoluteFormat = "dateTime", localeOverride, is24HourFormat: is24HourFormatOverride, timeZone: timeZoneOverride, date }) => {
23447
23642
  const { locale: contextLocale, is24HourFormat: contextIs24HourFormat, timeZone: contextTimeZone } = useLocale();
23448
23643
  const locale = localeOverride ?? contextLocale;
@@ -23453,14 +23648,14 @@ var useUpdatingDateString = ({ absoluteFormat = "dateTime", localeOverride, is24
23453
23648
  absolute: DateUtils.formatAbsolute(date, locale, absoluteFormat, { is24HourFormat, timeZone }),
23454
23649
  relative: DateUtils.formatRelative(date, locale)
23455
23650
  });
23456
- useEffect61(() => {
23651
+ useEffect62(() => {
23457
23652
  setDateAndTimeStrings({
23458
23653
  compareDate: date,
23459
23654
  absolute: DateUtils.formatAbsolute(date, locale, absoluteFormat, { is24HourFormat, timeZone }),
23460
23655
  relative: DateUtils.formatRelative(date, locale)
23461
23656
  });
23462
23657
  }, [date, absoluteFormat, locale, is24HourFormat, timeZone]);
23463
- useEffect61(() => {
23658
+ useEffect62(() => {
23464
23659
  let timeoutId;
23465
23660
  const startTimer = () => {
23466
23661
  const now = /* @__PURE__ */ new Date();
@@ -24102,6 +24297,7 @@ export {
24102
24297
  useSelectOptionDisplayLocation,
24103
24298
  useSingleSelection,
24104
24299
  useStorage,
24300
+ useSwipeGesture,
24105
24301
  useTabContext,
24106
24302
  useTableColumnDefinitionContext,
24107
24303
  useTableContainerContext,