@tanstack/query-core 5.102.7 → 5.103.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 (301) hide show
  1. package/build/legacy/environmentManager.cjs +15 -1
  2. package/build/legacy/environmentManager.cjs.map +1 -1
  3. package/build/legacy/environmentManager.d.cts +15 -1
  4. package/build/legacy/environmentManager.d.cts.map +1 -1
  5. package/build/legacy/environmentManager.d.ts +15 -1
  6. package/build/legacy/environmentManager.d.ts.map +1 -1
  7. package/build/legacy/environmentManager.js +15 -1
  8. package/build/legacy/environmentManager.js.map +1 -1
  9. package/build/legacy/focusManager.cjs +57 -0
  10. package/build/legacy/focusManager.cjs.map +1 -1
  11. package/build/legacy/focusManager.d.cts +57 -0
  12. package/build/legacy/focusManager.d.cts.map +1 -1
  13. package/build/legacy/focusManager.d.ts +57 -0
  14. package/build/legacy/focusManager.d.ts.map +1 -1
  15. package/build/legacy/focusManager.js +57 -0
  16. package/build/legacy/focusManager.js.map +1 -1
  17. package/build/legacy/{hydration-Bjs0MSgg.d.ts → hydration-Cq7QYAzB.d.ts} +1424 -7
  18. package/build/legacy/hydration-Cq7QYAzB.d.ts.map +1 -0
  19. package/build/legacy/{hydration-DWGr3cFC.d.cts → hydration-DwR10Hi-.d.cts} +1424 -7
  20. package/build/legacy/hydration-DwR10Hi-.d.cts.map +1 -0
  21. package/build/legacy/hydration.cjs +57 -4
  22. package/build/legacy/hydration.cjs.map +1 -1
  23. package/build/legacy/hydration.d.cts +1 -1
  24. package/build/legacy/hydration.d.ts +1 -1
  25. package/build/legacy/hydration.js +57 -4
  26. package/build/legacy/hydration.js.map +1 -1
  27. package/build/legacy/index.cjs.map +1 -1
  28. package/build/legacy/index.d.cts +5 -5
  29. package/build/legacy/index.d.ts +5 -5
  30. package/build/legacy/index.js.map +1 -1
  31. package/build/legacy/infiniteQueryBehavior.d.cts +1 -1
  32. package/build/legacy/infiniteQueryBehavior.d.ts +1 -1
  33. package/build/legacy/infiniteQueryObserver.cjs +67 -0
  34. package/build/legacy/infiniteQueryObserver.cjs.map +1 -1
  35. package/build/legacy/infiniteQueryObserver.d.cts +68 -1
  36. package/build/legacy/infiniteQueryObserver.d.cts.map +1 -1
  37. package/build/legacy/infiniteQueryObserver.d.ts +68 -1
  38. package/build/legacy/infiniteQueryObserver.d.ts.map +1 -1
  39. package/build/legacy/infiniteQueryObserver.js +67 -0
  40. package/build/legacy/infiniteQueryObserver.js.map +1 -1
  41. package/build/legacy/mutation.cjs +74 -0
  42. package/build/legacy/mutation.cjs.map +1 -1
  43. package/build/legacy/mutation.d.cts +1 -1
  44. package/build/legacy/mutation.d.ts +1 -1
  45. package/build/legacy/mutation.js +74 -0
  46. package/build/legacy/mutation.js.map +1 -1
  47. package/build/legacy/mutationCache.cjs +74 -0
  48. package/build/legacy/mutationCache.cjs.map +1 -1
  49. package/build/legacy/mutationCache.d.cts +1 -1
  50. package/build/legacy/mutationCache.d.ts +1 -1
  51. package/build/legacy/mutationCache.js +74 -0
  52. package/build/legacy/mutationCache.js.map +1 -1
  53. package/build/legacy/mutationObserver.cjs +71 -0
  54. package/build/legacy/mutationObserver.cjs.map +1 -1
  55. package/build/legacy/mutationObserver.d.cts +1 -1
  56. package/build/legacy/mutationObserver.d.ts +1 -1
  57. package/build/legacy/mutationObserver.js +71 -0
  58. package/build/legacy/mutationObserver.js.map +1 -1
  59. package/build/legacy/notifyManager.cjs +45 -1
  60. package/build/legacy/notifyManager.cjs.map +1 -1
  61. package/build/legacy/notifyManager.d.cts +83 -2
  62. package/build/legacy/notifyManager.d.cts.map +1 -1
  63. package/build/legacy/notifyManager.d.ts +83 -2
  64. package/build/legacy/notifyManager.d.ts.map +1 -1
  65. package/build/legacy/notifyManager.js +45 -1
  66. package/build/legacy/notifyManager.js.map +1 -1
  67. package/build/legacy/onlineManager.cjs +47 -0
  68. package/build/legacy/onlineManager.cjs.map +1 -1
  69. package/build/legacy/onlineManager.d.cts +47 -0
  70. package/build/legacy/onlineManager.d.cts.map +1 -1
  71. package/build/legacy/onlineManager.d.ts +47 -0
  72. package/build/legacy/onlineManager.d.ts.map +1 -1
  73. package/build/legacy/onlineManager.js +47 -0
  74. package/build/legacy/onlineManager.js.map +1 -1
  75. package/build/legacy/queriesObserver.cjs +64 -0
  76. package/build/legacy/queriesObserver.cjs.map +1 -1
  77. package/build/legacy/queriesObserver.d.cts +73 -1
  78. package/build/legacy/queriesObserver.d.cts.map +1 -1
  79. package/build/legacy/queriesObserver.d.ts +73 -1
  80. package/build/legacy/queriesObserver.d.ts.map +1 -1
  81. package/build/legacy/queriesObserver.js +64 -0
  82. package/build/legacy/queriesObserver.js.map +1 -1
  83. package/build/legacy/query.cjs +141 -0
  84. package/build/legacy/query.cjs.map +1 -1
  85. package/build/legacy/query.d.cts +1 -1
  86. package/build/legacy/query.d.ts +1 -1
  87. package/build/legacy/query.js +141 -0
  88. package/build/legacy/query.js.map +1 -1
  89. package/build/legacy/queryCache.cjs +120 -0
  90. package/build/legacy/queryCache.cjs.map +1 -1
  91. package/build/legacy/queryCache.d.cts +1 -1
  92. package/build/legacy/queryCache.d.ts +1 -1
  93. package/build/legacy/queryCache.js +120 -0
  94. package/build/legacy/queryCache.js.map +1 -1
  95. package/build/legacy/queryClient.cjs +363 -0
  96. package/build/legacy/queryClient.cjs.map +1 -1
  97. package/build/legacy/queryClient.d.cts +1 -1
  98. package/build/legacy/queryClient.d.ts +1 -1
  99. package/build/legacy/queryClient.js +363 -0
  100. package/build/legacy/queryClient.js.map +1 -1
  101. package/build/legacy/queryObserver.cjs +116 -2
  102. package/build/legacy/queryObserver.cjs.map +1 -1
  103. package/build/legacy/queryObserver.d.cts +1 -1
  104. package/build/legacy/queryObserver.d.ts +1 -1
  105. package/build/legacy/queryObserver.js +116 -2
  106. package/build/legacy/queryObserver.js.map +1 -1
  107. package/build/legacy/retryer.cjs +18 -0
  108. package/build/legacy/retryer.cjs.map +1 -1
  109. package/build/legacy/retryer.d.cts +1 -1
  110. package/build/legacy/retryer.d.ts +1 -1
  111. package/build/legacy/retryer.js +18 -0
  112. package/build/legacy/retryer.js.map +1 -1
  113. package/build/legacy/streamedQuery.cjs +10 -1
  114. package/build/legacy/streamedQuery.cjs.map +1 -1
  115. package/build/legacy/streamedQuery.d.cts +26 -2
  116. package/build/legacy/streamedQuery.d.cts.map +1 -1
  117. package/build/legacy/streamedQuery.d.ts +26 -2
  118. package/build/legacy/streamedQuery.d.ts.map +1 -1
  119. package/build/legacy/streamedQuery.js +10 -1
  120. package/build/legacy/streamedQuery.js.map +1 -1
  121. package/build/legacy/timeoutManager.cjs +99 -0
  122. package/build/legacy/timeoutManager.cjs.map +1 -1
  123. package/build/legacy/timeoutManager.d.cts +105 -0
  124. package/build/legacy/timeoutManager.d.cts.map +1 -1
  125. package/build/legacy/timeoutManager.d.ts +105 -0
  126. package/build/legacy/timeoutManager.d.ts.map +1 -1
  127. package/build/legacy/timeoutManager.js +99 -0
  128. package/build/legacy/timeoutManager.js.map +1 -1
  129. package/build/legacy/types.cjs.map +1 -1
  130. package/build/legacy/types.d.cts +1 -1
  131. package/build/legacy/types.d.ts +1 -1
  132. package/build/legacy/types.js.map +1 -1
  133. package/build/legacy/utils.cjs +76 -0
  134. package/build/legacy/utils.cjs.map +1 -1
  135. package/build/legacy/utils.d.cts +1 -1
  136. package/build/legacy/utils.d.ts +1 -1
  137. package/build/legacy/utils.js +76 -0
  138. package/build/legacy/utils.js.map +1 -1
  139. package/build/modern/environmentManager.cjs +15 -1
  140. package/build/modern/environmentManager.cjs.map +1 -1
  141. package/build/modern/environmentManager.d.cts +15 -1
  142. package/build/modern/environmentManager.d.cts.map +1 -1
  143. package/build/modern/environmentManager.d.ts +15 -1
  144. package/build/modern/environmentManager.d.ts.map +1 -1
  145. package/build/modern/environmentManager.js +15 -1
  146. package/build/modern/environmentManager.js.map +1 -1
  147. package/build/modern/focusManager.cjs +57 -0
  148. package/build/modern/focusManager.cjs.map +1 -1
  149. package/build/modern/focusManager.d.cts +57 -0
  150. package/build/modern/focusManager.d.cts.map +1 -1
  151. package/build/modern/focusManager.d.ts +57 -0
  152. package/build/modern/focusManager.d.ts.map +1 -1
  153. package/build/modern/focusManager.js +57 -0
  154. package/build/modern/focusManager.js.map +1 -1
  155. package/build/modern/{hydration-Bjs0MSgg.d.ts → hydration-Cq7QYAzB.d.ts} +1424 -7
  156. package/build/modern/hydration-Cq7QYAzB.d.ts.map +1 -0
  157. package/build/modern/{hydration-DWGr3cFC.d.cts → hydration-DwR10Hi-.d.cts} +1424 -7
  158. package/build/modern/hydration-DwR10Hi-.d.cts.map +1 -0
  159. package/build/modern/hydration.cjs +57 -4
  160. package/build/modern/hydration.cjs.map +1 -1
  161. package/build/modern/hydration.d.cts +1 -1
  162. package/build/modern/hydration.d.ts +1 -1
  163. package/build/modern/hydration.js +57 -4
  164. package/build/modern/hydration.js.map +1 -1
  165. package/build/modern/index.cjs.map +1 -1
  166. package/build/modern/index.d.cts +5 -5
  167. package/build/modern/index.d.ts +5 -5
  168. package/build/modern/index.js.map +1 -1
  169. package/build/modern/infiniteQueryBehavior.d.cts +1 -1
  170. package/build/modern/infiniteQueryBehavior.d.ts +1 -1
  171. package/build/modern/infiniteQueryObserver.cjs +67 -0
  172. package/build/modern/infiniteQueryObserver.cjs.map +1 -1
  173. package/build/modern/infiniteQueryObserver.d.cts +68 -1
  174. package/build/modern/infiniteQueryObserver.d.cts.map +1 -1
  175. package/build/modern/infiniteQueryObserver.d.ts +68 -1
  176. package/build/modern/infiniteQueryObserver.d.ts.map +1 -1
  177. package/build/modern/infiniteQueryObserver.js +67 -0
  178. package/build/modern/infiniteQueryObserver.js.map +1 -1
  179. package/build/modern/mutation.cjs +74 -0
  180. package/build/modern/mutation.cjs.map +1 -1
  181. package/build/modern/mutation.d.cts +1 -1
  182. package/build/modern/mutation.d.ts +1 -1
  183. package/build/modern/mutation.js +74 -0
  184. package/build/modern/mutation.js.map +1 -1
  185. package/build/modern/mutationCache.cjs +74 -0
  186. package/build/modern/mutationCache.cjs.map +1 -1
  187. package/build/modern/mutationCache.d.cts +1 -1
  188. package/build/modern/mutationCache.d.ts +1 -1
  189. package/build/modern/mutationCache.js +74 -0
  190. package/build/modern/mutationCache.js.map +1 -1
  191. package/build/modern/mutationObserver.cjs +71 -0
  192. package/build/modern/mutationObserver.cjs.map +1 -1
  193. package/build/modern/mutationObserver.d.cts +1 -1
  194. package/build/modern/mutationObserver.d.ts +1 -1
  195. package/build/modern/mutationObserver.js +71 -0
  196. package/build/modern/mutationObserver.js.map +1 -1
  197. package/build/modern/notifyManager.cjs +45 -1
  198. package/build/modern/notifyManager.cjs.map +1 -1
  199. package/build/modern/notifyManager.d.cts +83 -2
  200. package/build/modern/notifyManager.d.cts.map +1 -1
  201. package/build/modern/notifyManager.d.ts +83 -2
  202. package/build/modern/notifyManager.d.ts.map +1 -1
  203. package/build/modern/notifyManager.js +45 -1
  204. package/build/modern/notifyManager.js.map +1 -1
  205. package/build/modern/onlineManager.cjs +47 -0
  206. package/build/modern/onlineManager.cjs.map +1 -1
  207. package/build/modern/onlineManager.d.cts +47 -0
  208. package/build/modern/onlineManager.d.cts.map +1 -1
  209. package/build/modern/onlineManager.d.ts +47 -0
  210. package/build/modern/onlineManager.d.ts.map +1 -1
  211. package/build/modern/onlineManager.js +47 -0
  212. package/build/modern/onlineManager.js.map +1 -1
  213. package/build/modern/queriesObserver.cjs +64 -0
  214. package/build/modern/queriesObserver.cjs.map +1 -1
  215. package/build/modern/queriesObserver.d.cts +73 -1
  216. package/build/modern/queriesObserver.d.cts.map +1 -1
  217. package/build/modern/queriesObserver.d.ts +73 -1
  218. package/build/modern/queriesObserver.d.ts.map +1 -1
  219. package/build/modern/queriesObserver.js +64 -0
  220. package/build/modern/queriesObserver.js.map +1 -1
  221. package/build/modern/query.cjs +141 -0
  222. package/build/modern/query.cjs.map +1 -1
  223. package/build/modern/query.d.cts +1 -1
  224. package/build/modern/query.d.ts +1 -1
  225. package/build/modern/query.js +141 -0
  226. package/build/modern/query.js.map +1 -1
  227. package/build/modern/queryCache.cjs +120 -0
  228. package/build/modern/queryCache.cjs.map +1 -1
  229. package/build/modern/queryCache.d.cts +1 -1
  230. package/build/modern/queryCache.d.ts +1 -1
  231. package/build/modern/queryCache.js +120 -0
  232. package/build/modern/queryCache.js.map +1 -1
  233. package/build/modern/queryClient.cjs +363 -0
  234. package/build/modern/queryClient.cjs.map +1 -1
  235. package/build/modern/queryClient.d.cts +1 -1
  236. package/build/modern/queryClient.d.ts +1 -1
  237. package/build/modern/queryClient.js +363 -0
  238. package/build/modern/queryClient.js.map +1 -1
  239. package/build/modern/queryObserver.cjs +116 -2
  240. package/build/modern/queryObserver.cjs.map +1 -1
  241. package/build/modern/queryObserver.d.cts +1 -1
  242. package/build/modern/queryObserver.d.ts +1 -1
  243. package/build/modern/queryObserver.js +116 -2
  244. package/build/modern/queryObserver.js.map +1 -1
  245. package/build/modern/retryer.cjs +18 -0
  246. package/build/modern/retryer.cjs.map +1 -1
  247. package/build/modern/retryer.d.cts +1 -1
  248. package/build/modern/retryer.d.ts +1 -1
  249. package/build/modern/retryer.js +18 -0
  250. package/build/modern/retryer.js.map +1 -1
  251. package/build/modern/streamedQuery.cjs +10 -1
  252. package/build/modern/streamedQuery.cjs.map +1 -1
  253. package/build/modern/streamedQuery.d.cts +26 -2
  254. package/build/modern/streamedQuery.d.cts.map +1 -1
  255. package/build/modern/streamedQuery.d.ts +26 -2
  256. package/build/modern/streamedQuery.d.ts.map +1 -1
  257. package/build/modern/streamedQuery.js +10 -1
  258. package/build/modern/streamedQuery.js.map +1 -1
  259. package/build/modern/timeoutManager.cjs +99 -0
  260. package/build/modern/timeoutManager.cjs.map +1 -1
  261. package/build/modern/timeoutManager.d.cts +105 -0
  262. package/build/modern/timeoutManager.d.cts.map +1 -1
  263. package/build/modern/timeoutManager.d.ts +105 -0
  264. package/build/modern/timeoutManager.d.ts.map +1 -1
  265. package/build/modern/timeoutManager.js +99 -0
  266. package/build/modern/timeoutManager.js.map +1 -1
  267. package/build/modern/types.cjs.map +1 -1
  268. package/build/modern/types.d.cts +1 -1
  269. package/build/modern/types.d.ts +1 -1
  270. package/build/modern/types.js.map +1 -1
  271. package/build/modern/utils.cjs +76 -0
  272. package/build/modern/utils.cjs.map +1 -1
  273. package/build/modern/utils.d.cts +1 -1
  274. package/build/modern/utils.d.ts +1 -1
  275. package/build/modern/utils.js +76 -0
  276. package/build/modern/utils.js.map +1 -1
  277. package/package.json +9 -9
  278. package/src/environmentManager.ts +15 -1
  279. package/src/focusManager.ts +57 -0
  280. package/src/hydration.ts +82 -16
  281. package/src/index.ts +3 -0
  282. package/src/infiniteQueryObserver.ts +67 -0
  283. package/src/mutation.ts +108 -0
  284. package/src/mutationCache.ts +91 -0
  285. package/src/mutationObserver.ts +71 -0
  286. package/src/notifyManager.ts +46 -1
  287. package/src/onlineManager.ts +47 -0
  288. package/src/queriesObserver.ts +72 -0
  289. package/src/query.ts +193 -0
  290. package/src/queryCache.ts +134 -0
  291. package/src/queryClient.ts +369 -0
  292. package/src/queryObserver.ts +117 -4
  293. package/src/retryer.ts +18 -0
  294. package/src/streamedQuery.ts +25 -1
  295. package/src/timeoutManager.ts +105 -0
  296. package/src/types.ts +147 -5
  297. package/src/utils.ts +107 -0
  298. package/build/legacy/hydration-Bjs0MSgg.d.ts.map +0 -1
  299. package/build/legacy/hydration-DWGr3cFC.d.cts.map +0 -1
  300. package/build/modern/hydration-Bjs0MSgg.d.ts.map +0 -1
  301. package/build/modern/hydration-DWGr3cFC.d.cts.map +0 -1
