@microsoft/live-share-react 1.0.0-preview.10

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 (233) hide show
  1. package/.nycrc.json +10 -0
  2. package/LICENSE +87 -0
  3. package/README.md +544 -0
  4. package/bin/index.d.ts +7 -0
  5. package/bin/index.d.ts.map +1 -0
  6. package/bin/index.js +7 -0
  7. package/bin/index.js.map +1 -0
  8. package/bin/interfaces/LiveInterfaceExtensions.d.ts +9 -0
  9. package/bin/interfaces/LiveInterfaceExtensions.d.ts.map +1 -0
  10. package/bin/interfaces/LiveInterfaceExtensions.js +6 -0
  11. package/bin/interfaces/LiveInterfaceExtensions.js.map +1 -0
  12. package/bin/interfaces/index.d.ts +2 -0
  13. package/bin/interfaces/index.d.ts.map +1 -0
  14. package/bin/interfaces/index.js +2 -0
  15. package/bin/interfaces/index.js.map +1 -0
  16. package/bin/internal-hooks/index.d.ts +2 -0
  17. package/bin/internal-hooks/index.d.ts.map +1 -0
  18. package/bin/internal-hooks/index.js +2 -0
  19. package/bin/internal-hooks/index.js.map +1 -0
  20. package/bin/internal-hooks/useDynamicDDSRegistry.d.ts +14 -0
  21. package/bin/internal-hooks/useDynamicDDSRegistry.d.ts.map +1 -0
  22. package/bin/internal-hooks/useDynamicDDSRegistry.js +142 -0
  23. package/bin/internal-hooks/useDynamicDDSRegistry.js.map +1 -0
  24. package/bin/internal-hooks/useSharedStateRegistry.d.ts +31 -0
  25. package/bin/internal-hooks/useSharedStateRegistry.d.ts.map +1 -0
  26. package/bin/internal-hooks/useSharedStateRegistry.js +100 -0
  27. package/bin/internal-hooks/useSharedStateRegistry.js.map +1 -0
  28. package/bin/internal-hooks/useStateRef.d.ts +7 -0
  29. package/bin/internal-hooks/useStateRef.d.ts.map +1 -0
  30. package/bin/internal-hooks/useStateRef.js +15 -0
  31. package/bin/internal-hooks/useStateRef.js.map +1 -0
  32. package/bin/live-hooks/index.d.ts +7 -0
  33. package/bin/live-hooks/index.d.ts.map +1 -0
  34. package/bin/live-hooks/index.js +7 -0
  35. package/bin/live-hooks/index.js.map +1 -0
  36. package/bin/live-hooks/useLiveAICompletion.d.ts +29 -0
  37. package/bin/live-hooks/useLiveAICompletion.d.ts.map +1 -0
  38. package/bin/live-hooks/useLiveAICompletion.js +186 -0
  39. package/bin/live-hooks/useLiveAICompletion.js.map +1 -0
  40. package/bin/live-hooks/useLiveCanvas.d.ts +28 -0
  41. package/bin/live-hooks/useLiveCanvas.d.ts.map +1 -0
  42. package/bin/live-hooks/useLiveCanvas.js +167 -0
  43. package/bin/live-hooks/useLiveCanvas.js.map +1 -0
  44. package/bin/live-hooks/useLiveCoPilot.d.ts +28 -0
  45. package/bin/live-hooks/useLiveCoPilot.d.ts.map +1 -0
  46. package/bin/live-hooks/useLiveCoPilot.js +178 -0
  47. package/bin/live-hooks/useLiveCoPilot.js.map +1 -0
  48. package/bin/live-hooks/useLiveEvent.d.ts +22 -0
  49. package/bin/live-hooks/useLiveEvent.d.ts.map +1 -0
  50. package/bin/live-hooks/useLiveEvent.js +86 -0
  51. package/bin/live-hooks/useLiveEvent.js.map +1 -0
  52. package/bin/live-hooks/useLivePresence.d.ts +26 -0
  53. package/bin/live-hooks/useLivePresence.d.ts.map +1 -0
  54. package/bin/live-hooks/useLivePresence.js +93 -0
  55. package/bin/live-hooks/useLivePresence.js.map +1 -0
  56. package/bin/live-hooks/useLiveState.d.ts +19 -0
  57. package/bin/live-hooks/useLiveState.d.ts.map +1 -0
  58. package/bin/live-hooks/useLiveState.js +61 -0
  59. package/bin/live-hooks/useLiveState.js.map +1 -0
  60. package/bin/live-hooks/useLiveTimer.d.ts +8 -0
  61. package/bin/live-hooks/useLiveTimer.d.ts.map +1 -0
  62. package/bin/live-hooks/useLiveTimer.js +132 -0
  63. package/bin/live-hooks/useLiveTimer.js.map +1 -0
  64. package/bin/live-hooks/useMediaSynchronizer.d.ts +23 -0
  65. package/bin/live-hooks/useMediaSynchronizer.d.ts.map +1 -0
  66. package/bin/live-hooks/useMediaSynchronizer.js +162 -0
  67. package/bin/live-hooks/useMediaSynchronizer.js.map +1 -0
  68. package/bin/live-share-turbo/AzureTurboClient.d.ts +39 -0
  69. package/bin/live-share-turbo/AzureTurboClient.d.ts.map +1 -0
  70. package/bin/live-share-turbo/AzureTurboClient.js +56 -0
  71. package/bin/live-share-turbo/AzureTurboClient.js.map +1 -0
  72. package/bin/live-share-turbo/LiveShareTurboClient.d.ts +53 -0
  73. package/bin/live-share-turbo/LiveShareTurboClient.d.ts.map +1 -0
  74. package/bin/live-share-turbo/LiveShareTurboClient.js +69 -0
  75. package/bin/live-share-turbo/LiveShareTurboClient.js.map +1 -0
  76. package/bin/live-share-turbo/dds-objects/TurboDataObject.d.ts +31 -0
  77. package/bin/live-share-turbo/dds-objects/TurboDataObject.d.ts.map +1 -0
  78. package/bin/live-share-turbo/dds-objects/TurboDataObject.js +75 -0
  79. package/bin/live-share-turbo/dds-objects/TurboDataObject.js.map +1 -0
  80. package/bin/live-share-turbo/dds-objects/TurboLiveCanvas.d.ts +48 -0
  81. package/bin/live-share-turbo/dds-objects/TurboLiveCanvas.d.ts.map +1 -0
  82. package/bin/live-share-turbo/dds-objects/TurboLiveCanvas.js +104 -0
  83. package/bin/live-share-turbo/dds-objects/TurboLiveCanvas.js.map +1 -0
  84. package/bin/live-share-turbo/dds-objects/TurboLiveEvent.d.ts +28 -0
  85. package/bin/live-share-turbo/dds-objects/TurboLiveEvent.d.ts.map +1 -0
  86. package/bin/live-share-turbo/dds-objects/TurboLiveEvent.js +68 -0
  87. package/bin/live-share-turbo/dds-objects/TurboLiveEvent.js.map +1 -0
  88. package/bin/live-share-turbo/dds-objects/TurboLiveMediaSession.d.ts +60 -0
  89. package/bin/live-share-turbo/dds-objects/TurboLiveMediaSession.d.ts.map +1 -0
  90. package/bin/live-share-turbo/dds-objects/TurboLiveMediaSession.js +111 -0
  91. package/bin/live-share-turbo/dds-objects/TurboLiveMediaSession.js.map +1 -0
  92. package/bin/live-share-turbo/dds-objects/TurboLivePresence.d.ts +77 -0
  93. package/bin/live-share-turbo/dds-objects/TurboLivePresence.d.ts.map +1 -0
  94. package/bin/live-share-turbo/dds-objects/TurboLivePresence.js +137 -0
  95. package/bin/live-share-turbo/dds-objects/TurboLivePresence.js.map +1 -0
  96. package/bin/live-share-turbo/dds-objects/TurboLiveState.d.ts +30 -0
  97. package/bin/live-share-turbo/dds-objects/TurboLiveState.d.ts.map +1 -0
  98. package/bin/live-share-turbo/dds-objects/TurboLiveState.js +74 -0
  99. package/bin/live-share-turbo/dds-objects/TurboLiveState.js.map +1 -0
  100. package/bin/live-share-turbo/dds-objects/TurboSharedMap.d.ts +61 -0
  101. package/bin/live-share-turbo/dds-objects/TurboSharedMap.d.ts.map +1 -0
  102. package/bin/live-share-turbo/dds-objects/TurboSharedMap.js +108 -0
  103. package/bin/live-share-turbo/dds-objects/TurboSharedMap.js.map +1 -0
  104. package/bin/live-share-turbo/dds-objects/index.d.ts +8 -0
  105. package/bin/live-share-turbo/dds-objects/index.d.ts.map +1 -0
  106. package/bin/live-share-turbo/dds-objects/index.js +8 -0
  107. package/bin/live-share-turbo/dds-objects/index.js.map +1 -0
  108. package/bin/live-share-turbo/index.d.ts +5 -0
  109. package/bin/live-share-turbo/index.d.ts.map +1 -0
  110. package/bin/live-share-turbo/index.js +5 -0
  111. package/bin/live-share-turbo/index.js.map +1 -0
  112. package/bin/live-share-turbo/interfaces/IFluidTurboClient.d.ts +15 -0
  113. package/bin/live-share-turbo/interfaces/IFluidTurboClient.d.ts.map +1 -0
  114. package/bin/live-share-turbo/interfaces/IFluidTurboClient.js +2 -0
  115. package/bin/live-share-turbo/interfaces/IFluidTurboClient.js.map +1 -0
  116. package/bin/live-share-turbo/interfaces/index.d.ts +3 -0
  117. package/bin/live-share-turbo/interfaces/index.d.ts.map +1 -0
  118. package/bin/live-share-turbo/interfaces/index.js +3 -0
  119. package/bin/live-share-turbo/interfaces/index.js.map +1 -0
  120. package/bin/live-share-turbo/internals/FluidTurboClient.d.ts +39 -0
  121. package/bin/live-share-turbo/internals/FluidTurboClient.d.ts.map +1 -0
  122. package/bin/live-share-turbo/internals/FluidTurboClient.js +121 -0
  123. package/bin/live-share-turbo/internals/FluidTurboClient.js.map +1 -0
  124. package/bin/live-share-turbo/internals/index.d.ts +2 -0
  125. package/bin/live-share-turbo/internals/index.d.ts.map +1 -0
  126. package/bin/live-share-turbo/internals/index.js +2 -0
  127. package/bin/live-share-turbo/internals/index.js.map +1 -0
  128. package/bin/live-share-turbo/internals/types.d.ts +4 -0
  129. package/bin/live-share-turbo/internals/types.d.ts.map +1 -0
  130. package/bin/live-share-turbo/internals/types.js +2 -0
  131. package/bin/live-share-turbo/internals/types.js.map +1 -0
  132. package/bin/providers/AzureProvider.d.ts +34 -0
  133. package/bin/providers/AzureProvider.d.ts.map +1 -0
  134. package/bin/providers/AzureProvider.js +102 -0
  135. package/bin/providers/AzureProvider.js.map +1 -0
  136. package/bin/providers/FluidContextProvider.d.ts +34 -0
  137. package/bin/providers/FluidContextProvider.d.ts.map +1 -0
  138. package/bin/providers/FluidContextProvider.js +99 -0
  139. package/bin/providers/FluidContextProvider.js.map +1 -0
  140. package/bin/providers/LiveShareContextProvider.d.ts +42 -0
  141. package/bin/providers/LiveShareContextProvider.d.ts.map +1 -0
  142. package/bin/providers/LiveShareContextProvider.js +63 -0
  143. package/bin/providers/LiveShareContextProvider.js.map +1 -0
  144. package/bin/providers/LiveShareProvider.d.ts +42 -0
  145. package/bin/providers/LiveShareProvider.d.ts.map +1 -0
  146. package/bin/providers/LiveShareProvider.js +66 -0
  147. package/bin/providers/LiveShareProvider.js.map +1 -0
  148. package/bin/providers/index.d.ts +3 -0
  149. package/bin/providers/index.d.ts.map +1 -0
  150. package/bin/providers/index.js +3 -0
  151. package/bin/providers/index.js.map +1 -0
  152. package/bin/shared-hooks/index.d.ts +5 -0
  153. package/bin/shared-hooks/index.d.ts.map +1 -0
  154. package/bin/shared-hooks/index.js +5 -0
  155. package/bin/shared-hooks/index.js.map +1 -0
  156. package/bin/shared-hooks/useDynamicDDS.d.ts +19 -0
  157. package/bin/shared-hooks/useDynamicDDS.d.ts.map +1 -0
  158. package/bin/shared-hooks/useDynamicDDS.js +68 -0
  159. package/bin/shared-hooks/useDynamicDDS.js.map +1 -0
  160. package/bin/shared-hooks/useLockedTask.d.ts +11 -0
  161. package/bin/shared-hooks/useLockedTask.d.ts.map +1 -0
  162. package/bin/shared-hooks/useLockedTask.js +82 -0
  163. package/bin/shared-hooks/useLockedTask.js.map +1 -0
  164. package/bin/shared-hooks/useSharedMap.d.ts +22 -0
  165. package/bin/shared-hooks/useSharedMap.d.ts.map +1 -0
  166. package/bin/shared-hooks/useSharedMap.js +106 -0
  167. package/bin/shared-hooks/useSharedMap.js.map +1 -0
  168. package/bin/shared-hooks/useSharedState.d.ts +21 -0
  169. package/bin/shared-hooks/useSharedState.d.ts.map +1 -0
  170. package/bin/shared-hooks/useSharedState.js +63 -0
  171. package/bin/shared-hooks/useSharedState.js.map +1 -0
  172. package/bin/shared-hooks/useTaskManager.d.ts +13 -0
  173. package/bin/shared-hooks/useTaskManager.d.ts.map +1 -0
  174. package/bin/shared-hooks/useTaskManager.js +86 -0
  175. package/bin/shared-hooks/useTaskManager.js.map +1 -0
  176. package/bin/types/ActionTypes.d.ts +30 -0
  177. package/bin/types/ActionTypes.d.ts.map +1 -0
  178. package/bin/types/ActionTypes.js +6 -0
  179. package/bin/types/ActionTypes.js.map +1 -0
  180. package/bin/types/PropTypes.d.ts +8 -0
  181. package/bin/types/PropTypes.d.ts.map +1 -0
  182. package/bin/types/PropTypes.js +6 -0
  183. package/bin/types/PropTypes.js.map +1 -0
  184. package/bin/types/ResultTypes.d.ts +163 -0
  185. package/bin/types/ResultTypes.d.ts.map +1 -0
  186. package/bin/types/ResultTypes.js +6 -0
  187. package/bin/types/ResultTypes.js.map +1 -0
  188. package/bin/types/index.d.ts +4 -0
  189. package/bin/types/index.d.ts.map +1 -0
  190. package/bin/types/index.js +4 -0
  191. package/bin/types/index.js.map +1 -0
  192. package/bin/utils/getContainerSchema.d.ts +8 -0
  193. package/bin/utils/getContainerSchema.d.ts.map +1 -0
  194. package/bin/utils/getContainerSchema.js +41 -0
  195. package/bin/utils/getContainerSchema.js.map +1 -0
  196. package/bin/utils/index.d.ts +2 -0
  197. package/bin/utils/index.d.ts.map +1 -0
  198. package/bin/utils/index.js +2 -0
  199. package/bin/utils/index.js.map +1 -0
  200. package/bin/utils/type-check.d.ts +15 -0
  201. package/bin/utils/type-check.d.ts.map +1 -0
  202. package/bin/utils/type-check.js +54 -0
  203. package/bin/utils/type-check.js.map +1 -0
  204. package/package.json +47 -0
  205. package/src/index.ts +6 -0
  206. package/src/interfaces/LiveInterfaceExtensions.ts +9 -0
  207. package/src/interfaces/index.ts +1 -0
  208. package/src/internal-hooks/index.ts +1 -0
  209. package/src/internal-hooks/useSharedStateRegistry.ts +163 -0
  210. package/src/live-hooks/index.ts +6 -0
  211. package/src/live-hooks/useLiveCanvas.ts +198 -0
  212. package/src/live-hooks/useLiveEvent.ts +117 -0
  213. package/src/live-hooks/useLivePresence.ts +124 -0
  214. package/src/live-hooks/useLiveState.ts +87 -0
  215. package/src/live-hooks/useLiveTimer.ts +184 -0
  216. package/src/live-hooks/useMediaSynchronizer.ts +200 -0
  217. package/src/providers/AzureProvider.tsx +177 -0
  218. package/src/providers/LiveShareProvider.tsx +140 -0
  219. package/src/providers/index.ts +2 -0
  220. package/src/shared-hooks/index.ts +4 -0
  221. package/src/shared-hooks/useDynamicDDS.ts +71 -0
  222. package/src/shared-hooks/useSharedMap.ts +132 -0
  223. package/src/shared-hooks/useSharedState.ts +85 -0
  224. package/src/shared-hooks/useTaskManager.ts +82 -0
  225. package/src/types/ActionTypes.ts +75 -0
  226. package/src/types/PropTypes.ts +10 -0
  227. package/src/types/ResultTypes.ts +187 -0
  228. package/src/types/index.ts +3 -0
  229. package/src/utils/index.ts +1 -0
  230. package/src/utils/type-check.ts +69 -0
  231. package/tinylicious.log +4 -0
  232. package/tsconfig.build.json +6 -0
  233. package/tsconfig.json +72 -0
