@powerhousedao/reactor-browser 4.1.0-dev.9 → 4.1.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 (257) hide show
  1. package/README.md +578 -0
  2. package/dist/src/actions/dispatch.d.ts +3 -0
  3. package/dist/src/actions/dispatch.d.ts.map +1 -0
  4. package/dist/src/actions/dispatch.js +13 -0
  5. package/dist/src/actions/dispatch.js.map +1 -0
  6. package/dist/src/actions/document.d.ts +14 -0
  7. package/dist/src/actions/document.d.ts.map +1 -0
  8. package/dist/src/actions/document.js +260 -0
  9. package/dist/src/actions/document.js.map +1 -0
  10. package/dist/src/actions/drive.d.ts +14 -0
  11. package/dist/src/actions/drive.d.ts.map +1 -0
  12. package/dist/src/actions/drive.js +192 -0
  13. package/dist/src/actions/drive.js.map +1 -0
  14. package/dist/src/actions/index.d.ts +6 -0
  15. package/dist/src/actions/index.d.ts.map +1 -0
  16. package/dist/src/actions/index.js +6 -0
  17. package/dist/src/actions/index.js.map +1 -0
  18. package/dist/src/actions/queue.d.ts +9 -0
  19. package/dist/src/actions/queue.d.ts.map +1 -0
  20. package/dist/src/actions/queue.js +144 -0
  21. package/dist/src/actions/queue.js.map +1 -0
  22. package/dist/src/actions/sign.d.ts +5 -0
  23. package/dist/src/actions/sign.d.ts.map +1 -0
  24. package/dist/src/actions/sign.js +71 -0
  25. package/dist/src/actions/sign.js.map +1 -0
  26. package/dist/src/analytics/index.d.ts +2 -0
  27. package/dist/src/analytics/index.d.ts.map +1 -0
  28. package/dist/src/analytics/index.js +2 -0
  29. package/dist/src/analytics/index.js.map +1 -0
  30. package/dist/src/constants.d.ts +3 -0
  31. package/dist/src/constants.d.ts.map +1 -0
  32. package/dist/src/constants.js +3 -0
  33. package/dist/src/constants.js.map +1 -0
  34. package/dist/src/context/read-mode.d.ts.map +1 -1
  35. package/dist/src/context/read-mode.js +3 -7
  36. package/dist/src/context/read-mode.js.map +1 -1
  37. package/dist/src/crypto/index.d.ts +12 -5
  38. package/dist/src/crypto/index.d.ts.map +1 -1
  39. package/dist/src/crypto/index.js +61 -60
  40. package/dist/src/crypto/index.js.map +1 -1
  41. package/dist/src/events/add-ph-event-handlers.d.ts +2 -0
  42. package/dist/src/events/add-ph-event-handlers.d.ts.map +1 -0
  43. package/dist/src/events/add-ph-event-handlers.js +26 -0
  44. package/dist/src/events/add-ph-event-handlers.js.map +1 -0
  45. package/dist/src/events/config.d.ts +8 -0
  46. package/dist/src/events/config.d.ts.map +1 -0
  47. package/dist/src/events/config.js +25 -0
  48. package/dist/src/events/config.js.map +1 -0
  49. package/dist/src/events/crypto.d.ts +13 -0
  50. package/dist/src/events/crypto.d.ts.map +1 -0
  51. package/dist/src/events/crypto.js +49 -0
  52. package/dist/src/events/crypto.js.map +1 -0
  53. package/dist/src/events/documents.d.ts +7 -0
  54. package/dist/src/events/documents.d.ts.map +1 -0
  55. package/dist/src/events/documents.js +19 -0
  56. package/dist/src/events/documents.js.map +1 -0
  57. package/dist/src/events/drives.d.ts +13 -0
  58. package/dist/src/events/drives.d.ts.map +1 -0
  59. package/dist/src/events/drives.js +57 -0
  60. package/dist/src/events/drives.js.map +1 -0
  61. package/dist/src/events/index.d.ts +13 -0
  62. package/dist/src/events/index.d.ts.map +1 -0
  63. package/dist/src/events/index.js +13 -0
  64. package/dist/src/events/index.js.map +1 -0
  65. package/dist/src/events/nodes.d.ts +7 -0
  66. package/dist/src/events/nodes.d.ts.map +1 -0
  67. package/dist/src/events/nodes.js +34 -0
  68. package/dist/src/events/nodes.js.map +1 -0
  69. package/dist/src/events/processors.d.ts +8 -0
  70. package/dist/src/events/processors.d.ts.map +1 -0
  71. package/dist/src/events/processors.js +25 -0
  72. package/dist/src/events/processors.js.map +1 -0
  73. package/dist/src/events/reactor.d.ts +8 -0
  74. package/dist/src/events/reactor.d.ts.map +1 -0
  75. package/dist/src/events/reactor.js +25 -0
  76. package/dist/src/events/reactor.js.map +1 -0
  77. package/dist/src/events/renown.d.ts +8 -0
  78. package/dist/src/events/renown.d.ts.map +1 -0
  79. package/dist/src/events/renown.js +27 -0
  80. package/dist/src/events/renown.js.map +1 -0
  81. package/dist/src/events/types.d.ts +60 -0
  82. package/dist/src/events/types.d.ts.map +1 -0
  83. package/dist/src/{renown → events}/types.js.map +1 -1
  84. package/dist/src/events/user.d.ts +14 -0
  85. package/dist/src/events/user.d.ts.map +1 -0
  86. package/dist/src/events/user.js +50 -0
  87. package/dist/src/events/user.js.map +1 -0
  88. package/dist/src/events/vetra-packages.d.ts +8 -0
  89. package/dist/src/events/vetra-packages.d.ts.map +1 -0
  90. package/dist/src/events/vetra-packages.js +29 -0
  91. package/dist/src/events/vetra-packages.js.map +1 -0
  92. package/dist/src/hooks/config.d.ts +5 -0
  93. package/dist/src/hooks/config.d.ts.map +1 -0
  94. package/dist/src/hooks/config.js +18 -0
  95. package/dist/src/hooks/config.js.map +1 -0
  96. package/dist/src/hooks/crypto.d.ts +4 -0
  97. package/dist/src/hooks/crypto.d.ts.map +1 -0
  98. package/dist/src/hooks/crypto.js +15 -0
  99. package/dist/src/hooks/crypto.js.map +1 -0
  100. package/dist/src/hooks/dispatch.d.ts +3 -0
  101. package/dist/src/hooks/dispatch.d.ts.map +1 -0
  102. package/dist/src/hooks/dispatch.js +9 -0
  103. package/dist/src/hooks/dispatch.js.map +1 -0
  104. package/dist/src/hooks/documents.d.ts +12 -0
  105. package/dist/src/hooks/documents.d.ts.map +1 -0
  106. package/dist/src/hooks/documents.js +46 -0
  107. package/dist/src/hooks/documents.js.map +1 -0
  108. package/dist/src/hooks/{useDriveContext.d.ts → drive-context.d.ts} +1 -1
  109. package/dist/src/hooks/drive-context.d.ts.map +1 -0
  110. package/dist/src/hooks/{useDriveContext.js → drive-context.js} +1 -1
  111. package/dist/src/hooks/drive-context.js.map +1 -0
  112. package/dist/src/hooks/drives.d.ts +23 -0
  113. package/dist/src/hooks/drives.d.ts.map +1 -0
  114. package/dist/src/hooks/drives.js +88 -0
  115. package/dist/src/hooks/drives.js.map +1 -0
  116. package/dist/src/hooks/index.d.ts +11 -7
  117. package/dist/src/hooks/index.d.ts.map +1 -1
  118. package/dist/src/hooks/index.js +11 -7
  119. package/dist/src/hooks/index.js.map +1 -1
  120. package/dist/src/hooks/nodes.d.ts +41 -0
  121. package/dist/src/hooks/nodes.d.ts.map +1 -0
  122. package/dist/src/hooks/nodes.js +160 -0
  123. package/dist/src/hooks/nodes.js.map +1 -0
  124. package/dist/src/hooks/processor-manager.d.ts +3 -0
  125. package/dist/src/hooks/processor-manager.d.ts.map +1 -0
  126. package/dist/src/hooks/processor-manager.js +7 -0
  127. package/dist/src/hooks/processor-manager.js.map +1 -0
  128. package/dist/src/hooks/reactor.d.ts +3 -0
  129. package/dist/src/hooks/reactor.d.ts.map +1 -0
  130. package/dist/src/hooks/reactor.js +7 -0
  131. package/dist/src/hooks/reactor.js.map +1 -0
  132. package/dist/src/hooks/renown.d.ts +2 -0
  133. package/dist/src/hooks/renown.d.ts.map +1 -0
  134. package/dist/src/hooks/renown.js +7 -0
  135. package/dist/src/hooks/renown.js.map +1 -0
  136. package/dist/src/hooks/user.d.ts +7 -0
  137. package/dist/src/hooks/user.d.ts.map +1 -0
  138. package/dist/src/hooks/user.js +26 -0
  139. package/dist/src/hooks/user.js.map +1 -0
  140. package/dist/src/hooks/vetra-packages.d.ts +17 -0
  141. package/dist/src/hooks/vetra-packages.d.ts.map +1 -0
  142. package/dist/src/hooks/vetra-packages.js +82 -0
  143. package/dist/src/hooks/vetra-packages.js.map +1 -0
  144. package/dist/src/index.d.ts +6 -4
  145. package/dist/src/index.d.ts.map +1 -1
  146. package/dist/src/index.js +6 -2
  147. package/dist/src/index.js.map +1 -1
  148. package/dist/src/reactor.d.ts +7 -0
  149. package/dist/src/reactor.d.ts.map +1 -1
  150. package/dist/src/reactor.js +63 -0
  151. package/dist/src/reactor.js.map +1 -1
  152. package/dist/src/renown/index.d.ts +3 -0
  153. package/dist/src/renown/index.d.ts.map +1 -0
  154. package/dist/src/renown/index.js +3 -0
  155. package/dist/src/renown/index.js.map +1 -0
  156. package/dist/src/renown/utils.d.ts +7 -0
  157. package/dist/src/renown/utils.d.ts.map +1 -0
  158. package/dist/src/renown/utils.js +47 -0
  159. package/dist/src/renown/utils.js.map +1 -0
  160. package/dist/src/types/drive-editor.d.ts +9 -81
  161. package/dist/src/types/drive-editor.d.ts.map +1 -1
  162. package/dist/src/types/global.d.ts +64 -0
  163. package/dist/src/types/global.d.ts.map +1 -0
  164. package/dist/src/types/global.js +2 -0
  165. package/dist/src/types/global.js.map +1 -0
  166. package/dist/src/types/index.d.ts +3 -0
  167. package/dist/src/types/index.d.ts.map +1 -1
  168. package/dist/src/types/index.js +3 -0
  169. package/dist/src/types/index.js.map +1 -1
  170. package/dist/src/types/reactor.d.ts +4 -0
  171. package/dist/src/types/reactor.d.ts.map +1 -0
  172. package/dist/src/types/reactor.js +2 -0
  173. package/dist/src/types/reactor.js.map +1 -0
  174. package/dist/src/types/vetra.d.ts +65 -0
  175. package/dist/src/types/vetra.d.ts.map +1 -0
  176. package/dist/src/types/vetra.js +2 -0
  177. package/dist/src/types/vetra.js.map +1 -0
  178. package/dist/src/utils/drives.d.ts +32 -0
  179. package/dist/src/utils/drives.d.ts.map +1 -0
  180. package/dist/src/utils/drives.js +60 -0
  181. package/dist/src/utils/drives.js.map +1 -0
  182. package/dist/src/utils/index.d.ts +6 -4
  183. package/dist/src/utils/index.d.ts.map +1 -1
  184. package/dist/src/utils/index.js +6 -8
  185. package/dist/src/utils/index.js.map +1 -1
  186. package/dist/src/utils/nodes.d.ts +8 -0
  187. package/dist/src/utils/nodes.d.ts.map +1 -0
  188. package/dist/src/utils/nodes.js +17 -0
  189. package/dist/src/utils/nodes.js.map +1 -0
  190. package/dist/src/utils/url.d.ts +22 -0
  191. package/dist/src/utils/url.d.ts.map +1 -0
  192. package/dist/src/utils/url.js +59 -0
  193. package/dist/src/utils/url.js.map +1 -0
  194. package/dist/src/utils/user.d.ts +5 -0
  195. package/dist/src/utils/user.d.ts.map +1 -0
  196. package/dist/src/utils/user.js +15 -0
  197. package/dist/src/utils/user.js.map +1 -0
  198. package/dist/src/utils/vetra.d.ts +7 -0
  199. package/dist/src/utils/vetra.d.ts.map +1 -0
  200. package/dist/src/utils/vetra.js +78 -0
  201. package/dist/src/utils/vetra.js.map +1 -0
  202. package/dist/tsconfig.lib.tsbuildinfo +1 -1
  203. package/dist/vitest.config.d.ts +3 -0
  204. package/dist/vitest.config.d.ts.map +1 -0
  205. package/dist/vitest.config.js +24 -0
  206. package/dist/vitest.config.js.map +1 -0
  207. package/package.json +11 -5
  208. package/dist/package.json +0 -75
  209. package/dist/src/hooks/document-state.d.ts +0 -24
  210. package/dist/src/hooks/document-state.d.ts.map +0 -1
  211. package/dist/src/hooks/document-state.js +0 -89
  212. package/dist/src/hooks/document-state.js.map +0 -1
  213. package/dist/src/hooks/useAddDebouncedOperations.d.ts +0 -7
  214. package/dist/src/hooks/useAddDebouncedOperations.d.ts.map +0 -1
  215. package/dist/src/hooks/useAddDebouncedOperations.js +0 -53
  216. package/dist/src/hooks/useAddDebouncedOperations.js.map +0 -1
  217. package/dist/src/hooks/useConnectCrypto.d.ts +0 -4
  218. package/dist/src/hooks/useConnectCrypto.d.ts.map +0 -1
  219. package/dist/src/hooks/useConnectCrypto.js +0 -57
  220. package/dist/src/hooks/useConnectCrypto.js.map +0 -1
  221. package/dist/src/hooks/useDocument.d.ts +0 -8
  222. package/dist/src/hooks/useDocument.d.ts.map +0 -1
  223. package/dist/src/hooks/useDocument.js +0 -32
  224. package/dist/src/hooks/useDocument.js.map +0 -1
  225. package/dist/src/hooks/useDocumentDispatch.d.ts +0 -10
  226. package/dist/src/hooks/useDocumentDispatch.d.ts.map +0 -1
  227. package/dist/src/hooks/useDocumentDispatch.js +0 -42
  228. package/dist/src/hooks/useDocumentDispatch.js.map +0 -1
  229. package/dist/src/hooks/useDocumentDrives.d.ts +0 -12
  230. package/dist/src/hooks/useDocumentDrives.d.ts.map +0 -1
  231. package/dist/src/hooks/useDocumentDrives.js +0 -122
  232. package/dist/src/hooks/useDocumentDrives.js.map +0 -1
  233. package/dist/src/hooks/useDocumentEditor.d.ts +0 -32
  234. package/dist/src/hooks/useDocumentEditor.d.ts.map +0 -1
  235. package/dist/src/hooks/useDocumentEditor.js +0 -41
  236. package/dist/src/hooks/useDocumentEditor.js.map +0 -1
  237. package/dist/src/hooks/useDriveActions.d.ts +0 -79
  238. package/dist/src/hooks/useDriveActions.d.ts.map +0 -1
  239. package/dist/src/hooks/useDriveActions.js +0 -108
  240. package/dist/src/hooks/useDriveActions.js.map +0 -1
  241. package/dist/src/hooks/useDriveContext.d.ts.map +0 -1
  242. package/dist/src/hooks/useDriveContext.js.map +0 -1
  243. package/dist/src/hooks/useUserPermissions.d.ts +0 -6
  244. package/dist/src/hooks/useUserPermissions.d.ts.map +0 -1
  245. package/dist/src/hooks/useUserPermissions.js +0 -7
  246. package/dist/src/hooks/useUserPermissions.js.map +0 -1
  247. package/dist/src/renown/types.d.ts +0 -76
  248. package/dist/src/renown/types.d.ts.map +0 -1
  249. package/dist/src/utils/export-document.d.ts +0 -3
  250. package/dist/src/utils/export-document.d.ts.map +0 -1
  251. package/dist/src/utils/export-document.js +0 -19
  252. package/dist/src/utils/export-document.js.map +0 -1
  253. package/dist/src/utils/signature.d.ts +0 -5
  254. package/dist/src/utils/signature.d.ts.map +0 -1
  255. package/dist/src/utils/signature.js +0 -40
  256. package/dist/src/utils/signature.js.map +0 -1
  257. /package/dist/src/{renown → events}/types.js +0 -0
