@fluidframework/react 0.41.4 → 2.63.0-358419

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 (342) hide show
  1. package/.eslintrc.cjs +11 -0
  2. package/.mocharc.cjs +15 -0
  3. package/CHANGELOG.md +282 -0
  4. package/README.md +122 -273
  5. package/api-extractor/api-extractor-lint-alpha.cjs.json +5 -0
  6. package/api-extractor/api-extractor-lint-alpha.esm.json +5 -0
  7. package/api-extractor/api-extractor-lint-beta.cjs.json +5 -0
  8. package/api-extractor/api-extractor-lint-beta.esm.json +5 -0
  9. package/api-extractor/api-extractor-lint-bundle.json +5 -0
  10. package/api-extractor/api-extractor-lint-public.cjs.json +5 -0
  11. package/api-extractor/api-extractor-lint-public.esm.json +5 -0
  12. package/api-extractor-lint.json +4 -0
  13. package/api-extractor.json +2 -2
  14. package/api-report/react.alpha.api.md +114 -0
  15. package/api-report/react.beta.api.md +7 -0
  16. package/api-report/react.public.api.md +7 -0
  17. package/biome.jsonc +4 -0
  18. package/dist/alpha.d.ts +45 -0
  19. package/dist/beta.d.ts +15 -0
  20. package/dist/index.d.ts +11 -7
  21. package/dist/index.d.ts.map +1 -1
  22. package/dist/index.js +19 -17
  23. package/dist/index.js.map +1 -1
  24. package/dist/package.json +4 -0
  25. package/dist/propNode.d.ts +114 -0
  26. package/dist/propNode.d.ts.map +1 -0
  27. package/dist/propNode.js +43 -0
  28. package/dist/propNode.js.map +1 -0
  29. package/dist/public.d.ts +15 -0
  30. package/dist/reactSharedTreeView.d.ts +119 -0
  31. package/dist/reactSharedTreeView.d.ts.map +1 -0
  32. package/dist/reactSharedTreeView.js +206 -0
  33. package/dist/reactSharedTreeView.js.map +1 -0
  34. package/dist/simpleIdentifier.d.ts +19 -0
  35. package/dist/simpleIdentifier.d.ts.map +1 -0
  36. package/dist/simpleIdentifier.js +33 -0
  37. package/dist/simpleIdentifier.js.map +1 -0
  38. package/dist/useObservation.d.ts +83 -0
  39. package/dist/useObservation.d.ts.map +1 -0
  40. package/dist/useObservation.js +295 -0
  41. package/dist/useObservation.js.map +1 -0
  42. package/dist/useTree.d.ts +80 -0
  43. package/dist/useTree.d.ts.map +1 -0
  44. package/dist/useTree.js +137 -0
  45. package/dist/useTree.js.map +1 -0
  46. package/lib/alpha.d.ts +45 -0
  47. package/lib/beta.d.ts +15 -0
  48. package/lib/index.d.ts +16 -0
  49. package/lib/index.d.ts.map +1 -0
  50. package/lib/index.js +4 -7
  51. package/lib/index.js.map +1 -1
  52. package/lib/package.json +4 -0
  53. package/lib/propNode.d.ts +114 -0
  54. package/lib/propNode.d.ts.map +1 -0
  55. package/lib/propNode.js +36 -0
  56. package/lib/propNode.js.map +1 -0
  57. package/lib/public.d.ts +15 -0
  58. package/lib/reactSharedTreeView.d.ts +119 -0
  59. package/lib/reactSharedTreeView.d.ts.map +1 -0
  60. package/lib/reactSharedTreeView.js +176 -0
  61. package/lib/reactSharedTreeView.js.map +1 -0
  62. package/lib/simpleIdentifier.d.ts +19 -0
  63. package/lib/simpleIdentifier.d.ts.map +1 -0
  64. package/lib/simpleIdentifier.js +29 -0
  65. package/lib/simpleIdentifier.js.map +1 -0
  66. package/lib/test/propNode.spec.js +120 -0
  67. package/lib/test/propNode.spec.js.map +1 -0
  68. package/lib/test/reactSharedTreeView.spec.js +71 -0
  69. package/lib/test/reactSharedTreeView.spec.js.map +1 -0
  70. package/lib/test/simpleIdentifier.spec.js +18 -0
  71. package/lib/test/simpleIdentifier.spec.js.map +1 -0
  72. package/lib/test/useObservation.spec.js +162 -0
  73. package/lib/test/useObservation.spec.js.map +1 -0
  74. package/lib/test/useTree.spec.js +165 -0
  75. package/lib/test/useTree.spec.js.map +1 -0
  76. package/lib/tsdoc-metadata.json +11 -0
  77. package/lib/useObservation.d.ts +83 -0
  78. package/lib/useObservation.d.ts.map +1 -0
  79. package/lib/useObservation.js +266 -0
  80. package/lib/useObservation.js.map +1 -0
  81. package/lib/useTree.d.ts +80 -0
  82. package/lib/useTree.d.ts.map +1 -0
  83. package/lib/useTree.js +105 -0
  84. package/lib/useTree.js.map +1 -0
  85. package/package.json +150 -51
  86. package/react.test-files.tar +0 -0
  87. package/src/index.ts +42 -7
  88. package/src/propNode.ts +164 -0
  89. package/src/reactSharedTreeView.tsx +327 -0
  90. package/src/simpleIdentifier.ts +31 -0
  91. package/src/useObservation.ts +376 -0
  92. package/src/useTree.ts +147 -0
  93. package/tsconfig.cjs.json +7 -0
  94. package/tsconfig.json +12 -15
  95. package/tsdoc.json +4 -0
  96. package/.eslintrc.js +0 -11
  97. package/dist/createContextFluid.d.ts +0 -7
  98. package/dist/createContextFluid.d.ts.map +0 -1
  99. package/dist/createContextFluid.js +0 -46
  100. package/dist/createContextFluid.js.map +0 -1
  101. package/dist/helpers/generateFluidObjectSchema.d.ts +0 -16
  102. package/dist/helpers/generateFluidObjectSchema.d.ts.map +0 -1
  103. package/dist/helpers/generateFluidObjectSchema.js +0 -75
  104. package/dist/helpers/generateFluidObjectSchema.js.map +0 -1
  105. package/dist/helpers/getFluidFromView.d.ts +0 -15
  106. package/dist/helpers/getFluidFromView.d.ts.map +0 -1
  107. package/dist/helpers/getFluidFromView.js +0 -30
  108. package/dist/helpers/getFluidFromView.js.map +0 -1
  109. package/dist/helpers/getFluidState.d.ts +0 -15
  110. package/dist/helpers/getFluidState.d.ts.map +0 -1
  111. package/dist/helpers/getFluidState.js +0 -47
  112. package/dist/helpers/getFluidState.js.map +0 -1
  113. package/dist/helpers/getSchema.d.ts +0 -13
  114. package/dist/helpers/getSchema.d.ts.map +0 -1
  115. package/dist/helpers/getSchema.js +0 -15
  116. package/dist/helpers/getSchema.js.map +0 -1
  117. package/dist/helpers/getViewFromFluid.d.ts +0 -18
  118. package/dist/helpers/getViewFromFluid.d.ts.map +0 -1
  119. package/dist/helpers/getViewFromFluid.js +0 -47
  120. package/dist/helpers/getViewFromFluid.js.map +0 -1
  121. package/dist/helpers/index.d.ts +0 -16
  122. package/dist/helpers/index.d.ts.map +0 -1
  123. package/dist/helpers/index.js +0 -28
  124. package/dist/helpers/index.js.map +0 -1
  125. package/dist/helpers/initializeState.d.ts +0 -22
  126. package/dist/helpers/initializeState.d.ts.map +0 -1
  127. package/dist/helpers/initializeState.js +0 -77
  128. package/dist/helpers/initializeState.js.map +0 -1
  129. package/dist/helpers/internalInterface.d.ts +0 -15
  130. package/dist/helpers/internalInterface.d.ts.map +0 -1
  131. package/dist/helpers/internalInterface.js +0 -7
  132. package/dist/helpers/internalInterface.js.map +0 -1
  133. package/dist/helpers/rootCallbackListener.d.ts +0 -24
  134. package/dist/helpers/rootCallbackListener.d.ts.map +0 -1
  135. package/dist/helpers/rootCallbackListener.js +0 -55
  136. package/dist/helpers/rootCallbackListener.js.map +0 -1
  137. package/dist/helpers/setComponentSchema.d.ts +0 -14
  138. package/dist/helpers/setComponentSchema.d.ts.map +0 -1
  139. package/dist/helpers/setComponentSchema.js +0 -18
  140. package/dist/helpers/setComponentSchema.js.map +0 -1
  141. package/dist/helpers/setFluidState.d.ts +0 -20
  142. package/dist/helpers/setFluidState.d.ts.map +0 -1
  143. package/dist/helpers/setFluidState.js +0 -94
  144. package/dist/helpers/setFluidState.js.map +0 -1
  145. package/dist/helpers/syncState.d.ts +0 -25
  146. package/dist/helpers/syncState.d.ts.map +0 -1
  147. package/dist/helpers/syncState.js +0 -98
  148. package/dist/helpers/syncState.js.map +0 -1
  149. package/dist/helpers/updateStateAndFluidObjectMap.d.ts +0 -29
  150. package/dist/helpers/updateStateAndFluidObjectMap.d.ts.map +0 -1
  151. package/dist/helpers/updateStateAndFluidObjectMap.js +0 -30
  152. package/dist/helpers/updateStateAndFluidObjectMap.js.map +0 -1
  153. package/dist/helpers/utils.d.ts +0 -12
  154. package/dist/helpers/utils.d.ts.map +0 -1
  155. package/dist/helpers/utils.js +0 -74
  156. package/dist/helpers/utils.js.map +0 -1
  157. package/dist/interface.d.ts +0 -444
  158. package/dist/interface.d.ts.map +0 -1
  159. package/dist/interface.js +0 -18
  160. package/dist/interface.js.map +0 -1
  161. package/dist/reactView.d.ts +0 -32
  162. package/dist/reactView.d.ts.map +0 -1
  163. package/dist/reactView.js +0 -79
  164. package/dist/reactView.js.map +0 -1
  165. package/dist/syncedDataObject.d.ts +0 -80
  166. package/dist/syncedDataObject.d.ts.map +0 -1
  167. package/dist/syncedDataObject.js +0 -249
  168. package/dist/syncedDataObject.js.map +0 -1
  169. package/dist/syncedObjects/array/fluidSyncedArray.d.ts +0 -11
  170. package/dist/syncedObjects/array/fluidSyncedArray.d.ts.map +0 -1
  171. package/dist/syncedObjects/array/fluidSyncedArray.js +0 -78
  172. package/dist/syncedObjects/array/fluidSyncedArray.js.map +0 -1
  173. package/dist/syncedObjects/array/index.d.ts +0 -7
  174. package/dist/syncedObjects/array/index.d.ts.map +0 -1
  175. package/dist/syncedObjects/array/index.js +0 -19
  176. package/dist/syncedObjects/array/index.js.map +0 -1
  177. package/dist/syncedObjects/array/interface.d.ts +0 -33
  178. package/dist/syncedObjects/array/interface.d.ts.map +0 -1
  179. package/dist/syncedObjects/array/interface.js +0 -3
  180. package/dist/syncedObjects/array/interface.js.map +0 -1
  181. package/dist/syncedObjects/array/syncedArray.d.ts +0 -30
  182. package/dist/syncedObjects/array/syncedArray.d.ts.map +0 -1
  183. package/dist/syncedObjects/array/syncedArray.js +0 -42
  184. package/dist/syncedObjects/array/syncedArray.js.map +0 -1
  185. package/dist/syncedObjects/counter/fluidSyncedCounter.d.ts +0 -11
  186. package/dist/syncedObjects/counter/fluidSyncedCounter.d.ts.map +0 -1
  187. package/dist/syncedObjects/counter/fluidSyncedCounter.js +0 -79
  188. package/dist/syncedObjects/counter/fluidSyncedCounter.js.map +0 -1
  189. package/dist/syncedObjects/counter/index.d.ts +0 -7
  190. package/dist/syncedObjects/counter/index.d.ts.map +0 -1
  191. package/dist/syncedObjects/counter/index.js +0 -19
  192. package/dist/syncedObjects/counter/index.js.map +0 -1
  193. package/dist/syncedObjects/counter/interface.d.ts +0 -32
  194. package/dist/syncedObjects/counter/interface.d.ts.map +0 -1
  195. package/dist/syncedObjects/counter/interface.js +0 -3
  196. package/dist/syncedObjects/counter/interface.js.map +0 -1
  197. package/dist/syncedObjects/counter/syncedCounter.d.ts +0 -29
  198. package/dist/syncedObjects/counter/syncedCounter.d.ts.map +0 -1
  199. package/dist/syncedObjects/counter/syncedCounter.js +0 -36
  200. package/dist/syncedObjects/counter/syncedCounter.js.map +0 -1
  201. package/dist/syncedObjects/index.d.ts +0 -9
  202. package/dist/syncedObjects/index.d.ts.map +0 -1
  203. package/dist/syncedObjects/index.js +0 -21
  204. package/dist/syncedObjects/index.js.map +0 -1
  205. package/dist/syncedObjects/object/index.d.ts +0 -7
  206. package/dist/syncedObjects/object/index.d.ts.map +0 -1
  207. package/dist/syncedObjects/object/index.js +0 -19
  208. package/dist/syncedObjects/object/index.js.map +0 -1
  209. package/dist/syncedObjects/object/interface.d.ts +0 -13
  210. package/dist/syncedObjects/object/interface.d.ts.map +0 -1
  211. package/dist/syncedObjects/object/interface.js +0 -7
  212. package/dist/syncedObjects/object/interface.js.map +0 -1
  213. package/dist/syncedObjects/object/syncedObject.d.ts +0 -22
  214. package/dist/syncedObjects/object/syncedObject.d.ts.map +0 -1
  215. package/dist/syncedObjects/object/syncedObject.js +0 -46
  216. package/dist/syncedObjects/object/syncedObject.js.map +0 -1
  217. package/dist/syncedObjects/string/index.d.ts +0 -7
  218. package/dist/syncedObjects/string/index.d.ts.map +0 -1
  219. package/dist/syncedObjects/string/index.js +0 -19
  220. package/dist/syncedObjects/string/index.js.map +0 -1
  221. package/dist/syncedObjects/string/interface.d.ts +0 -16
  222. package/dist/syncedObjects/string/interface.d.ts.map +0 -1
  223. package/dist/syncedObjects/string/interface.js +0 -7
  224. package/dist/syncedObjects/string/interface.js.map +0 -1
  225. package/dist/syncedObjects/string/syncedString.d.ts +0 -25
  226. package/dist/syncedObjects/string/syncedString.d.ts.map +0 -1
  227. package/dist/syncedObjects/string/syncedString.js +0 -53
  228. package/dist/syncedObjects/string/syncedString.js.map +0 -1
  229. package/dist/useReducerFluid.d.ts +0 -7
  230. package/dist/useReducerFluid.d.ts.map +0 -1
  231. package/dist/useReducerFluid.js +0 -219
  232. package/dist/useReducerFluid.js.map +0 -1
  233. package/dist/useStateFluid.d.ts +0 -10
  234. package/dist/useStateFluid.d.ts.map +0 -1
  235. package/dist/useStateFluid.js +0 -67
  236. package/dist/useStateFluid.js.map +0 -1
  237. package/lib/createContextFluid.js +0 -23
  238. package/lib/createContextFluid.js.map +0 -1
  239. package/lib/helpers/generateFluidObjectSchema.js +0 -71
  240. package/lib/helpers/generateFluidObjectSchema.js.map +0 -1
  241. package/lib/helpers/getFluidFromView.js +0 -26
  242. package/lib/helpers/getFluidFromView.js.map +0 -1
  243. package/lib/helpers/getFluidState.js +0 -43
  244. package/lib/helpers/getFluidState.js.map +0 -1
  245. package/lib/helpers/getSchema.js +0 -11
  246. package/lib/helpers/getSchema.js.map +0 -1
  247. package/lib/helpers/getViewFromFluid.js +0 -43
  248. package/lib/helpers/getViewFromFluid.js.map +0 -1
  249. package/lib/helpers/index.js +0 -16
  250. package/lib/helpers/index.js.map +0 -1
  251. package/lib/helpers/initializeState.js +0 -73
  252. package/lib/helpers/initializeState.js.map +0 -1
  253. package/lib/helpers/internalInterface.js +0 -6
  254. package/lib/helpers/internalInterface.js.map +0 -1
  255. package/lib/helpers/rootCallbackListener.js +0 -51
  256. package/lib/helpers/rootCallbackListener.js.map +0 -1
  257. package/lib/helpers/setComponentSchema.js +0 -14
  258. package/lib/helpers/setComponentSchema.js.map +0 -1
  259. package/lib/helpers/setFluidState.js +0 -90
  260. package/lib/helpers/setFluidState.js.map +0 -1
  261. package/lib/helpers/syncState.js +0 -94
  262. package/lib/helpers/syncState.js.map +0 -1
  263. package/lib/helpers/updateStateAndFluidObjectMap.js +0 -26
  264. package/lib/helpers/updateStateAndFluidObjectMap.js.map +0 -1
  265. package/lib/helpers/utils.js +0 -67
  266. package/lib/helpers/utils.js.map +0 -1
  267. package/lib/interface.js +0 -8
  268. package/lib/interface.js.map +0 -1
  269. package/lib/reactView.js +0 -56
  270. package/lib/reactView.js.map +0 -1
  271. package/lib/syncedDataObject.js +0 -245
  272. package/lib/syncedDataObject.js.map +0 -1
  273. package/lib/syncedObjects/array/fluidSyncedArray.js +0 -72
  274. package/lib/syncedObjects/array/fluidSyncedArray.js.map +0 -1
  275. package/lib/syncedObjects/array/index.js +0 -7
  276. package/lib/syncedObjects/array/index.js.map +0 -1
  277. package/lib/syncedObjects/array/interface.js +0 -2
  278. package/lib/syncedObjects/array/interface.js.map +0 -1
  279. package/lib/syncedObjects/array/syncedArray.js +0 -37
  280. package/lib/syncedObjects/array/syncedArray.js.map +0 -1
  281. package/lib/syncedObjects/counter/fluidSyncedCounter.js +0 -73
  282. package/lib/syncedObjects/counter/fluidSyncedCounter.js.map +0 -1
  283. package/lib/syncedObjects/counter/index.js +0 -7
  284. package/lib/syncedObjects/counter/index.js.map +0 -1
  285. package/lib/syncedObjects/counter/interface.js +0 -2
  286. package/lib/syncedObjects/counter/interface.js.map +0 -1
  287. package/lib/syncedObjects/counter/syncedCounter.js +0 -31
  288. package/lib/syncedObjects/counter/syncedCounter.js.map +0 -1
  289. package/lib/syncedObjects/index.js +0 -9
  290. package/lib/syncedObjects/index.js.map +0 -1
  291. package/lib/syncedObjects/object/index.js +0 -7
  292. package/lib/syncedObjects/object/index.js.map +0 -1
  293. package/lib/syncedObjects/object/interface.js +0 -6
  294. package/lib/syncedObjects/object/interface.js.map +0 -1
  295. package/lib/syncedObjects/object/syncedObject.js +0 -41
  296. package/lib/syncedObjects/object/syncedObject.js.map +0 -1
  297. package/lib/syncedObjects/string/index.js +0 -7
  298. package/lib/syncedObjects/string/index.js.map +0 -1
  299. package/lib/syncedObjects/string/interface.js +0 -6
  300. package/lib/syncedObjects/string/interface.js.map +0 -1
  301. package/lib/syncedObjects/string/syncedString.js +0 -48
  302. package/lib/syncedObjects/string/syncedString.js.map +0 -1
  303. package/lib/useReducerFluid.js +0 -196
  304. package/lib/useReducerFluid.js.map +0 -1
  305. package/lib/useStateFluid.js +0 -44
  306. package/lib/useStateFluid.js.map +0 -1
  307. package/src/createContextFluid.tsx +0 -33
  308. package/src/helpers/generateFluidObjectSchema.ts +0 -95
  309. package/src/helpers/getFluidFromView.ts +0 -38
  310. package/src/helpers/getFluidState.ts +0 -67
  311. package/src/helpers/getSchema.ts +0 -18
  312. package/src/helpers/getViewFromFluid.ts +0 -68
  313. package/src/helpers/index.tsx +0 -16
  314. package/src/helpers/initializeState.ts +0 -162
  315. package/src/helpers/internalInterface.ts +0 -16
  316. package/src/helpers/rootCallbackListener.ts +0 -104
  317. package/src/helpers/setComponentSchema.ts +0 -21
  318. package/src/helpers/setFluidState.ts +0 -116
  319. package/src/helpers/syncState.ts +0 -159
  320. package/src/helpers/updateStateAndFluidObjectMap.ts +0 -85
  321. package/src/helpers/utils.tsx +0 -109
  322. package/src/interface.ts +0 -617
  323. package/src/reactView.tsx +0 -108
  324. package/src/syncedDataObject.ts +0 -337
  325. package/src/syncedObjects/array/fluidSyncedArray.ts +0 -126
  326. package/src/syncedObjects/array/index.ts +0 -7
  327. package/src/syncedObjects/array/interface.ts +0 -45
  328. package/src/syncedObjects/array/syncedArray.ts +0 -65
  329. package/src/syncedObjects/counter/fluidSyncedCounter.ts +0 -122
  330. package/src/syncedObjects/counter/index.ts +0 -7
  331. package/src/syncedObjects/counter/interface.ts +0 -44
  332. package/src/syncedObjects/counter/syncedCounter.ts +0 -64
  333. package/src/syncedObjects/index.ts +0 -9
  334. package/src/syncedObjects/object/index.ts +0 -7
  335. package/src/syncedObjects/object/interface.ts +0 -14
  336. package/src/syncedObjects/object/syncedObject.ts +0 -55
  337. package/src/syncedObjects/string/index.ts +0 -7
  338. package/src/syncedObjects/string/interface.ts +0 -17
  339. package/src/syncedObjects/string/syncedString.ts +0 -61
  340. package/src/useReducerFluid.tsx +0 -436
  341. package/src/useStateFluid.tsx +0 -84
  342. package/tsconfig.esnext.json +0 -7
