@processdynamics/components 0.1.7 → 0.1.8
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.cjs +179 -1
- package/dist/index.d.cts +39 -2
- package/dist/index.d.ts +39 -2
- package/dist/index.js +178 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -34,6 +34,7 @@ __export(index_exports, {
|
|
|
34
34
|
DatePicker: () => DatePicker,
|
|
35
35
|
DebouncedInput: () => DebouncedInput,
|
|
36
36
|
JobCard: () => JobCard,
|
|
37
|
+
PullToRefreshArea: () => PullToRefreshArea,
|
|
37
38
|
Toaster: () => Toaster2,
|
|
38
39
|
toast: () => import_sonner2.toast,
|
|
39
40
|
toastColors: () => toastColors
|
|
@@ -430,7 +431,7 @@ var DatePicker = ({
|
|
|
430
431
|
// src/components/debounceInput/DebouncedInput.tsx
|
|
431
432
|
var import_react2 = require("react");
|
|
432
433
|
|
|
433
|
-
// src/
|
|
434
|
+
// src/components/debounceInput/debounce.ts
|
|
434
435
|
function debounce(fn, delayMs) {
|
|
435
436
|
let timeout = null;
|
|
436
437
|
let latestArgs = null;
|
|
@@ -758,11 +759,188 @@ function toastColors({
|
|
|
758
759
|
function Toaster2({ position = "top-center", ...props }) {
|
|
759
760
|
return /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(Toaster, { position, ...props });
|
|
760
761
|
}
|
|
762
|
+
|
|
763
|
+
// src/components/pullToRefreshArea/PullToRefreshArea.tsx
|
|
764
|
+
var import_react4 = require("react");
|
|
765
|
+
|
|
766
|
+
// src/components/pullToRefreshArea/usePullToRefresh.ts
|
|
767
|
+
var import_react3 = require("react");
|
|
768
|
+
|
|
769
|
+
// src/components/pullToRefreshArea/pullToRefresh.ts
|
|
770
|
+
var DEAD_ZONE_PX = 8;
|
|
771
|
+
var RESISTANCE = 0.5;
|
|
772
|
+
var MAX_PULL_PX = 120;
|
|
773
|
+
var REFRESH_THRESHOLD_PX = 64;
|
|
774
|
+
var REFRESHING_HEIGHT_PX = 48;
|
|
775
|
+
function getPullDistance(fingerDeltaY) {
|
|
776
|
+
if (fingerDeltaY <= DEAD_ZONE_PX) return 0;
|
|
777
|
+
return Math.min((fingerDeltaY - DEAD_ZONE_PX) * RESISTANCE, MAX_PULL_PX);
|
|
778
|
+
}
|
|
779
|
+
function isPastThreshold(pullDistance) {
|
|
780
|
+
return pullDistance >= REFRESH_THRESHOLD_PX;
|
|
781
|
+
}
|
|
782
|
+
var IGNORED_SELECTOR = "input, textarea, select, [contenteditable='true'], [data-no-pull-refresh]";
|
|
783
|
+
function isScrolledVertically(element) {
|
|
784
|
+
const { overflowY } = getComputedStyle(element);
|
|
785
|
+
const canScroll = overflowY === "auto" || overflowY === "scroll";
|
|
786
|
+
return canScroll && element.scrollHeight > element.clientHeight && element.scrollTop > 0;
|
|
787
|
+
}
|
|
788
|
+
function shouldIgnoreTouchTarget(target, container) {
|
|
789
|
+
for (let element = target; element && element !== container; element = element.parentElement) {
|
|
790
|
+
if (element.matches(IGNORED_SELECTOR)) return true;
|
|
791
|
+
if (element instanceof HTMLElement && isScrolledVertically(element)) return true;
|
|
792
|
+
}
|
|
793
|
+
return false;
|
|
794
|
+
}
|
|
795
|
+
|
|
796
|
+
// src/components/pullToRefreshArea/usePullToRefresh.ts
|
|
797
|
+
var RELOAD_MESSAGE_DELAY_MS = 700;
|
|
798
|
+
var MIN_REFRESH_DISPLAY_MS = 500;
|
|
799
|
+
function wait(milliseconds) {
|
|
800
|
+
return new Promise((resolve) => setTimeout(resolve, milliseconds));
|
|
801
|
+
}
|
|
802
|
+
function usePullToRefresh({ containerRef, isEnabled, onRefresh, onReload }) {
|
|
803
|
+
const [pullDistance, setPullDistance] = (0, import_react3.useState)(0);
|
|
804
|
+
const [phase, setPhase] = (0, import_react3.useState)("idle");
|
|
805
|
+
const onRefreshRef = (0, import_react3.useRef)(onRefresh);
|
|
806
|
+
const onReloadRef = (0, import_react3.useRef)(onReload);
|
|
807
|
+
(0, import_react3.useEffect)(() => {
|
|
808
|
+
onRefreshRef.current = onRefresh;
|
|
809
|
+
onReloadRef.current = onReload;
|
|
810
|
+
});
|
|
811
|
+
(0, import_react3.useEffect)(() => {
|
|
812
|
+
const container = containerRef.current;
|
|
813
|
+
if (!container || !isEnabled) return;
|
|
814
|
+
let startY = 0;
|
|
815
|
+
let distance = 0;
|
|
816
|
+
let isTracking = false;
|
|
817
|
+
let isBusy = false;
|
|
818
|
+
function reset() {
|
|
819
|
+
distance = 0;
|
|
820
|
+
setPullDistance(0);
|
|
821
|
+
setPhase("idle");
|
|
822
|
+
}
|
|
823
|
+
function handleTouchStart(event) {
|
|
824
|
+
if (isBusy || event.touches.length !== 1 || !container || container.scrollTop > 0) return;
|
|
825
|
+
if (shouldIgnoreTouchTarget(event.target, container)) return;
|
|
826
|
+
startY = event.touches[0].clientY;
|
|
827
|
+
distance = 0;
|
|
828
|
+
isTracking = true;
|
|
829
|
+
}
|
|
830
|
+
function handleTouchMove(event) {
|
|
831
|
+
if (!isTracking || !container) return;
|
|
832
|
+
if (container.scrollTop > 0) {
|
|
833
|
+
isTracking = false;
|
|
834
|
+
reset();
|
|
835
|
+
return;
|
|
836
|
+
}
|
|
837
|
+
distance = getPullDistance(event.touches[0].clientY - startY);
|
|
838
|
+
if (distance > 0) event.preventDefault();
|
|
839
|
+
setPullDistance(distance);
|
|
840
|
+
setPhase(distance === 0 ? "idle" : isPastThreshold(distance) ? "ready" : "pulling");
|
|
841
|
+
}
|
|
842
|
+
async function handleTouchEnd() {
|
|
843
|
+
if (!isTracking) return;
|
|
844
|
+
isTracking = false;
|
|
845
|
+
if (!isPastThreshold(distance)) {
|
|
846
|
+
reset();
|
|
847
|
+
return;
|
|
848
|
+
}
|
|
849
|
+
isBusy = true;
|
|
850
|
+
setPhase("refreshing");
|
|
851
|
+
setPullDistance(REFRESHING_HEIGHT_PX);
|
|
852
|
+
const startedAt = Date.now();
|
|
853
|
+
let outcome = "refreshed";
|
|
854
|
+
try {
|
|
855
|
+
outcome = await onRefreshRef.current();
|
|
856
|
+
} catch (error) {
|
|
857
|
+
console.error("Pull-down refresh failed:", error);
|
|
858
|
+
}
|
|
859
|
+
if (outcome === "reloading") {
|
|
860
|
+
setPhase("reloading");
|
|
861
|
+
await wait(RELOAD_MESSAGE_DELAY_MS);
|
|
862
|
+
(onReloadRef.current ?? (() => window.location.reload()))();
|
|
863
|
+
return;
|
|
864
|
+
}
|
|
865
|
+
await wait(Math.max(0, MIN_REFRESH_DISPLAY_MS - (Date.now() - startedAt)));
|
|
866
|
+
isBusy = false;
|
|
867
|
+
reset();
|
|
868
|
+
}
|
|
869
|
+
function handleTouchCancel() {
|
|
870
|
+
if (!isTracking) return;
|
|
871
|
+
isTracking = false;
|
|
872
|
+
reset();
|
|
873
|
+
}
|
|
874
|
+
container.addEventListener("touchstart", handleTouchStart, { passive: true });
|
|
875
|
+
container.addEventListener("touchmove", handleTouchMove, { passive: false });
|
|
876
|
+
container.addEventListener("touchend", handleTouchEnd, { passive: true });
|
|
877
|
+
container.addEventListener("touchcancel", handleTouchCancel, { passive: true });
|
|
878
|
+
return () => {
|
|
879
|
+
container.removeEventListener("touchstart", handleTouchStart);
|
|
880
|
+
container.removeEventListener("touchmove", handleTouchMove);
|
|
881
|
+
container.removeEventListener("touchend", handleTouchEnd);
|
|
882
|
+
container.removeEventListener("touchcancel", handleTouchCancel);
|
|
883
|
+
};
|
|
884
|
+
}, [containerRef, isEnabled]);
|
|
885
|
+
return { pullDistance, phase };
|
|
886
|
+
}
|
|
887
|
+
|
|
888
|
+
// src/components/pullToRefreshArea/PullToRefreshArea.tsx
|
|
889
|
+
var import_jsx_runtime14 = require("react/jsx-runtime");
|
|
890
|
+
var LABELS = {
|
|
891
|
+
idle: "",
|
|
892
|
+
pulling: "Pull down to refresh",
|
|
893
|
+
ready: "Release to refresh",
|
|
894
|
+
refreshing: "Refreshing\u2026",
|
|
895
|
+
reloading: "Updating to the new version\u2026"
|
|
896
|
+
};
|
|
897
|
+
function PullToRefreshArea({
|
|
898
|
+
isEnabled,
|
|
899
|
+
onRefresh,
|
|
900
|
+
onReload,
|
|
901
|
+
className,
|
|
902
|
+
children
|
|
903
|
+
}) {
|
|
904
|
+
const containerRef = (0, import_react4.useRef)(null);
|
|
905
|
+
const { pullDistance, phase } = usePullToRefresh({
|
|
906
|
+
containerRef,
|
|
907
|
+
isEnabled,
|
|
908
|
+
onRefresh,
|
|
909
|
+
onReload
|
|
910
|
+
});
|
|
911
|
+
const isDragging = phase === "pulling" || phase === "ready";
|
|
912
|
+
const isWorking = phase === "refreshing" || phase === "reloading";
|
|
913
|
+
return /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)("div", { ref: containerRef, className: (0, import_cn6.cn)(className, isEnabled && "overscroll-y-contain"), children: [
|
|
914
|
+
isEnabled && /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
|
|
915
|
+
"div",
|
|
916
|
+
{
|
|
917
|
+
role: "status",
|
|
918
|
+
"aria-live": "polite",
|
|
919
|
+
className: "flex items-end justify-center overflow-hidden text-sm text-muted-foreground",
|
|
920
|
+
style: { height: pullDistance, transition: isDragging ? "none" : "height 200ms ease" },
|
|
921
|
+
children: phase !== "idle" && /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)("span", { className: "flex items-center gap-2 pb-2", children: [
|
|
922
|
+
isWorking ? /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("span", { className: "h-4 w-4 animate-spin rounded-full border-2 border-muted border-t-primary" }) : /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
|
|
923
|
+
"span",
|
|
924
|
+
{
|
|
925
|
+
"aria-hidden": "true",
|
|
926
|
+
className: "inline-block transition-transform",
|
|
927
|
+
style: { transform: phase === "ready" ? "rotate(180deg)" : "none" },
|
|
928
|
+
children: "\u2193"
|
|
929
|
+
}
|
|
930
|
+
),
|
|
931
|
+
LABELS[phase]
|
|
932
|
+
] })
|
|
933
|
+
}
|
|
934
|
+
),
|
|
935
|
+
children
|
|
936
|
+
] });
|
|
937
|
+
}
|
|
761
938
|
// Annotate the CommonJS export names for ESM import in node:
|
|
762
939
|
0 && (module.exports = {
|
|
763
940
|
DatePicker,
|
|
764
941
|
DebouncedInput,
|
|
765
942
|
JobCard,
|
|
943
|
+
PullToRefreshArea,
|
|
766
944
|
Toaster,
|
|
767
945
|
toast,
|
|
768
946
|
toastColors
|
package/dist/index.d.cts
CHANGED
|
@@ -268,5 +268,42 @@ declare function toastColors({ background, text, border, }: ToastColors): CSSPro
|
|
|
268
268
|
*/
|
|
269
269
|
declare function Toaster({ position, ...props }: ToasterProps): react.JSX.Element;
|
|
270
270
|
|
|
271
|
-
|
|
272
|
-
|
|
271
|
+
/** What a refresh reports back: the data was refreshed, or a new version of the app is about to replace the page. */
|
|
272
|
+
type RefreshOutcome = "refreshed" | "reloading";
|
|
273
|
+
type PullPhase = "idle" | "pulling" | "ready" | "refreshing" | "reloading";
|
|
274
|
+
|
|
275
|
+
interface PullToRefreshAreaProps {
|
|
276
|
+
/**
|
|
277
|
+
* Turns the pull gesture on or off. Turn it off where a refresh can't work,
|
|
278
|
+
* for example when the app can't reach its version check. When off, the area
|
|
279
|
+
* renders its children and nothing else. Not controlled by the area.
|
|
280
|
+
*/
|
|
281
|
+
isEnabled: boolean;
|
|
282
|
+
/**
|
|
283
|
+
* Runs when the user pulls past the threshold and lets go. Resolve with
|
|
284
|
+
* `"refreshed"` once the data is up to date, or `"reloading"` when a newer
|
|
285
|
+
* version of the app is live: the area then shows its updating message and
|
|
286
|
+
* calls `onReload`. If it rejects, the error is logged and the area resets.
|
|
287
|
+
*/
|
|
288
|
+
onRefresh: () => Promise<RefreshOutcome>;
|
|
289
|
+
/**
|
|
290
|
+
* Called after the updating message has been shown, when `onRefresh`
|
|
291
|
+
* resolved with `"reloading"`. Defaults to reloading the browser page.
|
|
292
|
+
*/
|
|
293
|
+
onReload?: () => void;
|
|
294
|
+
/** Classes for the scrolling container. Give it a fixed height or a flex size, because the area itself is what scrolls. */
|
|
295
|
+
className?: string;
|
|
296
|
+
/** The page content. */
|
|
297
|
+
children: ReactNode;
|
|
298
|
+
}
|
|
299
|
+
/**
|
|
300
|
+
* The scrolling page area, with a quiet strip that opens at the top while you
|
|
301
|
+
* pull down. The pull only starts when the area is scrolled to the top, and it
|
|
302
|
+
* ignores touches that begin on fields, inside lists that are scrolled down, or
|
|
303
|
+
* inside anything marked `data-no-pull-refresh`. What a refresh does is up to
|
|
304
|
+
* the app, through `onRefresh`.
|
|
305
|
+
*/
|
|
306
|
+
declare function PullToRefreshArea({ isEnabled, onRefresh, onReload, className, children, }: PullToRefreshAreaProps): react.JSX.Element;
|
|
307
|
+
|
|
308
|
+
export { DatePicker, DebouncedInput, JobCard, PullToRefreshArea, Toaster, toastColors };
|
|
309
|
+
export type { DebouncedInputProps, JobCardAction, JobCardBadge, JobCardBanner, JobCardColor, JobCardData, JobCardPill, JobCardPillTone, JobCardProps, JobCardStage, JobCardTone, PullPhase, PullToRefreshAreaProps, RefreshOutcome, ToastColors, ToasterProps };
|
package/dist/index.d.ts
CHANGED
|
@@ -268,5 +268,42 @@ declare function toastColors({ background, text, border, }: ToastColors): CSSPro
|
|
|
268
268
|
*/
|
|
269
269
|
declare function Toaster({ position, ...props }: ToasterProps): react.JSX.Element;
|
|
270
270
|
|
|
271
|
-
|
|
272
|
-
|
|
271
|
+
/** What a refresh reports back: the data was refreshed, or a new version of the app is about to replace the page. */
|
|
272
|
+
type RefreshOutcome = "refreshed" | "reloading";
|
|
273
|
+
type PullPhase = "idle" | "pulling" | "ready" | "refreshing" | "reloading";
|
|
274
|
+
|
|
275
|
+
interface PullToRefreshAreaProps {
|
|
276
|
+
/**
|
|
277
|
+
* Turns the pull gesture on or off. Turn it off where a refresh can't work,
|
|
278
|
+
* for example when the app can't reach its version check. When off, the area
|
|
279
|
+
* renders its children and nothing else. Not controlled by the area.
|
|
280
|
+
*/
|
|
281
|
+
isEnabled: boolean;
|
|
282
|
+
/**
|
|
283
|
+
* Runs when the user pulls past the threshold and lets go. Resolve with
|
|
284
|
+
* `"refreshed"` once the data is up to date, or `"reloading"` when a newer
|
|
285
|
+
* version of the app is live: the area then shows its updating message and
|
|
286
|
+
* calls `onReload`. If it rejects, the error is logged and the area resets.
|
|
287
|
+
*/
|
|
288
|
+
onRefresh: () => Promise<RefreshOutcome>;
|
|
289
|
+
/**
|
|
290
|
+
* Called after the updating message has been shown, when `onRefresh`
|
|
291
|
+
* resolved with `"reloading"`. Defaults to reloading the browser page.
|
|
292
|
+
*/
|
|
293
|
+
onReload?: () => void;
|
|
294
|
+
/** Classes for the scrolling container. Give it a fixed height or a flex size, because the area itself is what scrolls. */
|
|
295
|
+
className?: string;
|
|
296
|
+
/** The page content. */
|
|
297
|
+
children: ReactNode;
|
|
298
|
+
}
|
|
299
|
+
/**
|
|
300
|
+
* The scrolling page area, with a quiet strip that opens at the top while you
|
|
301
|
+
* pull down. The pull only starts when the area is scrolled to the top, and it
|
|
302
|
+
* ignores touches that begin on fields, inside lists that are scrolled down, or
|
|
303
|
+
* inside anything marked `data-no-pull-refresh`. What a refresh does is up to
|
|
304
|
+
* the app, through `onRefresh`.
|
|
305
|
+
*/
|
|
306
|
+
declare function PullToRefreshArea({ isEnabled, onRefresh, onReload, className, children, }: PullToRefreshAreaProps): react.JSX.Element;
|
|
307
|
+
|
|
308
|
+
export { DatePicker, DebouncedInput, JobCard, PullToRefreshArea, Toaster, toastColors };
|
|
309
|
+
export type { DebouncedInputProps, JobCardAction, JobCardBadge, JobCardBanner, JobCardColor, JobCardData, JobCardPill, JobCardPillTone, JobCardProps, JobCardStage, JobCardTone, PullPhase, PullToRefreshAreaProps, RefreshOutcome, ToastColors, ToasterProps };
|
package/dist/index.js
CHANGED
|
@@ -397,7 +397,7 @@ import {
|
|
|
397
397
|
useState as useState2
|
|
398
398
|
} from "react";
|
|
399
399
|
|
|
400
|
-
// src/
|
|
400
|
+
// src/components/debounceInput/debounce.ts
|
|
401
401
|
function debounce(fn, delayMs) {
|
|
402
402
|
let timeout = null;
|
|
403
403
|
let latestArgs = null;
|
|
@@ -725,10 +725,187 @@ function toastColors({
|
|
|
725
725
|
function Toaster2({ position = "top-center", ...props }) {
|
|
726
726
|
return /* @__PURE__ */ jsx12(Toaster, { position, ...props });
|
|
727
727
|
}
|
|
728
|
+
|
|
729
|
+
// src/components/pullToRefreshArea/PullToRefreshArea.tsx
|
|
730
|
+
import { useRef as useRef4 } from "react";
|
|
731
|
+
|
|
732
|
+
// src/components/pullToRefreshArea/usePullToRefresh.ts
|
|
733
|
+
import { useEffect as useEffect3, useRef as useRef3, useState as useState3 } from "react";
|
|
734
|
+
|
|
735
|
+
// src/components/pullToRefreshArea/pullToRefresh.ts
|
|
736
|
+
var DEAD_ZONE_PX = 8;
|
|
737
|
+
var RESISTANCE = 0.5;
|
|
738
|
+
var MAX_PULL_PX = 120;
|
|
739
|
+
var REFRESH_THRESHOLD_PX = 64;
|
|
740
|
+
var REFRESHING_HEIGHT_PX = 48;
|
|
741
|
+
function getPullDistance(fingerDeltaY) {
|
|
742
|
+
if (fingerDeltaY <= DEAD_ZONE_PX) return 0;
|
|
743
|
+
return Math.min((fingerDeltaY - DEAD_ZONE_PX) * RESISTANCE, MAX_PULL_PX);
|
|
744
|
+
}
|
|
745
|
+
function isPastThreshold(pullDistance) {
|
|
746
|
+
return pullDistance >= REFRESH_THRESHOLD_PX;
|
|
747
|
+
}
|
|
748
|
+
var IGNORED_SELECTOR = "input, textarea, select, [contenteditable='true'], [data-no-pull-refresh]";
|
|
749
|
+
function isScrolledVertically(element) {
|
|
750
|
+
const { overflowY } = getComputedStyle(element);
|
|
751
|
+
const canScroll = overflowY === "auto" || overflowY === "scroll";
|
|
752
|
+
return canScroll && element.scrollHeight > element.clientHeight && element.scrollTop > 0;
|
|
753
|
+
}
|
|
754
|
+
function shouldIgnoreTouchTarget(target, container) {
|
|
755
|
+
for (let element = target; element && element !== container; element = element.parentElement) {
|
|
756
|
+
if (element.matches(IGNORED_SELECTOR)) return true;
|
|
757
|
+
if (element instanceof HTMLElement && isScrolledVertically(element)) return true;
|
|
758
|
+
}
|
|
759
|
+
return false;
|
|
760
|
+
}
|
|
761
|
+
|
|
762
|
+
// src/components/pullToRefreshArea/usePullToRefresh.ts
|
|
763
|
+
var RELOAD_MESSAGE_DELAY_MS = 700;
|
|
764
|
+
var MIN_REFRESH_DISPLAY_MS = 500;
|
|
765
|
+
function wait(milliseconds) {
|
|
766
|
+
return new Promise((resolve) => setTimeout(resolve, milliseconds));
|
|
767
|
+
}
|
|
768
|
+
function usePullToRefresh({ containerRef, isEnabled, onRefresh, onReload }) {
|
|
769
|
+
const [pullDistance, setPullDistance] = useState3(0);
|
|
770
|
+
const [phase, setPhase] = useState3("idle");
|
|
771
|
+
const onRefreshRef = useRef3(onRefresh);
|
|
772
|
+
const onReloadRef = useRef3(onReload);
|
|
773
|
+
useEffect3(() => {
|
|
774
|
+
onRefreshRef.current = onRefresh;
|
|
775
|
+
onReloadRef.current = onReload;
|
|
776
|
+
});
|
|
777
|
+
useEffect3(() => {
|
|
778
|
+
const container = containerRef.current;
|
|
779
|
+
if (!container || !isEnabled) return;
|
|
780
|
+
let startY = 0;
|
|
781
|
+
let distance = 0;
|
|
782
|
+
let isTracking = false;
|
|
783
|
+
let isBusy = false;
|
|
784
|
+
function reset() {
|
|
785
|
+
distance = 0;
|
|
786
|
+
setPullDistance(0);
|
|
787
|
+
setPhase("idle");
|
|
788
|
+
}
|
|
789
|
+
function handleTouchStart(event) {
|
|
790
|
+
if (isBusy || event.touches.length !== 1 || !container || container.scrollTop > 0) return;
|
|
791
|
+
if (shouldIgnoreTouchTarget(event.target, container)) return;
|
|
792
|
+
startY = event.touches[0].clientY;
|
|
793
|
+
distance = 0;
|
|
794
|
+
isTracking = true;
|
|
795
|
+
}
|
|
796
|
+
function handleTouchMove(event) {
|
|
797
|
+
if (!isTracking || !container) return;
|
|
798
|
+
if (container.scrollTop > 0) {
|
|
799
|
+
isTracking = false;
|
|
800
|
+
reset();
|
|
801
|
+
return;
|
|
802
|
+
}
|
|
803
|
+
distance = getPullDistance(event.touches[0].clientY - startY);
|
|
804
|
+
if (distance > 0) event.preventDefault();
|
|
805
|
+
setPullDistance(distance);
|
|
806
|
+
setPhase(distance === 0 ? "idle" : isPastThreshold(distance) ? "ready" : "pulling");
|
|
807
|
+
}
|
|
808
|
+
async function handleTouchEnd() {
|
|
809
|
+
if (!isTracking) return;
|
|
810
|
+
isTracking = false;
|
|
811
|
+
if (!isPastThreshold(distance)) {
|
|
812
|
+
reset();
|
|
813
|
+
return;
|
|
814
|
+
}
|
|
815
|
+
isBusy = true;
|
|
816
|
+
setPhase("refreshing");
|
|
817
|
+
setPullDistance(REFRESHING_HEIGHT_PX);
|
|
818
|
+
const startedAt = Date.now();
|
|
819
|
+
let outcome = "refreshed";
|
|
820
|
+
try {
|
|
821
|
+
outcome = await onRefreshRef.current();
|
|
822
|
+
} catch (error) {
|
|
823
|
+
console.error("Pull-down refresh failed:", error);
|
|
824
|
+
}
|
|
825
|
+
if (outcome === "reloading") {
|
|
826
|
+
setPhase("reloading");
|
|
827
|
+
await wait(RELOAD_MESSAGE_DELAY_MS);
|
|
828
|
+
(onReloadRef.current ?? (() => window.location.reload()))();
|
|
829
|
+
return;
|
|
830
|
+
}
|
|
831
|
+
await wait(Math.max(0, MIN_REFRESH_DISPLAY_MS - (Date.now() - startedAt)));
|
|
832
|
+
isBusy = false;
|
|
833
|
+
reset();
|
|
834
|
+
}
|
|
835
|
+
function handleTouchCancel() {
|
|
836
|
+
if (!isTracking) return;
|
|
837
|
+
isTracking = false;
|
|
838
|
+
reset();
|
|
839
|
+
}
|
|
840
|
+
container.addEventListener("touchstart", handleTouchStart, { passive: true });
|
|
841
|
+
container.addEventListener("touchmove", handleTouchMove, { passive: false });
|
|
842
|
+
container.addEventListener("touchend", handleTouchEnd, { passive: true });
|
|
843
|
+
container.addEventListener("touchcancel", handleTouchCancel, { passive: true });
|
|
844
|
+
return () => {
|
|
845
|
+
container.removeEventListener("touchstart", handleTouchStart);
|
|
846
|
+
container.removeEventListener("touchmove", handleTouchMove);
|
|
847
|
+
container.removeEventListener("touchend", handleTouchEnd);
|
|
848
|
+
container.removeEventListener("touchcancel", handleTouchCancel);
|
|
849
|
+
};
|
|
850
|
+
}, [containerRef, isEnabled]);
|
|
851
|
+
return { pullDistance, phase };
|
|
852
|
+
}
|
|
853
|
+
|
|
854
|
+
// src/components/pullToRefreshArea/PullToRefreshArea.tsx
|
|
855
|
+
import { jsx as jsx13, jsxs as jsxs6 } from "react/jsx-runtime";
|
|
856
|
+
var LABELS = {
|
|
857
|
+
idle: "",
|
|
858
|
+
pulling: "Pull down to refresh",
|
|
859
|
+
ready: "Release to refresh",
|
|
860
|
+
refreshing: "Refreshing\u2026",
|
|
861
|
+
reloading: "Updating to the new version\u2026"
|
|
862
|
+
};
|
|
863
|
+
function PullToRefreshArea({
|
|
864
|
+
isEnabled,
|
|
865
|
+
onRefresh,
|
|
866
|
+
onReload,
|
|
867
|
+
className,
|
|
868
|
+
children
|
|
869
|
+
}) {
|
|
870
|
+
const containerRef = useRef4(null);
|
|
871
|
+
const { pullDistance, phase } = usePullToRefresh({
|
|
872
|
+
containerRef,
|
|
873
|
+
isEnabled,
|
|
874
|
+
onRefresh,
|
|
875
|
+
onReload
|
|
876
|
+
});
|
|
877
|
+
const isDragging = phase === "pulling" || phase === "ready";
|
|
878
|
+
const isWorking = phase === "refreshing" || phase === "reloading";
|
|
879
|
+
return /* @__PURE__ */ jsxs6("div", { ref: containerRef, className: cn6(className, isEnabled && "overscroll-y-contain"), children: [
|
|
880
|
+
isEnabled && /* @__PURE__ */ jsx13(
|
|
881
|
+
"div",
|
|
882
|
+
{
|
|
883
|
+
role: "status",
|
|
884
|
+
"aria-live": "polite",
|
|
885
|
+
className: "flex items-end justify-center overflow-hidden text-sm text-muted-foreground",
|
|
886
|
+
style: { height: pullDistance, transition: isDragging ? "none" : "height 200ms ease" },
|
|
887
|
+
children: phase !== "idle" && /* @__PURE__ */ jsxs6("span", { className: "flex items-center gap-2 pb-2", children: [
|
|
888
|
+
isWorking ? /* @__PURE__ */ jsx13("span", { className: "h-4 w-4 animate-spin rounded-full border-2 border-muted border-t-primary" }) : /* @__PURE__ */ jsx13(
|
|
889
|
+
"span",
|
|
890
|
+
{
|
|
891
|
+
"aria-hidden": "true",
|
|
892
|
+
className: "inline-block transition-transform",
|
|
893
|
+
style: { transform: phase === "ready" ? "rotate(180deg)" : "none" },
|
|
894
|
+
children: "\u2193"
|
|
895
|
+
}
|
|
896
|
+
),
|
|
897
|
+
LABELS[phase]
|
|
898
|
+
] })
|
|
899
|
+
}
|
|
900
|
+
),
|
|
901
|
+
children
|
|
902
|
+
] });
|
|
903
|
+
}
|
|
728
904
|
export {
|
|
729
905
|
DatePicker,
|
|
730
906
|
DebouncedInput,
|
|
731
907
|
JobCard,
|
|
908
|
+
PullToRefreshArea,
|
|
732
909
|
Toaster2 as Toaster,
|
|
733
910
|
toast,
|
|
734
911
|
toastColors
|