@microsoft/live-share-react 2.0.0-internal.2 → 2.0.0-internal.20

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 (252) hide show
  1. package/LICENSE +64 -61
  2. package/README.md +175 -164
  3. package/bin/esm/index.d.ts +7 -0
  4. package/bin/esm/index.d.ts.map +1 -0
  5. package/bin/esm/index.js +7 -0
  6. package/bin/esm/index.js.map +1 -0
  7. package/bin/esm/interfaces/LiveInterfaceExtensions.d.ts.map +1 -0
  8. package/bin/esm/interfaces/LiveInterfaceExtensions.js.map +1 -0
  9. package/bin/esm/interfaces/index.d.ts +2 -0
  10. package/bin/esm/interfaces/index.d.ts.map +1 -0
  11. package/bin/esm/interfaces/index.js +2 -0
  12. package/bin/esm/interfaces/index.js.map +1 -0
  13. package/bin/esm/internal/errors.d.ts.map +1 -0
  14. package/bin/esm/internal/errors.js.map +1 -0
  15. package/bin/esm/internal/index.d.ts +3 -0
  16. package/bin/esm/internal/index.d.ts.map +1 -0
  17. package/bin/esm/internal/index.js +3 -0
  18. package/bin/esm/internal/index.js.map +1 -0
  19. package/bin/{internal → esm/internal}/type-guards.d.ts +1 -1
  20. package/bin/esm/internal/type-guards.d.ts.map +1 -0
  21. package/bin/esm/internal/type-guards.js.map +1 -0
  22. package/bin/esm/live-hooks/index.d.ts +8 -0
  23. package/bin/esm/live-hooks/index.d.ts.map +1 -0
  24. package/bin/esm/live-hooks/index.js +8 -0
  25. package/bin/esm/live-hooks/index.js.map +1 -0
  26. package/bin/esm/live-hooks/useLiveCanvas.d.ts +80 -0
  27. package/bin/esm/live-hooks/useLiveCanvas.d.ts.map +1 -0
  28. package/bin/esm/live-hooks/useLiveCanvas.js +237 -0
  29. package/bin/esm/live-hooks/useLiveCanvas.js.map +1 -0
  30. package/bin/{live-hooks → esm/live-hooks}/useLiveEvent.d.ts +37 -1
  31. package/bin/esm/live-hooks/useLiveEvent.d.ts.map +1 -0
  32. package/bin/{live-hooks → esm/live-hooks}/useLiveEvent.js +45 -18
  33. package/bin/esm/live-hooks/useLiveEvent.js.map +1 -0
  34. package/bin/esm/live-hooks/useLiveFollowMode.d.ts +163 -0
  35. package/bin/esm/live-hooks/useLiveFollowMode.d.ts.map +1 -0
  36. package/bin/{live-hooks → esm/live-hooks}/useLiveFollowMode.js +173 -39
  37. package/bin/esm/live-hooks/useLiveFollowMode.js.map +1 -0
  38. package/bin/esm/live-hooks/useLivePresence.d.ts +76 -0
  39. package/bin/esm/live-hooks/useLivePresence.d.ts.map +1 -0
  40. package/bin/{live-hooks → esm/live-hooks}/useLivePresence.js +74 -25
  41. package/bin/esm/live-hooks/useLivePresence.js.map +1 -0
  42. package/bin/{live-hooks → esm/live-hooks}/useLiveState.d.ts +46 -1
  43. package/bin/esm/live-hooks/useLiveState.d.ts.map +1 -0
  44. package/bin/{live-hooks → esm/live-hooks}/useLiveState.js +58 -18
  45. package/bin/esm/live-hooks/useLiveState.js.map +1 -0
  46. package/bin/{live-hooks → esm/live-hooks}/useLiveTimer.d.ts +56 -1
  47. package/bin/esm/live-hooks/useLiveTimer.d.ts.map +1 -0
  48. package/bin/{live-hooks → esm/live-hooks}/useLiveTimer.js +80 -34
  49. package/bin/esm/live-hooks/useLiveTimer.js.map +1 -0
  50. package/bin/esm/live-hooks/useMediaSynchronizer.d.ts +86 -0
  51. package/bin/esm/live-hooks/useMediaSynchronizer.d.ts.map +1 -0
  52. package/bin/{live-hooks → esm/live-hooks}/useMediaSynchronizer.js +89 -37
  53. package/bin/esm/live-hooks/useMediaSynchronizer.js.map +1 -0
  54. package/bin/{providers → esm/providers}/AzureProvider.d.ts +9 -9
  55. package/bin/esm/providers/AzureProvider.d.ts.map +1 -0
  56. package/bin/{providers → esm/providers}/AzureProvider.js +28 -33
  57. package/bin/esm/providers/AzureProvider.js.map +1 -0
  58. package/bin/{providers → esm/providers}/LiveShareProvider.d.ts +106 -4
  59. package/bin/esm/providers/LiveShareProvider.d.ts.map +1 -0
  60. package/bin/esm/providers/LiveShareProvider.js +196 -0
  61. package/bin/esm/providers/LiveShareProvider.js.map +1 -0
  62. package/bin/esm/providers/index.d.ts +3 -0
  63. package/bin/esm/providers/index.d.ts.map +1 -0
  64. package/bin/esm/providers/index.js +3 -0
  65. package/bin/esm/providers/index.js.map +1 -0
  66. package/bin/esm/shared-hooks/index.d.ts +7 -0
  67. package/bin/esm/shared-hooks/index.d.ts.map +1 -0
  68. package/bin/esm/shared-hooks/index.js +7 -0
  69. package/bin/esm/shared-hooks/index.js.map +1 -0
  70. package/bin/esm/shared-hooks/internals/tree-node-constants.d.ts +3 -0
  71. package/bin/esm/shared-hooks/internals/tree-node-constants.d.ts.map +1 -0
  72. package/bin/esm/shared-hooks/internals/tree-node-constants.js +3 -0
  73. package/bin/esm/shared-hooks/internals/tree-node-constants.js.map +1 -0
  74. package/bin/esm/shared-hooks/internals/tree-node-types.d.ts +10 -0
  75. package/bin/esm/shared-hooks/internals/tree-node-types.d.ts.map +1 -0
  76. package/bin/esm/shared-hooks/internals/tree-node-types.js +18 -0
  77. package/bin/esm/shared-hooks/internals/tree-node-types.js.map +1 -0
  78. package/bin/esm/shared-hooks/internals/tree-node-utils.d.ts +33 -0
  79. package/bin/esm/shared-hooks/internals/tree-node-utils.d.ts.map +1 -0
  80. package/bin/esm/shared-hooks/internals/tree-node-utils.js +186 -0
  81. package/bin/esm/shared-hooks/internals/tree-node-utils.js.map +1 -0
  82. package/bin/{shared-hooks → esm/shared-hooks}/useDynamicDDS.d.ts +4 -4
  83. package/bin/esm/shared-hooks/useDynamicDDS.d.ts.map +1 -0
  84. package/bin/{shared-hooks → esm/shared-hooks}/useDynamicDDS.js +22 -22
  85. package/bin/esm/shared-hooks/useDynamicDDS.js.map +1 -0
  86. package/bin/{shared-hooks → esm/shared-hooks}/useSharedMap.d.ts +4 -2
  87. package/bin/esm/shared-hooks/useSharedMap.d.ts.map +1 -0
  88. package/bin/{shared-hooks → esm/shared-hooks}/useSharedMap.js +28 -14
  89. package/bin/esm/shared-hooks/useSharedMap.js.map +1 -0
  90. package/bin/{shared-hooks → esm/shared-hooks}/useSharedState.d.ts +1 -1
  91. package/bin/esm/shared-hooks/useSharedState.d.ts.map +1 -0
  92. package/bin/{shared-hooks → esm/shared-hooks}/useSharedState.js +2 -2
  93. package/bin/esm/shared-hooks/useSharedState.js.map +1 -0
  94. package/bin/{shared-hooks → esm/shared-hooks}/useSharedStateRegistry.d.ts +1 -1
  95. package/bin/esm/shared-hooks/useSharedStateRegistry.d.ts.map +1 -0
  96. package/bin/{shared-hooks → esm/shared-hooks}/useSharedStateRegistry.js +35 -24
  97. package/bin/esm/shared-hooks/useSharedStateRegistry.js.map +1 -0
  98. package/bin/esm/shared-hooks/useSharedTree.d.ts +57 -0
  99. package/bin/esm/shared-hooks/useSharedTree.d.ts.map +1 -0
  100. package/bin/esm/shared-hooks/useSharedTree.js +117 -0
  101. package/bin/esm/shared-hooks/useSharedTree.js.map +1 -0
  102. package/bin/esm/shared-hooks/useTreeNode.d.ts +96 -0
  103. package/bin/esm/shared-hooks/useTreeNode.d.ts.map +1 -0
  104. package/bin/esm/shared-hooks/useTreeNode.js +132 -0
  105. package/bin/esm/shared-hooks/useTreeNode.js.map +1 -0
  106. package/bin/{types → esm/types}/ActionTypes.d.ts +7 -7
  107. package/bin/esm/types/ActionTypes.d.ts.map +1 -0
  108. package/bin/esm/types/ActionTypes.js.map +1 -0
  109. package/bin/esm/types/FluidMap.d.ts +151 -0
  110. package/bin/esm/types/FluidMap.d.ts.map +1 -0
  111. package/bin/esm/types/FluidMap.js +24 -0
  112. package/bin/esm/types/FluidMap.js.map +1 -0
  113. package/bin/esm/types/PropTypes.d.ts +56 -0
  114. package/bin/esm/types/PropTypes.d.ts.map +1 -0
  115. package/bin/esm/types/PropTypes.js.map +1 -0
  116. package/bin/{types → esm/types}/ResultTypes.d.ts +62 -18
  117. package/bin/esm/types/ResultTypes.d.ts.map +1 -0
  118. package/bin/esm/types/ResultTypes.js.map +1 -0
  119. package/bin/esm/types/index.d.ts +4 -0
  120. package/bin/esm/types/index.d.ts.map +1 -0
  121. package/bin/esm/types/index.js +4 -0
  122. package/bin/esm/types/index.js.map +1 -0
  123. package/bin/esm/utils/index.d.ts +2 -0
  124. package/bin/esm/utils/index.d.ts.map +1 -0
  125. package/bin/esm/utils/index.js +2 -0
  126. package/bin/esm/utils/index.js.map +1 -0
  127. package/bin/esm/utils/type-check.d.ts.map +1 -0
  128. package/bin/{utils → esm/utils}/type-check.js +1 -1
  129. package/bin/esm/utils/type-check.js.map +1 -0
  130. package/package.json +51 -47
  131. package/src/index.ts +6 -6
  132. package/src/interfaces/index.ts +1 -1
  133. package/src/internal/index.ts +2 -2
  134. package/src/internal/type-guards.ts +1 -1
  135. package/src/live-hooks/index.ts +7 -7
  136. package/src/live-hooks/useLiveCanvas.ts +154 -82
  137. package/src/live-hooks/useLiveEvent.ts +43 -7
  138. package/src/live-hooks/useLiveFollowMode.ts +149 -6
  139. package/src/live-hooks/useLivePresence.ts +80 -17
  140. package/src/live-hooks/useLiveState.ts +54 -6
  141. package/src/live-hooks/useLiveTimer.ts +59 -4
  142. package/src/live-hooks/useMediaSynchronizer.ts +71 -6
  143. package/src/providers/AzureProvider.tsx +21 -21
  144. package/src/providers/LiveShareProvider.tsx +115 -13
  145. package/src/providers/index.ts +2 -2
  146. package/src/shared-hooks/index.ts +6 -4
  147. package/src/shared-hooks/internals/tree-node-constants.ts +2 -0
  148. package/src/shared-hooks/internals/tree-node-types.ts +26 -0
  149. package/src/shared-hooks/internals/tree-node-utils.ts +269 -0
  150. package/src/shared-hooks/useDynamicDDS.ts +28 -17
  151. package/src/shared-hooks/useSharedMap.ts +42 -17
  152. package/src/shared-hooks/useSharedState.ts +6 -3
  153. package/src/shared-hooks/useSharedStateRegistry.ts +44 -22
  154. package/src/shared-hooks/useSharedTree.ts +144 -0
  155. package/src/shared-hooks/useTreeNode.ts +147 -0
  156. package/src/types/ActionTypes.ts +13 -9
  157. package/src/types/FluidMap.ts +169 -0
  158. package/src/types/PropTypes.ts +57 -0
  159. package/src/types/ResultTypes.ts +88 -17
  160. package/src/types/index.ts +3 -3
  161. package/src/utils/index.ts +1 -1
  162. package/tsconfig.json +64 -70
  163. package/.nycrc.json +0 -10
  164. package/bin/index.d.ts +0 -7
  165. package/bin/index.d.ts.map +0 -1
  166. package/bin/index.js +0 -7
  167. package/bin/index.js.map +0 -1
  168. package/bin/interfaces/LiveInterfaceExtensions.d.ts.map +0 -1
  169. package/bin/interfaces/LiveInterfaceExtensions.js.map +0 -1
  170. package/bin/interfaces/index.d.ts +0 -2
  171. package/bin/interfaces/index.d.ts.map +0 -1
  172. package/bin/interfaces/index.js +0 -2
  173. package/bin/interfaces/index.js.map +0 -1
  174. package/bin/internal/errors.d.ts.map +0 -1
  175. package/bin/internal/errors.js.map +0 -1
  176. package/bin/internal/index.d.ts +0 -3
  177. package/bin/internal/index.d.ts.map +0 -1
  178. package/bin/internal/index.js +0 -3
  179. package/bin/internal/index.js.map +0 -1
  180. package/bin/internal/type-guards.d.ts.map +0 -1
  181. package/bin/internal/type-guards.js.map +0 -1
  182. package/bin/live-hooks/index.d.ts +0 -8
  183. package/bin/live-hooks/index.d.ts.map +0 -1
  184. package/bin/live-hooks/index.js +0 -8
  185. package/bin/live-hooks/index.js.map +0 -1
  186. package/bin/live-hooks/useLiveCanvas.d.ts +0 -29
  187. package/bin/live-hooks/useLiveCanvas.d.ts.map +0 -1
  188. package/bin/live-hooks/useLiveCanvas.js +0 -160
  189. package/bin/live-hooks/useLiveCanvas.js.map +0 -1
  190. package/bin/live-hooks/useLiveEvent.d.ts.map +0 -1
  191. package/bin/live-hooks/useLiveEvent.js.map +0 -1
  192. package/bin/live-hooks/useLiveFollowMode.d.ts +0 -24
  193. package/bin/live-hooks/useLiveFollowMode.d.ts.map +0 -1
  194. package/bin/live-hooks/useLiveFollowMode.js.map +0 -1
  195. package/bin/live-hooks/useLivePresence.d.ts +0 -26
  196. package/bin/live-hooks/useLivePresence.d.ts.map +0 -1
  197. package/bin/live-hooks/useLivePresence.js.map +0 -1
  198. package/bin/live-hooks/useLiveState.d.ts.map +0 -1
  199. package/bin/live-hooks/useLiveState.js.map +0 -1
  200. package/bin/live-hooks/useLiveTimer.d.ts.map +0 -1
  201. package/bin/live-hooks/useLiveTimer.js.map +0 -1
  202. package/bin/live-hooks/useMediaSynchronizer.d.ts +0 -25
  203. package/bin/live-hooks/useMediaSynchronizer.d.ts.map +0 -1
  204. package/bin/live-hooks/useMediaSynchronizer.js.map +0 -1
  205. package/bin/providers/AzureProvider.d.ts.map +0 -1
  206. package/bin/providers/AzureProvider.js.map +0 -1
  207. package/bin/providers/LiveShareProvider.d.ts.map +0 -1
  208. package/bin/providers/LiveShareProvider.js +0 -95
  209. package/bin/providers/LiveShareProvider.js.map +0 -1
  210. package/bin/providers/index.d.ts +0 -3
  211. package/bin/providers/index.d.ts.map +0 -1
  212. package/bin/providers/index.js +0 -3
  213. package/bin/providers/index.js.map +0 -1
  214. package/bin/shared-hooks/index.d.ts +0 -5
  215. package/bin/shared-hooks/index.d.ts.map +0 -1
  216. package/bin/shared-hooks/index.js +0 -5
  217. package/bin/shared-hooks/index.js.map +0 -1
  218. package/bin/shared-hooks/useDynamicDDS.d.ts.map +0 -1
  219. package/bin/shared-hooks/useDynamicDDS.js.map +0 -1
  220. package/bin/shared-hooks/useSharedMap.d.ts.map +0 -1
  221. package/bin/shared-hooks/useSharedMap.js.map +0 -1
  222. package/bin/shared-hooks/useSharedState.d.ts.map +0 -1
  223. package/bin/shared-hooks/useSharedState.js.map +0 -1
  224. package/bin/shared-hooks/useSharedStateRegistry.d.ts.map +0 -1
  225. package/bin/shared-hooks/useSharedStateRegistry.js.map +0 -1
  226. package/bin/types/ActionTypes.d.ts.map +0 -1
  227. package/bin/types/ActionTypes.js.map +0 -1
  228. package/bin/types/PropTypes.d.ts +0 -8
  229. package/bin/types/PropTypes.d.ts.map +0 -1
  230. package/bin/types/PropTypes.js.map +0 -1
  231. package/bin/types/ResultTypes.d.ts.map +0 -1
  232. package/bin/types/ResultTypes.js.map +0 -1
  233. package/bin/types/index.d.ts +0 -4
  234. package/bin/types/index.d.ts.map +0 -1
  235. package/bin/types/index.js +0 -4
  236. package/bin/types/index.js.map +0 -1
  237. package/bin/utils/index.d.ts +0 -2
  238. package/bin/utils/index.d.ts.map +0 -1
  239. package/bin/utils/index.js +0 -2
  240. package/bin/utils/index.js.map +0 -1
  241. package/bin/utils/type-check.d.ts.map +0 -1
  242. package/bin/utils/type-check.js.map +0 -1
  243. package/tsconfig.build.json +0 -6
  244. /package/bin/{interfaces → esm/interfaces}/LiveInterfaceExtensions.d.ts +0 -0
  245. /package/bin/{interfaces → esm/interfaces}/LiveInterfaceExtensions.js +0 -0
  246. /package/bin/{internal → esm/internal}/errors.d.ts +0 -0
  247. /package/bin/{internal → esm/internal}/errors.js +0 -0
  248. /package/bin/{internal → esm/internal}/type-guards.js +0 -0
  249. /package/bin/{types → esm/types}/ActionTypes.js +0 -0
  250. /package/bin/{types → esm/types}/PropTypes.js +0 -0
  251. /package/bin/{types → esm/types}/ResultTypes.js +0 -0
  252. /package/bin/{utils → esm/utils}/type-check.d.ts +0 -0
