@fluidframework/react 0.41.4 → 2.62.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.
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/tscon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AC;AACN,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport * as React from \"react\";\nimport { IFluidHandle } from \"@fluidframework/core-interfaces\";\nimport { SharedMap } from \"@fluidframework/map\";\nimport {\n IViewState,\n IFluidReducerProps,\n IFluidDataProps,\n instanceOfStateUpdateFunction,\n instanceOfAsyncStateUpdateFunction,\n instanceOfSelectorFunction,\n instanceOfFluidObjectSelectorFunction,\n instanceOfEffectFunction,\n instanceOfAsyncEffectFunction,\n IStateUpdateResult,\n IFluidState,\n IFluidReducer,\n IFluidSelector,\n ICombinedState,\n ISyncedStateConfig,\n} from \"./interface\";\nimport { useStateFluid } from \"./useStateFluid\";\nimport {\n updateStateAndFluidObjectMap,\n syncedStateCallbackListener,\n getFluidState,\n syncState,\n getSchema,\n} from \"./helpers\";\n\nexport function useReducerFluid<\n SV extends IViewState,\n SF extends IFluidState,\n A extends IFluidReducer<SV, SF, C>,\n B extends IFluidSelector<SV, SF, C>,\n C extends IFluidDataProps\n>(\n props: IFluidReducerProps<SV, SF, A, B, C>,\n initialViewState: SV,\n): [ICombinedState<SV, SF, C>, A, B] {\n const {\n syncedStateId,\n reducer,\n selector,\n syncedDataObject,\n } = props;\n const config = syncedDataObject.getConfig(syncedStateId);\n if (config === undefined) {\n throw Error(`Failed to find configuration for synced state ID: ${syncedStateId}`);\n }\n const dataProps = props.dataProps ?? syncedDataObject.dataProps as C;\n // Get our combined synced state and setState callbacks from the useStateFluid function\n const [viewState, setState] = useStateFluid<SV, SF>({\n syncedStateId,\n syncedDataObject,\n dataProps,\n }, initialViewState);\n const syncedState = syncedDataObject.syncedState;\n const { fluidToView, viewToFluid } = config as ISyncedStateConfig<SV, SF>;\n\n const schemaHandles = getSchema(\n syncedStateId,\n syncedState,\n );\n if (schemaHandles?.storedHandleMapHandle.absolutePath === undefined) {\n throw Error(`Component schema not initialized prior to render for ${syncedStateId}`);\n }\n const storedHandleMap = dataProps.fluidObjectMap.get(\n schemaHandles?.storedHandleMapHandle.absolutePath,\n )?.fluidObject as SharedMap;\n if (storedHandleMap === undefined) {\n throw Error(`Stored handle map not initialized prior to render for ${syncedStateId}`);\n }\n\n // Dispatch is an in-memory object that will load the reducer actions provided by the user\n // and add updates to the view and Fluid state based off of the type of function and\n // state values that were updated. Think of it as prepping the data in the first\n // stage of dynamic programming. The dispatch functions are copies of the user-defined functions\n // but with the updates to synced state also handled\n const dispatch = React.useCallback(\n (\n type: keyof A,\n dispatchState?: ICombinedState<SV, SF, C>,\n ...args: any\n ) => {\n // Retrieve the current state that is stored on the synced state for this Fluid object ID\n const currentFluidState = getFluidState(\n syncedStateId,\n syncedState,\n dataProps.fluidObjectMap,\n fluidToView,\n );\n if (currentFluidState === undefined) {\n throw Error(\n \"Attempted to dispatch function before fluid state was initialized\",\n );\n }\n const combinedDispatchFluidState: SF = {\n ...currentFluidState,\n ...dispatchState?.fluidState,\n };\n const combinedDispatchViewState: SV = {\n ...viewState,\n ...dispatchState?.viewState,\n };\n const combinedDispatchDataProps: C = {\n ...dataProps,\n ...dispatchState?.dataProps,\n };\n const combinedDispatchState = {\n fluidState: combinedDispatchFluidState,\n viewState: combinedDispatchViewState,\n dataProps: combinedDispatchDataProps,\n };\n const action = reducer[type];\n if (action !== undefined) {\n if (instanceOfStateUpdateFunction<SV, SF, C>(action)) {\n // If its a synchronous state update function, call it and inspect the result\n // for new Fluid object handles\n const result = (action.function as any)(\n combinedDispatchState,\n ...args,\n );\n if (result.newComponentHandles !== undefined) {\n // Fetch any new Fluid objects and add a listener to their synced state.\n // Then update the view state.\n const callback = syncedStateCallbackListener(\n combinedDispatchDataProps.fluidObjectMap,\n storedHandleMap,\n syncedStateId,\n syncedState,\n combinedDispatchDataProps.runtime,\n result.state.viewState,\n setState,\n fluidToView,\n viewToFluid,\n );\n // eslint-disable-next-line @typescript-eslint/no-floating-promises\n updateStateAndFluidObjectMap(\n result.newComponentHandles,\n combinedDispatchDataProps.fluidObjectMap,\n storedHandleMap,\n false,\n syncedStateId,\n syncedState,\n combinedDispatchDataProps.runtime,\n result.state.viewState,\n setState,\n callback,\n fluidToView,\n viewToFluid,\n );\n } else {\n // Update the state directly\n syncState(\n false,\n syncedStateId,\n syncedState,\n combinedDispatchDataProps.runtime,\n result.state.viewState,\n setState,\n combinedDispatchDataProps.fluidObjectMap,\n fluidToView,\n viewToFluid,\n );\n }\n } else if (instanceOfAsyncStateUpdateFunction<SV, SF, C>(action)) {\n // In the case of an async function, the function promise is treated as a Thenable\n // and the returned result is inspected after the function has completed\n (action.asyncFunction as any)(\n combinedDispatchState,\n ...args,\n ).then((result: IStateUpdateResult<SV, SF, C>) => {\n const callback = syncedStateCallbackListener(\n combinedDispatchDataProps.fluidObjectMap,\n storedHandleMap,\n syncedStateId,\n syncedState,\n combinedDispatchDataProps.runtime,\n result.state.viewState,\n setState,\n fluidToView,\n viewToFluid,\n );\n if (result.newFluidHandles !== undefined) {\n // eslint-disable-next-line @typescript-eslint/no-floating-promises\n updateStateAndFluidObjectMap(\n result.newFluidHandles,\n combinedDispatchDataProps.fluidObjectMap,\n storedHandleMap,\n false,\n syncedStateId,\n syncedState,\n combinedDispatchDataProps.runtime,\n result.state.viewState,\n setState,\n callback,\n fluidToView,\n viewToFluid,\n );\n } else {\n syncState(\n false,\n syncedStateId,\n syncedState,\n combinedDispatchDataProps.runtime,\n result.state.viewState,\n setState,\n combinedDispatchDataProps.fluidObjectMap,\n fluidToView,\n viewToFluid,\n );\n }\n });\n } else if (instanceOfAsyncEffectFunction<SV, SF, C>(action)) {\n (action.asyncFunction as any)(\n combinedDispatchState,\n ...args,\n ).then(() =>\n syncState(\n false,\n syncedStateId,\n syncedState,\n combinedDispatchDataProps.runtime,\n combinedDispatchState.viewState,\n setState,\n combinedDispatchDataProps.fluidObjectMap,\n fluidToView,\n viewToFluid,\n ),\n );\n } else if (instanceOfEffectFunction<SV, SF, C>(action)) {\n (action.function as any)(combinedDispatchState, ...args);\n syncState(\n false,\n syncedStateId,\n syncedState,\n combinedDispatchDataProps.runtime,\n combinedDispatchState.viewState,\n setState,\n combinedDispatchDataProps.fluidObjectMap,\n fluidToView,\n viewToFluid,\n );\n } else {\n throw new Error(\n `Action with key ${action} does not match an expected reducer action interface`,\n );\n }\n } else {\n throw new Error(\n `Action with key ${action} does not\n exist in the reducers provided`,\n );\n }\n },\n [reducer, viewState, setState, dataProps],\n );\n\n // The combinedReducer is then created using the dispatch functions we created above.\n // This allows us to preserve the reducer interface while injecting Fluid-specific logic\n // into the updating of the state. This is the second phase of DP, using the earlier created\n // in-memory object to access the function the user is trying to use in constant time and then,\n // subsequently performing it, taking the updated state, and applying it both locally and remotely\n const combinedReducer = {};\n Object.entries(reducer).forEach(([functionName, functionItem], i) => {\n if ((functionItem as any).asyncFunction !== undefined) {\n combinedReducer[functionName] = {\n asyncFunction: (\n dispatchState: ICombinedState<SV, SF, C>,\n ...args: any\n ) => dispatch(functionName, dispatchState, ...args),\n };\n } else {\n combinedReducer[functionName] = {\n function: (\n dispatchState: ICombinedState<SV, SF, C>,\n ...args: any\n ) => dispatch(functionName, dispatchState, ...args),\n };\n }\n });\n\n // Fetch is an in-memory object similar to dispatch, but now made for selector actions.\n // Selectors are NOT used for updating the state but instead to be able to access\n // and add other Fluid Fluid objects using the handle provided. If the handle provided is not available\n // in our Fluid object map, it will be dynamically updated and setState will be called again\n // with the updated Fluid object map available for use.\n // Alternatively, if you would like to pre-load Fluid objects before React is initialized,\n // you can do so and provide them in dataProps.\n // Fetch can also be used to retrieve data from these Fluid objects as they will also be available as a parameter.\n const fetch = React.useCallback(\n (\n type: keyof B,\n fetchState?: ICombinedState<SV, SF, C>,\n handle?: IFluidHandle,\n ) => {\n // Retrieve the current state that is stored on the syncedState for this Fluid object ID\n const currentFluidState = getFluidState(\n syncedStateId,\n syncedState,\n dataProps.fluidObjectMap,\n fluidToView,\n );\n if (currentFluidState === undefined) {\n throw Error(\n \"Attempted to dispatch function before fluid state was initialized\",\n );\n }\n const combinedFetchFluidState: SF = {\n ...currentFluidState,\n ...fetchState?.fluidState,\n };\n const combinedFetchViewState: SV = {\n ...viewState,\n ...fetchState?.viewState,\n };\n const combinedFetchDataProps: C = {\n ...dataProps,\n ...fetchState?.dataProps,\n };\n const combinedFetchState = {\n fluidState: combinedFetchFluidState,\n viewState: combinedFetchViewState,\n dataProps: combinedFetchDataProps,\n };\n const action = selector[type];\n if (action !== undefined) {\n if (instanceOfSelectorFunction<SV, SF, C>(action)) {\n // Add any new handles that were returned by the selector to our list\n // to be loaded to the fluid Fluid object map\n let newHandles: IFluidHandle[] = [];\n if (\n handle !== undefined &&\n instanceOfFluidObjectSelectorFunction<SV, SF, C>(action) &&\n combinedFetchDataProps.fluidObjectMap.get(\n handle.absolutePath,\n ) === undefined\n ) {\n newHandles.push(handle);\n }\n const actionResult = (action.function as any)(\n combinedFetchState,\n handle,\n );\n if (\n actionResult !== undefined &&\n actionResult.newComponentHandles !== undefined\n ) {\n newHandles = newHandles.concat(\n actionResult.newComponentHandles,\n );\n }\n // If there are handles, start a call to update the Fluid object map and then call the set state\n // callback when it has finished to provide the updated map in the state\n if (newHandles.length > 0) {\n const callback = syncedStateCallbackListener(\n combinedFetchDataProps.fluidObjectMap,\n storedHandleMap,\n syncedStateId,\n syncedState,\n combinedFetchDataProps.runtime,\n combinedFetchState.viewState,\n setState,\n fluidToView,\n viewToFluid,\n );\n // eslint-disable-next-line @typescript-eslint/no-floating-promises\n updateStateAndFluidObjectMap(\n newHandles,\n combinedFetchDataProps.fluidObjectMap,\n storedHandleMap,\n true,\n syncedStateId,\n syncedState,\n combinedFetchDataProps.runtime,\n combinedFetchState.viewState,\n setState,\n callback,\n fluidToView,\n viewToFluid,\n );\n }\n // Always return the result immediately\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return actionResult;\n } else {\n throw new Error(\n `Action with key ${action} does not match an expected selector action interface`,\n );\n }\n } else {\n throw new Error(\n `Action with key ${action} does not\n exist in the selectors provided`,\n );\n }\n },\n [selector, viewState, setState, dataProps],\n );\n\n // The combined selector is then similarly created with the Fluid-specific logic of adding any new Fluid objects\n // to our Fluid object map interjected into the setState logic\n const combinedSelector = {};\n Object.entries(selector).forEach(([functionName, functionItem], i) => {\n combinedSelector[functionName] = {\n function: (\n fetchState: ICombinedState<SV, SF, C>,\n handle?: IFluidHandle,\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n ) => fetch(functionName, fetchState, handle),\n };\n });\n\n // Retrieve the current state that is stored on the syncedState for this Fluid object ID\n const fluidState = getFluidState(\n syncedStateId,\n syncedState,\n dataProps.fluidObjectMap,\n fluidToView,\n );\n\n return [\n {\n viewState,\n fluidState,\n dataProps,\n },\n combinedReducer as A,\n combinedSelector as B,\n ];\n}\n"]}
@@ -1,44 +0,0 @@
1
- /*!
2
- * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
- * Licensed under the MIT License.
4
- */
5
- import * as React from "react";
6
- import { initializeState, syncState } from "./helpers";
7
- /**
8
- * A wrapper around the useState React hook that combines local and Fluid state updates
9
- */
10
- export function useStateFluid(props, initialViewState) {
11
- var _a;
12
- const { syncedStateId, syncedDataObject, } = props;
13
- const config = syncedDataObject.getConfig(syncedStateId);
14
- if (config === undefined) {
15
- throw Error(`Failed to find configuration for synced state ID: ${syncedStateId}`);
16
- }
17
- const syncedState = syncedDataObject.syncedState;
18
- const dataProps = (_a = props.dataProps) !== null && _a !== void 0 ? _a : syncedDataObject.dataProps;
19
- const { fluidToView, viewToFluid } = config;
20
- // Establish the react state and setState functions using the initialViewState passed in
21
- const [reactState, reactSetState] = React.useState(initialViewState);
22
- // If this is the first time this function is being called in this session
23
- // It's okay to disable eslint here as the state will be updated with the initialized values
24
- // after the async call has finished
25
- // eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
26
- if (!reactState.isInitialized) {
27
- // eslint-disable-next-line @typescript-eslint/no-floating-promises
28
- initializeState(syncedStateId, syncedState, dataProps, reactState, reactSetState, fluidToView, viewToFluid);
29
- }
30
- // Create the fluidSetState function as a callback that in turn calls either our combined state
31
- // update to both the local and Fluid state or just the local state respectively based off of
32
- // if the state update is coming locally, i.e. not from the root
33
- const fluidSetState = React.useCallback((newState, fromRootUpdate = false, isLocal = false) => {
34
- const newCombinedState = Object.assign(Object.assign(Object.assign({}, reactState), newState), { isInitialized: true });
35
- if (isLocal) {
36
- reactSetState(newCombinedState);
37
- }
38
- else {
39
- syncState(fromRootUpdate, syncedStateId, syncedState, dataProps.runtime, newCombinedState, reactSetState, dataProps.fluidObjectMap, fluidToView, viewToFluid);
40
- }
41
- }, [syncedState, viewToFluid, reactState, reactSetState, dataProps]);
42
- return [reactState, fluidSetState];
43
- }
44
- //# sourceMappingURL=useStateFluid.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useStateFluid.js","sourceRoot":"","sources":["../src/useStateFluid.tsx"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAO/B,OAAO,EAAE,eAAe,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAEvD;;GAEG;AACH,MAAM,UAAU,aAAa,CAIzB,KAA0B,EAAE,gBAAoB;;IAEhD,MAAM,EACF,aAAa,EACb,gBAAgB,GACnB,GAAG,KAAK,CAAC;IACV,MAAM,MAAM,GAAG,gBAAgB,CAAC,SAAS,CAAC,aAAa,CAAC,CAAC;IACzD,IAAI,MAAM,KAAK,SAAS,EAAE;QACtB,MAAM,KAAK,CAAC,qDAAqD,aAAa,EAAE,CAAC,CAAC;KACrF;IACD,MAAM,WAAW,GAAG,gBAAgB,CAAC,WAAW,CAAC;IACjD,MAAM,SAAS,SAAG,KAAK,CAAC,SAAS,mCAAI,gBAAgB,CAAC,SAAS,CAAC;IAChE,MAAM,EAAE,WAAW,EAAE,WAAW,EAAE,GAAG,MAAoC,CAAC;IAC1E,wFAAwF;IACxF,MAAM,CAAC,UAAU,EAAE,aAAa,CAAC,GAAG,KAAK,CAAC,QAAQ,CAAK,gBAAgB,CAAC,CAAC;IAEzE,0EAA0E;IAC1E,4FAA4F;IAC5F,oCAAoC;IACpC,yEAAyE;IACzE,IAAI,CAAC,UAAU,CAAC,aAAa,EAAE;QAC3B,mEAAmE;QACnE,eAAe,CACX,aAAa,EACb,WAAW,EACX,SAAS,EACT,UAAU,EACV,aAAa,EACb,WAAW,EACX,WAAW,CACd,CAAC;KACL;IAED,+FAA+F;IAC/F,6FAA6F;IAC7F,gEAAgE;IAChE,MAAM,aAAa,GAAG,KAAK,CAAC,WAAW,CACnC,CAAC,QAAqB,EAAE,cAAc,GAAG,KAAK,EAAE,UAAmB,KAAK,EAAE,EAAE;QACxE,MAAM,gBAAgB,iDACf,UAAU,GACV,QAAQ,KACX,aAAa,EAAE,IAAI,GACtB,CAAC;QACF,IAAI,OAAO,EAAE;YACT,aAAa,CAAC,gBAAgB,CAAC,CAAC;SACnC;aAAM;YACH,SAAS,CACL,cAAc,EACd,aAAa,EACb,WAAW,EACX,SAAS,CAAC,OAAO,EACjB,gBAAgB,EAChB,aAAa,EACb,SAAS,CAAC,cAAc,EACxB,WAAW,EACX,WAAW,CACd,CAAC;SACL;IACL,CAAC,EACD,CAAC,WAAW,EAAE,WAAW,EAAE,UAAU,EAAE,aAAa,EAAE,SAAS,CAAC,CACnE,CAAC;IACF,OAAO,CAAC,UAAU,EAAE,aAAa,CAAC,CAAC;AACvC,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport * as React from \"react\";\nimport {\n IViewState,\n IFluidProps,\n IFluidState,\n ISyncedStateConfig,\n} from \"./interface\";\nimport { initializeState, syncState } from \"./helpers\";\n\n/**\n * A wrapper around the useState React hook that combines local and Fluid state updates\n */\nexport function useStateFluid<\n SV extends IViewState,\n SF extends IFluidState\n>(\n props: IFluidProps<SV, SF>, initialViewState: SV,\n): [SV, (newState: SV, isSyncedStateUpdate?: boolean) => void] {\n const {\n syncedStateId,\n syncedDataObject,\n } = props;\n const config = syncedDataObject.getConfig(syncedStateId);\n if (config === undefined) {\n throw Error(`Failed to find configuration for synced state ID: ${syncedStateId}`);\n }\n const syncedState = syncedDataObject.syncedState;\n const dataProps = props.dataProps ?? syncedDataObject.dataProps;\n const { fluidToView, viewToFluid } = config as ISyncedStateConfig<SV, SF>;\n // Establish the react state and setState functions using the initialViewState passed in\n const [reactState, reactSetState] = React.useState<SV>(initialViewState);\n\n // If this is the first time this function is being called in this session\n // It's okay to disable eslint here as the state will be updated with the initialized values\n // after the async call has finished\n // eslint-disable-next-line @typescript-eslint/strict-boolean-expressions\n if (!reactState.isInitialized) {\n // eslint-disable-next-line @typescript-eslint/no-floating-promises\n initializeState<SV, SF>(\n syncedStateId,\n syncedState,\n dataProps,\n reactState,\n reactSetState,\n fluidToView,\n viewToFluid,\n );\n }\n\n // Create the fluidSetState function as a callback that in turn calls either our combined state\n // update to both the local and Fluid state or just the local state respectively based off of\n // if the state update is coming locally, i.e. not from the root\n const fluidSetState = React.useCallback(\n (newState: Partial<SV>, fromRootUpdate = false, isLocal: boolean = false) => {\n const newCombinedState = {\n ...reactState,\n ...newState,\n isInitialized: true,\n };\n if (isLocal) {\n reactSetState(newCombinedState);\n } else {\n syncState(\n fromRootUpdate,\n syncedStateId,\n syncedState,\n dataProps.runtime,\n newCombinedState,\n reactSetState,\n dataProps.fluidObjectMap,\n fluidToView,\n viewToFluid,\n );\n }\n },\n [syncedState, viewToFluid, reactState, reactSetState, dataProps],\n );\n return [reactState, fluidSetState];\n}\n"]}
@@ -1,33 +0,0 @@
1
- /*!
2
- * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
- * Licensed under the MIT License.
4
- */
5
-
6
- import * as React from "react";
7
- import {
8
- IViewState,
9
- IFluidContextProps,
10
- FluidContext,
11
- IFluidState,
12
- } from "./interface";
13
- import { useStateFluid } from "./useStateFluid";
14
-
15
- export function createContextFluid<
16
- SV extends IViewState,
17
- SF extends IFluidState,
18
- C
19
- >(props: IFluidContextProps<SV, SF, C>, initialViewState: SV): FluidContext<SV, C> {
20
- const [state, setState] = useStateFluid(props, initialViewState);
21
- const PrimedFluidContext = React.createContext({
22
- state,
23
- setState,
24
- reactContext: props.reactContext ?? {},
25
- });
26
- return {
27
- Provider: PrimedFluidContext.Provider,
28
- Consumer: PrimedFluidContext.Consumer,
29
- usePrimedContext: () => React.useContext(PrimedFluidContext),
30
- state,
31
- setState,
32
- };
33
- }
@@ -1,95 +0,0 @@
1
- /*!
2
- * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
- * Licensed under the MIT License.
4
- */
5
-
6
- import { IFluidDataStoreRuntime } from "@fluidframework/datastore-definitions";
7
- import { SharedMap } from "@fluidframework/map";
8
- import {
9
- IFluidState,
10
- IViewState,
11
- ViewToFluidMap,
12
- FluidToViewMap,
13
- IFluidSchema,
14
- } from "../interface";
15
-
16
- /**
17
- * Identifies which values within the Fluid and view states match
18
- * The view and Fluid matching map identify if the value in the respective states
19
- * needs a converter or not
20
- * @param runtime - The data store runtime used to create the SharedMap objects
21
- * @param fluidToView - The Fluid to view state conversion mapping
22
- * @param viewToFluid - The view to Fluid conversion state mapping
23
- * */
24
- export function generateFluidObjectSchema<
25
- SV extends IViewState,
26
- SF extends IFluidState
27
- >(
28
- runtime: IFluidDataStoreRuntime,
29
- defaultViewState: SV,
30
- fluidToView: FluidToViewMap<SV, SF>,
31
- viewToFluid?: ViewToFluidMap<SV, SF>,
32
- ): IFluidSchema {
33
- // matching primitives w/ the same key in view and fluid
34
- // true if needs converter or is a Fluid object, false if not
35
- const viewMatchingMap = SharedMap.create(runtime);
36
- const fluidMatchingMap = SharedMap.create(runtime);
37
- const storedHandleMap = SharedMap.create(runtime);
38
- for (const fluidStateKey of fluidToView.keys()) {
39
- const value = fluidToView.get(fluidStateKey);
40
- if (value === undefined) {
41
- throw Error("Cannot find fluidToView value");
42
- }
43
- const {
44
- type,
45
- viewKey,
46
- viewConverter,
47
- } = value;
48
- const fluidConverter = viewToFluid?.get(viewKey);
49
- if (fluidConverter === undefined) {
50
- if (
51
- defaultViewState[viewKey] !== undefined
52
- && typeof (defaultViewState[viewKey]) !== type
53
- && type !== "any"
54
- ) {
55
- throw Error(`Failed to find Fluid converter for key ${viewKey}`);
56
- } else {
57
- continue;
58
- }
59
- }
60
- if (type === fluidConverter.type) {
61
- fluidMatchingMap.set(fluidStateKey as string, false);
62
- } else if (viewConverter !== undefined) {
63
- fluidMatchingMap.set(fluidStateKey as string, true);
64
- } else {
65
- throw Error(`Failed to find view converter for Fluid key ${fluidStateKey}`);
66
- }
67
- }
68
-
69
- if (viewToFluid !== undefined) {
70
- for (const viewStateKey of viewToFluid.keys()) {
71
- const value = viewToFluid.get(viewStateKey);
72
- if (value === undefined) {
73
- throw Error("Cannot find viewToFluid value");
74
- }
75
- const {
76
- type,
77
- fluidKey,
78
- fluidConverter,
79
- } = value;
80
- const viewConverter = fluidToView.get(fluidKey);
81
- if (viewConverter === undefined) {
82
- throw Error(`Failed to find view converter for key ${fluidKey}`);
83
- }
84
- if (type === viewConverter.type) {
85
- viewMatchingMap.set(viewStateKey as string, false);
86
- } else if (fluidConverter !== undefined) {
87
- viewMatchingMap.set(viewStateKey as string, true);
88
- } else {
89
- throw Error(`Failed to find Fluid converter for view key ${viewStateKey}`);
90
- }
91
- }
92
- }
93
-
94
- return { viewMatchingMap, fluidMatchingMap, storedHandleMap };
95
- }
@@ -1,38 +0,0 @@
1
- /*!
2
- * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
- * Licensed under the MIT License.
4
- */
5
-
6
- import {
7
- IFluidConverter,
8
- IViewState,
9
- IFluidState,
10
- } from "../interface";
11
-
12
- /**
13
- * Return a partial Fluid state containing the view state key identified converted into its
14
- * corresponding Fluid state value in the partial Fluid state returned
15
- * @param state - The current view state
16
- * @param viewKey - The view state key that needs to converted to its Fluid state
17
- * @param viewToFluid - A map of the view state values that need conversion to their Fluid state counterparts and the
18
- * respective converters
19
- */
20
- export function getFluidFromView<
21
- SV extends IViewState,
22
- SF extends IFluidState
23
- >(
24
- state: SV,
25
- viewKey: keyof SV,
26
- fluidState: SF,
27
- viewToFluid?: Map<keyof SV, IFluidConverter<SV, SF>>,
28
- ): Partial<SF> {
29
- const fluidConverter = viewToFluid?.get(viewKey)?.fluidConverter;
30
- if (fluidConverter !== undefined) {
31
- // eslint-disable-next-line @typescript-eslint/no-unsafe-return
32
- return fluidConverter(state, fluidState);
33
- } else {
34
- const partialFluidState: Partial<SF> = {};
35
- partialFluidState[viewKey as string] = state[viewKey];
36
- return partialFluidState;
37
- }
38
- }
@@ -1,67 +0,0 @@
1
- /*!
2
- * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
- * Licensed under the MIT License.
4
- */
5
-
6
- import {
7
- IFluidObject,
8
- IFluidHandle,
9
- } from "@fluidframework/core-interfaces";
10
- import { ISharedMap, SharedMap } from "@fluidframework/map";
11
- import {
12
- IViewConverter,
13
- FluidObjectMap,
14
- IViewState,
15
- IFluidState,
16
- ISyncedState,
17
- IFluidObjectMapItem,
18
- } from "..";
19
-
20
- /**
21
- * Return the Fluid state from the syncedState with all handles converted into Fluid objects
22
- * @param syncedStateId - Unique ID for the synced state of this view
23
- * @param syncedState - Shared map the synced state is stored on
24
- * @param fluidObjectMap - Map of Fluid handle paths to their respective Fluid objects
25
- * @param fluidToView - Map of the Fluid state keys contains the optional syncedState key parameter,
26
- * in case the Fluid value is stored in the syncedState under a different key
27
- */
28
- export function getFluidState<
29
- SV extends IViewState,
30
- SF extends IFluidState
31
- >(
32
- syncedStateId: string,
33
- syncedState: ISyncedState,
34
- fluidObjectMap: FluidObjectMap,
35
- fluidToView?: Map<keyof SF, IViewConverter<SV, SF>>,
36
- ): SF | undefined {
37
- const fluidObjectStateHandle = syncedState.get<IFluidHandle<ISharedMap>>(
38
- `syncedState-${syncedStateId}`,
39
- );
40
- if (fluidObjectStateHandle === undefined) {
41
- return;
42
- }
43
- const fluidObjectState = fluidObjectMap.get(fluidObjectStateHandle.absolutePath)
44
- ?.fluidObject as SharedMap;
45
- if (fluidObjectState === undefined) {
46
- return;
47
- }
48
- const fluidState = {};
49
- for (const fluidKey of fluidObjectState.keys()) {
50
- const createCallback = fluidToView?.get(fluidKey as keyof SF)
51
- ?.sharedObjectCreate;
52
- let value = fluidObjectState.get(fluidKey);
53
- if (value !== undefined && createCallback !== undefined) {
54
- const possibleFluidObjectId = (value as IFluidObject)
55
- ?.IFluidHandle?.absolutePath;
56
- if (possibleFluidObjectId !== undefined) {
57
- value = (fluidObjectMap.get(possibleFluidObjectId)) as IFluidObjectMapItem;
58
- fluidState[fluidKey] = value?.fluidObject;
59
- } else {
60
- fluidState[fluidKey] = value;
61
- }
62
- } else {
63
- fluidState[fluidKey] = value;
64
- }
65
- }
66
- return fluidState as SF;
67
- }
@@ -1,18 +0,0 @@
1
- /*!
2
- * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
- * Licensed under the MIT License.
4
- */
5
-
6
- import { ISyncedState } from "../interface";
7
- import { IFluidSchemaHandles } from "./internalInterface";
8
-
9
- /**
10
- * Returns the schema stored on the synced state for this Fluid object
11
- * @param syncedStateId - Unique ID for this synced data object's state
12
- * @param syncedState - The shared map this Fluid shared state is stored on
13
- */
14
- export const getSchema = (
15
- syncedStateId: string,
16
- syncedState: ISyncedState,
17
- ): IFluidSchemaHandles | undefined =>
18
- syncedState.get<IFluidSchemaHandles>(`schema-${syncedStateId}`);
@@ -1,68 +0,0 @@
1
- /*!
2
- * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
- * Licensed under the MIT License.
4
- */
5
-
6
- import { IFluidObject } from "@fluidframework/core-interfaces";
7
- import {
8
- FluidObjectMap,
9
- IViewConverter,
10
- IViewState,
11
- IFluidState,
12
- ISyncedState,
13
- } from "../interface";
14
- import { getFluidState } from "./getFluidState";
15
-
16
- /**
17
- * Return a partial view state containing the Fluid state key identified converted into its
18
- * corresponding view state value in the partial view state returned
19
- * @param syncedStateId - Unique ID for the synced state of this view
20
- * @param syncedState - The shared map this shared state is stored on
21
- * @param fluidKey - The key of the value within the Fluid state that we want converted
22
- * @param fluidObjectMap - A map of Fluid handle paths to their Fluid objects
23
- * @param fluidToView - A map of the Fluid state values that need conversion to their view state counterparts and the
24
- * respective converters
25
- * @param combinedFluidState - Optional param containing the combined Fluid state so far to fetch from
26
- */
27
- export function getViewFromFluid<
28
- SV extends IViewState,
29
- SF extends IFluidState
30
- >(
31
- syncedStateId: string,
32
- syncedState: ISyncedState,
33
- fluidKey: keyof SF,
34
- fluidObjectMap: FluidObjectMap,
35
- fluidToView: Map<keyof SF, IViewConverter<SV, SF>>,
36
- viewState: SV,
37
- combinedFluidState?: Partial<SF>,
38
- ): Partial<SV> {
39
- const fluidObjectState = getFluidState(
40
- syncedStateId,
41
- syncedState,
42
- fluidObjectMap,
43
- fluidToView,
44
- );
45
- if (fluidObjectState === undefined) {
46
- throw Error(
47
- "Attempted to fetch view from Fluid state before it was initialized",
48
- );
49
- }
50
- let value = fluidObjectState[fluidKey];
51
- if (combinedFluidState !== undefined) {
52
- value = combinedFluidState[fluidKey] ?? value;
53
- }
54
- const viewConverter = fluidToView.get(fluidKey)?.viewConverter;
55
- if (viewConverter !== undefined) {
56
- const partialFluidState: Partial<SF> = {};
57
- partialFluidState[fluidKey] = value;
58
- return viewConverter(viewState, partialFluidState, fluidObjectMap);
59
- } else {
60
- const partialViewState: Partial<SV> = {};
61
- const valueAsIFluidHandle = (value as IFluidObject).IFluidHandle;
62
- const convertedValue = valueAsIFluidHandle !== undefined
63
- ? fluidObjectMap.get(valueAsIFluidHandle.absolutePath)
64
- : value;
65
- partialViewState[fluidKey as string] = convertedValue;
66
- return partialViewState;
67
- }
68
- }
@@ -1,16 +0,0 @@
1
- /*!
2
- * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
- * Licensed under the MIT License.
4
- */
5
-
6
- export * from "./getFluidFromView";
7
- export * from "./getViewFromFluid";
8
- export * from "./rootCallbackListener";
9
- export * from "./syncState";
10
- export * from "./updateStateAndFluidObjectMap";
11
- export * from "./generateFluidObjectSchema";
12
- export * from "./getFluidState";
13
- export * from "./setFluidState";
14
- export * from "./getSchema";
15
- export * from "./setComponentSchema";
16
- export * from "./initializeState";
@@ -1,162 +0,0 @@
1
- /*!
2
- * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
- * Licensed under the MIT License.
4
- */
5
-
6
- import { IFluidHandle } from "@fluidframework/core-interfaces";
7
- import {
8
- IValueChanged,
9
- SharedMap,
10
- } from "@fluidframework/map";
11
- import {
12
- IFluidDataProps,
13
- FluidToViewMap,
14
- ViewToFluidMap,
15
- IViewState,
16
- IFluidState,
17
- ISyncedState,
18
- } from "../interface";
19
- import {
20
- syncedStateCallbackListener,
21
- updateStateAndFluidObjectMap,
22
- getSchema,
23
- getFluidState,
24
- } from ".";
25
-
26
- /**
27
- * Fetch the synced state for this view from the SyncedDataObject sharedState and add
28
- * listeners for all state updates
29
- * @param syncedStateId - Unique ID for this synced data object's state
30
- * @param syncedState - The synced data object's shared state map
31
- * @param fluidToView - A map of the Fluid state values that need conversion to their view state counterparts and the
32
- * respective converters
33
- * @param dataProps - Contains the runtime and fluidObjectMap to create and store DDSes
34
- * @param state - Current view state
35
- * @param setState - Callback to update view state
36
- * @param viewToFluid - A map of the view state values that need conversion to their Fluid state counterparts and the
37
- * respective converters
38
- * @param fluidToView - A map of the Fluid state values that need conversion to their view state counterparts and the
39
- * respective converters
40
- */
41
- export async function initializeState<
42
- SV extends IViewState,
43
- SF extends IFluidState
44
- >(
45
- syncedStateId: string,
46
- syncedState: ISyncedState,
47
- dataProps: IFluidDataProps,
48
- state: SV,
49
- setState: (
50
- newState: SV,
51
- fromRootUpdate?: boolean,
52
- isLocal?: boolean
53
- ) => void,
54
- fluidToView: FluidToViewMap<SV, SF>,
55
- viewToFluid?: ViewToFluidMap<SV, SF>,
56
- ): Promise<void> {
57
- const schemaHandles = getSchema(
58
- syncedStateId,
59
- syncedState,
60
- );
61
- if (schemaHandles?.storedHandleMapHandle.absolutePath === undefined) {
62
- throw Error(`Schema not initialized prior to render for ${syncedStateId}`);
63
- }
64
- const storedHandleMap = dataProps.fluidObjectMap.get(
65
- schemaHandles?.storedHandleMapHandle.absolutePath,
66
- )?.fluidObject as SharedMap;
67
- if (storedHandleMap === undefined) {
68
- throw Error(`Stored handle map not initialized prior to render for ${syncedStateId}`);
69
- }
70
- const unlistenedHandles: IFluidHandle[] = [];
71
- for (const handle of storedHandleMap.values()) {
72
- unlistenedHandles.push(handle);
73
- }
74
-
75
- const currentFluidState = getFluidState(
76
- syncedStateId,
77
- syncedState,
78
- dataProps.fluidObjectMap,
79
- fluidToView,
80
- );
81
- if (currentFluidState === undefined) {
82
- throw Error("Synced state update triggered before Fluid state was initialized");
83
- }
84
-
85
- for (const fluidStateKey of fluidToView.keys()) {
86
- const value = fluidToView.get(fluidStateKey);
87
- if (value === undefined) {
88
- throw Error("Cannot find fluidToView value");
89
- }
90
- if (value.sharedObjectCreate !== undefined) {
91
- const fluidObject = currentFluidState[fluidStateKey] as any;
92
- unlistenedHandles.push(fluidObject.handle);
93
- }
94
- }
95
-
96
- state.isInitialized = true;
97
- state.syncedStateId = syncedStateId;
98
- // Define the synced state callback listener that will be responsible for triggering state updates on synced state
99
- // value changes
100
- const syncedStateCallback = (
101
- change: IValueChanged,
102
- local: boolean,
103
- ) => {
104
- const callback = syncedStateCallbackListener(
105
- dataProps.fluidObjectMap,
106
- storedHandleMap,
107
- syncedStateId,
108
- syncedState,
109
- dataProps.runtime,
110
- state,
111
- setState,
112
- fluidToView,
113
- viewToFluid,
114
- );
115
- return callback(change, local);
116
- };
117
-
118
- // Add the callback to the fluidObject's own synced state
119
- syncedState.addValueChangedListener(syncedStateCallback);
120
- storedHandleMap.on("valueChanged", (
121
- change: IValueChanged,
122
- local: boolean,
123
- ) => {
124
- const handle = storedHandleMap.get<IFluidHandle>(change.key);
125
- // eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
126
- if (handle !== undefined && !state.fluidObjectMap?.has(handle.absolutePath)) {
127
- state.fluidObjectMap?.set(handle.absolutePath, {
128
- isListened: false,
129
- });
130
- // eslint-disable-next-line @typescript-eslint/no-floating-promises
131
- updateStateAndFluidObjectMap<SV, SF>(
132
- [handle],
133
- dataProps.fluidObjectMap,
134
- storedHandleMap,
135
- true,
136
- syncedStateId,
137
- syncedState,
138
- dataProps.runtime,
139
- state,
140
- setState,
141
- syncedStateCallback,
142
- fluidToView,
143
- viewToFluid,
144
- );
145
- }
146
- });
147
-
148
- return updateStateAndFluidObjectMap<SV, SF>(
149
- unlistenedHandles,
150
- dataProps.fluidObjectMap,
151
- storedHandleMap,
152
- true,
153
- syncedStateId,
154
- syncedState,
155
- dataProps.runtime,
156
- state,
157
- setState,
158
- syncedStateCallback,
159
- fluidToView,
160
- viewToFluid,
161
- );
162
- }
@@ -1,16 +0,0 @@
1
- /*!
2
- * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
- * Licensed under the MIT License.
4
- */
5
-
6
- import { IFluidHandle } from "@fluidframework/core-interfaces";
7
- import { ISharedMap } from "@fluidframework/map";
8
-
9
- /**
10
- * The respective handles for the Fluid schema params listed above
11
- */
12
- export interface IFluidSchemaHandles {
13
- viewMatchingMapHandle: IFluidHandle<ISharedMap>;
14
- fluidMatchingMapHandle: IFluidHandle<ISharedMap>;
15
- storedHandleMapHandle: IFluidHandle<ISharedMap>;
16
- }