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