@comapeo/core-react 9.0.2 → 10.0.1
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/README.md +1 -1
- package/dist/commonjs/contexts/ClientApi.d.ts +1 -3
- package/dist/commonjs/contexts/ClientApi.js +2 -2
- package/dist/commonjs/hooks/client.d.ts +74 -33
- package/dist/commonjs/hooks/client.js +40 -11
- package/dist/commonjs/hooks/documents.d.ts +42 -429
- package/dist/commonjs/hooks/documents.js +100 -51
- package/dist/commonjs/hooks/invites.d.ts +153 -55
- package/dist/commonjs/hooks/invites.js +69 -20
- package/dist/commonjs/hooks/maps.d.ts +96 -225
- package/dist/commonjs/hooks/maps.js +104 -37
- package/dist/commonjs/hooks/projects.d.ts +666 -223
- package/dist/commonjs/hooks/projects.js +264 -131
- package/dist/commonjs/index.d.ts +2 -2
- package/dist/commonjs/lib/map-shares-stores.d.ts +1 -1
- package/dist/commonjs/lib/map-shares-stores.js +2 -2
- package/dist/commonjs/lib/presets.d.ts +1 -3
- package/dist/commonjs/lib/react-query.d.ts +103 -0
- package/dist/commonjs/lib/react-query.js +187 -0
- package/dist/commonjs/lib/sync.d.ts +2 -5
- package/dist/commonjs/lib/sync.js +0 -1
- package/dist/commonjs/lib/types.d.ts +4 -6
- package/dist/esm/contexts/ClientApi.d.ts +1 -3
- package/dist/esm/contexts/ClientApi.js +1 -1
- package/dist/esm/hooks/client.d.ts +74 -33
- package/dist/esm/hooks/client.js +40 -11
- package/dist/esm/hooks/documents.d.ts +42 -429
- package/dist/esm/hooks/documents.js +100 -51
- package/dist/esm/hooks/invites.d.ts +153 -55
- package/dist/esm/hooks/invites.js +69 -20
- package/dist/esm/hooks/maps.d.ts +96 -225
- package/dist/esm/hooks/maps.js +105 -38
- package/dist/esm/hooks/projects.d.ts +666 -223
- package/dist/esm/hooks/projects.js +262 -129
- package/dist/esm/index.d.ts +2 -2
- package/dist/esm/lib/map-shares-stores.d.ts +1 -1
- package/dist/esm/lib/map-shares-stores.js +1 -1
- package/dist/esm/lib/presets.d.ts +1 -3
- package/dist/esm/lib/react-query.d.ts +103 -0
- package/dist/esm/lib/react-query.js +162 -0
- package/dist/esm/lib/sync.d.ts +2 -5
- package/dist/esm/lib/sync.js +1 -1
- package/dist/esm/lib/types.d.ts +4 -6
- package/docs/API.md +137 -81
- package/package.json +39 -35
- package/dist/commonjs/lib/react-query/client.d.ts +0 -65
- package/dist/commonjs/lib/react-query/client.js +0 -68
- package/dist/commonjs/lib/react-query/documents.d.ts +0 -1484
- package/dist/commonjs/lib/react-query/documents.js +0 -149
- package/dist/commonjs/lib/react-query/invites.d.ts +0 -88
- package/dist/commonjs/lib/react-query/invites.js +0 -95
- package/dist/commonjs/lib/react-query/maps.d.ts +0 -104
- package/dist/commonjs/lib/react-query/maps.js +0 -129
- package/dist/commonjs/lib/react-query/mutation-result.d.ts +0 -8
- package/dist/commonjs/lib/react-query/mutation-result.js +0 -22
- package/dist/commonjs/lib/react-query/projects.d.ts +0 -316
- package/dist/commonjs/lib/react-query/projects.js +0 -359
- package/dist/commonjs/lib/react-query/shared.d.ts +0 -9
- package/dist/commonjs/lib/react-query/shared.js +0 -23
- package/dist/esm/lib/react-query/client.d.ts +0 -65
- package/dist/esm/lib/react-query/client.js +0 -59
- package/dist/esm/lib/react-query/documents.d.ts +0 -1484
- package/dist/esm/lib/react-query/documents.js +0 -137
- package/dist/esm/lib/react-query/invites.d.ts +0 -88
- package/dist/esm/lib/react-query/invites.js +0 -85
- package/dist/esm/lib/react-query/maps.d.ts +0 -104
- package/dist/esm/lib/react-query/maps.js +0 -119
- package/dist/esm/lib/react-query/mutation-result.d.ts +0 -8
- package/dist/esm/lib/react-query/mutation-result.js +0 -19
- package/dist/esm/lib/react-query/projects.d.ts +0 -316
- package/dist/esm/lib/react-query/projects.js +0 -324
- package/dist/esm/lib/react-query/shared.d.ts +0 -9
- package/dist/esm/lib/react-query/shared.js +0 -18
|
@@ -18,8 +18,7 @@ const react_query_1 = require("@tanstack/react-query");
|
|
|
18
18
|
const react_1 = require("react");
|
|
19
19
|
const MapServer_js_1 = require("../contexts/MapServer.js");
|
|
20
20
|
const MapShares_js_1 = require("../contexts/MapShares.js");
|
|
21
|
-
const
|
|
22
|
-
const mutation_result_js_1 = require("../lib/react-query/mutation-result.js");
|
|
21
|
+
const react_query_js_1 = require("../lib/react-query.js");
|
|
23
22
|
/**
|
|
24
23
|
* Get a URL that points to a StyleJSON resource served by the embedded HTTP server.
|
|
25
24
|
*
|
|
@@ -48,7 +47,22 @@ const mutation_result_js_1 = require("../lib/react-query/mutation-result.js");
|
|
|
48
47
|
*/
|
|
49
48
|
function useMapStyleUrl() {
|
|
50
49
|
const mapServerApi = (0, MapServer_js_1.useMapServerApi)();
|
|
51
|
-
|
|
50
|
+
// TODO: Support custom maps
|
|
51
|
+
const mapId = constants_js_1.DEFAULT_MAP_ID;
|
|
52
|
+
const { data, error, isRefetching } = (0, react_query_1.useSuspenseQuery)({
|
|
53
|
+
...(0, react_query_js_1.baseQueryOptions)(),
|
|
54
|
+
queryKey: (0, react_query_js_1.getStyleJsonUrlQueryKey)({ mapId }),
|
|
55
|
+
queryFn: async () => {
|
|
56
|
+
const result = await mapServerApi.getMapStyleJsonUrl(mapId);
|
|
57
|
+
const u = new URL(result);
|
|
58
|
+
// This ensures that every time this query is refetched, it will have a different search param, forcing the map to reload.
|
|
59
|
+
u.searchParams.set('refresh_token', Date.now().toString());
|
|
60
|
+
return u.href;
|
|
61
|
+
},
|
|
62
|
+
// Keep this cached until the cache is manually invalidated by a map upload
|
|
63
|
+
staleTime: Infinity,
|
|
64
|
+
gcTime: Infinity,
|
|
65
|
+
});
|
|
52
66
|
return { data, error, isRefetching };
|
|
53
67
|
}
|
|
54
68
|
/**
|
|
@@ -66,20 +80,54 @@ function useMapStyleUrl() {
|
|
|
66
80
|
function useImportCustomMapFile() {
|
|
67
81
|
const mapServerApi = (0, MapServer_js_1.useMapServerApi)();
|
|
68
82
|
const queryClient = (0, react_query_1.useQueryClient)();
|
|
69
|
-
|
|
70
|
-
const
|
|
71
|
-
return (0,
|
|
83
|
+
// TODO: Support importing to other custom map IDs, to support multiple maps.
|
|
84
|
+
const mapId = constants_js_1.CUSTOM_MAP_ID;
|
|
85
|
+
return (0, react_query_js_1.filterMutationResult)((0, react_query_1.useMutation)({
|
|
86
|
+
...(0, react_query_js_1.baseMutationOptions)(),
|
|
87
|
+
mutationFn: async ({ file }) => {
|
|
88
|
+
if ('exists' in file && !file.exists) {
|
|
89
|
+
throw new Error('File does not exist or is not accessible');
|
|
90
|
+
}
|
|
91
|
+
return mapServerApi.put(`maps/${mapId}`, {
|
|
92
|
+
body: file,
|
|
93
|
+
headers: {
|
|
94
|
+
'Content-Type': 'application/octet-stream',
|
|
95
|
+
},
|
|
96
|
+
});
|
|
97
|
+
},
|
|
98
|
+
onSuccess: async () => {
|
|
99
|
+
await (0, react_query_js_1.invalidateMapQueries)(queryClient, { mapId });
|
|
100
|
+
},
|
|
101
|
+
}));
|
|
72
102
|
}
|
|
73
103
|
function useRemoveCustomMapFile() {
|
|
74
104
|
const mapServerApi = (0, MapServer_js_1.useMapServerApi)();
|
|
75
105
|
const queryClient = (0, react_query_1.useQueryClient)();
|
|
76
|
-
const
|
|
77
|
-
|
|
78
|
-
|
|
106
|
+
const mapId = constants_js_1.CUSTOM_MAP_ID;
|
|
107
|
+
return (0, react_query_js_1.filterMutationResult)((0, react_query_1.useMutation)({
|
|
108
|
+
...(0, react_query_js_1.baseMutationOptions)(),
|
|
109
|
+
mutationFn: async () => {
|
|
110
|
+
return mapServerApi.delete(`maps/${mapId}`);
|
|
111
|
+
},
|
|
112
|
+
onSuccess: async () => {
|
|
113
|
+
await (0, react_query_js_1.invalidateMapQueries)(queryClient, { mapId });
|
|
114
|
+
},
|
|
115
|
+
}));
|
|
79
116
|
}
|
|
80
117
|
function useGetCustomMapInfo() {
|
|
81
118
|
const mapServerApi = (0, MapServer_js_1.useMapServerApi)();
|
|
82
|
-
|
|
119
|
+
// TODO: Support custom maps
|
|
120
|
+
const mapId = constants_js_1.CUSTOM_MAP_ID;
|
|
121
|
+
const { data, error, isRefetching } = (0, react_query_1.useQuery)({
|
|
122
|
+
...(0, react_query_js_1.baseQueryOptions)(),
|
|
123
|
+
queryKey: (0, react_query_js_1.getMapInfoQueryKey)({ mapId }),
|
|
124
|
+
queryFn: async () => {
|
|
125
|
+
return mapServerApi.get(`maps/${mapId}/info`).json();
|
|
126
|
+
},
|
|
127
|
+
// Keep this cached until the cache is manually invalidated by a map upload
|
|
128
|
+
staleTime: Infinity,
|
|
129
|
+
gcTime: Infinity,
|
|
130
|
+
});
|
|
83
131
|
return { data, error, isRefetching };
|
|
84
132
|
}
|
|
85
133
|
// ============================================
|
|
@@ -150,9 +198,12 @@ function useSingleReceivedMapShare({ shareId }) {
|
|
|
150
198
|
*/
|
|
151
199
|
function useDownloadReceivedMapShare() {
|
|
152
200
|
const { download } = (0, MapShares_js_1.useReceivedMapSharesActions)();
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
201
|
+
return (0, react_query_js_1.filterMutationResult)((0, react_query_1.useMutation)({
|
|
202
|
+
...(0, react_query_js_1.baseMutationOptions)(),
|
|
203
|
+
mutationFn: async (options) => {
|
|
204
|
+
return download(options);
|
|
205
|
+
},
|
|
206
|
+
}));
|
|
156
207
|
}
|
|
157
208
|
/**
|
|
158
209
|
* Decline a map share that has been received. Notifies the sender that the
|
|
@@ -178,9 +229,12 @@ function useDownloadReceivedMapShare() {
|
|
|
178
229
|
*/
|
|
179
230
|
function useDeclineReceivedMapShare() {
|
|
180
231
|
const { decline } = (0, MapShares_js_1.useReceivedMapSharesActions)();
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
232
|
+
return (0, react_query_js_1.filterMutationResult)((0, react_query_1.useMutation)({
|
|
233
|
+
...(0, react_query_js_1.baseMutationOptions)(),
|
|
234
|
+
mutationFn: async (options) => {
|
|
235
|
+
return decline(options);
|
|
236
|
+
},
|
|
237
|
+
}));
|
|
184
238
|
}
|
|
185
239
|
/**
|
|
186
240
|
* Abort an in-progress map share download.
|
|
@@ -199,9 +253,12 @@ function useDeclineReceivedMapShare() {
|
|
|
199
253
|
*/
|
|
200
254
|
function useAbortReceivedMapShareDownload() {
|
|
201
255
|
const { abort } = (0, MapShares_js_1.useReceivedMapSharesActions)();
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
256
|
+
return (0, react_query_js_1.filterMutationResult)((0, react_query_1.useMutation)({
|
|
257
|
+
...(0, react_query_js_1.baseMutationOptions)(),
|
|
258
|
+
mutationFn: async (options) => {
|
|
259
|
+
return abort(options);
|
|
260
|
+
},
|
|
261
|
+
}));
|
|
205
262
|
}
|
|
206
263
|
// ============================================
|
|
207
264
|
// SENDER HOOKS
|
|
@@ -217,25 +274,32 @@ function useAbortReceivedMapShareDownload() {
|
|
|
217
274
|
* @example
|
|
218
275
|
* ```tsx
|
|
219
276
|
* function SendMapButton({ projectId, deviceId }: { projectId: string; deviceId: string }) {
|
|
220
|
-
*
|
|
221
|
-
*
|
|
222
|
-
*
|
|
223
|
-
*
|
|
224
|
-
*
|
|
225
|
-
*
|
|
226
|
-
*
|
|
227
|
-
*
|
|
228
|
-
*
|
|
229
|
-
*
|
|
230
|
-
*
|
|
277
|
+
* const { mutate: send } = useSendMapShare()
|
|
278
|
+
*
|
|
279
|
+
* return (
|
|
280
|
+
* <button
|
|
281
|
+
* onClick={() =>
|
|
282
|
+
* send({ projectId, receiverDeviceId: deviceId, mapId: 'custom' }, {
|
|
283
|
+
* onSuccess: (mapShare) => {
|
|
284
|
+
* console.log('Share sent with id', mapShare.shareId)
|
|
285
|
+
* }
|
|
286
|
+
* )
|
|
287
|
+
* }
|
|
288
|
+
* >
|
|
289
|
+
* Send Map
|
|
290
|
+
* </button>
|
|
291
|
+
* )
|
|
231
292
|
* }
|
|
232
293
|
* ```
|
|
233
294
|
*/
|
|
234
|
-
function useSendMapShare(
|
|
295
|
+
function useSendMapShare() {
|
|
235
296
|
const { createAndSend } = (0, MapShares_js_1.useSentMapSharesActions)();
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
297
|
+
return (0, react_query_js_1.filterMutationResult)((0, react_query_1.useMutation)({
|
|
298
|
+
...(0, react_query_js_1.baseMutationOptions)(),
|
|
299
|
+
mutationFn: async (options) => {
|
|
300
|
+
return createAndSend(options);
|
|
301
|
+
},
|
|
302
|
+
}));
|
|
239
303
|
}
|
|
240
304
|
/**
|
|
241
305
|
* Cancel a map share that was previously sent. If the recipient has not yet
|
|
@@ -257,9 +321,12 @@ function useSendMapShare({ projectId }) {
|
|
|
257
321
|
*/
|
|
258
322
|
function useCancelSentMapShare() {
|
|
259
323
|
const { cancel } = (0, MapShares_js_1.useSentMapSharesActions)();
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
324
|
+
return (0, react_query_js_1.filterMutationResult)((0, react_query_1.useMutation)({
|
|
325
|
+
...(0, react_query_js_1.baseMutationOptions)(),
|
|
326
|
+
mutationFn: async (options) => {
|
|
327
|
+
return cancel(options);
|
|
328
|
+
},
|
|
329
|
+
}));
|
|
263
330
|
}
|
|
264
331
|
/**
|
|
265
332
|
* Track the status and progress of a sent map share. Returns the current state
|