package/README.md ADDED
@@ -0,0 +1,578 @@
1
+ # Editor state management hooks
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.
4
+
5
+ ## Key concepts
6
+
7
+ ### Reactor
8
+
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.
10
+
11
+
12
+ ### Selected drives, folders and documents
13
+ In the application, there are certain items that can be set as "selected".
14
+
15
+ - selected drive
16
+ - selected folder
17
+ - selected document
18
+
19
+ We provide hooks for getting the selected item for each:
20
+
21
+ `useSelectedDrive`
22
+ `useSelectedFolder`
23
+ `useSelectedDocument`
24
+
25
+ Folders and documents are part of a given drive, so they will both be undefined if the selected drive is undefined.
26
+
27
+ _Either_ a folder or a document can be selected but not both, so if one is defined then the other will be undefined.
28
+
29
+ To set the selected drive, we provide a function `setSelectedDrive` which takes either a `DocumentDriveDocument` or a `DocumentDriveDocument['header']['slug']`.
30
+
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.
32
+
33
+ ## Hooks
34
+
35
+
36
+ ### Reactor
37
+ ```ts
38
+ function useReactor(): Reactor | undefined
39
+ ```
40
+
41
+ Returns the reactor instance.
42
+
43
+ ##### Usage
44
+ ```jsx
45
+ import { useReactor } from '@powerhousedao/state`
46
+
47
+ function MyEditorComponent() {
48
+ const reactor = useReactor();
49
+ }
50
+ ```
51
+
52
+ ### Drives
53
+
54
+ #### useDrives
55
+ ```ts
56
+ function useDrives(): DocumentDriveDocument[] | undefined
57
+ ```
58
+ Returns the drives for a reactor.
59
+
60
+ ##### Usage
61
+
62
+ ```jsx
63
+ import { useDrives } from '@powerhousedao/state';
64
+
65
+ function MyEditorComponent() {
66
+ const drives = useDrives();
67
+ }
68
+ ```
69
+
70
+ #### useDriveById
71
+ ```ts
72
+ function useDriveById(id: string | null | undefined): DocumentDriveDocument | undefined
73
+ ```
74
+
75
+ Returns a drive by id.
76
+
77
+ ##### Usage
78
+
79
+ ```jsx
80
+ import { useDriveById } from '@powerhousedao/state';
81
+
82
+ function MyEditorComponent() {
83
+ const driveById = useDriveById();
84
+ }
85
+ ```
86
+
87
+ #### useSelectedDrive
88
+ ```ts
89
+ function useSelectedDrive(): DocumentDriveDocument | undefined
90
+ ```
91
+
92
+ Returns the selected drive. You can se the selected drive with `setSelectedDrive`.
93
+
94
+ ##### Usage
95
+
96
+ ```jsx
97
+ import { useSelectedDrive } from '@powerhousedao/state';
98
+
99
+ function MyEditorComponent() {
100
+ const selectedDrive = useSelectedDrive();
101
+ }
102
+ ```
103
+
104
+ #### drive properties convenience hooks
105
+ 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.
106
+
107
+ ```ts
108
+ /** Returns the remote URL for a drive. */
109
+ function useDriveRemoteUrl(driveId: string | null | undefined): string | undefined
110
+
111
+ /** Returns the pull responder trigger for a drive. */
112
+ function useDrivePullResponderTrigger(
113
+ driveId: string | null | undefined,
114
+ ): Trigger | undefined
115
+
116
+ /** Returns the pull responder URL for a drive. */
117
+ function useDrivePullResponderUrl(driveId: string | null | undefined): string | undefined
118
+
119
+ /** Returns whether a drive is remote. */
120
+ function useDriveIsRemote(driveId: string | null | undefined): boolean
121
+
122
+ /** Returns the sharing type for a drive. */
123
+ function useDriveSharingType(driveId: string | null | undefined): SharingType | undefined
124
+
125
+ /** Returns whether a drive is available offline. */
126
+ function useDriveAvailableOffline(driveId: string | null | undefined): boolean
127
+ ```
128
+
129
+ ##### Usage
130
+
131
+ ```jsx
132
+ import {
133
+ useDriveRemoteUrl,
134
+ useDrivePullResponderTrigger,
135
+ useDrivePullResponderUrl,
136
+ useDriveIsRemote,
137
+ useDriveSharingType,
138
+ useDriveAvailableOffline,
139
+ } from '@powerhousedao/state';
140
+
141
+ function MyEditorComponent() {
142
+ const myDriveId = "some-drive-id";
143
+ const driveRemoteUrl = useDriveRemoteUrl(myDriveId);
144
+ const drivePullResponderTrigger = useDrivePullResponderTrigger(myDriveId);
145
+ const drivePullResponderUrl = useDrivePullResponderUrl(myDriveId);
146
+ const driveIsRemote = useDriveIsRemote(myDriveId);
147
+ const driveSharingType = useDriveSharingType(myDriveId);
148
+ const driveAvailableOffline = useDriveAvailableOffline(myDriveId);
149
+
150
+ console.log({
151
+ driveRemoteUrl,
152
+ drivePullResponderTrigger,
153
+ drivePullResponderUrl,
154
+ driveIsRemote,
155
+ driveSharingType,
156
+ driveAvailableOffline,
157
+ })
158
+ }
159
+ ```
160
+
161
+ ### Documents
162
+
163
+ #### useAllDocuments/useSelectedDriveDocuments
164
+ ```ts
165
+ function useAllDocuments(): PHDocument[] | undefined
166
+ ```
167
+ Returns all of the documents in the reactor.
168
+
169
+ ```ts
170
+ function useSelectedDriveDocuments(): PHDocument[] | undefined
171
+ ```
172
+ Returns the documents in the reactor for the selected drive.
173
+
174
+ ##### Usage
175
+
176
+ ```jsx
177
+ import { useAllDocuments, useSelectedDriveDocuments } from '@powerhousedao/state';
178
+
179
+ function MyEditorComponent() {
180
+ const allDocuments = useAllDocuments();
181
+ const selectedDriveDocuments = useSelectedDriveDocuments();
182
+ }
183
+ ```
184
+
185
+ #### useSelectedDocument
186
+ ```ts
187
+ function useSelectedDocument(): PHDocument | undefined
188
+ ```
189
+ Returns the selected document. You can set the selected document with `setSelectedNode`.
190
+
191
+ ##### Usage
192
+
193
+ ```jsx
194
+ import { useSelectedDocument } from '@powerhousedao/state';
195
+
196
+ function MyEditorComponent() {
197
+ const selectedDocument = useSelectedDocument();
198
+ }
199
+ ```
200
+
201
+ #### useDocumentById
202
+ ```ts
203
+ function useDocumentById(id: string | null | undefined): PHDocument | undefined
204
+ ```
205
+ Returns a document by id.
206
+
207
+ ##### Usage
208
+
209
+ ```jsx
210
+ import { useDocumentById } from '@powerhousedao/state';
211
+
212
+ function MyEditorComponent() {
213
+ const myDocumentId = 'some-document-id';
214
+ const documentById = useDocumentById(myDocumentId);
215
+ }
216
+ ```
217
+
218
+ ### Nodes
219
+ "Nodes" refers to the items found in a given drive's `state.global.nodes` array. Nodes can represent both files (documents) and folders.
220
+
221
+ A document in a drive will have a node in the drive's node list which has the same id as the document.
222
+
223
+ 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.
224
+
225
+ 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.
226
+
227
+ ```ts
228
+ type FileNode = {
229
+ documentType: string;
230
+ id: string;
231
+ kind: string;
232
+ name: string;
233
+ parentFolder: string | null | undefined;
234
+ }
235
+
236
+ type FolderNode = {
237
+ id: string;
238
+ kind: string;
239
+ name: string;
240
+ parentFolder: string | null | undefined;
241
+ }
242
+
243
+ type Node = FileNode | FolderNode;
244
+ ```
245
+
246
+ #### useNodes
247
+ 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.
248
+
249
+ ```ts
250
+ function useNodes(): Node[] | undefined
251
+ ```
252
+ Returns the nodes for a drive.
253
+
254
+ ##### Usage
255
+
256
+ ```jsx
257
+ import { useNodes} from '@powerhousedao/state';
258
+
259
+ function MyEditorComponent() {
260
+ const nodes = useNodes();
261
+ }
262
+ ```
263
+
264
+ #### useNodeById
265
+ ```ts
266
+ function useNodeById(id: string | null | undefined): Node | undefined
267
+ ```
268
+ Returns a node in the selected drive by id.
269
+
270
+ ##### Usage
271
+
272
+ ```jsx
273
+ import { useNodeById } from '@powerhousedao/state';
274
+
275
+ function MyEditorComponent() {
276
+ const myFolderId = 'some-folder-id';
277
+ const myDocumentId = 'some-document-id';
278
+ const myFolderNode = useNodeById(myFolderId);
279
+ const myFileNode = useNodeById(myDocumentId);
280
+ }
281
+ ```
282
+
283
+ #### useSelectedFolder
284
+ ```ts
285
+ function useSelectedFolder(): FolderNode | undefined
286
+ ```
287
+ Returns the selected folder. You can set the selected folder with `setSelectedNode`
288
+
289
+ ##### Usage
290
+
291
+ ```jsx
292
+ import { useSelectedFolder } from '@powerhousedao/state';
293
+
294
+ function MyEditorComponent() {
295
+ const selectedFolder = useSelectedFolder();
296
+ }
297
+ ```
298
+
299
+ #### useSelectedNodePath
300
+ ```ts
301
+ function useSelectedNodePath(): Node[]
302
+ ```
303
+ Returns the path to the selected node. Useful for navigational components like breadcrumbs.
304
+
305
+ ##### Usage
306
+
307
+ ```jsx
308
+ import { useSelectedNodePath } from '@powerhousedao/state';
309
+
310
+ function MyEditorComponent() {
311
+ const nodes = useSelectedNodePath();
312
+
313
+ return <Breadcrumbs nodes={nodes}>
314
+ }
315
+ ```
316
+
317
+ #### useChildNodes/useFolderChildNodes/useFileChildNodes
318
+
319
+ ```ts
320
+ function useChildNodes(): Node[]
321
+ ```
322
+ Returns the child nodes for the selected drive or folder.
323
+
324
+ ```ts
325
+ function useFolderChildNodes(): FolderNode[]
326
+ ```
327
+ Returns the folder child nodes for the selected drive or folder.
328
+
329
+ ```ts
330
+ function useFileChildNodes(): FileNode[]
331
+ ```
332
+ Returns the file (document) child nodes for the selected drive or folder.
333
+
334
+ ##### Usage
335
+
336
+ ```jsx
337
+ import { useChildNodes, useFolderChildNodes, useFileChildNodes } from '@powerhousedao/state';
338
+
339
+ function MyEditorComponent() {
340
+ const nodes = useChildNodes();
341
+ const fileNodes = useChildFileNodes();
342
+ const folderNodes = useChildFolderNodes();
343
+
344
+ return (
345
+ <div>
346
+ <FilesAndFolders nodes={nodes}>
347
+ <Files fileNodes={fileNodes}>
348
+ <Folders folderNodes={folderNodes}>
349
+ </div>
350
+ )
351
+ }
352
+ ```
353
+
354
+ #### useChildNodesForId/useFolderChildNodesForId/useFileChildNodesForId
355
+ ```ts
356
+ function useChildNodesForId(id: string | null | undefined): Node[]
357
+ ```
358
+ Returns the child nodes for a drive or folder by id.
359
+ ```ts
360
+ function useFolderChildNodesForId(id: string | null | undefined): FolderNode[]
361
+ ```
362
+ Returns the folder child nodes for a drive or folder by id.
363
+ ```ts
364
+ function useFileChildNodesForId(id: string | null | undefined): FileNode[]
365
+ ```
366
+ Returns the file (document) child nodes for a drive or folder by id.
367
+
368
+ ##### Usage
369
+
370
+ ```jsx
371
+ import { useChildNodesForId, useFolderChildNodesForId, useFileChildNodesForId } from '@powerhousedao/state';
372
+
373
+ function MyEditorComponent() {
374
+ const driveOrFolderId = 'some-drive-or-folder-id';
375
+ const nodes = useChildNodesForId(driveOrFolderId);
376
+ const fileNodes = useFileChildNodesForId(driveOrFolderId);
377
+ const folderNodes = useFolderChildNodesForId(driveOrFolderId);
378
+
379
+ return (
380
+ <div>
381
+ <FilesAndFolders nodes={nodes}>
382
+ <Files fileNodes={fileNodes}>
383
+ <Folders folderNodes={folderNodes}>
384
+ </div>
385
+ )
386
+ }
387
+ ```
388
+
389
+ #### useNodeName/useNodeKind
390
+ ```ts
391
+ function useNodeName(id: string | null | undefined): string | undefined
392
+ ```
393
+ Returns the name of a node.
394
+ ```ts
395
+ function useNodeKind(id: string | null | undefined): NodeKind | undefined
396
+ ```
397
+ Returns the kind of a node.
398
+
399
+ ##### Usage
400
+
401
+ ```jsx
402
+ import { useNodeName, useNodeKind } from '@powerhousedao/state';
403
+
404
+ function MyEditorComponent() {
405
+ const nodeId = 'some-node-id';
406
+ const nodeName = useNodeName(nodeId);
407
+ const nodeKind = useNodeKind(nodeId);
408
+
409
+ if (nodeKind === 'file') {
410
+ return <File name={nodeName} />;
411
+ }
412
+
413
+ if (nodeKind === 'folder') {
414
+ return <Folder name={nodeName} />;
415
+ }
416
+ }
417
+ ```
418
+
419
+ ### Vetra packages and modules
420
+
421
+ 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.
422
+
423
+ These modules can be for:
424
+
425
+ - document models
426
+ - editors
427
+ - subgraphs
428
+ - import scripts
429
+ - processors
430
+
431
+ Each Vetra package contains a `modules` field which optionally contains lists of these modules.
432
+
433
+ #### useVetraPackages
434
+
435
+ ```ts
436
+ function useVetraPackages(): VetraPackage[] | undefined
437
+ ```
438
+
439
+ Returns all of the Vetra packages in your Connect app.
440
+
441
+ ##### Usage
442
+
443
+ ```jsx
444
+ import { useVetraPackages } from '@powerhousedao/state'
445
+
446
+ function MyEditorComponent() {
447
+ const vetraPackages = useVetraPackages()
448
+ }
449
+ ```
450
+
451
+ #### useDocumentModelModules
452
+
453
+ ```ts
454
+ function useDocumentModelModules(): DocumentModelModule[] | undefined
455
+ ```
456
+
457
+ Returns the document model modules from your Vetra packages.
458
+
459
+ ##### Usage
460
+
461
+ ```jsx
462
+ import { useDocumentModelModules } from '@powerhousedao/state'
463
+
464
+ function MyEditorComponent() {
465
+ const documentModelModules = useDocumentModelModules()
466
+ }
467
+ ```
468
+
469
+ #### useDocumentModelModuleById
470
+
471
+ ```ts
472
+ function useDocumentModelModuleById(): DocumentModelModule[] | undefined
473
+ ```
474
+
475
+ Returns the document model for a given id (document type).
476
+ *NOTE* What we call here an id is really the value in the "document type" field in the document model editor
477
+ *NOTE* Connect assumes that these document types (ids) are unique. It is your responsibility to enforce this.
478
+
479
+ ##### Usage
480
+
481
+ ```jsx
482
+ import { useDocumentModelModuleById } from '@powerhousedao/state'
483
+
484
+ function MyEditorComponent() {
485
+ const documentType = 'my-org/my-document';
486
+ const documentModelModuleById = useDocumentModelModuleById(documentType)
487
+ }
488
+ ```
489
+
490
+ #### useEditorModules
491
+
492
+ ```ts
493
+ function useEditorModules(): EditorModule[] | undefined
494
+ ```
495
+
496
+ Returns the editor modules from your Vetra packages.
497
+
498
+ ##### Usage
499
+
500
+ ```jsx
501
+ import { useEditorModules } from '@powerhousedao/state'
502
+
503
+ function MyEditorComponent() {
504
+ const editorModules = useEditorModules()
505
+ }
506
+ ```
507
+
508
+ #### useDriveEditorModules
509
+
510
+ ```ts
511
+ function useDriveEditorModules(): DriveEditorModule[] | undefined
512
+ ```
513
+
514
+ Returns the drive editor modules from your Vetra packages.
515
+
516
+ ##### Usage
517
+
518
+ ```jsx
519
+ import { useDriveEditorModules } from '@powerhousedao/state'
520
+
521
+ function MyDriveEditorComponent() {
522
+ const driveEditorModules = useDriveEditorModules()
523
+ }
524
+ ```
525
+
526
+ #### useProcessorModules
527
+
528
+ ```ts
529
+ function useProcessorModules(): ProcessorModule[] | undefined
530
+ ```
531
+
532
+ Returns the processor modules from your Vetra packages.
533
+
534
+ ##### Usage
535
+
536
+ ```jsx
537
+ import { useProcessorModules } from '@powerhousedao/state'
538
+
539
+ function MyProcessorComponent() {
540
+ const processorModules = useProcessorModules()
541
+ }
542
+ ```
543
+
544
+ #### useSubgraphModules
545
+
546
+ ```ts
547
+ function useSubgraphModules(): SubgraphModule[] | undefined
548
+ ```
549
+
550
+ Returns the subgraph modules from your Vetra packages.
551
+
552
+ ##### Usage
553
+
554
+ ```jsx
555
+ import { useSubgraphModules } from '@powerhousedao/state'
556
+
557
+ function MySubgraphComponent() {
558
+ const subgraphModules = useSubgraphModules()
559
+ }
560
+ ```
561
+
562
+ #### useImportScriptModules
563
+
564
+ ```ts
565
+ function useImportScriptModules(): ImportScriptModule[] | undefined
566
+ ```
567
+
568
+ Returns the import script modules from your Vetra packages.
569
+
570
+ ##### Usage
571
+
572
+ ```jsx
573
+ import { useImportScriptModules } from '@powerhousedao/state'
574
+
575
+ function MyImportScriptComponent() {
576
+ const importScriptModules = useImportScriptModules()
577
+ }
578
+ ```
@@ -0,0 +1,3 @@
1
+ import { type Action, type PHDocument } from "document-model";
2
+ export declare function dispatchActions(actionOrActions: Action[] | Action | undefined, document: PHDocument | undefined): Promise<PHDocument | undefined>;
3
+ //# sourceMappingURL=dispatch.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dispatch.d.ts","sourceRoot":"","sources":["../../../src/actions/dispatch.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,MAAM,EAAE,KAAK,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAI9D,wBAAsB,eAAe,CACnC,eAAe,EAAE,MAAM,EAAE,GAAG,MAAM,GAAG,SAAS,EAC9C,QAAQ,EAAE,UAAU,GAAG,SAAS,mCAYjC"}
@@ -0,0 +1,13 @@
1
+ import { logger } from "document-drive";
2
+ import { queueActions } from "./queue.js";
3
+ import { makeSignedActionsWithContext } from "./sign.js";
4
+ export async function dispatchActions(actionOrActions, document) {
5
+ const signedActionsWithContext = await makeSignedActionsWithContext(actionOrActions, document);
6
+ if (!signedActionsWithContext) {
7
+ logger.error("No signed actions with context found");
8
+ return;
9
+ }
10
+ const result = await queueActions(document, signedActionsWithContext);
11
+ return result;
12
+ }
13
+ //# sourceMappingURL=dispatch.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dispatch.js","sourceRoot":"","sources":["../../../src/actions/dispatch.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAExC,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC1C,OAAO,EAAE,4BAA4B,EAAE,MAAM,WAAW,CAAC;AAEzD,MAAM,CAAC,KAAK,UAAU,eAAe,CACnC,eAA8C,EAC9C,QAAgC;IAEhC,MAAM,wBAAwB,GAAG,MAAM,4BAA4B,CACjE,eAAe,EACf,QAAQ,CACT,CAAC;IACF,IAAI,CAAC,wBAAwB,EAAE,CAAC;QAC9B,MAAM,CAAC,KAAK,CAAC,sCAAsC,CAAC,CAAC;QACrD,OAAO;IACT,CAAC;IACD,MAAM,MAAM,GAAG,MAAM,YAAY,CAAC,QAAQ,EAAE,wBAAwB,CAAC,CAAC;IACtE,OAAO,MAAM,CAAC;AAChB,CAAC"}
@@ -0,0 +1,14 @@
1
+ import { type DocumentDriveDocument, type Node } from "document-drive";
2
+ import { type PHDocument } from "document-model";
3
+ export declare function downloadFile(document: PHDocument): void;
4
+ export declare function exportFile(document: PHDocument): Promise<FileSystemFileHandle | undefined>;
5
+ export declare function loadFile(path: string | File): Promise<PHDocument<unknown, unknown> | undefined>;
6
+ export declare function addDocument(driveId: string, name: string, documentType: string, parentFolder?: string, document?: PHDocument, id?: string, preferredEditor?: string): Promise<import("document-drive").FileNode | undefined>;
7
+ export declare function addFile(file: string | File, driveId: string, name?: string, parentFolder?: string): Promise<void>;
8
+ export declare function updateFile(driveId: string, nodeId: string, documentType?: string, name?: string, parentFolder?: string): Promise<import("document-drive").FileNode | undefined>;
9
+ export declare function addFolder(driveId: string, name: string, parentFolder?: string): Promise<import("document-drive").FolderNode | undefined>;
10
+ export declare function deleteNode(driveId: string, nodeId: string): Promise<void>;
11
+ export declare function renameNode(driveId: string, nodeId: string, name: string): Promise<Node | undefined>;
12
+ export declare function moveNode(src: Node, target: Node | undefined): Promise<void>;
13
+ export declare function copyNode(src: Node, target: Node | undefined): Promise<DocumentDriveDocument | undefined>;
14
+ //# sourceMappingURL=document.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"document.d.ts","sourceRoot":"","sources":["../../../src/actions/document.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,qBAAqB,EAC1B,KAAK,IAAI,EAYV,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACL,KAAK,UAAU,EAOhB,MAAM,gBAAgB,CAAC;AAQxB,wBAAgB,YAAY,CAAC,QAAQ,EAAE,UAAU,QAgBhD;AAED,wBAAsB,UAAU,CAAC,QAAQ,EAAE,UAAU,6CAyBpD;AAED,wBAAsB,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,qDAoBjD;AAED,wBAAsB,WAAW,CAC/B,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,MAAM,EACZ,YAAY,EAAE,MAAM,EACpB,YAAY,CAAC,EAAE,MAAM,EACrB,QAAQ,CAAC,EAAE,UAAU,EACrB,EAAE,CAAC,EAAE,MAAM,EACX,eAAe,CAAC,EAAE,MAAM,0DAmDzB;AAED,wBAAsB,OAAO,CAC3B,IAAI,EAAE,MAAM,GAAG,IAAI,EACnB,OAAO,EAAE,MAAM,EACf,IAAI,CAAC,EAAE,MAAM,EACb,YAAY,CAAC,EAAE,MAAM,iBA6DtB;AAED,wBAAsB,UAAU,CAC9B,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,MAAM,EACd,YAAY,CAAC,EAAE,MAAM,EACrB,IAAI,CAAC,EAAE,MAAM,EACb,YAAY,CAAC,EAAE,MAAM,0DA6BtB;AAED,wBAAsB,SAAS,CAC7B,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,MAAM,EACZ,YAAY,CAAC,EAAE,MAAM,4DA6BtB;AAED,wBAAsB,UAAU,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,iBAY/D;AAED,wBAAsB,UAAU,CAC9B,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,MAAM,GACX,OAAO,CAAC,IAAI,GAAG,SAAS,CAAC,CAuB3B;AAED,wBAAsB,QAAQ,CAAC,GAAG,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,GAAG,SAAS,iBA2BjE;AAED,wBAAsB,QAAQ,CAAC,GAAG,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,GAAG,SAAS,8CA2CjE"}