package/src/interface.ts DELETED
@@ -1,617 +0,0 @@
1
- /*!
2
- * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
- * Licensed under the MIT License.
4
- */
5
- import { ISharedMap, IValueChanged } from "@fluidframework/map";
6
- import { IFluidDataStoreRuntime } from "@fluidframework/datastore-definitions";
7
- import {
8
- IFluidHandle,
9
- IFluidLoadable,
10
- IFluidObject,
11
- } from "@fluidframework/core-interfaces";
12
- import { SyncedDataObject } from "./syncedDataObject";
13
-
14
- /**
15
- * The combined state contains the Fluid and view states and the data props
16
- * that are passed in to all reducers and selectors
17
- */
18
- export interface ICombinedState<
19
- SV extends IViewState,
20
- SF extends IFluidState,
21
- C extends IFluidDataProps
22
- > {
23
- /**
24
- * The react view state that will be used for all view renders
25
- */
26
- viewState: SV;
27
- /**
28
- * The Fluid state that will be used to update the synced values in the state. This will be
29
- * undefined until it is initialized, after which the state will update with the defined values
30
- */
31
- fluidState?: SF;
32
- /**
33
- * Data props that are loaded in during the Fluid initialization step. This contains the runtime
34
- * and the Fluid object map, along with any other properties the user wants to pass to reducers
35
- * and selectors
36
- */
37
- dataProps: C;
38
- }
39
-
40
- /**
41
- * The Fluid schema that is generated on load and will be stored in the synced state
42
- */
43
- export interface IFluidSchema {
44
- /**
45
- * (k,v) = (viewKeys, needsFluidConverter)
46
- */
47
- viewMatchingMap: ISharedMap;
48
- /**
49
- * (k,v) = (fluidKeys, needsViewConverter)
50
- */
51
- fluidMatchingMap: ISharedMap;
52
- /**
53
- * (k,v) = (path, handle)
54
- */
55
- storedHandleMap: ISharedMap;
56
- }
57
-
58
- /**
59
- * A map of the view state values that need conversion to their Fluid state counterparts and the
60
- * respective converters
61
- */
62
- export type ViewToFluidMap<SV, SF> = Map<keyof SV, IFluidConverter<SV, SF>>;
63
-
64
- /**
65
- * A map of the Fluid state values that need conversion to their view state counterparts and the
66
- * respective converters
67
- */
68
- export type FluidToViewMap<SV, SF> = Map<keyof SF, IViewConverter<SV, SF>>;
69
-
70
- /**
71
- * The Fluid reducer, containing an object that is keyed by function name and contains state update and
72
- * effect functions. Each function will have the view state, fluid state, and data props passed into it
73
- * as parameters in the combined state. State update functions are used to modify values on the state and return
74
- * the updated state and any new Fluid object handles. Effect functions use values on the state to apply changes
75
- * elsewhere. They do not return any new objects or state.
76
- */
77
- export interface IFluidReducer<
78
- SV extends IViewState,
79
- SF extends IFluidState,
80
- C extends IFluidDataProps
81
- > {
82
- [key: string]:
83
- | FluidAsyncStateUpdateFunction<SV, SF, C>
84
- | FluidStateUpdateFunction<SV, SF, C>
85
- | FluidEffectFunction<SV, SF, C>
86
- | FluidAsyncEffectFunction<SV, SF, C>;
87
- }
88
-
89
- /**
90
- * The Fluid selector, containing an object that is keyed by function name and contains selector
91
- * functions. Each function will have the view state, fluid state, and data props passed into it
92
- * as parameters in the combined state. Selector functions can also optionally pass in a
93
- * handle to fetch from the Fluid object map.
94
- * Selector functions are used to retrieve Fluid objects or parameters from other Fluid objects.
95
- * It offers a way to fetch these values and return them to the view, with the
96
- * Fluid object map being updated if the view requires a Fluid object that hasn't been locally loaded yet
97
- */
98
- export interface IFluidSelector<
99
- SV extends IViewState,
100
- SF extends IFluidState,
101
- C extends IFluidDataProps
102
- > {
103
- [key: string]:
104
- | FluidSelectorFunction<SV, SF, C>
105
- | FluidObjectSelectorFunction<SV, SF, C>;
106
- }
107
-
108
- /**
109
- * Props passed in to create a FluidReactView or passed in to the useStateFluid hook
110
- */
111
- export interface IFluidProps<
112
- SV extends IViewState,
113
- SF extends IFluidState
114
- > {
115
- /**
116
- * Unique ID to use for storing the synced state in the SyncedDataObject's syncedState SharedMap
117
- */
118
- syncedStateId: string;
119
- /**
120
- * An instance of the SyncedDataObject that this view will be rendered in
121
- */
122
- syncedDataObject: SyncedDataObject;
123
- /**
124
- * Data props containing the Fluid object map and the runtime
125
- * Optional as the above two will be passed by default. This only need to be defined
126
- * if there are additional values from the Fluid object lifecycle that need to be made
127
- * available to the reducers
128
- */
129
- dataProps?: IFluidDataProps;
130
- }
131
-
132
- /**
133
- * View converters to take the synced state Fluid value that they are keyed against in the FluidToView map
134
- * and convert them into their view state counterparts
135
- */
136
- export interface IViewConverter<
137
- SV extends IViewState,
138
- SF extends IFluidState
139
- > {
140
- /**
141
- * The type of object this key in the Fluid state holds
142
- */
143
- type: string;
144
- /**
145
- * The corresponding value key within the view state type
146
- */
147
- viewKey: keyof SV;
148
- /**
149
- * A callback that takes in the partial Fluid state containing the value that
150
- * this converter maps to, and returns the corresponding partial view state
151
- */
152
- viewConverter?: (
153
- viewState: SV,
154
- fluidState: Partial<SF>,
155
- fluidObjectMap: FluidObjectMap
156
- ) => Partial<SV>;
157
- /**
158
- * If this is a fluid DDS SharedObject type (i.e. SharedCounter, SharedMap), supply its create function
159
- * here and add any events that it will fire to the listenedEvents param below to trigger state updates
160
- */
161
- sharedObjectCreate?: (runtime: IFluidDataStoreRuntime) => any;
162
- /**
163
- * List of events fired on this Fluid object that will trigger a state update
164
- */
165
- listenedEvents?: string[];
166
- /**
167
- * If this Fluid object is stored on the Fluid DataObject root under a different key
168
- * than the name of this Fluid state key within the synced state map,
169
- * provide the key on the root for this object here. The changes will also
170
- * reflect under that key if the data needs to be used elsewhere
171
- */
172
- rootKey?: string;
173
- }
174
-
175
- /**
176
- * Fluid converters to take the view state value that they are keyed against in the ViewToFluid map
177
- * and convert them into their synced Fluid state counterparts
178
- */
179
- export interface IFluidConverter<
180
- SV extends IViewState,
181
- SF extends IFluidState
182
- > {
183
- /**
184
- * The type of object this key in the view state holds
185
- */
186
- type: string;
187
- /**
188
- * The corresponding value within the Fluid state
189
- */
190
- fluidKey: keyof SF;
191
- /**
192
- * A callback that takes in the partial view state containing the value that
193
- * this converter maps to, and optionally returns a value. This value will be automatically set on the synced state
194
- * under the view key this converter maps to
195
- */
196
- fluidConverter?: (viewState: SV, fluidState: Partial<SF>) => any;
197
- }
198
-
199
- /**
200
- * Base interface to extend from for the Fluid state. These values can and should be left
201
- * undefined when passing in the initial state as they will be used to establish the Fluid state
202
- */
203
- export interface IFluidState {
204
- /**
205
- * The unique state ID for this React Fluid view
206
- */
207
- syncedStateId?: string;
208
- /**
209
- * Boolean indicating if any DDSes or Fluid objects on this state are being listened on
210
- * for synced state updates to trigger React state updates
211
- */
212
- isInitialized?: boolean;
213
- }
214
-
215
- /**
216
- * Base interface to extend from for the view state.
217
- * This should be crafted based off of what the view will use from the Fluid state.
218
- */
219
- export interface IViewState
220
- extends IFluidState {
221
- /**
222
- * The map containing the locally available Fluid objects that have been loaded. If there are
223
- * any Fluid objects loaded during initialization that the view needs to use,
224
- * they should be fetched and loaded in here.
225
- * Any new Fluid objects added through reducers/selectors during the React lifecycle
226
- * will be automatically added to this map and the state will re-update when they become asynchronously available
227
- */
228
- fluidObjectMap?: FluidObjectMap;
229
- }
230
-
231
- export type IFluidReactState = IFluidState & IViewState;
232
-
233
- export const instanceOfIFluidLoadable = (
234
- object: any,
235
- ): object is IFluidLoadable =>
236
- object === Object(object) && "IFluidLoadable" in object;
237
-
238
- /**
239
- * The values stored in the Fluid object map
240
- */
241
- export interface IFluidObjectMapItem {
242
- /**
243
- * The actual Fluid object that the path this value is keyed against leads to
244
- */
245
- fluidObject?: IFluidObject & IFluidLoadable;
246
- /**
247
- * Boolean indicating if we are listening to changes on this Fluid object's synced state to trigger React
248
- * state updates. Only set if you want custom behavior for adding listeners to your Fluid state
249
- */
250
- isListened?: boolean;
251
- /**
252
- * List of events fired on this Fluid object that will trigger a state update
253
- */
254
- listenedEvents?: string[];
255
- /**
256
- * INTERNAL
257
- * Does not need to be set
258
- * Is this a SharedMap that was added as a Fluid React requirement
259
- */
260
- isRuntimeMap?: boolean;
261
- }
262
-
263
- /**
264
- * A map of the Fluid object handle absolute path to the Fluid object
265
- */
266
- export type FluidObjectMap = Map<string, IFluidObjectMapItem>;
267
-
268
- /**
269
- * Base interface to extend from for the data props that will be passed in for reducers and
270
- * selectors to use to offer inter-Fluid object operability
271
- */
272
- export interface IFluidDataProps {
273
- /**
274
- * The Fluid data store runtime passed in from Fluid object initialization
275
- */
276
- runtime: IFluidDataStoreRuntime;
277
- /**
278
- * The running map of all the Fluid objects being used to render the React view. This
279
- * can be view/data Fluid objects, and they will be asynchronously loaded here so that they are,
280
- * in turn, synchronously available for the view when the state updates after they are fetched
281
- */
282
- fluidObjectMap: FluidObjectMap;
283
- }
284
-
285
- /**
286
- * Definition for an effect function used in reducers
287
- */
288
- export interface FluidEffectFunction<
289
- SV extends IViewState,
290
- SF extends IFluidState,
291
- C extends IFluidDataProps
292
- > {
293
- /**
294
- * The function defined here will take the combined state and apply some
295
- * logic that does not cause any state update changes
296
- */
297
- function: (oldState?: ICombinedState<SV, SF, C>, ...args: any) => void;
298
- }
299
-
300
- export const instanceOfEffectFunction = <
301
- SV extends IViewState,
302
- SF extends IFluidState,
303
- C extends IFluidDataProps
304
- >(
305
- object: any,
306
- ): object is FluidEffectFunction<SV, SF, C> =>
307
- object === Object(object) && "function" in object;
308
-
309
- /**
310
- * Definition for an async effect function used in reducers
311
- */
312
- export interface FluidAsyncEffectFunction<
313
- SV extends IViewState,
314
- SF extends IFluidState,
315
- C extends IFluidDataProps
316
- > {
317
- /**
318
- * The function defined here will take the combined state and apply some
319
- * async logic that does not cause any state update changes
320
- */
321
- asyncFunction: (
322
- oldState?: ICombinedState<SV, SF, C>,
323
- ...args: any
324
- ) => Promise<void>;
325
- }
326
-
327
- export const instanceOfAsyncEffectFunction = <
328
- SV extends IViewState,
329
- SF extends IFluidState,
330
- C extends IFluidDataProps
331
- >(
332
- object: any,
333
- ): object is FluidAsyncEffectFunction<SV, SF, C> =>
334
- object === Object(object) && "asyncFunction" in object;
335
-
336
- /**
337
- * Definition for a state update function used in reducers
338
- */
339
- export interface FluidStateUpdateFunction<
340
- SV extends IViewState,
341
- SF extends IFluidState,
342
- C extends IFluidDataProps
343
- > {
344
- /**
345
- * The function defined here will take the combined state and update either
346
- * the Fluid state, the view state, or both. The new combined state and any new Fluid object
347
- * handles to load in are returned by the function.
348
- */
349
- function: (
350
- oldState?: ICombinedState<SV, SF, C>,
351
- ...args: any
352
- ) => IStateUpdateResult<SV, SF, C>;
353
- }
354
-
355
- export const instanceOfStateUpdateFunction = <
356
- SV extends IViewState,
357
- SF extends IFluidState,
358
- C extends IFluidDataProps
359
- >(
360
- object: any,
361
- ): object is FluidStateUpdateFunction<SV, SF, C> =>
362
- object === Object(object) && "function" in object;
363
-
364
- /**
365
- * Definition for an async state update function used in reducers
366
- */
367
- export interface FluidAsyncStateUpdateFunction<
368
- SV extends IViewState,
369
- SF extends IFluidState,
370
- C extends IFluidDataProps
371
- > {
372
- /**
373
- * The function defined here will take the combined state and update either
374
- * the Fluid state, the view state, or both in an async manner. The new combined state and any new
375
- * Fluid object handles to load in will be returned by the function when it finishes.
376
- */
377
- asyncFunction: (
378
- oldState?: ICombinedState<SV, SF, C>,
379
- ...args: any
380
- ) => Promise<IStateUpdateResult<SV, SF, C>>;
381
- }
382
-
383
- /**
384
- * The value returned by state update functions.
385
- */
386
- export interface IStateUpdateResult<
387
- SV extends IViewState,
388
- SF extends IFluidState,
389
- C extends IFluidDataProps
390
- > {
391
- /**
392
- * The new view and Fluid states that were updated by the function
393
- */
394
- state: ICombinedState<SV, SF, C>;
395
- /**
396
- * Any new Fluid objects that were added in due this function need to have
397
- * their corresponding handles passed in so that the object can also be loaded for all other users
398
- */
399
- newFluidHandles?: IFluidHandle[];
400
- }
401
-
402
- export const instanceOfAsyncStateUpdateFunction = <
403
- SV extends IViewState,
404
- SF extends IFluidState,
405
- C extends IFluidDataProps
406
- >(
407
- object: any,
408
- ): object is FluidAsyncStateUpdateFunction<SF, SV, C> =>
409
- object === Object(object) && "asyncFunction" in object;
410
-
411
- /**
412
- * Definition for a selector function used in selectors
413
- */
414
- export interface FluidSelectorFunction<
415
- SV extends IViewState,
416
- SF extends IFluidState,
417
- C extends IFluidDataProps
418
- > {
419
- /**
420
- * The function defined here will take the combined state and return
421
- * to the view any values that it needs from other values/Fluid objects that were passed
422
- * in to the data props on initializing.
423
- * It will also return any new Fluid handles that will be needed for other users to render the view value
424
- */
425
- function: (
426
- state?: ICombinedState<SV, SF, C>
427
- ) => {
428
- result: any | undefined;
429
- newFluidHandles?: IFluidHandle[];
430
- };
431
- }
432
-
433
- /**
434
- * Definition for a Fluid object selector function used in selectors
435
- */
436
- export interface FluidObjectSelectorFunction<
437
- SV extends IViewState,
438
- SF extends IFluidState,
439
- C extends IFluidDataProps
440
- > {
441
- /**
442
- * Similar to the FluidSelectorFunction's function but this also takes in a
443
- * handle if we need to fetch a Fluid object from the fluidObjectMap
444
- */
445
- function: (
446
- handle: IFluidHandle<any>,
447
- state?: ICombinedState<SV, SF, C>,
448
- ) => {
449
- result: IFluidObject | undefined;
450
- newFluidHandles?: IFluidHandle[];
451
- };
452
- }
453
-
454
- export const instanceOfSelectorFunction = <
455
- SV extends IViewState,
456
- SF extends IFluidState,
457
- C extends IFluidDataProps
458
- >(
459
- object: any,
460
- ): object is FluidSelectorFunction<SV, SF, C> =>
461
- object === Object(object) && "function" in object;
462
-
463
- export const instanceOfFluidObjectSelectorFunction = <
464
- SV extends IViewState,
465
- SF extends IFluidState,
466
- C extends IFluidDataProps
467
- >(
468
- object: any,
469
- ): object is FluidObjectSelectorFunction<SV, SF, C> =>
470
- object === Object(object) && "function" in object;
471
-
472
- /**
473
- * Props passed in to the useReducerFluid hook
474
- */
475
- export interface IFluidReducerProps<
476
- SV extends IViewState,
477
- SF extends IFluidState,
478
- A extends IFluidReducer<SV, SF, C>,
479
- B,
480
- C extends IFluidDataProps
481
- > {
482
- /**
483
- * Unique ID to use for storing the view's synced state in the SyncedDataObject's syncedState SharedMap
484
- */
485
- syncedStateId: string;
486
- /**
487
- * An instance of the SyncedDataObject that this will be rendered in
488
- */
489
- syncedDataObject: SyncedDataObject;
490
- /**
491
- * The Fluid reducer containing all the functions as defined by an extension of the IFluidReducer type.
492
- * Any mutations to the state, or effects outside of the Fluid object involving the state should be done here.
493
- */
494
- reducer: A;
495
- /**
496
- * The Fluid selector containing all the functions as defined by an extension of the IFluidSelector
497
- * type. Any fetching of new Fluid objects or data from other Fluid objects should be done here.
498
- */
499
- selector: B;
500
- /**
501
- * Data props that are loaded in during the Fluid initialization step. This contains the runtime
502
- * and the Fluid object map
503
- * TODO: Move data props out as it can be fetched from synced Fluid data object but
504
- * still needs to be extensible for reducers
505
- */
506
- dataProps?: C;
507
- }
508
-
509
- /**
510
- * Props containing the context that will be passed down through the Fluid context provider to the consumer
511
- */
512
- export interface IFluidContextProps<SV, SF, C> extends IFluidProps<SV, SF> {
513
- /**
514
- * The additional data that will be passed through the Fluid context
515
- */
516
- reactContext?: C;
517
- }
518
-
519
- /**
520
- * The state that is available through the react context
521
- */
522
- export interface FluidContextState<
523
- SV extends IViewState,
524
- C
525
- > {
526
- /**
527
- * The view state
528
- */
529
- state: SV;
530
- /**
531
- * Callback to update the state
532
- */
533
- setState: (state: SV) => void;
534
- /**
535
- * The context passed in from the props
536
- */
537
- reactContext: Partial<C>;
538
- }
539
-
540
- /**
541
- * The returned value of createFluidContext
542
- */
543
- export interface FluidContext<
544
- SV extends IViewState,
545
- C
546
- > {
547
- /**
548
- * The context provider React component that will give the FluidContextState to
549
- * its children
550
- */
551
- Provider: React.ProviderExoticComponent<
552
- React.ProviderProps<FluidContextState<SV, C>>
553
- >;
554
- /**
555
- * The context consumer that allows children to use the FluidContextState
556
- */
557
- Consumer: React.Consumer<FluidContextState<SV, C>>;
558
- /**
559
- * Callback to get the context
560
- */
561
- usePrimedContext: () => FluidContextState<SV, C>;
562
- /**
563
- * The view state
564
- */
565
- state: SV;
566
- /**
567
- * Callback to update the state
568
- */
569
- setState: (newState: SV) => void;
570
- }
571
-
572
- export interface ISyncedStateConfig<SV, SF> {
573
- /**
574
- * Unique ID to use for storing the view's synced state in the SyncedDataObject's syncedState SharedMap
575
- */
576
- syncedStateId: string;
577
- /**
578
- * The backup default view that any view with this ID will use prior to Fluid state initializing, this can be
579
- * overridden by the view developer themselves
580
- */
581
- defaultViewState: SV;
582
- /**
583
- * A map of the Fluid state values that need conversion to their view state counterparts and the
584
- * respective converters
585
- */
586
- fluidToView: FluidToViewMap<SV, SF>;
587
- /**
588
- * A map of the view state values that need conversion to their Fluid state counterparts and the
589
- * respective converters
590
- */
591
- viewToFluid?: ViewToFluidMap<SV, SF>;
592
- }
593
-
594
- /**
595
- * The configurations that define the relationships between Fluid and view states for
596
- * views that are rendered in a SyncedDataObject
597
- */
598
- export type SyncedStateConfig = Map<string, ISyncedStateConfig<any, any>>;
599
-
600
- /**
601
- * The interface for interacting with the synced state that is stored on a SyncedDataObject
602
- */
603
- export interface ISyncedState {
604
- /**
605
- * Set values on the synced state for a syncedStateId as key
606
- */
607
- set: (key: string, value: any) => void;
608
- /**
609
- * Get values from the synced state for a syncedStateId as key
610
- */
611
- get: <T>(key: string) => T | undefined;
612
- /**
613
- * Add a listener to the synced state using a provided callback
614
- */
615
- addValueChangedListener: (
616
- callback: (changed: IValueChanged, local: boolean) => void) => void;
617
- }