@microsoft/live-share-react 2.0.0-internal.1 → 2.0.0-internal.11

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 (313) hide show
  1. package/LICENSE +64 -61
  2. package/README.md +169 -164
  3. package/bin/cjs/index.d.ts +7 -0
  4. package/bin/cjs/index.d.ts.map +1 -0
  5. package/bin/cjs/index.js +23 -0
  6. package/bin/cjs/index.js.map +1 -0
  7. package/bin/cjs/interfaces/LiveInterfaceExtensions.d.ts +26 -0
  8. package/bin/cjs/interfaces/LiveInterfaceExtensions.d.ts.map +1 -0
  9. package/bin/cjs/interfaces/LiveInterfaceExtensions.js +7 -0
  10. package/bin/cjs/interfaces/LiveInterfaceExtensions.js.map +1 -0
  11. package/bin/cjs/interfaces/index.d.ts +2 -0
  12. package/bin/cjs/interfaces/index.d.ts.map +1 -0
  13. package/bin/cjs/interfaces/index.js +18 -0
  14. package/bin/cjs/interfaces/index.js.map +1 -0
  15. package/bin/cjs/internal/errors.d.ts +41 -0
  16. package/bin/cjs/internal/errors.d.ts.map +1 -0
  17. package/bin/cjs/internal/errors.js +48 -0
  18. package/bin/cjs/internal/errors.js.map +1 -0
  19. package/bin/cjs/internal/index.d.ts +3 -0
  20. package/bin/cjs/internal/index.d.ts.map +1 -0
  21. package/bin/cjs/internal/index.js +19 -0
  22. package/bin/cjs/internal/index.js.map +1 -0
  23. package/bin/cjs/internal/type-guards.d.ts +11 -0
  24. package/bin/cjs/internal/type-guards.d.ts.map +1 -0
  25. package/bin/cjs/internal/type-guards.js +24 -0
  26. package/bin/cjs/internal/type-guards.js.map +1 -0
  27. package/bin/cjs/live-hooks/index.d.ts +8 -0
  28. package/bin/cjs/live-hooks/index.d.ts.map +1 -0
  29. package/bin/cjs/live-hooks/index.js +24 -0
  30. package/bin/cjs/live-hooks/index.js.map +1 -0
  31. package/bin/cjs/live-hooks/useLiveCanvas.d.ts +80 -0
  32. package/bin/cjs/live-hooks/useLiveCanvas.d.ts.map +1 -0
  33. package/bin/cjs/live-hooks/useLiveCanvas.js +244 -0
  34. package/bin/cjs/live-hooks/useLiveCanvas.js.map +1 -0
  35. package/bin/cjs/live-hooks/useLiveEvent.d.ts +59 -0
  36. package/bin/cjs/live-hooks/useLiveEvent.d.ts.map +1 -0
  37. package/bin/cjs/live-hooks/useLiveEvent.js +150 -0
  38. package/bin/cjs/live-hooks/useLiveEvent.js.map +1 -0
  39. package/bin/cjs/live-hooks/useLiveFollowMode.d.ts +163 -0
  40. package/bin/cjs/live-hooks/useLiveFollowMode.d.ts.map +1 -0
  41. package/bin/cjs/live-hooks/useLiveFollowMode.js +360 -0
  42. package/bin/cjs/live-hooks/useLiveFollowMode.js.map +1 -0
  43. package/bin/cjs/live-hooks/useLivePresence.d.ts +76 -0
  44. package/bin/cjs/live-hooks/useLivePresence.d.ts.map +1 -0
  45. package/bin/cjs/live-hooks/useLivePresence.js +170 -0
  46. package/bin/cjs/live-hooks/useLivePresence.js.map +1 -0
  47. package/bin/cjs/live-hooks/useLiveState.d.ts +66 -0
  48. package/bin/cjs/live-hooks/useLiveState.d.ts.map +1 -0
  49. package/bin/cjs/live-hooks/useLiveState.js +134 -0
  50. package/bin/cjs/live-hooks/useLiveState.js.map +1 -0
  51. package/bin/cjs/live-hooks/useLiveTimer.d.ts +80 -0
  52. package/bin/cjs/live-hooks/useLiveTimer.d.ts.map +1 -0
  53. package/bin/cjs/live-hooks/useLiveTimer.js +233 -0
  54. package/bin/cjs/live-hooks/useLiveTimer.js.map +1 -0
  55. package/bin/cjs/live-hooks/useMediaSynchronizer.d.ts +86 -0
  56. package/bin/cjs/live-hooks/useMediaSynchronizer.d.ts.map +1 -0
  57. package/bin/cjs/live-hooks/useMediaSynchronizer.js +301 -0
  58. package/bin/cjs/live-hooks/useMediaSynchronizer.js.map +1 -0
  59. package/bin/cjs/package.json +1 -0
  60. package/bin/cjs/providers/AzureProvider.d.ts +113 -0
  61. package/bin/cjs/providers/AzureProvider.d.ts.map +1 -0
  62. package/bin/cjs/providers/AzureProvider.js +127 -0
  63. package/bin/cjs/providers/AzureProvider.js.map +1 -0
  64. package/bin/cjs/providers/LiveShareProvider.d.ts +193 -0
  65. package/bin/cjs/providers/LiveShareProvider.d.ts.map +1 -0
  66. package/bin/cjs/providers/LiveShareProvider.js +205 -0
  67. package/bin/cjs/providers/LiveShareProvider.js.map +1 -0
  68. package/bin/cjs/providers/index.d.ts +3 -0
  69. package/bin/cjs/providers/index.d.ts.map +1 -0
  70. package/bin/cjs/providers/index.js +19 -0
  71. package/bin/cjs/providers/index.js.map +1 -0
  72. package/bin/cjs/shared-hooks/index.d.ts +7 -0
  73. package/bin/cjs/shared-hooks/index.d.ts.map +1 -0
  74. package/bin/cjs/shared-hooks/index.js +23 -0
  75. package/bin/cjs/shared-hooks/index.js.map +1 -0
  76. package/bin/cjs/shared-hooks/internals/tree-node-constants.d.ts +3 -0
  77. package/bin/cjs/shared-hooks/internals/tree-node-constants.d.ts.map +1 -0
  78. package/bin/cjs/shared-hooks/internals/tree-node-constants.js +6 -0
  79. package/bin/cjs/shared-hooks/internals/tree-node-constants.js.map +1 -0
  80. package/bin/cjs/shared-hooks/internals/tree-node-types.d.ts +10 -0
  81. package/bin/cjs/shared-hooks/internals/tree-node-types.d.ts.map +1 -0
  82. package/bin/cjs/shared-hooks/internals/tree-node-types.js +23 -0
  83. package/bin/cjs/shared-hooks/internals/tree-node-types.js.map +1 -0
  84. package/bin/cjs/shared-hooks/internals/tree-node-utils.d.ts +33 -0
  85. package/bin/cjs/shared-hooks/internals/tree-node-utils.d.ts.map +1 -0
  86. package/bin/cjs/shared-hooks/internals/tree-node-utils.js +193 -0
  87. package/bin/cjs/shared-hooks/internals/tree-node-utils.js.map +1 -0
  88. package/bin/cjs/shared-hooks/useDynamicDDS.d.ts +23 -0
  89. package/bin/cjs/shared-hooks/useDynamicDDS.d.ts.map +1 -0
  90. package/bin/cjs/shared-hooks/useDynamicDDS.js +87 -0
  91. package/bin/cjs/shared-hooks/useDynamicDDS.js.map +1 -0
  92. package/bin/cjs/shared-hooks/useSharedMap.d.ts +25 -0
  93. package/bin/cjs/shared-hooks/useSharedMap.d.ts.map +1 -0
  94. package/bin/cjs/shared-hooks/useSharedMap.js +134 -0
  95. package/bin/cjs/shared-hooks/useSharedMap.js.map +1 -0
  96. package/bin/cjs/shared-hooks/useSharedState.d.ts +22 -0
  97. package/bin/cjs/shared-hooks/useSharedState.d.ts.map +1 -0
  98. package/bin/cjs/shared-hooks/useSharedState.js +80 -0
  99. package/bin/cjs/shared-hooks/useSharedState.js.map +1 -0
  100. package/bin/cjs/shared-hooks/useSharedStateRegistry.d.ts +37 -0
  101. package/bin/cjs/shared-hooks/useSharedStateRegistry.d.ts.map +1 -0
  102. package/bin/cjs/shared-hooks/useSharedStateRegistry.js +120 -0
  103. package/bin/cjs/shared-hooks/useSharedStateRegistry.js.map +1 -0
  104. package/bin/cjs/shared-hooks/useSharedTree.d.ts +57 -0
  105. package/bin/cjs/shared-hooks/useSharedTree.d.ts.map +1 -0
  106. package/bin/cjs/shared-hooks/useSharedTree.js +123 -0
  107. package/bin/cjs/shared-hooks/useSharedTree.js.map +1 -0
  108. package/bin/cjs/shared-hooks/useTreeNode.d.ts +96 -0
  109. package/bin/cjs/shared-hooks/useTreeNode.d.ts.map +1 -0
  110. package/bin/cjs/shared-hooks/useTreeNode.js +135 -0
  111. package/bin/cjs/shared-hooks/useTreeNode.js.map +1 -0
  112. package/bin/cjs/types/ActionTypes.d.ts +112 -0
  113. package/bin/cjs/types/ActionTypes.d.ts.map +1 -0
  114. package/bin/cjs/types/ActionTypes.js +7 -0
  115. package/bin/cjs/types/ActionTypes.js.map +1 -0
  116. package/bin/cjs/types/PropTypes.d.ts +56 -0
  117. package/bin/cjs/types/PropTypes.d.ts.map +1 -0
  118. package/bin/cjs/types/PropTypes.js +7 -0
  119. package/bin/cjs/types/PropTypes.js.map +1 -0
  120. package/bin/cjs/types/ResultTypes.d.ts +334 -0
  121. package/bin/cjs/types/ResultTypes.d.ts.map +1 -0
  122. package/bin/cjs/types/ResultTypes.js +7 -0
  123. package/bin/cjs/types/ResultTypes.js.map +1 -0
  124. package/bin/cjs/types/index.d.ts +4 -0
  125. package/bin/cjs/types/index.d.ts.map +1 -0
  126. package/bin/cjs/types/index.js +20 -0
  127. package/bin/cjs/types/index.js.map +1 -0
  128. package/bin/cjs/utils/index.d.ts +2 -0
  129. package/bin/cjs/utils/index.d.ts.map +1 -0
  130. package/bin/cjs/utils/index.js +18 -0
  131. package/bin/cjs/utils/index.js.map +1 -0
  132. package/bin/cjs/utils/type-check.d.ts +15 -0
  133. package/bin/cjs/utils/type-check.d.ts.map +1 -0
  134. package/bin/cjs/utils/type-check.js +62 -0
  135. package/bin/cjs/utils/type-check.js.map +1 -0
  136. package/bin/esm/index.d.ts +7 -0
  137. package/bin/esm/index.d.ts.map +1 -0
  138. package/bin/esm/index.js +7 -0
  139. package/bin/esm/index.js.map +1 -0
  140. package/bin/esm/interfaces/LiveInterfaceExtensions.d.ts +26 -0
  141. package/bin/esm/interfaces/LiveInterfaceExtensions.d.ts.map +1 -0
  142. package/bin/esm/interfaces/LiveInterfaceExtensions.js +6 -0
  143. package/bin/esm/interfaces/LiveInterfaceExtensions.js.map +1 -0
  144. package/bin/esm/interfaces/index.d.ts +2 -0
  145. package/bin/esm/interfaces/index.d.ts.map +1 -0
  146. package/bin/esm/interfaces/index.js +2 -0
  147. package/bin/esm/interfaces/index.js.map +1 -0
  148. package/bin/esm/internal/errors.d.ts +41 -0
  149. package/bin/esm/internal/errors.d.ts.map +1 -0
  150. package/bin/esm/internal/errors.js +42 -0
  151. package/bin/esm/internal/errors.js.map +1 -0
  152. package/bin/esm/internal/index.d.ts +3 -0
  153. package/bin/esm/internal/index.d.ts.map +1 -0
  154. package/bin/esm/internal/index.js +3 -0
  155. package/bin/esm/internal/index.js.map +1 -0
  156. package/bin/esm/internal/type-guards.d.ts +11 -0
  157. package/bin/esm/internal/type-guards.d.ts.map +1 -0
  158. package/bin/esm/internal/type-guards.js +20 -0
  159. package/bin/esm/internal/type-guards.js.map +1 -0
  160. package/bin/esm/live-hooks/index.d.ts +8 -0
  161. package/bin/esm/live-hooks/index.d.ts.map +1 -0
  162. package/bin/esm/live-hooks/index.js +8 -0
  163. package/bin/esm/live-hooks/index.js.map +1 -0
  164. package/bin/esm/live-hooks/useLiveCanvas.d.ts +80 -0
  165. package/bin/esm/live-hooks/useLiveCanvas.d.ts.map +1 -0
  166. package/bin/esm/live-hooks/useLiveCanvas.js +238 -0
  167. package/bin/esm/live-hooks/useLiveCanvas.js.map +1 -0
  168. package/bin/esm/live-hooks/useLiveEvent.d.ts +59 -0
  169. package/bin/esm/live-hooks/useLiveEvent.d.ts.map +1 -0
  170. package/bin/esm/live-hooks/useLiveEvent.js +144 -0
  171. package/bin/esm/live-hooks/useLiveEvent.js.map +1 -0
  172. package/bin/esm/live-hooks/useLiveFollowMode.d.ts +163 -0
  173. package/bin/esm/live-hooks/useLiveFollowMode.d.ts.map +1 -0
  174. package/bin/esm/live-hooks/useLiveFollowMode.js +354 -0
  175. package/bin/esm/live-hooks/useLiveFollowMode.js.map +1 -0
  176. package/bin/esm/live-hooks/useLivePresence.d.ts +76 -0
  177. package/bin/esm/live-hooks/useLivePresence.d.ts.map +1 -0
  178. package/bin/esm/live-hooks/useLivePresence.js +164 -0
  179. package/bin/esm/live-hooks/useLivePresence.js.map +1 -0
  180. package/bin/esm/live-hooks/useLiveState.d.ts +66 -0
  181. package/bin/esm/live-hooks/useLiveState.d.ts.map +1 -0
  182. package/bin/esm/live-hooks/useLiveState.js +128 -0
  183. package/bin/esm/live-hooks/useLiveState.js.map +1 -0
  184. package/bin/esm/live-hooks/useLiveTimer.d.ts +80 -0
  185. package/bin/esm/live-hooks/useLiveTimer.d.ts.map +1 -0
  186. package/bin/esm/live-hooks/useLiveTimer.js +227 -0
  187. package/bin/esm/live-hooks/useLiveTimer.js.map +1 -0
  188. package/bin/esm/live-hooks/useMediaSynchronizer.d.ts +86 -0
  189. package/bin/esm/live-hooks/useMediaSynchronizer.d.ts.map +1 -0
  190. package/bin/esm/live-hooks/useMediaSynchronizer.js +295 -0
  191. package/bin/esm/live-hooks/useMediaSynchronizer.js.map +1 -0
  192. package/bin/esm/providers/AzureProvider.d.ts +113 -0
  193. package/bin/esm/providers/AzureProvider.d.ts.map +1 -0
  194. package/bin/esm/providers/AzureProvider.js +119 -0
  195. package/bin/esm/providers/AzureProvider.js.map +1 -0
  196. package/bin/esm/providers/LiveShareProvider.d.ts +193 -0
  197. package/bin/esm/providers/LiveShareProvider.d.ts.map +1 -0
  198. package/bin/esm/providers/LiveShareProvider.js +197 -0
  199. package/bin/esm/providers/LiveShareProvider.js.map +1 -0
  200. package/bin/esm/providers/index.d.ts +3 -0
  201. package/bin/esm/providers/index.d.ts.map +1 -0
  202. package/bin/esm/providers/index.js +3 -0
  203. package/bin/esm/providers/index.js.map +1 -0
  204. package/bin/esm/shared-hooks/index.d.ts +7 -0
  205. package/bin/esm/shared-hooks/index.d.ts.map +1 -0
  206. package/bin/esm/shared-hooks/index.js +7 -0
  207. package/bin/esm/shared-hooks/index.js.map +1 -0
  208. package/bin/esm/shared-hooks/internals/tree-node-constants.d.ts +3 -0
  209. package/bin/esm/shared-hooks/internals/tree-node-constants.d.ts.map +1 -0
  210. package/bin/esm/shared-hooks/internals/tree-node-constants.js +3 -0
  211. package/bin/esm/shared-hooks/internals/tree-node-constants.js.map +1 -0
  212. package/bin/esm/shared-hooks/internals/tree-node-types.d.ts +10 -0
  213. package/bin/esm/shared-hooks/internals/tree-node-types.d.ts.map +1 -0
  214. package/bin/esm/shared-hooks/internals/tree-node-types.js +18 -0
  215. package/bin/esm/shared-hooks/internals/tree-node-types.js.map +1 -0
  216. package/bin/esm/shared-hooks/internals/tree-node-utils.d.ts +33 -0
  217. package/bin/esm/shared-hooks/internals/tree-node-utils.d.ts.map +1 -0
  218. package/bin/esm/shared-hooks/internals/tree-node-utils.js +188 -0
  219. package/bin/esm/shared-hooks/internals/tree-node-utils.js.map +1 -0
  220. package/bin/esm/shared-hooks/useDynamicDDS.d.ts +23 -0
  221. package/bin/esm/shared-hooks/useDynamicDDS.d.ts.map +1 -0
  222. package/bin/esm/shared-hooks/useDynamicDDS.js +81 -0
  223. package/bin/esm/shared-hooks/useDynamicDDS.js.map +1 -0
  224. package/bin/esm/shared-hooks/useSharedMap.d.ts +25 -0
  225. package/bin/esm/shared-hooks/useSharedMap.d.ts.map +1 -0
  226. package/bin/esm/shared-hooks/useSharedMap.js +128 -0
  227. package/bin/esm/shared-hooks/useSharedMap.js.map +1 -0
  228. package/bin/esm/shared-hooks/useSharedState.d.ts +22 -0
  229. package/bin/esm/shared-hooks/useSharedState.d.ts.map +1 -0
  230. package/bin/esm/shared-hooks/useSharedState.js +74 -0
  231. package/bin/esm/shared-hooks/useSharedState.js.map +1 -0
  232. package/bin/esm/shared-hooks/useSharedStateRegistry.d.ts +37 -0
  233. package/bin/esm/shared-hooks/useSharedStateRegistry.d.ts.map +1 -0
  234. package/bin/esm/shared-hooks/useSharedStateRegistry.js +113 -0
  235. package/bin/esm/shared-hooks/useSharedStateRegistry.js.map +1 -0
  236. package/bin/esm/shared-hooks/useSharedTree.d.ts +57 -0
  237. package/bin/esm/shared-hooks/useSharedTree.d.ts.map +1 -0
  238. package/bin/esm/shared-hooks/useSharedTree.js +117 -0
  239. package/bin/esm/shared-hooks/useSharedTree.js.map +1 -0
  240. package/bin/esm/shared-hooks/useTreeNode.d.ts +96 -0
  241. package/bin/esm/shared-hooks/useTreeNode.d.ts.map +1 -0
  242. package/bin/esm/shared-hooks/useTreeNode.js +132 -0
  243. package/bin/esm/shared-hooks/useTreeNode.js.map +1 -0
  244. package/bin/esm/types/ActionTypes.d.ts +112 -0
  245. package/bin/esm/types/ActionTypes.d.ts.map +1 -0
  246. package/bin/esm/types/ActionTypes.js +6 -0
  247. package/bin/esm/types/ActionTypes.js.map +1 -0
  248. package/bin/esm/types/PropTypes.d.ts +56 -0
  249. package/bin/esm/types/PropTypes.d.ts.map +1 -0
  250. package/bin/esm/types/PropTypes.js +6 -0
  251. package/bin/esm/types/PropTypes.js.map +1 -0
  252. package/bin/esm/types/ResultTypes.d.ts +334 -0
  253. package/bin/esm/types/ResultTypes.d.ts.map +1 -0
  254. package/bin/esm/types/ResultTypes.js +6 -0
  255. package/bin/esm/types/ResultTypes.js.map +1 -0
  256. package/bin/esm/types/index.d.ts +4 -0
  257. package/bin/esm/types/index.d.ts.map +1 -0
  258. package/bin/esm/types/index.js +4 -0
  259. package/bin/esm/types/index.js.map +1 -0
  260. package/bin/esm/utils/index.d.ts +2 -0
  261. package/bin/esm/utils/index.d.ts.map +1 -0
  262. package/bin/esm/utils/index.js +2 -0
  263. package/bin/esm/utils/index.js.map +1 -0
  264. package/bin/esm/utils/type-check.d.ts +15 -0
  265. package/bin/esm/utils/type-check.d.ts.map +1 -0
  266. package/bin/esm/utils/type-check.js +54 -0
  267. package/bin/esm/utils/type-check.js.map +1 -0
  268. package/bin/live-hooks/useLiveCanvas.js +1 -1
  269. package/bin/live-hooks/useLiveCanvas.js.map +1 -1
  270. package/bin/live-hooks/useLiveState.d.ts.map +1 -1
  271. package/bin/live-hooks/useLiveState.js +6 -2
  272. package/bin/live-hooks/useLiveState.js.map +1 -1
  273. package/bin/live-hooks/useMediaSynchronizer.js +1 -1
  274. package/bin/live-hooks/useMediaSynchronizer.js.map +1 -1
  275. package/bin/providers/AzureProvider.js +2 -2
  276. package/bin/providers/AzureProvider.js.map +1 -1
  277. package/bin/providers/LiveShareProvider.js +3 -3
  278. package/bin/providers/LiveShareProvider.js.map +1 -1
  279. package/package.json +61 -47
  280. package/src/index.ts +6 -6
  281. package/src/interfaces/index.ts +1 -1
  282. package/src/internal/index.ts +2 -2
  283. package/src/internal/type-guards.ts +1 -1
  284. package/src/live-hooks/index.ts +7 -7
  285. package/src/live-hooks/useLiveCanvas.ts +154 -82
  286. package/src/live-hooks/useLiveEvent.ts +43 -7
  287. package/src/live-hooks/useLiveFollowMode.ts +149 -6
  288. package/src/live-hooks/useLivePresence.ts +80 -17
  289. package/src/live-hooks/useLiveState.ts +54 -6
  290. package/src/live-hooks/useLiveTimer.ts +59 -4
  291. package/src/live-hooks/useMediaSynchronizer.ts +71 -6
  292. package/src/providers/AzureProvider.tsx +21 -21
  293. package/src/providers/LiveShareProvider.tsx +115 -13
  294. package/src/providers/index.ts +2 -2
  295. package/src/shared-hooks/index.ts +6 -4
  296. package/src/shared-hooks/internals/tree-node-constants.ts +2 -0
  297. package/src/shared-hooks/internals/tree-node-types.ts +26 -0
  298. package/src/shared-hooks/internals/tree-node-utils.ts +269 -0
  299. package/src/shared-hooks/useDynamicDDS.ts +28 -17
  300. package/src/shared-hooks/useSharedMap.ts +42 -17
  301. package/src/shared-hooks/useSharedState.ts +6 -3
  302. package/src/shared-hooks/useSharedStateRegistry.ts +44 -22
  303. package/src/shared-hooks/useSharedTree.ts +144 -0
  304. package/src/shared-hooks/useTreeNode.ts +147 -0
  305. package/src/types/ActionTypes.ts +13 -9
  306. package/src/types/PropTypes.ts +57 -0
  307. package/src/types/ResultTypes.ts +71 -17
  308. package/src/types/index.ts +3 -3
  309. package/src/utils/index.ts +1 -1
  310. package/tsconfig.cjs.json +14 -0
  311. package/tsconfig.json +65 -70
  312. package/.nycrc.json +0 -10
  313. package/tsconfig.build.json +0 -6
