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