@microsoft/live-share-react 2.0.0-internal.18 → 2.0.0-internal.19
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 +6 -0
- package/bin/esm/live-hooks/useLiveCanvas.js +29 -30
- package/bin/esm/live-hooks/useLiveCanvas.js.map +1 -1
- package/bin/esm/live-hooks/useLiveEvent.js +6 -15
- package/bin/esm/live-hooks/useLiveEvent.js.map +1 -1
- package/bin/esm/live-hooks/useLiveFollowMode.js +25 -34
- package/bin/esm/live-hooks/useLiveFollowMode.js.map +1 -1
- package/bin/esm/live-hooks/useLivePresence.js +5 -14
- package/bin/esm/live-hooks/useLivePresence.js.map +1 -1
- package/bin/esm/live-hooks/useLiveState.js +4 -13
- package/bin/esm/live-hooks/useLiveState.js.map +1 -1
- package/bin/esm/live-hooks/useLiveTimer.js +22 -31
- package/bin/esm/live-hooks/useLiveTimer.js.map +1 -1
- package/bin/esm/live-hooks/useMediaSynchronizer.js +24 -33
- package/bin/esm/live-hooks/useMediaSynchronizer.js.map +1 -1
- package/bin/esm/providers/AzureProvider.js +22 -27
- package/bin/esm/providers/AzureProvider.js.map +1 -1
- package/bin/esm/providers/LiveShareProvider.js +20 -21
- package/bin/esm/providers/LiveShareProvider.js.map +1 -1
- package/bin/esm/shared-hooks/internals/tree-node-types.js +1 -1
- package/bin/esm/shared-hooks/internals/tree-node-types.js.map +1 -1
- package/bin/esm/shared-hooks/internals/tree-node-utils.js +2 -4
- package/bin/esm/shared-hooks/internals/tree-node-utils.js.map +1 -1
- package/bin/esm/shared-hooks/useDynamicDDS.js +3 -12
- package/bin/esm/shared-hooks/useDynamicDDS.js.map +1 -1
- package/bin/esm/shared-hooks/useSharedMap.js +1 -1
- package/bin/esm/shared-hooks/useSharedMap.js.map +1 -1
- package/bin/esm/shared-hooks/useSharedStateRegistry.js +13 -10
- package/bin/esm/shared-hooks/useSharedStateRegistry.js.map +1 -1
- package/bin/esm/shared-hooks/useSharedTree.js +4 -4
- package/bin/esm/shared-hooks/useSharedTree.js.map +1 -1
- package/bin/esm/types/FluidMap.d.ts +151 -0
- package/bin/esm/types/FluidMap.d.ts.map +1 -0
- package/bin/esm/types/FluidMap.js +24 -0
- package/bin/esm/types/FluidMap.js.map +1 -0
- package/bin/esm/types/ResultTypes.d.ts +15 -1
- package/bin/esm/types/ResultTypes.d.ts.map +1 -1
- package/bin/esm/utils/type-check.js +1 -1
- package/bin/esm/utils/type-check.js.map +1 -1
- package/package.json +11 -21
- package/src/types/FluidMap.ts +169 -0
- package/src/types/ResultTypes.ts +18 -1
- package/tsconfig.json +3 -4
- package/bin/cjs/index.d.ts +0 -7
- package/bin/cjs/index.d.ts.map +0 -1
- package/bin/cjs/index.js +0 -23
- package/bin/cjs/index.js.map +0 -1
- package/bin/cjs/interfaces/LiveInterfaceExtensions.d.ts +0 -26
- package/bin/cjs/interfaces/LiveInterfaceExtensions.d.ts.map +0 -1
- package/bin/cjs/interfaces/LiveInterfaceExtensions.js +0 -7
- package/bin/cjs/interfaces/LiveInterfaceExtensions.js.map +0 -1
- package/bin/cjs/interfaces/index.d.ts +0 -2
- package/bin/cjs/interfaces/index.d.ts.map +0 -1
- package/bin/cjs/interfaces/index.js +0 -18
- package/bin/cjs/interfaces/index.js.map +0 -1
- package/bin/cjs/internal/errors.d.ts +0 -41
- package/bin/cjs/internal/errors.d.ts.map +0 -1
- package/bin/cjs/internal/errors.js +0 -48
- package/bin/cjs/internal/errors.js.map +0 -1
- package/bin/cjs/internal/index.d.ts +0 -3
- package/bin/cjs/internal/index.d.ts.map +0 -1
- package/bin/cjs/internal/index.js +0 -19
- package/bin/cjs/internal/index.js.map +0 -1
- package/bin/cjs/internal/type-guards.d.ts +0 -11
- package/bin/cjs/internal/type-guards.d.ts.map +0 -1
- package/bin/cjs/internal/type-guards.js +0 -24
- package/bin/cjs/internal/type-guards.js.map +0 -1
- package/bin/cjs/live-hooks/index.d.ts +0 -8
- package/bin/cjs/live-hooks/index.d.ts.map +0 -1
- package/bin/cjs/live-hooks/index.js +0 -24
- package/bin/cjs/live-hooks/index.js.map +0 -1
- package/bin/cjs/live-hooks/useLiveCanvas.d.ts +0 -80
- package/bin/cjs/live-hooks/useLiveCanvas.d.ts.map +0 -1
- package/bin/cjs/live-hooks/useLiveCanvas.js +0 -244
- package/bin/cjs/live-hooks/useLiveCanvas.js.map +0 -1
- package/bin/cjs/live-hooks/useLiveEvent.d.ts +0 -59
- package/bin/cjs/live-hooks/useLiveEvent.d.ts.map +0 -1
- package/bin/cjs/live-hooks/useLiveEvent.js +0 -150
- package/bin/cjs/live-hooks/useLiveEvent.js.map +0 -1
- package/bin/cjs/live-hooks/useLiveFollowMode.d.ts +0 -163
- package/bin/cjs/live-hooks/useLiveFollowMode.d.ts.map +0 -1
- package/bin/cjs/live-hooks/useLiveFollowMode.js +0 -360
- package/bin/cjs/live-hooks/useLiveFollowMode.js.map +0 -1
- package/bin/cjs/live-hooks/useLivePresence.d.ts +0 -76
- package/bin/cjs/live-hooks/useLivePresence.d.ts.map +0 -1
- package/bin/cjs/live-hooks/useLivePresence.js +0 -170
- package/bin/cjs/live-hooks/useLivePresence.js.map +0 -1
- package/bin/cjs/live-hooks/useLiveState.d.ts +0 -66
- package/bin/cjs/live-hooks/useLiveState.d.ts.map +0 -1
- package/bin/cjs/live-hooks/useLiveState.js +0 -134
- package/bin/cjs/live-hooks/useLiveState.js.map +0 -1
- package/bin/cjs/live-hooks/useLiveTimer.d.ts +0 -80
- package/bin/cjs/live-hooks/useLiveTimer.d.ts.map +0 -1
- package/bin/cjs/live-hooks/useLiveTimer.js +0 -233
- package/bin/cjs/live-hooks/useLiveTimer.js.map +0 -1
- package/bin/cjs/live-hooks/useMediaSynchronizer.d.ts +0 -86
- package/bin/cjs/live-hooks/useMediaSynchronizer.d.ts.map +0 -1
- package/bin/cjs/live-hooks/useMediaSynchronizer.js +0 -301
- package/bin/cjs/live-hooks/useMediaSynchronizer.js.map +0 -1
- package/bin/cjs/package.json +0 -1
- package/bin/cjs/providers/AzureProvider.d.ts +0 -113
- package/bin/cjs/providers/AzureProvider.d.ts.map +0 -1
- package/bin/cjs/providers/AzureProvider.js +0 -127
- package/bin/cjs/providers/AzureProvider.js.map +0 -1
- package/bin/cjs/providers/LiveShareProvider.d.ts +0 -193
- package/bin/cjs/providers/LiveShareProvider.d.ts.map +0 -1
- package/bin/cjs/providers/LiveShareProvider.js +0 -205
- package/bin/cjs/providers/LiveShareProvider.js.map +0 -1
- package/bin/cjs/providers/index.d.ts +0 -3
- package/bin/cjs/providers/index.d.ts.map +0 -1
- package/bin/cjs/providers/index.js +0 -19
- package/bin/cjs/providers/index.js.map +0 -1
- package/bin/cjs/shared-hooks/index.d.ts +0 -7
- package/bin/cjs/shared-hooks/index.d.ts.map +0 -1
- package/bin/cjs/shared-hooks/index.js +0 -23
- package/bin/cjs/shared-hooks/index.js.map +0 -1
- package/bin/cjs/shared-hooks/internals/tree-node-constants.d.ts +0 -3
- package/bin/cjs/shared-hooks/internals/tree-node-constants.d.ts.map +0 -1
- package/bin/cjs/shared-hooks/internals/tree-node-constants.js +0 -6
- package/bin/cjs/shared-hooks/internals/tree-node-constants.js.map +0 -1
- package/bin/cjs/shared-hooks/internals/tree-node-types.d.ts +0 -10
- package/bin/cjs/shared-hooks/internals/tree-node-types.d.ts.map +0 -1
- package/bin/cjs/shared-hooks/internals/tree-node-types.js +0 -23
- package/bin/cjs/shared-hooks/internals/tree-node-types.js.map +0 -1
- package/bin/cjs/shared-hooks/internals/tree-node-utils.d.ts +0 -33
- package/bin/cjs/shared-hooks/internals/tree-node-utils.d.ts.map +0 -1
- package/bin/cjs/shared-hooks/internals/tree-node-utils.js +0 -193
- package/bin/cjs/shared-hooks/internals/tree-node-utils.js.map +0 -1
- package/bin/cjs/shared-hooks/useDynamicDDS.d.ts +0 -23
- package/bin/cjs/shared-hooks/useDynamicDDS.d.ts.map +0 -1
- package/bin/cjs/shared-hooks/useDynamicDDS.js +0 -87
- package/bin/cjs/shared-hooks/useDynamicDDS.js.map +0 -1
- package/bin/cjs/shared-hooks/useSharedMap.d.ts +0 -25
- package/bin/cjs/shared-hooks/useSharedMap.d.ts.map +0 -1
- package/bin/cjs/shared-hooks/useSharedMap.js +0 -134
- package/bin/cjs/shared-hooks/useSharedMap.js.map +0 -1
- package/bin/cjs/shared-hooks/useSharedState.d.ts +0 -22
- package/bin/cjs/shared-hooks/useSharedState.d.ts.map +0 -1
- package/bin/cjs/shared-hooks/useSharedState.js +0 -80
- package/bin/cjs/shared-hooks/useSharedState.js.map +0 -1
- package/bin/cjs/shared-hooks/useSharedStateRegistry.d.ts +0 -37
- package/bin/cjs/shared-hooks/useSharedStateRegistry.d.ts.map +0 -1
- package/bin/cjs/shared-hooks/useSharedStateRegistry.js +0 -120
- package/bin/cjs/shared-hooks/useSharedStateRegistry.js.map +0 -1
- package/bin/cjs/shared-hooks/useSharedTree.d.ts +0 -57
- package/bin/cjs/shared-hooks/useSharedTree.d.ts.map +0 -1
- package/bin/cjs/shared-hooks/useSharedTree.js +0 -123
- package/bin/cjs/shared-hooks/useSharedTree.js.map +0 -1
- package/bin/cjs/shared-hooks/useTreeNode.d.ts +0 -96
- package/bin/cjs/shared-hooks/useTreeNode.d.ts.map +0 -1
- package/bin/cjs/shared-hooks/useTreeNode.js +0 -135
- package/bin/cjs/shared-hooks/useTreeNode.js.map +0 -1
- package/bin/cjs/types/ActionTypes.d.ts +0 -112
- package/bin/cjs/types/ActionTypes.d.ts.map +0 -1
- package/bin/cjs/types/ActionTypes.js +0 -7
- package/bin/cjs/types/ActionTypes.js.map +0 -1
- package/bin/cjs/types/PropTypes.d.ts +0 -56
- package/bin/cjs/types/PropTypes.d.ts.map +0 -1
- package/bin/cjs/types/PropTypes.js +0 -7
- package/bin/cjs/types/PropTypes.js.map +0 -1
- package/bin/cjs/types/ResultTypes.d.ts +0 -334
- package/bin/cjs/types/ResultTypes.d.ts.map +0 -1
- package/bin/cjs/types/ResultTypes.js +0 -7
- package/bin/cjs/types/ResultTypes.js.map +0 -1
- package/bin/cjs/types/index.d.ts +0 -4
- package/bin/cjs/types/index.d.ts.map +0 -1
- package/bin/cjs/types/index.js +0 -20
- package/bin/cjs/types/index.js.map +0 -1
- package/bin/cjs/utils/index.d.ts +0 -2
- package/bin/cjs/utils/index.d.ts.map +0 -1
- package/bin/cjs/utils/index.js +0 -18
- package/bin/cjs/utils/index.js.map +0 -1
- package/bin/cjs/utils/type-check.d.ts +0 -15
- package/bin/cjs/utils/type-check.d.ts.map +0 -1
- package/bin/cjs/utils/type-check.js +0 -62
- package/bin/cjs/utils/type-check.js.map +0 -1
- package/bin/index.d.ts +0 -7
- package/bin/index.d.ts.map +0 -1
- package/bin/index.js +0 -7
- package/bin/index.js.map +0 -1
- package/bin/interfaces/LiveInterfaceExtensions.d.ts +0 -26
- package/bin/interfaces/LiveInterfaceExtensions.d.ts.map +0 -1
- package/bin/interfaces/LiveInterfaceExtensions.js +0 -6
- package/bin/interfaces/LiveInterfaceExtensions.js.map +0 -1
- package/bin/interfaces/index.d.ts +0 -2
- package/bin/interfaces/index.d.ts.map +0 -1
- package/bin/interfaces/index.js +0 -2
- package/bin/interfaces/index.js.map +0 -1
- package/bin/internal/errors.d.ts +0 -41
- package/bin/internal/errors.d.ts.map +0 -1
- package/bin/internal/errors.js +0 -42
- package/bin/internal/errors.js.map +0 -1
- package/bin/internal/index.d.ts +0 -3
- package/bin/internal/index.d.ts.map +0 -1
- package/bin/internal/index.js +0 -3
- package/bin/internal/index.js.map +0 -1
- package/bin/internal/type-guards.d.ts +0 -11
- package/bin/internal/type-guards.d.ts.map +0 -1
- package/bin/internal/type-guards.js +0 -20
- package/bin/internal/type-guards.js.map +0 -1
- package/bin/live-hooks/index.d.ts +0 -8
- package/bin/live-hooks/index.d.ts.map +0 -1
- package/bin/live-hooks/index.js +0 -8
- package/bin/live-hooks/index.js.map +0 -1
- package/bin/live-hooks/useLiveCanvas.d.ts +0 -29
- package/bin/live-hooks/useLiveCanvas.d.ts.map +0 -1
- package/bin/live-hooks/useLiveCanvas.js +0 -160
- package/bin/live-hooks/useLiveCanvas.js.map +0 -1
- package/bin/live-hooks/useLiveEvent.d.ts +0 -23
- package/bin/live-hooks/useLiveEvent.d.ts.map +0 -1
- package/bin/live-hooks/useLiveEvent.js +0 -108
- package/bin/live-hooks/useLiveEvent.js.map +0 -1
- package/bin/live-hooks/useLiveFollowMode.d.ts +0 -24
- package/bin/live-hooks/useLiveFollowMode.d.ts.map +0 -1
- package/bin/live-hooks/useLiveFollowMode.js +0 -211
- package/bin/live-hooks/useLiveFollowMode.js.map +0 -1
- package/bin/live-hooks/useLivePresence.d.ts +0 -26
- package/bin/live-hooks/useLivePresence.d.ts.map +0 -1
- package/bin/live-hooks/useLivePresence.js +0 -106
- package/bin/live-hooks/useLivePresence.js.map +0 -1
- package/bin/live-hooks/useLiveState.d.ts +0 -21
- package/bin/live-hooks/useLiveState.d.ts.map +0 -1
- package/bin/live-hooks/useLiveState.js +0 -83
- package/bin/live-hooks/useLiveState.js.map +0 -1
- package/bin/live-hooks/useLiveTimer.d.ts +0 -25
- package/bin/live-hooks/useLiveTimer.d.ts.map +0 -1
- package/bin/live-hooks/useLiveTimer.js +0 -172
- package/bin/live-hooks/useLiveTimer.js.map +0 -1
- package/bin/live-hooks/useMediaSynchronizer.d.ts +0 -25
- package/bin/live-hooks/useMediaSynchronizer.d.ts.map +0 -1
- package/bin/live-hooks/useMediaSynchronizer.js +0 -234
- package/bin/live-hooks/useMediaSynchronizer.js.map +0 -1
- package/bin/providers/AzureProvider.d.ts +0 -113
- package/bin/providers/AzureProvider.d.ts.map +0 -1
- package/bin/providers/AzureProvider.js +0 -119
- package/bin/providers/AzureProvider.js.map +0 -1
- package/bin/providers/LiveShareProvider.d.ts +0 -91
- package/bin/providers/LiveShareProvider.d.ts.map +0 -1
- package/bin/providers/LiveShareProvider.js +0 -95
- package/bin/providers/LiveShareProvider.js.map +0 -1
- package/bin/providers/index.d.ts +0 -3
- package/bin/providers/index.d.ts.map +0 -1
- package/bin/providers/index.js +0 -3
- package/bin/providers/index.js.map +0 -1
- package/bin/shared-hooks/index.d.ts +0 -5
- package/bin/shared-hooks/index.d.ts.map +0 -1
- package/bin/shared-hooks/index.js +0 -5
- package/bin/shared-hooks/index.js.map +0 -1
- package/bin/shared-hooks/useDynamicDDS.d.ts +0 -23
- package/bin/shared-hooks/useDynamicDDS.d.ts.map +0 -1
- package/bin/shared-hooks/useDynamicDDS.js +0 -72
- package/bin/shared-hooks/useDynamicDDS.js.map +0 -1
- package/bin/shared-hooks/useSharedMap.d.ts +0 -23
- package/bin/shared-hooks/useSharedMap.d.ts.map +0 -1
- package/bin/shared-hooks/useSharedMap.js +0 -114
- package/bin/shared-hooks/useSharedMap.js.map +0 -1
- package/bin/shared-hooks/useSharedState.d.ts +0 -22
- package/bin/shared-hooks/useSharedState.d.ts.map +0 -1
- package/bin/shared-hooks/useSharedState.js +0 -74
- package/bin/shared-hooks/useSharedState.js.map +0 -1
- package/bin/shared-hooks/useSharedStateRegistry.d.ts +0 -37
- package/bin/shared-hooks/useSharedStateRegistry.d.ts.map +0 -1
- package/bin/shared-hooks/useSharedStateRegistry.js +0 -105
- package/bin/shared-hooks/useSharedStateRegistry.js.map +0 -1
- package/bin/types/ActionTypes.d.ts +0 -112
- package/bin/types/ActionTypes.d.ts.map +0 -1
- package/bin/types/ActionTypes.js +0 -6
- package/bin/types/ActionTypes.js.map +0 -1
- package/bin/types/PropTypes.d.ts +0 -8
- package/bin/types/PropTypes.d.ts.map +0 -1
- package/bin/types/PropTypes.js +0 -6
- package/bin/types/PropTypes.js.map +0 -1
- package/bin/types/ResultTypes.d.ts +0 -302
- package/bin/types/ResultTypes.d.ts.map +0 -1
- package/bin/types/ResultTypes.js +0 -6
- package/bin/types/ResultTypes.js.map +0 -1
- package/bin/types/index.d.ts +0 -4
- package/bin/types/index.d.ts.map +0 -1
- package/bin/types/index.js +0 -4
- package/bin/types/index.js.map +0 -1
- package/bin/utils/index.d.ts +0 -2
- package/bin/utils/index.d.ts.map +0 -1
- package/bin/utils/index.js +0 -2
- package/bin/utils/index.js.map +0 -1
- package/bin/utils/type-check.d.ts +0 -15
- package/bin/utils/type-check.d.ts.map +0 -1
- package/bin/utils/type-check.js +0 -54
- package/bin/utils/type-check.js.map +0 -1
- package/tsconfig.cjs.json +0 -14
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/*!
|
|
3
|
-
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
4
|
-
* Licensed under the Microsoft Live Share SDK License.
|
|
5
|
-
*/
|
|
6
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
7
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
8
|
-
};
|
|
9
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
-
exports.useSharedStateRegistry = void 0;
|
|
11
|
-
const react_1 = __importDefault(require("react"));
|
|
12
|
-
const internal_1 = require("@microsoft/live-share/internal");
|
|
13
|
-
/**
|
|
14
|
-
* 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.
|
|
15
|
-
*
|
|
16
|
-
* @remarks
|
|
17
|
-
* Use this if you are building a custom `LiveShareProvider` or `AzureProvider` implementation in your app.
|
|
18
|
-
*
|
|
19
|
-
* @param results IAzureContainerResults response or undefined
|
|
20
|
-
* @returns ISharedStateRegistryResponse object
|
|
21
|
-
*/
|
|
22
|
-
const useSharedStateRegistry = (results) => {
|
|
23
|
-
const registeredSharedSetStateActionMapRef = react_1.default.useRef(new Map());
|
|
24
|
-
const stateMap = useStateMap(results === null || results === void 0 ? void 0 : results.container);
|
|
25
|
-
/**
|
|
26
|
-
* @see ISharedStateRegistryResponse.registerSharedSetStateAction
|
|
27
|
-
*/
|
|
28
|
-
const registerSharedSetStateAction = react_1.default.useCallback((uniqueKey, componentId, setLocalStateAction) => {
|
|
29
|
-
let actionsMap = registeredSharedSetStateActionMapRef.current.get(uniqueKey);
|
|
30
|
-
if (actionsMap) {
|
|
31
|
-
if (!actionsMap.has(componentId)) {
|
|
32
|
-
actionsMap.set(componentId, setLocalStateAction);
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
else {
|
|
36
|
-
actionsMap = new Map();
|
|
37
|
-
actionsMap.set(componentId, setLocalStateAction);
|
|
38
|
-
registeredSharedSetStateActionMapRef.current.set(uniqueKey, actionsMap);
|
|
39
|
-
}
|
|
40
|
-
// Set initial values, if known
|
|
41
|
-
const initialValue = stateMap === null || stateMap === void 0 ? void 0 : stateMap.get(uniqueKey);
|
|
42
|
-
if (initialValue) {
|
|
43
|
-
setLocalStateAction(initialValue);
|
|
44
|
-
}
|
|
45
|
-
}, [stateMap]);
|
|
46
|
-
/**
|
|
47
|
-
* @see ISharedStateRegistryResponse.unregisterSharedSetStateAction
|
|
48
|
-
*/
|
|
49
|
-
const unregisterSharedSetStateAction = react_1.default.useCallback((uniqueKey, componentId) => {
|
|
50
|
-
let actionsMap = registeredSharedSetStateActionMapRef.current.get(uniqueKey);
|
|
51
|
-
if (actionsMap === null || actionsMap === void 0 ? void 0 : actionsMap.has(componentId)) {
|
|
52
|
-
actionsMap.delete(componentId);
|
|
53
|
-
}
|
|
54
|
-
}, []);
|
|
55
|
-
/**
|
|
56
|
-
* @see ISharedStateRegistryResponse.updateSharedState
|
|
57
|
-
*/
|
|
58
|
-
const updateSharedState = react_1.default.useCallback((uniqueKey, value) => {
|
|
59
|
-
if (!stateMap)
|
|
60
|
-
return;
|
|
61
|
-
stateMap === null || stateMap === void 0 ? void 0 : stateMap.set(uniqueKey, value);
|
|
62
|
-
}, [stateMap]);
|
|
63
|
-
/**
|
|
64
|
-
* @see ISharedStateRegistryResponse.deleteSharedState
|
|
65
|
-
*/
|
|
66
|
-
const deleteSharedState = react_1.default.useCallback((uniqueKey) => {
|
|
67
|
-
if (!stateMap)
|
|
68
|
-
return;
|
|
69
|
-
let actionsMap = registeredSharedSetStateActionMapRef.current.get(uniqueKey);
|
|
70
|
-
actionsMap === null || actionsMap === void 0 ? void 0 : actionsMap.clear();
|
|
71
|
-
stateMap.delete(uniqueKey);
|
|
72
|
-
}, [stateMap]);
|
|
73
|
-
react_1.default.useEffect(() => {
|
|
74
|
-
if (!stateMap)
|
|
75
|
-
return;
|
|
76
|
-
const valueChangedListener = (changed) => {
|
|
77
|
-
if (registeredSharedSetStateActionMapRef.current.has(changed.key)) {
|
|
78
|
-
const value = stateMap === null || stateMap === void 0 ? void 0 : stateMap.get(changed.key);
|
|
79
|
-
const actionMap = registeredSharedSetStateActionMapRef.current.get(changed.key);
|
|
80
|
-
actionMap === null || actionMap === void 0 ? void 0 : actionMap.forEach((setLocalStateHandler) => {
|
|
81
|
-
setLocalStateHandler(value);
|
|
82
|
-
});
|
|
83
|
-
}
|
|
84
|
-
};
|
|
85
|
-
stateMap.on("valueChanged", valueChangedListener);
|
|
86
|
-
// Set initial values
|
|
87
|
-
stateMap.forEach((value, key) => {
|
|
88
|
-
const actionMap = registeredSharedSetStateActionMapRef.current.get(key);
|
|
89
|
-
actionMap === null || actionMap === void 0 ? void 0 : actionMap.forEach((setLocalStateHandler) => {
|
|
90
|
-
setLocalStateHandler(value);
|
|
91
|
-
});
|
|
92
|
-
});
|
|
93
|
-
return () => {
|
|
94
|
-
stateMap === null || stateMap === void 0 ? void 0 : stateMap.off("valueChanged", valueChangedListener);
|
|
95
|
-
};
|
|
96
|
-
}, [stateMap]);
|
|
97
|
-
return {
|
|
98
|
-
registerSharedSetStateAction,
|
|
99
|
-
unregisterSharedSetStateAction,
|
|
100
|
-
updateSharedState,
|
|
101
|
-
deleteSharedState,
|
|
102
|
-
};
|
|
103
|
-
};
|
|
104
|
-
exports.useSharedStateRegistry = useSharedStateRegistry;
|
|
105
|
-
const useStateMap = (container) => {
|
|
106
|
-
const [stateMap, setStateMap] = react_1.default.useState();
|
|
107
|
-
react_1.default.useEffect(() => {
|
|
108
|
-
if (!container) {
|
|
109
|
-
return;
|
|
110
|
-
}
|
|
111
|
-
const rootDataObject = (0, internal_1.getRootDataObject)(container);
|
|
112
|
-
const rootDirectory = (0, internal_1.getRootDirectory)(rootDataObject);
|
|
113
|
-
const turboDir = rootDirectory.getSubDirectory(internal_1.TurboDirectory);
|
|
114
|
-
turboDir === null || turboDir === void 0 ? void 0 : turboDir.get(internal_1.TurboStateMap).get().then((state) => {
|
|
115
|
-
setStateMap(state);
|
|
116
|
-
});
|
|
117
|
-
}, [container]);
|
|
118
|
-
return stateMap;
|
|
119
|
-
};
|
|
120
|
-
//# sourceMappingURL=useSharedStateRegistry.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useSharedStateRegistry.js","sourceRoot":"","sources":["../../../src/shared-hooks/useSharedStateRegistry.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;;AAOH,kDAA0B;AAS1B,6DAKwC;AAwBxC;;;;;;;;GAQG;AACI,MAAM,sBAAsB,GAAG,CAClC,OAA2C,EACf,EAAE;IAC9B,MAAM,oCAAoC,GAAG,eAAK,CAAC,MAAM,CAEvD,IAAI,GAAG,EAAE,CAAC,CAAC;IAEb,MAAM,QAAQ,GAAG,WAAW,CAAC,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,SAAS,CAAC,CAAC;IAEjD;;OAEG;IACH,MAAM,4BAA4B,GAAG,eAAK,CAAC,WAAW,CAClD,CACI,SAAiB,EACjB,WAAmB,EACnB,mBAAwC,EAC1C,EAAE;QACA,IAAI,UAAU,GACV,oCAAoC,CAAC,OAAO,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;QAChE,IAAI,UAAU,EAAE,CAAC;YACb,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,WAAW,CAAC,EAAE,CAAC;gBAC/B,UAAU,CAAC,GAAG,CAAC,WAAW,EAAE,mBAAmB,CAAC,CAAC;YACrD,CAAC;QACL,CAAC;aAAM,CAAC;YACJ,UAAU,GAAG,IAAI,GAAG,EAA+B,CAA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E,oBAAoB,CAAC,CAAC;QACxD,CAAC,CAAC;IACN,CAAC,EAAE,CAAC,QAAQ,CAAC,CAAC,CAAC;IAEf,OAAO;QACH,4BAA4B;QAC5B,8BAA8B;QAC9B,iBAAiB;QACjB,iBAAiB;KACpB,CAAC;AACN,CAAC,CAAC;AAlHW,QAAA,sBAAsB,0BAkHjC;AAEF,MAAM,WAAW,GAAG,CAAC,SAAsC,EAAE,EAAE;IAC3D,MAAM,CAAC,QAAQ,EAAE,WAAW,CAAC,GAAG,eAAK,CAAC,QAAQ,EAAyB,CAAC;IACxE,eAAK,CAAC,SAAS,CAAC,GAAG,EAAE;QACjB,IAAI,CAAC,SAAS,EAAE,CAAC;YACb,OAAO;QACX,CAAC;QACD,MAAM,cAAc,GAAG,IAAA,4BAAiB,EAAC,SAAS,CAAC,CAAC;QACpD,MAAM,aAAa,GAAG,IAAA,2BAAgB,EAAC,cAAc,CAAC,CAAC;QACvD,MAAM,QAAQ,GAAG,aAAa,CAAC,eAAe,CAAC,yBAAc,CAAC,CAAC;QAC/D,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CACF,GAAG,CAAC,wBAAa,EAClB,GAAG,GACH,IAAI,CAAC,CAAC,KAAgB,EAAE,EAAE;YACvB,WAAW,CAAC,KAAK,CAAC,CAAC;QACvB,CAAC,CAAC,CAAC;IACX,CAAC,EAAE,CAAC,SAAS,CAAC,CAAC,CAAC;IAEhB,OAAO,QAAQ,CAAC;AACpB,CAAC,CAAC"}
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import { ImplicitFieldSchema, TreeViewConfiguration, InsertableTreeFieldFromImplicitField } from "fluid-framework";
|
|
2
|
-
import { IUseSharedTreeResults } from "../types/index.js";
|
|
3
|
-
/**
|
|
4
|
-
* Creates a new Fluid `SharedTree` instance if one doesn't already exist.
|
|
5
|
-
* @remarks
|
|
6
|
-
* Use the `root` variable from the {@link IUseSharedTreeResults} response from this hook with {@link useTreeNode}.
|
|
7
|
-
* This makes `root` stateful with React whenever a leaf of `root` changes.
|
|
8
|
-
*
|
|
9
|
-
* @param uniqueKey the unique key for the `SharedTree`. If one does not yet exist, a new `SharedTree` will be created.
|
|
10
|
-
* Otherwise it will use the existing one.
|
|
11
|
-
* @param treeViewConfiguration the tree view configuration that contains the `SharedTree` field schema.
|
|
12
|
-
* @param initialData the initial data to load into the `SharedTree` when it is first created.
|
|
13
|
-
* @returns the {@link IUseSharedTreeResults} with the `root` node.
|
|
14
|
-
*
|
|
15
|
-
* @example
|
|
16
|
-
* ```tsx
|
|
17
|
-
* import { SchemaFactory, TreeViewConfiguration } from "fluid-framework";
|
|
18
|
-
* import { useSharedTree, useTreeNode } from "@microsoft/live-share-react";
|
|
19
|
-
* // Declare a schema factory with your unique uuid
|
|
20
|
-
* const sf = new SchemaFactory("fc1db2e8-0000-11ee-be57-0242ac120002");
|
|
21
|
-
* class YourObject extends sf.object("YourObject", {
|
|
22
|
-
* listChangedCount: sf.number,
|
|
23
|
-
* list: sf.array(sf.string),
|
|
24
|
-
* }) {
|
|
25
|
-
* // You can add your own utility functions
|
|
26
|
-
* insert() {
|
|
27
|
-
* this.list.insertAtEnd("some text");
|
|
28
|
-
* this.listChangedCount += 1;
|
|
29
|
-
* }
|
|
30
|
-
* }
|
|
31
|
-
* const config = new TreeViewConfiguration({ schema: YourObject });
|
|
32
|
-
* const initialData = new YourObject({
|
|
33
|
-
* number: 0,
|
|
34
|
-
* list: [],
|
|
35
|
-
* });
|
|
36
|
-
*
|
|
37
|
-
* // Must be child component of <LiveShareProvider> or <AzureProvider>
|
|
38
|
-
* export const YourComponent = () => {
|
|
39
|
-
* // Get the root node of the `SharedTree` mapped to "some-unique-key"
|
|
40
|
-
* const { root } = useSharedTree("some-unique-key", config, initialData);
|
|
41
|
-
* // Makes root stateful / automatically update when the node changes (e.g., node.count)
|
|
42
|
-
* const { node } = useTreeNode(root);
|
|
43
|
-
* // node.list is its own TreeNode, so we make it stateful as well
|
|
44
|
-
* const { node: list } = useTreeNode(node?.list);
|
|
45
|
-
* if (!node || !list) return (<>"Loading"</>);
|
|
46
|
-
* return (
|
|
47
|
-
* <div>
|
|
48
|
-
* <div>Changed: {node.listChangedCount}</div>
|
|
49
|
-
* <button onClick={() => node.insert()}>Insert</button>
|
|
50
|
-
* { list.map((item) => <div key={item}>{item}</div>) }
|
|
51
|
-
* </div>
|
|
52
|
-
* );
|
|
53
|
-
* }
|
|
54
|
-
* ```
|
|
55
|
-
*/
|
|
56
|
-
export declare function useSharedTree<TSchema extends ImplicitFieldSchema = ImplicitFieldSchema>(uniqueKey: string, treeViewConfiguration: TreeViewConfiguration<TSchema>, initialData: InsertableTreeFieldFromImplicitField<TSchema>): IUseSharedTreeResults<TSchema>;
|
|
57
|
-
//# sourceMappingURL=useSharedTree.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useSharedTree.d.ts","sourceRoot":"","sources":["../../../src/shared-hooks/useSharedTree.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,mBAAmB,EACnB,qBAAqB,EAIrB,oCAAoC,EAEvC,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AAI1D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoDG;AACH,wBAAgB,aAAa,CACzB,OAAO,SAAS,mBAAmB,GAAG,mBAAmB,EAEzD,SAAS,EAAE,MAAM,EACjB,qBAAqB,EAAE,qBAAqB,CAAC,OAAO,CAAC,EACrD,WAAW,EAAE,oCAAoC,CAAC,OAAO,CAAC,GAC3D,qBAAqB,CAAC,OAAO,CAAC,CAuEhC"}
|
|
@@ -1,123 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.useSharedTree = useSharedTree;
|
|
7
|
-
const fluid_framework_1 = require("fluid-framework");
|
|
8
|
-
const index_js_1 = require("../shared-hooks/index.js");
|
|
9
|
-
const react_1 = __importDefault(require("react"));
|
|
10
|
-
/**
|
|
11
|
-
* Creates a new Fluid `SharedTree` instance if one doesn't already exist.
|
|
12
|
-
* @remarks
|
|
13
|
-
* Use the `root` variable from the {@link IUseSharedTreeResults} response from this hook with {@link useTreeNode}.
|
|
14
|
-
* This makes `root` stateful with React whenever a leaf of `root` changes.
|
|
15
|
-
*
|
|
16
|
-
* @param uniqueKey the unique key for the `SharedTree`. If one does not yet exist, a new `SharedTree` will be created.
|
|
17
|
-
* Otherwise it will use the existing one.
|
|
18
|
-
* @param treeViewConfiguration the tree view configuration that contains the `SharedTree` field schema.
|
|
19
|
-
* @param initialData the initial data to load into the `SharedTree` when it is first created.
|
|
20
|
-
* @returns the {@link IUseSharedTreeResults} with the `root` node.
|
|
21
|
-
*
|
|
22
|
-
* @example
|
|
23
|
-
* ```tsx
|
|
24
|
-
* import { SchemaFactory, TreeViewConfiguration } from "fluid-framework";
|
|
25
|
-
* import { useSharedTree, useTreeNode } from "@microsoft/live-share-react";
|
|
26
|
-
* // Declare a schema factory with your unique uuid
|
|
27
|
-
* const sf = new SchemaFactory("fc1db2e8-0000-11ee-be57-0242ac120002");
|
|
28
|
-
* class YourObject extends sf.object("YourObject", {
|
|
29
|
-
* listChangedCount: sf.number,
|
|
30
|
-
* list: sf.array(sf.string),
|
|
31
|
-
* }) {
|
|
32
|
-
* // You can add your own utility functions
|
|
33
|
-
* insert() {
|
|
34
|
-
* this.list.insertAtEnd("some text");
|
|
35
|
-
* this.listChangedCount += 1;
|
|
36
|
-
* }
|
|
37
|
-
* }
|
|
38
|
-
* const config = new TreeViewConfiguration({ schema: YourObject });
|
|
39
|
-
* const initialData = new YourObject({
|
|
40
|
-
* number: 0,
|
|
41
|
-
* list: [],
|
|
42
|
-
* });
|
|
43
|
-
*
|
|
44
|
-
* // Must be child component of <LiveShareProvider> or <AzureProvider>
|
|
45
|
-
* export const YourComponent = () => {
|
|
46
|
-
* // Get the root node of the `SharedTree` mapped to "some-unique-key"
|
|
47
|
-
* const { root } = useSharedTree("some-unique-key", config, initialData);
|
|
48
|
-
* // Makes root stateful / automatically update when the node changes (e.g., node.count)
|
|
49
|
-
* const { node } = useTreeNode(root);
|
|
50
|
-
* // node.list is its own TreeNode, so we make it stateful as well
|
|
51
|
-
* const { node: list } = useTreeNode(node?.list);
|
|
52
|
-
* if (!node || !list) return (<>"Loading"</>);
|
|
53
|
-
* return (
|
|
54
|
-
* <div>
|
|
55
|
-
* <div>Changed: {node.listChangedCount}</div>
|
|
56
|
-
* <button onClick={() => node.insert()}>Insert</button>
|
|
57
|
-
* { list.map((item) => <div key={item}>{item}</div>) }
|
|
58
|
-
* </div>
|
|
59
|
-
* );
|
|
60
|
-
* }
|
|
61
|
-
* ```
|
|
62
|
-
*/
|
|
63
|
-
function useSharedTree(uniqueKey, treeViewConfiguration, initialData) {
|
|
64
|
-
const [treeView, setTreeView] = react_1.default.useState();
|
|
65
|
-
const [root, setRoot] = react_1.default.useState();
|
|
66
|
-
const onFirstInitialize = react_1.default.useCallback((newDDS) => {
|
|
67
|
-
try {
|
|
68
|
-
// Create a `treeView` with the provided `treeViewConfiguration`
|
|
69
|
-
const _treeView = newDDS.viewWith(treeViewConfiguration);
|
|
70
|
-
if (_treeView.compatibility.canInitialize) {
|
|
71
|
-
// Set initial data
|
|
72
|
-
_treeView.initialize(initialData);
|
|
73
|
-
}
|
|
74
|
-
// `onFirstInitialize` is only called for the user that created the tree, but we need this object for all clients.
|
|
75
|
-
// Dispose, since we will call `sharedTree.viewWith` in a `useEffect` down below and set it to state.
|
|
76
|
-
_treeView.dispose();
|
|
77
|
-
}
|
|
78
|
-
catch (err) {
|
|
79
|
-
console.error(err);
|
|
80
|
-
}
|
|
81
|
-
}, [treeViewConfiguration, initialData]);
|
|
82
|
-
/**
|
|
83
|
-
* User facing: dynamically load the `SharedTree` DDS for the given unique key.
|
|
84
|
-
*/
|
|
85
|
-
const { dds: sharedTree } = (0, index_js_1.useDynamicDDS)(uniqueKey, fluid_framework_1.SharedTree, onFirstInitialize);
|
|
86
|
-
/**
|
|
87
|
-
* Sets the tree view and root view
|
|
88
|
-
*/
|
|
89
|
-
react_1.default.useEffect(() => {
|
|
90
|
-
if (!sharedTree)
|
|
91
|
-
return;
|
|
92
|
-
let _treeView = undefined;
|
|
93
|
-
try {
|
|
94
|
-
// Create a `treeView` with the provided `treeViewConfiguration`
|
|
95
|
-
_treeView = sharedTree.viewWith(treeViewConfiguration);
|
|
96
|
-
setTreeView(_treeView);
|
|
97
|
-
}
|
|
98
|
-
catch (err) {
|
|
99
|
-
console.error(err);
|
|
100
|
-
}
|
|
101
|
-
// Listen for changes to root view
|
|
102
|
-
const updateRoot = () => {
|
|
103
|
-
if (_treeView === null || _treeView === void 0 ? void 0 : _treeView.compatibility.canView) {
|
|
104
|
-
setRoot(_treeView.root);
|
|
105
|
-
}
|
|
106
|
-
else {
|
|
107
|
-
setRoot(undefined);
|
|
108
|
-
}
|
|
109
|
-
};
|
|
110
|
-
updateRoot();
|
|
111
|
-
const unsubscribeToRoot = _treeView === null || _treeView === void 0 ? void 0 : _treeView.events.on("rootChanged", updateRoot);
|
|
112
|
-
return () => {
|
|
113
|
-
_treeView === null || _treeView === void 0 ? void 0 : _treeView.dispose();
|
|
114
|
-
unsubscribeToRoot === null || unsubscribeToRoot === void 0 ? void 0 : unsubscribeToRoot();
|
|
115
|
-
};
|
|
116
|
-
}, [sharedTree, treeViewConfiguration]);
|
|
117
|
-
return {
|
|
118
|
-
treeView,
|
|
119
|
-
sharedTree,
|
|
120
|
-
root,
|
|
121
|
-
};
|
|
122
|
-
}
|
|
123
|
-
//# sourceMappingURL=useSharedTree.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useSharedTree.js","sourceRoot":"","sources":["../../../src/shared-hooks/use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AC,QAAQ,CAAC,qBAAqB,CAAC,CAAC;YACvD,WAAW,CAAC,SAAS,CAAC,CAAC;QAC3B,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACX,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QACvB,CAAC;QAED,kCAAkC;QAClC,MAAM,UAAU,GAAG,GAAS,EAAE;YAC1B,IAAI,SAAS,aAAT,SAAS,uBAAT,SAAS,CAAE,aAAa,CAAC,OAAO,EAAE,CAAC;gBACnC,OAAO,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;YAC5B,CAAC;iBAAM,CAAC;gBACJ,OAAO,CAAC,SAAS,CAAC,CAAC;YACvB,CAAC;QACL,CAAC,CAAC;QAEF,UAAU,EAAE,CAAC;QACb,MAAM,iBAAiB,GAAG,SAAS,aAAT,SAAS,uBAAT,SAAS,CAAE,MAAM,CAAC,EAAE,CAC1C,aAAa,EACb,UAAU,CACb,CAAC;QACF,OAAO,GAAG,EAAE;YACR,SAAS,aAAT,SAAS,uBAAT,SAAS,CAAE,OAAO,EAAE,CAAC;YACrB,iBAAiB,aAAjB,iBAAiB,uBAAjB,iBAAiB,EAAI,CAAC;QAC1B,CAAC,CAAC;IACN,CAAC,EAAE,CAAC,UAAU,EAAE,qBAAqB,CAAC,CAAC,CAAC;IAExC,OAAO;QACH,QAAQ;QACR,UAAU;QACV,IAAI;KACP,CAAC;AACN,CAAC"}
|
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
import { TreeChangeEvents, TreeNode } from "fluid-framework";
|
|
2
|
-
import { IUseTreeNodeResults } from "../types/index.js";
|
|
3
|
-
/**
|
|
4
|
-
* Makes a provided Fluid `TreeNode` stateful in React.
|
|
5
|
-
*
|
|
6
|
-
* @param node the Fluid `SharedTree` `TreeNode` instance to make stateful.
|
|
7
|
-
* @param stateChangeType listener type to apply changes for. Default value is "nodeChanged", which has the most optimal performance.
|
|
8
|
-
* Provide "treeChanged" to make all children nodes stateful as well when those child nodes change.
|
|
9
|
-
* When using the default, you must pass all child `TreeNode` values into `useTreeNode` for them to be stateful as well.
|
|
10
|
-
* @returns a stateful version `node`
|
|
11
|
-
*
|
|
12
|
-
* @example
|
|
13
|
-
* Example using default `"nodeChanged"` `stateChangeType`
|
|
14
|
-
* ```tsx
|
|
15
|
-
* import { SchemaFactory, TreeViewConfiguration } from "fluid-framework";
|
|
16
|
-
* import { useSharedTree, useTreeNode } from "@microsoft/live-share-react";
|
|
17
|
-
* // Declare a schema factory with your unique uuid
|
|
18
|
-
* const sf = new SchemaFactory("fc1db2e8-0000-11ee-be57-0242ac120002");
|
|
19
|
-
* class YourObject extends sf.object("YourObject", {
|
|
20
|
-
* listChangedCount: sf.number,
|
|
21
|
-
* list: sf.array(sf.string),
|
|
22
|
-
* }) {
|
|
23
|
-
* // You can add your own utility functions
|
|
24
|
-
* insert() {
|
|
25
|
-
* this.list.insertAtEnd("some text");
|
|
26
|
-
* this.listChangedCount += 1;
|
|
27
|
-
* }
|
|
28
|
-
* }
|
|
29
|
-
* const config = new TreeViewConfiguration({ schema: YourObject });
|
|
30
|
-
* const initialData = new YourObject({
|
|
31
|
-
* number: 0,
|
|
32
|
-
* list: [],
|
|
33
|
-
* });
|
|
34
|
-
*
|
|
35
|
-
* // Must be child component of <LiveShareProvider> or <AzureProvider>
|
|
36
|
-
* export const YourComponent = () => {
|
|
37
|
-
* // Get the root node of the `SharedTree` mapped to "some-unique-key"
|
|
38
|
-
* const { root } = useSharedTree("some-unique-key", config, initialData);
|
|
39
|
-
* // Makes root stateful / automatically update when the node changes (e.g., node.count)
|
|
40
|
-
* const { node } = useTreeNode(root);
|
|
41
|
-
* // node.list is its own TreeNode, so we make it stateful as well
|
|
42
|
-
* const { node: list } = useTreeNode(node?.list);
|
|
43
|
-
* if (!node || !list) return (<>"Loading"</>);
|
|
44
|
-
* return (
|
|
45
|
-
* <div>
|
|
46
|
-
* <div>Changed: {node.listChangedCount}</div>
|
|
47
|
-
* <button onClick={() => node.insert()}>Insert</button>
|
|
48
|
-
* { list.map((item) => <div key={item}>{item}</div>) }
|
|
49
|
-
* </div>
|
|
50
|
-
* );
|
|
51
|
-
* }
|
|
52
|
-
* ```
|
|
53
|
-
*
|
|
54
|
-
* @example
|
|
55
|
-
* Example using `"treeChanged"` `stateChangeType`
|
|
56
|
-
* ```tsx
|
|
57
|
-
* import { SchemaFactory, TreeViewConfiguration } from "fluid-framework";
|
|
58
|
-
* import { useSharedTree, useTreeNode } from "@microsoft/live-share-react";
|
|
59
|
-
* // Declare a schema factory with your unique uuid
|
|
60
|
-
* const sf = new SchemaFactory("fc1db2e8-0000-11ee-be57-0242ac120002");
|
|
61
|
-
*
|
|
62
|
-
* class ChildObject extends sf.object("ChildObject", {
|
|
63
|
-
* count: sf.number,
|
|
64
|
-
* }) {
|
|
65
|
-
* increment() {
|
|
66
|
-
* this.count += 1;
|
|
67
|
-
* }
|
|
68
|
-
* }
|
|
69
|
-
*
|
|
70
|
-
* class YourObject extends sf.object("YourObject", {
|
|
71
|
-
* child: ChildObject,
|
|
72
|
-
* }) {}
|
|
73
|
-
* const config = new TreeViewConfiguration({ schema: YourObject });
|
|
74
|
-
* const initialData = new YourObject({
|
|
75
|
-
* child: new ChildObject({ count: 0 }),
|
|
76
|
-
* });
|
|
77
|
-
*
|
|
78
|
-
* // Must be child component of <LiveShareProvider> or <AzureProvider>
|
|
79
|
-
* export const YourComponent = () => {
|
|
80
|
-
* // Get the root node of the `SharedTree` mapped to "some-unique-key"
|
|
81
|
-
* const { root } = useSharedTree("some-unique-key", config, initialData);
|
|
82
|
-
* // Using "treeChanged" prop makes all children nodes stateful as well.
|
|
83
|
-
* // Use with caution / measure render performance with React dev tools.
|
|
84
|
-
* const { node } = useTreeNode(root, "treeChanged");
|
|
85
|
-
* if (!node) return (<>"Loading"</>);
|
|
86
|
-
* return (
|
|
87
|
-
* <div>
|
|
88
|
-
* <div>Changed: {node.child.count}</div>
|
|
89
|
-
* <button onClick={() => node.increment()}>Insert</button>
|
|
90
|
-
* </div>
|
|
91
|
-
* );
|
|
92
|
-
* }
|
|
93
|
-
* ```
|
|
94
|
-
*/
|
|
95
|
-
export declare function useTreeNode<TNode extends TreeNode | undefined = TreeNode>(node: TNode, stateChangeType?: keyof TreeChangeEvents): IUseTreeNodeResults<TNode>;
|
|
96
|
-
//# sourceMappingURL=useTreeNode.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useTreeNode.d.ts","sourceRoot":"","sources":["../../../src/shared-hooks/useTreeNode.ts"],"names":[],"mappings":"AAAA,OAAO,EAAQ,gBAAgB,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AACnE,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAQxD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2FG;AACH,wBAAgB,WAAW,CAAC,KAAK,SAAS,QAAQ,GAAG,SAAS,GAAG,QAAQ,EACrE,IAAI,EAAE,KAAK,EACX,eAAe,GAAE,MAAM,gBAAgC,GACxD,mBAAmB,CAAC,KAAK,CAAC,CA0C5B"}
|
|
@@ -1,135 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.useTreeNode = useTreeNode;
|
|
4
|
-
const fluid_framework_1 = require("fluid-framework");
|
|
5
|
-
const react_1 = require("react");
|
|
6
|
-
const tree_node_utils_js_1 = require("./internals/tree-node-utils.js");
|
|
7
|
-
/**
|
|
8
|
-
* Makes a provided Fluid `TreeNode` stateful in React.
|
|
9
|
-
*
|
|
10
|
-
* @param node the Fluid `SharedTree` `TreeNode` instance to make stateful.
|
|
11
|
-
* @param stateChangeType listener type to apply changes for. Default value is "nodeChanged", which has the most optimal performance.
|
|
12
|
-
* Provide "treeChanged" to make all children nodes stateful as well when those child nodes change.
|
|
13
|
-
* When using the default, you must pass all child `TreeNode` values into `useTreeNode` for them to be stateful as well.
|
|
14
|
-
* @returns a stateful version `node`
|
|
15
|
-
*
|
|
16
|
-
* @example
|
|
17
|
-
* Example using default `"nodeChanged"` `stateChangeType`
|
|
18
|
-
* ```tsx
|
|
19
|
-
* import { SchemaFactory, TreeViewConfiguration } from "fluid-framework";
|
|
20
|
-
* import { useSharedTree, useTreeNode } from "@microsoft/live-share-react";
|
|
21
|
-
* // Declare a schema factory with your unique uuid
|
|
22
|
-
* const sf = new SchemaFactory("fc1db2e8-0000-11ee-be57-0242ac120002");
|
|
23
|
-
* class YourObject extends sf.object("YourObject", {
|
|
24
|
-
* listChangedCount: sf.number,
|
|
25
|
-
* list: sf.array(sf.string),
|
|
26
|
-
* }) {
|
|
27
|
-
* // You can add your own utility functions
|
|
28
|
-
* insert() {
|
|
29
|
-
* this.list.insertAtEnd("some text");
|
|
30
|
-
* this.listChangedCount += 1;
|
|
31
|
-
* }
|
|
32
|
-
* }
|
|
33
|
-
* const config = new TreeViewConfiguration({ schema: YourObject });
|
|
34
|
-
* const initialData = new YourObject({
|
|
35
|
-
* number: 0,
|
|
36
|
-
* list: [],
|
|
37
|
-
* });
|
|
38
|
-
*
|
|
39
|
-
* // Must be child component of <LiveShareProvider> or <AzureProvider>
|
|
40
|
-
* export const YourComponent = () => {
|
|
41
|
-
* // Get the root node of the `SharedTree` mapped to "some-unique-key"
|
|
42
|
-
* const { root } = useSharedTree("some-unique-key", config, initialData);
|
|
43
|
-
* // Makes root stateful / automatically update when the node changes (e.g., node.count)
|
|
44
|
-
* const { node } = useTreeNode(root);
|
|
45
|
-
* // node.list is its own TreeNode, so we make it stateful as well
|
|
46
|
-
* const { node: list } = useTreeNode(node?.list);
|
|
47
|
-
* if (!node || !list) return (<>"Loading"</>);
|
|
48
|
-
* return (
|
|
49
|
-
* <div>
|
|
50
|
-
* <div>Changed: {node.listChangedCount}</div>
|
|
51
|
-
* <button onClick={() => node.insert()}>Insert</button>
|
|
52
|
-
* { list.map((item) => <div key={item}>{item}</div>) }
|
|
53
|
-
* </div>
|
|
54
|
-
* );
|
|
55
|
-
* }
|
|
56
|
-
* ```
|
|
57
|
-
*
|
|
58
|
-
* @example
|
|
59
|
-
* Example using `"treeChanged"` `stateChangeType`
|
|
60
|
-
* ```tsx
|
|
61
|
-
* import { SchemaFactory, TreeViewConfiguration } from "fluid-framework";
|
|
62
|
-
* import { useSharedTree, useTreeNode } from "@microsoft/live-share-react";
|
|
63
|
-
* // Declare a schema factory with your unique uuid
|
|
64
|
-
* const sf = new SchemaFactory("fc1db2e8-0000-11ee-be57-0242ac120002");
|
|
65
|
-
*
|
|
66
|
-
* class ChildObject extends sf.object("ChildObject", {
|
|
67
|
-
* count: sf.number,
|
|
68
|
-
* }) {
|
|
69
|
-
* increment() {
|
|
70
|
-
* this.count += 1;
|
|
71
|
-
* }
|
|
72
|
-
* }
|
|
73
|
-
*
|
|
74
|
-
* class YourObject extends sf.object("YourObject", {
|
|
75
|
-
* child: ChildObject,
|
|
76
|
-
* }) {}
|
|
77
|
-
* const config = new TreeViewConfiguration({ schema: YourObject });
|
|
78
|
-
* const initialData = new YourObject({
|
|
79
|
-
* child: new ChildObject({ count: 0 }),
|
|
80
|
-
* });
|
|
81
|
-
*
|
|
82
|
-
* // Must be child component of <LiveShareProvider> or <AzureProvider>
|
|
83
|
-
* export const YourComponent = () => {
|
|
84
|
-
* // Get the root node of the `SharedTree` mapped to "some-unique-key"
|
|
85
|
-
* const { root } = useSharedTree("some-unique-key", config, initialData);
|
|
86
|
-
* // Using "treeChanged" prop makes all children nodes stateful as well.
|
|
87
|
-
* // Use with caution / measure render performance with React dev tools.
|
|
88
|
-
* const { node } = useTreeNode(root, "treeChanged");
|
|
89
|
-
* if (!node) return (<>"Loading"</>);
|
|
90
|
-
* return (
|
|
91
|
-
* <div>
|
|
92
|
-
* <div>Changed: {node.child.count}</div>
|
|
93
|
-
* <button onClick={() => node.increment()}>Insert</button>
|
|
94
|
-
* </div>
|
|
95
|
-
* );
|
|
96
|
-
* }
|
|
97
|
-
* ```
|
|
98
|
-
*/
|
|
99
|
-
function useTreeNode(node, stateChangeType = "nodeChanged") {
|
|
100
|
-
// When we return a proxied node to a developer, it's possible they will pass it back to us in this hook.
|
|
101
|
-
// We can't listen using Tree.on using a proxy node though...
|
|
102
|
-
// Thus, if we are already listening to a node from another instance of this hook, we look for the unproxied node.
|
|
103
|
-
const rawNode = (0, tree_node_utils_js_1.getRawNode)(node);
|
|
104
|
-
const [proxyNode, setProxyNode] = (0, react_1.useState)(rawNode);
|
|
105
|
-
const treeProxyMapRef = (0, react_1.useRef)(new WeakMap());
|
|
106
|
-
(0, react_1.useEffect)(() => {
|
|
107
|
-
if (!rawNode)
|
|
108
|
-
return;
|
|
109
|
-
// Set default value
|
|
110
|
-
setProxyNode(rawNode);
|
|
111
|
-
function onNodeChanged() {
|
|
112
|
-
if (!rawNode)
|
|
113
|
-
return;
|
|
114
|
-
const proxyNode = (0, tree_node_utils_js_1.buildProxy)(rawNode, treeProxyMapRef.current);
|
|
115
|
-
setProxyNode(proxyNode);
|
|
116
|
-
}
|
|
117
|
-
// Listen to Fluid's base node from their TreeView so Fluid flex nodes continue to work
|
|
118
|
-
const unsubscribeListeners = [
|
|
119
|
-
fluid_framework_1.Tree.on(rawNode, "nodeChanged", onNodeChanged),
|
|
120
|
-
];
|
|
121
|
-
if (stateChangeType === "treeChanged") {
|
|
122
|
-
// Recursively for all child nodes of this node in the tree
|
|
123
|
-
(0, tree_node_utils_js_1.setUpListenersForNodeChildren)(rawNode, rawNode, treeProxyMapRef.current, unsubscribeListeners,
|
|
124
|
-
// TODO: fix typing so casting isn't necessary
|
|
125
|
-
setProxyNode);
|
|
126
|
-
}
|
|
127
|
-
return () => {
|
|
128
|
-
unsubscribeListeners.forEach((unsubscribe) => unsubscribe());
|
|
129
|
-
};
|
|
130
|
-
}, [rawNode, stateChangeType]);
|
|
131
|
-
return {
|
|
132
|
-
node: proxyNode,
|
|
133
|
-
};
|
|
134
|
-
}
|
|
135
|
-
//# sourceMappingURL=useTreeNode.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useTreeNode.js","sourceRoot":"","sources":["../../../src/shared-hooks/useTreeNode.ts"],"names":[],"mappings":";;AAqGA,kCA6CC;AAlJD,qDAAmE;AAEnE,iCAAoD;AACpD,uEAIwC;AAExC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2FG;AACH,SAAgB,WAAW,CACvB,IAAW,EACX,kBAA0C,aAAa;IAEvD,yGAAyG;IACzG,6DAA6D;IAC7D,kHAAkH;IAClH,MAAM,OAAO,GAAG,IAAA,+BAAU,EAAC,IAAI,CAAC,CAAC;IACjC,MAAM,CAAC,SAAS,EAAE,YAAY,CAAC,GAAG,IAAA,gBAAQ,EAAQ,OAAO,CAAC,CAAC;IAC3D,MAAM,eAAe,GAAG,IAAA,cAAM,EAA8B,IAAI,OAAO,EAAE,CAAC,CAAC;IAE3E,IAAA,iBAAS,EAAC,GAAG,EAAE;QACX,IAAI,CAAC,OAAO;YAAE,OAAO;QAErB,oBAAoB;QACpB,YAAY,CAAC,OAAO,CAAC,CAAC;QACtB,SAAS,aAAa;YAClB,IAAI,CAAC,OAAO;gBAAE,OAAO;YAErB,MAAM,SAAS,GAAG,IAAA,+BAAU,EAAC,OAAO,EAAE,eAAe,CAAC,OAAO,CAAC,CAAC;YAC/D,YAAY,CAAC,SAAS,CAAC,CAAC;QAC5B,CAAC;QACD,uFAAuF;QACvF,MAAM,oBAAoB,GAAmB;YACzC,sBAAI,CAAC,EAAE,CAAC,OAAO,EAAE,aAAa,EAAE,aAAa,CAAC;SACjD,CAAC;QACF,IAAI,eAAe,KAAK,aAAa,EAAE,CAAC;YACpC,2DAA2D;YAC3D,IAAA,kDAA6B,EACzB,OAAO,EACP,OAAO,EACP,eAAe,CAAC,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