@microsoft/live-share-react 1.0.0-preview.8 → 1.0.1-preview.1
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.
- package/README.md +99 -34
- package/bin/index.d.ts +6 -6
- package/bin/index.js +6 -6
- package/bin/interfaces/LiveInterfaceExtensions.d.ts +25 -8
- package/bin/interfaces/LiveInterfaceExtensions.d.ts.map +1 -1
- package/bin/interfaces/LiveInterfaceExtensions.js +5 -5
- package/bin/interfaces/index.d.ts +1 -1
- package/bin/interfaces/index.js +1 -1
- package/bin/internal/errors.d.ts +26 -0
- package/bin/internal/errors.d.ts.map +1 -0
- package/bin/internal/errors.js +39 -0
- package/bin/internal/errors.js.map +1 -0
- package/bin/internal/index.d.ts +4 -0
- package/bin/internal/index.d.ts.map +1 -0
- package/bin/internal/index.js +4 -0
- package/bin/internal/index.js.map +1 -0
- package/bin/internal/type-guards.d.ts +6 -0
- package/bin/internal/type-guards.d.ts.map +1 -0
- package/bin/internal/type-guards.js +8 -0
- package/bin/internal/type-guards.js.map +1 -0
- package/bin/{internal-hooks → internal}/useSharedStateRegistry.d.ts +30 -30
- package/bin/internal/useSharedStateRegistry.d.ts.map +1 -0
- package/bin/{internal-hooks → internal}/useSharedStateRegistry.js +101 -99
- package/bin/internal/useSharedStateRegistry.js.map +1 -0
- package/bin/live-hooks/index.d.ts +6 -6
- package/bin/live-hooks/index.js +6 -6
- package/bin/live-hooks/useLiveCanvas.d.ts +27 -27
- package/bin/live-hooks/useLiveCanvas.d.ts.map +1 -1
- package/bin/live-hooks/useLiveCanvas.js +158 -166
- package/bin/live-hooks/useLiveCanvas.js.map +1 -1
- package/bin/live-hooks/useLiveEvent.d.ts +21 -21
- package/bin/live-hooks/useLiveEvent.d.ts.map +1 -1
- package/bin/live-hooks/useLiveEvent.js +100 -85
- package/bin/live-hooks/useLiveEvent.js.map +1 -1
- package/bin/live-hooks/useLivePresence.d.ts +25 -25
- package/bin/live-hooks/useLivePresence.d.ts.map +1 -1
- package/bin/live-hooks/useLivePresence.js +106 -92
- package/bin/live-hooks/useLivePresence.js.map +1 -1
- package/bin/live-hooks/useLiveState.d.ts +19 -19
- package/bin/live-hooks/useLiveState.d.ts.map +1 -1
- package/bin/live-hooks/useLiveState.js +79 -70
- package/bin/live-hooks/useLiveState.js.map +1 -1
- package/bin/live-hooks/useLiveTimer.d.ts +7 -7
- package/bin/live-hooks/useLiveTimer.d.ts.map +1 -1
- package/bin/live-hooks/useLiveTimer.js +150 -131
- package/bin/live-hooks/useLiveTimer.js.map +1 -1
- package/bin/live-hooks/useMediaSynchronizer.d.ts +22 -22
- package/bin/live-hooks/useMediaSynchronizer.d.ts.map +1 -1
- package/bin/live-hooks/useMediaSynchronizer.js +206 -161
- package/bin/live-hooks/useMediaSynchronizer.js.map +1 -1
- package/bin/providers/AzureProvider.d.ts +33 -33
- package/bin/providers/AzureProvider.d.ts.map +1 -1
- package/bin/providers/AzureProvider.js +101 -101
- package/bin/providers/AzureProvider.js.map +1 -1
- package/bin/providers/LiveShareProvider.d.ts +62 -41
- package/bin/providers/LiveShareProvider.d.ts.map +1 -1
- package/bin/providers/LiveShareProvider.js +68 -65
- package/bin/providers/LiveShareProvider.js.map +1 -1
- package/bin/providers/index.d.ts +2 -2
- package/bin/providers/index.js +2 -2
- package/bin/shared-hooks/index.d.ts +3 -4
- package/bin/shared-hooks/index.d.ts.map +1 -1
- package/bin/shared-hooks/index.js +3 -4
- package/bin/shared-hooks/index.js.map +1 -1
- package/bin/shared-hooks/useDynamicDDS.d.ts +18 -18
- package/bin/shared-hooks/useDynamicDDS.d.ts.map +1 -1
- package/bin/shared-hooks/useDynamicDDS.js +67 -67
- package/bin/shared-hooks/useDynamicDDS.js.map +1 -1
- package/bin/shared-hooks/useSharedMap.d.ts +21 -21
- package/bin/shared-hooks/useSharedMap.d.ts.map +1 -1
- package/bin/shared-hooks/useSharedMap.js +112 -105
- package/bin/shared-hooks/useSharedMap.js.map +1 -1
- package/bin/shared-hooks/useSharedState.d.ts +20 -20
- package/bin/shared-hooks/useSharedState.d.ts.map +1 -1
- package/bin/shared-hooks/useSharedState.js +72 -62
- package/bin/shared-hooks/useSharedState.js.map +1 -1
- package/bin/types/ActionTypes.d.ts +111 -29
- package/bin/types/ActionTypes.d.ts.map +1 -1
- package/bin/types/ActionTypes.js +5 -5
- package/bin/types/PropTypes.d.ts +7 -7
- package/bin/types/PropTypes.d.ts.map +1 -1
- package/bin/types/PropTypes.js +5 -5
- package/bin/types/ResultTypes.d.ts +174 -162
- package/bin/types/ResultTypes.d.ts.map +1 -1
- package/bin/types/ResultTypes.js +5 -5
- package/bin/types/index.d.ts +3 -3
- package/bin/types/index.js +3 -3
- package/bin/utils/index.d.ts +1 -1
- package/bin/utils/index.js +1 -1
- package/bin/utils/type-check.d.ts +14 -14
- package/bin/utils/type-check.js +53 -53
- package/package.json +18 -14
- package/src/interfaces/LiveInterfaceExtensions.ts +19 -2
- package/src/internal/errors.ts +48 -0
- package/src/internal/index.ts +3 -0
- package/src/internal/type-guards.ts +9 -0
- package/src/{internal-hooks → internal}/useSharedStateRegistry.ts +6 -5
- package/src/live-hooks/useLiveCanvas.ts +12 -20
- package/src/live-hooks/useLiveEvent.ts +41 -22
- package/src/live-hooks/useLivePresence.ts +52 -33
- package/src/live-hooks/useLiveState.ts +48 -53
- package/src/live-hooks/useLiveTimer.ts +50 -41
- package/src/live-hooks/useMediaSynchronizer.ts +108 -41
- package/src/providers/AzureProvider.tsx +3 -8
- package/src/providers/LiveShareProvider.tsx +46 -16
- package/src/shared-hooks/index.ts +0 -1
- package/src/shared-hooks/useDynamicDDS.ts +15 -8
- package/src/shared-hooks/useSharedMap.ts +48 -22
- package/src/shared-hooks/useSharedState.ts +15 -5
- package/src/types/ActionTypes.ts +100 -15
- package/src/types/ResultTypes.ts +23 -9
- package/bin/internal-hooks/index.d.ts +0 -2
- package/bin/internal-hooks/index.d.ts.map +0 -1
- package/bin/internal-hooks/index.js +0 -2
- package/bin/internal-hooks/index.js.map +0 -1
- package/bin/internal-hooks/useDynamicDDSRegistry.d.ts +0 -14
- package/bin/internal-hooks/useDynamicDDSRegistry.d.ts.map +0 -1
- package/bin/internal-hooks/useDynamicDDSRegistry.js +0 -142
- package/bin/internal-hooks/useDynamicDDSRegistry.js.map +0 -1
- package/bin/internal-hooks/useSharedStateRegistry.d.ts.map +0 -1
- package/bin/internal-hooks/useSharedStateRegistry.js.map +0 -1
- package/bin/internal-hooks/useStateRef.d.ts +0 -7
- package/bin/internal-hooks/useStateRef.d.ts.map +0 -1
- package/bin/internal-hooks/useStateRef.js +0 -15
- package/bin/internal-hooks/useStateRef.js.map +0 -1
- package/bin/live-hooks/useLiveAICompletion.d.ts +0 -29
- package/bin/live-hooks/useLiveAICompletion.d.ts.map +0 -1
- package/bin/live-hooks/useLiveAICompletion.js +0 -186
- package/bin/live-hooks/useLiveAICompletion.js.map +0 -1
- package/bin/live-hooks/useLiveCoPilot.d.ts +0 -28
- package/bin/live-hooks/useLiveCoPilot.d.ts.map +0 -1
- package/bin/live-hooks/useLiveCoPilot.js +0 -178
- package/bin/live-hooks/useLiveCoPilot.js.map +0 -1
- package/bin/live-share-turbo/AzureTurboClient.d.ts +0 -39
- package/bin/live-share-turbo/AzureTurboClient.d.ts.map +0 -1
- package/bin/live-share-turbo/AzureTurboClient.js +0 -56
- package/bin/live-share-turbo/AzureTurboClient.js.map +0 -1
- package/bin/live-share-turbo/LiveShareTurboClient.d.ts +0 -53
- package/bin/live-share-turbo/LiveShareTurboClient.d.ts.map +0 -1
- package/bin/live-share-turbo/LiveShareTurboClient.js +0 -69
- package/bin/live-share-turbo/LiveShareTurboClient.js.map +0 -1
- package/bin/live-share-turbo/dds-objects/TurboDataObject.d.ts +0 -31
- package/bin/live-share-turbo/dds-objects/TurboDataObject.d.ts.map +0 -1
- package/bin/live-share-turbo/dds-objects/TurboDataObject.js +0 -75
- package/bin/live-share-turbo/dds-objects/TurboDataObject.js.map +0 -1
- package/bin/live-share-turbo/dds-objects/TurboLiveCanvas.d.ts +0 -48
- package/bin/live-share-turbo/dds-objects/TurboLiveCanvas.d.ts.map +0 -1
- package/bin/live-share-turbo/dds-objects/TurboLiveCanvas.js +0 -104
- package/bin/live-share-turbo/dds-objects/TurboLiveCanvas.js.map +0 -1
- package/bin/live-share-turbo/dds-objects/TurboLiveEvent.d.ts +0 -28
- package/bin/live-share-turbo/dds-objects/TurboLiveEvent.d.ts.map +0 -1
- package/bin/live-share-turbo/dds-objects/TurboLiveEvent.js +0 -68
- package/bin/live-share-turbo/dds-objects/TurboLiveEvent.js.map +0 -1
- package/bin/live-share-turbo/dds-objects/TurboLiveMediaSession.d.ts +0 -60
- package/bin/live-share-turbo/dds-objects/TurboLiveMediaSession.d.ts.map +0 -1
- package/bin/live-share-turbo/dds-objects/TurboLiveMediaSession.js +0 -111
- package/bin/live-share-turbo/dds-objects/TurboLiveMediaSession.js.map +0 -1
- package/bin/live-share-turbo/dds-objects/TurboLivePresence.d.ts +0 -77
- package/bin/live-share-turbo/dds-objects/TurboLivePresence.d.ts.map +0 -1
- package/bin/live-share-turbo/dds-objects/TurboLivePresence.js +0 -137
- package/bin/live-share-turbo/dds-objects/TurboLivePresence.js.map +0 -1
- package/bin/live-share-turbo/dds-objects/TurboLiveState.d.ts +0 -30
- package/bin/live-share-turbo/dds-objects/TurboLiveState.d.ts.map +0 -1
- package/bin/live-share-turbo/dds-objects/TurboLiveState.js +0 -74
- package/bin/live-share-turbo/dds-objects/TurboLiveState.js.map +0 -1
- package/bin/live-share-turbo/dds-objects/TurboSharedMap.d.ts +0 -61
- package/bin/live-share-turbo/dds-objects/TurboSharedMap.d.ts.map +0 -1
- package/bin/live-share-turbo/dds-objects/TurboSharedMap.js +0 -108
- package/bin/live-share-turbo/dds-objects/TurboSharedMap.js.map +0 -1
- package/bin/live-share-turbo/dds-objects/index.d.ts +0 -8
- package/bin/live-share-turbo/dds-objects/index.d.ts.map +0 -1
- package/bin/live-share-turbo/dds-objects/index.js +0 -8
- package/bin/live-share-turbo/dds-objects/index.js.map +0 -1
- package/bin/live-share-turbo/index.d.ts +0 -5
- package/bin/live-share-turbo/index.d.ts.map +0 -1
- package/bin/live-share-turbo/index.js +0 -5
- package/bin/live-share-turbo/index.js.map +0 -1
- package/bin/live-share-turbo/interfaces/IFluidTurboClient.d.ts +0 -15
- package/bin/live-share-turbo/interfaces/IFluidTurboClient.d.ts.map +0 -1
- package/bin/live-share-turbo/interfaces/IFluidTurboClient.js +0 -2
- package/bin/live-share-turbo/interfaces/IFluidTurboClient.js.map +0 -1
- package/bin/live-share-turbo/interfaces/index.d.ts +0 -3
- package/bin/live-share-turbo/interfaces/index.d.ts.map +0 -1
- package/bin/live-share-turbo/interfaces/index.js +0 -3
- package/bin/live-share-turbo/interfaces/index.js.map +0 -1
- package/bin/live-share-turbo/internals/FluidTurboClient.d.ts +0 -39
- package/bin/live-share-turbo/internals/FluidTurboClient.d.ts.map +0 -1
- package/bin/live-share-turbo/internals/FluidTurboClient.js +0 -121
- package/bin/live-share-turbo/internals/FluidTurboClient.js.map +0 -1
- package/bin/live-share-turbo/internals/index.d.ts +0 -2
- package/bin/live-share-turbo/internals/index.d.ts.map +0 -1
- package/bin/live-share-turbo/internals/index.js +0 -2
- package/bin/live-share-turbo/internals/index.js.map +0 -1
- package/bin/live-share-turbo/internals/types.d.ts +0 -4
- package/bin/live-share-turbo/internals/types.d.ts.map +0 -1
- package/bin/live-share-turbo/internals/types.js +0 -2
- package/bin/live-share-turbo/internals/types.js.map +0 -1
- package/bin/providers/FluidContextProvider.d.ts +0 -34
- package/bin/providers/FluidContextProvider.d.ts.map +0 -1
- package/bin/providers/FluidContextProvider.js +0 -99
- package/bin/providers/FluidContextProvider.js.map +0 -1
- package/bin/providers/LiveShareContextProvider.d.ts +0 -42
- package/bin/providers/LiveShareContextProvider.d.ts.map +0 -1
- package/bin/providers/LiveShareContextProvider.js +0 -63
- package/bin/providers/LiveShareContextProvider.js.map +0 -1
- package/bin/shared-hooks/useLockedTask.d.ts +0 -11
- package/bin/shared-hooks/useLockedTask.d.ts.map +0 -1
- package/bin/shared-hooks/useLockedTask.js +0 -82
- package/bin/shared-hooks/useLockedTask.js.map +0 -1
- package/bin/shared-hooks/useTaskManager.d.ts +0 -13
- package/bin/shared-hooks/useTaskManager.d.ts.map +0 -1
- package/bin/shared-hooks/useTaskManager.js +0 -86
- package/bin/shared-hooks/useTaskManager.js.map +0 -1
- package/bin/utils/getContainerSchema.d.ts +0 -8
- package/bin/utils/getContainerSchema.d.ts.map +0 -1
- package/bin/utils/getContainerSchema.js +0 -41
- package/bin/utils/getContainerSchema.js.map +0 -1
- package/src/internal-hooks/index.ts +0 -1
- package/src/shared-hooks/useTaskManager.ts +0 -82
- package/tinylicious.log +0 -4
|
@@ -1,100 +1,102 @@
|
|
|
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
|
-
/**
|
|
7
|
-
* Hook used internally to keep track of the SharedSetStateActionMap for each unique key. It sets state values for provided keys and updates components listening to the values.
|
|
8
|
-
*
|
|
9
|
-
* @param results IAzureContainerResults response or undefined
|
|
10
|
-
* @returns ISharedStateRegistryResponse object
|
|
11
|
-
*/
|
|
12
|
-
export const useSharedStateRegistry = (results) => {
|
|
13
|
-
const registeredSharedSetStateActionMapRef = React.useRef(new Map());
|
|
14
|
-
/**
|
|
15
|
-
* @see ISharedStateRegistryResponse.registerSharedSetStateAction
|
|
16
|
-
*/
|
|
17
|
-
const registerSharedSetStateAction = React.useCallback((uniqueKey, componentId, setLocalStateAction) => {
|
|
18
|
-
let actionsMap = registeredSharedSetStateActionMapRef.current.get(uniqueKey);
|
|
19
|
-
if (actionsMap) {
|
|
20
|
-
if (!actionsMap.has(componentId)) {
|
|
21
|
-
actionsMap.set(componentId, setLocalStateAction);
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
else {
|
|
25
|
-
actionsMap = new Map();
|
|
26
|
-
actionsMap.set(componentId, setLocalStateAction);
|
|
27
|
-
registeredSharedSetStateActionMapRef.current.set(uniqueKey, actionsMap);
|
|
28
|
-
}
|
|
29
|
-
// Set initial values, if known
|
|
30
|
-
const stateMap = results === null || results === void 0 ? void 0 : results.container.initialObjects.TURBO_STATE_MAP;
|
|
31
|
-
const initialValue = stateMap === null || stateMap === void 0 ? void 0 : stateMap.get(uniqueKey);
|
|
32
|
-
if (initialValue) {
|
|
33
|
-
setLocalStateAction(initialValue);
|
|
34
|
-
}
|
|
35
|
-
}, [results]);
|
|
36
|
-
/**
|
|
37
|
-
* @see ISharedStateRegistryResponse.unregisterSharedSetStateAction
|
|
38
|
-
*/
|
|
39
|
-
const unregisterSharedSetStateAction = React.useCallback((uniqueKey, componentId) => {
|
|
40
|
-
let actionsMap = registeredSharedSetStateActionMapRef.current.get(uniqueKey);
|
|
41
|
-
if (actionsMap === null || actionsMap === void 0 ? void 0 : actionsMap.has(componentId)) {
|
|
42
|
-
actionsMap.delete(componentId);
|
|
43
|
-
}
|
|
44
|
-
}, []);
|
|
45
|
-
/**
|
|
46
|
-
* @see ISharedStateRegistryResponse.updateSharedState
|
|
47
|
-
*/
|
|
48
|
-
const updateSharedState = React.useCallback((uniqueKey, value) => {
|
|
49
|
-
if (!results)
|
|
50
|
-
return;
|
|
51
|
-
const { container } = results;
|
|
52
|
-
const stateMap = container.initialObjects
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
stateMap.
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
const
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
stateMap.
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
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
|
+
/**
|
|
7
|
+
* Hook used internally to keep track of the SharedSetStateActionMap for each unique key. It sets state values for provided keys and updates components listening to the values.
|
|
8
|
+
*
|
|
9
|
+
* @param results IAzureContainerResults response or undefined
|
|
10
|
+
* @returns ISharedStateRegistryResponse object
|
|
11
|
+
*/
|
|
12
|
+
export const useSharedStateRegistry = (results) => {
|
|
13
|
+
const registeredSharedSetStateActionMapRef = React.useRef(new Map());
|
|
14
|
+
/**
|
|
15
|
+
* @see ISharedStateRegistryResponse.registerSharedSetStateAction
|
|
16
|
+
*/
|
|
17
|
+
const registerSharedSetStateAction = React.useCallback((uniqueKey, componentId, setLocalStateAction) => {
|
|
18
|
+
let actionsMap = registeredSharedSetStateActionMapRef.current.get(uniqueKey);
|
|
19
|
+
if (actionsMap) {
|
|
20
|
+
if (!actionsMap.has(componentId)) {
|
|
21
|
+
actionsMap.set(componentId, setLocalStateAction);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
actionsMap = new Map();
|
|
26
|
+
actionsMap.set(componentId, setLocalStateAction);
|
|
27
|
+
registeredSharedSetStateActionMapRef.current.set(uniqueKey, actionsMap);
|
|
28
|
+
}
|
|
29
|
+
// Set initial values, if known
|
|
30
|
+
const stateMap = results === null || results === void 0 ? void 0 : results.container.initialObjects.TURBO_STATE_MAP;
|
|
31
|
+
const initialValue = stateMap === null || stateMap === void 0 ? void 0 : stateMap.get(uniqueKey);
|
|
32
|
+
if (initialValue) {
|
|
33
|
+
setLocalStateAction(initialValue);
|
|
34
|
+
}
|
|
35
|
+
}, [results]);
|
|
36
|
+
/**
|
|
37
|
+
* @see ISharedStateRegistryResponse.unregisterSharedSetStateAction
|
|
38
|
+
*/
|
|
39
|
+
const unregisterSharedSetStateAction = React.useCallback((uniqueKey, componentId) => {
|
|
40
|
+
let actionsMap = registeredSharedSetStateActionMapRef.current.get(uniqueKey);
|
|
41
|
+
if (actionsMap === null || actionsMap === void 0 ? void 0 : actionsMap.has(componentId)) {
|
|
42
|
+
actionsMap.delete(componentId);
|
|
43
|
+
}
|
|
44
|
+
}, []);
|
|
45
|
+
/**
|
|
46
|
+
* @see ISharedStateRegistryResponse.updateSharedState
|
|
47
|
+
*/
|
|
48
|
+
const updateSharedState = React.useCallback((uniqueKey, value) => {
|
|
49
|
+
if (!results)
|
|
50
|
+
return;
|
|
51
|
+
const { container } = results;
|
|
52
|
+
const stateMap = container.initialObjects
|
|
53
|
+
.TURBO_STATE_MAP;
|
|
54
|
+
stateMap.set(uniqueKey, value);
|
|
55
|
+
}, [results]);
|
|
56
|
+
/**
|
|
57
|
+
* @see ISharedStateRegistryResponse.deleteSharedState
|
|
58
|
+
*/
|
|
59
|
+
const deleteSharedState = React.useCallback((uniqueKey) => {
|
|
60
|
+
if (!results)
|
|
61
|
+
return;
|
|
62
|
+
const { container } = results;
|
|
63
|
+
let actionsMap = registeredSharedSetStateActionMapRef.current.get(uniqueKey);
|
|
64
|
+
actionsMap === null || actionsMap === void 0 ? void 0 : actionsMap.clear();
|
|
65
|
+
const stateMap = container.initialObjects
|
|
66
|
+
.TURBO_STATE_MAP;
|
|
67
|
+
stateMap.delete(uniqueKey);
|
|
68
|
+
}, [results]);
|
|
69
|
+
React.useEffect(() => {
|
|
70
|
+
if (!results)
|
|
71
|
+
return;
|
|
72
|
+
const { container } = results;
|
|
73
|
+
const stateMap = container.initialObjects.TURBO_STATE_MAP;
|
|
74
|
+
const valueChangedListener = (changed) => {
|
|
75
|
+
if (registeredSharedSetStateActionMapRef.current.has(changed.key)) {
|
|
76
|
+
const value = stateMap.get(changed.key);
|
|
77
|
+
const actionMap = registeredSharedSetStateActionMapRef.current.get(changed.key);
|
|
78
|
+
actionMap === null || actionMap === void 0 ? void 0 : actionMap.forEach((setLocalStateHandler) => {
|
|
79
|
+
setLocalStateHandler(value);
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
stateMap.on("valueChanged", valueChangedListener);
|
|
84
|
+
// Set initial values
|
|
85
|
+
stateMap.forEach((value, key) => {
|
|
86
|
+
const actionMap = registeredSharedSetStateActionMapRef.current.get(key);
|
|
87
|
+
actionMap === null || actionMap === void 0 ? void 0 : actionMap.forEach((setLocalStateHandler) => {
|
|
88
|
+
setLocalStateHandler(value);
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
return () => {
|
|
92
|
+
stateMap.off("valueChanged", valueChangedListener);
|
|
93
|
+
};
|
|
94
|
+
}, [results]);
|
|
95
|
+
return {
|
|
96
|
+
registerSharedSetStateAction,
|
|
97
|
+
unregisterSharedSetStateAction,
|
|
98
|
+
updateSharedState,
|
|
99
|
+
deleteSharedState,
|
|
100
|
+
};
|
|
101
|
+
};
|
|
100
102
|
//# sourceMappingURL=useSharedStateRegistry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useSharedStateRegistry.js","sourceRoot":"","sources":["../../src/internal/useSharedStateRegistry.ts"],"names":[],"mappings":"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"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export * from "./useLivePresence";
|
|
2
|
-
export * from "./useLiveState";
|
|
3
|
-
export * from "./useMediaSynchronizer";
|
|
4
|
-
export * from "./useLiveEvent";
|
|
5
|
-
export * from "./useLiveCanvas";
|
|
6
|
-
export * from "./useLiveTimer";
|
|
1
|
+
export * from "./useLivePresence";
|
|
2
|
+
export * from "./useLiveState";
|
|
3
|
+
export * from "./useMediaSynchronizer";
|
|
4
|
+
export * from "./useLiveEvent";
|
|
5
|
+
export * from "./useLiveCanvas";
|
|
6
|
+
export * from "./useLiveTimer";
|
|
7
7
|
//# sourceMappingURL=index.d.ts.map
|
package/bin/live-hooks/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export * from "./useLivePresence";
|
|
2
|
-
export * from "./useLiveState";
|
|
3
|
-
export * from "./useMediaSynchronizer";
|
|
4
|
-
export * from "./useLiveEvent";
|
|
5
|
-
export * from "./useLiveCanvas";
|
|
6
|
-
export * from "./useLiveTimer";
|
|
1
|
+
export * from "./useLivePresence";
|
|
2
|
+
export * from "./useLiveState";
|
|
3
|
+
export * from "./useMediaSynchronizer";
|
|
4
|
+
export * from "./useLiveEvent";
|
|
5
|
+
export * from "./useLiveCanvas";
|
|
6
|
+
export * from "./useLiveTimer";
|
|
7
7
|
//# sourceMappingURL=index.js.map
|
|
@@ -1,28 +1,28 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
-
* Licensed under the Microsoft Live Share SDK License.
|
|
4
|
-
*/
|
|
5
|
-
import { CanvasReferencePoint, IBrush, InkingTool, IPoint
|
|
6
|
-
import React from "react";
|
|
7
|
-
import { IUseLiveCanvasResults } from "../types";
|
|
8
|
-
/**
|
|
9
|
-
* React hook for using a Live Share Canvas `LiveCanvas` and `InkingManager`.
|
|
10
|
-
*
|
|
11
|
-
* @remarks
|
|
12
|
-
* Use this hook to set up an `LiveCanvas` object, which is used for collaborative inking. It takes several input parameters, including a unique key,
|
|
13
|
-
* a reference to a canvas element, and various settings for the inking tool, brush, and canvas offset and scale.
|
|
14
|
-
*
|
|
15
|
-
* @param uniqueKey the unique key for the `LiveCanvas`. If one does not yet exist, a new one.
|
|
16
|
-
* @param canvasElementRef the HTML div element ref or document ID that `InkingManager` will use for canvas-based collaboration.
|
|
17
|
-
* @param active Optional. Stateful boolean that will activate/de-activate `InkingManager` accordingly.
|
|
18
|
-
* @param tool Optional. Stateful enum for what tool to use in the `InkingManager`.
|
|
19
|
-
* @param lineBrush Optional. Stateful lineBrush object for the selected lineBrush options to use in `InkingManager`.
|
|
20
|
-
* @param offset Optional. Stateful offset point to use in the `InkingManager`. Gets the viewport offset. Defaults to 0,0.
|
|
21
|
-
* @param scale Optional. Stateful scale number to use in the `InkingManager`. Defaults to 1 and must be greater than 0.
|
|
22
|
-
* @param referencePoint Optional. Stateful reference point enum to use in the `InkingManger`. Defaults to "center".
|
|
23
|
-
* @param isCursorShared Optional. Stateful boolean flag for whether cursor should be shared in `LiveCanvas`. Defaults to false.
|
|
24
|
-
* @param
|
|
25
|
-
* @returns IUseLiveCanvasResults object that contains the `liveCanvas` data object and `inkingManager`.
|
|
26
|
-
*/
|
|
27
|
-
export declare function useLiveCanvas(uniqueKey: string, canvasElementRef: React.RefObject<HTMLElement | null> | string, active?: boolean, tool?: InkingTool, lineBrush?: IBrush, offset?: IPoint, scale?: number, referencePoint?: CanvasReferencePoint, isCursorShared?: boolean,
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
* Licensed under the Microsoft Live Share SDK License.
|
|
4
|
+
*/
|
|
5
|
+
import { CanvasReferencePoint, IBrush, InkingTool, IPoint } from "@microsoft/live-share-canvas";
|
|
6
|
+
import React from "react";
|
|
7
|
+
import { IUseLiveCanvasResults } from "../types";
|
|
8
|
+
/**
|
|
9
|
+
* React hook for using a Live Share Canvas `LiveCanvas` and `InkingManager`.
|
|
10
|
+
*
|
|
11
|
+
* @remarks
|
|
12
|
+
* Use this hook to set up an `LiveCanvas` object, which is used for collaborative inking. It takes several input parameters, including a unique key,
|
|
13
|
+
* a reference to a canvas element, and various settings for the inking tool, brush, and canvas offset and scale.
|
|
14
|
+
*
|
|
15
|
+
* @param uniqueKey the unique key for the `LiveCanvas`. If one does not yet exist, a new one.
|
|
16
|
+
* @param canvasElementRef the HTML div element ref or document ID that `InkingManager` will use for canvas-based collaboration.
|
|
17
|
+
* @param active Optional. Stateful boolean that will activate/de-activate `InkingManager` accordingly.
|
|
18
|
+
* @param tool Optional. Stateful enum for what tool to use in the `InkingManager`.
|
|
19
|
+
* @param lineBrush Optional. Stateful lineBrush object for the selected lineBrush options to use in `InkingManager`.
|
|
20
|
+
* @param offset Optional. Stateful offset point to use in the `InkingManager`. Gets the viewport offset. Defaults to 0,0.
|
|
21
|
+
* @param scale Optional. Stateful scale number to use in the `InkingManager`. Defaults to 1 and must be greater than 0.
|
|
22
|
+
* @param referencePoint Optional. Stateful reference point enum to use in the `InkingManger`. Defaults to "center".
|
|
23
|
+
* @param isCursorShared Optional. Stateful boolean flag for whether cursor should be shared in `LiveCanvas`. Defaults to false.
|
|
24
|
+
* @param localUserPictureUrl Optional. url string for the local user to display alongside their cursor. Defaults to undefined.
|
|
25
|
+
* @returns IUseLiveCanvasResults object that contains the `liveCanvas` data object and `inkingManager`.
|
|
26
|
+
*/
|
|
27
|
+
export declare function useLiveCanvas(uniqueKey: string, canvasElementRef: React.RefObject<HTMLElement | null> | string, active?: boolean, tool?: InkingTool, lineBrush?: IBrush, offset?: IPoint, scale?: number, referencePoint?: CanvasReferencePoint, isCursorShared?: boolean, localUserPictureUrl?: string): IUseLiveCanvasResults;
|
|
28
28
|
//# sourceMappingURL=useLiveCanvas.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useLiveCanvas.d.ts","sourceRoot":"","sources":["../../src/live-hooks/useLiveCanvas.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EACH,oBAAoB,EACpB,MAAM,EAEN,UAAU,EACV,MAAM,
|
|
1
|
+
{"version":3,"file":"useLiveCanvas.d.ts","sourceRoot":"","sources":["../../src/live-hooks/useLiveCanvas.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EACH,oBAAoB,EACpB,MAAM,EAEN,UAAU,EACV,MAAM,EAET,MAAM,8BAA8B,CAAC;AACtC,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,EAAE,qBAAqB,EAAE,MAAM,UAAU,CAAC;AAGjD;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,aAAa,CACzB,SAAS,EAAE,MAAM,EACjB,gBAAgB,EAAE,KAAK,CAAC,SAAS,CAAC,WAAW,GAAG,IAAI,CAAC,GAAG,MAAM,EAC9D,MAAM,CAAC,EAAE,OAAO,EAChB,IAAI,CAAC,EAAE,UAAU,EACjB,SAAS,CAAC,EAAE,MAAM,EAClB,MAAM,CAAC,EAAE,MAAM,EACf,KAAK,CAAC,EAAE,MAAM,EACd,cAAc,CAAC,EAAE,oBAAoB,EACrC,cAAc,CAAC,EAAE,OAAO,EACxB,mBAAmB,CAAC,EAAE,MAAM,GAC7B,qBAAqB,CA6IvB"}
|
|
@@ -1,167 +1,159 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
-
* Licensed under the Microsoft Live Share SDK License.
|
|
4
|
-
*/
|
|
5
|
-
import { InkingManager, LiveCanvas, } from "@microsoft/live-share-canvas";
|
|
6
|
-
import React from "react";
|
|
7
|
-
import { useDynamicDDS } from "../shared-hooks";
|
|
8
|
-
import { isRefObject } from "../utils";
|
|
9
|
-
/**
|
|
10
|
-
* React hook for using a Live Share Canvas `LiveCanvas` and `InkingManager`.
|
|
11
|
-
*
|
|
12
|
-
* @remarks
|
|
13
|
-
* Use this hook to set up an `LiveCanvas` object, which is used for collaborative inking. It takes several input parameters, including a unique key,
|
|
14
|
-
* a reference to a canvas element, and various settings for the inking tool, brush, and canvas offset and scale.
|
|
15
|
-
*
|
|
16
|
-
* @param uniqueKey the unique key for the `LiveCanvas`. If one does not yet exist, a new one.
|
|
17
|
-
* @param canvasElementRef the HTML div element ref or document ID that `InkingManager` will use for canvas-based collaboration.
|
|
18
|
-
* @param active Optional. Stateful boolean that will activate/de-activate `InkingManager` accordingly.
|
|
19
|
-
* @param tool Optional. Stateful enum for what tool to use in the `InkingManager`.
|
|
20
|
-
* @param lineBrush Optional. Stateful lineBrush object for the selected lineBrush options to use in `InkingManager`.
|
|
21
|
-
* @param offset Optional. Stateful offset point to use in the `InkingManager`. Gets the viewport offset. Defaults to 0,0.
|
|
22
|
-
* @param scale Optional. Stateful scale number to use in the `InkingManager`. Defaults to 1 and must be greater than 0.
|
|
23
|
-
* @param referencePoint Optional. Stateful reference point enum to use in the `InkingManger`. Defaults to "center".
|
|
24
|
-
* @param isCursorShared Optional. Stateful boolean flag for whether cursor should be shared in `LiveCanvas`. Defaults to false.
|
|
25
|
-
* @param
|
|
26
|
-
* @returns IUseLiveCanvasResults object that contains the `liveCanvas` data object and `inkingManager`.
|
|
27
|
-
*/
|
|
28
|
-
export function useLiveCanvas(uniqueKey, canvasElementRef, active, tool, lineBrush, offset, scale, referencePoint, isCursorShared,
|
|
29
|
-
/**
|
|
30
|
-
* User facing: inking manager instance
|
|
31
|
-
*/
|
|
32
|
-
const [inkingManager, setInkingManager] = React.useState();
|
|
33
|
-
/**
|
|
34
|
-
* User facing: dynamically load the DDS for the given unique key.
|
|
35
|
-
*/
|
|
36
|
-
const { dds: liveCanvas } = useDynamicDDS(uniqueKey, LiveCanvas);
|
|
37
|
-
/**
|
|
38
|
-
* Setup the InkingManager and LiveCanvas
|
|
39
|
-
*/
|
|
40
|
-
React.useEffect(() => {
|
|
41
|
-
// if the component is already listening or liveCanvas is not yet initialized, return
|
|
42
|
-
if (!liveCanvas)
|
|
43
|
-
return;
|
|
44
|
-
// get the canvas element from the ref or document
|
|
45
|
-
let htmlElement;
|
|
46
|
-
if (isRefObject(canvasElementRef)) {
|
|
47
|
-
htmlElement = canvasElementRef.current;
|
|
48
|
-
}
|
|
49
|
-
else {
|
|
50
|
-
htmlElement = document.getElementById(canvasElementRef);
|
|
51
|
-
}
|
|
52
|
-
if (htmlElement === null)
|
|
53
|
-
return;
|
|
54
|
-
// Create the InkingManager and initialize the liveCanvas with it
|
|
55
|
-
const inkingManager = new InkingManager(htmlElement);
|
|
56
|
-
setInkingManager(inkingManager);
|
|
57
|
-
liveCanvas.initialize(inkingManager);
|
|
58
|
-
// cleanup function to be called when the component is unmount
|
|
59
|
-
return () => {
|
|
60
|
-
liveCanvas.dispose();
|
|
61
|
-
inkingManager.removeAllListeners();
|
|
62
|
-
};
|
|
63
|
-
}, [liveCanvas]);
|
|
64
|
-
/**
|
|
65
|
-
* Activate or deactivate the inkingManager based on the 'active' prop
|
|
66
|
-
*/
|
|
67
|
-
React.useEffect(() => {
|
|
68
|
-
if (inkingManager && active !== undefined) {
|
|
69
|
-
if (active) {
|
|
70
|
-
inkingManager.activate();
|
|
71
|
-
}
|
|
72
|
-
else {
|
|
73
|
-
inkingManager.deactivate();
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
}, [active, inkingManager]);
|
|
77
|
-
/**
|
|
78
|
-
* Sets the tool of the inkingManager based on the 'tool' prop
|
|
79
|
-
*/
|
|
80
|
-
React.useEffect(() => {
|
|
81
|
-
if (inkingManager && tool !== undefined) {
|
|
82
|
-
inkingManager.tool = tool;
|
|
83
|
-
}
|
|
84
|
-
}, [tool, inkingManager]);
|
|
85
|
-
/**
|
|
86
|
-
* Sets the offset of the inkingManager based on the 'offset' prop
|
|
87
|
-
*/
|
|
88
|
-
React.useEffect(() => {
|
|
89
|
-
if (inkingManager && offset !== undefined) {
|
|
90
|
-
inkingManager.offset = {
|
|
91
|
-
x: offset.x,
|
|
92
|
-
y: offset.y,
|
|
93
|
-
};
|
|
94
|
-
}
|
|
95
|
-
}, [offset === null || offset === void 0 ? void 0 : offset.x, offset === null || offset === void 0 ? void 0 : offset.y, inkingManager]);
|
|
96
|
-
/**
|
|
97
|
-
* Sets the scale of the inkingManager based on the 'scale' prop
|
|
98
|
-
*/
|
|
99
|
-
React.useEffect(() => {
|
|
100
|
-
if (inkingManager && scale !== undefined) {
|
|
101
|
-
inkingManager.scale = scale;
|
|
102
|
-
}
|
|
103
|
-
}, [scale, inkingManager]);
|
|
104
|
-
/**
|
|
105
|
-
* Sets the referencePoint of the inkingManager based on the 'referencePoint' prop
|
|
106
|
-
*/
|
|
107
|
-
React.useEffect(() => {
|
|
108
|
-
if (inkingManager && referencePoint !== undefined) {
|
|
109
|
-
inkingManager.referencePoint = referencePoint;
|
|
110
|
-
}
|
|
111
|
-
}, [referencePoint, inkingManager]);
|
|
112
|
-
/**
|
|
113
|
-
* Sets the lineBrush of the inkingManager based on the 'lineBrush' prop
|
|
114
|
-
*/
|
|
115
|
-
React.useEffect(() => {
|
|
116
|
-
if (inkingManager && lineBrush) {
|
|
117
|
-
inkingManager.lineBrush = {
|
|
118
|
-
color: lineBrush.color,
|
|
119
|
-
tip: lineBrush.tip,
|
|
120
|
-
tipSize: lineBrush.tipSize,
|
|
121
|
-
type: lineBrush.type,
|
|
122
|
-
endArrow: lineBrush.endArrow,
|
|
123
|
-
};
|
|
124
|
-
}
|
|
125
|
-
}, [
|
|
126
|
-
lineBrush === null || lineBrush === void 0 ? void 0 : lineBrush.color,
|
|
127
|
-
lineBrush === null || lineBrush === void 0 ? void 0 : lineBrush.tip,
|
|
128
|
-
lineBrush === null || lineBrush === void 0 ? void 0 : lineBrush.tipSize,
|
|
129
|
-
lineBrush === null || lineBrush === void 0 ? void 0 : lineBrush.type,
|
|
130
|
-
lineBrush === null || lineBrush === void 0 ? void 0 : lineBrush.endArrow,
|
|
131
|
-
inkingManager,
|
|
132
|
-
]);
|
|
133
|
-
/**
|
|
134
|
-
* Sets the isCursorShared of the liveCanvas based on the 'isCursorShared' prop
|
|
135
|
-
*/
|
|
136
|
-
React.useEffect(() => {
|
|
137
|
-
if (
|
|
138
|
-
isCursorShared
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
/**
|
|
160
|
-
* Return hook response
|
|
161
|
-
*/
|
|
162
|
-
return {
|
|
163
|
-
inkingManager,
|
|
164
|
-
liveCanvas,
|
|
165
|
-
};
|
|
166
|
-
}
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
* Licensed under the Microsoft Live Share SDK License.
|
|
4
|
+
*/
|
|
5
|
+
import { InkingManager, LiveCanvas, } from "@microsoft/live-share-canvas";
|
|
6
|
+
import React from "react";
|
|
7
|
+
import { useDynamicDDS } from "../shared-hooks";
|
|
8
|
+
import { isRefObject } from "../utils";
|
|
9
|
+
/**
|
|
10
|
+
* React hook for using a Live Share Canvas `LiveCanvas` and `InkingManager`.
|
|
11
|
+
*
|
|
12
|
+
* @remarks
|
|
13
|
+
* Use this hook to set up an `LiveCanvas` object, which is used for collaborative inking. It takes several input parameters, including a unique key,
|
|
14
|
+
* a reference to a canvas element, and various settings for the inking tool, brush, and canvas offset and scale.
|
|
15
|
+
*
|
|
16
|
+
* @param uniqueKey the unique key for the `LiveCanvas`. If one does not yet exist, a new one.
|
|
17
|
+
* @param canvasElementRef the HTML div element ref or document ID that `InkingManager` will use for canvas-based collaboration.
|
|
18
|
+
* @param active Optional. Stateful boolean that will activate/de-activate `InkingManager` accordingly.
|
|
19
|
+
* @param tool Optional. Stateful enum for what tool to use in the `InkingManager`.
|
|
20
|
+
* @param lineBrush Optional. Stateful lineBrush object for the selected lineBrush options to use in `InkingManager`.
|
|
21
|
+
* @param offset Optional. Stateful offset point to use in the `InkingManager`. Gets the viewport offset. Defaults to 0,0.
|
|
22
|
+
* @param scale Optional. Stateful scale number to use in the `InkingManager`. Defaults to 1 and must be greater than 0.
|
|
23
|
+
* @param referencePoint Optional. Stateful reference point enum to use in the `InkingManger`. Defaults to "center".
|
|
24
|
+
* @param isCursorShared Optional. Stateful boolean flag for whether cursor should be shared in `LiveCanvas`. Defaults to false.
|
|
25
|
+
* @param localUserPictureUrl Optional. url string for the local user to display alongside their cursor. Defaults to undefined.
|
|
26
|
+
* @returns IUseLiveCanvasResults object that contains the `liveCanvas` data object and `inkingManager`.
|
|
27
|
+
*/
|
|
28
|
+
export function useLiveCanvas(uniqueKey, canvasElementRef, active, tool, lineBrush, offset, scale, referencePoint, isCursorShared, localUserPictureUrl) {
|
|
29
|
+
/**
|
|
30
|
+
* User facing: inking manager instance
|
|
31
|
+
*/
|
|
32
|
+
const [inkingManager, setInkingManager] = React.useState();
|
|
33
|
+
/**
|
|
34
|
+
* User facing: dynamically load the DDS for the given unique key.
|
|
35
|
+
*/
|
|
36
|
+
const { dds: liveCanvas } = useDynamicDDS(uniqueKey, LiveCanvas);
|
|
37
|
+
/**
|
|
38
|
+
* Setup the InkingManager and LiveCanvas
|
|
39
|
+
*/
|
|
40
|
+
React.useEffect(() => {
|
|
41
|
+
// if the component is already listening or liveCanvas is not yet initialized, return
|
|
42
|
+
if (!liveCanvas)
|
|
43
|
+
return;
|
|
44
|
+
// get the canvas element from the ref or document
|
|
45
|
+
let htmlElement;
|
|
46
|
+
if (isRefObject(canvasElementRef)) {
|
|
47
|
+
htmlElement = canvasElementRef.current;
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
htmlElement = document.getElementById(canvasElementRef);
|
|
51
|
+
}
|
|
52
|
+
if (htmlElement === null)
|
|
53
|
+
return;
|
|
54
|
+
// Create the InkingManager and initialize the liveCanvas with it
|
|
55
|
+
const inkingManager = new InkingManager(htmlElement);
|
|
56
|
+
setInkingManager(inkingManager);
|
|
57
|
+
liveCanvas.initialize(inkingManager);
|
|
58
|
+
// cleanup function to be called when the component is unmount
|
|
59
|
+
return () => {
|
|
60
|
+
liveCanvas.dispose();
|
|
61
|
+
inkingManager.removeAllListeners();
|
|
62
|
+
};
|
|
63
|
+
}, [liveCanvas]);
|
|
64
|
+
/**
|
|
65
|
+
* Activate or deactivate the inkingManager based on the 'active' prop
|
|
66
|
+
*/
|
|
67
|
+
React.useEffect(() => {
|
|
68
|
+
if (inkingManager && active !== undefined) {
|
|
69
|
+
if (active) {
|
|
70
|
+
inkingManager.activate();
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
inkingManager.deactivate();
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}, [active, inkingManager]);
|
|
77
|
+
/**
|
|
78
|
+
* Sets the tool of the inkingManager based on the 'tool' prop
|
|
79
|
+
*/
|
|
80
|
+
React.useEffect(() => {
|
|
81
|
+
if (inkingManager && tool !== undefined) {
|
|
82
|
+
inkingManager.tool = tool;
|
|
83
|
+
}
|
|
84
|
+
}, [tool, inkingManager]);
|
|
85
|
+
/**
|
|
86
|
+
* Sets the offset of the inkingManager based on the 'offset' prop
|
|
87
|
+
*/
|
|
88
|
+
React.useEffect(() => {
|
|
89
|
+
if (inkingManager && offset !== undefined) {
|
|
90
|
+
inkingManager.offset = {
|
|
91
|
+
x: offset.x,
|
|
92
|
+
y: offset.y,
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
}, [offset === null || offset === void 0 ? void 0 : offset.x, offset === null || offset === void 0 ? void 0 : offset.y, inkingManager]);
|
|
96
|
+
/**
|
|
97
|
+
* Sets the scale of the inkingManager based on the 'scale' prop
|
|
98
|
+
*/
|
|
99
|
+
React.useEffect(() => {
|
|
100
|
+
if (inkingManager && scale !== undefined) {
|
|
101
|
+
inkingManager.scale = scale;
|
|
102
|
+
}
|
|
103
|
+
}, [scale, inkingManager]);
|
|
104
|
+
/**
|
|
105
|
+
* Sets the referencePoint of the inkingManager based on the 'referencePoint' prop
|
|
106
|
+
*/
|
|
107
|
+
React.useEffect(() => {
|
|
108
|
+
if (inkingManager && referencePoint !== undefined) {
|
|
109
|
+
inkingManager.referencePoint = referencePoint;
|
|
110
|
+
}
|
|
111
|
+
}, [referencePoint, inkingManager]);
|
|
112
|
+
/**
|
|
113
|
+
* Sets the lineBrush of the inkingManager based on the 'lineBrush' prop
|
|
114
|
+
*/
|
|
115
|
+
React.useEffect(() => {
|
|
116
|
+
if (inkingManager && lineBrush) {
|
|
117
|
+
inkingManager.lineBrush = {
|
|
118
|
+
color: lineBrush.color,
|
|
119
|
+
tip: lineBrush.tip,
|
|
120
|
+
tipSize: lineBrush.tipSize,
|
|
121
|
+
type: lineBrush.type,
|
|
122
|
+
endArrow: lineBrush.endArrow,
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
}, [
|
|
126
|
+
lineBrush === null || lineBrush === void 0 ? void 0 : lineBrush.color,
|
|
127
|
+
lineBrush === null || lineBrush === void 0 ? void 0 : lineBrush.tip,
|
|
128
|
+
lineBrush === null || lineBrush === void 0 ? void 0 : lineBrush.tipSize,
|
|
129
|
+
lineBrush === null || lineBrush === void 0 ? void 0 : lineBrush.type,
|
|
130
|
+
lineBrush === null || lineBrush === void 0 ? void 0 : lineBrush.endArrow,
|
|
131
|
+
inkingManager,
|
|
132
|
+
]);
|
|
133
|
+
/**
|
|
134
|
+
* Sets the isCursorShared of the liveCanvas based on the 'isCursorShared' prop
|
|
135
|
+
*/
|
|
136
|
+
React.useEffect(() => {
|
|
137
|
+
if (liveCanvas && isCursorShared !== undefined) {
|
|
138
|
+
liveCanvas.isCursorShared = isCursorShared;
|
|
139
|
+
}
|
|
140
|
+
}, [isCursorShared, liveCanvas]);
|
|
141
|
+
/**
|
|
142
|
+
* Sets the onGetLocalUserInfo method of the liveCanvas based on the 'localUserCursor' prop
|
|
143
|
+
*/
|
|
144
|
+
React.useEffect(() => {
|
|
145
|
+
if (liveCanvas && localUserPictureUrl) {
|
|
146
|
+
liveCanvas.onGetLocalUserPictureUrl = () => {
|
|
147
|
+
return localUserPictureUrl;
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
}, [localUserPictureUrl, liveCanvas]);
|
|
151
|
+
/**
|
|
152
|
+
* Return hook response
|
|
153
|
+
*/
|
|
154
|
+
return {
|
|
155
|
+
inkingManager,
|
|
156
|
+
liveCanvas,
|
|
157
|
+
};
|
|
158
|
+
}
|
|
167
159
|
//# sourceMappingURL=useLiveCanvas.js.map
|