@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.
- package/build/legacy/environmentManager.cjs +15 -1
- package/build/legacy/environmentManager.cjs.map +1 -1
- package/build/legacy/environmentManager.d.cts +15 -1
- package/build/legacy/environmentManager.d.cts.map +1 -1
- package/build/legacy/environmentManager.d.ts +15 -1
- package/build/legacy/environmentManager.d.ts.map +1 -1
- package/build/legacy/environmentManager.js +15 -1
- package/build/legacy/environmentManager.js.map +1 -1
- package/build/legacy/focusManager.cjs +57 -0
- package/build/legacy/focusManager.cjs.map +1 -1
- package/build/legacy/focusManager.d.cts +57 -0
- package/build/legacy/focusManager.d.cts.map +1 -1
- package/build/legacy/focusManager.d.ts +57 -0
- package/build/legacy/focusManager.d.ts.map +1 -1
- package/build/legacy/focusManager.js +57 -0
- package/build/legacy/focusManager.js.map +1 -1
- package/build/legacy/{hydration-Bjs0MSgg.d.ts → hydration-Cq7QYAzB.d.ts} +1424 -7
- package/build/legacy/hydration-Cq7QYAzB.d.ts.map +1 -0
- package/build/legacy/{hydration-DWGr3cFC.d.cts → hydration-DwR10Hi-.d.cts} +1424 -7
- package/build/legacy/hydration-DwR10Hi-.d.cts.map +1 -0
- package/build/legacy/hydration.cjs +57 -4
- package/build/legacy/hydration.cjs.map +1 -1
- package/build/legacy/hydration.d.cts +1 -1
- package/build/legacy/hydration.d.ts +1 -1
- package/build/legacy/hydration.js +57 -4
- package/build/legacy/hydration.js.map +1 -1
- package/build/legacy/index.cjs.map +1 -1
- package/build/legacy/index.d.cts +5 -5
- package/build/legacy/index.d.ts +5 -5
- package/build/legacy/index.js.map +1 -1
- package/build/legacy/infiniteQueryBehavior.d.cts +1 -1
- package/build/legacy/infiniteQueryBehavior.d.ts +1 -1
- package/build/legacy/infiniteQueryObserver.cjs +67 -0
- package/build/legacy/infiniteQueryObserver.cjs.map +1 -1
- package/build/legacy/infiniteQueryObserver.d.cts +68 -1
- package/build/legacy/infiniteQueryObserver.d.cts.map +1 -1
- package/build/legacy/infiniteQueryObserver.d.ts +68 -1
- package/build/legacy/infiniteQueryObserver.d.ts.map +1 -1
- package/build/legacy/infiniteQueryObserver.js +67 -0
- package/build/legacy/infiniteQueryObserver.js.map +1 -1
- package/build/legacy/mutation.cjs +74 -0
- package/build/legacy/mutation.cjs.map +1 -1
- package/build/legacy/mutation.d.cts +1 -1
- package/build/legacy/mutation.d.ts +1 -1
- package/build/legacy/mutation.js +74 -0
- package/build/legacy/mutation.js.map +1 -1
- package/build/legacy/mutationCache.cjs +74 -0
- package/build/legacy/mutationCache.cjs.map +1 -1
- package/build/legacy/mutationCache.d.cts +1 -1
- package/build/legacy/mutationCache.d.ts +1 -1
- package/build/legacy/mutationCache.js +74 -0
- package/build/legacy/mutationCache.js.map +1 -1
- package/build/legacy/mutationObserver.cjs +71 -0
- package/build/legacy/mutationObserver.cjs.map +1 -1
- package/build/legacy/mutationObserver.d.cts +1 -1
- package/build/legacy/mutationObserver.d.ts +1 -1
- package/build/legacy/mutationObserver.js +71 -0
- package/build/legacy/mutationObserver.js.map +1 -1
- package/build/legacy/notifyManager.cjs +45 -1
- package/build/legacy/notifyManager.cjs.map +1 -1
- package/build/legacy/notifyManager.d.cts +83 -2
- package/build/legacy/notifyManager.d.cts.map +1 -1
- package/build/legacy/notifyManager.d.ts +83 -2
- package/build/legacy/notifyManager.d.ts.map +1 -1
- package/build/legacy/notifyManager.js +45 -1
- package/build/legacy/notifyManager.js.map +1 -1
- package/build/legacy/onlineManager.cjs +47 -0
- package/build/legacy/onlineManager.cjs.map +1 -1
- package/build/legacy/onlineManager.d.cts +47 -0
- package/build/legacy/onlineManager.d.cts.map +1 -1
- package/build/legacy/onlineManager.d.ts +47 -0
- package/build/legacy/onlineManager.d.ts.map +1 -1
- package/build/legacy/onlineManager.js +47 -0
- package/build/legacy/onlineManager.js.map +1 -1
- package/build/legacy/queriesObserver.cjs +64 -0
- package/build/legacy/queriesObserver.cjs.map +1 -1
- package/build/legacy/queriesObserver.d.cts +73 -1
- package/build/legacy/queriesObserver.d.cts.map +1 -1
- package/build/legacy/queriesObserver.d.ts +73 -1
- package/build/legacy/queriesObserver.d.ts.map +1 -1
- package/build/legacy/queriesObserver.js +64 -0
- package/build/legacy/queriesObserver.js.map +1 -1
- package/build/legacy/query.cjs +141 -0
- package/build/legacy/query.cjs.map +1 -1
- package/build/legacy/query.d.cts +1 -1
- package/build/legacy/query.d.ts +1 -1
- package/build/legacy/query.js +141 -0
- package/build/legacy/query.js.map +1 -1
- package/build/legacy/queryCache.cjs +120 -0
- package/build/legacy/queryCache.cjs.map +1 -1
- package/build/legacy/queryCache.d.cts +1 -1
- package/build/legacy/queryCache.d.ts +1 -1
- package/build/legacy/queryCache.js +120 -0
- package/build/legacy/queryCache.js.map +1 -1
- package/build/legacy/queryClient.cjs +363 -0
- package/build/legacy/queryClient.cjs.map +1 -1
- package/build/legacy/queryClient.d.cts +1 -1
- package/build/legacy/queryClient.d.ts +1 -1
- package/build/legacy/queryClient.js +363 -0
- package/build/legacy/queryClient.js.map +1 -1
- package/build/legacy/queryObserver.cjs +116 -2
- package/build/legacy/queryObserver.cjs.map +1 -1
- package/build/legacy/queryObserver.d.cts +1 -1
- package/build/legacy/queryObserver.d.ts +1 -1
- package/build/legacy/queryObserver.js +116 -2
- package/build/legacy/queryObserver.js.map +1 -1
- package/build/legacy/retryer.cjs +18 -0
- package/build/legacy/retryer.cjs.map +1 -1
- package/build/legacy/retryer.d.cts +1 -1
- package/build/legacy/retryer.d.ts +1 -1
- package/build/legacy/retryer.js +18 -0
- package/build/legacy/retryer.js.map +1 -1
- package/build/legacy/streamedQuery.cjs +10 -1
- package/build/legacy/streamedQuery.cjs.map +1 -1
- package/build/legacy/streamedQuery.d.cts +26 -2
- package/build/legacy/streamedQuery.d.cts.map +1 -1
- package/build/legacy/streamedQuery.d.ts +26 -2
- package/build/legacy/streamedQuery.d.ts.map +1 -1
- package/build/legacy/streamedQuery.js +10 -1
- package/build/legacy/streamedQuery.js.map +1 -1
- package/build/legacy/timeoutManager.cjs +99 -0
- package/build/legacy/timeoutManager.cjs.map +1 -1
- package/build/legacy/timeoutManager.d.cts +105 -0
- package/build/legacy/timeoutManager.d.cts.map +1 -1
- package/build/legacy/timeoutManager.d.ts +105 -0
- package/build/legacy/timeoutManager.d.ts.map +1 -1
- package/build/legacy/timeoutManager.js +99 -0
- package/build/legacy/timeoutManager.js.map +1 -1
- package/build/legacy/types.cjs.map +1 -1
- package/build/legacy/types.d.cts +1 -1
- package/build/legacy/types.d.ts +1 -1
- package/build/legacy/types.js.map +1 -1
- package/build/legacy/utils.cjs +76 -0
- package/build/legacy/utils.cjs.map +1 -1
- package/build/legacy/utils.d.cts +1 -1
- package/build/legacy/utils.d.ts +1 -1
- package/build/legacy/utils.js +76 -0
- package/build/legacy/utils.js.map +1 -1
- package/build/modern/environmentManager.cjs +15 -1
- package/build/modern/environmentManager.cjs.map +1 -1
- package/build/modern/environmentManager.d.cts +15 -1
- package/build/modern/environmentManager.d.cts.map +1 -1
- package/build/modern/environmentManager.d.ts +15 -1
- package/build/modern/environmentManager.d.ts.map +1 -1
- package/build/modern/environmentManager.js +15 -1
- package/build/modern/environmentManager.js.map +1 -1
- package/build/modern/focusManager.cjs +57 -0
- package/build/modern/focusManager.cjs.map +1 -1
- package/build/modern/focusManager.d.cts +57 -0
- package/build/modern/focusManager.d.cts.map +1 -1
- package/build/modern/focusManager.d.ts +57 -0
- package/build/modern/focusManager.d.ts.map +1 -1
- package/build/modern/focusManager.js +57 -0
- package/build/modern/focusManager.js.map +1 -1
- package/build/modern/{hydration-Bjs0MSgg.d.ts → hydration-Cq7QYAzB.d.ts} +1424 -7
- package/build/modern/hydration-Cq7QYAzB.d.ts.map +1 -0
- package/build/modern/{hydration-DWGr3cFC.d.cts → hydration-DwR10Hi-.d.cts} +1424 -7
- package/build/modern/hydration-DwR10Hi-.d.cts.map +1 -0
- package/build/modern/hydration.cjs +57 -4
- package/build/modern/hydration.cjs.map +1 -1
- package/build/modern/hydration.d.cts +1 -1
- package/build/modern/hydration.d.ts +1 -1
- package/build/modern/hydration.js +57 -4
- package/build/modern/hydration.js.map +1 -1
- package/build/modern/index.cjs.map +1 -1
- package/build/modern/index.d.cts +5 -5
- package/build/modern/index.d.ts +5 -5
- package/build/modern/index.js.map +1 -1
- package/build/modern/infiniteQueryBehavior.d.cts +1 -1
- package/build/modern/infiniteQueryBehavior.d.ts +1 -1
- package/build/modern/infiniteQueryObserver.cjs +67 -0
- package/build/modern/infiniteQueryObserver.cjs.map +1 -1
- package/build/modern/infiniteQueryObserver.d.cts +68 -1
- package/build/modern/infiniteQueryObserver.d.cts.map +1 -1
- package/build/modern/infiniteQueryObserver.d.ts +68 -1
- package/build/modern/infiniteQueryObserver.d.ts.map +1 -1
- package/build/modern/infiniteQueryObserver.js +67 -0
- package/build/modern/infiniteQueryObserver.js.map +1 -1
- package/build/modern/mutation.cjs +74 -0
- package/build/modern/mutation.cjs.map +1 -1
- package/build/modern/mutation.d.cts +1 -1
- package/build/modern/mutation.d.ts +1 -1
- package/build/modern/mutation.js +74 -0
- package/build/modern/mutation.js.map +1 -1
- package/build/modern/mutationCache.cjs +74 -0
- package/build/modern/mutationCache.cjs.map +1 -1
- package/build/modern/mutationCache.d.cts +1 -1
- package/build/modern/mutationCache.d.ts +1 -1
- package/build/modern/mutationCache.js +74 -0
- package/build/modern/mutationCache.js.map +1 -1
- package/build/modern/mutationObserver.cjs +71 -0
- package/build/modern/mutationObserver.cjs.map +1 -1
- package/build/modern/mutationObserver.d.cts +1 -1
- package/build/modern/mutationObserver.d.ts +1 -1
- package/build/modern/mutationObserver.js +71 -0
- package/build/modern/mutationObserver.js.map +1 -1
- package/build/modern/notifyManager.cjs +45 -1
- package/build/modern/notifyManager.cjs.map +1 -1
- package/build/modern/notifyManager.d.cts +83 -2
- package/build/modern/notifyManager.d.cts.map +1 -1
- package/build/modern/notifyManager.d.ts +83 -2
- package/build/modern/notifyManager.d.ts.map +1 -1
- package/build/modern/notifyManager.js +45 -1
- package/build/modern/notifyManager.js.map +1 -1
- package/build/modern/onlineManager.cjs +47 -0
- package/build/modern/onlineManager.cjs.map +1 -1
- package/build/modern/onlineManager.d.cts +47 -0
- package/build/modern/onlineManager.d.cts.map +1 -1
- package/build/modern/onlineManager.d.ts +47 -0
- package/build/modern/onlineManager.d.ts.map +1 -1
- package/build/modern/onlineManager.js +47 -0
- package/build/modern/onlineManager.js.map +1 -1
- package/build/modern/queriesObserver.cjs +64 -0
- package/build/modern/queriesObserver.cjs.map +1 -1
- package/build/modern/queriesObserver.d.cts +73 -1
- package/build/modern/queriesObserver.d.cts.map +1 -1
- package/build/modern/queriesObserver.d.ts +73 -1
- package/build/modern/queriesObserver.d.ts.map +1 -1
- package/build/modern/queriesObserver.js +64 -0
- package/build/modern/queriesObserver.js.map +1 -1
- package/build/modern/query.cjs +141 -0
- package/build/modern/query.cjs.map +1 -1
- package/build/modern/query.d.cts +1 -1
- package/build/modern/query.d.ts +1 -1
- package/build/modern/query.js +141 -0
- package/build/modern/query.js.map +1 -1
- package/build/modern/queryCache.cjs +120 -0
- package/build/modern/queryCache.cjs.map +1 -1
- package/build/modern/queryCache.d.cts +1 -1
- package/build/modern/queryCache.d.ts +1 -1
- package/build/modern/queryCache.js +120 -0
- package/build/modern/queryCache.js.map +1 -1
- package/build/modern/queryClient.cjs +363 -0
- package/build/modern/queryClient.cjs.map +1 -1
- package/build/modern/queryClient.d.cts +1 -1
- package/build/modern/queryClient.d.ts +1 -1
- package/build/modern/queryClient.js +363 -0
- package/build/modern/queryClient.js.map +1 -1
- package/build/modern/queryObserver.cjs +116 -2
- package/build/modern/queryObserver.cjs.map +1 -1
- package/build/modern/queryObserver.d.cts +1 -1
- package/build/modern/queryObserver.d.ts +1 -1
- package/build/modern/queryObserver.js +116 -2
- package/build/modern/queryObserver.js.map +1 -1
- package/build/modern/retryer.cjs +18 -0
- package/build/modern/retryer.cjs.map +1 -1
- package/build/modern/retryer.d.cts +1 -1
- package/build/modern/retryer.d.ts +1 -1
- package/build/modern/retryer.js +18 -0
- package/build/modern/retryer.js.map +1 -1
- package/build/modern/streamedQuery.cjs +10 -1
- package/build/modern/streamedQuery.cjs.map +1 -1
- package/build/modern/streamedQuery.d.cts +26 -2
- package/build/modern/streamedQuery.d.cts.map +1 -1
- package/build/modern/streamedQuery.d.ts +26 -2
- package/build/modern/streamedQuery.d.ts.map +1 -1
- package/build/modern/streamedQuery.js +10 -1
- package/build/modern/streamedQuery.js.map +1 -1
- package/build/modern/timeoutManager.cjs +99 -0
- package/build/modern/timeoutManager.cjs.map +1 -1
- package/build/modern/timeoutManager.d.cts +105 -0
- package/build/modern/timeoutManager.d.cts.map +1 -1
- package/build/modern/timeoutManager.d.ts +105 -0
- package/build/modern/timeoutManager.d.ts.map +1 -1
- package/build/modern/timeoutManager.js +99 -0
- package/build/modern/timeoutManager.js.map +1 -1
- package/build/modern/types.cjs.map +1 -1
- package/build/modern/types.d.cts +1 -1
- package/build/modern/types.d.ts +1 -1
- package/build/modern/types.js.map +1 -1
- package/build/modern/utils.cjs +76 -0
- package/build/modern/utils.cjs.map +1 -1
- package/build/modern/utils.d.cts +1 -1
- package/build/modern/utils.d.ts +1 -1
- package/build/modern/utils.js +76 -0
- package/build/modern/utils.js.map +1 -1
- package/package.json +9 -9
- package/src/environmentManager.ts +15 -1
- package/src/focusManager.ts +57 -0
- package/src/hydration.ts +82 -16
- package/src/index.ts +3 -0
- package/src/infiniteQueryObserver.ts +67 -0
- package/src/mutation.ts +108 -0
- package/src/mutationCache.ts +91 -0
- package/src/mutationObserver.ts +71 -0
- package/src/notifyManager.ts +46 -1
- package/src/onlineManager.ts +47 -0
- package/src/queriesObserver.ts +72 -0
- package/src/query.ts +193 -0
- package/src/queryCache.ts +134 -0
- package/src/queryClient.ts +369 -0
- package/src/queryObserver.ts +117 -4
- package/src/retryer.ts +18 -0
- package/src/streamedQuery.ts +25 -1
- package/src/timeoutManager.ts +105 -0
- package/src/types.ts +147 -5
- package/src/utils.ts +107 -0
- package/build/legacy/hydration-Bjs0MSgg.d.ts.map +0 -1
- package/build/legacy/hydration-DWGr3cFC.d.cts.map +0 -1
- package/build/modern/hydration-Bjs0MSgg.d.ts.map +0 -1
- 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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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":"
|
|
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
|
|
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
|
|
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":"
|
|
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"}
|