@@ -0,0 +1,11 @@
1
+ /**
2
+ * A hook for joining a queue to lock tasks for a given id. Guaranteed to have only one user assigned to a task at a time.
3
+ *
4
+ * @param uniqueKey the unique key for the TaskManager DDS
5
+ * @param taskId the task id to lock
6
+ * @returns stateful data about the status of the task lock
7
+ */
8
+ export declare const useLockedTask: (uniqueKey: string, taskId?: string) => {
9
+ lockedTask: boolean;
10
+ };
11
+ //# sourceMappingURL=useLockedTask.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useLockedTask.d.ts","sourceRoot":"","sources":["../../src/shared-hooks/useLockedTask.ts"],"names":[],"mappings":"AAIA;;;;;;GAMG;AACH,eAAO,MAAM,aAAa,cAAe,MAAM,WAAW,MAAM;gBAChD,OAAO;CA+DtB,CAAC"}
@@ -0,0 +1,82 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import React, { useEffect } from "react";
11
+ import { TaskManager } from "@fluid-experimental/task-manager";
12
+ import { useDynamicDDS } from "./useDynamicDDS";
13
+ /**
14
+ * A hook for joining a queue to lock tasks for a given id. Guaranteed to have only one user assigned to a task at a time.
15
+ *
16
+ * @param uniqueKey the unique key for the TaskManager DDS
17
+ * @param taskId the task id to lock
18
+ * @returns stateful data about the status of the task lock
19
+ */
20
+ export const useLockedTask = (uniqueKey, taskId) => {
21
+ /**
22
+ * TaskId currently in queue for
23
+ */
24
+ const currentTaskIdRef = React.useRef(undefined);
25
+ /**
26
+ * Stateful boolean that is true when the user is currently assigned the task
27
+ */
28
+ const [lockedTask, setLockedTask] = React.useState(false);
29
+ /**
30
+ * User facing: dynamically load the TaskManager DDS for the given unique key.
31
+ */
32
+ const { dds: taskManager } = useDynamicDDS(uniqueKey, TaskManager);
33
+ /**
34
+ * When the task id changes, lock the task. When the task id is undefined, abandon the task.
35
+ */
36
+ useEffect(() => {
37
+ let mounted = true;
38
+ if (taskManager) {
39
+ if (taskId && currentTaskIdRef.current !== taskId) {
40
+ if (currentTaskIdRef.current) {
41
+ taskManager.abandon(currentTaskIdRef.current);
42
+ setLockedTask(false);
43
+ }
44
+ currentTaskIdRef.current = taskId;
45
+ const onLockTask = () => __awaiter(void 0, void 0, void 0, function* () {
46
+ try {
47
+ yield taskManager.lockTask(taskId);
48
+ if (mounted) {
49
+ setLockedTask(true);
50
+ }
51
+ }
52
+ catch (_a) {
53
+ if (mounted) {
54
+ setLockedTask(false);
55
+ currentTaskIdRef.current = undefined;
56
+ }
57
+ }
58
+ });
59
+ onLockTask();
60
+ }
61
+ else if (!taskId && currentTaskIdRef.current) {
62
+ taskManager.abandon(currentTaskIdRef.current);
63
+ setLockedTask(false);
64
+ currentTaskIdRef.current = undefined;
65
+ }
66
+ }
67
+ /**
68
+ * When the component unmounts, abandon the task if it is still locked
69
+ */
70
+ return () => {
71
+ mounted = false;
72
+ if (currentTaskIdRef.current) {
73
+ taskManager === null || taskManager === void 0 ? void 0 : taskManager.abandon(currentTaskIdRef.current);
74
+ }
75
+ currentTaskIdRef.current = undefined;
76
+ };
77
+ }, [taskManager, taskId]);
78
+ return {
79
+ lockedTask,
80
+ };
81
+ };
82
+ //# sourceMappingURL=useLockedTask.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useLockedTask.js","sourceRoot":"","sources":["../../src/shared-hooks/useLockedTask.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,KAAK,EAAE,EAAE,SA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AC;aAChB;iBAAM,IAAI,CAAC,MAAM,IAAI,gBAAgB,CAAC,OAAO,EAAE;gBAC5C,WAAW,CAAC,OAAO,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC;gBAC9C,aAAa,CAAC,KAAK,CAAC,CAAC;gBACrB,gBAAgB,CAAC,OAAO,GAAG,SAAS,CAAC;aACxC;SACJ;QACD;;WAEG;QACH,OAAO,GAAG,EAAE;YACR,OAAO,GAAG,KAAK,CAAC;YAChB,IAAI,gBAAgB,CAAC,OAAO,EAAE;gBAC1B,WAAW,aAAX,WAAW,uBAAX,WAAW,CAAE,OAAO,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC;aAClD;YACD,gBAAgB,CAAC,OAAO,GAAG,SAAS,CAAC;QACzC,CAAC,CAAA;IACL,CAAC,EAAE,CAAC,WAAW,EAAE,MAAM,CAAC,CAAC,CAAC;IAE1B,OAAO;QACH,UAAU;KACb,CAAC;AACN,CAAC,CAAC"}
@@ -0,0 +1,22 @@
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation. All rights reserved.
3
+ * Licensed under the Microsoft Live Share SDK License.
4
+ */
5
+ import { IUseSharedMapResults, SharedMapInitialData } from "../types";
6
+ /**
7
+ * React hook for using a Fluid `SharedMap`.
8
+ *
9
+ * @remarks
10
+ * The primary benefit of using the `useSharedMap` hook rather than the Fluid `SharedMap`
11
+ * directly is that it integrates nicely with React state and automates repetitive tasks.
12
+ * If you want to use `SharedMap` this hook creates directly, you can do that as well.
13
+ *
14
+ * @template TData Optional typing for objects stored in the SharedMap. Default is `object` type.
15
+ * @param uniqueKey the unique key for the `SharedMap`. If one does not yet exist, a new `SharedMap`
16
+ * will be created, otherwise it will use the existing one.
17
+ * @param initialData a JS Map, entries array, or JSON object to insert into the `SharedMap` when creating
18
+ * the DDS for the first time.
19
+ * @returns stateful `map` entries, `setEntry` callback, `deleteEntry` callback, and the Fluid `sharedMap`.
20
+ */
21
+ export declare function useSharedMap<TData extends object = object>(uniqueKey: string, initialData?: SharedMapInitialData<TData>): IUseSharedMapResults<TData>;
22
+ //# sourceMappingURL=useSharedMap.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useSharedMap.d.ts","sourceRoot":"","sources":["../../src/shared-hooks/useSharedMap.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,OAAO,EAAE,oBAAoB,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAC;AAItE;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,YAAY,CAAC,KAAK,SAAS,MAAM,GAAG,MAAM,EACtD,SAAS,EAAE,MAAM,EACjB,WAAW,CAAC,EAAE,oBAAoB,CAAC,KAAK,CAAC,GAC1C,oBAAoB,CAAC,KAAK,CAAC,CA8E7B"}
@@ -0,0 +1,106 @@
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation. All rights reserved.
3
+ * Licensed under the Microsoft Live Share SDK License.
4
+ */
5
+ import React from "react";
6
+ import { isEntries, isJSON, isMap } from "../utils";
7
+ import { useDynamicDDS } from "./useDynamicDDS";
8
+ import { SharedMap } from "fluid-framework";
9
+ /**
10
+ * React hook for using a Fluid `SharedMap`.
11
+ *
12
+ * @remarks
13
+ * The primary benefit of using the `useSharedMap` hook rather than the Fluid `SharedMap`
14
+ * directly is that it integrates nicely with React state and automates repetitive tasks.
15
+ * If you want to use `SharedMap` this hook creates directly, you can do that as well.
16
+ *
17
+ * @template TData Optional typing for objects stored in the SharedMap. Default is `object` type.
18
+ * @param uniqueKey the unique key for the `SharedMap`. If one does not yet exist, a new `SharedMap`
19
+ * will be created, otherwise it will use the existing one.
20
+ * @param initialData a JS Map, entries array, or JSON object to insert into the `SharedMap` when creating
21
+ * the DDS for the first time.
22
+ * @returns stateful `map` entries, `setEntry` callback, `deleteEntry` callback, and the Fluid `sharedMap`.
23
+ */
24
+ export function useSharedMap(uniqueKey, initialData) {
25
+ /**
26
+ * Stateful readonly map (user facing) with most recent values from `SharedMap` and its setter method.
27
+ */
28
+ const [map, setMap] = React.useState(getInitialData(initialData));
29
+ const onFirstInitialize = React.useCallback((newDDS) => {
30
+ /**
31
+ * Callback method to set the `initialData` into the map when the `SharedMap` is first created.
32
+ * Only should be used as a prop to useDynamicDDS.
33
+ */
34
+ getInitialData(initialData).forEach((value, key) => {
35
+ newDDS.set(key, value);
36
+ });
37
+ }, [initialData]);
38
+ /**
39
+ * User facing: dynamically load the SharedMap DDS for the given unique key.
40
+ */
41
+ const { dds: sharedMap } = useDynamicDDS(uniqueKey, SharedMap, onFirstInitialize);
42
+ /**
43
+ * User facing: set a value to the Fluid `SharedMap`.
44
+ */
45
+ const setEntry = React.useCallback((key, value) => {
46
+ if (!sharedMap) {
47
+ console.error(new Error("Cannot call set when sharedMap is undefined"));
48
+ return;
49
+ }
50
+ sharedMap.set(key, value);
51
+ }, [sharedMap]);
52
+ /**
53
+ * User facing: delete a value from the Fluid `SharedMap`.
54
+ */
55
+ const deleteEntry = React.useCallback((key) => {
56
+ if (!sharedMap) {
57
+ console.error(new Error("Cannot call remove when sharedMap is undefined"));
58
+ return;
59
+ }
60
+ sharedMap.delete(key);
61
+ }, [sharedMap]);
62
+ // Setup change listeners, initial values, etc.
63
+ React.useEffect(() => {
64
+ if (!sharedMap)
65
+ return;
66
+ // Register valueChanged listener for `SharedMap`.
67
+ const onValueChanged = () => {
68
+ setMap(new Map(sharedMap.entries()));
69
+ };
70
+ sharedMap.on("valueChanged", onValueChanged);
71
+ // Get initial values from `SharedMap`.
72
+ onValueChanged();
73
+ return () => {
74
+ // Cleanup on component unmount.
75
+ sharedMap === null || sharedMap === void 0 ? void 0 : sharedMap.off("valueChanged", onValueChanged);
76
+ };
77
+ }, [sharedMap]);
78
+ return {
79
+ map,
80
+ setEntry,
81
+ deleteEntry,
82
+ sharedMap,
83
+ };
84
+ }
85
+ /**
86
+ * Helper method for converting different initial data props into a Map<string, TData> to insert into the Fluid SharedMap
87
+ * @template TData Optional typing for objects stored in the SharedMap. Default is `object` type.
88
+ * @param initialData a JS Map, entries array, or JSON object.
89
+ * @returns A Map<string, TData> with the entries provided.
90
+ */
91
+ function getInitialData(initialData) {
92
+ if (isMap(initialData)) {
93
+ return initialData;
94
+ }
95
+ else if (isEntries(initialData)) {
96
+ return new Map(initialData);
97
+ }
98
+ else if (isJSON(initialData)) {
99
+ const values = Object.keys(initialData).map((key) => {
100
+ return [key, initialData[key]];
101
+ });
102
+ return new Map(values);
103
+ }
104
+ return new Map();
105
+ }
106
+ //# sourceMappingURL=useSharedMap.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useSharedMap.js","sourceRoot":"","sources":["../../src/shared-hooks/useSharedMap.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AAEpD,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,YAAY,CACxB,SAAiB,EACjB,WAAyC;IAEzC;;OAEG;IACH,MAAM,CAAC,GAAG,EAAE,MAAM,CAAC,GAAG,KAAK,CAAC,QAAQ,CAChC,cAAc,CAAQ,WAAW,CAAC,CACrC,CAAC;IAEF,MAAM,iBAAiB,GAAG,KAAK,CAAC,WAAW,CAAC,CAAC,MAAiB,EAAQ,EAAE;QACpE;;;WAGG;QACH,cAAc,CAAC,WAAW,CAAC,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE;YAC/C,MAAM,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;QAC3B,CAAC,CAAC,CAAC;IACP,CAAC,EAAE,CAAC,WAAW,CAAC,CAAC,CAAC;IAClB;;OAEG;IACH,MAAM,EAAE,GAAG,EAAE,SAAS,EAAE,GAAG,aAAa,CAAY,SAAS,EAAE,SAA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QACX,SAAS;KACZ,CAAC;AACN,CAAC;AAED;;;;;GAKG;AACH,SAAS,cAAc,CACnB,WAAwC;IAExC,IAAI,KAAK,CAAC,WAAW,CAAC,EAAE;QACpB,OAAO,WAAW,CAAC;KACtB;SAAM,IAAI,SAAS,CAAC,WAAW,CAAC,EAAE;QAC/B,OAAO,IAAI,GAAG,CAAgB,WAAW,CAAC,CAAC;KAC9C;SAAM,IAAI,MAAM,CAAC,WAAW,CAAC,EAAE;QAC5B,MAAM,MAAM,GAAiC,MAAM,CAAC,IAAI,CACpD,WAAW,CACd,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE;YACV,OAAO,CAAC,GAAG,EAAE,WAAW,CAAC,GAAG,CAAC,CAAC,CAAC;QACnC,CAAC,CAAC,CAAC;QACH,OAAO,IAAI,GAAG,CAAgB,MAAM,CAAC,CAAC;KACzC;IACD,OAAO,IAAI,GAAG,EAAiB,CAAC;AACpC,CAAC"}
@@ -0,0 +1,21 @@
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation. All rights reserved.
3
+ * Licensed under the Microsoft Live Share SDK License.
4
+ */
5
+ import { DisposeSharedStateAction, SetSharedStateAction } from "../types";
6
+ /**
7
+ * Inspired by React's `useState` hook, `useSharedState` makes it easy to synchronize state in your app.
8
+ *
9
+ * @remarks
10
+ * Values set through this state is automatically attached to a `SharedMap` that the `AzureProvider`
11
+ * creates. If you are synchronizing complex data structures that multiple users will be setting simultaneously,
12
+ * consider using an optimized hook for your data structure (e.g., `useSharedMap`, `useSharedString`, etc.).
13
+ *
14
+ * @template S Typing for objects stored associated with the `uniqueKey`.
15
+ * @param uniqueKey the unique key for a `SharedMap`. If you use the same key for multiple components, those components will reference the same state.
16
+ * @param initialState a default state for the `SharedMap`.
17
+ *
18
+ * @returns a stateful value, the function to update it, and an optional dispose method to delete it from the `SharedMap`.
19
+ */
20
+ export declare function useSharedState<S>(uniqueKey: string, initialState: S): [S, SetSharedStateAction<S>, DisposeSharedStateAction];
21
+ //# sourceMappingURL=useSharedState.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useSharedState.d.ts","sourceRoot":"","sources":["../../src/shared-hooks/useSharedState.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,OAAO,EAAE,wBAAwB,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAC;AAG1E;;;;;;;;;;;;;GAaG;AACH,wBAAgB,cAAc,CAAC,CAAC,EAC5B,SAAS,EAAE,MAAM,EACjB,YAAY,EAAE,CAAC,GAChB,CAAC,CAAC,EAAE,oBAAoB,CAAC,CAAC,CAAC,EAAE,wBAAwB,CAAC,CAyDxD"}
@@ -0,0 +1,63 @@
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation. All rights reserved.
3
+ * Licensed under the Microsoft Live Share SDK License.
4
+ */
5
+ import React from "react";
6
+ import { useFluidObjectsContext } from "../providers";
7
+ import { v4 as uuid } from "uuid";
8
+ /**
9
+ * Inspired by React's `useState` hook, `useSharedState` makes it easy to synchronize state in your app.
10
+ *
11
+ * @remarks
12
+ * Values set through this state is automatically attached to a `SharedMap` that the `AzureProvider`
13
+ * creates. If you are synchronizing complex data structures that multiple users will be setting simultaneously,
14
+ * consider using an optimized hook for your data structure (e.g., `useSharedMap`, `useSharedString`, etc.).
15
+ *
16
+ * @template S Typing for objects stored associated with the `uniqueKey`.
17
+ * @param uniqueKey the unique key for a `SharedMap`. If you use the same key for multiple components, those components will reference the same state.
18
+ * @param initialState a default state for the `SharedMap`.
19
+ *
20
+ * @returns a stateful value, the function to update it, and an optional dispose method to delete it from the `SharedMap`.
21
+ */
22
+ export function useSharedState(uniqueKey, initialState) {
23
+ /**
24
+ * User facing: stateful value and non-user facing setter.
25
+ */
26
+ const [localState, setLocalState] = React.useState(initialState);
27
+ /**
28
+ * Unique ID reference for the component.
29
+ */
30
+ const componentIdRef = React.useRef(uuid());
31
+ /**
32
+ * Register set state callbacks from AzureProvider and update/delete callbacks for initial object's `stateMap`.
33
+ */
34
+ const { registerSharedSetStateAction, unregisterSharedSetStateAction, updateSharedState, deleteSharedState, } = useFluidObjectsContext();
35
+ /**
36
+ * User facing: callback to change the shared state.
37
+ */
38
+ const setSharedState = React.useCallback((updatedState) => {
39
+ setLocalState(updatedState);
40
+ updateSharedState(uniqueKey, updatedState);
41
+ }, [uniqueKey, setLocalState, updateSharedState]);
42
+ /**
43
+ * User facing: callback to dispose the shared state from the `stateMap`.
44
+ */
45
+ const disposeSharedState = React.useCallback(() => {
46
+ deleteSharedState(uniqueKey);
47
+ }, [uniqueKey, deleteSharedState]);
48
+ /**
49
+ * Once container is available, this effect will register the setter method so that the `S` value
50
+ * from `stateMap` that matches `uniqueKey` can be passed back to this hook whenever changed.
51
+ *
52
+ * @see registerSharedSetStateAction to see how new values from `stateMap` are passed to this hook.
53
+ * @see unregisterSharedSetStateAction to see how this component stops listening to changes in the `stateMap`.
54
+ */
55
+ React.useEffect(() => {
56
+ registerSharedSetStateAction(uniqueKey, componentIdRef.current, setLocalState);
57
+ return () => {
58
+ unregisterSharedSetStateAction(uniqueKey, componentIdRef.current);
59
+ };
60
+ }, [uniqueKey, registerSharedSetStateAction, unregisterSharedSetStateAction]);
61
+ return [localState, setSharedState, disposeSharedState];
62
+ }
63
+ //# sourceMappingURL=useSharedState.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useSharedState.js","sourceRoot":"","sources":["../../src/shared-hooks/useSharedState.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,sBAAsB,EAAE,MAAM,cAAc,CAAC;AAEtD,OAAO,EAAE,EAAE,IAAI,IAAI,EAAE,MAAM,MAAM,CAAC;AAElC;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,cAAc,CAC1B,SAAiB,EACjB,YAAe;IAEf;;OAEG;IACH,MAAM,CAAC,UAAU,EAAE,aAAa,CAAC,GAAG,KAAK,CAAC,QAAQ,CAAI,YAAY,CAAC,CAAC;IACpE;;OAEG;IACH,MAAM,cAAc,GAAG,KAAK,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC;IAC5C;;OAEG;IACH,MAAM,EACF,4BAA4B,EAC5B,8BAA8B,EAC9B,iBAAiB,EACjB,iBAAiB,GACpB,GAAG,sBAAsB,EAAE,CAAC;IAE7B;;OAEG;IACH,MAAM,cAAc,GAA4B,KAAK,CAAC,WAAW,CAC7D,CAAC,YAAe,EAAE,EAAE;QAChB,aAAa,CAAC,YAAY,CAAC,CAAC;QAC5B,iBAAiB,CAAC,SAAS,EAAE,YAAY,CAAC,CAAC;IAC/C,CAAC,EACD,CAAC,SAAS,EAAE,aAAa,EAAE,iBAAiB,CAAC,CAChD,CAAC;IAEF;;OAEG;IACH,MAAM,kBAAkB,GACpB,KAAK,CAAC,WAAW,CAAC,GAAG,EAAE;QACnB,iBAAiB,CAAC,SAAS,CAAC,CAAC;IACjC,CAAC,EAAE,CAAC,SAAS,EAAE,iBAAiB,CAAC,CAAC,CAAC;IAEvC;;;;;;OAMG;IACH,KAAK,CAAC,SAAS,CAAC,GAAG,EAAE;QACjB,4BAA4B,CACxB,SAAS,EACT,cAAc,CAAC,OAAO,EACtB,aAAa,CAChB,CAAC;QACF,OAAO,GAAG,EAAE;YACR,8BAA8B,CAAC,SAAS,EAAE,cAAc,CAAC,OAAO,CAAC,CAAC;QACtE,CAAC,CAAC;IACN,CAAC,EAAE,CAAC,SAAS,EAAE,4BAA4B,EAAE,8BAA8B,CAAC,CAAC,CAAC;IAE9E,OAAO,CAAC,UAAU,EAAE,cAAc,EAAE,kBAAkB,CAAC,CAAC;AAC5D,CAAC"}
@@ -0,0 +1,13 @@
1
+ import { TaskManager } from "@fluid-experimental/task-manager";
2
+ /**
3
+ * A hook for joining a queue to lock tasks for a given id. Guaranteed to have only one user assigned to a task at a time.
4
+ *
5
+ * @param uniqueKey the unique key for the TaskManager DDS
6
+ * @param taskId the task id to lock
7
+ * @returns stateful data about the status of the task lock
8
+ */
9
+ export declare const useTaskManager: (uniqueKey: string, taskId?: string) => {
10
+ lockedTask: boolean;
11
+ taskManager: TaskManager | undefined;
12
+ };
13
+ //# sourceMappingURL=useTaskManager.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useTaskManager.d.ts","sourceRoot":"","sources":["../../src/shared-hooks/useTaskManager.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAG,MAAM,kCAAkC,CAAC;AAMhE;;;;;;GAMG;AACH,eAAO,MAAM,cAAc,cAAe,MAAM,WAAW,MAAM;gBACjD,OAAO;iBACN,WAAW,GAAG,SAAS;CAgEvC,CAAC"}
@@ -0,0 +1,86 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import React from "react";
11
+ import { useDynamicDDS } from "./useDynamicDDS";
12
+ import { TaskManager } from "@fluid-experimental/task-manager";
13
+ import { DynamicObjectRegistry } from "@microsoft/live-share";
14
+ // Register TaskManager as dynamic object
15
+ DynamicObjectRegistry.registerObjectClass(TaskManager, TaskManager.getFactory().type);
16
+ /**
17
+ * A hook for joining a queue to lock tasks for a given id. Guaranteed to have only one user assigned to a task at a time.
18
+ *
19
+ * @param uniqueKey the unique key for the TaskManager DDS
20
+ * @param taskId the task id to lock
21
+ * @returns stateful data about the status of the task lock
22
+ */
23
+ export const useTaskManager = (uniqueKey, taskId) => {
24
+ /**
25
+ * TaskId currently in queue for
26
+ */
27
+ const currentTaskIdRef = React.useRef(undefined);
28
+ /**
29
+ * Stateful boolean that is true when the user is currently assigned the task
30
+ */
31
+ const [lockedTask, setLockedTask] = React.useState(false);
32
+ /**
33
+ * User facing: dynamically load the TaskManager DDS for the given unique key.
34
+ */
35
+ const { dds: taskManager } = useDynamicDDS(uniqueKey, TaskManager);
36
+ /**
37
+ * When the task id changes, lock the task. When the task id is undefined, abandon the task.
38
+ */
39
+ React.useEffect(() => {
40
+ let mounted = true;
41
+ if (taskManager) {
42
+ if (taskId && currentTaskIdRef.current !== taskId) {
43
+ if (currentTaskIdRef.current) {
44
+ taskManager.abandon(currentTaskIdRef.current);
45
+ setLockedTask(false);
46
+ }
47
+ currentTaskIdRef.current = taskId;
48
+ const onLockTask = () => __awaiter(void 0, void 0, void 0, function* () {
49
+ try {
50
+ yield taskManager.lockTask(taskId);
51
+ if (mounted) {
52
+ setLockedTask(true);
53
+ }
54
+ }
55
+ catch (_a) {
56
+ if (mounted) {
57
+ setLockedTask(false);
58
+ currentTaskIdRef.current = undefined;
59
+ }
60
+ }
61
+ });
62
+ onLockTask();
63
+ }
64
+ else if (!taskId && currentTaskIdRef.current) {
65
+ taskManager.abandon(currentTaskIdRef.current);
66
+ setLockedTask(false);
67
+ currentTaskIdRef.current = undefined;
68
+ }
69
+ }
70
+ /**
71
+ * When the component unmounts, abandon the task if it is still locked
72
+ */
73
+ return () => {
74
+ mounted = false;
75
+ if (currentTaskIdRef.current) {
76
+ taskManager === null || taskManager === void 0 ? void 0 : taskManager.abandon(currentTaskIdRef.current);
77
+ }
78
+ currentTaskIdRef.current = undefined;
79
+ };
80
+ }, [taskManager, taskId]);
81
+ return {
82
+ lockedTask,
83
+ taskManager,
84
+ };
85
+ };
86
+ //# sourceMappingURL=useTaskManager.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useTaskManager.js","sourceRoot":"","sources":["../../src/shared-hooks/useTaskManager.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,aAAa,EAA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AK,CAAC,CAAC;4BACrB,gBAAgB,CAAC,OAAO,GAAG,SAAS,CAAC;yBACxC;qBACJ;gBACL,CAAC,CAAA,CAAA;gBACD,UAAU,EAAE,CAAC;aAChB;iBAAM,IAAI,CAAC,MAAM,IAAI,gBAAgB,CAAC,OAAO,EAAE;gBAC5C,WAAW,CAAC,OAAO,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC;gBAC9C,aAAa,CAAC,KAAK,CAAC,CAAC;gBACrB,gBAAgB,CAAC,OAAO,GAAG,SAAS,CAAC;aACxC;SACJ;QACD;;WAEG;QACH,OAAO,GAAG,EAAE;YACR,OAAO,GAAG,KAAK,CAAC;YAChB,IAAI,gBAAgB,CAAC,OAAO,EAAE;gBAC1B,WAAW,aAAX,WAAW,uBAAX,WAAW,CAAE,OAAO,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC;aAClD;YACD,gBAAgB,CAAC,OAAO,GAAG,SAAS,CAAC;QACzC,CAAC,CAAA;IACL,CAAC,EAAE,CAAC,WAAW,EAAE,MAAM,CAAC,CAAC,CAAC;IAE1B,OAAO;QACH,UAAU;QACV,WAAW;KACd,CAAC;AACN,CAAC,CAAC"}
@@ -0,0 +1,30 @@
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation. All rights reserved.
3
+ * Licensed under the Microsoft Live Share SDK License.
4
+ */
5
+ import React from "react";
6
+ import { IFluidLoadable } from "@fluidframework/core-interfaces";
7
+ import { LoadableObjectClass } from "fluid-framework";
8
+ import { ITimerConfig, PresenceState } from "@microsoft/live-share";
9
+ export declare type SetSharedStateAction<T> = (state: T) => void;
10
+ export declare type SetLocalStateAction = React.Dispatch<React.SetStateAction<any>>;
11
+ export declare type RegisterDDSSetStateAction = <T extends IFluidLoadable>(uniqueKey: string, componentId: string, objectClass: LoadableObjectClass<T>, setLocalStateAction: SetLocalStateAction, onDidFirstInitialize?: (dds: T) => void) => void;
12
+ export declare type UnregisterDDSSetStateAction = (uniqueKey: string, componentId: string) => void;
13
+ export declare type RegisterSharedSetStateAction = (uniqueKey: string, componentId: string, setLocalStateAction: SetLocalStateAction) => void;
14
+ export declare type UnregisterSharedSetStateAction = (uniqueKey: string, componentId: string) => void;
15
+ export declare type UpdateSharedStateAction = (uniqueKey: string, value: any) => void;
16
+ export declare type DeleteSharedStateAction = (uniqueKey: string) => void;
17
+ export declare type DisposeSharedStateAction = () => void;
18
+ export declare type SetLiveStateAction<TState = undefined> = (state: TState) => void;
19
+ export declare type SendLiveEventAction<TEvent> = (event: TEvent) => void;
20
+ export declare type OnReceivedLiveEventAction<TEvent> = (event: TEvent, local: boolean) => void;
21
+ export declare type OnUpdateLivePresenceAction<TData extends object = object> = (state?: PresenceState | undefined, data?: TData | undefined) => void;
22
+ export declare type OnStartTimerAction = (duration: number) => void;
23
+ export declare type OnPlayTimerAction = () => void;
24
+ export declare type OnPauseTimerAction = () => void;
25
+ export declare type OnTimerTickAction = (milliRemaining: number) => void;
26
+ export declare type OnTimerDidStartAction = (timerConfig: ITimerConfig) => void;
27
+ export declare type OnTimerDidPauseAction = (timerConfig: ITimerConfig) => void;
28
+ export declare type OnTimerDidPlayAction = (timerConfig: ITimerConfig) => void;
29
+ export declare type OnTimerDidFinishAction = (timerConfig: ITimerConfig) => void;
30
+ //# sourceMappingURL=ActionTypes.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ActionTypes.d.ts","sourceRoot":"","sources":["../../src/types/ActionTypes.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,cAAc,EAAE,MAAM,iCAAiC,CAAC;AACjE,OAAO,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AACtD,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAGpE,oBAAY,oBAAoB,CAAC,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC,KAAK,IAAI,CAAC;AACzD,oBAAY,mBAAmB,G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AAG,SAAS,EACjC,IAAI,CAAC,EAAE,KAAK,GAAG,SAAS,KACvB,IAAI,CAAC;AAEV,oBAAY,kBAAkB,GAAG,CAC7B,QAAQ,EAAE,MAAM,KACf,IAAI,CAAC;AAEV,oBAAY,iBAAiB,GAAG,MAAM,IAAI,CAAC;AAE3C,oBAAY,kBAAkB,GAAG,MAAM,IAAI,CAAC;AAE5C,oBAAY,iBAAiB,GAAG,CAAC,cAAc,EAAE,MAAM,KAAK,IAAI,CAAC;AACjE,oBAAY,qBAAqB,GAAG,CAAC,WAAW,EAAE,YAAY,KAAK,IAAI,CAAC;AACxE,oBAAY,qBAAqB,GAAG,CAAC,WAAW,EAAE,YAAY,KAAK,IAAI,CAAC;AACxE,oBAAY,oBAAoB,GAAG,CAAC,WAAW,EAAE,YAAY,KAAK,IAAI,CAAC;AACvE,oBAAY,sBAAsB,GAAG,CAAC,WAAW,EAAE,YAAY,KAAK,IAAI,CAAC"}
@@ -0,0 +1,6 @@
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation. All rights reserved.
3
+ * Licensed under the Microsoft Live Share SDK License.
4
+ */
5
+ export {};
6
+ //# sourceMappingURL=ActionTypes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ActionTypes.js","sourceRoot":"","sources":["../../src/types/ActionTypes.ts"],"names":[],"mappings":"AAAA;;;GAGG"}
@@ -0,0 +1,8 @@
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation. All rights reserved.
3
+ * Licensed under the Microsoft Live Share SDK License.
4
+ */
5
+ export declare type SharedMapInitialData<T> = Map<string, T> | readonly (readonly [string, T])[] | {
6
+ [key: string]: T;
7
+ } | undefined;
8
+ //# sourceMappingURL=PropTypes.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PropTypes.d.ts","sourceRoot":"","sources":["../../src/types/PropTypes.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,oBAAY,oBAAoB,CAAC,CAAC,IAC5B,GAAG,CAAC,MAAM,EAAE,CAAC,CAAC,GACd,SAAS,CAAC,SAAS,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,GACjC;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,CAAC,CAAA;CAAE,GACpB,SAAS,CAAC"}
@@ -0,0 +1,6 @@
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation. All rights reserved.
3
+ * Licensed under the Microsoft Live Share SDK License.
4
+ */
5
+ export {};
6
+ //# sourceMappingURL=PropTypes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PropTypes.js","sourceRoot":"","sources":["../../src/types/PropTypes.ts"],"names":[],"mappings":"AAAA;;;GAGG"}