@powerhousedao/reactor-browser 5.1.0-staging.0 → 5.1.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.
Files changed (61) hide show
  1. package/README.md +482 -282
  2. package/dist/src/actions/dispatch.js +1 -1
  3. package/dist/src/actions/dispatch.js.map +1 -1
  4. package/dist/src/actions/document.js +12 -12
  5. package/dist/src/actions/document.js.map +1 -1
  6. package/dist/src/actions/drive.js +9 -9
  7. package/dist/src/actions/drive.js.map +1 -1
  8. package/dist/src/actions/queue.js +2 -2
  9. package/dist/src/actions/queue.js.map +1 -1
  10. package/dist/src/actions/sign.js +1 -1
  11. package/dist/src/actions/sign.js.map +1 -1
  12. package/dist/src/hooks/add-ph-event-handlers.d.ts.map +1 -1
  13. package/dist/src/hooks/add-ph-event-handlers.js +2 -6
  14. package/dist/src/hooks/add-ph-event-handlers.js.map +1 -1
  15. package/dist/src/hooks/connect.d.ts +1 -1
  16. package/dist/src/hooks/connect.d.ts.map +1 -1
  17. package/dist/src/hooks/connect.js +1 -1
  18. package/dist/src/hooks/connect.js.map +1 -1
  19. package/dist/src/hooks/crypto.d.ts +1 -7
  20. package/dist/src/hooks/crypto.d.ts.map +1 -1
  21. package/dist/src/hooks/crypto.js +1 -7
  22. package/dist/src/hooks/crypto.js.map +1 -1
  23. package/dist/src/hooks/index.d.ts +0 -1
  24. package/dist/src/hooks/index.d.ts.map +1 -1
  25. package/dist/src/hooks/index.js +0 -1
  26. package/dist/src/hooks/index.js.map +1 -1
  27. package/dist/src/hooks/reactor.d.ts +5 -18
  28. package/dist/src/hooks/reactor.d.ts.map +1 -1
  29. package/dist/src/hooks/reactor.js +6 -20
  30. package/dist/src/hooks/reactor.js.map +1 -1
  31. package/dist/src/hooks/renown.d.ts +2 -3
  32. package/dist/src/hooks/renown.d.ts.map +1 -1
  33. package/dist/src/hooks/renown.js.map +1 -1
  34. package/dist/src/hooks/user.d.ts +1 -7
  35. package/dist/src/hooks/user.d.ts.map +1 -1
  36. package/dist/src/hooks/user.js +1 -7
  37. package/dist/src/hooks/user.js.map +1 -1
  38. package/dist/src/hooks/vetra-packages.js +1 -1
  39. package/dist/src/hooks/vetra-packages.js.map +1 -1
  40. package/dist/src/reactor.d.ts +1 -1
  41. package/dist/src/reactor.d.ts.map +1 -1
  42. package/dist/src/reactor.js +5 -5
  43. package/dist/src/reactor.js.map +1 -1
  44. package/dist/src/renown/constants.d.ts +1 -1
  45. package/dist/src/renown/constants.d.ts.map +1 -1
  46. package/dist/src/renown/constants.js +1 -1
  47. package/dist/src/renown/constants.js.map +1 -1
  48. package/dist/src/renown/utils.d.ts +2 -2
  49. package/dist/src/renown/utils.d.ts.map +1 -1
  50. package/dist/src/renown/utils.js +1 -1
  51. package/dist/src/renown/utils.js.map +1 -1
  52. package/dist/src/types/global.d.ts +1 -5
  53. package/dist/src/types/global.d.ts.map +1 -1
  54. package/dist/src/utils/drives.js +2 -2
  55. package/dist/src/utils/drives.js.map +1 -1
  56. package/dist/tsconfig.tsbuildinfo +1 -1
  57. package/package.json +5 -7
  58. package/dist/src/hooks/features.d.ts +0 -5
  59. package/dist/src/hooks/features.d.ts.map +0 -1
  60. package/dist/src/hooks/features.js +0 -6
  61. package/dist/src/hooks/features.js.map +0 -1
package/README.md CHANGED
@@ -1,492 +1,692 @@
1
- # Reactor Browser Hooks API Documentation
1
+ # Editor state management hooks
2
2
 
3
- This document contains all documentation comments for the hooks exported from `packages/reactor-browser/src/hooks/index.ts`.
3
+ This library provides hooks intended to be used by editors (including drive editors) which will be rendered inside of Powerhouse applications such as Connect and Vetra.
4
4
 
5
- ## Table of Contents
5
+ ## Key concepts
6
6
 
