@rpcbase/client 0.286.0 → 0.288.0

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.
Files changed (39) hide show
  1. package/dist/RootProvider/index.d.ts +1 -1
  2. package/dist/RootProvider/index.d.ts.map +1 -1
  3. package/dist/apiClient/getServerApiClient.d.ts +1 -1
  4. package/dist/apiClient/getServerApiClient.d.ts.map +1 -1
  5. package/dist/apiClient/index.d.ts +1 -1
  6. package/dist/apiClient/index.d.ts.map +1 -1
  7. package/dist/cleanupURL.d.ts.map +1 -1
  8. package/dist/getFeatureFlag.d.ts.map +1 -1
  9. package/dist/hooks/index.d.ts +2 -2
  10. package/dist/hooks/index.d.ts.map +1 -1
  11. package/dist/hooks/useMediaQuery.d.ts.map +1 -1
  12. package/dist/hooks/useThrottledMeasure.d.ts +1 -1
  13. package/dist/hooks/useThrottledMeasure.d.ts.map +1 -1
  14. package/dist/index.d.ts +6 -5
  15. package/dist/index.d.ts.map +1 -1
  16. package/dist/index.js +1477 -5
  17. package/dist/initWithRoutes.d.ts +1 -1
  18. package/dist/initWithRoutes.d.ts.map +1 -1
  19. package/dist/instrument.d.ts +3 -1
  20. package/dist/instrument.d.ts.map +1 -1
  21. package/dist/instrument.js +25 -28
  22. package/dist/types.d.ts +2 -2
  23. package/dist/types.d.ts.map +1 -1
  24. package/dist/utils/useApplyScroll.d.ts.map +1 -1
  25. package/package.json +24 -13
  26. package/dist/RootProvider/index.js +0 -8
  27. package/dist/apiClient/getServerApiClient.js +0 -97
  28. package/dist/apiClient/index.js +0 -50
  29. package/dist/cleanupURL.js +0 -37
  30. package/dist/getFeatureFlag.js +0 -43
  31. package/dist/hooks/index.js +0 -2
  32. package/dist/hooks/useMediaQuery.js +0 -24
  33. package/dist/hooks/useThrottledMeasure.js +0 -32
  34. package/dist/hooks.d.ts +0 -2
  35. package/dist/hooks.d.ts.map +0 -1
  36. package/dist/hooks.js +0 -1
  37. package/dist/initWithRoutes.js +0 -80
  38. package/dist/types.js +0 -1
  39. package/dist/utils/useApplyScroll.js +0 -138
@@ -1,138 +0,0 @@
1
- import { useCallback, useEffect, useRef } from "react";
2
- import { useLocation } from "@rpcbase/router";
3
- function throttle(callback, limit) {
4
- let wait = false;
5
- return (...args) => {
6
- if (!wait) {
7
- callback(...args);
8
- wait = true;
9
- setTimeout(() => {
10
- wait = false;
11
- }, limit);
12
- }
13
- };
14
- }
15
- export function useApplyScroll() {
16
- const location = useLocation();
17
- const previousPathRef = useRef(location.pathname);
18
- const isScrollingProgrammatically = useRef(false);
19
- const scrollTimeoutRef = useRef(null);
20
- const lastAppliedHashRef = useRef("");
21
- useEffect(() => {
22
- if (typeof window !== "undefined") {
23
- lastAppliedHashRef.current = window.location.hash || "";
24
- }
25
- }, []);
26
- useEffect(() => {
27
- lastAppliedHashRef.current = location.hash || "";
28
- }, [location.hash]);
29
- const replaceHashSilently = useCallback((hash) => {
30
- if (typeof window === "undefined") {
31
- return;
32
- }
33
- if (lastAppliedHashRef.current === hash) {
34
- return;
35
- }
36
- const base = `${window.location.pathname}${window.location.search}`;
37
- window.history.replaceState(window.history.state, "", `${base}${hash}`);
38
- lastAppliedHashRef.current = hash;
39
- }, []);
40
- const markProgrammaticScroll = useCallback(() => {
41
- isScrollingProgrammatically.current = true;
42
- if (scrollTimeoutRef.current) {
43
- clearTimeout(scrollTimeoutRef.current);
44
- }
45
- scrollTimeoutRef.current = setTimeout(() => {
46
- isScrollingProgrammatically.current = false;
47
- }, 1000);
48
- }, []);
49
- useEffect(() => {
50
- const pathChanged = previousPathRef.current !== location.pathname;
51
- if (pathChanged) {
52
- previousPathRef.current = location.pathname;
53
- if (!location.hash) {
54
- window.scrollTo({ top: 0, left: 0, behavior: "auto" });
55
- return;
56
- }
57
- setTimeout(() => {
58
- const id = location.hash.substring(1);
59
- const element = document.getElementById(id);
60
- if (element) {
61
- markProgrammaticScroll();
62
- element.scrollIntoView({ behavior: "smooth" });
63
- }
64
- }, 100);
65
- return;
66
- }
67
- if (!location.hash) {
68
- return;
69
- }
70
- const id = location.hash.substring(1);
71
- const element = document.getElementById(id);
72
- if (element) {
73
- markProgrammaticScroll();
74
- element.scrollIntoView({ behavior: "smooth" });
75
- }
76
- }, [location.hash, location.pathname, markProgrammaticScroll]);
77
- useEffect(() => {
78
- if (typeof window === "undefined") {
79
- return;
80
- }
81
- const handleScroll = throttle(() => {
82
- if (isScrollingProgrammatically.current) {
83
- return;
84
- }
85
- const sections = Array.from(document.querySelectorAll("section[id]"));
86
- if (sections.length === 0) {
87
- replaceHashSilently("");
88
- return;
89
- }
90
- const scrollPosition = window.scrollY;
91
- const viewportHeight = window.innerHeight;
92
- const checkPoint = scrollPosition + viewportHeight / 3;
93
- let activeSectionId = null;
94
- for (const section of sections) {
95
- if (section.offsetTop <= checkPoint &&
96
- section.offsetTop + section.offsetHeight > checkPoint) {
97
- activeSectionId = section.id;
98
- break;
99
- }
100
- }
101
- const newHash = activeSectionId ? `#${activeSectionId}` : "";
102
- replaceHashSilently(newHash);
103
- }, 150);
104
- document.addEventListener("scroll", handleScroll);
105
- return () => {
106
- document.removeEventListener("scroll", handleScroll);
107
- if (scrollTimeoutRef.current) {
108
- clearTimeout(scrollTimeoutRef.current);
109
- scrollTimeoutRef.current = null;
110
- }
111
- };
112
- }, [replaceHashSilently]);
113
- useEffect(() => {
114
- const handleClick = (event) => {
115
- const target = event.target;
116
- const link = target?.closest("a");
117
- const currentHash = typeof window !== "undefined"
118
- ? window.location.hash
119
- : location.hash || "";
120
- if (!link ||
121
- !link.hash ||
122
- link.pathname !== location.pathname ||
123
- link.hash !== currentHash) {
124
- return;
125
- }
126
- const id = link.hash.substring(1);
127
- const element = document.getElementById(id);
128
- if (element) {
129
- event.preventDefault();
130
- event.stopPropagation();
131
- markProgrammaticScroll();
132
- element.scrollIntoView({ behavior: "smooth" });
133
- }
134
- };
135
- document.addEventListener("click", handleClick, true);
136
- return () => document.removeEventListener("click", handleClick, true);
137
- }, [location.hash, location.pathname, markProgrammaticScroll]);
138
- }