@microsoft/live-share-react 1.2.0-preview.1 → 1.2.2-preview.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 (65) hide show
  1. package/bin/internal/errors.d.ts.map +1 -1
  2. package/bin/internal/errors.js +7 -4
  3. package/bin/internal/errors.js.map +1 -1
  4. package/bin/live-hooks/useLiveCanvas.d.ts +1 -0
  5. package/bin/live-hooks/useLiveCanvas.d.ts.map +1 -1
  6. package/bin/live-hooks/useLiveCanvas.js +1 -0
  7. package/bin/live-hooks/useLiveCanvas.js.map +1 -1
  8. package/bin/live-hooks/useLiveEvent.d.ts +1 -0
  9. package/bin/live-hooks/useLiveEvent.d.ts.map +1 -1
  10. package/bin/live-hooks/useLiveEvent.js +1 -0
  11. package/bin/live-hooks/useLiveEvent.js.map +1 -1
  12. package/bin/live-hooks/useLiveFollowMode.d.ts +1 -0
  13. package/bin/live-hooks/useLiveFollowMode.d.ts.map +1 -1
  14. package/bin/live-hooks/useLiveFollowMode.js +7 -6
  15. package/bin/live-hooks/useLiveFollowMode.js.map +1 -1
  16. package/bin/live-hooks/useLivePresence.d.ts +1 -0
  17. package/bin/live-hooks/useLivePresence.d.ts.map +1 -1
  18. package/bin/live-hooks/useLivePresence.js +1 -0
  19. package/bin/live-hooks/useLivePresence.js.map +1 -1
  20. package/bin/live-hooks/useLiveState.d.ts +1 -0
  21. package/bin/live-hooks/useLiveState.d.ts.map +1 -1
  22. package/bin/live-hooks/useLiveState.js +1 -0
  23. package/bin/live-hooks/useLiveState.js.map +1 -1
  24. package/bin/live-hooks/useLiveTimer.d.ts +17 -0
  25. package/bin/live-hooks/useLiveTimer.d.ts.map +1 -1
  26. package/bin/live-hooks/useLiveTimer.js +17 -0
  27. package/bin/live-hooks/useLiveTimer.js.map +1 -1
  28. package/bin/live-hooks/useMediaSynchronizer.d.ts +1 -0
  29. package/bin/live-hooks/useMediaSynchronizer.d.ts.map +1 -1
  30. package/bin/live-hooks/useMediaSynchronizer.js +1 -0
  31. package/bin/live-hooks/useMediaSynchronizer.js.map +1 -1
  32. package/bin/providers/AzureProvider.d.ts +82 -3
  33. package/bin/providers/AzureProvider.d.ts.map +1 -1
  34. package/bin/providers/AzureProvider.js +17 -0
  35. package/bin/providers/AzureProvider.js.map +1 -1
  36. package/bin/providers/LiveShareProvider.d.ts +36 -8
  37. package/bin/providers/LiveShareProvider.d.ts.map +1 -1
  38. package/bin/providers/LiveShareProvider.js +18 -0
  39. package/bin/providers/LiveShareProvider.js.map +1 -1
  40. package/bin/shared-hooks/useDynamicDDS.d.ts +4 -0
  41. package/bin/shared-hooks/useDynamicDDS.d.ts.map +1 -1
  42. package/bin/shared-hooks/useDynamicDDS.js +4 -0
  43. package/bin/shared-hooks/useDynamicDDS.js.map +1 -1
  44. package/bin/shared-hooks/useSharedMap.d.ts +1 -0
  45. package/bin/shared-hooks/useSharedMap.d.ts.map +1 -1
  46. package/bin/shared-hooks/useSharedMap.js +1 -0
  47. package/bin/shared-hooks/useSharedMap.js.map +1 -1
  48. package/bin/shared-hooks/useSharedState.d.ts +1 -0
  49. package/bin/shared-hooks/useSharedState.d.ts.map +1 -1
  50. package/bin/shared-hooks/useSharedState.js +1 -0
  51. package/bin/shared-hooks/useSharedState.js.map +1 -1
  52. package/package.json +8 -8
  53. package/src/internal/errors.ts +15 -6
  54. package/src/live-hooks/useLiveCanvas.ts +1 -0
  55. package/src/live-hooks/useLiveEvent.ts +1 -0
  56. package/src/live-hooks/useLiveFollowMode.ts +7 -6
  57. package/src/live-hooks/useLivePresence.ts +1 -0
  58. package/src/live-hooks/useLiveState.ts +1 -0
  59. package/src/live-hooks/useLiveTimer.ts +17 -0
  60. package/src/live-hooks/useMediaSynchronizer.ts +1 -0
  61. package/src/providers/AzureProvider.tsx +91 -2
  62. package/src/providers/LiveShareProvider.tsx +48 -8
  63. package/src/shared-hooks/useDynamicDDS.ts +4 -0
  64. package/src/shared-hooks/useSharedMap.ts +1 -0
  65. package/src/shared-hooks/useSharedState.ts +1 -0