@@ -7,7 +7,21 @@ let isServerFn = () => require_utils.isServer;
7
7
  */
8
8
  const isServer = () => isServerFn();
9
9
  /**
10
- * Manages environment detection used by TanStack Query internals.
10
+ * Manages how TanStack Query detects whether the current runtime should be treated as
11
+ * server-side, which disables scheduling refetch timers and changes the default `retry` count
12
+ * and `gcTime`. By default, the detection treats a missing `window` (or the presence of a
13
+ * `Deno` global) as server.
14
+ *
15
+ * Override this for runtimes where that default detection would give the wrong answer — for
16
+ * example, a Service Worker, where `window` is undefined even though the environment should
17
+ * behave like a client.
18
+ *
19
+ * @example
20
+ * ```ts
21
+ * import { environmentManager } from '@tanstack/query-core'
22
+ *
23
+ * environmentManager.setIsServer(() => false)
24
+ * ```
11
25
  */
12
26
  const environmentManager = {
13
27
  isServer,
@@ -1 +1 @@
1
- {"version":3,"file":"environmentManager.cjs","names":["defaultIsServer"],"sources":["../../src/environmentManager.ts"],"sourcesContent":["import { isServer as defaultIsServer } from './utils'\n\nexport type IsServerValue = () => boolean\n\nlet isServerFn: IsServerValue = () => defaultIsServer\n\n/**\n * Returns whether the current runtime should be treated as a server environment.\n */\nexport const isServer = (): boolean => isServerFn()\n\n/**\n * Manages environment detection used by TanStack Query internals.\n */\nexport const environmentManager = {\n isServer,\n /**\n * Overrides the server check globally.\n */\n setIsServer(isServerValue: IsServerValue): void {\n isServerFn = isServerValue\n },\n}\n"],"mappings":";;;AAIA,IAAI,mBAAkCA,cAAAA;;;;AAKtC,MAAa,iBAA0B,WAAW;;;;AAKlD,MAAa,qBAAqB;CAChC;;;;CAIA,YAAY,eAAoC;EAC9C,aAAa;CACf;AACF"}
1
+ {"version":3,"file":"environmentManager.cjs","names":["defaultIsServer"],"sources":["../../src/environmentManager.ts"],"sourcesContent":["import { isServer as defaultIsServer } from './utils'\n\nexport type IsServerValue = () => boolean\n\nlet isServerFn: IsServerValue = () => defaultIsServer\n\n/**\n * Returns whether the current runtime should be treated as a server environment.\n */\nexport const isServer = (): boolean => isServerFn()\n\n/**\n * Manages how TanStack Query detects whether the current runtime should be treated as\n * server-side, which disables scheduling refetch timers and changes the default `retry` count\n * and `gcTime`. By default, the detection treats a missing `window` (or the presence of a\n * `Deno` global) as server.\n *\n * Override this for runtimes where that default detection would give the wrong answer — for\n * example, a Service Worker, where `window` is undefined even though the environment should\n * behave like a client.\n *\n * @example\n * ```ts\n * import { environmentManager } from '@tanstack/query-core'\n *\n * environmentManager.setIsServer(() => false)\n * ```\n */\nexport const environmentManager = {\n isServer,\n /**\n * Overrides the server check globally.\n */\n setIsServer(isServerValue: IsServerValue): void {\n isServerFn = isServerValue\n },\n}\n"],"mappings":";;;AAIA,IAAI,mBAAkCA,cAAAA;;;;AAKtC,MAAa,iBAA0B,WAAW;;;;;;;;;;;;;;;;;;AAmBlD,MAAa,qBAAqB;CAChC;;;;CAIA,YAAY,eAAoC;EAC9C,aAAa;CACf;AACF"}
@@ -5,7 +5,21 @@ type IsServerValue = () => boolean;
5
5
  */
6
6
  declare const isServer: () => boolean;
7
7
  /**
8
- * Manages environment detection used by TanStack Query internals.
8
+ * Manages how TanStack Query detects whether the current runtime should be treated as
9
+ * server-side, which disables scheduling refetch timers and changes the default `retry` count
10
+ * and `gcTime`. By default, the detection treats a missing `window` (or the presence of a
11
+ * `Deno` global) as server.
12
+ *
13
+ * Override this for runtimes where that default detection would give the wrong answer — for
14
+ * example, a Service Worker, where `window` is undefined even though the environment should
15
+ * behave like a client.
16
+ *
17
+ * @example
18
+ * ```ts
19
+ * import { environmentManager } from '@tanstack/query-core'
20
+ *
21
+ * environmentManager.setIsServer(() => false)
22
+ * ```
9
23
  */
10
24
  declare const environmentManager: {
11
25
  isServer: () => boolean;
@@ -1 +1 @@
1
- {"version":3,"file":"environmentManager.d.cts","names":[],"sources":["../../src/environmentManager.ts"],"mappings":";KAEY;;;;cAOC;;;;cAKA;EALe;;;;EAUC,YAAA,eAAA"}
1
+ {"version":3,"file":"environmentManager.d.cts","names":[],"sources":["../../src/environmentManager.ts"],"mappings":";KAEY;;;;cAOC;;;;;;;;;;;;;;;;;;cAmBA;EAnBe;;;;EAwBC,YAAA,eAAA"}
@@ -5,7 +5,21 @@ type IsServerValue = () => boolean;
5
5
  */
6
6
  declare const isServer: () => boolean;
7
7
  /**
8
- * Manages environment detection used by TanStack Query internals.
8
+ * Manages how TanStack Query detects whether the current runtime should be treated as
9
+ * server-side, which disables scheduling refetch timers and changes the default `retry` count
10
+ * and `gcTime`. By default, the detection treats a missing `window` (or the presence of a
11
+ * `Deno` global) as server.
12
+ *
13
+ * Override this for runtimes where that default detection would give the wrong answer — for
14
+ * example, a Service Worker, where `window` is undefined even though the environment should
15
+ * behave like a client.
16
+ *
17
+ * @example
18
+ * ```ts
19
+ * import { environmentManager } from '@tanstack/query-core'
20
+ *
21
+ * environmentManager.setIsServer(() => false)
22
+ * ```
9
23
  */
10
24
  declare const environmentManager: {
11
25
  isServer: () => boolean;
@@ -1 +1 @@
1
- {"version":3,"file":"environmentManager.d.ts","names":[],"sources":["../../src/environmentManager.ts"],"mappings":";KAEY;;;;cAOC;;;;cAKA;EALe;;;;EAUC,YAAA,eAAA"}
1
+ {"version":3,"file":"environmentManager.d.ts","names":[],"sources":["../../src/environmentManager.ts"],"mappings":";KAEY;;;;cAOC;;;;;;;;;;;;;;;;;;cAmBA;EAnBe;;;;EAwBC,YAAA,eAAA"}
@@ -6,7 +6,21 @@ let isServerFn = () => isServer$1;
6
6
  */
7
7
  const isServer = () => isServerFn();
8
8
  /**
9
- * Manages environment detection used by TanStack Query internals.
9
+ * Manages how TanStack Query detects whether the current runtime should be treated as
10
+ * server-side, which disables scheduling refetch timers and changes the default `retry` count
11
+ * and `gcTime`. By default, the detection treats a missing `window` (or the presence of a
12
+ * `Deno` global) as server.
13
+ *
14
+ * Override this for runtimes where that default detection would give the wrong answer — for
15
+ * example, a Service Worker, where `window` is undefined even though the environment should
16
+ * behave like a client.
17
+ *
18
+ * @example
19
+ * ```ts
20
+ * import { environmentManager } from '@tanstack/query-core'
21
+ *
22
+ * environmentManager.setIsServer(() => false)
23
+ * ```
10
24
  */
11
25
  const environmentManager = {
12
26
  isServer,
@@ -1 +1 @@
1
- {"version":3,"file":"environmentManager.js","names":["defaultIsServer"],"sources":["../../src/environmentManager.ts"],"sourcesContent":["import { isServer as defaultIsServer } from './utils'\n\nexport type IsServerValue = () => boolean\n\nlet isServerFn: IsServerValue = () => defaultIsServer\n\n/**\n * Returns whether the current runtime should be treated as a server environment.\n */\nexport const isServer = (): boolean => isServerFn()\n\n/**\n * Manages environment detection used by TanStack Query internals.\n */\nexport const environmentManager = {\n isServer,\n /**\n * Overrides the server check globally.\n */\n setIsServer(isServerValue: IsServerValue): void {\n isServerFn = isServerValue\n },\n}\n"],"mappings":";;AAIA,IAAI,mBAAkCA;;;;AAKtC,MAAa,iBAA0B,WAAW;;;;AAKlD,MAAa,qBAAqB;CAChC;;;;CAIA,YAAY,eAAoC;EAC9C,aAAa;CACf;AACF"}
1
+ {"version":3,"file":"environmentManager.js","names":["defaultIsServer"],"sources":["../../src/environmentManager.ts"],"sourcesContent":["import { isServer as defaultIsServer } from './utils'\n\nexport type IsServerValue = () => boolean\n\nlet isServerFn: IsServerValue = () => defaultIsServer\n\n/**\n * Returns whether the current runtime should be treated as a server environment.\n */\nexport const isServer = (): boolean => isServerFn()\n\n/**\n * Manages how TanStack Query detects whether the current runtime should be treated as\n * server-side, which disables scheduling refetch timers and changes the default `retry` count\n * and `gcTime`. By default, the detection treats a missing `window` (or the presence of a\n * `Deno` global) as server.\n *\n * Override this for runtimes where that default detection would give the wrong answer — for\n * example, a Service Worker, where `window` is undefined even though the environment should\n * behave like a client.\n *\n * @example\n * ```ts\n * import { environmentManager } from '@tanstack/query-core'\n *\n * environmentManager.setIsServer(() => false)\n * ```\n */\nexport const environmentManager = {\n isServer,\n /**\n * Overrides the server check globally.\n */\n setIsServer(isServerValue: IsServerValue): void {\n isServerFn = isServerValue\n },\n}\n"],"mappings":";;AAIA,IAAI,mBAAkCA;;;;AAKtC,MAAa,iBAA0B,WAAW;;;;;;;;;;;;;;;;;;AAmBlD,MAAa,qBAAqB;CAChC;;;;CAIA,YAAY,eAAoC;EAC9C,aAAa;CACf;AACF"}
@@ -5,6 +5,11 @@ const require_subscribable = require("./subscribable.cjs");
5
5
  var _focused = /* @__PURE__ */ new WeakMap();
6
6
  var _cleanup = /* @__PURE__ */ new WeakMap();
7
7
  var _setup = /* @__PURE__ */ new WeakMap();
8
+ /**
9
+ * The `FocusManager` manages the focus state within TanStack Query.
10
+ *
11
+ * It can be used to change the default event listeners or to manually change the focus state.
12
+ */
8
13
  var FocusManager = class extends require_subscribable.Subscribable {
9
14
  constructor() {
10
15
  super();
@@ -31,6 +36,31 @@ var FocusManager = class extends require_subscribable.Subscribable {
31
36
  require_classPrivateFieldSet2._classPrivateFieldSet2(_cleanup, this, void 0);
32
37
  }
33
38
  }
39
+ /**
40
+ * `setEventListener` can be used to set a custom event listener that will
41
+ * be used to determine the focus state. The provided `setup` function
42
+ * receives a `setFocused` callback: call it with a `boolean` to manually
43
+ * set the focus state, or with no arguments to re-evaluate the current
44
+ * focus state and notify subscribers.
45
+ *
46
+ * @example
47
+ * ```ts
48
+ * import { focusManager } from '@tanstack/query-core'
49
+ *
50
+ * focusManager.setEventListener((handleFocus) => {
51
+ * const listener = () => handleFocus()
52
+ * // Listen to visibilitychange
53
+ * if (typeof window !== 'undefined' && window.addEventListener) {
54
+ * window.addEventListener('visibilitychange', listener, false)
55
+ * }
56
+ *
57
+ * return () => {
58
+ * // Be sure to unsubscribe if a new handler is set
59
+ * window.removeEventListener('visibilitychange', listener)
60
+ * }
61
+ * })
62
+ * ```
63
+ */
34
64
  setEventListener(setup) {
35
65
  var _classPrivateFieldGet3;
36
66
  require_classPrivateFieldSet2._classPrivateFieldSet2(_setup, this, setup);
@@ -40,24 +70,51 @@ var FocusManager = class extends require_subscribable.Subscribable {
40
70
  else this.onFocus();
41
71
  }));
42
72
  }
73
+ /**
74
+ * `setFocused` can be used to manually set the focus state. Set `undefined`
75
+ * to fall back to the default focus check.
76
+ *
77
+ * @example
78
+ * ```ts
79
+ * import { focusManager } from '@tanstack/query-core'
80
+ *
81
+ * // Set focused
82
+ * focusManager.setFocused(true)
83
+ *
84
+ * // Set unfocused
85
+ * focusManager.setFocused(false)
86
+ *
87
+ * // Fallback to the default focus check
88
+ * focusManager.setFocused(undefined)
89
+ * ```
90
+ */
43
91
  setFocused(focused) {
44
92
  if (require_classPrivateFieldSet2._classPrivateFieldGet2(_focused, this) !== focused) {
45
93
  require_classPrivateFieldSet2._classPrivateFieldSet2(_focused, this, focused);
46
94
  this.onFocus();
47
95
  }
48
96
  }
97
+ /**
98
+ * `onFocus` notifies all subscribed listeners with the current focus state.
99
+ */
49
100
  onFocus() {
50
101
  const isFocused = this.isFocused();
51
102
  this.listeners.forEach((listener) => {
52
103
  listener(isFocused);
53
104
  });
54
105
  }
106
+ /**
107
+ * `isFocused` can be used to get the current focus state.
108
+ */
55
109
  isFocused() {
56
110
  var _globalThis$document;
57
111
  if (typeof require_classPrivateFieldSet2._classPrivateFieldGet2(_focused, this) === "boolean") return require_classPrivateFieldSet2._classPrivateFieldGet2(_focused, this);
58
112
  return ((_globalThis$document = globalThis.document) === null || _globalThis$document === void 0 ? void 0 : _globalThis$document.visibilityState) !== "hidden";
59
113
  }
60
114
  };
115
+ /**
116
+ * Singleton instance of {@link FocusManager}, used to manage and observe the focus state within TanStack Query.
117
+ */
61
118
  const focusManager = new FocusManager();
62
119
  //#endregion
63
120
  exports.FocusManager = FocusManager;
@@ -1 +1 @@
1
- {"version":3,"file":"focusManager.cjs","names":["Subscribable"],"sources":["../../src/focusManager.ts"],"sourcesContent":["import { Subscribable } from './subscribable'\n\ntype Listener = (focused: boolean) => void\n\ntype SetupFn = (\n setFocused: (focused?: boolean) => void,\n) => (() => void) | undefined\n\nexport class FocusManager extends Subscribable<Listener> {\n #focused?: boolean\n #cleanup?: () => void\n\n #setup: SetupFn\n\n constructor() {\n super()\n this.#setup = (onFocus) => {\n // addEventListener does not exist in React Native, but window does\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n if (typeof window !== 'undefined' && window.addEventListener) {\n const listener = () => onFocus()\n // Listen to visibilitychange\n window.addEventListener('visibilitychange', listener, false)\n\n return () => {\n // Be sure to unsubscribe if a new handler is set\n window.removeEventListener('visibilitychange', listener)\n }\n }\n return\n }\n }\n\n protected onSubscribe(): void {\n if (!this.#cleanup) {\n this.setEventListener(this.#setup)\n }\n }\n\n protected onUnsubscribe() {\n if (!this.hasListeners()) {\n this.#cleanup?.()\n this.#cleanup = undefined\n }\n }\n\n setEventListener(setup: SetupFn): void {\n this.#setup = setup\n this.#cleanup?.()\n this.#cleanup = setup((focused) => {\n if (typeof focused === 'boolean') {\n this.setFocused(focused)\n } else {\n this.onFocus()\n }\n })\n }\n\n setFocused(focused?: boolean): void {\n const changed = this.#focused !== focused\n if (changed) {\n this.#focused = focused\n this.onFocus()\n }\n }\n\n onFocus(): void {\n const isFocused = this.isFocused()\n this.listeners.forEach((listener) => {\n listener(isFocused)\n })\n }\n\n isFocused(): boolean {\n if (typeof this.#focused === 'boolean') {\n return this.#focused\n }\n\n // document global can be unavailable in react native\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n return globalThis.document?.visibilityState !== 'hidden'\n }\n}\n\nexport const focusManager = new FocusManager()\n"],"mappings":";;;;;;;AAQA,IAAa,eAAb,cAAkCA,qBAAAA,aAAuB;CAMvD,cAAc;EACZ,MAAM;;;;EACN,8BAAA,uBAAA,QAAA,OAAe,YAAY;GAGzB,IAAI,OAAO,WAAW,eAAe,OAAO,kBAAkB;IAC5D,MAAM,iBAAiB,QAAQ;IAE/B,OAAO,iBAAiB,oBAAoB,UAAU,KAAK;IAE3D,aAAa;KAEX,OAAO,oBAAoB,oBAAoB,QAAQ;IACzD;GACF;EAEF,CAAA;CACF;CAEA,cAA8B;EAC5B,IAAI,CAAA,8BAAA,uBAAA,UAAC,IAAA,GACH,KAAK,iBAAA,8BAAA,uBAAA,QAAiB,IAAA,CAAW;CAErC;CAEA,gBAA0B;EACxB,IAAI,CAAC,KAAK,aAAa,GAAG;;GACxB,CAAA,2BAAA,8BAAA,uBAAA,UAAA,IAAA,OAAA,QAAA,6BAAA,KAAA,KAAA,yBAAA,KAAA,IAAgB;GAChB,8BAAA,uBAAA,UAAA,MAAgB,KAAA,CAAA;EAClB;CACF;CAEA,iBAAiB,OAAsB;;EACrC,8BAAA,uBAAA,QAAA,MAAc,KAAA;EACd,CAAA,yBAAA,8BAAA,uBAAA,UAAA,IAAA,OAAA,QAAA,2BAAA,KAAA,KAAA,uBAAA,KAAA,IAAgB;EAChB,8BAAA,uBAAA,UAAA,MAAgB,OAAO,YAAY;GACjC,IAAI,OAAO,YAAY,WACrB,KAAK,WAAW,OAAO;QAEvB,KAAK,QAAQ;EAEjB,CAAC,CAAA;CACH;CAEA,WAAW,SAAyB;EAElC,IAAA,8BAAA,uBAAA,UADgB,IAAA,MAAkB,SACrB;GACX,8BAAA,uBAAA,UAAA,MAAgB,OAAA;GAChB,KAAK,QAAQ;EACf;CACF;CAEA,UAAgB;EACd,MAAM,YAAY,KAAK,UAAU;EACjC,KAAK,UAAU,SAAS,aAAa;GACnC,SAAS,SAAS;EACpB,CAAC;CACH;CAEA,YAAqB;;EACnB,IAAI,OAAA,8BAAA,uBAAA,UAAO,IAAA,MAAkB,WAC3B,OAAA,8BAAA,uBAAA,UAAO,IAAA;EAKT,SAAA,uBAAO,WAAW,cAAA,QAAA,yBAAA,KAAA,IAAA,KAAA,IAAA,qBAAU,qBAAoB;CAClD;AACF;AAEA,MAAa,eAAe,IAAI,aAAa"}
1
+ {"version":3,"file":"focusManager.cjs","names":["Subscribable"],"sources":["../../src/focusManager.ts"],"sourcesContent":["import { Subscribable } from './subscribable'\n\ntype Listener = (focused: boolean) => void\n\ntype SetupFn = (\n setFocused: (focused?: boolean) => void,\n) => (() => void) | undefined\n\n/**\n * The `FocusManager` manages the focus state within TanStack Query.\n *\n * It can be used to change the default event listeners or to manually change the focus state.\n */\nexport class FocusManager extends Subscribable<Listener> {\n #focused?: boolean\n #cleanup?: () => void\n\n #setup: SetupFn\n\n constructor() {\n super()\n this.#setup = (onFocus) => {\n // addEventListener does not exist in React Native, but window does\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n if (typeof window !== 'undefined' && window.addEventListener) {\n const listener = () => onFocus()\n // Listen to visibilitychange\n window.addEventListener('visibilitychange', listener, false)\n\n return () => {\n // Be sure to unsubscribe if a new handler is set\n window.removeEventListener('visibilitychange', listener)\n }\n }\n return\n }\n }\n\n protected onSubscribe(): void {\n if (!this.#cleanup) {\n this.setEventListener(this.#setup)\n }\n }\n\n protected onUnsubscribe() {\n if (!this.hasListeners()) {\n this.#cleanup?.()\n this.#cleanup = undefined\n }\n }\n\n /**\n * `setEventListener` can be used to set a custom event listener that will\n * be used to determine the focus state. The provided `setup` function\n * receives a `setFocused` callback: call it with a `boolean` to manually\n * set the focus state, or with no arguments to re-evaluate the current\n * focus state and notify subscribers.\n *\n * @example\n * ```ts\n * import { focusManager } from '@tanstack/query-core'\n *\n * focusManager.setEventListener((handleFocus) => {\n * const listener = () => handleFocus()\n * // Listen to visibilitychange\n * if (typeof window !== 'undefined' && window.addEventListener) {\n * window.addEventListener('visibilitychange', listener, false)\n * }\n *\n * return () => {\n * // Be sure to unsubscribe if a new handler is set\n * window.removeEventListener('visibilitychange', listener)\n * }\n * })\n * ```\n */\n setEventListener(setup: SetupFn): void {\n this.#setup = setup\n this.#cleanup?.()\n this.#cleanup = setup((focused) => {\n if (typeof focused === 'boolean') {\n this.setFocused(focused)\n } else {\n this.onFocus()\n }\n })\n }\n\n /**\n * `setFocused` can be used to manually set the focus state. Set `undefined`\n * to fall back to the default focus check.\n *\n * @example\n * ```ts\n * import { focusManager } from '@tanstack/query-core'\n *\n * // Set focused\n * focusManager.setFocused(true)\n *\n * // Set unfocused\n * focusManager.setFocused(false)\n *\n * // Fallback to the default focus check\n * focusManager.setFocused(undefined)\n * ```\n */\n setFocused(focused?: boolean): void {\n const changed = this.#focused !== focused\n if (changed) {\n this.#focused = focused\n this.onFocus()\n }\n }\n\n /**\n * `onFocus` notifies all subscribed listeners with the current focus state.\n */\n onFocus(): void {\n const isFocused = this.isFocused()\n this.listeners.forEach((listener) => {\n listener(isFocused)\n })\n }\n\n /**\n * `isFocused` can be used to get the current focus state.\n */\n isFocused(): boolean {\n if (typeof this.#focused === 'boolean') {\n return this.#focused\n }\n\n // document global can be unavailable in react native\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n return globalThis.document?.visibilityState !== 'hidden'\n }\n}\n\n/**\n * Singleton instance of {@link FocusManager}, used to manage and observe the focus state within TanStack Query.\n */\nexport const focusManager = new FocusManager()\n"],"mappings":";;;;;;;;;;;;AAaA,IAAa,eAAb,cAAkCA,qBAAAA,aAAuB;CAMvD,cAAc;EACZ,MAAM;;;;EACN,8BAAA,uBAAA,QAAA,OAAe,YAAY;GAGzB,IAAI,OAAO,WAAW,eAAe,OAAO,kBAAkB;IAC5D,MAAM,iBAAiB,QAAQ;IAE/B,OAAO,iBAAiB,oBAAoB,UAAU,KAAK;IAE3D,aAAa;KAEX,OAAO,oBAAoB,oBAAoB,QAAQ;IACzD;GACF;EAEF,CAAA;CACF;CAEA,cAA8B;EAC5B,IAAI,CAAA,8BAAA,uBAAA,UAAC,IAAA,GACH,KAAK,iBAAA,8BAAA,uBAAA,QAAiB,IAAA,CAAW;CAErC;CAEA,gBAA0B;EACxB,IAAI,CAAC,KAAK,aAAa,GAAG;;GACxB,CAAA,2BAAA,8BAAA,uBAAA,UAAA,IAAA,OAAA,QAAA,6BAAA,KAAA,KAAA,yBAAA,KAAA,IAAgB;GAChB,8BAAA,uBAAA,UAAA,MAAgB,KAAA,CAAA;EAClB;CACF;;;;;;;;;;;;;;;;;;;;;;;;;;CA2BA,iBAAiB,OAAsB;;EACrC,8BAAA,uBAAA,QAAA,MAAc,KAAA;EACd,CAAA,yBAAA,8BAAA,uBAAA,UAAA,IAAA,OAAA,QAAA,2BAAA,KAAA,KAAA,uBAAA,KAAA,IAAgB;EAChB,8BAAA,uBAAA,UAAA,MAAgB,OAAO,YAAY;GACjC,IAAI,OAAO,YAAY,WACrB,KAAK,WAAW,OAAO;QAEvB,KAAK,QAAQ;EAEjB,CAAC,CAAA;CACH;;;;;;;;;;;;;;;;;;;CAoBA,WAAW,SAAyB;EAElC,IAAA,8BAAA,uBAAA,UADgB,IAAA,MAAkB,SACrB;GACX,8BAAA,uBAAA,UAAA,MAAgB,OAAA;GAChB,KAAK,QAAQ;EACf;CACF;;;;CAKA,UAAgB;EACd,MAAM,YAAY,KAAK,UAAU;EACjC,KAAK,UAAU,SAAS,aAAa;GACnC,SAAS,SAAS;EACpB,CAAC;CACH;;;;CAKA,YAAqB;;EACnB,IAAI,OAAA,8BAAA,uBAAA,UAAO,IAAA,MAAkB,WAC3B,OAAA,8BAAA,uBAAA,UAAO,IAAA;EAKT,SAAA,uBAAO,WAAW,cAAA,QAAA,yBAAA,KAAA,IAAA,KAAA,IAAA,qBAAU,qBAAoB;CAClD;AACF;;;;AAKA,MAAa,eAAe,IAAI,aAAa"}
@@ -2,16 +2,73 @@ import { t as Subscribable } from "./subscribable-CbifVTKz.cjs";
2
2
  //#region src/focusManager.d.ts
3
3
  type Listener = (focused: boolean) => void;
4
4
  type SetupFn = (setFocused: (focused?: boolean) => void) => (() => void) | undefined;
5
+ /**
6
+ * The `FocusManager` manages the focus state within TanStack Query.
7
+ *
8
+ * It can be used to change the default event listeners or to manually change the focus state.
9
+ */
5
10
  declare class FocusManager extends Subscribable<Listener> {
6
11
  #private;
7
12
  constructor();
8
13
  protected onSubscribe(): void;
9
14
  protected onUnsubscribe(): void;
15
+ /**
16
+ * `setEventListener` can be used to set a custom event listener that will
17
+ * be used to determine the focus state. The provided `setup` function
18
+ * receives a `setFocused` callback: call it with a `boolean` to manually
19
+ * set the focus state, or with no arguments to re-evaluate the current
20
+ * focus state and notify subscribers.
21
+ *
22
+ * @example
23
+ * ```ts
24
+ * import { focusManager } from '@tanstack/query-core'
25
+ *
26
+ * focusManager.setEventListener((handleFocus) => {
27
+ * const listener = () => handleFocus()
28
+ * // Listen to visibilitychange
29
+ * if (typeof window !== 'undefined' && window.addEventListener) {
30
+ * window.addEventListener('visibilitychange', listener, false)
31
+ * }
32
+ *
33
+ * return () => {
34
+ * // Be sure to unsubscribe if a new handler is set
35
+ * window.removeEventListener('visibilitychange', listener)
36
+ * }
37
+ * })
38
+ * ```
39
+ */
10
40
  setEventListener(setup: SetupFn): void;
41
+ /**
42
+ * `setFocused` can be used to manually set the focus state. Set `undefined`
43
+ * to fall back to the default focus check.
44
+ *
45
+ * @example
46
+ * ```ts
47
+ * import { focusManager } from '@tanstack/query-core'
48
+ *
49
+ * // Set focused
50
+ * focusManager.setFocused(true)
51
+ *
52
+ * // Set unfocused
53
+ * focusManager.setFocused(false)
54
+ *
55
+ * // Fallback to the default focus check
56
+ * focusManager.setFocused(undefined)
57
+ * ```
58
+ */
11
59
  setFocused(focused?: boolean): void;
60
+ /**
61
+ * `onFocus` notifies all subscribed listeners with the current focus state.
62
+ */
12
63
  onFocus(): void;
64
+ /**
65
+ * `isFocused` can be used to get the current focus state.
66
+ */
13
67
  isFocused(): boolean;
14
68
  }
69
+ /**
70
+ * Singleton instance of {@link FocusManager}, used to manage and observe the focus state within TanStack Query.
71
+ */
15
72
  declare const focusManager: FocusManager;
16
73
  //#endregion
17
74
  export { FocusManager, focusManager };
@@ -1 +1 @@
1
- {"version":3,"file":"focusManager.d.cts","names":[],"sources":["../../src/focusManager.ts"],"mappings":";;KAEK,YAAY;KAEZ,WACH,aAAa;cAGF,qBAAqB,aAAa;;;YAyBnC;YAMA;EAOV,iBAAiB,OAAO;EAYxB,WAAW;EAQX;EAOA;;cAWW,cAAY"}
1
+ {"version":3,"file":"focusManager.d.cts","names":[],"sources":["../../src/focusManager.ts"],"mappings":";;KAEK,YAAY;KAEZ,WACH,aAAa;;;;;;cAQF,qBAAqB,aAAa;;;YAyBnC;YAMA;;;;;;;;;;;;;;;;;;;;;;;;;;EAgCV,iBAAiB,OAAO;;;;;;;;;;;;;;;;;;;EA8BxB,WAAW;;;;EAWX;;;;EAUA;;;;;cAcW,cAAY"}
@@ -2,16 +2,73 @@ import { t as Subscribable } from "./subscribable-CbifVTKz.js";
2
2
  //#region src/focusManager.d.ts
3
3
  type Listener = (focused: boolean) => void;
4
4
  type SetupFn = (setFocused: (focused?: boolean) => void) => (() => void) | undefined;
5
+ /**
6
+ * The `FocusManager` manages the focus state within TanStack Query.
7
+ *
8
+ * It can be used to change the default event listeners or to manually change the focus state.
9
+ */
5
10
  declare class FocusManager extends Subscribable<Listener> {
6
11
  #private;
7
12
  constructor();
8
13
  protected onSubscribe(): void;
9
14
  protected onUnsubscribe(): void;
15
+ /**
16
+ * `setEventListener` can be used to set a custom event listener that will
17
+ * be used to determine the focus state. The provided `setup` function
18
+ * receives a `setFocused` callback: call it with a `boolean` to manually
19
+ * set the focus state, or with no arguments to re-evaluate the current
20
+ * focus state and notify subscribers.
21
+ *
22
+ * @example
23
+ * ```ts
24
+ * import { focusManager } from '@tanstack/query-core'
25
+ *
26
+ * focusManager.setEventListener((handleFocus) => {
27
+ * const listener = () => handleFocus()
28
+ * // Listen to visibilitychange
29
+ * if (typeof window !== 'undefined' && window.addEventListener) {
30
+ * window.addEventListener('visibilitychange', listener, false)
31
+ * }
32
+ *
33
+ * return () => {
34
+ * // Be sure to unsubscribe if a new handler is set
35
+ * window.removeEventListener('visibilitychange', listener)
36
+ * }
37
+ * })
38
+ * ```
39
+ */
10
40
  setEventListener(setup: SetupFn): void;
41
+ /**
42
+ * `setFocused` can be used to manually set the focus state. Set `undefined`
43
+ * to fall back to the default focus check.
44
+ *
45
+ * @example
46
+ * ```ts
47
+ * import { focusManager } from '@tanstack/query-core'
48
+ *
49
+ * // Set focused
50
+ * focusManager.setFocused(true)
51
+ *
52
+ * // Set unfocused
53
+ * focusManager.setFocused(false)
54
+ *
55
+ * // Fallback to the default focus check
56
+ * focusManager.setFocused(undefined)
57
+ * ```
58
+ */
11
59
  setFocused(focused?: boolean): void;
60
+ /**
61
+ * `onFocus` notifies all subscribed listeners with the current focus state.
62
+ */
12
63
  onFocus(): void;
64
+ /**
65
+ * `isFocused` can be used to get the current focus state.
66
+ */
13
67
  isFocused(): boolean;
14
68
  }
69
+ /**
70
+ * Singleton instance of {@link FocusManager}, used to manage and observe the focus state within TanStack Query.
71
+ */
15
72
  declare const focusManager: FocusManager;
16
73
  //#endregion
17
74
  export { FocusManager, focusManager };
@@ -1 +1 @@
1
- {"version":3,"file":"focusManager.d.ts","names":[],"sources":["../../src/focusManager.ts"],"mappings":";;KAEK,YAAY;KAEZ,WACH,aAAa;cAGF,qBAAqB,aAAa;;;YAyBnC;YAMA;EAOV,iBAAiB,OAAO;EAYxB,WAAW;EAQX;EAOA;;cAWW,cAAY"}
1
+ {"version":3,"file":"focusManager.d.ts","names":[],"sources":["../../src/focusManager.ts"],"mappings":";;KAEK,YAAY;KAEZ,WACH,aAAa;;;;;;cAQF,qBAAqB,aAAa;;;YAyBnC;YAMA;;;;;;;;;;;;;;;;;;;;;;;;;;EAgCV,iBAAiB,OAAO;;;;;;;;;;;;;;;;;;;EA8BxB,WAAW;;;;EAWX;;;;EAUA;;;;;cAcW,cAAY"}
@@ -4,6 +4,11 @@ import { Subscribable } from "./subscribable.js";
4
4
  var _focused = /* @__PURE__ */ new WeakMap();
5
5
  var _cleanup = /* @__PURE__ */ new WeakMap();
6
6
  var _setup = /* @__PURE__ */ new WeakMap();
7
+ /**
8
+ * The `FocusManager` manages the focus state within TanStack Query.
9
+ *
10
+ * It can be used to change the default event listeners or to manually change the focus state.
11
+ */
7
12
  var FocusManager = class extends Subscribable {
8
13
  constructor() {
9
14
  super();
@@ -30,6 +35,31 @@ var FocusManager = class extends Subscribable {
30
35
  _classPrivateFieldSet2(_cleanup, this, void 0);
31
36
  }
32
37
  }
38
+ /**
39
+ * `setEventListener` can be used to set a custom event listener that will
40
+ * be used to determine the focus state. The provided `setup` function
41
+ * receives a `setFocused` callback: call it with a `boolean` to manually
42
+ * set the focus state, or with no arguments to re-evaluate the current
43
+ * focus state and notify subscribers.
44
+ *
45
+ * @example
46
+ * ```ts
47
+ * import { focusManager } from '@tanstack/query-core'
48
+ *
49
+ * focusManager.setEventListener((handleFocus) => {
50
+ * const listener = () => handleFocus()
51
+ * // Listen to visibilitychange
52
+ * if (typeof window !== 'undefined' && window.addEventListener) {
53
+ * window.addEventListener('visibilitychange', listener, false)
54
+ * }
55
+ *
56
+ * return () => {
57
+ * // Be sure to unsubscribe if a new handler is set
58
+ * window.removeEventListener('visibilitychange', listener)
59
+ * }
60
+ * })
61
+ * ```
62
+ */
33
63
  setEventListener(setup) {
34
64
  var _classPrivateFieldGet3;
35
65
  _classPrivateFieldSet2(_setup, this, setup);
@@ -39,24 +69,51 @@ var FocusManager = class extends Subscribable {
39
69
  else this.onFocus();
40
70
  }));
41
71
  }
72
+ /**
73
+ * `setFocused` can be used to manually set the focus state. Set `undefined`
74
+ * to fall back to the default focus check.
75
+ *
76
+ * @example
77
+ * ```ts
78
+ * import { focusManager } from '@tanstack/query-core'
79
+ *
80
+ * // Set focused
81
+ * focusManager.setFocused(true)
82
+ *
83
+ * // Set unfocused
84
+ * focusManager.setFocused(false)
85
+ *
86
+ * // Fallback to the default focus check
87
+ * focusManager.setFocused(undefined)
88
+ * ```
89
+ */
42
90
  setFocused(focused) {
43
91
  if (_classPrivateFieldGet2(_focused, this) !== focused) {
44
92
  _classPrivateFieldSet2(_focused, this, focused);
45
93
  this.onFocus();
46
94
  }
47
95
  }
96
+ /**
97
+ * `onFocus` notifies all subscribed listeners with the current focus state.
98
+ */
48
99
  onFocus() {
49
100
  const isFocused = this.isFocused();
50
101
  this.listeners.forEach((listener) => {
51
102
  listener(isFocused);
52
103
  });
53
104
  }
105
+ /**
106
+ * `isFocused` can be used to get the current focus state.
107
+ */
54
108
  isFocused() {
55
109
  var _globalThis$document;
56
110
  if (typeof _classPrivateFieldGet2(_focused, this) === "boolean") return _classPrivateFieldGet2(_focused, this);
57
111
  return ((_globalThis$document = globalThis.document) === null || _globalThis$document === void 0 ? void 0 : _globalThis$document.visibilityState) !== "hidden";
58
112
  }
59
113
  };
