@comapeo/core-react 1.0.1 → 2.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/dist/commonjs/contexts/ClientApi.d.ts +14 -0
- package/dist/commonjs/contexts/ClientApi.js +16 -0
- package/dist/commonjs/hooks/client.d.ts +80 -0
- package/dist/commonjs/hooks/client.js +91 -0
- package/dist/{hooks → commonjs/hooks}/documents.d.ts +60 -5
- package/dist/commonjs/hooks/documents.js +192 -0
- package/dist/commonjs/hooks/invites.d.ts +51 -0
- package/dist/commonjs/hooks/invites.js +50 -0
- package/dist/commonjs/hooks/maps.js +37 -0
- package/dist/commonjs/hooks/projects.d.ts +334 -0
- package/dist/commonjs/hooks/projects.js +320 -0
- package/dist/commonjs/index.d.ts +12 -0
- package/dist/commonjs/index.js +69 -0
- package/dist/commonjs/lib/react-query/client.d.ts +61 -0
- package/dist/commonjs/lib/react-query/client.js +68 -0
- package/dist/{lib → commonjs/lib}/react-query/documents.d.ts +789 -706
- package/dist/commonjs/lib/react-query/documents.js +149 -0
- package/dist/commonjs/lib/react-query/invites.d.ts +71 -0
- package/dist/commonjs/lib/react-query/invites.js +85 -0
- package/dist/commonjs/lib/react-query/maps.d.ts +24 -0
- package/dist/commonjs/lib/react-query/maps.js +27 -0
- package/dist/commonjs/lib/react-query/projects.d.ts +332 -0
- package/dist/commonjs/lib/react-query/projects.js +235 -0
- package/dist/{lib → commonjs/lib}/react-query/shared.d.ts +5 -1
- package/dist/commonjs/lib/react-query/shared.js +23 -0
- package/dist/commonjs/package.json +3 -0
- package/dist/{contexts → esm/contexts}/ClientApi.d.ts +3 -3
- package/dist/{hooks → esm/hooks}/client.d.ts +23 -2
- package/dist/{hooks → esm/hooks}/client.js +21 -3
- package/dist/esm/hooks/documents.d.ts +167 -0
- package/dist/{hooks → esm/hooks}/documents.js +54 -3
- package/dist/esm/hooks/invites.d.ts +51 -0
- package/dist/esm/hooks/invites.js +44 -0
- package/dist/esm/hooks/maps.d.ts +33 -0
- package/dist/{hooks → esm/hooks}/maps.js +2 -2
- package/dist/{hooks → esm/hooks}/projects.d.ts +89 -6
- package/dist/{hooks → esm/hooks}/projects.js +59 -3
- package/dist/esm/index.d.ts +12 -0
- package/dist/esm/index.js +12 -0
- package/dist/esm/lib/react-query/client.d.ts +61 -0
- package/dist/esm/lib/react-query/client.js +59 -0
- package/dist/esm/lib/react-query/documents.d.ts +1584 -0
- package/dist/{lib → esm/lib}/react-query/documents.js +56 -2
- package/dist/esm/lib/react-query/invites.d.ts +71 -0
- package/dist/esm/lib/react-query/invites.js +76 -0
- package/dist/esm/lib/react-query/maps.d.ts +24 -0
- package/dist/{lib → esm/lib}/react-query/maps.js +6 -2
- package/dist/esm/lib/react-query/projects.d.ts +332 -0
- package/dist/{lib → esm/lib}/react-query/projects.js +84 -2
- package/dist/esm/lib/react-query/shared.d.ts +9 -0
- package/dist/{lib → esm/lib}/react-query/shared.js +7 -1
- package/dist/esm/package.json +3 -0
- package/docs/API.md +157 -258
- package/package.json +51 -37
- package/dist/index.d.ts +0 -11
- package/dist/index.js +0 -11
- package/dist/lib/react-query/client.d.ts +0 -30
- package/dist/lib/react-query/client.js +0 -29
- package/dist/lib/react-query/invites.d.ts +0 -12
- package/dist/lib/react-query/invites.js +0 -17
- package/dist/lib/react-query/maps.d.ts +0 -15
- package/dist/lib/react-query/projects.d.ts +0 -196
- /package/dist/{hooks → commonjs/hooks}/maps.d.ts +0 -0
- /package/dist/{contexts → esm/contexts}/ClientApi.js +0 -0
|
@@ -0,0 +1,334 @@
|
|
|
1
|
+
import type { BitmapOpts, SvgOpts } from '@comapeo/core/dist/icon-api.js' with { 'resolution-mode': 'import' };
|
|
2
|
+
import type { BlobId } from '@comapeo/core/dist/types.js' with { 'resolution-mode': 'import' };
|
|
3
|
+
/**
|
|
4
|
+
* Retrieve the project settings for a project.
|
|
5
|
+
*
|
|
6
|
+
* @param opts.projectId Project public ID
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```tsx
|
|
10
|
+
* function BasicExample() {
|
|
11
|
+
* const { data } = useProjectSettings({ projectId: '...' })
|
|
12
|
+
*
|
|
13
|
+
* console.log(data.name)
|
|
14
|
+
* }
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
export declare function useProjectSettings({ projectId }: {
|
|
18
|
+
projectId: string;
|
|
19
|
+
}): {
|
|
20
|
+
data: import("@comapeo/core/dist/mapeo-project.js", { with: { "resolution-mode": "import" } }).EditableProjectSettings;
|
|
21
|
+
error: Error | null;
|
|
22
|
+
isRefetching: boolean;
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* Retrieve a project API instance for a project.
|
|
26
|
+
*
|
|
27
|
+
* This is mostly used internally by the other hooks and should only be used if certain project APIs are not exposed via the hooks.
|
|
28
|
+
*
|
|
29
|
+
* @param opts.projectId Project public ID
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* ```tsx
|
|
33
|
+
* function BasicExample() {
|
|
34
|
+
* const { data } = useSingleProject({ projectId: '...' })
|
|
35
|
+
* }
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
export declare function useSingleProject({ projectId }: {
|
|
39
|
+
projectId: string;
|
|
40
|
+
}): {
|
|
41
|
+
data: import("rpc-reflector/lib/types.js").ClientApi<import("@comapeo/core/dist/mapeo-project.js", { with: { "resolution-mode": "import" } }).MapeoProject>;
|
|
42
|
+
error: Error | null;
|
|
43
|
+
isRefetching: boolean;
|
|
44
|
+
};
|
|
45
|
+
/**
|
|
46
|
+
* Retrieve project information for each project that exists.
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* ```tsx
|
|
50
|
+
* function BasicExample() {
|
|
51
|
+
* const { data } = useManyProjects()
|
|
52
|
+
*
|
|
53
|
+
* console.log(data.map(project => project.name))
|
|
54
|
+
* }
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
57
|
+
export declare function useManyProjects(): {
|
|
58
|
+
data: (Pick<{
|
|
59
|
+
schemaName: "projectSettings";
|
|
60
|
+
name?: string | undefined;
|
|
61
|
+
defaultPresets?: {
|
|
62
|
+
point: string[];
|
|
63
|
+
area: string[];
|
|
64
|
+
vertex: string[];
|
|
65
|
+
line: string[];
|
|
66
|
+
relation: string[];
|
|
67
|
+
} | undefined;
|
|
68
|
+
configMetadata?: {
|
|
69
|
+
name: string;
|
|
70
|
+
buildDate: string;
|
|
71
|
+
importDate: string;
|
|
72
|
+
fileVersion: string;
|
|
73
|
+
} | undefined;
|
|
74
|
+
}, "name"> & {
|
|
75
|
+
projectId: string;
|
|
76
|
+
createdAt?: string | undefined;
|
|
77
|
+
updatedAt?: string | undefined;
|
|
78
|
+
})[];
|
|
79
|
+
error: Error | null;
|
|
80
|
+
isRefetching: boolean;
|
|
81
|
+
};
|
|
82
|
+
/**
|
|
83
|
+
* Retrieve a single member of a project.
|
|
84
|
+
*
|
|
85
|
+
* @param opts.projectId Project public ID
|
|
86
|
+
* @param opts.projectId Device ID of interest
|
|
87
|
+
*
|
|
88
|
+
* @example
|
|
89
|
+
* ```tsx
|
|
90
|
+
* function BasicExample() {
|
|
91
|
+
* const { data } = useSingleMember({ projectId: '...', deviceId: '...' })
|
|
92
|
+
*
|
|
93
|
+
* console.log(data.role)
|
|
94
|
+
* }
|
|
95
|
+
* ```
|
|
96
|
+
*/
|
|
97
|
+
export declare function useSingleMember({ projectId, deviceId, }: {
|
|
98
|
+
projectId: string;
|
|
99
|
+
deviceId: string;
|
|
100
|
+
}): {
|
|
101
|
+
data: import("@comapeo/core/dist/member-api.js", { with: { "resolution-mode": "import" } }).MemberInfo;
|
|
102
|
+
error: Error | null;
|
|
103
|
+
isRefetching: boolean;
|
|
104
|
+
};
|
|
105
|
+
/**
|
|
106
|
+
* Retrieve all members of a project.
|
|
107
|
+
*
|
|
108
|
+
* @param opts.projectId Project public ID
|
|
109
|
+
*
|
|
110
|
+
* @example
|
|
111
|
+
* ```tsx
|
|
112
|
+
* function BasicExample() {
|
|
113
|
+
* const { data } = useManyMembers({ projectId: '...' })
|
|
114
|
+
*
|
|
115
|
+
* console.log(data.role)
|
|
116
|
+
* }
|
|
117
|
+
* ```
|
|
118
|
+
*/
|
|
119
|
+
export declare function useManyMembers({ projectId }: {
|
|
120
|
+
projectId: string;
|
|
121
|
+
}): {
|
|
122
|
+
data: import("@comapeo/core/dist/member-api.js", { with: { "resolution-mode": "import" } }).MemberInfo[];
|
|
123
|
+
error: Error | null;
|
|
124
|
+
isRefetching: boolean;
|
|
125
|
+
};
|
|
126
|
+
/**
|
|
127
|
+
* Retrieve a URL that points to icon resources served by the embedded HTTP server.
|
|
128
|
+
*
|
|
129
|
+
* _TODO: Explain bitmap opts vs svg opts_
|
|
130
|
+
*
|
|
131
|
+
* @param opts.projectId Project public ID
|
|
132
|
+
* @param opts.iconId Icon ID of interest
|
|
133
|
+
* @param opts.mimeType MIME type of desired resource
|
|
134
|
+
* @param opts.pixelDensity Pixel density resource (only applicable when `mimeType` is `'image/png'`)
|
|
135
|
+
* @param opts.size Size of desired resource
|
|
136
|
+
*
|
|
137
|
+
* @example
|
|
138
|
+
* ```tsx
|
|
139
|
+
* function PngExample() {
|
|
140
|
+
* const { data } = useIconUrl({
|
|
141
|
+
* projectId: '...',
|
|
142
|
+
* iconId: '...',
|
|
143
|
+
* mimeType: 'image/png',
|
|
144
|
+
* pixelDensity: 1,
|
|
145
|
+
* size: 'medium'
|
|
146
|
+
* })
|
|
147
|
+
* }
|
|
148
|
+
* ```
|
|
149
|
+
*
|
|
150
|
+
* ```tsx
|
|
151
|
+
* function SvgExample() {
|
|
152
|
+
* const { data } = useIconUrl({
|
|
153
|
+
* projectId: '...',
|
|
154
|
+
* iconId: '...',
|
|
155
|
+
* mimeType: 'image/svg',
|
|
156
|
+
* size: 'medium'
|
|
157
|
+
* })
|
|
158
|
+
* }
|
|
159
|
+
* ```
|
|
160
|
+
*/
|
|
161
|
+
export declare function useIconUrl({ projectId, iconId, ...mimeBasedOpts }: {
|
|
162
|
+
projectId: string;
|
|
163
|
+
iconId: string;
|
|
164
|
+
} & (BitmapOpts | SvgOpts)): {
|
|
165
|
+
data: string;
|
|
166
|
+
error: Error | null;
|
|
167
|
+
isRefetching: boolean;
|
|
168
|
+
};
|
|
169
|
+
/**
|
|
170
|
+
* Retrieve a URL that points to a desired blob resource.
|
|
171
|
+
*
|
|
172
|
+
* _TODO: Explain BlobId in more depth_
|
|
173
|
+
*
|
|
174
|
+
* @param opts.projectId Project public Id
|
|
175
|
+
* @param opts.blobId Blob ID of the desired resource
|
|
176
|
+
*
|
|
177
|
+
* @example
|
|
178
|
+
* ```tsx
|
|
179
|
+
* function PhotoExample() {
|
|
180
|
+
* const { data } = useAttachmentUrl({
|
|
181
|
+
* projectId: '...',
|
|
182
|
+
* blobId: {
|
|
183
|
+
* type: 'photo',
|
|
184
|
+
* variant: 'thumbnail',
|
|
185
|
+
* name: '...',
|
|
186
|
+
* driveId: '...',
|
|
187
|
+
* }
|
|
188
|
+
* })
|
|
189
|
+
* }
|
|
190
|
+
* ```
|
|
191
|
+
*
|
|
192
|
+
* ```tsx
|
|
193
|
+
* function AudioExample() {
|
|
194
|
+
* const { data } = useAttachmentUrl({
|
|
195
|
+
* projectId: '...',
|
|
196
|
+
* blobId: {
|
|
197
|
+
* type: 'audio',
|
|
198
|
+
* variant: 'original',
|
|
199
|
+
* name: '...',
|
|
200
|
+
* driveId: '...',
|
|
201
|
+
* }
|
|
202
|
+
* })
|
|
203
|
+
* }
|
|
204
|
+
* ```
|
|
205
|
+
*
|
|
206
|
+
* ```tsx
|
|
207
|
+
* function VideoExample() {
|
|
208
|
+
* const { data } = useAttachmentUrl({
|
|
209
|
+
* projectId: '...',
|
|
210
|
+
* blobId: {
|
|
211
|
+
* type: 'video',
|
|
212
|
+
* variant: 'original',
|
|
213
|
+
* name: '...',
|
|
214
|
+
* driveId: '...',
|
|
215
|
+
* }
|
|
216
|
+
* })
|
|
217
|
+
* }
|
|
218
|
+
* ```
|
|
219
|
+
*/
|
|
220
|
+
export declare function useAttachmentUrl({ projectId, blobId, }: {
|
|
221
|
+
projectId: string;
|
|
222
|
+
blobId: BlobId;
|
|
223
|
+
}): {
|
|
224
|
+
data: string;
|
|
225
|
+
error: Error | null;
|
|
226
|
+
isRefetching: boolean;
|
|
227
|
+
};
|
|
228
|
+
/**
|
|
229
|
+
* Retrieve the device ID that created a document.
|
|
230
|
+
*
|
|
231
|
+
* @param opts.projectId Project public ID
|
|
232
|
+
* @param opts.originalVersionId Version ID of document
|
|
233
|
+
*
|
|
234
|
+
* @example
|
|
235
|
+
* ```tsx
|
|
236
|
+
* function BasicExample() {
|
|
237
|
+
* const { data } = useDocumentCreatedBy({
|
|
238
|
+
* projectId: '...',
|
|
239
|
+
* originalVersionId: '...',
|
|
240
|
+
* })
|
|
241
|
+
* }
|
|
242
|
+
* ```
|
|
243
|
+
*/
|
|
244
|
+
export declare function useDocumentCreatedBy({ projectId, originalVersionId, }: {
|
|
245
|
+
projectId: string;
|
|
246
|
+
originalVersionId: string;
|
|
247
|
+
}): {
|
|
248
|
+
data: string;
|
|
249
|
+
error: Error | null;
|
|
250
|
+
isRefetching: boolean;
|
|
251
|
+
};
|
|
252
|
+
export declare function useAddServerPeer({ projectId }: {
|
|
253
|
+
projectId: string;
|
|
254
|
+
}): {
|
|
255
|
+
mutate: import("@tanstack/react-query").UseMutateFunction<void, Error, {
|
|
256
|
+
baseUrl: string;
|
|
257
|
+
dangerouslyAllowInsecureConnections?: boolean;
|
|
258
|
+
}, unknown>;
|
|
259
|
+
reset: () => void;
|
|
260
|
+
status: "pending" | "error" | "success" | "idle";
|
|
261
|
+
};
|
|
262
|
+
/**
|
|
263
|
+
* Create a new project.
|
|
264
|
+
*/
|
|
265
|
+
export declare function useCreateProject(): {
|
|
266
|
+
mutate: import("@tanstack/react-query").UseMutateFunction<string, Error, {
|
|
267
|
+
name?: string;
|
|
268
|
+
configPath?: string;
|
|
269
|
+
} | undefined, unknown>;
|
|
270
|
+
reset: () => void;
|
|
271
|
+
status: "pending" | "error" | "success" | "idle";
|
|
272
|
+
};
|
|
273
|
+
/**
|
|
274
|
+
* Leave an existing project.
|
|
275
|
+
*/
|
|
276
|
+
export declare function useLeaveProject(): {
|
|
277
|
+
mutate: import("@tanstack/react-query").UseMutateFunction<void, Error, {
|
|
278
|
+
projectId: string;
|
|
279
|
+
}, unknown>;
|
|
280
|
+
reset: () => void;
|
|
281
|
+
status: "pending" | "error" | "success" | "idle";
|
|
282
|
+
};
|
|
283
|
+
/**
|
|
284
|
+
* Update the configuration of a project using an external file.
|
|
285
|
+
*
|
|
286
|
+
* @param opts.projectId Public ID of the project to apply changes to.
|
|
287
|
+
*/
|
|
288
|
+
export declare function useImportProjectConfig({ projectId }: {
|
|
289
|
+
projectId: string;
|
|
290
|
+
}): {
|
|
291
|
+
mutate: import("@tanstack/react-query").UseMutateFunction<Error[], Error, {
|
|
292
|
+
configPath: string;
|
|
293
|
+
}, unknown>;
|
|
294
|
+
reset: () => void;
|
|
295
|
+
status: "pending" | "error" | "success" | "idle";
|
|
296
|
+
};
|
|
297
|
+
/**
|
|
298
|
+
* Update the settings of a project.
|
|
299
|
+
*
|
|
300
|
+
* @param opts.projectId Public ID of the project to apply changes to.
|
|
301
|
+
*/
|
|
302
|
+
export declare function useUpdateProjectSettings({ projectId }: {
|
|
303
|
+
projectId: string;
|
|
304
|
+
}): {
|
|
305
|
+
mutate: import("@tanstack/react-query").UseMutateFunction<import("@comapeo/core/dist/mapeo-project.js", { with: { "resolution-mode": "import" } }).EditableProjectSettings, Error, {
|
|
306
|
+
name?: import("@comapeo/schema", { with: { "resolution-mode": "import" } }).ProjectSettings["name"];
|
|
307
|
+
configMetadata?: import("@comapeo/schema", { with: { "resolution-mode": "import" } }).ProjectSettings["configMetadata"];
|
|
308
|
+
defaultPresets?: import("@comapeo/schema", { with: { "resolution-mode": "import" } }).ProjectSettings["defaultPresets"];
|
|
309
|
+
}, unknown>;
|
|
310
|
+
reset: () => void;
|
|
311
|
+
status: "pending" | "error" | "success" | "idle";
|
|
312
|
+
};
|
|
313
|
+
/**
|
|
314
|
+
* Create a blob for a project.
|
|
315
|
+
*
|
|
316
|
+
* @param opts.projectId Public project ID of project to apply to changes to.
|
|
317
|
+
*/
|
|
318
|
+
export declare function useCreateBlob({ projectId }: {
|
|
319
|
+
projectId: string;
|
|
320
|
+
}): {
|
|
321
|
+
mutate: import("@tanstack/react-query").UseMutateFunction<{
|
|
322
|
+
driveId: string;
|
|
323
|
+
name: string;
|
|
324
|
+
type: "photo" | "video" | "audio";
|
|
325
|
+
hash: string;
|
|
326
|
+
}, Error, {
|
|
327
|
+
original: string;
|
|
328
|
+
preview?: string;
|
|
329
|
+
thumbnail?: string;
|
|
330
|
+
metadata: import("@comapeo/core/dist/blob-api.js", { with: { "resolution-mode": "import" } }).Metadata;
|
|
331
|
+
}, unknown>;
|
|
332
|
+
reset: () => void;
|
|
333
|
+
status: "pending" | "error" | "success" | "idle";
|
|
334
|
+
};
|
|
@@ -0,0 +1,320 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useProjectSettings = useProjectSettings;
|
|
4
|
+
exports.useSingleProject = useSingleProject;
|
|
5
|
+
exports.useManyProjects = useManyProjects;
|
|
6
|
+
exports.useSingleMember = useSingleMember;
|
|
7
|
+
exports.useManyMembers = useManyMembers;
|
|
8
|
+
exports.useIconUrl = useIconUrl;
|
|
9
|
+
exports.useAttachmentUrl = useAttachmentUrl;
|
|
10
|
+
exports.useDocumentCreatedBy = useDocumentCreatedBy;
|
|
11
|
+
exports.useAddServerPeer = useAddServerPeer;
|
|
12
|
+
exports.useCreateProject = useCreateProject;
|
|
13
|
+
exports.useLeaveProject = useLeaveProject;
|
|
14
|
+
exports.useImportProjectConfig = useImportProjectConfig;
|
|
15
|
+
exports.useUpdateProjectSettings = useUpdateProjectSettings;
|
|
16
|
+
exports.useCreateBlob = useCreateBlob;
|
|
17
|
+
const react_query_1 = require("@tanstack/react-query");
|
|
18
|
+
const projects_js_1 = require("../lib/react-query/projects.js");
|
|
19
|
+
const client_js_1 = require("./client.js");
|
|
20
|
+
/**
|
|
21
|
+
* Retrieve the project settings for a project.
|
|
22
|
+
*
|
|
23
|
+
* @param opts.projectId Project public ID
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* ```tsx
|
|
27
|
+
* function BasicExample() {
|
|
28
|
+
* const { data } = useProjectSettings({ projectId: '...' })
|
|
29
|
+
*
|
|
30
|
+
* console.log(data.name)
|
|
31
|
+
* }
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
function useProjectSettings({ projectId }) {
|
|
35
|
+
const clientApi = (0, client_js_1.useClientApi)();
|
|
36
|
+
const { data: projectApi } = (0, react_query_1.useSuspenseQuery)((0, projects_js_1.projectByIdQueryOptions)({
|
|
37
|
+
projectId,
|
|
38
|
+
clientApi,
|
|
39
|
+
}));
|
|
40
|
+
const { data, error, isRefetching } = (0, react_query_1.useSuspenseQuery)((0, projects_js_1.projectSettingsQueryOptions)({
|
|
41
|
+
projectApi,
|
|
42
|
+
projectId,
|
|
43
|
+
}));
|
|
44
|
+
return { data, error, isRefetching };
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Retrieve a project API instance for a project.
|
|
48
|
+
*
|
|
49
|
+
* This is mostly used internally by the other hooks and should only be used if certain project APIs are not exposed via the hooks.
|
|
50
|
+
*
|
|
51
|
+
* @param opts.projectId Project public ID
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* ```tsx
|
|
55
|
+
* function BasicExample() {
|
|
56
|
+
* const { data } = useSingleProject({ projectId: '...' })
|
|
57
|
+
* }
|
|
58
|
+
* ```
|
|
59
|
+
*/
|
|
60
|
+
function useSingleProject({ projectId }) {
|
|
61
|
+
const clientApi = (0, client_js_1.useClientApi)();
|
|
62
|
+
const { data, error, isRefetching } = (0, react_query_1.useSuspenseQuery)({
|
|
63
|
+
...(0, projects_js_1.projectByIdQueryOptions)({
|
|
64
|
+
clientApi,
|
|
65
|
+
projectId,
|
|
66
|
+
}),
|
|
67
|
+
// Keep project instances around indefinitely - shouldn't be a memory
|
|
68
|
+
// problem because these are only lightweight proxy objects, and project
|
|
69
|
+
// references are kept indefinitely on the backend anyway once they are
|
|
70
|
+
// accessed
|
|
71
|
+
staleTime: Infinity,
|
|
72
|
+
gcTime: Infinity,
|
|
73
|
+
});
|
|
74
|
+
return { data, error, isRefetching };
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Retrieve project information for each project that exists.
|
|
78
|
+
*
|
|
79
|
+
* @example
|
|
80
|
+
* ```tsx
|
|
81
|
+
* function BasicExample() {
|
|
82
|
+
* const { data } = useManyProjects()
|
|
83
|
+
*
|
|
84
|
+
* console.log(data.map(project => project.name))
|
|
85
|
+
* }
|
|
86
|
+
* ```
|
|
87
|
+
*/
|
|
88
|
+
function useManyProjects() {
|
|
89
|
+
const clientApi = (0, client_js_1.useClientApi)();
|
|
90
|
+
const { data, error, isRefetching } = (0, react_query_1.useSuspenseQuery)((0, projects_js_1.projectsQueryOptions)({
|
|
91
|
+
clientApi,
|
|
92
|
+
}));
|
|
93
|
+
return { data, error, isRefetching };
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Retrieve a single member of a project.
|
|
97
|
+
*
|
|
98
|
+
* @param opts.projectId Project public ID
|
|
99
|
+
* @param opts.projectId Device ID of interest
|
|
100
|
+
*
|
|
101
|
+
* @example
|
|
102
|
+
* ```tsx
|
|
103
|
+
* function BasicExample() {
|
|
104
|
+
* const { data } = useSingleMember({ projectId: '...', deviceId: '...' })
|
|
105
|
+
*
|
|
106
|
+
* console.log(data.role)
|
|
107
|
+
* }
|
|
108
|
+
* ```
|
|
109
|
+
*/
|
|
110
|
+
function useSingleMember({ projectId, deviceId, }) {
|
|
111
|
+
const { data: projectApi } = useSingleProject({ projectId });
|
|
112
|
+
const { data, error, isRefetching } = (0, react_query_1.useSuspenseQuery)((0, projects_js_1.projectMemberByIdQueryOptions)({
|
|
113
|
+
projectApi,
|
|
114
|
+
projectId,
|
|
115
|
+
deviceId,
|
|
116
|
+
}));
|
|
117
|
+
return { data, error, isRefetching };
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Retrieve all members of a project.
|
|
121
|
+
*
|
|
122
|
+
* @param opts.projectId Project public ID
|
|
123
|
+
*
|
|
124
|
+
* @example
|
|
125
|
+
* ```tsx
|
|
126
|
+
* function BasicExample() {
|
|
127
|
+
* const { data } = useManyMembers({ projectId: '...' })
|
|
128
|
+
*
|
|
129
|
+
* console.log(data.role)
|
|
130
|
+
* }
|
|
131
|
+
* ```
|
|
132
|
+
*/
|
|
133
|
+
function useManyMembers({ projectId }) {
|
|
134
|
+
const { data: projectApi } = useSingleProject({ projectId });
|
|
135
|
+
const { data, error, isRefetching } = (0, react_query_1.useSuspenseQuery)((0, projects_js_1.projectMembersQueryOptions)({ projectApi, projectId }));
|
|
136
|
+
return { data, error, isRefetching };
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Retrieve a URL that points to icon resources served by the embedded HTTP server.
|
|
140
|
+
*
|
|
141
|
+
* _TODO: Explain bitmap opts vs svg opts_
|
|
142
|
+
*
|
|
143
|
+
* @param opts.projectId Project public ID
|
|
144
|
+
* @param opts.iconId Icon ID of interest
|
|
145
|
+
* @param opts.mimeType MIME type of desired resource
|
|
146
|
+
* @param opts.pixelDensity Pixel density resource (only applicable when `mimeType` is `'image/png'`)
|
|
147
|
+
* @param opts.size Size of desired resource
|
|
148
|
+
*
|
|
149
|
+
* @example
|
|
150
|
+
* ```tsx
|
|
151
|
+
* function PngExample() {
|
|
152
|
+
* const { data } = useIconUrl({
|
|
153
|
+
* projectId: '...',
|
|
154
|
+
* iconId: '...',
|
|
155
|
+
* mimeType: 'image/png',
|
|
156
|
+
* pixelDensity: 1,
|
|
157
|
+
* size: 'medium'
|
|
158
|
+
* })
|
|
159
|
+
* }
|
|
160
|
+
* ```
|
|
161
|
+
*
|
|
162
|
+
* ```tsx
|
|
163
|
+
* function SvgExample() {
|
|
164
|
+
* const { data } = useIconUrl({
|
|
165
|
+
* projectId: '...',
|
|
166
|
+
* iconId: '...',
|
|
167
|
+
* mimeType: 'image/svg',
|
|
168
|
+
* size: 'medium'
|
|
169
|
+
* })
|
|
170
|
+
* }
|
|
171
|
+
* ```
|
|
172
|
+
*/
|
|
173
|
+
function useIconUrl({ projectId, iconId, ...mimeBasedOpts }) {
|
|
174
|
+
const { data: projectApi } = useSingleProject({ projectId });
|
|
175
|
+
const { data, error, isRefetching } = (0, react_query_1.useSuspenseQuery)((0, projects_js_1.iconUrlQueryOptions)({
|
|
176
|
+
...mimeBasedOpts,
|
|
177
|
+
projectApi,
|
|
178
|
+
projectId,
|
|
179
|
+
iconId,
|
|
180
|
+
}));
|
|
181
|
+
return { data, error, isRefetching };
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* Retrieve a URL that points to a desired blob resource.
|
|
185
|
+
*
|
|
186
|
+
* _TODO: Explain BlobId in more depth_
|
|
187
|
+
*
|
|
188
|
+
* @param opts.projectId Project public Id
|
|
189
|
+
* @param opts.blobId Blob ID of the desired resource
|
|
190
|
+
*
|
|
191
|
+
* @example
|
|
192
|
+
* ```tsx
|
|
193
|
+
* function PhotoExample() {
|
|
194
|
+
* const { data } = useAttachmentUrl({
|
|
195
|
+
* projectId: '...',
|
|
196
|
+
* blobId: {
|
|
197
|
+
* type: 'photo',
|
|
198
|
+
* variant: 'thumbnail',
|
|
199
|
+
* name: '...',
|
|
200
|
+
* driveId: '...',
|
|
201
|
+
* }
|
|
202
|
+
* })
|
|
203
|
+
* }
|
|
204
|
+
* ```
|
|
205
|
+
*
|
|
206
|
+
* ```tsx
|
|
207
|
+
* function AudioExample() {
|
|
208
|
+
* const { data } = useAttachmentUrl({
|
|
209
|
+
* projectId: '...',
|
|
210
|
+
* blobId: {
|
|
211
|
+
* type: 'audio',
|
|
212
|
+
* variant: 'original',
|
|
213
|
+
* name: '...',
|
|
214
|
+
* driveId: '...',
|
|
215
|
+
* }
|
|
216
|
+
* })
|
|
217
|
+
* }
|
|
218
|
+
* ```
|
|
219
|
+
*
|
|
220
|
+
* ```tsx
|
|
221
|
+
* function VideoExample() {
|
|
222
|
+
* const { data } = useAttachmentUrl({
|
|
223
|
+
* projectId: '...',
|
|
224
|
+
* blobId: {
|
|
225
|
+
* type: 'video',
|
|
226
|
+
* variant: 'original',
|
|
227
|
+
* name: '...',
|
|
228
|
+
* driveId: '...',
|
|
229
|
+
* }
|
|
230
|
+
* })
|
|
231
|
+
* }
|
|
232
|
+
* ```
|
|
233
|
+
*/
|
|
234
|
+
function useAttachmentUrl({ projectId, blobId, }) {
|
|
235
|
+
const { data: projectApi } = useSingleProject({ projectId });
|
|
236
|
+
const { data, error, isRefetching } = (0, react_query_1.useSuspenseQuery)((0, projects_js_1.attachmentUrlQueryOptions)({
|
|
237
|
+
projectApi,
|
|
238
|
+
projectId,
|
|
239
|
+
blobId,
|
|
240
|
+
}));
|
|
241
|
+
return { data, error, isRefetching };
|
|
242
|
+
}
|
|
243
|
+
// TODO: Eventually remove in favor of this information being provided by the backend when retrieving documents
|
|
244
|
+
/**
|
|
245
|
+
* Retrieve the device ID that created a document.
|
|
246
|
+
*
|
|
247
|
+
* @param opts.projectId Project public ID
|
|
248
|
+
* @param opts.originalVersionId Version ID of document
|
|
249
|
+
*
|
|
250
|
+
* @example
|
|
251
|
+
* ```tsx
|
|
252
|
+
* function BasicExample() {
|
|
253
|
+
* const { data } = useDocumentCreatedBy({
|
|
254
|
+
* projectId: '...',
|
|
255
|
+
* originalVersionId: '...',
|
|
256
|
+
* })
|
|
257
|
+
* }
|
|
258
|
+
* ```
|
|
259
|
+
*/
|
|
260
|
+
function useDocumentCreatedBy({ projectId, originalVersionId, }) {
|
|
261
|
+
const { data: projectApi } = useSingleProject({ projectId });
|
|
262
|
+
const { data, error, isRefetching } = (0, react_query_1.useSuspenseQuery)((0, projects_js_1.documentCreatedByQueryOptions)({ projectApi, projectId, originalVersionId }));
|
|
263
|
+
return { data, error, isRefetching };
|
|
264
|
+
}
|
|
265
|
+
function useAddServerPeer({ projectId }) {
|
|
266
|
+
const queryClient = (0, react_query_1.useQueryClient)();
|
|
267
|
+
const { data: projectApi } = useSingleProject({ projectId });
|
|
268
|
+
const { mutate, reset, status } = (0, react_query_1.useMutation)((0, projects_js_1.addServerPeerMutationOptions)({ projectApi, projectId, queryClient }));
|
|
269
|
+
return { mutate, reset, status };
|
|
270
|
+
}
|
|
271
|
+
/**
|
|
272
|
+
* Create a new project.
|
|
273
|
+
*/
|
|
274
|
+
function useCreateProject() {
|
|
275
|
+
const queryClient = (0, react_query_1.useQueryClient)();
|
|
276
|
+
const clientApi = (0, client_js_1.useClientApi)();
|
|
277
|
+
const { mutate, status, reset } = (0, react_query_1.useMutation)((0, projects_js_1.createProjectMutationOptions)({ clientApi, queryClient }));
|
|
278
|
+
return { mutate, reset, status };
|
|
279
|
+
}
|
|
280
|
+
/**
|
|
281
|
+
* Leave an existing project.
|
|
282
|
+
*/
|
|
283
|
+
function useLeaveProject() {
|
|
284
|
+
const queryClient = (0, react_query_1.useQueryClient)();
|
|
285
|
+
const clientApi = (0, client_js_1.useClientApi)();
|
|
286
|
+
const { mutate, status, reset } = (0, react_query_1.useMutation)((0, projects_js_1.leaveProjectMutationOptions)({ clientApi, queryClient }));
|
|
287
|
+
return { mutate, reset, status };
|
|
288
|
+
}
|
|
289
|
+
/**
|
|
290
|
+
* Update the configuration of a project using an external file.
|
|
291
|
+
*
|
|
292
|
+
* @param opts.projectId Public ID of the project to apply changes to.
|
|
293
|
+
*/
|
|
294
|
+
function useImportProjectConfig({ projectId }) {
|
|
295
|
+
const queryClient = (0, react_query_1.useQueryClient)();
|
|
296
|
+
const { data: projectApi } = useSingleProject({ projectId });
|
|
297
|
+
const { mutate, status, reset } = (0, react_query_1.useMutation)((0, projects_js_1.importProjectConfigMutationOptions)({ queryClient, projectApi, projectId }));
|
|
298
|
+
return { mutate, reset, status };
|
|
299
|
+
}
|
|
300
|
+
/**
|
|
301
|
+
* Update the settings of a project.
|
|
302
|
+
*
|
|
303
|
+
* @param opts.projectId Public ID of the project to apply changes to.
|
|
304
|
+
*/
|
|
305
|
+
function useUpdateProjectSettings({ projectId }) {
|
|
306
|
+
const queryClient = (0, react_query_1.useQueryClient)();
|
|
307
|
+
const { data: projectApi } = useSingleProject({ projectId });
|
|
308
|
+
const { mutate, reset, status } = (0, react_query_1.useMutation)((0, projects_js_1.updateProjectSettingsMutationOptions)({ projectApi, queryClient }));
|
|
309
|
+
return { mutate, reset, status };
|
|
310
|
+
}
|
|
311
|
+
/**
|
|
312
|
+
* Create a blob for a project.
|
|
313
|
+
*
|
|
314
|
+
* @param opts.projectId Public project ID of project to apply to changes to.
|
|
315
|
+
*/
|
|
316
|
+
function useCreateBlob({ projectId }) {
|
|
317
|
+
const { data: projectApi } = useSingleProject({ projectId });
|
|
318
|
+
const { mutate, reset, status } = (0, react_query_1.useMutation)((0, projects_js_1.createBlobMutationOptions)({ projectApi }));
|
|
319
|
+
return { mutate, reset, status };
|
|
320
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export { ClientApiContext, ClientApiProvider } from './contexts/ClientApi.js';
|
|
2
|
+
export { useClientApi, useIsArchiveDevice, useOwnDeviceInfo, useSetIsArchiveDevice, useSetOwnDeviceInfo, } from './hooks/client.js';
|
|
3
|
+
export { useCreateDocument, useDeleteDocument, useManyDocs, useSingleDocByDocId, useSingleDocByVersionId, useUpdateDocument, } from './hooks/documents.js';
|
|
4
|
+
export { useAcceptInvite, useRejectInvite, useRequestCancelInvite, useSendInvite, } from './hooks/invites.js';
|
|
5
|
+
export { useMapStyleUrl } from './hooks/maps.js';
|
|
6
|
+
export { useAddServerPeer, useAttachmentUrl, useCreateBlob, useCreateProject, useDocumentCreatedBy, useIconUrl, useImportProjectConfig, useLeaveProject, useManyMembers, useManyProjects, useProjectSettings, useSingleMember, useSingleProject, useUpdateProjectSettings, } from './hooks/projects.js';
|
|
7
|
+
export { getClientQueryKey, getDeviceInfoQueryKey, getIsArchiveDeviceQueryKey, } from './lib/react-query/client.js';
|
|
8
|
+
export { getDocumentByDocIdQueryKey, getDocumentByVersionIdQueryKey, getDocumentsQueryKey, getManyDocumentsQueryKey, type WriteableDocument, type WriteableDocumentType, type WriteableValue, } from './lib/react-query/documents.js';
|
|
9
|
+
export { getInvitesQueryKey, getPendingInvitesQueryKey, } from './lib/react-query/invites.js';
|
|
10
|
+
export { getMapsQueryKey, getStyleJsonUrlQueryKey, } from './lib/react-query/maps.js';
|
|
11
|
+
export { getAttachmentUrlQueryKey, getDocumentCreatedByQueryKey, getIconUrlQueryKey, getMemberByIdQueryKey, getMembersQueryKey, getProjectByIdQueryKey, getProjectRoleQueryKey, getProjectSettingsQueryKey, getProjectsQueryKey, } from './lib/react-query/projects.js';
|
|
12
|
+
export { ROOT_QUERY_KEY } from './lib/react-query/shared.js';
|