@tanstack/angular-query-devtools 5.0.0-rc.4 → 5.0.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/devtools-panel/index.mjs +1 -5
- package/devtools-panel/inject-devtools-panel.mjs +75 -82
- package/devtools-panel/inject-devtools-panel.mjs.map +1 -1
- package/devtools-panel/production/index.mjs +1 -5
- package/devtools-panel/stub.d.ts +4 -0
- package/devtools-panel/stub.mjs +10 -8
- package/devtools-panel/stub.mjs.map +1 -1
- package/devtools-panel/types.d.ts +18 -6
- package/index.mjs +1 -5
- package/package.json +3 -4
- package/production/index.mjs +1 -5
- package/stub.d.ts +4 -0
- package/stub.mjs +9 -5
- package/stub.mjs.map +1 -1
- package/types.d.ts +5 -3
- package/with-devtools.mjs +112 -95
- package/with-devtools.mjs.map +1 -1
- package/devtools-panel/index.mjs.map +0 -1
- package/devtools-panel/production/index.mjs.map +0 -1
- package/index.mjs.map +0 -1
- package/production/index.mjs.map +0 -1
package/devtools-panel/index.mjs
CHANGED
|
@@ -1,84 +1,77 @@
|
|
|
1
|
-
import { assertInInjectionContext, inject, DestroyRef, PLATFORM_ID, computed, effect, untracked } from "@angular/core";
|
|
2
|
-
import { QueryClient, onlineManager } from "@tanstack/query-core";
|
|
3
1
|
import { isPlatformBrowser } from "@angular/common";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
destroyRef.onDestroy(destroy);
|
|
77
|
-
return {
|
|
78
|
-
destroy
|
|
79
|
-
};
|
|
2
|
+
import { DestroyRef, PLATFORM_ID, assertInInjectionContext, computed, effect, inject, untracked } from "@angular/core";
|
|
3
|
+
import { QueryClient, onlineManager } from "@tanstack/angular-query";
|
|
4
|
+
// src/devtools-panel/inject-devtools-panel.ts
|
|
5
|
+
/**
|
|
6
|
+
* Inject a TanStack Query devtools panel and render it in the DOM.
|
|
7
|
+
*
|
|
8
|
+
* Devtools panel allows programmatic control over the devtools, for example if you want to render
|
|
9
|
+
* the devtools as part of your own devtools.
|
|
10
|
+
*
|
|
11
|
+
* Consider `withDevtools` instead if you don't need this.
|
|
12
|
+
* @param injectDevtoolsPanelFn - A function that returns devtools panel options.
|
|
13
|
+
* @returns DevtoolsPanelRef
|
|
14
|
+
* @see https://tanstack.com/query/v5/docs/framework/angular/devtools
|
|
15
|
+
*/
|
|
16
|
+
var injectDevtoolsPanel = (injectDevtoolsPanelFn) => {
|
|
17
|
+
assertInInjectionContext(injectDevtoolsPanel);
|
|
18
|
+
const destroyRef = inject(DestroyRef);
|
|
19
|
+
const isBrowser = isPlatformBrowser(inject(PLATFORM_ID));
|
|
20
|
+
const injectedClient = inject(QueryClient, { optional: true });
|
|
21
|
+
const queryOptions = computed(injectDevtoolsPanelFn);
|
|
22
|
+
let devtools = null;
|
|
23
|
+
let optionsEffect;
|
|
24
|
+
let manuallyDestroyed = false;
|
|
25
|
+
let loadGeneration = 0;
|
|
26
|
+
const unmount = () => {
|
|
27
|
+
devtools?.unmount();
|
|
28
|
+
devtools = null;
|
|
29
|
+
};
|
|
30
|
+
const destroy = () => {
|
|
31
|
+
if (manuallyDestroyed) return;
|
|
32
|
+
manuallyDestroyed = true;
|
|
33
|
+
loadGeneration++;
|
|
34
|
+
optionsEffect?.destroy();
|
|
35
|
+
unmount();
|
|
36
|
+
};
|
|
37
|
+
if (!isBrowser) return { destroy };
|
|
38
|
+
optionsEffect = effect(() => {
|
|
39
|
+
const generation = ++loadGeneration;
|
|
40
|
+
const { client = injectedClient, errorTypes = [], theme, styleNonce, shadowDOMTarget, hideDisabledQueries, onClose, hostElement } = queryOptions();
|
|
41
|
+
untracked(() => {
|
|
42
|
+
if (!client) throw new Error("No QueryClient found");
|
|
43
|
+
if (!devtools && hostElement) import("@tanstack/query-devtools").then((queryDevtools) => {
|
|
44
|
+
if (manuallyDestroyed || destroyRef.destroyed || generation !== loadGeneration) return;
|
|
45
|
+
devtools = new queryDevtools.TanstackQueryDevtoolsPanel({
|
|
46
|
+
client,
|
|
47
|
+
queryFlavor: "Angular Query",
|
|
48
|
+
version: "5",
|
|
49
|
+
buttonPosition: "bottom-left",
|
|
50
|
+
position: "bottom",
|
|
51
|
+
initialIsOpen: true,
|
|
52
|
+
errorTypes,
|
|
53
|
+
theme,
|
|
54
|
+
styleNonce,
|
|
55
|
+
shadowDOMTarget,
|
|
56
|
+
hideDisabledQueries,
|
|
57
|
+
onClose,
|
|
58
|
+
onlineManager
|
|
59
|
+
});
|
|
60
|
+
devtools.mount(hostElement.nativeElement);
|
|
61
|
+
}).catch((error) => {
|
|
62
|
+
console.error("Failed to load @tanstack/query-devtools.", error);
|
|
63
|
+
});
|
|
64
|
+
else if (devtools && hostElement) {
|
|
65
|
+
devtools.setClient(client);
|
|
66
|
+
devtools.setErrorTypes(errorTypes);
|
|
67
|
+
devtools.setTheme(theme);
|
|
68
|
+
devtools.setOnClose(onClose ?? (() => {}));
|
|
69
|
+
} else if (devtools && !hostElement) unmount();
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
destroyRef.onDestroy(destroy);
|
|
73
|
+
return { destroy };
|
|
80
74
|
};
|
|
81
|
-
export {
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
//# sourceMappingURL=inject-devtools-panel.mjs.map
|
|
75
|
+
export { injectDevtoolsPanel };
|
|
76
|
+
|
|
77
|
+
//# sourceMappingURL=inject-devtools-panel.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"inject-devtools-panel.mjs","sources":["../../src/devtools-panel/inject-devtools-panel.ts"],"sourcesContent":["import {\n DestroyRef,\n PLATFORM_ID,\n assertInInjectionContext,\n computed,\n effect,\n inject,\n untracked,\n} from '@angular/core'\nimport { QueryClient, onlineManager } from '@tanstack/query
|
|
1
|
+
{"version":3,"file":"inject-devtools-panel.mjs","names":[],"sources":["../../src/devtools-panel/inject-devtools-panel.ts"],"sourcesContent":["import { isPlatformBrowser } from '@angular/common'\nimport {\n DestroyRef,\n PLATFORM_ID,\n assertInInjectionContext,\n computed,\n effect,\n inject,\n untracked,\n} from '@angular/core'\nimport { QueryClient, onlineManager } from '@tanstack/angular-query'\nimport type { TanstackQueryDevtoolsPanel } from '@tanstack/query-devtools'\nimport type { DevtoolsPanelOptions, InjectDevtoolsPanel } from './types'\n\n/**\n * Inject a TanStack Query devtools panel and render it in the DOM.\n *\n * Devtools panel allows programmatic control over the devtools, for example if you want to render\n * the devtools as part of your own devtools.\n *\n * Consider `withDevtools` instead if you don't need this.\n * @param injectDevtoolsPanelFn - A function that returns devtools panel options.\n * @returns DevtoolsPanelRef\n * @see https://tanstack.com/query/v5/docs/framework/angular/devtools\n */\nexport const injectDevtoolsPanel: InjectDevtoolsPanel = (\n injectDevtoolsPanelFn: () => DevtoolsPanelOptions,\n) => {\n assertInInjectionContext(injectDevtoolsPanel)\n const destroyRef = inject(DestroyRef)\n const isBrowser = isPlatformBrowser(inject(PLATFORM_ID))\n const injectedClient = inject(QueryClient, { optional: true })\n\n const queryOptions = computed(injectDevtoolsPanelFn)\n let devtools: TanstackQueryDevtoolsPanel | null = null\n // oxlint-disable-next-line prefer-const -- assigned after the server early return, but `destroy` may run before it\n let optionsEffect: ReturnType<typeof effect> | undefined\n let manuallyDestroyed = false\n let loadGeneration = 0\n\n const unmount = () => {\n devtools?.unmount()\n devtools = null\n }\n\n const destroy = () => {\n if (manuallyDestroyed) return\n\n manuallyDestroyed = true\n loadGeneration++\n optionsEffect?.destroy()\n unmount()\n }\n\n if (!isBrowser)\n return {\n destroy,\n }\n\n optionsEffect = effect(() => {\n const generation = ++loadGeneration\n const {\n client = injectedClient,\n errorTypes = [],\n theme,\n styleNonce,\n shadowDOMTarget,\n hideDisabledQueries,\n onClose,\n hostElement,\n } = queryOptions()\n\n untracked(() => {\n if (!client) throw new Error('No QueryClient found')\n if (!devtools && hostElement) {\n import('@tanstack/query-devtools')\n .then((queryDevtools) => {\n if (\n manuallyDestroyed ||\n destroyRef.destroyed ||\n generation !== loadGeneration\n ) {\n return\n }\n\n devtools = new queryDevtools.TanstackQueryDevtoolsPanel({\n client,\n queryFlavor: 'Angular Query',\n version: '5',\n buttonPosition: 'bottom-left',\n position: 'bottom',\n initialIsOpen: true,\n errorTypes,\n theme,\n styleNonce,\n shadowDOMTarget,\n hideDisabledQueries,\n onClose,\n onlineManager,\n })\n devtools.mount(hostElement.nativeElement)\n })\n .catch((error) => {\n console.error('Failed to load @tanstack/query-devtools.', error)\n })\n } else if (devtools && hostElement) {\n devtools.setClient(client)\n devtools.setErrorTypes(errorTypes)\n devtools.setTheme(theme)\n devtools.setOnClose(onClose ?? (() => {}))\n } else if (devtools && !hostElement) {\n unmount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,kBAAkB,CAAC,EAAE;GAC3C,OAAO,IAAI,YAAY,CAAC,aACtB,QAAQ;EAEZ,CAAC;CACH,CAAC;CAED,WAAW,UAAU,OAAO;CAE5B,OAAO,EACL,QACF;AACF"}
|
package/devtools-panel/stub.d.ts
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
1
|
import { DevtoolsPanelOptions, DevtoolsPanelRef, InjectDevtoolsPanel } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Replaces `injectDevtoolsPanel` in production builds: returns a panel whose `destroy` does nothing.
|
|
4
|
+
* @returns A devtools panel that does nothing.
|
|
5
|
+
*/
|
|
2
6
|
export declare const injectDevtoolsPanel: InjectDevtoolsPanel;
|
|
3
7
|
export type { InjectDevtoolsPanel, DevtoolsPanelOptions, DevtoolsPanelRef };
|
package/devtools-panel/stub.mjs
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import { noop } from "@tanstack/query
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
};
|
|
8
|
-
|
|
1
|
+
import { noop } from "@tanstack/angular-query";
|
|
2
|
+
// src/devtools-panel/stub.ts
|
|
3
|
+
/**
|
|
4
|
+
* Replaces `injectDevtoolsPanel` in production builds: returns a panel whose `destroy` does nothing.
|
|
5
|
+
* @returns A devtools panel that does nothing.
|
|
6
|
+
*/
|
|
7
|
+
var injectDevtoolsPanel = () => ({ destroy: noop });
|
|
8
|
+
export { injectDevtoolsPanel };
|
|
9
|
+
|
|
10
|
+
//# sourceMappingURL=stub.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stub.mjs","sources":["../../src/devtools-panel/stub.ts"],"sourcesContent":["import { noop } from '@tanstack/query
|
|
1
|
+
{"version":3,"file":"stub.mjs","names":[],"sources":["../../src/devtools-panel/stub.ts"],"sourcesContent":["import { noop } from '@tanstack/angular-query'\nimport type {\n DevtoolsPanelOptions,\n DevtoolsPanelRef,\n InjectDevtoolsPanel,\n} from './types'\n\n/**\n * Replaces `injectDevtoolsPanel` in production builds: returns a panel whose `destroy` does nothing.\n * @returns A devtools panel that does nothing.\n */\nexport const injectDevtoolsPanel: InjectDevtoolsPanel = () => ({\n destroy: noop,\n})\n\nexport type { InjectDevtoolsPanel, DevtoolsPanelOptions, DevtoolsPanelRef }\n"],"mappings":";;;;;;AAWA,IAAa,6BAAkD,EAC7D,SAAS,KACX"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { DevtoolsErrorType, Theme } from '@tanstack/query-devtools';
|
|
2
1
|
import { ElementRef } from '@angular/core';
|
|
3
|
-
import { QueryClient } from '@tanstack/query
|
|
2
|
+
import { QueryClient } from '@tanstack/angular-query';
|
|
3
|
+
import { DevtoolsErrorType, Theme } from '@tanstack/query-devtools';
|
|
4
4
|
/**
|
|
5
5
|
* A devtools panel, which can be manually destroyed.
|
|
6
6
|
*/
|
|
@@ -10,6 +10,9 @@ export interface DevtoolsPanelRef {
|
|
|
10
10
|
*/
|
|
11
11
|
destroy: () => void;
|
|
12
12
|
}
|
|
13
|
+
/**
|
|
14
|
+
* Options for the devtools panel, returned by the function passed to `injectDevtoolsPanel`.
|
|
15
|
+
*/
|
|
13
16
|
export interface DevtoolsPanelOptions {
|
|
14
17
|
/**
|
|
15
18
|
* Custom instance of QueryClient
|
|
@@ -20,8 +23,9 @@ export interface DevtoolsPanelOptions {
|
|
|
20
23
|
*/
|
|
21
24
|
errorTypes?: Array<DevtoolsErrorType>;
|
|
22
25
|
/**
|
|
23
|
-
* The theme of the devtools panel.
|
|
24
|
-
*
|
|
26
|
+
* The theme of the devtools panel. Overrides the theme selected in the devtools
|
|
27
|
+
* Settings menu. When omitted, the selected theme is used, or `'system'` if none
|
|
28
|
+
* is selected.
|
|
25
29
|
*/
|
|
26
30
|
theme?: Theme;
|
|
27
31
|
/**
|
|
@@ -29,17 +33,25 @@ export interface DevtoolsPanelOptions {
|
|
|
29
33
|
*/
|
|
30
34
|
styleNonce?: string;
|
|
31
35
|
/**
|
|
32
|
-
* Use this
|
|
36
|
+
* Use this to pass a shadow DOM target to the devtools so that the styles will be applied
|
|
37
|
+
* within the shadow DOM instead of within the head tag in the light DOM.
|
|
33
38
|
*/
|
|
34
39
|
shadowDOMTarget?: ShadowRoot;
|
|
40
|
+
/**
|
|
41
|
+
* Set this to true to hide disabled queries from the devtools panel.
|
|
42
|
+
*/
|
|
43
|
+
hideDisabledQueries?: boolean;
|
|
35
44
|
/**
|
|
36
45
|
* Callback function that is called when the devtools panel is closed
|
|
37
46
|
*/
|
|
38
47
|
onClose?: () => unknown;
|
|
39
48
|
/**
|
|
40
49
|
* Element where to render the devtools panel. When set to undefined or null, the devtools panel will not be created, or destroyed if existing.
|
|
41
|
-
* If changed from undefined to
|
|
50
|
+
* If changed from undefined to an ElementRef, the devtools panel will be created.
|
|
42
51
|
*/
|
|
43
52
|
hostElement?: ElementRef | null;
|
|
44
53
|
}
|
|
54
|
+
/**
|
|
55
|
+
* The signature of `injectDevtoolsPanel`, which creates a devtools panel from reactive options.
|
|
56
|
+
*/
|
|
45
57
|
export type InjectDevtoolsPanel = (injectDevtoolsPanelFn: () => DevtoolsPanelOptions) => DevtoolsPanelRef;
|
package/index.mjs
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/angular-query-devtools",
|
|
3
|
-
"version": "5.0.0
|
|
3
|
+
"version": "5.0.0",
|
|
4
4
|
"description": "Developer tools to interact with and visualize the TanStack Angular Query cache",
|
|
5
5
|
"author": "Arnoud de Vries",
|
|
6
6
|
"license": "MIT",
|
|
@@ -69,12 +69,11 @@
|
|
|
69
69
|
},
|
|
70
70
|
"sideEffects": false,
|
|
71
71
|
"dependencies": {
|
|
72
|
-
"@tanstack/query-
|
|
73
|
-
"@tanstack/query-devtools": "5.103.2"
|
|
72
|
+
"@tanstack/query-devtools": "5.107.2"
|
|
74
73
|
},
|
|
75
74
|
"peerDependencies": {
|
|
76
75
|
"@angular/common": ">=20.1.0",
|
|
77
76
|
"@angular/core": ">=20.1.0",
|
|
78
|
-
"@tanstack/angular-query": "^5.0.0
|
|
77
|
+
"@tanstack/angular-query": "^5.0.0"
|
|
79
78
|
}
|
|
80
79
|
}
|
package/production/index.mjs
CHANGED
package/stub.d.ts
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
1
|
import { DevtoolsOptions, WithDevtools, WithDevtoolsFn } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Provides an inert Query feature for production builds.
|
|
4
|
+
* @returns A feature that creates no devtools or subscriptions.
|
|
5
|
+
*/
|
|
2
6
|
export declare const withDevtools: WithDevtools;
|
|
3
7
|
export type { DevtoolsOptions, WithDevtools, WithDevtoolsFn };
|
package/stub.mjs
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
import { makeEnvironmentProviders } from "@angular/core";
|
|
2
2
|
import { queryFeature } from "@tanstack/angular-query/internal";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
3
|
+
// src/stub.ts
|
|
4
|
+
/**
|
|
5
|
+
* Provides an inert Query feature for production builds.
|
|
6
|
+
* @returns A feature that creates no devtools or subscriptions.
|
|
7
|
+
*/
|
|
8
|
+
var withDevtools = () => queryFeature(makeEnvironmentProviders([]));
|
|
9
|
+
export { withDevtools };
|
|
10
|
+
|
|
11
|
+
//# sourceMappingURL=stub.mjs.map
|
package/stub.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stub.mjs","sources":["../src/stub.ts"],"sourcesContent":["import { makeEnvironmentProviders } from '@angular/core'\nimport { queryFeature } from '@tanstack/angular-query/internal'\nimport type { DevtoolsOptions, WithDevtools, WithDevtoolsFn } from './types'\n\n// Stub which replaces `withDevtools` in production builds\nexport const withDevtools: WithDevtools = () =>\n queryFeature(makeEnvironmentProviders([]))\n\nexport type { DevtoolsOptions, WithDevtools, WithDevtoolsFn }\n"],"
|
|
1
|
+
{"version":3,"file":"stub.mjs","names":[],"sources":["../src/stub.ts"],"sourcesContent":["import { makeEnvironmentProviders } from '@angular/core'\nimport { queryFeature } from '@tanstack/angular-query/internal'\nimport type { DevtoolsOptions, WithDevtools, WithDevtoolsFn } from './types'\n\n// Stub which replaces `withDevtools` in production builds\n/**\n * Provides an inert Query feature for production builds.\n * @returns A feature that creates no devtools or subscriptions.\n */\nexport const withDevtools: WithDevtools = () =>\n queryFeature(makeEnvironmentProviders([]))\n\nexport type { DevtoolsOptions, WithDevtools, WithDevtoolsFn }\n"],"mappings":";;;;;;;AASA,IAAa,qBACX,aAAa,yBAAyB,CAAC,CAAC,CAAC"}
|
package/types.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { QueryClient } from '@tanstack/query-core';
|
|
2
|
-
import { DevtoolsButtonPosition, DevtoolsErrorType, DevtoolsPosition, Theme } from '@tanstack/query-devtools';
|
|
3
|
-
import { QueryFeature } from '@tanstack/angular-query';
|
|
4
1
|
import { Signal } from '@angular/core';
|
|
2
|
+
import { QueryClient, QueryFeature } from '@tanstack/angular-query';
|
|
3
|
+
import { DevtoolsButtonPosition, DevtoolsErrorType, DevtoolsPosition, Theme } from '@tanstack/query-devtools';
|
|
5
4
|
/** A static devtools option or an Angular signal containing that option. */
|
|
6
5
|
type MaybeSignal<T> = T | Signal<T | undefined>;
|
|
7
6
|
/**
|
|
@@ -79,5 +78,8 @@ export interface DevtoolsOptions {
|
|
|
79
78
|
* `hideDisabledQueries` are read only when the devtools are constructed.
|
|
80
79
|
*/
|
|
81
80
|
export type WithDevtoolsFn = () => DevtoolsOptions;
|
|
81
|
+
/**
|
|
82
|
+
* Creates a Query feature from an optional factory of developer-tools options.
|
|
83
|
+
*/
|
|
82
84
|
export type WithDevtools = (withDevtoolsFn?: WithDevtoolsFn) => QueryFeature;
|
|
83
85
|
export {};
|
package/with-devtools.mjs
CHANGED
|
@@ -1,100 +1,117 @@
|
|
|
1
1
|
import { isPlatformBrowser } from "@angular/common";
|
|
2
|
-
import { InjectionToken,
|
|
2
|
+
import { DestroyRef, InjectionToken, PLATFORM_ID, afterRenderEffect, computed, inject, isDevMode, isSignal, makeEnvironmentProviders, provideEnvironmentInitializer, untracked } from "@angular/core";
|
|
3
|
+
import { QueryClient, onlineManager } from "@tanstack/angular-query";
|
|
3
4
|
import { queryFeature } from "@tanstack/angular-query/internal";
|
|
4
|
-
import { QueryClient, onlineManager } from "@tanstack/query-core";
|
|
5
5
|
import { TanstackQueryDevtools } from "@tanstack/query-devtools";
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
});
|
|
11
|
-
|
|
6
|
+
// src/with-devtools.ts
|
|
7
|
+
/**
|
|
8
|
+
* Internal token used to prevent double providing of devtools in child injectors
|
|
9
|
+
*/
|
|
10
|
+
var DEVTOOLS_PROVIDED = new InjectionToken("", { factory: () => ({ isProvided: false }) });
|
|
11
|
+
/** Internal token for providing devtools options. */
|
|
12
|
+
var DEVTOOLS_OPTIONS = new InjectionToken("");
|
|
13
|
+
/**
|
|
14
|
+
* Reads a devtools option that may be supplied as an Angular signal.
|
|
15
|
+
* @param option - A static option value or a signal containing it.
|
|
16
|
+
* @returns The current option value, or undefined when no value is supplied.
|
|
17
|
+
*/
|
|
12
18
|
function resolveOption(option) {
|
|
13
|
-
|
|
19
|
+
return isSignal(option) ? option() : option;
|
|
14
20
|
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
)
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
21
|
+
/**
|
|
22
|
+
* Enables developer tools in Angular development builds.
|
|
23
|
+
*
|
|
24
|
+
* **Example**
|
|
25
|
+
*
|
|
26
|
+
* ```ts
|
|
27
|
+
* export const appConfig: ApplicationConfig = {
|
|
28
|
+
* providers: [
|
|
29
|
+
* provideTanStackQuery(() => new QueryClient(), withDevtools()),
|
|
30
|
+
* ]
|
|
31
|
+
* }
|
|
32
|
+
* ```
|
|
33
|
+
* The devtools will be rendered in `<body>`.
|
|
34
|
+
*
|
|
35
|
+
* If you need more control over when devtools are loaded, you can use the `loadDevtools` option.
|
|
36
|
+
*
|
|
37
|
+
* If you need more control over where devtools are rendered, consider `injectDevtoolsPanel`. This allows rendering devtools inside your own devtools for example.
|
|
38
|
+
* @param withDevtoolsFn - A function that returns `DevtoolsOptions`. It runs
|
|
39
|
+
* once in an Angular injection context and can call `inject()`. Return signals
|
|
40
|
+
* as individual mutable option values to update them reactively.
|
|
41
|
+
* @returns A set of providers for use with `provideTanStackQuery`.
|
|
42
|
+
* @see {@link provideTanStackQuery}
|
|
43
|
+
* @see {@link DevtoolsOptions}
|
|
44
|
+
*/
|
|
45
|
+
var withDevtools = (withDevtoolsFn) => queryFeature(makeEnvironmentProviders([{
|
|
46
|
+
provide: DEVTOOLS_OPTIONS,
|
|
47
|
+
useFactory: () => withDevtoolsFn?.() ?? {}
|
|
48
|
+
}, provideEnvironmentInitializer(() => {
|
|
49
|
+
const devtoolsProvided = inject(DEVTOOLS_PROVIDED);
|
|
50
|
+
if (!isPlatformBrowser(inject(PLATFORM_ID)) || devtoolsProvided.isProvided) return;
|
|
51
|
+
const injectedClient = inject(QueryClient, { optional: true });
|
|
52
|
+
const options = inject(DEVTOOLS_OPTIONS);
|
|
53
|
+
const destroyRef = inject(DestroyRef);
|
|
54
|
+
const client = resolveOption(options.client) ?? injectedClient;
|
|
55
|
+
devtoolsProvided.isProvided = true;
|
|
56
|
+
destroyRef.onDestroy(() => {
|
|
57
|
+
devtoolsProvided.isProvided = false;
|
|
58
|
+
});
|
|
59
|
+
if (!client) throw new Error("No QueryClient found");
|
|
60
|
+
const devtools = new TanstackQueryDevtools({
|
|
61
|
+
client,
|
|
62
|
+
queryFlavor: "Angular Query",
|
|
63
|
+
version: "5",
|
|
64
|
+
onlineManager,
|
|
65
|
+
buttonPosition: resolveOption(options.buttonPosition),
|
|
66
|
+
position: resolveOption(options.position),
|
|
67
|
+
initialIsOpen: resolveOption(options.initialIsOpen),
|
|
68
|
+
errorTypes: resolveOption(options.errorTypes),
|
|
69
|
+
styleNonce: options.styleNonce,
|
|
70
|
+
shadowDOMTarget: options.shadowDOMTarget,
|
|
71
|
+
hideDisabledQueries: options.hideDisabledQueries,
|
|
72
|
+
theme: resolveOption(options.theme)
|
|
73
|
+
});
|
|
74
|
+
const shouldMount = computed(() => {
|
|
75
|
+
const loadDevtools = resolveOption(options.loadDevtools);
|
|
76
|
+
return typeof loadDevtools === "boolean" ? loadDevtools : isDevMode();
|
|
77
|
+
});
|
|
78
|
+
const mount = () => {
|
|
79
|
+
const element = document.body.appendChild(document.createElement("div"));
|
|
80
|
+
element.classList.add("tsqd-parent-container");
|
|
81
|
+
devtools.mount(element);
|
|
82
|
+
return () => {
|
|
83
|
+
devtools.unmount();
|
|
84
|
+
element.remove();
|
|
85
|
+
};
|
|
86
|
+
};
|
|
87
|
+
afterRenderEffect({ write: (onCleanup) => {
|
|
88
|
+
if (shouldMount()) onCleanup(untracked(mount));
|
|
89
|
+
} });
|
|
90
|
+
const registerOptionEffect = (option, update) => {
|
|
91
|
+
if (!isSignal(option)) return;
|
|
92
|
+
afterRenderEffect({ write: () => {
|
|
93
|
+
update(option());
|
|
94
|
+
} });
|
|
95
|
+
};
|
|
96
|
+
registerOptionEffect(options.client, (value) => {
|
|
97
|
+
devtools.setClient(value ?? injectedClient);
|
|
98
|
+
});
|
|
99
|
+
registerOptionEffect(options.buttonPosition, (value) => {
|
|
100
|
+
devtools.setButtonPosition(value ?? "bottom-right");
|
|
101
|
+
});
|
|
102
|
+
registerOptionEffect(options.position, (value) => {
|
|
103
|
+
devtools.setPosition(value ?? "bottom");
|
|
104
|
+
});
|
|
105
|
+
registerOptionEffect(options.initialIsOpen, (value) => {
|
|
106
|
+
devtools.setInitialIsOpen(value ?? false);
|
|
107
|
+
});
|
|
108
|
+
registerOptionEffect(options.errorTypes, (value) => {
|
|
109
|
+
devtools.setErrorTypes(value ?? []);
|
|
110
|
+
});
|
|
111
|
+
registerOptionEffect(options.theme, (value) => {
|
|
112
|
+
devtools.setTheme(value);
|
|
113
|
+
});
|
|
114
|
+
})]));
|
|
115
|
+
export { withDevtools };
|
|
116
|
+
|
|
117
|
+
//# sourceMappingURL=with-devtools.mjs.map
|
package/with-devtools.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"with-devtools.mjs","sources":["../src/with-devtools.ts"],"sourcesContent":["import { isPlatformBrowser } from '@angular/common'\nimport {\n DestroyRef,\n InjectionToken,\n PLATFORM_ID,\n afterRenderEffect,\n computed,\n inject,\n isDevMode,\n isSignal,\n makeEnvironmentProviders,\n provideEnvironmentInitializer,\n untracked,\n} from '@angular/core'\nimport {
|
|
1
|
+
{"version":3,"file":"with-devtools.mjs","names":[],"sources":["../src/with-devtools.ts"],"sourcesContent":["import { isPlatformBrowser } from '@angular/common'\nimport {\n DestroyRef,\n InjectionToken,\n PLATFORM_ID,\n afterRenderEffect,\n computed,\n inject,\n isDevMode,\n isSignal,\n makeEnvironmentProviders,\n provideEnvironmentInitializer,\n untracked,\n} from '@angular/core'\nimport { QueryClient, onlineManager } from '@tanstack/angular-query'\nimport { queryFeature } from '@tanstack/angular-query/internal'\nimport { TanstackQueryDevtools } from '@tanstack/query-devtools'\nimport type { Signal } from '@angular/core'\nimport type { DevtoolsOptions, WithDevtools } from './types'\n\n/**\n * Internal token used to prevent double providing of devtools in child injectors\n */\nconst DEVTOOLS_PROVIDED = new InjectionToken('', {\n factory: () => ({\n isProvided: false,\n }),\n})\n\n/** Internal token for providing devtools options. */\nconst DEVTOOLS_OPTIONS = new InjectionToken<DevtoolsOptions>('')\n\n/**\n * Reads a devtools option that may be supplied as an Angular signal.\n * @param option - A static option value or a signal containing it.\n * @returns The current option value, or undefined when no value is supplied.\n */\nfunction resolveOption<T>(option: T | Signal<T | undefined> | undefined) {\n return isSignal(option) ? option() : option\n}\n\n/**\n * Enables developer tools in Angular development builds.\n *\n * **Example**\n *\n * ```ts\n * export const appConfig: ApplicationConfig = {\n * providers: [\n * provideTanStackQuery(() => new QueryClient(), withDevtools()),\n * ]\n * }\n * ```\n * The devtools will be rendered in `<body>`.\n *\n * If you need more control over when devtools are loaded, you can use the `loadDevtools` option.\n *\n * If you need more control over where devtools are rendered, consider `injectDevtoolsPanel`. This allows rendering devtools inside your own devtools for example.\n * @param withDevtoolsFn - A function that returns `DevtoolsOptions`. It runs\n * once in an Angular injection context and can call `inject()`. Return signals\n * as individual mutable option values to update them reactively.\n * @returns A set of providers for use with `provideTanStackQuery`.\n * @see {@link provideTanStackQuery}\n * @see {@link DevtoolsOptions}\n */\nexport const withDevtools: WithDevtools = (withDevtoolsFn) =>\n queryFeature(\n makeEnvironmentProviders([\n {\n provide: DEVTOOLS_OPTIONS,\n useFactory: () => withDevtoolsFn?.() ?? {},\n },\n provideEnvironmentInitializer(() => {\n const devtoolsProvided = inject(DEVTOOLS_PROVIDED)\n if (\n !isPlatformBrowser(inject(PLATFORM_ID)) ||\n devtoolsProvided.isProvided\n )\n return\n\n const injectedClient = inject(QueryClient, { optional: true })\n const options = inject(DEVTOOLS_OPTIONS)\n const destroyRef = inject(DestroyRef)\n\n const client = resolveOption(options.client) ?? injectedClient\n\n devtoolsProvided.isProvided = true\n destroyRef.onDestroy(() => {\n devtoolsProvided.isProvided = false\n })\n\n if (!client) throw new Error('No QueryClient found')\n\n const devtools = new TanstackQueryDevtools({\n client,\n queryFlavor: 'Angular Query',\n version: '5',\n onlineManager,\n buttonPosition: resolveOption(options.buttonPosition),\n position: resolveOption(options.position),\n initialIsOpen: resolveOption(options.initialIsOpen),\n errorTypes: resolveOption(options.errorTypes),\n styleNonce: options.styleNonce,\n shadowDOMTarget: options.shadowDOMTarget,\n hideDisabledQueries: options.hideDisabledQueries,\n theme: resolveOption(options.theme),\n })\n\n const shouldMount = computed(() => {\n const loadDevtools = resolveOption(options.loadDevtools)\n return typeof loadDevtools === 'boolean' ? loadDevtools : isDevMode()\n })\n\n const mount = () => {\n const element = document.body.appendChild(\n document.createElement('div'),\n )\n element.classList.add('tsqd-parent-container')\n devtools.mount(element)\n\n return () => {\n devtools.unmount()\n element.remove()\n }\n }\n\n afterRenderEffect({\n write: (onCleanup) => {\n if (shouldMount()) onCleanup(untracked(mount))\n },\n })\n\n const registerOptionEffect = <T>(\n option: T | Signal<T | undefined> | undefined,\n update: (value: T | undefined) => void,\n ) => {\n if (!isSignal(option)) return\n afterRenderEffect({\n write: () => {\n update(option())\n },\n })\n }\n\n registerOptionEffect(options.client, (value) => {\n devtools.setClient(value ?? injectedClient!)\n })\n registerOptionEffect(options.buttonPosition, (value) => {\n devtools.setButtonPosition(value ?? 'bottom-right')\n })\n registerOptionEffect(options.position, (value) => {\n devtools.setPosition(value ?? 'bottom')\n })\n registerOptionEffect(options.initialIsOpen, (value) => {\n devtools.setInitialIsOpen(value ?? false)\n })\n registerOptionEffect(options.errorTypes, (value) => {\n devtools.setErrorTypes(value ?? [])\n })\n registerOptionEffect(options.theme, (value) => {\n devtools.setTheme(value)\n })\n }),\n ]),\n )\n"],"mappings":";;;;;;;;;AAuBA,IAAM,oBAAoB,IAAI,eAAe,IAAI,EAC/C,gBAAgB,EACd,YAAY,MACd,GACF,CAAC;;AAGD,IAAM,mBAAmB,IAAI,eAAgC,EAAE;;;;;;AAO/D,SAAS,cAAiB,QAA+C;CACvE,OAAO,SAAS,MAAM,IAAI,OAAO,IAAI;AACvC;;;;;;;;;;;;;;;;;;;;;;;;;AA0BA,IAAa,gBAA8B,mBACzC,aACE,yBAAyB,CACvB;CACE,SAAS;CACT,kBAAkB,iBAAiB,KAAK,CAAC;AAC3C,GACA,oCAAoC;CAClC,MAAM,mBAAmB,OAAO,iBAAiB;CACjD,IACE,CAAC,kBAAkB,OAAO,WAAW,CAAC,KACtC,iBAAiB,YAEjB;CAEF,MAAM,iBAAiB,OAAO,aAAa,EAAE,UAAU,KAAK,CAAC;CAC7D,MAAM,UAAU,OAAO,gBAAgB;CACvC,MAAM,aAAa,OAAO,UAAU;CAEpC,MAAM,SAAS,cAAc,QAAQ,MAAM,KAAK;CAEhD,iBAAiB,aAAa;CAC9B,WAAW,gBAAgB;EACzB,iBAAiB,aAAa;CAChC,CAAC;CAED,IAAI,CAAC,QAAQ,MAAM,IAAI,MAAM,sBAAsB;CAEnD,MAAM,WAAW,IAAI,sBAAsB;EACzC;EACA,aAAa;EACb,S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AS,SAAS,KAAK;CACzB,CAAC;AACH,CAAC,CACH,CAAC,CACH"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";"}
|
package/index.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";"}
|
package/production/index.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";"}
|