@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.
- package/README.md +482 -282
- package/dist/src/actions/dispatch.js +1 -1
- package/dist/src/actions/dispatch.js.map +1 -1
- package/dist/src/actions/document.js +12 -12
- package/dist/src/actions/document.js.map +1 -1
- package/dist/src/actions/drive.js +9 -9
- package/dist/src/actions/drive.js.map +1 -1
- package/dist/src/actions/queue.js +2 -2
- package/dist/src/actions/queue.js.map +1 -1
- package/dist/src/actions/sign.js +1 -1
- package/dist/src/actions/sign.js.map +1 -1
- package/dist/src/hooks/add-ph-event-handlers.d.ts.map +1 -1
- package/dist/src/hooks/add-ph-event-handlers.js +2 -6
- package/dist/src/hooks/add-ph-event-handlers.js.map +1 -1
- package/dist/src/hooks/connect.d.ts +1 -1
- package/dist/src/hooks/connect.d.ts.map +1 -1
- package/dist/src/hooks/connect.js +1 -1
- package/dist/src/hooks/connect.js.map +1 -1
- package/dist/src/hooks/crypto.d.ts +1 -7
- package/dist/src/hooks/crypto.d.ts.map +1 -1
- package/dist/src/hooks/crypto.js +1 -7
- package/dist/src/hooks/crypto.js.map +1 -1
- package/dist/src/hooks/index.d.ts +0 -1
- package/dist/src/hooks/index.d.ts.map +1 -1
- package/dist/src/hooks/index.js +0 -1
- package/dist/src/hooks/index.js.map +1 -1
- package/dist/src/hooks/reactor.d.ts +5 -18
- package/dist/src/hooks/reactor.d.ts.map +1 -1
- package/dist/src/hooks/reactor.js +6 -20
- package/dist/src/hooks/reactor.js.map +1 -1
- package/dist/src/hooks/renown.d.ts +2 -3
- package/dist/src/hooks/renown.d.ts.map +1 -1
- package/dist/src/hooks/renown.js.map +1 -1
- package/dist/src/hooks/user.d.ts +1 -7
- package/dist/src/hooks/user.d.ts.map +1 -1
- package/dist/src/hooks/user.js +1 -7
- package/dist/src/hooks/user.js.map +1 -1
- package/dist/src/hooks/vetra-packages.js +1 -1
- package/dist/src/hooks/vetra-packages.js.map +1 -1
- package/dist/src/reactor.d.ts +1 -1
- package/dist/src/reactor.d.ts.map +1 -1
- package/dist/src/reactor.js +5 -5
- package/dist/src/reactor.js.map +1 -1
- package/dist/src/renown/constants.d.ts +1 -1
- package/dist/src/renown/constants.d.ts.map +1 -1
- package/dist/src/renown/constants.js +1 -1
- package/dist/src/renown/constants.js.map +1 -1
- package/dist/src/renown/utils.d.ts +2 -2
- package/dist/src/renown/utils.d.ts.map +1 -1
- package/dist/src/renown/utils.js +1 -1
- package/dist/src/renown/utils.js.map +1 -1
- package/dist/src/types/global.d.ts +1 -5
- package/dist/src/types/global.d.ts.map +1 -1
- package/dist/src/utils/drives.js +2 -2
- package/dist/src/utils/drives.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +5 -7
- package/dist/src/hooks/features.d.ts +0 -5
- package/dist/src/hooks/features.d.ts.map +0 -1
- package/dist/src/hooks/features.js +0 -6
- package/dist/src/hooks/features.js.map +0 -1
package/README.md
CHANGED
|
@@ -1,492 +1,692 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Editor state management hooks
|
|
2
2
|
|
|
3
|
-
This
|
|
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
|
-
##
|
|
5
|
+
## Key concepts
|
|
6
6
|
|
|
7
|
-
|
|
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
|
-
|
|
11
|
+
### Selected drives, folders and documents
|
|
36
12
|
|
|
37
|
-
|
|
13
|
+
In the application, there are certain items that can be set as "selected".
|
|
38
14
|
|
|
39
|
-
|
|
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
|
-
|
|
21
|
+
`useSelectedDrive`
|
|
22
|
+
`useSelectedFolder`
|
|
23
|
+
`useSelectedDocument`
|
|
44
24
|
|
|
45
|
-
|
|
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
|
-
|
|
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
|
-
|
|
29
|
+
To set the selected drive, we provide a function `setSelectedDrive` which takes either a `DocumentDriveDocument` or a `DocumentDriveDocument['header']['slug']`.
|
|
68
30
|
|
|
69
|
-
|
|
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
|
-
|
|
33
|
+
## Hooks
|
|
72
34
|
|
|
73
|
-
###
|
|
35
|
+
### Reactor
|
|
74
36
|
|
|
75
|
-
|
|
37
|
+
```ts
|
|
38
|
+
function useReactor(): Reactor | undefined;
|
|
39
|
+
```
|
|
76
40
|
|
|
77
|
-
|
|
41
|
+
Returns the reactor instance.
|
|
78
42
|
|
|
79
|
-
|
|
80
|
-
This hook will suspend rendering while the document is loading.
|
|
43
|
+
##### Usage
|
|
81
44
|
|
|
82
|
-
|
|
83
|
-
|
|
45
|
+
```jsx
|
|
46
|
+
import { useReactor } from '@powerhousedao/state`
|
|
84
47
|
|
|
85
|
-
|
|
48
|
+
function MyEditorComponent() {
|
|
49
|
+
const reactor = useReactor();
|
|
50
|
+
}
|
|
51
|
+
```
|
|
86
52
|
|
|
87
|
-
###
|
|
53
|
+
### Drives
|
|
88
54
|
|
|
89
|
-
|
|
90
|
-
This hook will suspend rendering while any of the documents are loading.
|
|
55
|
+
#### useDrives
|
|
91
56
|
|
|
92
|
-
|
|
93
|
-
|
|
57
|
+
```ts
|
|
58
|
+
function useDrives(): DocumentDriveDocument[] | undefined;
|
|
59
|
+
```
|
|
94
60
|
|
|
95
|
-
|
|
61
|
+
Returns the drives for a reactor.
|
|
96
62
|
|
|
97
|
-
|
|
63
|
+
##### Usage
|
|
98
64
|
|
|
99
|
-
|
|
100
|
-
|
|
65
|
+
```jsx
|
|
66
|
+
import { useDrives } from "@powerhousedao/state";
|
|
101
67
|
|
|
102
|
-
|
|
103
|
-
|
|
68
|
+
function MyEditorComponent() {
|
|
69
|
+
const drives = useDrives();
|
|
70
|
+
}
|
|
71
|
+
```
|
|
104
72
|
|
|
105
|
-
|
|
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
|
-
|
|
81
|
+
Returns a drive by id.
|
|
115
82
|
|
|
116
|
-
|
|
83
|
+
##### Usage
|
|
117
84
|
|
|
118
|
-
|
|
85
|
+
```jsx
|
|
86
|
+
import { useDriveById } from "@powerhousedao/state";
|
|
119
87
|
|
|
120
|
-
|
|
88
|
+
function MyEditorComponent() {
|
|
89
|
+
const driveById = useDriveById();
|
|
90
|
+
}
|
|
91
|
+
```
|
|
121
92
|
|
|
122
|
-
|
|
93
|
+
#### useSelectedDrive
|
|
123
94
|
|
|
124
|
-
|
|
95
|
+
```ts
|
|
96
|
+
function useSelectedDrive(): DocumentDriveDocument | undefined;
|
|
97
|
+
```
|
|
125
98
|
|
|
126
|
-
Returns the
|
|
99
|
+
Returns the selected drive. You can se the selected drive with `setSelectedDrive`.
|
|
127
100
|
|
|
128
|
-
|
|
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
|
-
|
|
106
|
+
function MyEditorComponent() {
|
|
107
|
+
const selectedDrive = useSelectedDrive();
|
|
108
|
+
}
|
|
109
|
+
```
|
|
134
110
|
|
|
135
|
-
|
|
111
|
+
#### drive properties convenience hooks
|
|
136
112
|
|
|
137
|
-
|
|
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
|
-
|
|
115
|
+
```ts
|
|
116
|
+
/** Returns the remote URL for a drive. */
|
|
117
|
+
function useDriveRemoteUrl(
|
|
118
|
+
driveId: string | null | undefined,
|
|
119
|
+
): string | undefined;
|
|
140
120
|
|
|
141
|
-
|
|
121
|
+
/** Returns the pull responder trigger for a drive. */
|
|
122
|
+
function useDrivePullResponderTrigger(
|
|
123
|
+
driveId: string | null | undefined,
|
|
124
|
+
): Trigger | undefined;
|
|
142
125
|
|
|
143
|
-
|
|
126
|
+
/** Returns the pull responder URL for a drive. */
|
|
127
|
+
function useDrivePullResponderUrl(
|
|
128
|
+
driveId: string | null | undefined,
|
|
129
|
+
): string | undefined;
|
|
144
130
|
|
|
145
|
-
|
|
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
|
-
|
|
139
|
+
/** Returns whether a drive is available offline. */
|
|
140
|
+
function useDriveAvailableOffline(driveId: string | null | undefined): boolean;
|
|
141
|
+
```
|
|
150
142
|
|
|
151
|
-
|
|
143
|
+
##### Usage
|
|
152
144
|
|
|
153
|
-
|
|
145
|
+
```jsx
|
|
146
|
+
import {
|
|
147
|
+
useDriveRemoteUrl,
|
|
148
|
+
useDrivePullResponderTrigger,
|
|
149
|
+
useDrivePullResponderUrl,
|
|
150
|
+
useDriveIsRemote,
|
|
151
|
+
useDriveSharingType,
|
|
152
|
+
useDriveAvailableOffline,
|
|
153
|
+
} from "@powerhousedao/state";
|
|
154
154
|
|
|
155
|
-
|
|
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
|
-
|
|
164
|
+
console.log({
|
|
165
|
+
driveRemoteUrl,
|
|
166
|
+
drivePullResponderTrigger,
|
|
167
|
+
drivePullResponderUrl,
|
|
168
|
+
driveIsRemote,
|
|
169
|
+
driveSharingType,
|
|
170
|
+
driveAvailableOffline,
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
```
|
|
158
174
|
|
|
159
|
-
###
|
|
175
|
+
### Documents
|
|
160
176
|
|
|
161
|
-
|
|
177
|
+
#### useDocumentById
|
|
162
178
|
|
|
163
|
-
|
|
179
|
+
```ts
|
|
180
|
+
function useDocumentById(id: string | null | undefined): PHDocument | undefined;
|
|
181
|
+
```
|
|
164
182
|
|
|
165
|
-
Returns
|
|
183
|
+
Returns a document and a dispatch function by id.
|
|
166
184
|
|
|
167
|
-
|
|
185
|
+
##### Usage
|
|
168
186
|
|
|
169
|
-
|
|
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
|
-
|
|
196
|
+
#### useGetDocument
|
|
174
197
|
|
|
175
|
-
|
|
198
|
+
```ts
|
|
199
|
+
function useGetDocument(id: string | null | undefined): PHDocument | undefined;
|
|
200
|
+
```
|
|
176
201
|
|
|
177
|
-
|
|
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
|
-
|
|
204
|
+
##### Usage
|
|
180
205
|
|
|
181
|
-
|
|
206
|
+
```jsx
|
|
207
|
+
import { useGetDocument } from "@powerhousedao/state";
|
|
182
208
|
|
|
183
|
-
|
|
209
|
+
function MyEditorComponent() {
|
|
210
|
+
const documentId = "some-document-id";
|
|
211
|
+
const document = useGetDocument(documentId);
|
|
212
|
+
}
|
|
213
|
+
```
|
|
184
214
|
|
|
185
|
-
|
|
215
|
+
#### useGetDocuments
|
|
186
216
|
|
|
187
|
-
|
|
217
|
+
```ts
|
|
218
|
+
function useGetDocuments(
|
|
219
|
+
ids: string[] | null | undefined,
|
|
220
|
+
): PHDocument[] | undefined;
|
|
221
|
+
```
|
|
188
222
|
|
|
189
|
-
|
|
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
|
-
|
|
227
|
+
```jsx
|
|
228
|
+
import { useGetDocuments } from "@powerhousedao/state";
|
|
194
229
|
|
|
195
|
-
|
|
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
|
-
|
|
236
|
+
#### useGetDocumentAsync
|
|
198
237
|
|
|
199
|
-
|
|
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
|
-
|
|
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
|
-
|
|
250
|
+
##### Usage
|
|
204
251
|
|
|
205
|
-
|
|
252
|
+
```jsx
|
|
253
|
+
import { useGetDocumentAsync } from "@powerhousedao/state";
|
|
206
254
|
|
|
207
|
-
|
|
255
|
+
function MyEditorComponent() {
|
|
256
|
+
const documentId = "some-document-id";
|
|
257
|
+
const { status, data, isPending, error, reload } =
|
|
258
|
+
useGetDocumentAsync(documentId);
|
|
208
259
|
|
|
209
|
-
|
|
260
|
+
if (isPending) {
|
|
261
|
+
return <div>Loading...</div>;
|
|
262
|
+
}
|
|
210
263
|
|
|
211
|
-
|
|
264
|
+
if (error) {
|
|
265
|
+
return <div>Error: {error.message}</div>;
|
|
266
|
+
}
|
|
212
267
|
|
|
213
|
-
|
|
268
|
+
if (status === "success" && data) {
|
|
269
|
+
return <div>Document: {data.name}</div>;
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
```
|
|
214
273
|
|
|
215
|
-
|
|
274
|
+
#### useDocumentsInSelectedDrive
|
|
216
275
|
|
|
217
|
-
|
|
276
|
+
```ts
|
|
277
|
+
function useDocumentsInSelectedDrive(): PHDocument[] | undefined;
|
|
278
|
+
```
|
|
218
279
|
|
|
219
|
-
|
|
280
|
+
Returns the documents in the reactor for the selected drive.
|
|
220
281
|
|
|
221
|
-
|
|
282
|
+
##### Usage
|
|
222
283
|
|
|
223
|
-
|
|
284
|
+
```jsx
|
|
285
|
+
import { useDocumentsInSelectedDrive } from "@powerhousedao/state";
|
|
224
286
|
|
|
225
|
-
|
|
287
|
+
function MyEditorComponent() {
|
|
288
|
+
const selectedDriveDocuments = useDocumentsInSelectedDrive();
|
|
289
|
+
}
|
|
290
|
+
```
|
|
226
291
|
|
|
227
|
-
|
|
292
|
+
#### useSelectedDocument
|
|
228
293
|
|
|
229
|
-
|
|
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
|
-
|
|
298
|
+
Returns the selected document. You can set the selected document with `setSelectedNode`.
|
|
240
299
|
|
|
241
|
-
|
|
300
|
+
##### Usage
|
|
242
301
|
|
|
243
|
-
|
|
302
|
+
```jsx
|
|
303
|
+
import { useSelectedDocument } from "@powerhousedao/state";
|
|
244
304
|
|
|
245
|
-
|
|
305
|
+
function MyEditorComponent() {
|
|
306
|
+
const selectedDocument = useSelectedDocument();
|
|
307
|
+
}
|
|
308
|
+
```
|
|
246
309
|
|
|
247
|
-
###
|
|
310
|
+
### Nodes
|
|
248
311
|
|
|
249
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
329
|
+
type FolderNode = {
|
|
330
|
+
id: string;
|
|
331
|
+
kind: string;
|
|
332
|
+
name: string;
|
|
333
|
+
parentFolder: string | null | undefined;
|
|
334
|
+
};
|
|
260
335
|
|
|
261
|
-
|
|
336
|
+
type Node = FileNode | FolderNode;
|
|
337
|
+
```
|
|
262
338
|
|
|
263
|
-
|
|
339
|
+
#### useNodes
|
|
264
340
|
|
|
265
|
-
|
|
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
|
-
|
|
347
|
+
Returns the nodes for a drive.
|
|
270
348
|
|
|
271
|
-
|
|
349
|
+
##### Usage
|
|
272
350
|
|
|
273
|
-
|
|
351
|
+
```jsx
|
|
352
|
+
import { useNodes } from "@powerhousedao/state";
|
|
274
353
|
|
|
275
|
-
|
|
354
|
+
function MyEditorComponent() {
|
|
355
|
+
const nodes = useNodes();
|
|
356
|
+
}
|
|
357
|
+
```
|
|
276
358
|
|
|
277
|
-
|
|
359
|
+
#### useNodeById
|
|
278
360
|
|
|
279
|
-
|
|
361
|
+
```ts
|
|
362
|
+
function useNodeById(id: string | null | undefined): Node | undefined;
|
|
363
|
+
```
|
|
280
364
|
|
|
281
|
-
Returns
|
|
282
|
-
|
|
283
|
-
---
|
|
284
|
-
|
|
285
|
-
## Selected Drive
|
|
286
|
-
|
|
287
|
-
### `useSelectedDriveId`
|
|
365
|
+
Returns a node in the selected drive by id.
|
|
288
366
|
|
|
289
|
-
|
|
367
|
+
##### Usage
|
|
290
368
|
|
|
291
|
-
|
|
369
|
+
```jsx
|
|
370
|
+
import { useNodeById } from "@powerhousedao/state";
|
|
292
371
|
|
|
293
|
-
|
|
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
|
-
|
|
380
|
+
#### useSelectedFolder
|
|
296
381
|
|
|
297
|
-
|
|
382
|
+
```ts
|
|
383
|
+
function useSelectedFolder(): FolderNode | undefined;
|
|
384
|
+
```
|
|
298
385
|
|
|
299
|
-
|
|
386
|
+
Returns the selected folder. You can set the selected folder with `setSelectedNode`
|
|
300
387
|
|
|
301
|
-
|
|
388
|
+
##### Usage
|
|
302
389
|
|
|
303
|
-
|
|
390
|
+
```jsx
|
|
391
|
+
import { useSelectedFolder } from "@powerhousedao/state";
|
|
304
392
|
|
|
305
|
-
|
|
393
|
+
function MyEditorComponent() {
|
|
394
|
+
const selectedFolder = useSelectedFolder();
|
|
395
|
+
}
|
|
396
|
+
```
|
|
306
397
|
|
|
307
|
-
|
|
398
|
+
#### useSelectedNodePath
|
|
308
399
|
|
|
309
|
-
|
|
400
|
+
```ts
|
|
401
|
+
function useSelectedNodePath(): Node[];
|
|
402
|
+
```
|
|
310
403
|
|
|
311
|
-
|
|
404
|
+
Returns the path to the selected node. Useful for navigational components like breadcrumbs.
|
|
312
405
|
|
|
313
|
-
|
|
406
|
+
##### Usage
|
|
314
407
|
|
|
315
|
-
|
|
408
|
+
```jsx
|
|
409
|
+
import { useSelectedNodePath } from '@powerhousedao/state';
|
|
316
410
|
|
|
317
|
-
|
|
411
|
+
function MyEditorComponent() {
|
|
412
|
+
const nodes = useSelectedNodePath();
|
|
318
413
|
|
|
319
|
-
|
|
414
|
+
return <Breadcrumbs nodes={nodes}>
|
|
415
|
+
}
|
|
416
|
+
```
|
|
320
417
|
|
|
321
|
-
|
|
418
|
+
#### useChildNodes/useFolderChildNodes/useFileChildNodes
|
|
322
419
|
|
|
323
|
-
|
|
420
|
+
```ts
|
|
421
|
+
function useChildNodes(): Node[];
|
|
422
|
+
```
|
|
324
423
|
|
|
325
|
-
|
|
424
|
+
Returns the child nodes for the selected drive or folder.
|
|
326
425
|
|
|
327
|
-
|
|
426
|
+
```ts
|
|
427
|
+
function useFolderChildNodes(): FolderNode[];
|
|
428
|
+
```
|
|
328
429
|
|
|
329
|
-
|
|
430
|
+
Returns the folder child nodes for the selected drive or folder.
|
|
330
431
|
|
|
331
|
-
|
|
432
|
+
```ts
|
|
433
|
+
function useFileChildNodes(): FileNode[];
|
|
434
|
+
```
|
|
332
435
|
|
|
333
|
-
Returns the selected
|
|
436
|
+
Returns the file (document) child nodes for the selected drive or folder.
|
|
334
437
|
|
|
335
|
-
|
|
438
|
+
##### Usage
|
|
336
439
|
|
|
337
|
-
|
|
440
|
+
```jsx
|
|
441
|
+
import { useChildNodes, useFolderChildNodes, useFileChildNodes } from '@powerhousedao/state';
|
|
338
442
|
|
|
339
|
-
|
|
443
|
+
function MyEditorComponent() {
|
|
444
|
+
const nodes = useChildNodes();
|
|
445
|
+
const fileNodes = useChildFileNodes();
|
|
446
|
+
const folderNodes = useChildFolderNodes();
|
|
340
447
|
|
|
341
|
-
|
|
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
|
-
|
|
460
|
+
```ts
|
|
461
|
+
function useChildNodesForId(id: string | null | undefined): Node[];
|
|
462
|
+
```
|
|
346
463
|
|
|
347
|
-
|
|
464
|
+
Returns the child nodes for a drive or folder by id.
|
|
348
465
|
|
|
349
|
-
|
|
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
|
-
|
|
472
|
+
```ts
|
|
473
|
+
function useFileChildNodesForId(id: string | null | undefined): FileNode[];
|
|
474
|
+
```
|
|
354
475
|
|
|
355
|
-
|
|
476
|
+
Returns the file (document) child nodes for a drive or folder by id.
|
|
356
477
|
|
|
357
|
-
|
|
478
|
+
##### Usage
|
|
358
479
|
|
|
359
|
-
|
|
480
|
+
```jsx
|
|
481
|
+
import { useChildNodesForId, useFolderChildNodesForId, useFileChildNodesForId } from '@powerhousedao/state';
|
|
360
482
|
|
|
361
|
-
|
|
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
|
-
|
|
489
|
+
return (
|
|
490
|
+
<div>
|
|
491
|
+
<FilesAndFolders nodes={nodes}>
|
|
492
|
+
<Files fileNodes={fileNodes}>
|
|
493
|
+
<Folders folderNodes={folderNodes}>
|
|
494
|
+
</div>
|
|
495
|
+
)
|
|
496
|
+
}
|
|
497
|
+
```
|
|
364
498
|
|
|
365
|
-
|
|
499
|
+
#### useNodeName/useNodeKind
|
|
366
500
|
|
|
367
|
-
|
|
501
|
+
```ts
|
|
502
|
+
function useNodeName(id: string | null | undefined): string | undefined;
|
|
503
|
+
```
|
|
368
504
|
|
|
369
|
-
|
|
505
|
+
Returns the name of a node.
|
|
370
506
|
|
|
371
|
-
|
|
507
|
+
```ts
|
|
508
|
+
function useNodeKind(id: string | null | undefined): NodeKind | undefined;
|
|
509
|
+
```
|
|
372
510
|
|
|
373
|
-
|
|
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
|
-
|
|
378
|
-
with authentication when called.
|
|
513
|
+
##### Usage
|
|
379
514
|
|
|
380
|
-
|
|
381
|
-
|
|
515
|
+
```jsx
|
|
516
|
+
import { useNodeName, useNodeKind } from "@powerhousedao/state";
|
|
382
517
|
|
|
383
|
-
|
|
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
|
-
|
|
527
|
+
if (nodeKind === "folder") {
|
|
528
|
+
return <Folder name={nodeName} />;
|
|
529
|
+
}
|
|
530
|
+
}
|
|
531
|
+
```
|
|
388
532
|
|
|
389
|
-
###
|
|
533
|
+
### Vetra packages and modules
|
|
390
534
|
|
|
391
|
-
|
|
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
|
-
|
|
537
|
+
These modules can be for:
|
|
394
538
|
|
|
395
|
-
|
|
539
|
+
- document models
|
|
540
|
+
- editors
|
|
541
|
+
- subgraphs
|
|
542
|
+
- import scripts
|
|
543
|
+
- processors
|
|
396
544
|
|
|
397
|
-
|
|
545
|
+
Each Vetra package contains a `modules` field which optionally contains lists of these modules.
|
|
398
546
|
|
|
399
|
-
|
|
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
|
-
|
|
555
|
+
##### Usage
|
|
405
556
|
|
|
406
|
-
|
|
557
|
+
```jsx
|
|
558
|
+
import { useVetraPackages } from "@powerhousedao/state";
|
|
407
559
|
|
|
408
|
-
|
|
560
|
+
function MyEditorComponent() {
|
|
561
|
+
const vetraPackages = useVetraPackages();
|
|
562
|
+
}
|
|
563
|
+
```
|
|
409
564
|
|
|
410
|
-
|
|
565
|
+
#### useDocumentModelModules
|
|
411
566
|
|
|
412
|
-
|
|
567
|
+
```ts
|
|
568
|
+
function useDocumentModelModules(): DocumentModelModule[] | undefined;
|
|
569
|
+
```
|
|
413
570
|
|
|
414
|
-
|
|
571
|
+
Returns the document model modules from your Vetra packages.
|
|
415
572
|
|
|
416
|
-
|
|
573
|
+
##### Usage
|
|
417
574
|
|
|
418
|
-
|
|
575
|
+
```jsx
|
|
576
|
+
import { useDocumentModelModules } from "@powerhousedao/state";
|
|
419
577
|
|
|
420
|
-
|
|
578
|
+
function MyEditorComponent() {
|
|
579
|
+
const documentModelModules = useDocumentModelModules();
|
|
580
|
+
}
|
|
581
|
+
```
|
|
421
582
|
|
|
422
|
-
|
|
583
|
+
#### useDocumentModelModuleById
|
|
423
584
|
|
|
424
|
-
|
|
585
|
+
```ts
|
|
586
|
+
function useDocumentModelModuleById(): DocumentModelModule[] | undefined;
|
|
587
|
+
```
|
|
425
588
|
|
|
426
|
-
|
|
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
|
-
|
|
593
|
+
##### Usage
|
|
429
594
|
|
|
430
|
-
|
|
595
|
+
```jsx
|
|
596
|
+
import { useDocumentModelModuleById } from "@powerhousedao/state";
|
|
431
597
|
|
|
432
|
-
|
|
598
|
+
function MyEditorComponent() {
|
|
599
|
+
const documentType = "my-org/my-document";
|
|
600
|
+
const documentModelModuleById = useDocumentModelModuleById(documentType);
|
|
601
|
+
}
|
|
602
|
+
```
|
|
433
603
|
|
|
434
|
-
|
|
604
|
+
#### useEditorModules
|
|
435
605
|
|
|
436
|
-
|
|
606
|
+
```ts
|
|
607
|
+
function useEditorModules(): EditorModule[] | undefined;
|
|
608
|
+
```
|
|
437
609
|
|
|
438
|
-
|
|
610
|
+
Returns the editor modules from your Vetra packages.
|
|
439
611
|
|
|
440
|
-
|
|
612
|
+
##### Usage
|
|
441
613
|
|
|
442
|
-
|
|
614
|
+
```jsx
|
|
615
|
+
import { useEditorModules } from "@powerhousedao/state";
|
|
443
616
|
|
|
444
|
-
|
|
617
|
+
function MyEditorComponent() {
|
|
618
|
+
const editorModules = useEditorModules();
|
|
619
|
+
}
|
|
620
|
+
```
|
|
445
621
|
|
|
446
|
-
|
|
622
|
+
#### useDriveEditorModules
|
|
447
623
|
|
|
448
|
-
|
|
624
|
+
```ts
|
|
625
|
+
function useDriveEditorModules(): DriveEditorModule[] | undefined;
|
|
626
|
+
```
|
|
449
627
|
|
|
450
|
-
|
|
628
|
+
Returns the drive editor modules from your Vetra packages.
|
|
451
629
|
|
|
452
|
-
|
|
630
|
+
##### Usage
|
|
453
631
|
|
|
454
|
-
|
|
632
|
+
```jsx
|
|
633
|
+
import { useDriveEditorModules } from "@powerhousedao/state";
|
|
455
634
|
|
|
456
|
-
|
|
635
|
+
function MyDriveEditorComponent() {
|
|
636
|
+
const driveEditorModules = useDriveEditorModules();
|
|
637
|
+
}
|
|
638
|
+
```
|
|
457
639
|
|
|
458
|
-
|
|
640
|
+
#### useProcessorModules
|
|
459
641
|
|
|
460
|
-
|
|
642
|
+
```ts
|
|
643
|
+
function useProcessorModules(): ProcessorModule[] | undefined;
|
|
644
|
+
```
|
|
461
645
|
|
|
462
|
-
|
|
646
|
+
Returns the processor modules from your Vetra packages.
|
|
463
647
|
|
|
464
|
-
|
|
648
|
+
##### Usage
|
|
465
649
|
|
|
466
|
-
|
|
650
|
+
```jsx
|
|
651
|
+
import { useProcessorModules } from "@powerhousedao/state";
|
|
467
652
|
|
|
468
|
-
|
|
653
|
+
function MyProcessorComponent() {
|
|
654
|
+
const processorModules = useProcessorModules();
|
|
655
|
+
}
|
|
656
|
+
```
|
|
469
657
|
|
|
470
|
-
|
|
658
|
+
#### useSubgraphModules
|
|
471
659
|
|
|
472
|
-
|
|
660
|
+
```ts
|
|
661
|
+
function useSubgraphModules(): SubgraphModule[] | undefined;
|
|
662
|
+
```
|
|
473
663
|
|
|
474
|
-
|
|
664
|
+
Returns the subgraph modules from your Vetra packages.
|
|
475
665
|
|
|
476
|
-
|
|
666
|
+
##### Usage
|
|
477
667
|
|
|
478
|
-
|
|
668
|
+
```jsx
|
|
669
|
+
import { useSubgraphModules } from "@powerhousedao/state";
|
|
479
670
|
|
|
480
|
-
|
|
671
|
+
function MySubgraphComponent() {
|
|
672
|
+
const subgraphModules = useSubgraphModules();
|
|
673
|
+
}
|
|
674
|
+
```
|
|
481
675
|
|
|
482
|
-
|
|
676
|
+
#### useImportScriptModules
|
|
483
677
|
|
|
484
|
-
|
|
678
|
+
```ts
|
|
679
|
+
function useImportScriptModules(): ImportScriptModule[] | undefined;
|
|
680
|
+
```
|
|
485
681
|
|
|
486
|
-
|
|
682
|
+
Returns the import script modules from your Vetra packages.
|
|
487
683
|
|
|
488
|
-
|
|
684
|
+
##### Usage
|
|
489
685
|
|
|
490
|
-
|
|
686
|
+
```jsx
|
|
687
|
+
import { useImportScriptModules } from "@powerhousedao/state";
|
|
491
688
|
|
|
492
|
-
|
|
689
|
+
function MyImportScriptComponent() {
|
|
690
|
+
const importScriptModules = useImportScriptModules();
|
|
691
|
+
}
|
|
692
|
+
```
|