@@ -0,0 +1,113 @@
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation. All rights reserved.
3
+ * Licensed under the Microsoft Live Share SDK License.
4
+ */
5
+ import { ContainerSchema, IFluidContainer } from "fluid-framework";
6
+ import React from "react";
7
+ import { AzureClientProps, AzureContainerServices } from "@fluidframework/azure-client";
8
+ import { IAzureContainerResults } from "../types/index.js";
9
+ import { ISharedStateRegistryResponse } from "../shared-hooks/index.js";
10
+ import { BaseLiveShareClient } from "@microsoft/live-share/internal";
11
+ /**
12
+ * React Context provider values for `<AzureProvider>` and `<LiveShareProvider>`.
13
+ *
14
+ * @remarks
15
+ * To get the latest values, use the {@link useFluidObjectsContext} hook.
16
+ */
17
+ export interface IFluidContext extends ISharedStateRegistryResponse {
18
+ /**
19
+ * The Fluid Turbo client used for connecting to the Fluid container.
20
+ */
21
+ clientRef: React.MutableRefObject<BaseLiveShareClient>;
22
+ /**
23
+ * Stateful Fluid container.
24
+ */
25
+ container: IFluidContainer | undefined;
26
+ /**
27
+ * The Azure container services (e.g., audience).
28
+ */
29
+ services: AzureContainerServices | undefined;
30
+ /**
31
+ * A stateful error object that is set if there was an error connecting to the Fluid container.
32
+ */
33
+ joinError: Error | undefined;
34
+ /**
35
+ * React callback function to connect to an existing Fluid container.
36
+ *
37
+ * @remarks
38
+ * The results will also be set to their stateful counterparts for `container` and `services`.
39
+ *
40
+ * @param containerId the containerId to connect to.
41
+ * @param initialObjects Optional. initial object schema, which should match that passed to `createContainer()`.
42
+ * @returns promise that returns a results object once complete (e.g., container, services, etc.)
43
+ */
44
+ getContainer: (containerId: string, fluidContainerSchema?: ContainerSchema) => Promise<IAzureContainerResults>;
45
+ /**
46
+ * React callback function to create and connect to a new Fluid container.
47
+ *
48
+ * @remarks
49
+ * The results will also be set to their stateful counterparts for `container` and `services`.
50
+ *
51
+ * @param initialObjects Optional. The initial object schema to apply to the container.
52
+ * @param onInitializeContainer Optional. A callback for when the container is first initialized, which is useful for setting default values to objects in `initialObjects`.
53
+ * @returns promise that returns a results object once complete (e.g., container, services, etc.)
54
+ */
55
+ createContainer: (fluidContainerSchema?: ContainerSchema, onInitializeContainer?: (container: IFluidContainer) => void) => Promise<IAzureContainerResults>;
56
+ }
57
+ /**
58
+ * @hidden
59
+ */
60
+ export declare const FluidContext: React.Context<IFluidContext>;
61
+ /**
62
+ * Hook to get the latest React context state for `FluidContext`.
63
+ *
64
+ * @remarks
65
+ * This hook can only be used in a child component of `<LiveShareProvider>` or `<AzureProvider>`.
66
+ *
67
+ * @returns current state of `LiveShareContext`
68
+ */
69
+ export declare const useFluidObjectsContext: () => IFluidContext;
70
+ /**
71
+ * Prop types for {@link AzureProvider} component.
72
+ */
73
+ export interface IAzureProviderProps {
74
+ /**
75
+ * Optional. React children node for the React Context Provider.
76
+ */
77
+ children?: React.ReactNode;
78
+ /**
79
+ * Props for initializing a new `AzureClient` instance.
80
+ */
81
+ clientOptions: AzureClientProps;
82
+ /**
83
+ * The `containerId` to connect to when {@link joinOnLoad} is true.
84
+ *
85
+ * @remarks
86
+ * If you pass in an `undefined` value when {@link createOnLoad} is true, a new container will be created.
87
+ */
88
+ containerId?: string;
89
+ /**
90
+ * Flag to control whether or not a new container should be created on first mount.
91
+ *
92
+ * @remarks
93
+ * If no {@link containerId} is set when the component first mounts, setting this to `true` will automatically create a new container.
94
+ * This prop does not do anything if you are using `<LiveShareProvider>` instead of `<AzureProvider>`.
95
+ */
96
+ createOnLoad?: boolean;
97
+ /**
98
+ * The initial schema to use when {@link joinOnLoad} or {@link createOnLoad} is true.
99
+ */
100
+ fluidContainerSchema?: ContainerSchema;
101
+ /**
102
+ * Flag to control whether or not to connect to an existing container on first mount.
103
+ *
104
+ * @remarks
105
+ * Setting this to true will connect to the container if {@link containerId} is provided as a prop.
106
+ */
107
+ joinOnLoad?: boolean;
108
+ }
109
+ /**
110
+ * React Context provider component for using Fluid data objects & joining/creating a Fluid document `AzureClient`.
111
+ */
112
+ export declare const AzureProvider: React.FC<IAzureProviderProps>;
113
+ //# sourceMappingURL=AzureProvider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AzureProvider.d.ts","sourceRoot":"","sources":["../../../src/providers/AzureProvider.tsx"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AACnE,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EACH,gBAAgB,EAChB,sBAAsB,EACzB,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAAE,sBAAsB,EAAE,MAAM,mBAAmB,CAAC;AAC3D,OAAO,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,CAAC,mBAAmB,CAoHvD,CAAC"}
@@ -0,0 +1,127 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.AzureProvider = exports.useFluidObjectsContext = exports.FluidContext = void 0;
16
+ const jsx_runtime_1 = require("react/jsx-runtime");
17
+ const react_1 = __importDefault(require("react"));
18
+ const index_js_1 = require("../shared-hooks/index.js");
19
+ const live_share_1 = require("@microsoft/live-share");
20
+ /**
21
+ * @hidden
22
+ */
23
+ exports.FluidContext = react_1.default.createContext({});
24
+ /**
25
+ * Hook to get the latest React context state for `FluidContext`.
26
+ *
27
+ * @remarks
28
+ * This hook can only be used in a child component of `<LiveShareProvider>` or `<AzureProvider>`.
29
+ *
30
+ * @returns current state of `LiveShareContext`
31
+ */
32
+ const useFluidObjectsContext = () => {
33
+ const context = react_1.default.useContext(exports.FluidContext);
34
+ if (!isFluidObjectsContext(context)) {
35
+ throw new Error("@microsoft/live-share-react: attempting to use `useFluidObjectsContext()` from a component that is not a child of `<LiveShareProvider>` or `<AzureProvider>`.\nTo fix this error, ensure that you are only using Live Share hooks (e.g., `useLiveState`) from a child component of `<LiveShareProvider>` or `<AzureProvider>`.");
36
+ }
37
+ return context;
38
+ };
39
+ exports.useFluidObjectsContext = useFluidObjectsContext;
40
+ /**
41
+ * React Context provider component for using Fluid data objects & joining/creating a Fluid document `AzureClient`.
42
+ */
43
+ const AzureProvider = (props) => {
44
+ var _a;
45
+ const startedRef = react_1.default.useRef(false);
46
+ const clientRef = react_1.default.useRef(new live_share_1.AzureLiveShareClient(props.clientOptions));
47
+ const [results, setResults] = react_1.default.useState();
48
+ const [joinError, setJoinError] = react_1.default.useState();
49
+ const stateRegistryCallbacks = (0, index_js_1.useSharedStateRegistry)(results);
50
+ /**
51
+ * Get the container for a given containerId using AzureClient
52
+ */
53
+ const getContainer = react_1.default.useCallback((containerId, fluidContainerSchema) => __awaiter(void 0, void 0, void 0, function* () {
54
+ return new Promise((resolve, reject) => __awaiter(void 0, void 0, void 0, function* () {
55
+ try {
56
+ const results = yield clientRef.current.getContainer(containerId, fluidContainerSchema);
57
+ setResults(results);
58
+ resolve(results);
59
+ }
60
+ catch (error) {
61
+ if (error instanceof Error) {
62
+ setJoinError(error);
63
+ }
64
+ reject(error);
65
+ }
66
+ }));
67
+ }), [props.containerId, setResults]);
68
+ /**
69
+ * Create container callback to create a new container using AzureClient
70
+ */
71
+ const createContainer = react_1.default.useCallback((fluidContainerSchema, onInitializeContainer) => __awaiter(void 0, void 0, void 0, function* () {
72
+ return new Promise((resolve, reject) => __awaiter(void 0, void 0, void 0, function* () {
73
+ try {
74
+ const results = yield clientRef.current.createContainer(fluidContainerSchema);
75
+ if (onInitializeContainer) {
76
+ onInitializeContainer(results.container);
77
+ }
78
+ const containerId = yield results.container.attach();
79
+ window.location.hash = containerId;
80
+ setResults(results);
81
+ resolve(results);
82
+ }
83
+ catch (error) {
84
+ if (error instanceof Error) {
85
+ setJoinError(error);
86
+ }
87
+ reject(error);
88
+ }
89
+ }));
90
+ }), [props.containerId, setResults]);
91
+ /**
92
+ * Joins a container if `props.joinOnLoad` is true and `props.containerId` is known. Creates a new container if `props.createOnLoad` is true
93
+ * and `props.containerId` is not known.
94
+ */
95
+ react_1.default.useEffect(() => {
96
+ var _a;
97
+ // This hook should only be called once, so we use a ref to track if it has been called.
98
+ // This is a workaround for the fact that useEffect is called twice on initial render in React V18.
99
+ // We are not doing this here for backwards compatibility. View the README for more information.
100
+ if (((_a = results === null || results === void 0 ? void 0 : results.container) === null || _a === void 0 ? void 0 : _a.connectionState) !== undefined ||
101
+ startedRef.current)
102
+ return;
103
+ startedRef.current = true;
104
+ if (props.containerId && props.joinOnLoad) {
105
+ getContainer(props.containerId, props.fluidContainerSchema);
106
+ }
107
+ else if (!props.containerId && props.createOnLoad) {
108
+ createContainer(props.fluidContainerSchema);
109
+ }
110
+ }, [
111
+ (_a = results === null || results === void 0 ? void 0 : results.container) === null || _a === void 0 ? void 0 : _a.connectionState,
112
+ props.containerId,
113
+ props.createOnLoad,
114
+ props.joinOnLoad,
115
+ props.fluidContainerSchema,
116
+ getContainer,
117
+ createContainer,
118
+ ]);
119
+ return ((0, jsx_runtime_1.jsx)(exports.FluidContext.Provider, { value: Object.assign({ clientRef, container: results === null || results === void 0 ? void 0 : results.container, services: results === null || results === void 0 ? void 0 : results.services, joinError,
120
+ createContainer,
121
+ getContainer }, stateRegistryCallbacks), children: props.children }));
122
+ };
123
+ exports.AzureProvider = AzureProvider;
124
+ function isFluidObjectsContext(value) {
125
+ return !!(value === null || value === void 0 ? void 0 : value.clientRef);
126
+ }
127
+ //# sourceMappingURL=AzureProvider.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AzureProvider.js","sourceRoot":"","sources":["../../../src/providers/AzureProvider.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAMA,kDAA0B;AAM1B,uDAGkC;AAClC,sDAA6D;AAwD7D;;GAEG;AACU,QAAA,YAAY,GAAG,eAAK,CAAC,aAAa,CAC3C,EAAmB,CACtB,CAAC;AAEF;;;;;;;GAOG;AACI,MAAM,sBAAsB,GAAG,GAAkB,EAAE;IACtD,MAAM,OAAO,GAAG,eAAK,CAAC,UAAU,CAAC,oBAAY,CAAC,CAAC;IAC/C,IAAI,CAAC,qBAAqB,CAAC,OAAO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C,KAAK,CAAC,WAAW,EAAE,KAAK,CAAC,oBAAoB,CAAC,CAAC;QAChE,CAAC;aAAM,IAAI,CAAC,KAAK,CAAC,WAAW,IAAI,KAAK,CAAC,YAAY,EAAE,CAAC;YAClD,eAAe,CAAC,KAAK,CAAC,oBAAoB,CAAC,CAAC;QAChD,CAAC;IACL,CAAC,EAAE;QACC,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,SAAS,0CAAE,eAAe;QACnC,KAAK,CAAC,WAAW;QACjB,KAAK,CAAC,YAAY;QAClB,KAAK,CAAC,UAAU;QAChB,KAAK,CAAC,oBAAoB;QAC1B,YAAY;QACZ,eAAe;KAClB,CAAC,CAAC;IAEH,OAAO,CACH,uBAAC,oBAAY,CAAC,QAAQ,IAClB,KAAK,kBACD,SAAS,EACT,SAAS,EAAE,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,SAAS,EAC7B,QAAQ,EAAE,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,QAAQ,EAC3B,SAAS;YACT,eAAe;YACf,YAAY,IACT,sBAAsB,aAG5B,KAAK,CAAC,QAAQ,GACK,CAC3B,CAAC;AACN,CAAC,CAAC;AApHW,QAAA,aAAa,iBAoHxB;AAEF,SAAS,qBAAqB,CAAC,KAAU;IACrC,OAAO,CAAC,CAAC,CAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,SAAS,CAAA,CAAC;AAC9B,CAAC"}
@@ -0,0 +1,193 @@
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation. All rights reserved.
3
+ * Licensed under the Microsoft Live Share SDK License.
4
+ */
5
+ import { ContainerSchema, IFluidContainer } from "fluid-framework";
6
+ import React from "react";
7
+ import { ILiveShareClientOptions, ILiveShareHost, ILiveShareJoinResults, ITimestampProvider } from "@microsoft/live-share";
8
+ /**
9
+ * React Context provider values for `<LiveShareProvider>`.
10
+ *
11
+ * @remarks
12
+ * To get the latest values, use the {@link useLiveShareContext} hook.
13
+ * Use the {@link useFluidObjectsContext} hook for other relevant context values.
14
+ */
15
+ export interface ILiveShareContext {
16
+ /**
17
+ * True if the local user created the Fluid container
18
+ */
19
+ created: boolean;
20
+ /**
21
+ * True if connected to the Live Share container
22
+ */
23
+ joined: boolean;
24
+ /**
25
+ * An error that will be defined if there was a problem joining the container, or undefined if not.
26
+ */
27
+ joinError: Error | undefined;
28
+ /**
29
+ * Live Share timestamp provider. Can be used to `.getTimestamp()` for a global clock value.
30
+ * This reference timestamp value should be fairly consistent for all users in the session.
31
+ */
32
+ timestampProvider: ITimestampProvider | undefined;
33
+ /**
34
+ * Join callback method for manually connecting to the Fluid container.
35
+ *
36
+ * @remarks
37
+ * Use this callback if `joinOnLoad` is `false` or `undefined` in {@link ILiveShareProviderProps}.
38
+ *
39
+ * @param initialObjects Optional. The initial objects for the Fluid container schema.
40
+ * @param onInitializeContainer Optional. Callback for when the container is first created.
41
+ * @returns Promise with `ILiveShareJoinResults`, which includes the Fluid container
42
+ */
43
+ join: (fluidContainerSchema?: ContainerSchema, onInitializeContainer?: (container: IFluidContainer) => void) => Promise<ILiveShareJoinResults>;
44
+ }
45
+ /**
46
+ * @hidden
47
+ */
48
+ export declare const LiveShareContext: React.Context<ILiveShareContext>;
49
+ /**
50
+ * Hook to get the latest React context state for `LiveShareContext`.
51
+ *
52
+ * @remarks
53
+ * This hook can only be used in a child component of `<LiveShareProvider>`.
54
+ * See `useFluidObjectsContext` for other information related to the Live Share session, such as the `container`.
55
+ *
56
+ * @returns current state of `LiveShareContext`
57
+ *
58
+ * @example
59
+ ```jsx
60
+ // LiveShareApp.jsx
61
+ import { LiveShareProvider } from "@microsoft/live-share-react";
62
+ import { LiveShareHost } from "@microsoft/teams-js";
63
+
64
+ const host = LiveShareHost.create();
65
+
66
+ export function LiveShareApp() {
67
+ // Call app.initialize() from teams-js before rendering LiveShareProvider
68
+
69
+ return (
70
+ <LiveShareProvider
71
+ joinOnLoad={true}
72
+ host={host}
73
+ >
74
+ <LiveShareLoader>
75
+ <LiveCheckbox />
76
+ </LiveShareLoader>
77
+ </LiveShareProvider>
78
+ );
79
+ }
80
+
81
+ // LiveShareLoader.jsx
82
+ import { useLiveShareContext } from "@microsoft/live-share-react";
83
+
84
+ export function LiveShareLoader({ children }) {
85
+ const { joined, joinError } = useLiveShareContext();
86
+
87
+ if (joinError) return <>{joinError.message}</>;
88
+ if (!joined) return <>Joining Live Share session...</>;
89
+ return <>{children}</>
90
+ }
91
+
92
+ // LiveCheckbox.jsx
93
+ import { useLiveState } from "@microsoft/live-share-react";
94
+
95
+ export function LiveCheckbox() {
96
+ const [checked, setChecked] = useLiveState("MY-UNIQUE-ID", false);
97
+ return (
98
+ <input
99
+ type="checkbox"
100
+ checked={checked}
101
+ onChange={() => {
102
+ setChecked(!checked);
103
+ }}
104
+ />
105
+ );
106
+ }
107
+ ```
108
+ */
109
+ export declare const useLiveShareContext: () => ILiveShareContext;
110
+ /**
111
+ * Prop types for {@link LiveShareProvider} component.
112
+ */
113
+ export interface ILiveShareProviderProps {
114
+ /**
115
+ * Optional. React children node for the React Context Provider
116
+ */
117
+ children?: React.ReactNode;
118
+ /**
119
+ * Optional. Options for initializing `LiveShareClient`.
120
+ */
121
+ clientOptions?: ILiveShareClientOptions;
122
+ /**
123
+ * Host to initialize `LiveShareClient` with.
124
+ *
125
+ * @remarks
126
+ * If using the `LiveShareClient` class from `@microsoft/teams-js`, you must ensure that you have first called `teamsJs.app.initialize()` before calling `LiveShareClient.create()`.
127
+ */
128
+ host: ILiveShareHost;
129
+ /**
130
+ * The schema to use when {@link joinOnLoad} is true.
131
+ */
132
+ fluidContainerSchema?: ContainerSchema;
133
+ /**
134
+ * Optional. Flag to determine whether to join Fluid container on load.
135
+ */
136
+ joinOnLoad?: boolean;
137
+ }
138
+ /**
139
+ * React Context provider component for using Live Share data objects & joining a Live Share session using `LiveShareClient`.
140
+ *
141
+ * @example
142
+ ```jsx
143
+ // LiveShareApp.jsx
144
+ import { LiveShareProvider } from "@microsoft/live-share-react";
145
+ import { LiveShareHost } from "@microsoft/teams-js";
146
+
147
+ const host = LiveShareHost.create();
148
+
149
+ export function LiveShareApp() {
150
+ // Call app.initialize() from teams-js before rendering LiveShareProvider
151
+
152
+ return (
153
+ <LiveShareProvider
154
+ joinOnLoad={true}
155
+ host={host}
156
+ >
157
+ <LiveShareLoader>
158
+ <LiveCheckbox />
159
+ </LiveShareLoader>
160
+ </LiveShareProvider>
161
+ );
162
+ }
163
+
164
+ // LiveShareLoader.jsx
165
+ import { useLiveShareContext } from "@microsoft/live-share-react";
166
+
167
+ export function LiveShareLoader({ children }) {
168
+ const { joined, joinError } = useLiveShareContext();
169
+
170
+ if (joinError) return <>{joinError.message}</>;
171
+ if (!joined) return <>Joining Live Share session...</>;
172
+ return <>{children}</>
173
+ }
174
+
175
+ // LiveCheckbox.jsx
176
+ import { useLiveState } from "@microsoft/live-share-react";
177
+
178
+ export function LiveCheckbox() {
179
+ const [checked, setChecked] = useLiveState("MY-UNIQUE-ID", false);
180
+ return (
181
+ <input
182
+ type="checkbox"
183
+ checked={checked}
184
+ onChange={() => {
185
+ setChecked(!checked);
186
+ }}
187
+ />
188
+ );
189
+ }
190
+ ```
191
+ */
192
+ export declare const LiveShareProvider: React.FC<ILiveShareProviderProps>;
193
+ //# sourceMappingURL=LiveShareProvider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"LiveShareProvider.d.ts","sourceRoot":"","sources":["../../../src/providers/LiveShareProvider.tsx"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AACnE,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,EACH,uBAAuB,EACvB,cAAc,EACd,qBAAqB,EACrB,kBAAkB,EAErB,MAAM,uBAAuB,CAAC;AAI/B;;;;;;GAMG;AACH,MAAM,WAAW,iBAAiB;IAC9B;;OAEG;IACH,OAAO,EAAE,OAAO,CAAC;IACjB;;OAEG;IACH,MAAM,EAAE,OAAO,CAAC;IAChB;;OAEG;IACH,SAAS,EAAE,KAAK,GAAG,SAAS,CAAC;IAC7B;;;OAGG;IACH,iBAAiB,EAAE,kBAAkB,GAAG,SAAS,CAAC;IAClD;;;;;;;;;OASG;IACH,IAAI,EAAE,CACF,oBAAoB,CAAC,EAAE,eAAe,EACtC,qBAAqB,CAAC,EAAE,CAAC,SAAS,EAAE,eAAe,KAAK,IAAI,KAC3D,OAAO,CAAC,qBAAqB,CAAC,CAAC;CACvC;AAED;;GAEG;AACH,eAAO,MAAM,gBAAgB,kCAE5B,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2DG;AACH,eAAO,MAAM,mBAAmB,QAAO,iBAQtC,CAAC;AAEF;;GAEG;AACH,MAAM,WAAW,uBAAuB;IACpC;;OAEG;IACH,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IAC3B;;OAEG;IACH,aAAa,CAAC,EAAE,uBAAuB,CAAC;IACxC;;;;;OAKG;IACH,IAAI,EAAE,cAAc,CAAC;IACrB;;OAEG;IACH,oBAAoB,CAAC,EAAE,eAAe,CAAC;IACvC;;OAEG;IACH,UAAU,CAAC,EAAE,OAAO,CAAC;CACxB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqDG;AACH,eAAO,MAAM,iBAAiB,EAAE,KAAK,CAAC,EAAE,CAAC,uBAAuB,CAkG/D,CAAC"}
@@ -0,0 +1,205 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.LiveShareProvider = exports.useLiveShareContext = exports.LiveShareContext = void 0;
16
+ const jsx_runtime_1 = require("react/jsx-runtime");
17
+ const react_1 = __importDefault(require("react"));
18
+ const index_js_1 = require("../shared-hooks/index.js");
19
+ const live_share_1 = require("@microsoft/live-share");
20
+ const AzureProvider_js_1 = require("./AzureProvider.js");
21
+ const index_js_2 = require("../internal/index.js");
22
+ /**
23
+ * @hidden
24
+ */
25
+ exports.LiveShareContext = react_1.default.createContext({});
26
+ /**
27
+ * Hook to get the latest React context state for `LiveShareContext`.
28
+ *
29
+ * @remarks
30
+ * This hook can only be used in a child component of `<LiveShareProvider>`.
31
+ * See `useFluidObjectsContext` for other information related to the Live Share session, such as the `container`.
32
+ *
33
+ * @returns current state of `LiveShareContext`
34
+ *
35
+ * @example
36
+ ```jsx
37
+ // LiveShareApp.jsx
38
+ import { LiveShareProvider } from "@microsoft/live-share-react";
39
+ import { LiveShareHost } from "@microsoft/teams-js";
40
+
41
+ const host = LiveShareHost.create();
42
+
43
+ export function LiveShareApp() {
44
+ // Call app.initialize() from teams-js before rendering LiveShareProvider
45
+
46
+ return (
47
+ <LiveShareProvider
48
+ joinOnLoad={true}
49
+ host={host}
50
+ >
51
+ <LiveShareLoader>
52
+ <LiveCheckbox />
53
+ </LiveShareLoader>
54
+ </LiveShareProvider>
55
+ );
56
+ }
57
+
58
+ // LiveShareLoader.jsx
59
+ import { useLiveShareContext } from "@microsoft/live-share-react";
60
+
61
+ export function LiveShareLoader({ children }) {
62
+ const { joined, joinError } = useLiveShareContext();
63
+
64
+ if (joinError) return <>{joinError.message}</>;
65
+ if (!joined) return <>Joining Live Share session...</>;
66
+ return <>{children}</>
67
+ }
68
+
69
+ // LiveCheckbox.jsx
70
+ import { useLiveState } from "@microsoft/live-share-react";
71
+
72
+ export function LiveCheckbox() {
73
+ const [checked, setChecked] = useLiveState("MY-UNIQUE-ID", false);
74
+ return (
75
+ <input
76
+ type="checkbox"
77
+ checked={checked}
78
+ onChange={() => {
79
+ setChecked(!checked);
80
+ }}
81
+ />
82
+ );
83
+ }
84
+ ```
85
+ */
86
+ const useLiveShareContext = () => {
87
+ const context = react_1.default.useContext(exports.LiveShareContext);
88
+ if (!isLiveShareContext(context)) {
89
+ throw new Error("@microsoft/live-share-react: attempting to use `useLiveShareContext()` from a component that is not a child of `<LiveShareProvider>`.\nTo fix this error, ensure that you are only using Live Share hooks (e.g., `useLiveState`) from a child component of `<LiveShareProvider>`.");
90
+ }
91
+ return context;
92
+ };
93
+ exports.useLiveShareContext = useLiveShareContext;
94
+ /**
95
+ * React Context provider component for using Live Share data objects & joining a Live Share session using `LiveShareClient`.
96
+ *
97
+ * @example
98
+ ```jsx
99
+ // LiveShareApp.jsx
100
+ import { LiveShareProvider } from "@microsoft/live-share-react";
101
+ import { LiveShareHost } from "@microsoft/teams-js";
102
+
103
+ const host = LiveShareHost.create();
104
+
105
+ export function LiveShareApp() {
106
+ // Call app.initialize() from teams-js before rendering LiveShareProvider
107
+
108
+ return (
109
+ <LiveShareProvider
110
+ joinOnLoad={true}
111
+ host={host}
112
+ >
113
+ <LiveShareLoader>
114
+ <LiveCheckbox />
115
+ </LiveShareLoader>
116
+ </LiveShareProvider>
117
+ );
118
+ }
119
+
120
+ // LiveShareLoader.jsx
121
+ import { useLiveShareContext } from "@microsoft/live-share-react";
122
+
123
+ export function LiveShareLoader({ children }) {
124
+ const { joined, joinError } = useLiveShareContext();
125
+
126
+ if (joinError) return <>{joinError.message}</>;
127
+ if (!joined) return <>Joining Live Share session...</>;
128
+ return <>{children}</>
129
+ }
130
+
131
+ // LiveCheckbox.jsx
132
+ import { useLiveState } from "@microsoft/live-share-react";
133
+
134
+ export function LiveCheckbox() {
135
+ const [checked, setChecked] = useLiveState("MY-UNIQUE-ID", false);
136
+ return (
137
+ <input
138
+ type="checkbox"
139
+ checked={checked}
140
+ onChange={() => {
141
+ setChecked(!checked);
142
+ }}
143
+ />
144
+ );
145
+ }
146
+ ```
147
+ */
148
+ const LiveShareProvider = (props) => {
149
+ const startedRef = react_1.default.useRef(false);
150
+ const clientRef = react_1.default.useRef(new live_share_1.LiveShareClient(props.host, props.clientOptions));
151
+ const [results, setResults] = react_1.default.useState();
152
+ const [joinError, setJoinError] = react_1.default.useState();
153
+ const stateRegistryCallbacks = (0, index_js_1.useSharedStateRegistry)(results);
154
+ /**
155
+ * Join container callback for joining the Live Share session
156
+ */
157
+ const join = react_1.default.useCallback((fluidContainerSchema, onInitializeContainer) => __awaiter(void 0, void 0, void 0, function* () {
158
+ startedRef.current = true;
159
+ const results = yield clientRef.current.join(fluidContainerSchema, onInitializeContainer);
160
+ setResults(results);
161
+ return results;
162
+ }), []);
163
+ /**
164
+ * Joins the container on load if `props.joinOnLoad` is true
165
+ */
166
+ react_1.default.useEffect(() => {
167
+ // This hook should only be called once, so we use a ref to track if it has been called.
168
+ // This is a workaround for the fact that useEffect is called twice on initial render in React V18.
169
+ // We are not doing this here for backwards compatibility. View the README for more information.
170
+ if (results !== undefined || startedRef.current || !props.joinOnLoad)
171
+ return;
172
+ join(props.fluidContainerSchema).catch((error) => {
173
+ var _a;
174
+ console.error(error);
175
+ if (error instanceof Error) {
176
+ setJoinError(error);
177
+ }
178
+ else if ((0, index_js_2.isITeamsJsSdkError)(error)) {
179
+ setJoinError(new Error(`[${error.errorCode}] ${(_a = error.message) !== null && _a !== void 0 ? _a : "An unknown error occurred while joining container."}`));
180
+ }
181
+ else if (typeof error == "string") {
182
+ setJoinError(new Error(error));
183
+ }
184
+ else {
185
+ setJoinError(new Error("LiveShareProvider: An unknown error occurred while joining container."));
186
+ }
187
+ });
188
+ }, [results, props.joinOnLoad, props.fluidContainerSchema, join]);
189
+ return ((0, jsx_runtime_1.jsx)(exports.LiveShareContext.Provider, { value: {
190
+ created: !!(results === null || results === void 0 ? void 0 : results.created),
191
+ timestampProvider: results === null || results === void 0 ? void 0 : results.timestampProvider,
192
+ joined: !!(results === null || results === void 0 ? void 0 : results.container),
193
+ joinError,
194
+ join,
195
+ }, children: (0, jsx_runtime_1.jsx)(AzureProvider_js_1.FluidContext.Provider, { value: Object.assign({ clientRef, container: results === null || results === void 0 ? void 0 : results.container, services: results === null || results === void 0 ? void 0 : results.services, joinError, getContainer: () => __awaiter(void 0, void 0, void 0, function* () {
196
+ throw new Error("Cannot join new container through getContainer in LiveShareProvider");
197
+ }), createContainer: () => __awaiter(void 0, void 0, void 0, function* () {
198
+ throw new Error("Cannot create new container through createContainer in LiveShareProvider");
199
+ }) }, stateRegistryCallbacks), children: props.children }) }));
200
+ };
201
+ exports.LiveShareProvider = LiveShareProvider;
202
+ function isLiveShareContext(value) {
203
+ return (typeof (value === null || value === void 0 ? void 0 : value.created) === "boolean" && typeof (value === null || value === void 0 ? void 0 : value.join) === "function");
204
+ }
205
+ //# sourceMappingURL=LiveShareProvider.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"LiveShareProvider.js","sourceRoot":"","sources":["../../../src/providers/LiveShareProvider.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAMA,kDAA0B;AAC1B,uDAAkE;AAClE,sDAM+B;AAC/B,yDAA0E;AAC1E,mDAA0D;AA2C1D;;GAEG;AACU,QAAA,gBAAgB,GAAG,eAAK,CAAC,aAAa,CAC/C,EAAuB,CAC1B,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2DG;AACI,MAAM,mBAAmB,GAAG,GAAsB,EAAE;IACvD,MAAM,OAAO,GAAG,eAAK,CAAC,UAAU,CAAC,wBAAgB,CAAC,CAAC;IACnD,IAAI,CAAC,kBAAkB,CAAC,OAAO,CAA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E,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,QAAQ,EAC3B,SAAS,EACT,YAAY,EAAE,GAAS,EAAE;oBACrB,MAAM,IAAI,KAAK,CACX,qEAAqE,CACxE,CAAC;gBACN,CAAC,CAAA,EACD,eAAe,EAAE,GAAS,EAAE;oBACxB,MAAM,IAAI,KAAK,CACX,0EAA0E,CAC7E,CAAC;gBACN,CAAC,CAAA,IACE,sBAAsB,aAG5B,KAAK,CAAC,QAAQ,GACK,GACA,CAC/B,CAAC;AACN,CAAC,CAAC;AAlGW,QAAA,iBAAiB,qBAkG5B;AAEF,SAAS,kBAAkB,CAAC,KAAU;IAClC,OAAO,CACH,OAAO,CAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,OAAO,CAAA,KAAK,SAAS,IAAI,OAAO,CAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,IAAI,CAAA,KAAK,UAAU,CAC3E,CAAC;AACN,CAAC"}
@@ -0,0 +1,3 @@
1
+ export * from "./AzureProvider.js";
2
+ export * from "./LiveShareProvider.js";
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/providers/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AACnC,cAAc,wBAAwB,CAAC"}