@@ -0,0 +1,196 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import React from "react";
3
+ import { useSharedStateRegistry } from "../shared-hooks/index.js";
4
+ import { LiveShareClient, } from "@microsoft/live-share";
5
+ import { FluidContext } from "./AzureProvider.js";
6
+ import { isITeamsJsSdkError } from "../internal/index.js";
7
+ /**
8
+ * @hidden
9
+ */
10
+ export const LiveShareContext = React.createContext({});
11
+ /**
12
+ * Hook to get the latest React context state for `LiveShareContext`.
13
+ *
14
+ * @remarks
15
+ * This hook can only be used in a child component of `<LiveShareProvider>`.
16
+ * See `useFluidObjectsContext` for other information related to the Live Share session, such as the `container`.
17
+ *
18
+ * @returns current state of `LiveShareContext`
19
+ *
20
+ * @example
21
+ ```jsx
22
+ // LiveShareApp.jsx
23
+ import { LiveShareProvider } from "@microsoft/live-share-react";
24
+ import { LiveShareHost } from "@microsoft/teams-js";
25
+
26
+ const host = LiveShareHost.create();
27
+
28
+ export function LiveShareApp() {
29
+ // Call app.initialize() from teams-js before rendering LiveShareProvider
30
+
31
+ return (
32
+ <LiveShareProvider
33
+ joinOnLoad={true}
34
+ host={host}
35
+ >
36
+ <LiveShareLoader>
37
+ <LiveCheckbox />
38
+ </LiveShareLoader>
39
+ </LiveShareProvider>
40
+ );
41
+ }
42
+
43
+ // LiveShareLoader.jsx
44
+ import { useLiveShareContext } from "@microsoft/live-share-react";
45
+
46
+ export function LiveShareLoader({ children }) {
47
+ const { joined, joinError } = useLiveShareContext();
48
+
49
+ if (joinError) return <>{joinError.message}</>;
50
+ if (!joined) return <>Joining Live Share session...</>;
51
+ return <>{children}</>
52
+ }
53
+
54
+ // LiveCheckbox.jsx
55
+ import { useLiveState } from "@microsoft/live-share-react";
56
+
57
+ export function LiveCheckbox() {
58
+ const [checked, setChecked] = useLiveState("MY-UNIQUE-ID", false);
59
+ return (
60
+ <input
61
+ type="checkbox"
62
+ checked={checked}
63
+ onChange={() => {
64
+ setChecked(!checked);
65
+ }}
66
+ />
67
+ );
68
+ }
69
+ ```
70
+ */
71
+ export const useLiveShareContext = () => {
72
+ const context = React.useContext(LiveShareContext);
73
+ if (!isLiveShareContext(context)) {
74
+ 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>`.");
75
+ }
76
+ return context;
77
+ };
78
+ /**
79
+ * React Context provider component for using Live Share data objects & joining a Live Share session using `LiveShareClient`.
80
+ *
81
+ * @example
82
+ ```jsx
83
+ // LiveShareApp.jsx
84
+ import { LiveShareProvider } from "@microsoft/live-share-react";
85
+ import { LiveShareHost } from "@microsoft/teams-js";
86
+
87
+ const host = LiveShareHost.create();
88
+
89
+ export function LiveShareApp() {
90
+ // Call app.initialize() from teams-js before rendering LiveShareProvider
91
+
92
+ return (
93
+ <LiveShareProvider
94
+ joinOnLoad={true}
95
+ host={host}
96
+ >
97
+ <LiveShareLoader>
98
+ <LiveCheckbox />
99
+ </LiveShareLoader>
100
+ </LiveShareProvider>
101
+ );
102
+ }
103
+
104
+ // LiveShareLoader.jsx
105
+ import { useLiveShareContext } from "@microsoft/live-share-react";
106
+
107
+ export function LiveShareLoader({ children }) {
108
+ const { joined, joinError } = useLiveShareContext();
109
+
110
+ if (joinError) return <>{joinError.message}</>;
111
+ if (!joined) return <>Joining Live Share session...</>;
112
+ return <>{children}</>
113
+ }
114
+
115
+ // LiveCheckbox.jsx
116
+ import { useLiveState } from "@microsoft/live-share-react";
117
+
118
+ export function LiveCheckbox() {
119
+ const [checked, setChecked] = useLiveState("MY-UNIQUE-ID", false);
120
+ return (
121
+ <input
122
+ type="checkbox"
123
+ checked={checked}
124
+ onChange={() => {
125
+ setChecked(!checked);
126
+ }}
127
+ />
128
+ );
129
+ }
130
+ ```
131
+ */
132
+ export const LiveShareProvider = (props) => {
133
+ const startedRef = React.useRef(false);
134
+ const clientRef = React.useRef(new LiveShareClient(props.host, props.clientOptions));
135
+ const [results, setResults] = React.useState();
136
+ const [joinError, setJoinError] = React.useState();
137
+ const stateRegistryCallbacks = useSharedStateRegistry(results);
138
+ /**
139
+ * Join container callback for joining the Live Share session
140
+ */
141
+ const join = React.useCallback(async (fluidContainerSchema, onInitializeContainer) => {
142
+ startedRef.current = true;
143
+ const results = await clientRef.current.join(fluidContainerSchema, onInitializeContainer);
144
+ setResults(results);
145
+ return results;
146
+ }, []);
147
+ /**
148
+ * Joins the container on load if `props.joinOnLoad` is true
149
+ */
150
+ React.useEffect(() => {
151
+ // This hook should only be called once, so we use a ref to track if it has been called.
152
+ // This is a workaround for the fact that useEffect is called twice on initial render in React V18.
153
+ // We are not doing this here for backwards compatibility. View the README for more information.
154
+ if (results !== undefined || startedRef.current || !props.joinOnLoad)
155
+ return;
156
+ join(props.fluidContainerSchema).catch((error) => {
157
+ console.error(error);
158
+ if (error instanceof Error) {
159
+ setJoinError(error);
160
+ }
161
+ else if (isITeamsJsSdkError(error)) {
162
+ setJoinError(new Error(`[${error.errorCode}] ${error.message ??
163
+ "An unknown error occurred while joining container."}`));
164
+ }
165
+ else if (typeof error == "string") {
166
+ setJoinError(new Error(error));
167
+ }
168
+ else {
169
+ setJoinError(new Error("LiveShareProvider: An unknown error occurred while joining container."));
170
+ }
171
+ });
172
+ }, [results, props.joinOnLoad, props.fluidContainerSchema, join]);
173
+ return (_jsx(LiveShareContext.Provider, { value: {
174
+ created: !!results?.created,
175
+ timestampProvider: results?.timestampProvider,
176
+ joined: !!results?.container,
177
+ joinError,
178
+ join,
179
+ }, children: _jsx(FluidContext.Provider, { value: {
180
+ clientRef,
181
+ container: results?.container,
182
+ services: results?.services,
183
+ joinError,
184
+ getContainer: async () => {
185
+ throw new Error("Cannot join new container through getContainer in LiveShareProvider");
186
+ },
187
+ createContainer: async () => {
188
+ throw new Error("Cannot create new container through createContainer in LiveShareProvider");
189
+ },
190
+ ...stateRegistryCallbacks,
191
+ }, children: props.children }) }));
192
+ };
193
+ function isLiveShareContext(value) {
194
+ return (typeof value?.created === "boolean" && typeof value?.join === "function");
195
+ }
196
+ //# sourceMappingURL=LiveShareProvider.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"LiveShareProvider.js","sourceRoot":"","sources":["../../../src/providers/LiveShareProvider.tsx"],"names":[],"mappings":";AAMA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAClE,OAAO,EAKH,eAAe,GAClB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,YAAY,EAA0B,MAAM,oBAAoB,CAAC;AAC1E,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AA2C1D;;GAEG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,KAAK,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IAAI;SACP,YAED,KAAC,YAAY,CAAC,QAAQ,IAClB,KAAK,EAAE;gBACH,SAAS;gBACT,SAAS,EAAE,OAAO,EAAE,SAAS;gBAC7B,QAAQ,EAAE,OAAO,EAAE,QAAQ;gBAC3B,SAAS;gBACT,YAAY,EAAE,KAAK,IAAI,EAAE;oBACrB,MAAM,IAAI,KAAK,CACX,qEAAqE,CACxE,CAAC;gBACN,CAAC;gBACD,eAAe,EAAE,KAAK,IAAI,EAAE;oBACxB,MAAM,IAAI,KAAK,CACX,0EAA0E,CAC7E,CAAC;gBACN,CAAC;gBACD,GAAG,sBAAsB;aAC5B,YAEA,KAAK,CAAC,QAAQ,GACK,GACA,CAC/B,CAAC;AACN,CAAC,CAAC;AAEF,SAAS,kBAAkB,CAAC,KAAU;IAClC,OAAO,CACH,OAAO,KAAK,EAAE,OAAO,KAAK,SAAS,IAAI,OAAO,KAAK,EAAE,IAAI,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"}
@@ -0,0 +1,3 @@
1
+ export * from "./AzureProvider.js";
2
+ export * from "./LiveShareProvider.js";
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/providers/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AACnC,cAAc,wBAAwB,CAAC"}
@@ -0,0 +1,7 @@
1
+ export * from "./useSharedState.js";
2
+ export * from "./useSharedMap.js";
3
+ export * from "./useDynamicDDS.js";
4
+ export * from "./useSharedStateRegistry.js";
5
+ export * from "./useSharedTree.js";
6
+ export * from "./useTreeNode.js";
7
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/shared-hooks/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC;AACpC,cAAc,mBAAmB,CAAC;AAClC,cAAc,oBAAoB,CAAC;AACnC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,oBAAoB,CAAC;AACnC,cAAc,kBAAkB,CAAC"}
@@ -0,0 +1,7 @@
1
+ export * from "./useSharedState.js";
2
+ export * from "./useSharedMap.js";
3
+ export * from "./useDynamicDDS.js";
4
+ export * from "./useSharedStateRegistry.js";
5
+ export * from "./useSharedTree.js";
6
+ export * from "./useTreeNode.js";
7
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/shared-hooks/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC;AACpC,cAAc,mBAAmB,CAAC;AAClC,cAAc,oBAAoB,CAAC;AACnC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,oBAAoB,CAAC;AACnC,cAAc,kBAAkB,CAAC"}
@@ -0,0 +1,3 @@
1
+ export declare const rawTNodeKey = "[[FluidTreeNode]]";
2
+ export declare const proxiedChildrenKey = "[[FluidChildNodes]]";
3
+ //# sourceMappingURL=tree-node-constants.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tree-node-constants.d.ts","sourceRoot":"","sources":["../../../../src/shared-hooks/internals/tree-node-constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,WAAW,sBAAsB,CAAC;AAC/C,eAAO,MAAM,kBAAkB,wBAAwB,CAAC"}
@@ -0,0 +1,3 @@
1
+ export const rawTNodeKey = "[[FluidTreeNode]]";
2
+ export const proxiedChildrenKey = "[[FluidChildNodes]]";
3
+ //# sourceMappingURL=tree-node-constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tree-node-constants.js","sourceRoot":"","sources":["../../../../src/shared-hooks/internals/tree-node-constants.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,WAAW,GAAG,mBAAmB,CAAC;AAC/C,MAAM,CAAC,MAAM,kBAAkB,GAAG,qBAAqB,CAAC"}
@@ -0,0 +1,10 @@
1
+ import { TreeNode } from "fluid-framework";
2
+ import { proxiedChildrenKey, rawTNodeKey } from "./tree-node-constants.js";
3
+ export interface ICustomProxyHandler<TNode extends TreeNode = TreeNode> {
4
+ [rawTNodeKey]: TNode;
5
+ [proxiedChildrenKey]: Record<string, TreeNode>;
6
+ }
7
+ export declare function isProxy(value: any): value is typeof Proxy;
8
+ export declare function isCustomProxyHandler<TNode extends TreeNode = TreeNode>(value: any): value is ICustomProxyHandler<TNode>;
9
+ export declare function isTreeNode(value: any): value is TreeNode;
10
+ //# sourceMappingURL=tree-node-types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tree-node-types.d.ts","sourceRoot":"","sources":["../../../../src/shared-hooks/internals/tree-node-types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAQ,MAAM,iBAAiB,CAAC;AACjD,OAAO,EAAE,kBAAkB,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAE3E,MAAM,WAAW,mBAAmB,CAAC,KAAK,SAAS,QAAQ,GAAG,QAAQ;IAClE,CAAC,WAAW,CAAC,EAAE,KAAK,CAAC;IACrB,CAAC,kBAAkB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;CAClD;AAED,wBAAgB,OAAO,CAAC,KAAK,EAAE,GAAG,GAAG,KAAK,IAAI,OAAO,KAAK,CAEzD;AAED,wBAAgB,oBAAoB,CAAC,KAAK,SAAS,QAAQ,GAAG,QAAQ,EAClE,KAAK,EAAE,GAAG,GACX,KAAK,IAAI,mBAAmB,CAAC,KAAK,CAAC,CAErC;AAED,wBAAgB,UAAU,CAAC,KAAK,EAAE,GAAG,GAAG,KAAK,IAAI,QAAQ,CAOxD"}
@@ -0,0 +1,18 @@
1
+ import { Tree } from "fluid-framework";
2
+ import { proxiedChildrenKey, rawTNodeKey } from "./tree-node-constants.js";
3
+ export function isProxy(value) {
4
+ return value && value["[[Handler]]"];
5
+ }
6
+ export function isCustomProxyHandler(value) {
7
+ return value?.[rawTNodeKey] !== undefined;
8
+ }
9
+ export function isTreeNode(value) {
10
+ try {
11
+ Tree.schema(value);
12
+ return true;
13
+ }
14
+ catch (_) {
15
+ return false;
16
+ }
17
+ }
18
+ //# sourceMappingURL=tree-node-types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tree-node-types.js","sourceRoot":"","sources":["../../../../src/shared-hooks/internals/tree-node-types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,IAAI,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,EAAE,kBAAkB,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAO3E,MAAM,UAAU,OAAO,CAAC,KAAU;IAC9B,OAAO,KAAK,IAAI,KAAK,CAAC,aAAa,CAAC,CAAC;AACzC,CAAC;AAED,MAAM,UAAU,oBAAoB,CAChC,KAAU;IAEV,OAAO,KAAK,EAAE,CAAC,WAAW,CAAC,KAAK,SAAS,CAAC;AAC9C,CAAC;AAED,MAAM,UAAU,UAAU,CAAC,KAAU;IACjC,IAAI,CAAC;QACD,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QACnB,OAAO,IAAI,CAAC;IAChB,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACT,OAAO,KAAK,CAAC;IACjB,CAAC;AACL,CAAC"}
@@ -0,0 +1,33 @@
1
+ import { TreeNode } from "fluid-framework";
2
+ import { Dispatch, SetStateAction } from "react";
3
+ /**
4
+ * @internal
5
+ * Build a proxied version of a node and set its value to the treeMap provided
6
+ *
7
+ * @param rawNode the raw proxy node exposed by Fluid
8
+ * @param treeMap a map where Fluid's proxy node is mapped to our proxied node
9
+ * @returns TNode instance
10
+ */
11
+ export declare function buildProxy<TNode extends TreeNode = TreeNode>(rawNode: TNode, treeMap: WeakMap<TreeNode, TreeNode>): TNode;
12
+ /**
13
+ * @internal
14
+ * Set up listeners for a given TreeNode.
15
+ * Will recursively call this function for all children nodes of each children until there are no more child nodes.
16
+ *
17
+ * @param parentRawNode raw parent node
18
+ * @param rootNodeForListener root node being listened to in useTreeNode
19
+ * @param treeMap a map where Fluid's proxy node is mapped to our proxied node
20
+ * @param unsubscribeListeners list of unsubscribe listeners, where we set the unsubscribe callbacks
21
+ * @param setProxyNode setter to set the root proxy node listened to in useTreeNode
22
+ */
23
+ export declare function setUpListenersForNodeChildren<TNode extends TreeNode = TreeNode>(parentRawNode: TreeNode, rootNodeForListener: TreeNode, treeMap: WeakMap<TreeNode, TreeNode>, unsubscribeListeners: (() => void)[], setProxyNode: Dispatch<SetStateAction<TNode>>): void;
24
+ /**
25
+ * @internal
26
+ * Fluid only knows how to work with their proxied version of a TreeNode.
27
+ * We store a reference to that node in our proxied instances so we can easily use it when working with Fluid APIs.
28
+ *
29
+ * @param node get the raw node from the proxy
30
+ * @returns the raw proxied node that Fluid expects
31
+ */
32
+ export declare function getRawNode<TNode extends TreeNode | undefined = TreeNode>(node: TNode): TNode;
33
+ //# sourceMappingURL=tree-node-utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tree-node-utils.d.ts","sourceRoot":"","sources":["../../../../src/shared-hooks/internals/tree-node-utils.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,QAAQ,EAAQ,MAAM,iBAAiB,CAAC;AACjD,OAAO,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,OAAO,CAAC;AAIjD;;;;;;;GAOG;AACH,wBAAgB,UAAU,CAAC,KAAK,SAAS,QAAQ,GAAG,QAAQ,EACxD,OAAO,EAAE,KAAK,EACd,OAAO,EAAE,OAAO,CAAC,QAAQ,EAAE,QAAQ,CAAC,GACrC,KAAK,CAwCP;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,6BAA6B,CACzC,KAAK,SAAS,QAAQ,GAAG,QAAQ,EAEjC,aAAa,EAAE,QAAQ,EACvB,mBAAmB,EAAE,QAAQ,EAC7B,OAAO,EAAE,OAAO,CAAC,QAAQ,EAAE,QAAQ,CAAC,EACpC,oBAAoB,EAAE,CAAC,MAAM,IAAI,CAAC,EAAE,EACpC,YAAY,EAAE,QAAQ,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC,QAmChD;AAED;;;;;;;GAOG;AACH,wBAAgB,UAAU,CAAC,KAAK,SAAS,QAAQ,GAAG,SAAS,GAAG,QAAQ,EACpE,IAAI,EAAE,KAAK,GACZ,KAAK,CAKP"}
@@ -0,0 +1,186 @@
1
+ import { proxiedChildrenKey, rawTNodeKey } from "./tree-node-constants.js";
2
+ import { isCustomProxyHandler, isTreeNode, isProxy, } from "./tree-node-types.js";
3
+ import { Tree } from "fluid-framework";
4
+ // Exported utils
5
+ /**
6
+ * @internal
7
+ * Build a proxied version of a node and set its value to the treeMap provided
8
+ *
9
+ * @param rawNode the raw proxy node exposed by Fluid
10
+ * @param treeMap a map where Fluid's proxy node is mapped to our proxied node
11
+ * @returns TNode instance
12
+ */
13
+ export function buildProxy(rawNode, treeMap) {
14
+ const previousProxy = treeMap.get(rawNode);
15
+ const previousProxyHandler = previousProxy
16
+ ? getCustomProxyHandler(previousProxy)
17
+ : undefined;
18
+ const proxyHandler = {
19
+ // Add some extra stuff into the handler so we can store the original Fluid TreeNode and access it later
20
+ // Without overriding the rest of the getters in the object.
21
+ [rawTNodeKey]: rawNode,
22
+ [proxiedChildrenKey]: previousProxyHandler?.[proxiedChildrenKey] ?? {},
23
+ get: (target, prop, _) => {
24
+ if (prop === "[[Handler]]") {
25
+ return proxyHandler;
26
+ }
27
+ if (typeof prop === "string" &&
28
+ proxyHandler[proxiedChildrenKey][prop]) {
29
+ return proxyHandler[proxiedChildrenKey][prop];
30
+ }
31
+ // pass in the rawNode so Fluid doesn't get confused by our proxy object and can find the flex node
32
+ const value = Reflect.get(target, prop, rawNode);
33
+ return typeof value === "function" &&
34
+ typeof prop === "string" &&
35
+ // TODO: need a better way of identifying which types of functions need to be proxied
36
+ // This is because if a developer uses an array prototype function, we need to return proxied
37
+ // objects so React can detect changes to those nodes...
38
+ !["map", "flatMap", "filter", "find", "indexOf"].includes(prop)
39
+ ? value.bind(rawNode)
40
+ : value;
41
+ },
42
+ set(target, p, newValue, _) {
43
+ return Reflect.set(target, p, newValue, rawNode);
44
+ },
45
+ };
46
+ const proxy = new Proxy(rawNode, proxyHandler);
47
+ // Track the proxy for the rawNode
48
+ treeMap.set(rawNode, proxy);
49
+ // Set raw node getter so we can access it before things like Tree.on
50
+ return proxy;
51
+ }
52
+ /**
53
+ * @internal
54
+ * Set up listeners for a given TreeNode.
55
+ * Will recursively call this function for all children nodes of each children until there are no more child nodes.
56
+ *
57
+ * @param parentRawNode raw parent node
58
+ * @param rootNodeForListener root node being listened to in useTreeNode
59
+ * @param treeMap a map where Fluid's proxy node is mapped to our proxied node
60
+ * @param unsubscribeListeners list of unsubscribe listeners, where we set the unsubscribe callbacks
61
+ * @param setProxyNode setter to set the root proxy node listened to in useTreeNode
62
+ */
63
+ export function setUpListenersForNodeChildren(parentRawNode, rootNodeForListener, treeMap, unsubscribeListeners, setProxyNode) {
64
+ let entries = Object.entries(parentRawNode);
65
+ for (let i = 0; i < entries.length; i++) {
66
+ const [key, entry] = entries[i];
67
+ if (!entry ||
68
+ ["string", "boolean", "number", "function"].includes(typeof entry) ||
69
+ !isTreeNode(entry)) {
70
+ continue;
71
+ }
72
+ const rawEntry = getRawNode(entry);
73
+ const onNodeChanged = () => {
74
+ onTreeNodeChanged(key, rawEntry, rootNodeForListener, treeMap, setProxyNode);
75
+ };
76
+ const unsubscribe = Tree.on(rawEntry, "nodeChanged", onNodeChanged);
77
+ unsubscribeListeners.push(unsubscribe);
78
+ // Recursively listen to children nodes of this node
79
+ setUpListenersForNodeChildren(rawEntry, rootNodeForListener, treeMap, unsubscribeListeners, setProxyNode);
80
+ }
81
+ }
82
+ /**
83
+ * @internal
84
+ * Fluid only knows how to work with their proxied version of a TreeNode.
85
+ * We store a reference to that node in our proxied instances so we can easily use it when working with Fluid APIs.
86
+ *
87
+ * @param node get the raw node from the proxy
88
+ * @returns the raw proxied node that Fluid expects
89
+ */
90
+ export function getRawNode(node) {
91
+ if (isProxy(node)) {
92
+ return getRawNodeFromProxy(node);
93
+ }
94
+ return node;
95
+ }
96
+ // Non public utils
97
+ /**
98
+ * Callback for when a tree node changed
99
+ *
100
+ * @param key key where the object is stored in the parent
101
+ * @param rawNode the raw node that changed
102
+ * @param rootNodeForListener the root node that is being listened to in useTreeNode
103
+ * @param treeMap a map where Fluid's proxy node is mapped to our proxied node
104
+ * @param setProxyNode setter to set the root proxy node listened to in useTreeNode
105
+ */
106
+ function onTreeNodeChanged(key, rawNode, rootNodeForListener, treeMap, setProxyNode) {
107
+ const proxyNode = buildProxy(rawNode, treeMap);
108
+ const parent = Tree.parent(rawNode);
109
+ if (!parent) {
110
+ throw new Error("useTreeNode onTreeNodeChanged: no parent found for rawParentNode");
111
+ }
112
+ proxyParentForNode(key, parent, proxyNode, rootNodeForListener, treeMap, setProxyNode);
113
+ }
114
+ /**
115
+ * Proxies the parent and sets reference to the child node that changed.
116
+ *
117
+ * @param key key where the object is referenced in its parent node
118
+ * @param rawParentNode raw parent tree node
119
+ * @param proxyNode proxied instance of the node that changed
120
+ * @param rootNodeForListener root node listened to in useTreeNode
121
+ * @param treeMap a map where Fluid's proxy node is mapped to our proxied node
122
+ * @param setProxyNode setter to set the root proxy node listened to in useTreeNode
123
+ */
124
+ function proxyParentForNode(key, rawParentNode, proxyNode, rootNodeForListener, treeMap, setProxyNode) {
125
+ const parentProxy = buildProxy(rawParentNode, treeMap);
126
+ let parentProxyHandler = getCustomProxyHandler(parentProxy);
127
+ if (!parentProxyHandler) {
128
+ throw new Error("useTreeNode proxyParentForNode: unexpected error, should always find valid proxy handler");
129
+ }
130
+ parentProxyHandler[proxiedChildrenKey][key] = proxyNode;
131
+ if (rawParentNode === rootNodeForListener) {
132
+ setProxyNode(parentProxy);
133
+ }
134
+ else {
135
+ const parentOfParent = Tree.parent(rawParentNode);
136
+ if (!parentOfParent) {
137
+ throw new Error("useTreeNode proxyParentForNode: no parent found for rawParentNode");
138
+ }
139
+ const parentKey = findKeyOfNode(rawParentNode, parentOfParent);
140
+ proxyParentForNode(parentKey, parentOfParent, parentProxy, rootNodeForListener, treeMap, setProxyNode);
141
+ }
142
+ }
143
+ /**
144
+ * Returns key where parent[key] == nodeToCheck
145
+ *
146
+ * @param nodeToCheck tree node to check
147
+ * @param parent parent node where nodeToCheck is a child of
148
+ * @returns the key for node
149
+ */
150
+ function findKeyOfNode(nodeToCheck, parent) {
151
+ let entries = Object.entries(parent);
152
+ for (let i = 0; i < entries.length; i++) {
153
+ const [key, entry] = entries[i];
154
+ if (!entry ||
155
+ ["string", "boolean", "number", "function"].includes(typeof entry) ||
156
+ !isTreeNode(entry)) {
157
+ continue;
158
+ }
159
+ if (entry === nodeToCheck)
160
+ return key;
161
+ }
162
+ throw new Error("Did not find node as a child of parent");
163
+ }
164
+ // Type utils
165
+ /**
166
+ * Gets the proxy handler for a given TreeNode, assuming `isCustomProxyHandler` returns true.
167
+ * @param proxy the proxied TreeNode to get the handler for.
168
+ * @returns the handler if valid, otherwise undefined
169
+ */
170
+ function getCustomProxyHandler(proxy) {
171
+ const handler = proxy["[[Handler]]"];
172
+ if (isCustomProxyHandler(handler)) {
173
+ return handler;
174
+ }
175
+ return undefined;
176
+ }
177
+ /**
178
+ * Gets the raw node for a given proxied tree node
179
+ *
180
+ * @param proxy the proxied TreeNode to get the raw node for
181
+ * @returns the raw node if valid, otherwise undefined
182
+ */
183
+ function getRawNodeFromProxy(proxy) {
184
+ return getCustomProxyHandler(proxy)?.[rawTNodeKey];
185
+ }
186
+ //# sourceMappingURL=tree-node-utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file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AI,KAAK,CAAC,wCAAwC,CAAC,CAAC;AAC9D,CAAC;AAED,aAAa;AAEb;;;;GAIG;AACH,SAAS,qBAAqB,CAAC,KAAe;IAC1C,MAAM,OAAO,GAAI,KAAa,CAAC,aAAa,CAAC,CAAC;IAC9C,IAAI,oBAAoB,CAAC,OAAO,CAAC,EAAE,CAAC;QAChC,OAAO,OAAO,CAAC;IACnB,CAAC;IACD,OAAO,SAAS,CAAC;AACrB,CAAC;AAED;;;;;GAKG;AACH,SAAS,mBAAmB,CAAC,KAAe;IACxC,OAAO,qBAAqB,CAAC,KAAK,CAAC,EAAE,CAAC,WAAW,CAAC,CAAC;AACvD,CAAC"}
@@ -3,20 +3,20 @@
3
3
  * Licensed under the Microsoft Live Share SDK License.
4
4
  */
5
5
  import { FluidObject, IFluidLoadable } from "@fluidframework/core-interfaces";
6
- import { LoadableObjectClass } from "fluid-framework";
6
+ import { SharedObjectKind } from "fluid-framework";
7
7
  /**
8
8
  * Hook to gets or creates a DDS that corresponds to a given uniqueKey string.
9
9
  *
10
10
  * @remarks
11
11
  * This hook can only be used in a child component of `<LiveShareProvider>` or `<AzureProvider>`.
12
12
  *
13
- * @template T Type of Fluid LoadableObjectClass type to load. Must conform to IFluidLoadable interface.
13
+ * @template T Type of Fluid SharedObjectKind type to load. Must conform to IFluidLoadable interface.
14
14
  * @param uniqueKey uniqueKey value for the data object
15
- * @param loadableObjectClass Fluid LoadableObjectClass<T> to create/load.
15
+ * @param objectKind Fluid SharedObjectKind<T> to create/load.
16
16
  * @param onFirstInitialize Optional. Callback function for when the DDS is first loaded
17
17
  * @returns the DDS object, which is of type T when loaded and undefined while loading
18
18
  */
19
- export declare function useDynamicDDS<T extends IFluidLoadable = FluidObject<any> & IFluidLoadable>(uniqueKey: string, loadableObjectClass: LoadableObjectClass<T>, onFirstInitialize?: (dds: T) => void): {
19
+ export declare function useDynamicDDS<T extends IFluidLoadable = FluidObject<any> & IFluidLoadable>(uniqueKey: string, objectClass: SharedObjectKind<T>, onFirstInitialize?: (dds: T) => void): {
20
20
  dds: T | undefined;
21
21
  error: Error | undefined;
22
22
  };
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useDynamicDDS.d.ts","sourceRoot":"","sources":["../../../src/shared-hooks/useDynamicDDS.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,iCAAiC,CAAC;AAE9E,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAEnD;;;;;;;;;;;GAWG;AACH,wBAAgB,aAAa,CACzB,CAAC,SAAS,cAAc,GAAG,WAAW,CAAC,GAAG,CAAC,GAAG,cAAc,EAE5D,SAAS,EAAE,MAAM,EACjB,WAAW,EAAE,gBAAgB,CAAC,CAAC,CAAC,EAChC,iBAAiB,CAAC,EAAE,CAAC,GAAG,EAAE,CAAC,KAAK,IAAI,GACrC;IACC,GAAG,EAAE,CAAC,GAAG,SAAS,CAAC;IACnB,KAAK,EAAE,KAAK,GAAG,SAAS,CAAC;CAC5B,CA6DA"}