@procore/saved-views 6.1.0 → 6.2.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/dist/legacy/adapters/hub-data-loader.d.mts +22 -0
- package/dist/legacy/adapters/hub-data-loader.d.ts +22 -0
- package/dist/legacy/adapters/hub-data-loader.js +273 -0
- package/dist/legacy/adapters/hub-data-loader.mjs +273 -0
- package/dist/legacy/chunk-6DZX6EAA.mjs +37 -0
- package/dist/legacy/chunk-QGM4M3NI.js +37 -0
- package/dist/legacy/index.d.mts +13 -2
- package/dist/legacy/index.d.ts +13 -2
- package/dist/legacy/index.js +549 -471
- package/dist/legacy/index.mjs +223 -192
- package/dist/legacy/transport/default.d.mts +15 -0
- package/dist/legacy/transport/default.d.ts +15 -0
- package/dist/legacy/transport/default.js +104 -0
- package/dist/legacy/transport/default.mjs +104 -0
- package/dist/legacy/types-BWhJ-on3.d.mts +109 -0
- package/dist/legacy/types-BWhJ-on3.d.ts +109 -0
- package/dist/modern/adapters/hub-data-loader.d.mts +22 -0
- package/dist/modern/adapters/hub-data-loader.d.ts +22 -0
- package/dist/modern/adapters/hub-data-loader.js +270 -0
- package/dist/modern/adapters/hub-data-loader.mjs +270 -0
- package/dist/modern/chunk-6DZX6EAA.mjs +37 -0
- package/dist/modern/chunk-QGM4M3NI.js +37 -0
- package/dist/modern/index.d.mts +13 -2
- package/dist/modern/index.d.ts +13 -2
- package/dist/modern/index.js +606 -528
- package/dist/modern/index.mjs +223 -192
- package/dist/modern/transport/default.d.mts +15 -0
- package/dist/modern/transport/default.d.ts +15 -0
- package/dist/modern/transport/default.js +104 -0
- package/dist/modern/transport/default.mjs +104 -0
- package/dist/modern/types-BWhJ-on3.d.mts +109 -0
- package/dist/modern/types-BWhJ-on3.d.ts +109 -0
- package/package.json +35 -2
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { S as SavedViewsTransport } from '../types-BWhJ-on3.mjs';
|
|
2
|
+
import 'react';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* The default transport. Preserves today's behavior bit-for-bit:
|
|
6
|
+
* - HTTP via `requestJSON` from `@procore/core-http`.
|
|
7
|
+
* - Caching via a module-singleton `QueryClient` (was previously declared in
|
|
8
|
+
* `SavedViews.tsx`).
|
|
9
|
+
* - URL sync via `useSearchParams` from `react-router-dom`.
|
|
10
|
+
*
|
|
11
|
+
* Consumers that omit the `transport` prop get this transport automatically.
|
|
12
|
+
*/
|
|
13
|
+
declare const defaultTransport: SavedViewsTransport;
|
|
14
|
+
|
|
15
|
+
export { defaultTransport };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { S as SavedViewsTransport } from '../types-BWhJ-on3.js';
|
|
2
|
+
import 'react';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* The default transport. Preserves today's behavior bit-for-bit:
|
|
6
|
+
* - HTTP via `requestJSON` from `@procore/core-http`.
|
|
7
|
+
* - Caching via a module-singleton `QueryClient` (was previously declared in
|
|
8
|
+
* `SavedViews.tsx`).
|
|
9
|
+
* - URL sync via `useSearchParams` from `react-router-dom`.
|
|
10
|
+
*
|
|
11
|
+
* Consumers that omit the `transport` prop get this transport automatically.
|
|
12
|
+
*/
|
|
13
|
+
declare const defaultTransport: SavedViewsTransport;
|
|
14
|
+
|
|
15
|
+
export { defaultTransport };
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }require('../chunk-QGM4M3NI.js');
|
|
2
|
+
|
|
3
|
+
// src/transport/default.tsx
|
|
4
|
+
var _react = require('react'); var _react2 = _interopRequireDefault(_react);
|
|
5
|
+
var _corehttp = require('@procore/core-http');
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
var _reactquery = require('@tanstack/react-query');
|
|
13
|
+
var _reactrouterdom = require('react-router-dom');
|
|
14
|
+
var queryClient = new (0, _reactquery.QueryClient)();
|
|
15
|
+
var DefaultCacheProvider = ({ children }) => /* @__PURE__ */ _react2.default.createElement(_reactquery.QueryClientProvider, { client: queryClient }, children);
|
|
16
|
+
var useDefaultHttp = () => {
|
|
17
|
+
return async (req) => {
|
|
18
|
+
const init = {};
|
|
19
|
+
if (req.priority) {
|
|
20
|
+
init.priority = req.priority;
|
|
21
|
+
}
|
|
22
|
+
if (req.method !== "GET") {
|
|
23
|
+
init.method = req.method;
|
|
24
|
+
}
|
|
25
|
+
if (req.body !== void 0) {
|
|
26
|
+
init.body = typeof req.body === "string" ? req.body : JSON.stringify(req.body);
|
|
27
|
+
}
|
|
28
|
+
if (req.headers) {
|
|
29
|
+
init.headers = req.headers;
|
|
30
|
+
}
|
|
31
|
+
return _corehttp.requestJSON.call(void 0, req.url, init);
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
var useDefaultQueryAdapter = (args) => {
|
|
35
|
+
const { data, isLoading, isError, error } = _reactquery.useQuery.call(void 0, {
|
|
36
|
+
queryKey: args.queryKey,
|
|
37
|
+
queryFn: args.queryFn,
|
|
38
|
+
enabled: args.enabled
|
|
39
|
+
});
|
|
40
|
+
return { data, isLoading, isError, error };
|
|
41
|
+
};
|
|
42
|
+
var useDefaultMutationAdapter = (args) => {
|
|
43
|
+
const mutation = _reactquery.useMutation.call(void 0, {
|
|
44
|
+
mutationKey: args.mutationKey,
|
|
45
|
+
mutationFn: args.mutationFn,
|
|
46
|
+
onSuccess: args.onSuccess,
|
|
47
|
+
onError: args.onError
|
|
48
|
+
});
|
|
49
|
+
return {
|
|
50
|
+
mutate: (variables, options) => mutation.mutate(variables, {
|
|
51
|
+
onSuccess: options == null ? void 0 : options.onSuccess,
|
|
52
|
+
onError: options == null ? void 0 : options.onError
|
|
53
|
+
}),
|
|
54
|
+
isPending: mutation.isPending,
|
|
55
|
+
error: mutation.error,
|
|
56
|
+
reset: mutation.reset
|
|
57
|
+
};
|
|
58
|
+
};
|
|
59
|
+
var useDefaultCacheControl = () => {
|
|
60
|
+
const client = _reactquery.useQueryClient.call(void 0, );
|
|
61
|
+
return {
|
|
62
|
+
invalidate: (queryKey) => {
|
|
63
|
+
client.invalidateQueries({ queryKey: [...queryKey] });
|
|
64
|
+
},
|
|
65
|
+
setData: (queryKey, updater) => {
|
|
66
|
+
client.setQueryData([...queryKey], updater);
|
|
67
|
+
},
|
|
68
|
+
getData: (queryKey) => client.getQueryData([...queryKey])
|
|
69
|
+
};
|
|
70
|
+
};
|
|
71
|
+
var useDefaultUrlAdapter = () => {
|
|
72
|
+
const [searchParams, setSearchParams] = _reactrouterdom.useSearchParams.call(void 0, );
|
|
73
|
+
return {
|
|
74
|
+
getViewToken: () => searchParams.get("saved-view"),
|
|
75
|
+
setViewToken: (token) => {
|
|
76
|
+
setSearchParams(
|
|
77
|
+
(current) => {
|
|
78
|
+
const next = new URLSearchParams(current);
|
|
79
|
+
if (token === null) {
|
|
80
|
+
next.delete("saved-view");
|
|
81
|
+
} else {
|
|
82
|
+
next.set("saved-view", token);
|
|
83
|
+
}
|
|
84
|
+
return next;
|
|
85
|
+
},
|
|
86
|
+
{ replace: true }
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
};
|
|
91
|
+
var defaultTransport = {
|
|
92
|
+
// The default transport owns the page URL via `react-router-dom`, so the
|
|
93
|
+
// `?saved-view=<token>` share link works — keep the copy-link affordance.
|
|
94
|
+
supportsUrlSharing: true,
|
|
95
|
+
CacheProvider: DefaultCacheProvider,
|
|
96
|
+
useHttp: useDefaultHttp,
|
|
97
|
+
useQueryAdapter: useDefaultQueryAdapter,
|
|
98
|
+
useMutationAdapter: useDefaultMutationAdapter,
|
|
99
|
+
useCacheControl: useDefaultCacheControl,
|
|
100
|
+
useUrlAdapter: useDefaultUrlAdapter
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
exports.defaultTransport = defaultTransport;
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import "../chunk-6DZX6EAA.mjs";
|
|
2
|
+
|
|
3
|
+
// src/transport/default.tsx
|
|
4
|
+
import React from "react";
|
|
5
|
+
import { requestJSON } from "@procore/core-http";
|
|
6
|
+
import {
|
|
7
|
+
QueryClient,
|
|
8
|
+
QueryClientProvider,
|
|
9
|
+
useMutation,
|
|
10
|
+
useQuery,
|
|
11
|
+
useQueryClient
|
|
12
|
+
} from "@tanstack/react-query";
|
|
13
|
+
import { useSearchParams } from "react-router-dom";
|
|
14
|
+
var queryClient = new QueryClient();
|
|
15
|
+
var DefaultCacheProvider = ({ children }) => /* @__PURE__ */ React.createElement(QueryClientProvider, { client: queryClient }, children);
|
|
16
|
+
var useDefaultHttp = () => {
|
|
17
|
+
return async (req) => {
|
|
18
|
+
const init = {};
|
|
19
|
+
if (req.priority) {
|
|
20
|
+
init.priority = req.priority;
|
|
21
|
+
}
|
|
22
|
+
if (req.method !== "GET") {
|
|
23
|
+
init.method = req.method;
|
|
24
|
+
}
|
|
25
|
+
if (req.body !== void 0) {
|
|
26
|
+
init.body = typeof req.body === "string" ? req.body : JSON.stringify(req.body);
|
|
27
|
+
}
|
|
28
|
+
if (req.headers) {
|
|
29
|
+
init.headers = req.headers;
|
|
30
|
+
}
|
|
31
|
+
return requestJSON(req.url, init);
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
var useDefaultQueryAdapter = (args) => {
|
|
35
|
+
const { data, isLoading, isError, error } = useQuery({
|
|
36
|
+
queryKey: args.queryKey,
|
|
37
|
+
queryFn: args.queryFn,
|
|
38
|
+
enabled: args.enabled
|
|
39
|
+
});
|
|
40
|
+
return { data, isLoading, isError, error };
|
|
41
|
+
};
|
|
42
|
+
var useDefaultMutationAdapter = (args) => {
|
|
43
|
+
const mutation = useMutation({
|
|
44
|
+
mutationKey: args.mutationKey,
|
|
45
|
+
mutationFn: args.mutationFn,
|
|
46
|
+
onSuccess: args.onSuccess,
|
|
47
|
+
onError: args.onError
|
|
48
|
+
});
|
|
49
|
+
return {
|
|
50
|
+
mutate: (variables, options) => mutation.mutate(variables, {
|
|
51
|
+
onSuccess: options == null ? void 0 : options.onSuccess,
|
|
52
|
+
onError: options == null ? void 0 : options.onError
|
|
53
|
+
}),
|
|
54
|
+
isPending: mutation.isPending,
|
|
55
|
+
error: mutation.error,
|
|
56
|
+
reset: mutation.reset
|
|
57
|
+
};
|
|
58
|
+
};
|
|
59
|
+
var useDefaultCacheControl = () => {
|
|
60
|
+
const client = useQueryClient();
|
|
61
|
+
return {
|
|
62
|
+
invalidate: (queryKey) => {
|
|
63
|
+
client.invalidateQueries({ queryKey: [...queryKey] });
|
|
64
|
+
},
|
|
65
|
+
setData: (queryKey, updater) => {
|
|
66
|
+
client.setQueryData([...queryKey], updater);
|
|
67
|
+
},
|
|
68
|
+
getData: (queryKey) => client.getQueryData([...queryKey])
|
|
69
|
+
};
|
|
70
|
+
};
|
|
71
|
+
var useDefaultUrlAdapter = () => {
|
|
72
|
+
const [searchParams, setSearchParams] = useSearchParams();
|
|
73
|
+
return {
|
|
74
|
+
getViewToken: () => searchParams.get("saved-view"),
|
|
75
|
+
setViewToken: (token) => {
|
|
76
|
+
setSearchParams(
|
|
77
|
+
(current) => {
|
|
78
|
+
const next = new URLSearchParams(current);
|
|
79
|
+
if (token === null) {
|
|
80
|
+
next.delete("saved-view");
|
|
81
|
+
} else {
|
|
82
|
+
next.set("saved-view", token);
|
|
83
|
+
}
|
|
84
|
+
return next;
|
|
85
|
+
},
|
|
86
|
+
{ replace: true }
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
};
|
|
91
|
+
var defaultTransport = {
|
|
92
|
+
// The default transport owns the page URL via `react-router-dom`, so the
|
|
93
|
+
// `?saved-view=<token>` share link works — keep the copy-link affordance.
|
|
94
|
+
supportsUrlSharing: true,
|
|
95
|
+
CacheProvider: DefaultCacheProvider,
|
|
96
|
+
useHttp: useDefaultHttp,
|
|
97
|
+
useQueryAdapter: useDefaultQueryAdapter,
|
|
98
|
+
useMutationAdapter: useDefaultMutationAdapter,
|
|
99
|
+
useCacheControl: useDefaultCacheControl,
|
|
100
|
+
useUrlAdapter: useDefaultUrlAdapter
|
|
101
|
+
};
|
|
102
|
+
export {
|
|
103
|
+
defaultTransport
|
|
104
|
+
};
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { ComponentType, ReactNode } from 'react';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* A normalized HTTP request descriptor that the saved-views package builds
|
|
5
|
+
* internally. The transport's `useHttp()` adapter is responsible for fulfilling
|
|
6
|
+
* the request against the consumer's preferred HTTP layer (`@procore/core-http`
|
|
7
|
+
* for the default transport, `@procore/web-sdk-hub-data-loader` for the Hub
|
|
8
|
+
* Card transport).
|
|
9
|
+
*/
|
|
10
|
+
interface SavedViewsHttpRequest {
|
|
11
|
+
method: 'GET' | 'POST' | 'PUT' | 'DELETE';
|
|
12
|
+
/**
|
|
13
|
+
* Absolute URL or path. The default transport passes this straight to
|
|
14
|
+
* `requestJSON`. The hub-data-loader transport parses out the path and query
|
|
15
|
+
* string to build a `DataOperationParams` payload.
|
|
16
|
+
*/
|
|
17
|
+
url: string;
|
|
18
|
+
body?: unknown;
|
|
19
|
+
headers?: Record<string, string>;
|
|
20
|
+
/**
|
|
21
|
+
* Browser fetch priority hint. Matches the native `RequestPriority` type so
|
|
22
|
+
* that the default transport can pass it straight to `requestJSON`.
|
|
23
|
+
*/
|
|
24
|
+
priority?: 'high' | 'low' | 'auto';
|
|
25
|
+
}
|
|
26
|
+
/** Adapter shape mirroring TanStack Query's `useQuery` return contract. */
|
|
27
|
+
interface SavedViewsQueryResult<T> {
|
|
28
|
+
data: T | undefined;
|
|
29
|
+
isLoading: boolean;
|
|
30
|
+
isError: boolean;
|
|
31
|
+
error?: unknown;
|
|
32
|
+
}
|
|
33
|
+
interface SavedViewsQueryArgs<T> {
|
|
34
|
+
queryKey: readonly unknown[];
|
|
35
|
+
queryFn: () => Promise<T>;
|
|
36
|
+
enabled?: boolean;
|
|
37
|
+
}
|
|
38
|
+
/** Adapter shape mirroring TanStack Query's `useMutation` return contract. */
|
|
39
|
+
interface SavedViewsMutationResult<Variables, Result, Err = unknown> {
|
|
40
|
+
mutate: (variables: Variables, options?: {
|
|
41
|
+
onSuccess?: (result: Result, variables: Variables) => void;
|
|
42
|
+
onError?: (error: Err, variables: Variables) => void;
|
|
43
|
+
}) => void;
|
|
44
|
+
isPending: boolean;
|
|
45
|
+
error: Err | null;
|
|
46
|
+
reset: () => void;
|
|
47
|
+
}
|
|
48
|
+
interface SavedViewsMutationArgs<Variables, Result, Err = unknown> {
|
|
49
|
+
mutationKey: readonly unknown[];
|
|
50
|
+
mutationFn: (variables: Variables) => Promise<Result>;
|
|
51
|
+
onSuccess?: (result: Result, variables: Variables) => void;
|
|
52
|
+
onError?: (error: Err, variables: Variables) => void;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Imperative cache surgery — mirrors a tiny slice of TanStack's `QueryClient`.
|
|
56
|
+
* The default transport delegates to a real `QueryClient`; the hub-data-loader
|
|
57
|
+
* transport implements this against its own subscription-based local cache so
|
|
58
|
+
* the rename-in-place UX is preserved without a second `QueryClient` on the
|
|
59
|
+
* page.
|
|
60
|
+
*/
|
|
61
|
+
interface SavedViewsCacheControl {
|
|
62
|
+
invalidate: (queryKey: readonly unknown[]) => void;
|
|
63
|
+
setData: <T>(queryKey: readonly unknown[], updater: (old: T | undefined) => T) => void;
|
|
64
|
+
getData: <T>(queryKey: readonly unknown[]) => T | undefined;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Adapter for the `?saved-view=<token>` URL convention. The default transport
|
|
68
|
+
* wraps `react-router-dom`'s `useSearchParams`; the hub-data-loader transport
|
|
69
|
+
* is a no-op because Hub Cards cannot own the URL (see
|
|
70
|
+
* `routing-in-hub-cards.md` in the project-list-hub-card repo).
|
|
71
|
+
*/
|
|
72
|
+
interface SavedViewsUrlAdapter {
|
|
73
|
+
getViewToken: () => string | null;
|
|
74
|
+
setViewToken: (token: string | null) => void;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* The full transport contract injected via the `transport` prop on
|
|
78
|
+
* `SavedViews` / `DataTableSavedViews` / `SmartGridSavedViews`. When the prop
|
|
79
|
+
* is omitted, the package falls back to `defaultTransport`, which preserves
|
|
80
|
+
* today's behavior bit-for-bit.
|
|
81
|
+
*/
|
|
82
|
+
interface SavedViewsTransport {
|
|
83
|
+
/**
|
|
84
|
+
* Whether this transport owns a shareable page URL. Drives URL-dependent UI
|
|
85
|
+
* such as the "Copy share link" action: the link only works when the consumer
|
|
86
|
+
* can read the `?saved-view=<token>` param back on load. The default transport
|
|
87
|
+
* sets this `true` (it owns the URL via `react-router-dom`); the hub-data-loader
|
|
88
|
+
* transport sets it `false` because Hub Cards cannot own the host URL, so the
|
|
89
|
+
* copy-link affordance is hidden there. Optional for backward compatibility —
|
|
90
|
+
* treated as `true` (shown) when omitted.
|
|
91
|
+
*/
|
|
92
|
+
supportsUrlSharing?: boolean;
|
|
93
|
+
/**
|
|
94
|
+
* Wraps the saved-views subtree. The default transport mounts the
|
|
95
|
+
* package-owned `QueryClientProvider` here; the hub-data-loader transport
|
|
96
|
+
* mounts a small subscription cache provider that exists only to support
|
|
97
|
+
* `setData`.
|
|
98
|
+
*/
|
|
99
|
+
CacheProvider: ComponentType<{
|
|
100
|
+
children: ReactNode;
|
|
101
|
+
}>;
|
|
102
|
+
useHttp: () => (req: SavedViewsHttpRequest) => Promise<unknown>;
|
|
103
|
+
useQueryAdapter: <T>(args: SavedViewsQueryArgs<T>) => SavedViewsQueryResult<T>;
|
|
104
|
+
useMutationAdapter: <Variables, Result, Err = unknown>(args: SavedViewsMutationArgs<Variables, Result, Err>) => SavedViewsMutationResult<Variables, Result, Err>;
|
|
105
|
+
useCacheControl: () => SavedViewsCacheControl;
|
|
106
|
+
useUrlAdapter: () => SavedViewsUrlAdapter;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
export type { SavedViewsTransport as S, SavedViewsCacheControl as a, SavedViewsHttpRequest as b, SavedViewsMutationArgs as c, SavedViewsMutationResult as d, SavedViewsQueryArgs as e, SavedViewsQueryResult as f, SavedViewsUrlAdapter as g };
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { ComponentType, ReactNode } from 'react';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* A normalized HTTP request descriptor that the saved-views package builds
|
|
5
|
+
* internally. The transport's `useHttp()` adapter is responsible for fulfilling
|
|
6
|
+
* the request against the consumer's preferred HTTP layer (`@procore/core-http`
|
|
7
|
+
* for the default transport, `@procore/web-sdk-hub-data-loader` for the Hub
|
|
8
|
+
* Card transport).
|
|
9
|
+
*/
|
|
10
|
+
interface SavedViewsHttpRequest {
|
|
11
|
+
method: 'GET' | 'POST' | 'PUT' | 'DELETE';
|
|
12
|
+
/**
|
|
13
|
+
* Absolute URL or path. The default transport passes this straight to
|
|
14
|
+
* `requestJSON`. The hub-data-loader transport parses out the path and query
|
|
15
|
+
* string to build a `DataOperationParams` payload.
|
|
16
|
+
*/
|
|
17
|
+
url: string;
|
|
18
|
+
body?: unknown;
|
|
19
|
+
headers?: Record<string, string>;
|
|
20
|
+
/**
|
|
21
|
+
* Browser fetch priority hint. Matches the native `RequestPriority` type so
|
|
22
|
+
* that the default transport can pass it straight to `requestJSON`.
|
|
23
|
+
*/
|
|
24
|
+
priority?: 'high' | 'low' | 'auto';
|
|
25
|
+
}
|
|
26
|
+
/** Adapter shape mirroring TanStack Query's `useQuery` return contract. */
|
|
27
|
+
interface SavedViewsQueryResult<T> {
|
|
28
|
+
data: T | undefined;
|
|
29
|
+
isLoading: boolean;
|
|
30
|
+
isError: boolean;
|
|
31
|
+
error?: unknown;
|
|
32
|
+
}
|
|
33
|
+
interface SavedViewsQueryArgs<T> {
|
|
34
|
+
queryKey: readonly unknown[];
|
|
35
|
+
queryFn: () => Promise<T>;
|
|
36
|
+
enabled?: boolean;
|
|
37
|
+
}
|
|
38
|
+
/** Adapter shape mirroring TanStack Query's `useMutation` return contract. */
|
|
39
|
+
interface SavedViewsMutationResult<Variables, Result, Err = unknown> {
|
|
40
|
+
mutate: (variables: Variables, options?: {
|
|
41
|
+
onSuccess?: (result: Result, variables: Variables) => void;
|
|
42
|
+
onError?: (error: Err, variables: Variables) => void;
|
|
43
|
+
}) => void;
|
|
44
|
+
isPending: boolean;
|
|
45
|
+
error: Err | null;
|
|
46
|
+
reset: () => void;
|
|
47
|
+
}
|
|
48
|
+
interface SavedViewsMutationArgs<Variables, Result, Err = unknown> {
|
|
49
|
+
mutationKey: readonly unknown[];
|
|
50
|
+
mutationFn: (variables: Variables) => Promise<Result>;
|
|
51
|
+
onSuccess?: (result: Result, variables: Variables) => void;
|
|
52
|
+
onError?: (error: Err, variables: Variables) => void;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Imperative cache surgery — mirrors a tiny slice of TanStack's `QueryClient`.
|
|
56
|
+
* The default transport delegates to a real `QueryClient`; the hub-data-loader
|
|
57
|
+
* transport implements this against its own subscription-based local cache so
|
|
58
|
+
* the rename-in-place UX is preserved without a second `QueryClient` on the
|
|
59
|
+
* page.
|
|
60
|
+
*/
|
|
61
|
+
interface SavedViewsCacheControl {
|
|
62
|
+
invalidate: (queryKey: readonly unknown[]) => void;
|
|
63
|
+
setData: <T>(queryKey: readonly unknown[], updater: (old: T | undefined) => T) => void;
|
|
64
|
+
getData: <T>(queryKey: readonly unknown[]) => T | undefined;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Adapter for the `?saved-view=<token>` URL convention. The default transport
|
|
68
|
+
* wraps `react-router-dom`'s `useSearchParams`; the hub-data-loader transport
|
|
69
|
+
* is a no-op because Hub Cards cannot own the URL (see
|
|
70
|
+
* `routing-in-hub-cards.md` in the project-list-hub-card repo).
|
|
71
|
+
*/
|
|
72
|
+
interface SavedViewsUrlAdapter {
|
|
73
|
+
getViewToken: () => string | null;
|
|
74
|
+
setViewToken: (token: string | null) => void;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* The full transport contract injected via the `transport` prop on
|
|
78
|
+
* `SavedViews` / `DataTableSavedViews` / `SmartGridSavedViews`. When the prop
|
|
79
|
+
* is omitted, the package falls back to `defaultTransport`, which preserves
|
|
80
|
+
* today's behavior bit-for-bit.
|
|
81
|
+
*/
|
|
82
|
+
interface SavedViewsTransport {
|
|
83
|
+
/**
|
|
84
|
+
* Whether this transport owns a shareable page URL. Drives URL-dependent UI
|
|
85
|
+
* such as the "Copy share link" action: the link only works when the consumer
|
|
86
|
+
* can read the `?saved-view=<token>` param back on load. The default transport
|
|
87
|
+
* sets this `true` (it owns the URL via `react-router-dom`); the hub-data-loader
|
|
88
|
+
* transport sets it `false` because Hub Cards cannot own the host URL, so the
|
|
89
|
+
* copy-link affordance is hidden there. Optional for backward compatibility —
|
|
90
|
+
* treated as `true` (shown) when omitted.
|
|
91
|
+
*/
|
|
92
|
+
supportsUrlSharing?: boolean;
|
|
93
|
+
/**
|
|
94
|
+
* Wraps the saved-views subtree. The default transport mounts the
|
|
95
|
+
* package-owned `QueryClientProvider` here; the hub-data-loader transport
|
|
96
|
+
* mounts a small subscription cache provider that exists only to support
|
|
97
|
+
* `setData`.
|
|
98
|
+
*/
|
|
99
|
+
CacheProvider: ComponentType<{
|
|
100
|
+
children: ReactNode;
|
|
101
|
+
}>;
|
|
102
|
+
useHttp: () => (req: SavedViewsHttpRequest) => Promise<unknown>;
|
|
103
|
+
useQueryAdapter: <T>(args: SavedViewsQueryArgs<T>) => SavedViewsQueryResult<T>;
|
|
104
|
+
useMutationAdapter: <Variables, Result, Err = unknown>(args: SavedViewsMutationArgs<Variables, Result, Err>) => SavedViewsMutationResult<Variables, Result, Err>;
|
|
105
|
+
useCacheControl: () => SavedViewsCacheControl;
|
|
106
|
+
useUrlAdapter: () => SavedViewsUrlAdapter;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
export type { SavedViewsTransport as S, SavedViewsCacheControl as a, SavedViewsHttpRequest as b, SavedViewsMutationArgs as c, SavedViewsMutationResult as d, SavedViewsQueryArgs as e, SavedViewsQueryResult as f, SavedViewsUrlAdapter as g };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { SystemEvents } from '@procore/web-sdk-events';
|
|
2
|
+
import { S as SavedViewsTransport } from '../types-BWhJ-on3.mjs';
|
|
3
|
+
export { a as SavedViewsCacheControl, b as SavedViewsHttpRequest, c as SavedViewsMutationArgs, d as SavedViewsMutationResult, e as SavedViewsQueryArgs, f as SavedViewsQueryResult, g as SavedViewsUrlAdapter } from '../types-BWhJ-on3.mjs';
|
|
4
|
+
import 'react';
|
|
5
|
+
|
|
6
|
+
interface CreateHubDataLoaderTransportOptions {
|
|
7
|
+
/**
|
|
8
|
+
* Stable identifier of the Hub Card consuming saved-views. Forwarded to
|
|
9
|
+
* `useHubDataLoader(hubCardId, systemEvents)`. Use the same `HUB_CARD_ID`
|
|
10
|
+
* the card already uses elsewhere (e.g. for `system:request` events).
|
|
11
|
+
*/
|
|
12
|
+
hubCardId: string;
|
|
13
|
+
/**
|
|
14
|
+
* The card's `SystemEvents` instance, initialized against the card's mount
|
|
15
|
+
* node. The Hub Card platform requires this to be scoped to the card, not
|
|
16
|
+
* `window`, so multiple cards on the same page don't cross-talk.
|
|
17
|
+
*/
|
|
18
|
+
systemEvents: SystemEvents;
|
|
19
|
+
}
|
|
20
|
+
declare const createHubDataLoaderTransport: (options: CreateHubDataLoaderTransportOptions) => SavedViewsTransport;
|
|
21
|
+
|
|
22
|
+
export { type CreateHubDataLoaderTransportOptions, SavedViewsTransport, createHubDataLoaderTransport };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { SystemEvents } from '@procore/web-sdk-events';
|
|
2
|
+
import { S as SavedViewsTransport } from '../types-BWhJ-on3.js';
|
|
3
|
+
export { a as SavedViewsCacheControl, b as SavedViewsHttpRequest, c as SavedViewsMutationArgs, d as SavedViewsMutationResult, e as SavedViewsQueryArgs, f as SavedViewsQueryResult, g as SavedViewsUrlAdapter } from '../types-BWhJ-on3.js';
|
|
4
|
+
import 'react';
|
|
5
|
+
|
|
6
|
+
interface CreateHubDataLoaderTransportOptions {
|
|
7
|
+
/**
|
|
8
|
+
* Stable identifier of the Hub Card consuming saved-views. Forwarded to
|
|
9
|
+
* `useHubDataLoader(hubCardId, systemEvents)`. Use the same `HUB_CARD_ID`
|
|
10
|
+
* the card already uses elsewhere (e.g. for `system:request` events).
|
|
11
|
+
*/
|
|
12
|
+
hubCardId: string;
|
|
13
|
+
/**
|
|
14
|
+
* The card's `SystemEvents` instance, initialized against the card's mount
|
|
15
|
+
* node. The Hub Card platform requires this to be scoped to the card, not
|
|
16
|
+
* `window`, so multiple cards on the same page don't cross-talk.
|
|
17
|
+
*/
|
|
18
|
+
systemEvents: SystemEvents;
|
|
19
|
+
}
|
|
20
|
+
declare const createHubDataLoaderTransport: (options: CreateHubDataLoaderTransportOptions) => SavedViewsTransport;
|
|
21
|
+
|
|
22
|
+
export { type CreateHubDataLoaderTransportOptions, SavedViewsTransport, createHubDataLoaderTransport };
|