7
- - [Allowed Document Model Modules](#allowed-document-model-modules)
8
- - [Child Nodes](#child-nodes)
9
- - [Config: Editor](#config-editor)
10
- - [Config: Set Config by Object](#config-set-config-by-object)
11
- - [Config: Use Value by Key](#config-use-value-by-key)
12
- - [Document by ID](#document-by-id)
13
- - [Document Cache](#document-cache)
14
- - [Document of Type](#document-of-type)
15
- - [Document Types](#document-types)
16
- - [Drives](#drives)
17
- - [Items in Selected Drive](#items-in-selected-drive)
18
- - [Items in Selected Folder](#items-in-selected-folder)
19
- - [Modals](#modals)
20
- - [Node by ID](#node-by-id)
21
- - [Node Path](#node-path)
22
- - [Revision History](#revision-history)
23
- - [Selected Document](#selected-document)
24
- - [Selected Drive](#selected-drive)
25
- - [Selected Folder](#selected-folder)
26
- - [Selected Node](#selected-node)
27
- - [Selected Timeline Item](#selected-timeline-item)
28
- - [Supported Document Types](#supported-document-types)
29
- - [Timeline Revision](#timeline-revision)
30
- - [Use Get Switchboard Link](#use-get-switchboard-link)
31
- - [Vetra Packages](#vetra-packages)
7
+ ### Reactor
32
8
 
33
- ---
9
+ All of the data used by these hooks is ultimately derived from the `Reactor`, which manages the asynchronous eventually consistent state of drives and documents.
34
10
 
35
- ## Allowed Document Model Modules
11
+ ### Selected drives, folders and documents
36
12
 
37
- ### `useAllowedDocumentModelModules`
13
+ In the application, there are certain items that can be set as "selected".
38
14
 
39
- No documentation available.
15
+ - selected drive
16
+ - selected folder
17
+ - selected document
40
18
 
41
- ---
19
+ We provide hooks for getting the selected item for each:
42
20
 
43
- ## Child Nodes
21
+ `useSelectedDrive`
22
+ `useSelectedFolder`
23
+ `useSelectedDocument`
44
24
 
45
- ### `useNodesInSelectedDriveOrFolder`
25
+ Folders and documents are part of a given drive, so they will both be undefined if the selected drive is undefined.
46
26
 
47
- Returns the child nodes for the selected drive or folder.
48
-
49
- ---
50
-
51
- ## Document by ID
52
-
53
- ### `useDocumentById`
54
-
55
- Returns a document by id.
56
-
57
- ### `useDocumentsByIds`
58
-
59
- Returns documents by ids.
60
-
61
- ---
62
-
63
- ## Document Cache
64
-
65
- ### `useDocumentCache`
27
+ _Either_ a folder or a document can be selected but not both, so if one is defined then the other will be undefined.
66
28
 
67
- Returns all documents in the reactor.
29
+ To set the selected drive, we provide a function `setSelectedDrive` which takes either a `DocumentDriveDocument` or a `DocumentDriveDocument['header']['slug']`.
68
30
 
69
- ### `setDocumentCache`
31
+ To set the selected document/folder, we provide a function `setSelectedNode` which returns a setter function which can be used for _both_ documents and folders. This function takes either a `Node` or a slug which can be the url slug or the node's id.
70
32
 
71
- Sets all of the documents in the reactor.
33
+ ## Hooks
72
34
 
73
- ### `addDocumentCacheEventHandler`
35
+ ### Reactor
74
36
 
75
- Adds an event handler for all of the documents in the reactor.
37
+ ```ts
38
+ function useReactor(): Reactor | undefined;
39
+ ```
76
40
 
77
- ### `useGetDocument`
41
+ Returns the reactor instance.
78
42
 
79
- Retrieves a document from the reactor and subscribes to changes using React Suspense.
80
- This hook will suspend rendering while the document is loading.
43
+ ##### Usage
81
44
 
82
- **Parameters:**
83
- - `id` - The document ID to retrieve, or null/undefined to skip retrieval
45
+ ```jsx
46
+ import { useReactor } from '@powerhousedao/state`
84
47
 
85
- **Returns:** The document if found, or undefined if id is null/undefined
48
+ function MyEditorComponent() {
49
+ const reactor = useReactor();
50
+ }
51
+ ```
86
52
 
87
- ### `useGetDocuments`
53
+ ### Drives
88
54
 
89
- Retrieves multiple documents from the reactor using React Suspense.
90
- This hook will suspend rendering while any of the documents are loading.
55
+ #### useDrives
91
56
 
92
- **Parameters:**
93
- - `ids` - Array of document IDs to retrieve, or null/undefined to skip retrieval
57
+ ```ts
58
+ function useDrives(): DocumentDriveDocument[] | undefined;
59
+ ```
94
60
 
95
- **Returns:** An array of documents if found, or undefined if ids is null/undefined
61
+ Returns the drives for a reactor.
96
62
 
97
- ### `useGetDocumentAsync`
63
+ ##### Usage
98
64
 
99
- Retrieves a document from the reactor without suspending rendering.
100
- Returns the current state of the document loading operation.
65
+ ```jsx
66
+ import { useDrives } from "@powerhousedao/state";
101
67
 
102
- **Parameters:**
103
- - `id` - The document ID to retrieve, or null/undefined to skip retrieval
68
+ function MyEditorComponent() {
69
+ const drives = useDrives();
70
+ }
71
+ ```
104
72
 
105
- **Returns:** An object containing:
106
- - `status`: "initial" | "pending" | "success" | "error"
107
- - `data`: The document if successfully loaded
108
- - `isPending`: Boolean indicating if the document is currently loading
109
- - `error`: Any error that occurred during loading
110
- - `reload`: Function to force reload the document from cache
73
+ #### useDriveById
111
74
 
112
- ---
75
+ ```ts
76
+ function useDriveById(
77
+ id: string | null | undefined,
78
+ ): DocumentDriveDocument | undefined;
79
+ ```
113
80
 
114
- ## Document of Type
81
+ Returns a drive by id.
115
82
 
116
- ### `useDocumentOfType`
83
+ ##### Usage
117
84
 
118
- Returns a document of a specific type, throws an error if the found document has a different type.
85
+ ```jsx
86
+ import { useDriveById } from "@powerhousedao/state";
119
87
 
120
- ---
88
+ function MyEditorComponent() {
89
+ const driveById = useDriveById();
90
+ }
91
+ ```
121
92
 
122
- ## Document Types
93
+ #### useSelectedDrive
123
94
 
124
- ### `useDocumentTypes`
95
+ ```ts
96
+ function useSelectedDrive(): DocumentDriveDocument | undefined;
97
+ ```
125
98
 
126
- Returns the document types a drive editor supports.
99
+ Returns the selected drive. You can se the selected drive with `setSelectedDrive`.
127
100
 
128
- If present, uses the `allowedDocumentTypes` config value.
129
- Otherwise, uses the supported document types from the reactor.
101
+ ##### Usage
130
102
 
131
- ---
103
+ ```jsx
104
+ import { useSelectedDrive } from "@powerhousedao/state";
132
105
 
133
- ## Drives
106
+ function MyEditorComponent() {
107
+ const selectedDrive = useSelectedDrive();
108
+ }
109
+ ```
134
110
 
135
- ### `useDrives`
111
+ #### drive properties convenience hooks
136
112
 
137
- Returns all of the drives in the reactor.
113
+ We provide hooks for accessing various properties on the drive object for your convenience. These use the above hooks to get a drive and then return properties in the object.
138
114
 
139
- ### `setDrives`
115
+ ```ts
116
+ /** Returns the remote URL for a drive. */
117
+ function useDriveRemoteUrl(
118
+ driveId: string | null | undefined,
119
+ ): string | undefined;
140
120
 
141
- Sets the drives in the reactor.
121
+ /** Returns the pull responder trigger for a drive. */
122
+ function useDrivePullResponderTrigger(
123
+ driveId: string | null | undefined,
124
+ ): Trigger | undefined;
142
125
 
143
- ### `addDrivesEventHandler`
126
+ /** Returns the pull responder URL for a drive. */
127
+ function useDrivePullResponderUrl(
128
+ driveId: string | null | undefined,
129
+ ): string | undefined;
144
130
 
145
- Adds an event handler for the drives.
131
+ /** Returns whether a drive is remote. */
132
+ function useDriveIsRemote(driveId: string | null | undefined): boolean;
146
133
 
147
- ---
134
+ /** Returns the sharing type for a drive. */
135
+ function useDriveSharingType(
136
+ driveId: string | null | undefined,
137
+ ): SharingType | undefined;
148
138
 
149
- ## Items in Selected Drive
139
+ /** Returns whether a drive is available offline. */
140
+ function useDriveAvailableOffline(driveId: string | null | undefined): boolean;
141
+ ```
150
142
 
151
- ### `useNodesInSelectedDrive`
143
+ ##### Usage
152
144
 
153
- Returns the nodes in the selected drive.
145
+ ```jsx
146
+ import {
147
+ useDriveRemoteUrl,
148
+ useDrivePullResponderTrigger,
149
+ useDrivePullResponderUrl,
150
+ useDriveIsRemote,
151
+ useDriveSharingType,
152
+ useDriveAvailableOffline,
153
+ } from "@powerhousedao/state";
154
154
 
155
- ### `useFileNodesInSelectedDrive`
155
+ function MyEditorComponent() {
156
+ const myDriveId = "some-drive-id";
157
+ const driveRemoteUrl = useDriveRemoteUrl(myDriveId);
158
+ const drivePullResponderTrigger = useDrivePullResponderTrigger(myDriveId);
159
+ const drivePullResponderUrl = useDrivePullResponderUrl(myDriveId);
160
+ const driveIsRemote = useDriveIsRemote(myDriveId);
161
+ const driveSharingType = useDriveSharingType(myDriveId);
162
+ const driveAvailableOffline = useDriveAvailableOffline(myDriveId);
156
163
 
157
- Returns the file nodes in the selected drive.
164
+ console.log({
165
+ driveRemoteUrl,
166
+ drivePullResponderTrigger,
167
+ drivePullResponderUrl,
168
+ driveIsRemote,
169
+ driveSharingType,
170
+ driveAvailableOffline,
171
+ });
172
+ }
173
+ ```
158
174
 
159
- ### `useFolderNodesInSelectedDrive`
175
+ ### Documents
160
176
 
161
- Returns the folder nodes in the selected drive.
177
+ #### useDocumentById
162
178
 
163
- ### `useDocumentsInSelectedDrive`
179
+ ```ts
180
+ function useDocumentById(id: string | null | undefined): PHDocument | undefined;
181
+ ```
164
182
 
165
- Returns the documents in the selected drive.
183
+ Returns a document and a dispatch function by id.
166
184
 
167
- ### `useDocumentTypesInSelectedDrive`
185
+ ##### Usage
168
186
 
169
- Returns the document types supported by the selected drive, as defined by the document model documents present in the drive.
187
+ ```jsx
188
+ import { useDocumentById } from "@powerhousedao/state";
170
189
 
171
- ---
190
+ function MyEditorComponent() {
191
+ const myDocumentId = "some-document-id";
192
+ const [document, dispatch] = useDocumentById(myDocumentId);
193
+ }
194
+ ```
172
195
 
173
- ## Items in Selected Folder
196
+ #### useGetDocument
174
197
 
175
- ### `useNodesInSelectedFolder`
198
+ ```ts
199
+ function useGetDocument(id: string | null | undefined): PHDocument | undefined;
200
+ ```
176
201
 
177
- Returns the nodes in the selected folder.
202
+ Retrieves a document from the reactor and subscribes to changes using React Suspense. This hook will suspend rendering while the document is loading.
178
203
 
179
- ### `useFileNodesInSelectedFolder`
204
+ ##### Usage
180
205
 
181
- Returns the file nodes in the selected folder.
206
+ ```jsx
207
+ import { useGetDocument } from "@powerhousedao/state";
182
208
 
183
- ### `useFolderNodesInSelectedFolder`
209
+ function MyEditorComponent() {
210
+ const documentId = "some-document-id";
211
+ const document = useGetDocument(documentId);
212
+ }
213
+ ```
184
214
 
185
- Returns the folder nodes in the selected folder.
215
+ #### useGetDocuments
186
216
 
187
- ### `useDocumentsInSelectedFolder`
217
+ ```ts
218
+ function useGetDocuments(
219
+ ids: string[] | null | undefined,
220
+ ): PHDocument[] | undefined;
221
+ ```
188
222
 
189
- Returns the documents in the selected folder.
223
+ Retrieves multiple documents from the reactor using React Suspense. This hook will suspend rendering while any of the documents are loading.
190
224
 
191
- ---
225
+ ##### Usage
192
226
 
193
- ## Modals
227
+ ```jsx
228
+ import { useGetDocuments } from "@powerhousedao/state";
194
229
 
195
- ### `usePHModal`
230
+ function MyEditorComponent() {
231
+ const documentIds = ["doc-id-1", "doc-id-2", "doc-id-3"];
232
+ const documents = useGetDocuments(documentIds);
233
+ }
234
+ ```
196
235
 
197
- Returns the current modal.
236
+ #### useGetDocumentAsync
198
237
 
199
- ### `setPHModal`
238
+ ```ts
239
+ function useGetDocumentAsync(id: string | null | undefined): {
240
+ status: "initial" | "pending" | "success" | "error";
241
+ data: PHDocument | undefined;
242
+ isPending: boolean;
243
+ error: unknown;
244
+ reload: (() => void) | undefined;
245
+ };
246
+ ```
200
247
 
201
- Sets the current modal.
248
+ Retrieves a document from the reactor without suspending rendering. Returns the current state of the document loading operation, including status, data, error, and a reload function.
202
249
 
203
- ### `addModalEventHandler`
250
+ ##### Usage
204
251
 
205
- Adds an event handler for the modal.
252
+ ```jsx
253
+ import { useGetDocumentAsync } from "@powerhousedao/state";
206
254
 
207
- ### `showPHModal`
255
+ function MyEditorComponent() {
256
+ const documentId = "some-document-id";
257
+ const { status, data, isPending, error, reload } =
258
+ useGetDocumentAsync(documentId);
208
259
 
209
- Shows a modal.
260
+ if (isPending) {
261
+ return <div>Loading...</div>;
262
+ }
210
263
 
211
- ### `closePHModal`
264
+ if (error) {
265
+ return <div>Error: {error.message}</div>;
266
+ }
212
267
 
213
- Closes the current modal.
268
+ if (status === "success" && data) {
269
+ return <div>Document: {data.name}</div>;
270
+ }
271
+ }
272
+ ```
214
273
 
215
- ### `showCreateDocumentModal`
274
+ #### useDocumentsInSelectedDrive
216
275
 
217
- Shows the create document modal.
276
+ ```ts
277
+ function useDocumentsInSelectedDrive(): PHDocument[] | undefined;
278
+ ```
218
279
 
219
- ### `showDeleteNodeModal`
280
+ Returns the documents in the reactor for the selected drive.
220
281
 
221
- Shows the delete node modal.
282
+ ##### Usage
222
283
 
223
- ---
284
+ ```jsx
285
+ import { useDocumentsInSelectedDrive } from "@powerhousedao/state";
224
286
 
225
- ## Node by ID
287
+ function MyEditorComponent() {
288
+ const selectedDriveDocuments = useDocumentsInSelectedDrive();
289
+ }
290
+ ```
226
291
 
227
- ### `useNodeById`
292
+ #### useSelectedDocument
228
293
 
229
- Returns a node in the selected drive by id.
230
-
231
- ---
232
-
233
- ## Node Path
234
-
235
- ### `useNodePathById`
236
-
237
- Returns the path to a node in the selected drive.
294
+ ```ts
295
+ function useSelectedDocument(): PHDocument | undefined;
296
+ ```
238
297
 
239
- ### `useSelectedNodePath`
298
+ Returns the selected document. You can set the selected document with `setSelectedNode`.
240
299
 
241
- Returns the path to the currently selected node in the selected drive.
300
+ ##### Usage
242
301
 
243
- ---
302
+ ```jsx
303
+ import { useSelectedDocument } from "@powerhousedao/state";
244
304
 
245
- ## Revision History
305
+ function MyEditorComponent() {
306
+ const selectedDocument = useSelectedDocument();
307
+ }
308
+ ```
246
309
 
247
- ### `useRevisionHistoryVisible`
310
+ ### Nodes
248
311
 
249
- Returns whether revision history is visible.
312
+ "Nodes" refers to the items found in a given drive's `state.global.nodes` array. Nodes can represent both files (documents) and folders.
250
313
 
251
- ### `setRevisionHistoryVisible`
314
+ A document in a drive will have a node in the drive's node list which has the same id as the document.
252
315
 
253
- Sets revision history visibility.
316
+ Nodes have an optional `parentFolder` field, which is the id of a folder node in the drive when it is defined. If it is undefined, the node is a direct child of the drive.
254
317
 
255
- ### `addRevisionHistoryVisibleEventHandler`
318
+ A given folder node's children are the nodes in the drive's node list which have their parent folder set to the folder node's id.
256
319
 
257
- Adds event handler for revision history visibility.
320
+ ```ts
321
+ type FileNode = {
322
+ documentType: string;
323
+ id: string;
324
+ kind: string;
325
+ name: string;
326
+ parentFolder: string | null | undefined;
327
+ };
258
328
 
259
- ### `showRevisionHistory`
329
+ type FolderNode = {
330
+ id: string;
331
+ kind: string;
332
+ name: string;
333
+ parentFolder: string | null | undefined;
334
+ };
260
335
 
261
- Shows the revision history.
336
+ type Node = FileNode | FolderNode;
337
+ ```
262
338
 
263
- ### `hideRevisionHistory`
339
+ #### useNodes
264
340
 
265
- Hides the revision history.
341
+ Ideally you should not need to handle the list of nodes directly, since we already provide documents and folders. But these hooks are provided just in case.
266
342
 
267
- ---
343
+ ```ts
344
+ function useNodes(): Node[] | undefined;
345
+ ```
268
346
 
269
- ## Selected Document
347
+ Returns the nodes for a drive.
270
348
 
271
- ### `useSelectedDocumentId`
349
+ ##### Usage
272
350
 
273
- Returns the selected document id.
351
+ ```jsx
352
+ import { useNodes } from "@powerhousedao/state";
274
353
 
275
- ### `useSelectedDocument`
354
+ function MyEditorComponent() {
355
+ const nodes = useNodes();
356
+ }
357
+ ```
276
358
 
277
- Returns the selected document.
359
+ #### useNodeById
278
360
 
279
- ### `useSelectedDocumentOfType`
361
+ ```ts
362
+ function useNodeById(id: string | null | undefined): Node | undefined;
363
+ ```
280
364
 
281
- Returns the selected document of a specific type, throws an error if the found document has a different type.
282
-
283
- ---
284
-
285
- ## Selected Drive
286
-
287
- ### `useSelectedDriveId`
365
+ Returns a node in the selected drive by id.
288
366
 
289
- Returns the selected drive id.
367
+ ##### Usage
290
368
 
291
- ### `setSelectedDriveId`
369
+ ```jsx
370
+ import { useNodeById } from "@powerhousedao/state";
292
371
 
293
- Sets the selected drive id.
372
+ function MyEditorComponent() {
373
+ const myFolderId = "some-folder-id";
374
+ const myDocumentId = "some-document-id";
375
+ const myFolderNode = useNodeById(myFolderId);
376
+ const myFileNode = useNodeById(myDocumentId);
377
+ }
378
+ ```
294
379
 
295
- ### `addSelectedDriveIdEventHandler`
380
+ #### useSelectedFolder
296
381
 
297
- Adds an event handler for the selected drive id.
382
+ ```ts
383
+ function useSelectedFolder(): FolderNode | undefined;
384
+ ```
298
385
 
299
- ### `useSelectedDrive`
386
+ Returns the selected folder. You can set the selected folder with `setSelectedNode`
300
387
 
301
- Returns the selected drive.
388
+ ##### Usage
302
389
 
303
- ### `useSelectedDriveSafe`
390
+ ```jsx
391
+ import { useSelectedFolder } from "@powerhousedao/state";
304
392
 
305
- Returns the selected drive, or undefined if no drive is selected.
393
+ function MyEditorComponent() {
394
+ const selectedFolder = useSelectedFolder();
395
+ }
396
+ ```
306
397
 
307
- ---
398
+ #### useSelectedNodePath
308
399
 
309
- ## Selected Folder
400
+ ```ts
401
+ function useSelectedNodePath(): Node[];
402
+ ```
310
403
 
311
- ### `useSelectedFolder`
404
+ Returns the path to the selected node. Useful for navigational components like breadcrumbs.
312
405
 
313
- Returns the selected folder.
406
+ ##### Usage
314
407
 
315
- ---
408
+ ```jsx
409
+ import { useSelectedNodePath } from '@powerhousedao/state';
316
410
 
317
- ## Selected Node
411
+ function MyEditorComponent() {
412
+ const nodes = useSelectedNodePath();
318
413
 
319
- ### `useSelectedNode`
414
+ return <Breadcrumbs nodes={nodes}>
415
+ }
416
+ ```
320
417
 
321
- Returns the selected node.
418
+ #### useChildNodes/useFolderChildNodes/useFileChildNodes
322
419
 
323
- ### `setSelectedNode`
420
+ ```ts
421
+ function useChildNodes(): Node[];
422
+ ```
324
423
 
325
- Sets the selected node (file or folder).
424
+ Returns the child nodes for the selected drive or folder.
326
425
 
327
- ---
426
+ ```ts
427
+ function useFolderChildNodes(): FolderNode[];
428
+ ```
328
429
 
329
- ## Selected Timeline Item
430
+ Returns the folder child nodes for the selected drive or folder.
330
431
 
331
- ### `useSelectedTimelineItem`
432
+ ```ts
433
+ function useFileChildNodes(): FileNode[];
434
+ ```
332
435
 
333
- Returns the selected timeline item.
436
+ Returns the file (document) child nodes for the selected drive or folder.
334
437
 
335
- ### `setSelectedTimelineItem`
438
+ ##### Usage
336
439
 
337
- Sets the selected timeline item.
440
+ ```jsx
441
+ import { useChildNodes, useFolderChildNodes, useFileChildNodes } from '@powerhousedao/state';
338
442
 
339
- ### `addSelectedTimelineItemEventHandler`
443
+ function MyEditorComponent() {
444
+ const nodes = useChildNodes();
445
+ const fileNodes = useChildFileNodes();
446
+ const folderNodes = useChildFolderNodes();
340
447
 
341
- Adds event handler for selected timeline item.
448
+ return (
449
+ <div>
450
+ <FilesAndFolders nodes={nodes}>
451
+ <Files fileNodes={fileNodes}>
452
+ <Folders folderNodes={folderNodes}>
453
+ </div>
454
+ )
455
+ }
456
+ ```
342
457
 
343
- ---
458
+ #### useChildNodesForId/useFolderChildNodesForId/useFileChildNodesForId
344
459
 
345
- ## Supported Document Types
460
+ ```ts
461
+ function useChildNodesForId(id: string | null | undefined): Node[];
462
+ ```
346
463
 
347
- ### `useSupportedDocumentTypesInReactor`
464
+ Returns the child nodes for a drive or folder by id.
348
465
 
349
- Returns the supported document types for the reactor (derived from the document model modules).
466
+ ```ts
467
+ function useFolderChildNodesForId(id: string | null | undefined): FolderNode[];
468
+ ```
350
469
 
351
- ---
470
+ Returns the folder child nodes for a drive or folder by id.
352
471
 
353
- ## Timeline Revision
472
+ ```ts
473
+ function useFileChildNodesForId(id: string | null | undefined): FileNode[];
474
+ ```
354
475
 
355
- ### `useSelectedTimelineRevision`
476
+ Returns the file (document) child nodes for a drive or folder by id.
356
477
 
357
- Returns the selected timeline revision.
478
+ ##### Usage
358
479
 
359
- ### `setSelectedTimelineRevision`
480
+ ```jsx
481
+ import { useChildNodesForId, useFolderChildNodesForId, useFileChildNodesForId } from '@powerhousedao/state';
360
482
 
361
- Sets the selected timeline revision.
483
+ function MyEditorComponent() {
484
+ const driveOrFolderId = 'some-drive-or-folder-id';
485
+ const nodes = useChildNodesForId(driveOrFolderId);
486
+ const fileNodes = useFileChildNodesForId(driveOrFolderId);
487
+ const folderNodes = useFolderChildNodesForId(driveOrFolderId);
362
488
 
363
- ### `addSelectedTimelineRevisionEventHandler`
489
+ return (
490
+ <div>
491
+ <FilesAndFolders nodes={nodes}>
492
+ <Files fileNodes={fileNodes}>
493
+ <Folders folderNodes={folderNodes}>
494
+ </div>
495
+ )
496
+ }
497
+ ```
364
498
 
365
- Adds an event handler for the selected timeline revision.
499
+ #### useNodeName/useNodeKind
366
500
 
367
- ---
501
+ ```ts
502
+ function useNodeName(id: string | null | undefined): string | undefined;
503
+ ```
368
504
 
369
- ## Use Get Switchboard Link
505
+ Returns the name of a node.
370
506
 
371
- ### `useGetSwitchboardLink`
507
+ ```ts
508
+ function useNodeKind(id: string | null | undefined): NodeKind | undefined;
509
+ ```
372
510
 
373
- Hook that returns a function to generate a document's switchboard URL.
374
- Only returns a function for documents in remote drives.
375
- Returns null for local drives or when the document/drive cannot be determined.
511
+ Returns the kind of a node.
376
512
 
377
- The returned function generates a fresh bearer token and builds the switchboard URL
378
- with authentication when called.
513
+ ##### Usage
379
514
 
380
- **Parameters:**
381
- - `document` - The document to create a switchboard URL generator for
515
+ ```jsx
516
+ import { useNodeName, useNodeKind } from "@powerhousedao/state";
382
517
 
383
- **Returns:** An async function that returns the switchboard URL, or null if not applicable
518
+ function MyEditorComponent() {
519
+ const nodeId = "some-node-id";
520
+ const nodeName = useNodeName(nodeId);
521
+ const nodeKind = useNodeKind(nodeId);
384
522
 
385
- ---
523
+ if (nodeKind === "file") {
524
+ return <File name={nodeName} />;
525
+ }
386
526
 
387
- ## Vetra Packages
527
+ if (nodeKind === "folder") {
528
+ return <Folder name={nodeName} />;
529
+ }
530
+ }
531
+ ```
388
532
 
389
- ### `useVetraPackages`
533
+ ### Vetra packages and modules
390
534
 
391
- Returns all of the Vetra packages loaded by the Connect instance.
535
+ Vetra packages hold code which can plug into your Connect application. This includes common default modules like the document model document model editor and document drive document model, as well as the modules from your local project and the various packages you have installed.
392
536
 
393
- ### `addVetraPackagesEventHandler`
537
+ These modules can be for:
394
538
 
395
- Adds the Vetra packages event handler.
539
+ - document models
540
+ - editors
541
+ - subgraphs
542
+ - import scripts
543
+ - processors
396
544
 
397
- ### `setVetraPackages`
545
+ Each Vetra package contains a `modules` field which optionally contains lists of these modules.
398
546
 
399
- Sets the Vetra packages for the Connect instance.
547
+ #### useVetraPackages
400
548
 
401
- ---
549
+ ```ts
550
+ function useVetraPackages(): VetraPackage[] | undefined;
551
+ ```
402
552
 
553
+ Returns all of the Vetra packages in your Connect app.
403
554
 
404
- ## Config: Editor
555
+ ##### Usage
405
556
 
406
- ### `setIsExternalControlsEnabled`
557
+ ```jsx
558
+ import { useVetraPackages } from "@powerhousedao/state";
407
559
 
408
- Sets whether external controls are enabled for a given editor.
560
+ function MyEditorComponent() {
561
+ const vetraPackages = useVetraPackages();
562
+ }
563
+ ```
409
564
 
410
- ### `useIsExternalControlsEnabled`
565
+ #### useDocumentModelModules
411
566
 
412
- Gets whether external controls are enabled for a given editor.
567
+ ```ts
568
+ function useDocumentModelModules(): DocumentModelModule[] | undefined;
569
+ ```
413
570
 
414
- ### `addIsExternalControlsEnabledEventHandler`
571
+ Returns the document model modules from your Vetra packages.
415
572
 
416
- Adds an event handler for when the external controls enabled state changes.
573
+ ##### Usage
417
574
 
418
- ### `setIsDragAndDropEnabled`
575
+ ```jsx
576
+ import { useDocumentModelModules } from "@powerhousedao/state";
419
577
 
420
- Sets whether drag and drop is enabled for a given drive editor.
578
+ function MyEditorComponent() {
579
+ const documentModelModules = useDocumentModelModules();
580
+ }
581
+ ```
421
582
 
422
- ### `useIsDragAndDropEnabled`
583
+ #### useDocumentModelModuleById
423
584
 
424
- Gets whether drag and drop is enabled for a given drive editor.
585
+ ```ts
586
+ function useDocumentModelModuleById(): DocumentModelModule[] | undefined;
587
+ ```
425
588
 
426
- ### `addIsDragAndDropEnabledEventHandler`
589
+ Returns the document model for a given id (document type).
590
+ _NOTE_ What we call here an id is really the value in the "document type" field in the document model editor
591
+ _NOTE_ Connect assumes that these document types (ids) are unique. It is your responsibility to enforce this.
427
592
 
428
- Adds an event handler for when the drag and drop enabled state changes.
593
+ ##### Usage
429
594
 
430
- ### `setAllowedDocumentTypes`
595
+ ```jsx
596
+ import { useDocumentModelModuleById } from "@powerhousedao/state";
431
597
 
432
- Sets the allowed document types for a given drive editor.
598
+ function MyEditorComponent() {
599
+ const documentType = "my-org/my-document";
600
+ const documentModelModuleById = useDocumentModelModuleById(documentType);
601
+ }
602
+ ```
433
603
 
434
- ### `useAllowedDocumentTypes`
604
+ #### useEditorModules
435
605
 
436
- Defines the document types a drive supports.
606
+ ```ts
607
+ function useEditorModules(): EditorModule[] | undefined;
608
+ ```
437
609
 
438
- Defaults to all of the document types registered in the reactor.
610
+ Returns the editor modules from your Vetra packages.
439
611
 
440
- ### `addAllowedDocumentTypesEventHandler`
612
+ ##### Usage
441
613
 
442
- Adds an event handler for when the allowed document types for a given drive editor changes.
614
+ ```jsx
615
+ import { useEditorModules } from "@powerhousedao/state";
443
616
 
444
- ---
617
+ function MyEditorComponent() {
618
+ const editorModules = useEditorModules();
619
+ }
620
+ ```
445
621
 
446
- ## Config: Set Config by Object
622
+ #### useDriveEditorModules
447
623
 
448
- ### `setPHDriveEditorConfig`
624
+ ```ts
625
+ function useDriveEditorModules(): DriveEditorModule[] | undefined;
626
+ ```
449
627
 
450
- Sets the global drive config.
628
+ Returns the drive editor modules from your Vetra packages.
451
629
 
452
- Pass in a partial object of the global drive config to set.
630
+ ##### Usage
453
631
 
454
- ### `setPHDocumentEditorConfig`
632
+ ```jsx
633
+ import { useDriveEditorModules } from "@powerhousedao/state";
455
634
 
456
- Sets the global document config.
635
+ function MyDriveEditorComponent() {
636
+ const driveEditorModules = useDriveEditorModules();
637
+ }
638
+ ```
457
639
 
458
- Pass in a partial object of the global document config to set.
640
+ #### useProcessorModules
459
641
 
460
- ### `useSetPHDriveEditorConfig`
642
+ ```ts
643
+ function useProcessorModules(): ProcessorModule[] | undefined;
644
+ ```
461
645
 
462
- Wrapper hook for setting the global drive editor config.
646
+ Returns the processor modules from your Vetra packages.
463
647
 
464
- Automatically sets the global drive editor config when the component mounts.
648
+ ##### Usage
465
649
 
466
- Pass in a partial object of the global drive editor config to set.
650
+ ```jsx
651
+ import { useProcessorModules } from "@powerhousedao/state";
467
652
 
468
- ### `useSetPHDocumentEditorConfig`
653
+ function MyProcessorComponent() {
654
+ const processorModules = useProcessorModules();
655
+ }
656
+ ```
469
657
 
470
- Wrapper hook for setting the global document editor config.
658
+ #### useSubgraphModules
471
659
 
472
- Automatically sets the global document editor config when the component mounts.
660
+ ```ts
661
+ function useSubgraphModules(): SubgraphModule[] | undefined;
662
+ ```
473
663
 
474
- Pass in a partial object of the global document editor config to set.
664
+ Returns the subgraph modules from your Vetra packages.
475
665
 
476
- ---
666
+ ##### Usage
477
667
 
478
- ## Config: Use Value by Key
668
+ ```jsx
669
+ import { useSubgraphModules } from "@powerhousedao/state";
479
670
 
480
- ### `usePHDriveEditorConfigByKey`
671
+ function MySubgraphComponent() {
672
+ const subgraphModules = useSubgraphModules();
673
+ }
674
+ ```
481
675
 
482
- Gets the value of an item in the global drive config for a given key.
676
+ #### useImportScriptModules
483
677
 
484
- Strongly typed, inferred from type definition for the key.
678
+ ```ts
679
+ function useImportScriptModules(): ImportScriptModule[] | undefined;
680
+ ```
485
681
 
486
- ### `usePHDocumentEditorConfigByKey`
682
+ Returns the import script modules from your Vetra packages.
487
683
 
488
- Gets the value of an item in the global document config for a given key.
684
+ ##### Usage
489
685
 
490
- Strongly typed, inferred from type definition for the key.
686
+ ```jsx
687
+ import { useImportScriptModules } from "@powerhousedao/state";
491
688
 
492
- ---
689
+ function MyImportScriptComponent() {
690
+ const importScriptModules = useImportScriptModules();
691
+ }
692
+ ```