114
+ /**
115
+ * Singleton instance of {@link FocusManager}, used to manage and observe the focus state within TanStack Query.
116
+ */
60
117
  const focusManager = new FocusManager();
61
118
  //#endregion
62
119
  export { FocusManager, focusManager };
@@ -1 +1 @@
1
- {"version":3,"file":"focusManager.js","names":[],"sources":["../../src/focusManager.ts"],"sourcesContent":["import { Subscribable } from './subscribable'\n\ntype Listener = (focused: boolean) => void\n\ntype SetupFn = (\n setFocused: (focused?: boolean) => void,\n) => (() => void) | undefined\n\nexport class FocusManager extends Subscribable<Listener> {\n #focused?: boolean\n #cleanup?: () => void\n\n #setup: SetupFn\n\n constructor() {\n super()\n this.#setup = (onFocus) => {\n // addEventListener does not exist in React Native, but window does\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n if (typeof window !== 'undefined' && window.addEventListener) {\n const listener = () => onFocus()\n // Listen to visibilitychange\n window.addEventListener('visibilitychange', listener, false)\n\n return () => {\n // Be sure to unsubscribe if a new handler is set\n window.removeEventListener('visibilitychange', listener)\n }\n }\n return\n }\n }\n\n protected onSubscribe(): void {\n if (!this.#cleanup) {\n this.setEventListener(this.#setup)\n }\n }\n\n protected onUnsubscribe() {\n if (!this.hasListeners()) {\n this.#cleanup?.()\n this.#cleanup = undefined\n }\n }\n\n setEventListener(setup: SetupFn): void {\n this.#setup = setup\n this.#cleanup?.()\n this.#cleanup = setup((focused) => {\n if (typeof focused === 'boolean') {\n this.setFocused(focused)\n } else {\n this.onFocus()\n }\n })\n }\n\n setFocused(focused?: boolean): void {\n const changed = this.#focused !== focused\n if (changed) {\n this.#focused = focused\n this.onFocus()\n }\n }\n\n onFocus(): void {\n const isFocused = this.isFocused()\n this.listeners.forEach((listener) => {\n listener(isFocused)\n })\n }\n\n isFocused(): boolean {\n if (typeof this.#focused === 'boolean') {\n return this.#focused\n }\n\n // document global can be unavailable in react native\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n return globalThis.document?.visibilityState !== 'hidden'\n }\n}\n\nexport const focusManager = new FocusManager()\n"],"mappings":";;;;;;AAQA,IAAa,eAAb,cAAkC,aAAuB;CAMvD,cAAc;EACZ,MAAM;;;;EACN,uBAAA,QAAA,OAAe,YAAY;GAGzB,IAAI,OAAO,WAAW,eAAe,OAAO,kBAAkB;IAC5D,MAAM,iBAAiB,QAAQ;IAE/B,OAAO,iBAAiB,oBAAoB,UAAU,KAAK;IAE3D,aAAa;KAEX,OAAO,oBAAoB,oBAAoB,QAAQ;IACzD;GACF;EAEF,CAAA;CACF;CAEA,cAA8B;EAC5B,IAAI,CAAA,uBAAA,UAAC,IAAA,GACH,KAAK,iBAAA,uBAAA,QAAiB,IAAA,CAAW;CAErC;CAEA,gBAA0B;EACxB,IAAI,CAAC,KAAK,aAAa,GAAG;;GACxB,CAAA,2BAAA,uBAAA,UAAA,IAAA,OAAA,QAAA,6BAAA,KAAA,KAAA,yBAAA,KAAA,IAAgB;GAChB,uBAAA,UAAA,MAAgB,KAAA,CAAA;EAClB;CACF;CAEA,iBAAiB,OAAsB;;EACrC,uBAAA,QAAA,MAAc,KAAA;EACd,CAAA,yBAAA,uBAAA,UAAA,IAAA,OAAA,QAAA,2BAAA,KAAA,KAAA,uBAAA,KAAA,IAAgB;EAChB,uBAAA,UAAA,MAAgB,OAAO,YAAY;GACjC,IAAI,OAAO,YAAY,WACrB,KAAK,WAAW,OAAO;QAEvB,KAAK,QAAQ;EAEjB,CAAC,CAAA;CACH;CAEA,WAAW,SAAyB;EAElC,IAAA,uBAAA,UADgB,IAAA,MAAkB,SACrB;GACX,uBAAA,UAAA,MAAgB,OAAA;GAChB,KAAK,QAAQ;EACf;CACF;CAEA,UAAgB;EACd,MAAM,YAAY,KAAK,UAAU;EACjC,KAAK,UAAU,SAAS,aAAa;GACnC,SAAS,SAAS;EACpB,CAAC;CACH;CAEA,YAAqB;;EACnB,IAAI,OAAA,uBAAA,UAAO,IAAA,MAAkB,WAC3B,OAAA,uBAAA,UAAO,IAAA;EAKT,SAAA,uBAAO,WAAW,cAAA,QAAA,yBAAA,KAAA,IAAA,KAAA,IAAA,qBAAU,qBAAoB;CAClD;AACF;AAEA,MAAa,eAAe,IAAI,aAAa"}
1
+ {"version":3,"file":"focusManager.js","names":[],"sources":["../../src/focusManager.ts"],"sourcesContent":["import { Subscribable } from './subscribable'\n\ntype Listener = (focused: boolean) => void\n\ntype SetupFn = (\n setFocused: (focused?: boolean) => void,\n) => (() => void) | undefined\n\n/**\n * The `FocusManager` manages the focus state within TanStack Query.\n *\n * It can be used to change the default event listeners or to manually change the focus state.\n */\nexport class FocusManager extends Subscribable<Listener> {\n #focused?: boolean\n #cleanup?: () => void\n\n #setup: SetupFn\n\n constructor() {\n super()\n this.#setup = (onFocus) => {\n // addEventListener does not exist in React Native, but window does\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n if (typeof window !== 'undefined' && window.addEventListener) {\n const listener = () => onFocus()\n // Listen to visibilitychange\n window.addEventListener('visibilitychange', listener, false)\n\n return () => {\n // Be sure to unsubscribe if a new handler is set\n window.removeEventListener('visibilitychange', listener)\n }\n }\n return\n }\n }\n\n protected onSubscribe(): void {\n if (!this.#cleanup) {\n this.setEventListener(this.#setup)\n }\n }\n\n protected onUnsubscribe() {\n if (!this.hasListeners()) {\n this.#cleanup?.()\n this.#cleanup = undefined\n }\n }\n\n /**\n * `setEventListener` can be used to set a custom event listener that will\n * be used to determine the focus state. The provided `setup` function\n * receives a `setFocused` callback: call it with a `boolean` to manually\n * set the focus state, or with no arguments to re-evaluate the current\n * focus state and notify subscribers.\n *\n * @example\n * ```ts\n * import { focusManager } from '@tanstack/query-core'\n *\n * focusManager.setEventListener((handleFocus) => {\n * const listener = () => handleFocus()\n * // Listen to visibilitychange\n * if (typeof window !== 'undefined' && window.addEventListener) {\n * window.addEventListener('visibilitychange', listener, false)\n * }\n *\n * return () => {\n * // Be sure to unsubscribe if a new handler is set\n * window.removeEventListener('visibilitychange', listener)\n * }\n * })\n * ```\n */\n setEventListener(setup: SetupFn): void {\n this.#setup = setup\n this.#cleanup?.()\n this.#cleanup = setup((focused) => {\n if (typeof focused === 'boolean') {\n this.setFocused(focused)\n } else {\n this.onFocus()\n }\n })\n }\n\n /**\n * `setFocused` can be used to manually set the focus state. Set `undefined`\n * to fall back to the default focus check.\n *\n * @example\n * ```ts\n * import { focusManager } from '@tanstack/query-core'\n *\n * // Set focused\n * focusManager.setFocused(true)\n *\n * // Set unfocused\n * focusManager.setFocused(false)\n *\n * // Fallback to the default focus check\n * focusManager.setFocused(undefined)\n * ```\n */\n setFocused(focused?: boolean): void {\n const changed = this.#focused !== focused\n if (changed) {\n this.#focused = focused\n this.onFocus()\n }\n }\n\n /**\n * `onFocus` notifies all subscribed listeners with the current focus state.\n */\n onFocus(): void {\n const isFocused = this.isFocused()\n this.listeners.forEach((listener) => {\n listener(isFocused)\n })\n }\n\n /**\n * `isFocused` can be used to get the current focus state.\n */\n isFocused(): boolean {\n if (typeof this.#focused === 'boolean') {\n return this.#focused\n }\n\n // document global can be unavailable in react native\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n return globalThis.document?.visibilityState !== 'hidden'\n }\n}\n\n/**\n * Singleton instance of {@link FocusManager}, used to manage and observe the focus state within TanStack Query.\n */\nexport const focusManager = new FocusManager()\n"],"mappings":";;;;;;;;;;;AAaA,IAAa,eAAb,cAAkC,aAAuB;CAMvD,cAAc;EACZ,MAAM;;;;EACN,uBAAA,QAAA,OAAe,YAAY;GAGzB,IAAI,OAAO,WAAW,eAAe,OAAO,kBAAkB;IAC5D,MAAM,iBAAiB,QAAQ;IAE/B,OAAO,iBAAiB,oBAAoB,UAAU,KAAK;IAE3D,aAAa;KAEX,OAAO,oBAAoB,oBAAoB,QAAQ;IACzD;GACF;EAEF,CAAA;CACF;CAEA,cAA8B;EAC5B,IAAI,CAAA,uBAAA,UAAC,IAAA,GACH,KAAK,iBAAA,uBAAA,QAAiB,IAAA,CAAW;CAErC;CAEA,gBAA0B;EACxB,IAAI,CAAC,KAAK,aAAa,GAAG;;GACxB,CAAA,2BAAA,uBAAA,UAAA,IAAA,OAAA,QAAA,6BAAA,KAAA,KAAA,yBAAA,KAAA,IAAgB;GAChB,uBAAA,UAAA,MAAgB,KAAA,CAAA;EAClB;CACF;;;;;;;;;;;;;;;;;;;;;;;;;;CA2BA,iBAAiB,OAAsB;;EACrC,uBAAA,QAAA,MAAc,KAAA;EACd,CAAA,yBAAA,uBAAA,UAAA,IAAA,OAAA,QAAA,2BAAA,KAAA,KAAA,uBAAA,KAAA,IAAgB;EAChB,uBAAA,UAAA,MAAgB,OAAO,YAAY;GACjC,IAAI,OAAO,YAAY,WACrB,KAAK,WAAW,OAAO;QAEvB,KAAK,QAAQ;EAEjB,CAAC,CAAA;CACH;;;;;;;;;;;;;;;;;;;CAoBA,WAAW,SAAyB;EAElC,IAAA,uBAAA,UADgB,IAAA,MAAkB,SACrB;GACX,uBAAA,UAAA,MAAgB,OAAA;GAChB,KAAK,QAAQ;EACf;CACF;;;;CAKA,UAAgB;EACd,MAAM,YAAY,KAAK,UAAU;EACjC,KAAK,UAAU,SAAS,aAAa;GACnC,SAAS,SAAS;EACpB,CAAC;CACH;;;;CAKA,YAAqB;;EACnB,IAAI,OAAA,uBAAA,UAAO,IAAA,MAAkB,WAC3B,OAAA,uBAAA,UAAO,IAAA;EAKT,SAAA,uBAAO,WAAW,cAAA,QAAA,yBAAA,KAAA,IAAA,KAAA,IAAA,qBAAU,qBAAoB;CAClD;AACF;;;;AAKA,MAAa,eAAe,IAAI,aAAa"}