@@ -12,9 +12,16 @@ import {
12
12
  ILiveShareJoinResults,
13
13
  ITimestampProvider,
14
14
  } from "@microsoft/live-share";
15
- import { FluidContext } from "./AzureProvider";
15
+ import { FluidContext, useFluidObjectsContext } from "./AzureProvider";
16
16
  import { LiveShareTurboClient } from "@microsoft/live-share-turbo";
17
17
 
18
+ /**
19
+ * React Context provider values for `<LiveShareProvider>`.
20
+ *
21
+ * @remarks
22
+ * To get the latest values, use the {@link useLiveShareContext} hook.
23
+ * Use the {@link useFluidObjectsContext} hook for other relevant context values.
24
+ */
18
25
  export interface ILiveShareContext {
19
26
  /**
20
27
  * True if the local user created the Fluid container
@@ -34,10 +41,14 @@ export interface ILiveShareContext {
34
41
  */
35
42
  timestampProvider: ITimestampProvider | undefined;
36
43
  /**
37
- * Join callback method
44
+ * Join callback method for manually connecting to the Fluid container.
45
+ *
46
+ * @remarks
47
+ * Use this callback if `joinOnLoad` is `false` or `undefined` in {@link ILiveShareProviderProps}.
48
+ *
38
49
  * @param initialObjects Optional. The initial objects for the Fluid container schema.
39
50
  * @param onInitializeContainer Optional. Callback for when the container is first created.
40
- * @returns `ILiveShareJoinResults`, which includes the Fluid container
51
+ * @returns Promise with `ILiveShareJoinResults`, which includes the Fluid container
41
52
  */
42
53
  join: (
43
54
  initialObjects?: LoadableObjectClassRecord,
@@ -45,34 +56,57 @@ export interface ILiveShareContext {
45
56
  ) => Promise<ILiveShareJoinResults>;
46
57
  }
47
58
 
59
+ /**
60
+ * @hidden
61
+ */
48
62
  export const LiveShareContext = React.createContext<ILiveShareContext>(
49
63
  {} as ILiveShareContext
50
64
  );
51
65
 
66
+ /**
67
+ * Hook to get the latest React context state for `LiveShareContext`.
68
+ *
69
+ * @remarks
70
+ * This hook can only be used in a child component of `<LiveShareProvider>`.
71
+ * See `useFluidObjectsContext` for other information related to the Live Share session, such as the `container`.
72
+ *
73
+ * @returns current state of `LiveShareContext`
74
+ */
52
75
  export const useLiveShareContext = (): ILiveShareContext => {
53
76
  const context = React.useContext(LiveShareContext);
77
+ if (!isLiveShareContext(context)) {
78
+ throw new Error(
79
+ "@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>`."
80
+ );
81
+ }
54
82
  return context;
55
83
  };
56
84
 
57
- interface ILiveShareProviderProps {
85
+ /**
86
+ * Prop types for {@link LiveShareProvider} component.
87
+ */
88
+ export interface ILiveShareProviderProps {
58
89
  /**
59
90
  * Optional. React children node for the React Context Provider
60
91
  */
61
92
  children?: React.ReactNode;
62
93
  /**
63
- * Optional. Options to pass into LiveShareClient initializer
94
+ * Optional. Options for initializing `LiveShareClient`.
64
95
  */
65
96
  clientOptions?: ILiveShareClientOptions;
66
97
  /**
67
- * Host to initialize LiveShareClient with
98
+ * Host to initialize `LiveShareClient` with.
99
+ *
100
+ * @remarks
101
+ * If using the `LiveShareClient` class from `@microsoft/teams-js`, you must ensure that you have first called `teamsJs.app.initialize()` before calling `LiveShareClient.create()`.
68
102
  */
69
103
  host: ILiveShareHost;
70
104
  /**
71
- * Optional. Initial Fluid objects to load when the container is first created
105
+ * The initial object schema to use when {@link joinOnLoad} is true.
72
106
  */
73
107
  initialObjects?: LoadableObjectClassRecord;
74
108
  /**
75
- * Optional. Flag to determine whether to join Fluid container on load
109
+ * Optional. Flag to determine whether to join Fluid container on load.
76
110
  */
77
111
  joinOnLoad?: boolean;
78
112
  }
@@ -168,3 +202,9 @@ export const LiveShareProvider: React.FC<ILiveShareProviderProps> = (props) => {
168
202
  </LiveShareContext.Provider>
169
203
  );
170
204
  };
205
+
206
+ function isLiveShareContext(value: any): value is ILiveShareContext {
207
+ return (
208
+ typeof value?.created === "boolean" && typeof value?.join === "function"
209
+ );
210
+ }
@@ -10,6 +10,10 @@ import { LoadableObjectClass } from "fluid-framework";
10
10
 
11
11
  /**
12
12
  * Hook to gets or creates a DDS that corresponds to a given uniqueKey string.
13
+ *
14
+ * @remarks
15
+ * This hook can only be used in a child component of `<LiveShareProvider>` or `<AzureProvider>`.
16
+ *
13
17
  * @template T Type of Fluid LoadableObjectClass type to load. Must conform to IFluidLoadable interface.
14
18
  * @param uniqueKey uniqueKey value for the data object
15
19
  * @param loadableObjectClass Fluid LoadableObjectClass<T> to create/load.
@@ -21,6 +21,7 @@ import {
21
21
  * The primary benefit of using the `useSharedMap` hook rather than the Fluid `SharedMap`
22
22
  * directly is that it integrates nicely with React state and automates repetitive tasks.
23
23
  * If you want to use `SharedMap` this hook creates directly, you can do that as well.
24
+ * This hook can only be used in a child component of `<LiveShareProvider>` or `<AzureProvider>`.
24
25
  *
25
26
  * @template TData Optional typing for objects stored in the SharedMap. Default is `any` type.
26
27
  * @param uniqueKey the unique key for the `SharedMap`. If one does not yet exist, a new `SharedMap`
@@ -16,6 +16,7 @@ import { isPrevStateCallback } from "../internal";
16
16
  * Values set through this state is automatically attached to a `SharedMap` that the `AzureProvider`
17
17
  * creates. If you are synchronizing complex data structures that multiple users will be setting simultaneously,
18
18
  * consider using an optimized hook for your data structure (e.g., `useSharedMap`, `useSharedString`, etc.).
19
+ * This hook can only be used in a child component of `<LiveShareProvider>` or `<AzureProvider>`.
19
20
  *
20
21
  * @template S Typing for objects stored associated with the `uniqueKey`.
21
22
  * @param uniqueKey the unique key for a `SharedMap`. If you use the same key for multiple components, those components will reference the same state.