@microsoft/live-share-react 1.3.1-preview.0 → 1.4.1-preview.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/cjs/index.d.ts +7 -0
- package/bin/cjs/index.d.ts.map +1 -0
- package/bin/cjs/index.js +23 -0
- package/bin/cjs/index.js.map +1 -0
- package/bin/cjs/interfaces/LiveInterfaceExtensions.d.ts +26 -0
- package/bin/cjs/interfaces/LiveInterfaceExtensions.d.ts.map +1 -0
- package/bin/cjs/interfaces/LiveInterfaceExtensions.js +7 -0
- package/bin/cjs/interfaces/LiveInterfaceExtensions.js.map +1 -0
- package/bin/cjs/interfaces/index.d.ts +2 -0
- package/bin/cjs/interfaces/index.d.ts.map +1 -0
- package/bin/cjs/interfaces/index.js +18 -0
- package/bin/cjs/interfaces/index.js.map +1 -0
- package/bin/cjs/internal/errors.d.ts +41 -0
- package/bin/cjs/internal/errors.d.ts.map +1 -0
- package/bin/cjs/internal/errors.js +48 -0
- package/bin/cjs/internal/errors.js.map +1 -0
- package/bin/cjs/internal/index.d.ts +3 -0
- package/bin/cjs/internal/index.d.ts.map +1 -0
- package/bin/cjs/internal/index.js +19 -0
- package/bin/cjs/internal/index.js.map +1 -0
- package/bin/cjs/internal/type-guards.d.ts +11 -0
- package/bin/cjs/internal/type-guards.d.ts.map +1 -0
- package/bin/cjs/internal/type-guards.js +24 -0
- package/bin/cjs/internal/type-guards.js.map +1 -0
- package/bin/cjs/live-hooks/index.d.ts +8 -0
- package/bin/cjs/live-hooks/index.d.ts.map +1 -0
- package/bin/cjs/live-hooks/index.js +24 -0
- package/bin/cjs/live-hooks/index.js.map +1 -0
- package/bin/cjs/live-hooks/useLiveCanvas.d.ts +80 -0
- package/bin/cjs/live-hooks/useLiveCanvas.d.ts.map +1 -0
- package/bin/cjs/live-hooks/useLiveCanvas.js +244 -0
- package/bin/cjs/live-hooks/useLiveCanvas.js.map +1 -0
- package/bin/cjs/live-hooks/useLiveEvent.d.ts +59 -0
- package/bin/cjs/live-hooks/useLiveEvent.d.ts.map +1 -0
- package/bin/cjs/live-hooks/useLiveEvent.js +150 -0
- package/bin/cjs/live-hooks/useLiveEvent.js.map +1 -0
- package/bin/cjs/live-hooks/useLiveFollowMode.d.ts +163 -0
- package/bin/cjs/live-hooks/useLiveFollowMode.d.ts.map +1 -0
- package/bin/cjs/live-hooks/useLiveFollowMode.js +360 -0
- package/bin/cjs/live-hooks/useLiveFollowMode.js.map +1 -0
- package/bin/cjs/live-hooks/useLivePresence.d.ts +76 -0
- package/bin/cjs/live-hooks/useLivePresence.d.ts.map +1 -0
- package/bin/cjs/live-hooks/useLivePresence.js +170 -0
- package/bin/cjs/live-hooks/useLivePresence.js.map +1 -0
- package/bin/cjs/live-hooks/useLiveState.d.ts +66 -0
- package/bin/cjs/live-hooks/useLiveState.d.ts.map +1 -0
- package/bin/cjs/live-hooks/useLiveState.js +134 -0
- package/bin/cjs/live-hooks/useLiveState.js.map +1 -0
- package/bin/cjs/live-hooks/useLiveTimer.d.ts +80 -0
- package/bin/cjs/live-hooks/useLiveTimer.d.ts.map +1 -0
- package/bin/cjs/live-hooks/useLiveTimer.js +233 -0
- package/bin/cjs/live-hooks/useLiveTimer.js.map +1 -0
- package/bin/cjs/live-hooks/useMediaSynchronizer.d.ts +86 -0
- package/bin/cjs/live-hooks/useMediaSynchronizer.d.ts.map +1 -0
- package/bin/cjs/live-hooks/useMediaSynchronizer.js +301 -0
- package/bin/cjs/live-hooks/useMediaSynchronizer.js.map +1 -0
- package/bin/cjs/package.json +1 -0
- package/bin/cjs/providers/AzureProvider.d.ts +113 -0
- package/bin/cjs/providers/AzureProvider.d.ts.map +1 -0
- package/bin/cjs/providers/AzureProvider.js +127 -0
- package/bin/cjs/providers/AzureProvider.js.map +1 -0
- package/bin/cjs/providers/LiveShareProvider.d.ts +193 -0
- package/bin/cjs/providers/LiveShareProvider.d.ts.map +1 -0
- package/bin/cjs/providers/LiveShareProvider.js +205 -0
- package/bin/cjs/providers/LiveShareProvider.js.map +1 -0
- package/bin/cjs/providers/index.d.ts +3 -0
- package/bin/cjs/providers/index.d.ts.map +1 -0
- package/bin/cjs/providers/index.js +19 -0
- package/bin/cjs/providers/index.js.map +1 -0
- package/bin/cjs/shared-hooks/index.d.ts +7 -0
- package/bin/cjs/shared-hooks/index.d.ts.map +1 -0
- package/bin/cjs/shared-hooks/index.js +23 -0
- package/bin/cjs/shared-hooks/index.js.map +1 -0
- package/bin/cjs/shared-hooks/internals/tree-node-constants.d.ts +3 -0
- package/bin/cjs/shared-hooks/internals/tree-node-constants.d.ts.map +1 -0
- package/bin/cjs/shared-hooks/internals/tree-node-constants.js +6 -0
- package/bin/cjs/shared-hooks/internals/tree-node-constants.js.map +1 -0
- package/bin/cjs/shared-hooks/internals/tree-node-types.d.ts +10 -0
- package/bin/cjs/shared-hooks/internals/tree-node-types.d.ts.map +1 -0
- package/bin/cjs/shared-hooks/internals/tree-node-types.js +23 -0
- package/bin/cjs/shared-hooks/internals/tree-node-types.js.map +1 -0
- package/bin/cjs/shared-hooks/internals/tree-node-utils.d.ts +33 -0
- package/bin/cjs/shared-hooks/internals/tree-node-utils.d.ts.map +1 -0
- package/bin/cjs/shared-hooks/internals/tree-node-utils.js +193 -0
- package/bin/cjs/shared-hooks/internals/tree-node-utils.js.map +1 -0
- package/bin/cjs/shared-hooks/useDynamicDDS.d.ts +23 -0
- package/bin/cjs/shared-hooks/useDynamicDDS.d.ts.map +1 -0
- package/bin/cjs/shared-hooks/useDynamicDDS.js +87 -0
- package/bin/cjs/shared-hooks/useDynamicDDS.js.map +1 -0
- package/bin/cjs/shared-hooks/useSharedMap.d.ts +25 -0
- package/bin/cjs/shared-hooks/useSharedMap.d.ts.map +1 -0
- package/bin/cjs/shared-hooks/useSharedMap.js +134 -0
- package/bin/cjs/shared-hooks/useSharedMap.js.map +1 -0
- package/bin/cjs/shared-hooks/useSharedState.d.ts +22 -0
- package/bin/cjs/shared-hooks/useSharedState.d.ts.map +1 -0
- package/bin/cjs/shared-hooks/useSharedState.js +80 -0
- package/bin/cjs/shared-hooks/useSharedState.js.map +1 -0
- package/bin/cjs/shared-hooks/useSharedStateRegistry.d.ts +37 -0
- package/bin/cjs/shared-hooks/useSharedStateRegistry.d.ts.map +1 -0
- package/bin/cjs/shared-hooks/useSharedStateRegistry.js +120 -0
- package/bin/cjs/shared-hooks/useSharedStateRegistry.js.map +1 -0
- package/bin/cjs/shared-hooks/useSharedTree.d.ts +57 -0
- package/bin/cjs/shared-hooks/useSharedTree.d.ts.map +1 -0
- package/bin/cjs/shared-hooks/useSharedTree.js +123 -0
- package/bin/cjs/shared-hooks/useSharedTree.js.map +1 -0
- package/bin/cjs/shared-hooks/useTreeNode.d.ts +96 -0
- package/bin/cjs/shared-hooks/useTreeNode.d.ts.map +1 -0
- package/bin/cjs/shared-hooks/useTreeNode.js +135 -0
- package/bin/cjs/shared-hooks/useTreeNode.js.map +1 -0
- package/bin/cjs/types/ActionTypes.d.ts +112 -0
- package/bin/cjs/types/ActionTypes.d.ts.map +1 -0
- package/bin/cjs/types/ActionTypes.js +7 -0
- package/bin/cjs/types/ActionTypes.js.map +1 -0
- package/bin/cjs/types/PropTypes.d.ts +56 -0
- package/bin/cjs/types/PropTypes.d.ts.map +1 -0
- package/bin/cjs/types/PropTypes.js +7 -0
- package/bin/cjs/types/PropTypes.js.map +1 -0
- package/bin/cjs/types/ResultTypes.d.ts +334 -0
- package/bin/cjs/types/ResultTypes.d.ts.map +1 -0
- package/bin/cjs/types/ResultTypes.js +7 -0
- package/bin/cjs/types/ResultTypes.js.map +1 -0
- package/bin/cjs/types/index.d.ts +4 -0
- package/bin/cjs/types/index.d.ts.map +1 -0
- package/bin/cjs/types/index.js +20 -0
- package/bin/cjs/types/index.js.map +1 -0
- package/bin/cjs/utils/index.d.ts +2 -0
- package/bin/cjs/utils/index.d.ts.map +1 -0
- package/bin/cjs/utils/index.js +18 -0
- package/bin/cjs/utils/index.js.map +1 -0
- package/bin/cjs/utils/type-check.d.ts +15 -0
- package/bin/cjs/utils/type-check.d.ts.map +1 -0
- package/bin/cjs/utils/type-check.js +62 -0
- package/bin/cjs/utils/type-check.js.map +1 -0
- package/bin/esm/index.d.ts +7 -0
- package/bin/esm/index.d.ts.map +1 -0
- package/bin/esm/index.js +7 -0
- package/bin/esm/index.js.map +1 -0
- package/bin/esm/interfaces/LiveInterfaceExtensions.d.ts +26 -0
- package/bin/esm/interfaces/LiveInterfaceExtensions.d.ts.map +1 -0
- package/bin/esm/interfaces/LiveInterfaceExtensions.js +6 -0
- package/bin/esm/interfaces/LiveInterfaceExtensions.js.map +1 -0
- package/bin/esm/interfaces/index.d.ts +2 -0
- package/bin/esm/interfaces/index.d.ts.map +1 -0
- package/bin/esm/interfaces/index.js +2 -0
- package/bin/esm/interfaces/index.js.map +1 -0
- package/bin/esm/internal/errors.d.ts +41 -0
- package/bin/esm/internal/errors.d.ts.map +1 -0
- package/bin/esm/internal/errors.js +42 -0
- package/bin/esm/internal/errors.js.map +1 -0
- package/bin/esm/internal/index.d.ts +3 -0
- package/bin/esm/internal/index.d.ts.map +1 -0
- package/bin/esm/internal/index.js +3 -0
- package/bin/esm/internal/index.js.map +1 -0
- package/bin/esm/internal/type-guards.d.ts +11 -0
- package/bin/esm/internal/type-guards.d.ts.map +1 -0
- package/bin/esm/internal/type-guards.js +20 -0
- package/bin/esm/internal/type-guards.js.map +1 -0
- package/bin/esm/live-hooks/index.d.ts +8 -0
- package/bin/esm/live-hooks/index.d.ts.map +1 -0
- package/bin/esm/live-hooks/index.js +8 -0
- package/bin/esm/live-hooks/index.js.map +1 -0
- package/bin/esm/live-hooks/useLiveCanvas.d.ts +80 -0
- package/bin/esm/live-hooks/useLiveCanvas.d.ts.map +1 -0
- package/bin/esm/live-hooks/useLiveCanvas.js +238 -0
- package/bin/esm/live-hooks/useLiveCanvas.js.map +1 -0
- package/bin/esm/live-hooks/useLiveEvent.d.ts +59 -0
- package/bin/esm/live-hooks/useLiveEvent.d.ts.map +1 -0
- package/bin/esm/live-hooks/useLiveEvent.js +144 -0
- package/bin/esm/live-hooks/useLiveEvent.js.map +1 -0
- package/bin/esm/live-hooks/useLiveFollowMode.d.ts +163 -0
- package/bin/esm/live-hooks/useLiveFollowMode.d.ts.map +1 -0
- package/bin/esm/live-hooks/useLiveFollowMode.js +354 -0
- package/bin/esm/live-hooks/useLiveFollowMode.js.map +1 -0
- package/bin/esm/live-hooks/useLivePresence.d.ts +76 -0
- package/bin/esm/live-hooks/useLivePresence.d.ts.map +1 -0
- package/bin/esm/live-hooks/useLivePresence.js +164 -0
- package/bin/esm/live-hooks/useLivePresence.js.map +1 -0
- package/bin/esm/live-hooks/useLiveState.d.ts +66 -0
- package/bin/esm/live-hooks/useLiveState.d.ts.map +1 -0
- package/bin/esm/live-hooks/useLiveState.js +128 -0
- package/bin/esm/live-hooks/useLiveState.js.map +1 -0
- package/bin/esm/live-hooks/useLiveTimer.d.ts +80 -0
- package/bin/esm/live-hooks/useLiveTimer.d.ts.map +1 -0
- package/bin/esm/live-hooks/useLiveTimer.js +227 -0
- package/bin/esm/live-hooks/useLiveTimer.js.map +1 -0
- package/bin/esm/live-hooks/useMediaSynchronizer.d.ts +86 -0
- package/bin/esm/live-hooks/useMediaSynchronizer.d.ts.map +1 -0
- package/bin/esm/live-hooks/useMediaSynchronizer.js +295 -0
- package/bin/esm/live-hooks/useMediaSynchronizer.js.map +1 -0
- package/bin/esm/providers/AzureProvider.d.ts +113 -0
- package/bin/esm/providers/AzureProvider.d.ts.map +1 -0
- package/bin/esm/providers/AzureProvider.js +119 -0
- package/bin/esm/providers/AzureProvider.js.map +1 -0
- package/bin/esm/providers/LiveShareProvider.d.ts +193 -0
- package/bin/esm/providers/LiveShareProvider.d.ts.map +1 -0
- package/bin/esm/providers/LiveShareProvider.js +197 -0
- package/bin/esm/providers/LiveShareProvider.js.map +1 -0
- package/bin/esm/providers/index.d.ts +3 -0
- package/bin/esm/providers/index.d.ts.map +1 -0
- package/bin/esm/providers/index.js +3 -0
- package/bin/esm/providers/index.js.map +1 -0
- package/bin/esm/shared-hooks/index.d.ts +7 -0
- package/bin/esm/shared-hooks/index.d.ts.map +1 -0
- package/bin/esm/shared-hooks/index.js +7 -0
- package/bin/esm/shared-hooks/index.js.map +1 -0
- package/bin/esm/shared-hooks/internals/tree-node-constants.d.ts +3 -0
- package/bin/esm/shared-hooks/internals/tree-node-constants.d.ts.map +1 -0
- package/bin/esm/shared-hooks/internals/tree-node-constants.js +3 -0
- package/bin/esm/shared-hooks/internals/tree-node-constants.js.map +1 -0
- package/bin/esm/shared-hooks/internals/tree-node-types.d.ts +10 -0
- package/bin/esm/shared-hooks/internals/tree-node-types.d.ts.map +1 -0
- package/bin/esm/shared-hooks/internals/tree-node-types.js +18 -0
- package/bin/esm/shared-hooks/internals/tree-node-types.js.map +1 -0
- package/bin/esm/shared-hooks/internals/tree-node-utils.d.ts +33 -0
- package/bin/esm/shared-hooks/internals/tree-node-utils.d.ts.map +1 -0
- package/bin/esm/shared-hooks/internals/tree-node-utils.js +188 -0
- package/bin/esm/shared-hooks/internals/tree-node-utils.js.map +1 -0
- package/bin/esm/shared-hooks/useDynamicDDS.d.ts +23 -0
- package/bin/esm/shared-hooks/useDynamicDDS.d.ts.map +1 -0
- package/bin/esm/shared-hooks/useDynamicDDS.js +81 -0
- package/bin/esm/shared-hooks/useDynamicDDS.js.map +1 -0
- package/bin/esm/shared-hooks/useSharedMap.d.ts +25 -0
- package/bin/esm/shared-hooks/useSharedMap.d.ts.map +1 -0
- package/bin/esm/shared-hooks/useSharedMap.js +128 -0
- package/bin/esm/shared-hooks/useSharedMap.js.map +1 -0
- package/bin/esm/shared-hooks/useSharedState.d.ts +22 -0
- package/bin/esm/shared-hooks/useSharedState.d.ts.map +1 -0
- package/bin/esm/shared-hooks/useSharedState.js +74 -0
- package/bin/esm/shared-hooks/useSharedState.js.map +1 -0
- package/bin/esm/shared-hooks/useSharedStateRegistry.d.ts +37 -0
- package/bin/esm/shared-hooks/useSharedStateRegistry.d.ts.map +1 -0
- package/bin/esm/shared-hooks/useSharedStateRegistry.js +113 -0
- package/bin/esm/shared-hooks/useSharedStateRegistry.js.map +1 -0
- package/bin/esm/shared-hooks/useSharedTree.d.ts +57 -0
- package/bin/esm/shared-hooks/useSharedTree.d.ts.map +1 -0
- package/bin/esm/shared-hooks/useSharedTree.js +117 -0
- package/bin/esm/shared-hooks/useSharedTree.js.map +1 -0
- package/bin/esm/shared-hooks/useTreeNode.d.ts +96 -0
- package/bin/esm/shared-hooks/useTreeNode.d.ts.map +1 -0
- package/bin/esm/shared-hooks/useTreeNode.js +132 -0
- package/bin/esm/shared-hooks/useTreeNode.js.map +1 -0
- package/bin/esm/types/ActionTypes.d.ts +112 -0
- package/bin/esm/types/ActionTypes.d.ts.map +1 -0
- package/bin/esm/types/ActionTypes.js +6 -0
- package/bin/esm/types/ActionTypes.js.map +1 -0
- package/bin/esm/types/PropTypes.d.ts +56 -0
- package/bin/esm/types/PropTypes.d.ts.map +1 -0
- package/bin/esm/types/PropTypes.js +6 -0
- package/bin/esm/types/PropTypes.js.map +1 -0
- package/bin/esm/types/ResultTypes.d.ts +334 -0
- package/bin/esm/types/ResultTypes.d.ts.map +1 -0
- package/bin/esm/types/ResultTypes.js +6 -0
- package/bin/esm/types/ResultTypes.js.map +1 -0
- package/bin/esm/types/index.d.ts +4 -0
- package/bin/esm/types/index.d.ts.map +1 -0
- package/bin/esm/types/index.js +4 -0
- package/bin/esm/types/index.js.map +1 -0
- package/bin/esm/utils/index.d.ts +2 -0
- package/bin/esm/utils/index.d.ts.map +1 -0
- package/bin/esm/utils/index.js +2 -0
- package/bin/esm/utils/index.js.map +1 -0
- package/bin/esm/utils/type-check.d.ts +15 -0
- package/bin/esm/utils/type-check.d.ts.map +1 -0
- package/bin/esm/utils/type-check.js +54 -0
- package/bin/esm/utils/type-check.js.map +1 -0
- package/bin/internal/errors.d.ts +15 -0
- package/bin/internal/errors.d.ts.map +1 -1
- package/bin/internal/errors.js.map +1 -1
- package/bin/internal/type-guards.d.ts +5 -0
- package/bin/internal/type-guards.d.ts.map +1 -1
- package/bin/internal/type-guards.js +12 -0
- package/bin/internal/type-guards.js.map +1 -1
- package/bin/live-hooks/useLiveEvent.d.ts.map +1 -1
- package/bin/live-hooks/useLiveEvent.js +6 -0
- package/bin/live-hooks/useLiveEvent.js.map +1 -1
- package/bin/live-hooks/useLiveFollowMode.d.ts.map +1 -1
- package/bin/live-hooks/useLiveFollowMode.js +2 -4
- package/bin/live-hooks/useLiveFollowMode.js.map +1 -1
- package/bin/live-hooks/useLivePresence.d.ts.map +1 -1
- package/bin/live-hooks/useLivePresence.js +1 -3
- package/bin/live-hooks/useLivePresence.js.map +1 -1
- package/bin/live-hooks/useLiveState.d.ts.map +1 -1
- package/bin/live-hooks/useLiveState.js +4 -2
- package/bin/live-hooks/useLiveState.js.map +1 -1
- package/bin/live-hooks/useLiveTimer.d.ts.map +1 -1
- package/bin/live-hooks/useLiveTimer.js +4 -0
- package/bin/live-hooks/useLiveTimer.js.map +1 -1
- package/bin/providers/LiveShareProvider.d.ts.map +1 -1
- package/bin/providers/LiveShareProvider.js +8 -0
- package/bin/providers/LiveShareProvider.js.map +1 -1
- package/package.json +8 -8
- package/src/internal/errors.ts +16 -0
- package/src/internal/type-guards.ts +12 -0
- package/src/live-hooks/useLiveEvent.ts +6 -0
- package/src/live-hooks/useLiveFollowMode.ts +2 -3
- package/src/live-hooks/useLivePresence.ts +1 -2
- package/src/live-hooks/useLiveState.ts +4 -3
- package/src/live-hooks/useLiveTimer.ts +4 -0
- package/src/providers/LiveShareProvider.tsx +12 -0
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.buildProxy = buildProxy;
|
|
4
|
+
exports.setUpListenersForNodeChildren = setUpListenersForNodeChildren;
|
|
5
|
+
exports.getRawNode = getRawNode;
|
|
6
|
+
const tree_node_constants_js_1 = require("./tree-node-constants.js");
|
|
7
|
+
const tree_node_types_js_1 = require("./tree-node-types.js");
|
|
8
|
+
const fluid_framework_1 = require("fluid-framework");
|
|
9
|
+
// Exported utils
|
|
10
|
+
/**
|
|
11
|
+
* @internal
|
|
12
|
+
* Build a proxied version of a node and set its value to the treeMap provided
|
|
13
|
+
*
|
|
14
|
+
* @param rawNode the raw proxy node exposed by Fluid
|
|
15
|
+
* @param treeMap a map where Fluid's proxy node is mapped to our proxied node
|
|
16
|
+
* @returns TNode instance
|
|
17
|
+
*/
|
|
18
|
+
function buildProxy(rawNode, treeMap) {
|
|
19
|
+
var _a;
|
|
20
|
+
const previousProxy = treeMap.get(rawNode);
|
|
21
|
+
const previousProxyHandler = previousProxy
|
|
22
|
+
? getCustomProxyHandler(previousProxy)
|
|
23
|
+
: undefined;
|
|
24
|
+
const proxyHandler = {
|
|
25
|
+
// Add some extra stuff into the handler so we can store the original Fluid TreeNode and access it later
|
|
26
|
+
// Without overriding the rest of the getters in the object.
|
|
27
|
+
[tree_node_constants_js_1.rawTNodeKey]: rawNode,
|
|
28
|
+
[tree_node_constants_js_1.proxiedChildrenKey]: (_a = previousProxyHandler === null || previousProxyHandler === void 0 ? void 0 : previousProxyHandler[tree_node_constants_js_1.proxiedChildrenKey]) !== null && _a !== void 0 ? _a : {},
|
|
29
|
+
get: (target, prop, _) => {
|
|
30
|
+
if (prop === "[[Handler]]") {
|
|
31
|
+
return proxyHandler;
|
|
32
|
+
}
|
|
33
|
+
if (typeof prop === "string" &&
|
|
34
|
+
proxyHandler[tree_node_constants_js_1.proxiedChildrenKey][prop]) {
|
|
35
|
+
return proxyHandler[tree_node_constants_js_1.proxiedChildrenKey][prop];
|
|
36
|
+
}
|
|
37
|
+
// pass in the rawNode so Fluid doesn't get confused by our proxy object and can find the flex node
|
|
38
|
+
const value = Reflect.get(target, prop, rawNode);
|
|
39
|
+
return typeof value === "function" &&
|
|
40
|
+
typeof prop === "string" &&
|
|
41
|
+
// TODO: need a better way of identifying which types of functions need to be proxied
|
|
42
|
+
// This is because if a developer uses an array prototype function, we need to return proxied
|
|
43
|
+
// objects so React can detect changes to those nodes...
|
|
44
|
+
!["map", "flatMap", "filter", "find", "indexOf"].includes(prop)
|
|
45
|
+
? value.bind(rawNode)
|
|
46
|
+
: value;
|
|
47
|
+
},
|
|
48
|
+
set(target, p, newValue, _) {
|
|
49
|
+
return Reflect.set(target, p, newValue, rawNode);
|
|
50
|
+
},
|
|
51
|
+
};
|
|
52
|
+
const proxy = new Proxy(rawNode, proxyHandler);
|
|
53
|
+
// Track the proxy for the rawNode
|
|
54
|
+
treeMap.set(rawNode, proxy);
|
|
55
|
+
// Set raw node getter so we can access it before things like Tree.on
|
|
56
|
+
return proxy;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* @internal
|
|
60
|
+
* Set up listeners for a given TreeNode.
|
|
61
|
+
* Will recursively call this function for all children nodes of each children until there are no more child nodes.
|
|
62
|
+
*
|
|
63
|
+
* @param parentRawNode raw parent node
|
|
64
|
+
* @param rootNodeForListener root node being listened to in useTreeNode
|
|
65
|
+
* @param treeMap a map where Fluid's proxy node is mapped to our proxied node
|
|
66
|
+
* @param unsubscribeListeners list of unsubscribe listeners, where we set the unsubscribe callbacks
|
|
67
|
+
* @param setProxyNode setter to set the root proxy node listened to in useTreeNode
|
|
68
|
+
*/
|
|
69
|
+
function setUpListenersForNodeChildren(parentRawNode, rootNodeForListener, treeMap, unsubscribeListeners, setProxyNode) {
|
|
70
|
+
let entries = Object.entries(parentRawNode);
|
|
71
|
+
for (let i = 0; i < entries.length; i++) {
|
|
72
|
+
const [key, entry] = entries[i];
|
|
73
|
+
if (!entry ||
|
|
74
|
+
["string", "boolean", "number", "function"].includes(typeof entry) ||
|
|
75
|
+
!(0, tree_node_types_js_1.isTreeNode)(entry)) {
|
|
76
|
+
continue;
|
|
77
|
+
}
|
|
78
|
+
const rawEntry = getRawNode(entry);
|
|
79
|
+
const onNodeChanged = () => {
|
|
80
|
+
onTreeNodeChanged(key, rawEntry, rootNodeForListener, treeMap, setProxyNode);
|
|
81
|
+
};
|
|
82
|
+
const unsubscribe = fluid_framework_1.Tree.on(rawEntry, "nodeChanged", onNodeChanged);
|
|
83
|
+
unsubscribeListeners.push(unsubscribe);
|
|
84
|
+
// Recursively listen to children nodes of this node
|
|
85
|
+
setUpListenersForNodeChildren(rawEntry, rootNodeForListener, treeMap, unsubscribeListeners, setProxyNode);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* @internal
|
|
90
|
+
* Fluid only knows how to work with their proxied version of a TreeNode.
|
|
91
|
+
* We store a reference to that node in our proxied instances so we can easily use it when working with Fluid APIs.
|
|
92
|
+
*
|
|
93
|
+
* @param node get the raw node from the proxy
|
|
94
|
+
* @returns the raw proxied node that Fluid expects
|
|
95
|
+
*/
|
|
96
|
+
function getRawNode(node) {
|
|
97
|
+
if ((0, tree_node_types_js_1.isProxy)(node)) {
|
|
98
|
+
return getRawNodeFromProxy(node);
|
|
99
|
+
}
|
|
100
|
+
return node;
|
|
101
|
+
}
|
|
102
|
+
// Non public utils
|
|
103
|
+
/**
|
|
104
|
+
* Callback for when a tree node changed
|
|
105
|
+
*
|
|
106
|
+
* @param key key where the object is stored in the parent
|
|
107
|
+
* @param rawNode the raw node that changed
|
|
108
|
+
* @param rootNodeForListener the root node that is being listened to in useTreeNode
|
|
109
|
+
* @param treeMap a map where Fluid's proxy node is mapped to our proxied node
|
|
110
|
+
* @param setProxyNode setter to set the root proxy node listened to in useTreeNode
|
|
111
|
+
*/
|
|
112
|
+
function onTreeNodeChanged(key, rawNode, rootNodeForListener, treeMap, setProxyNode) {
|
|
113
|
+
const proxyNode = buildProxy(rawNode, treeMap);
|
|
114
|
+
const parent = fluid_framework_1.Tree.parent(rawNode);
|
|
115
|
+
if (!parent) {
|
|
116
|
+
throw new Error("useTreeNode onTreeNodeChanged: no parent found for rawParentNode");
|
|
117
|
+
}
|
|
118
|
+
proxyParentForNode(key, parent, proxyNode, rootNodeForListener, treeMap, setProxyNode);
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Proxies the parent and sets reference to the child node that changed.
|
|
122
|
+
*
|
|
123
|
+
* @param key key where the object is referenced in its parent node
|
|
124
|
+
* @param rawParentNode raw parent tree node
|
|
125
|
+
* @param proxyNode proxied instance of the node that changed
|
|
126
|
+
* @param rootNodeForListener root node listened to in useTreeNode
|
|
127
|
+
* @param treeMap a map where Fluid's proxy node is mapped to our proxied node
|
|
128
|
+
* @param setProxyNode setter to set the root proxy node listened to in useTreeNode
|
|
129
|
+
*/
|
|
130
|
+
function proxyParentForNode(key, rawParentNode, proxyNode, rootNodeForListener, treeMap, setProxyNode) {
|
|
131
|
+
const parentProxy = buildProxy(rawParentNode, treeMap);
|
|
132
|
+
let parentProxyHandler = getCustomProxyHandler(parentProxy);
|
|
133
|
+
if (!parentProxyHandler) {
|
|
134
|
+
throw new Error("useTreeNode proxyParentForNode: unexpected error, should always find valid proxy handler");
|
|
135
|
+
}
|
|
136
|
+
parentProxyHandler[tree_node_constants_js_1.proxiedChildrenKey][key] = proxyNode;
|
|
137
|
+
if (rawParentNode === rootNodeForListener) {
|
|
138
|
+
setProxyNode(parentProxy);
|
|
139
|
+
}
|
|
140
|
+
else {
|
|
141
|
+
const parentOfParent = fluid_framework_1.Tree.parent(rawParentNode);
|
|
142
|
+
if (!parentOfParent) {
|
|
143
|
+
throw new Error("useTreeNode proxyParentForNode: no parent found for rawParentNode");
|
|
144
|
+
}
|
|
145
|
+
const parentKey = findKeyOfNode(rawParentNode, parentOfParent);
|
|
146
|
+
proxyParentForNode(parentKey, parentOfParent, parentProxy, rootNodeForListener, treeMap, setProxyNode);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Returns key where parent[key] == nodeToCheck
|
|
151
|
+
*
|
|
152
|
+
* @param nodeToCheck tree node to check
|
|
153
|
+
* @param parent parent node where nodeToCheck is a child of
|
|
154
|
+
* @returns the key for node
|
|
155
|
+
*/
|
|
156
|
+
function findKeyOfNode(nodeToCheck, parent) {
|
|
157
|
+
let entries = Object.entries(parent);
|
|
158
|
+
for (let i = 0; i < entries.length; i++) {
|
|
159
|
+
const [key, entry] = entries[i];
|
|
160
|
+
if (!entry ||
|
|
161
|
+
["string", "boolean", "number", "function"].includes(typeof entry) ||
|
|
162
|
+
!(0, tree_node_types_js_1.isTreeNode)(entry)) {
|
|
163
|
+
continue;
|
|
164
|
+
}
|
|
165
|
+
if (entry === nodeToCheck)
|
|
166
|
+
return key;
|
|
167
|
+
}
|
|
168
|
+
throw new Error("Did not find node as a child of parent");
|
|
169
|
+
}
|
|
170
|
+
// Type utils
|
|
171
|
+
/**
|
|
172
|
+
* Gets the proxy handler for a given TreeNode, assuming `isCustomProxyHandler` returns true.
|
|
173
|
+
* @param proxy the proxied TreeNode to get the handler for.
|
|
174
|
+
* @returns the handler if valid, otherwise undefined
|
|
175
|
+
*/
|
|
176
|
+
function getCustomProxyHandler(proxy) {
|
|
177
|
+
const handler = proxy["[[Handler]]"];
|
|
178
|
+
if ((0, tree_node_types_js_1.isCustomProxyHandler)(handler)) {
|
|
179
|
+
return handler;
|
|
180
|
+
}
|
|
181
|
+
return undefined;
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* Gets the raw node for a given proxied tree node
|
|
185
|
+
*
|
|
186
|
+
* @param proxy the proxied TreeNode to get the raw node for
|
|
187
|
+
* @returns the raw node if valid, otherwise undefined
|
|
188
|
+
*/
|
|
189
|
+
function getRawNodeFromProxy(proxy) {
|
|
190
|
+
var _a;
|
|
191
|
+
return (_a = getCustomProxyHandler(proxy)) === null || _a === void 0 ? void 0 : _a[tree_node_constants_js_1.rawTNodeKey];
|
|
192
|
+
}
|
|
193
|
+
//# sourceMappingURL=tree-node-utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tree-node-utils.js","sourceRoot":"","sources":["../../../../src/shared-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C,KAAe;IAC1C,MAAM,OAAO,GAAI,KAAa,CAAC,aAAa,CAAC,CAAC;IAC9C,IAAI,IAAA,yCAAoB,EAAC,OAAO,CAAC,EAAE,CAAC;QAChC,OAAO,OAAO,CAAC;IACnB,CAAC;IACD,OAAO,SAAS,CAAC;AACrB,CAAC;AAED;;;;;GAKG;AACH,SAAS,mBAAmB,CAAC,KAAe;;IACxC,OAAO,MAAA,qBAAqB,CAAC,KAAK,CAAC,0CAAG,oCAAW,CAAC,CAAC;AACvD,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
* Licensed under the Microsoft Live Share SDK License.
|
|
4
|
+
*/
|
|
5
|
+
import { FluidObject, IFluidLoadable } from "@fluidframework/core-interfaces";
|
|
6
|
+
import { SharedObjectKind } from "fluid-framework";
|
|
7
|
+
/**
|
|
8
|
+
* Hook to gets or creates a DDS that corresponds to a given uniqueKey string.
|
|
9
|
+
*
|
|
10
|
+
* @remarks
|
|
11
|
+
* This hook can only be used in a child component of `<LiveShareProvider>` or `<AzureProvider>`.
|
|
12
|
+
*
|
|
13
|
+
* @template T Type of Fluid SharedObjectKind type to load. Must conform to IFluidLoadable interface.
|
|
14
|
+
* @param uniqueKey uniqueKey value for the data object
|
|
15
|
+
* @param objectKind Fluid SharedObjectKind<T> to create/load.
|
|
16
|
+
* @param onFirstInitialize Optional. Callback function for when the DDS is first loaded
|
|
17
|
+
* @returns the DDS object, which is of type T when loaded and undefined while loading
|
|
18
|
+
*/
|
|
19
|
+
export declare function useDynamicDDS<T extends IFluidLoadable = FluidObject<any> & IFluidLoadable>(uniqueKey: string, objectClass: SharedObjectKind<T>, onFirstInitialize?: (dds: T) => void): {
|
|
20
|
+
dds: T | undefined;
|
|
21
|
+
error: Error | undefined;
|
|
22
|
+
};
|
|
23
|
+
//# sourceMappingURL=useDynamicDDS.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useDynamicDDS.d.ts","sourceRoot":"","sources":["../../../src/shared-hooks/useDynamicDDS.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,iCAAiC,CAAC;AAE9E,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAEnD;;;;;;;;;;;GAWG;AACH,wBAAgB,aAAa,CACzB,CAAC,SAAS,cAAc,GAAG,WAAW,CAAC,GAAG,CAAC,GAAG,cAAc,EAE5D,SAAS,EAAE,MAAM,EACjB,WAAW,EAAE,gBAAgB,CAAC,CAAC,CAAC,EAChC,iBAAiB,CAAC,EAAE,CAAC,GAAG,EAAE,CAAC,KAAK,IAAI,GACrC;IACC,GAAG,EAAE,CAAC,GAAG,SAAS,CAAC;IACnB,KAAK,EAAE,KAAK,GAAG,SAAS,CAAC;CAC5B,CA6DA"}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*!
|
|
3
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
4
|
+
* Licensed under the Microsoft Live Share SDK License.
|
|
5
|
+
*/
|
|
6
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
7
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
8
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
9
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
10
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
11
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
12
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
13
|
+
});
|
|
14
|
+
};
|
|
15
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
16
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
17
|
+
};
|
|
18
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
+
exports.useDynamicDDS = useDynamicDDS;
|
|
20
|
+
const react_1 = __importDefault(require("react"));
|
|
21
|
+
const AzureProvider_js_1 = require("../providers/AzureProvider.js");
|
|
22
|
+
/**
|
|
23
|
+
* Hook to gets or creates a DDS that corresponds to a given uniqueKey string.
|
|
24
|
+
*
|
|
25
|
+
* @remarks
|
|
26
|
+
* This hook can only be used in a child component of `<LiveShareProvider>` or `<AzureProvider>`.
|
|
27
|
+
*
|
|
28
|
+
* @template T Type of Fluid SharedObjectKind type to load. Must conform to IFluidLoadable interface.
|
|
29
|
+
* @param uniqueKey uniqueKey value for the data object
|
|
30
|
+
* @param objectKind Fluid SharedObjectKind<T> to create/load.
|
|
31
|
+
* @param onFirstInitialize Optional. Callback function for when the DDS is first loaded
|
|
32
|
+
* @returns the DDS object, which is of type T when loaded and undefined while loading
|
|
33
|
+
*/
|
|
34
|
+
function useDynamicDDS(uniqueKey, objectClass, onFirstInitialize) {
|
|
35
|
+
const [dds, setDDS] = react_1.default.useState();
|
|
36
|
+
const [error, setError] = react_1.default.useState();
|
|
37
|
+
/**
|
|
38
|
+
* Import container and DDS object register callbacks from AzureProvider.
|
|
39
|
+
*/
|
|
40
|
+
const { container, clientRef } = (0, AzureProvider_js_1.useFluidObjectsContext)();
|
|
41
|
+
const mountedRef = react_1.default.useRef(false);
|
|
42
|
+
react_1.default.useEffect(() => {
|
|
43
|
+
mountedRef.current = true;
|
|
44
|
+
return () => {
|
|
45
|
+
mountedRef.current = false;
|
|
46
|
+
};
|
|
47
|
+
}, []);
|
|
48
|
+
const getDDSPromisesRef = react_1.default.useRef(new Map());
|
|
49
|
+
/**
|
|
50
|
+
* Once container is available, this effect will register the setter method so that the DDS loaded
|
|
51
|
+
* from `dynamicObjects` that matches `uniqueKey` can be passed back to this hook. If one does not yet exist,
|
|
52
|
+
* a new DDS is automatically created. If multiple users try to create a DDS at the same time when this component first
|
|
53
|
+
* mounts, `live-share` ensures it will ultimately self correct using last-writer wins.
|
|
54
|
+
*/
|
|
55
|
+
react_1.default.useEffect(() => {
|
|
56
|
+
if (container === undefined)
|
|
57
|
+
return;
|
|
58
|
+
// Callback method to set the `initialData` into the map when the DDS is first created.
|
|
59
|
+
const onGetDDS = () => __awaiter(this, void 0, void 0, function* () {
|
|
60
|
+
try {
|
|
61
|
+
let getPromise = getDDSPromisesRef.current.get(uniqueKey);
|
|
62
|
+
if (!getPromise) {
|
|
63
|
+
getPromise = clientRef.current.getDDS(uniqueKey, objectClass, onFirstInitialize);
|
|
64
|
+
getDDSPromisesRef.current.set(uniqueKey, getPromise);
|
|
65
|
+
}
|
|
66
|
+
const dds = yield getPromise;
|
|
67
|
+
if (mountedRef.current) {
|
|
68
|
+
setDDS(dds);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
catch (error) {
|
|
72
|
+
if (error instanceof Error) {
|
|
73
|
+
setError(error);
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
setError(new Error("useDynamicDDS: an unknown error occurred while getting the DDS"));
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
onGetDDS();
|
|
81
|
+
}, [container, uniqueKey, onFirstInitialize]);
|
|
82
|
+
return {
|
|
83
|
+
dds,
|
|
84
|
+
error,
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
//# sourceMappingURL=useDynamicDDS.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useDynamicDDS.js","sourceRoot":"","sources":["../../../src/shared-hooks/useDynamicDDS.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;;;;;;;;;;AAmBH,sCAsEC;AAvFD,kDAA0B;AAE1B,oEAAuE;AAGvE;;;;;;;;;;;GAWG;AACH,SAAgB,aAAa,CAGzB,SAAiB,EACjB,WAAgC,EAChC,iBAAoC;IAKpC,MAAM,CAAC,GAAG,EAAE,MAAM,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AAK,YAAY,KAAK,EAAE,CAAC;oBACzB,QAAQ,CAAC,KAAK,CAAC,CAAC;gBACpB,CAAC;qBAAM,CAAC;oBACJ,QAAQ,CACJ,IAAI,KAAK,CACL,gEAAgE,CACnE,CACJ,CAAC;gBACN,CAAC;YACL,CAAC;QACL,CAAC,CAAA,CAAC;QACF,QAAQ,EAAE,CAAC;IACf,CAAC,EAAE,CAAC,SAAS,EAAE,SAAS,EAAE,iBAAiB,CAAC,CAAC,CAAC;IAE9C,OAAO;QACH,GAAG;QACH,KAAK;KACR,CAAC;AACN,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
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/index.js";
|
|
6
|
+
/**
|
|
7
|
+
* @deprecated use {@link useSharedTree} instead.
|
|
8
|
+
*
|
|
9
|
+
* React hook for using a Fluid `SharedMap`.
|
|
10
|
+
*
|
|
11
|
+
* @remarks
|
|
12
|
+
* The primary benefit of using the `useSharedMap` hook rather than the Fluid `SharedMap`
|
|
13
|
+
* directly is that it integrates nicely with React state and automates repetitive tasks.
|
|
14
|
+
* If you want to use `SharedMap` this hook creates directly, you can do that as well.
|
|
15
|
+
* This hook can only be used in a child component of `<LiveShareProvider>` or `<AzureProvider>`.
|
|
16
|
+
*
|
|
17
|
+
* @template TData Optional typing for objects stored in the SharedMap. Default is `any` 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 the Fluid `sharedMap`.
|
|
23
|
+
*/
|
|
24
|
+
export declare function useSharedMap<TData = any>(uniqueKey: string, initialData?: SharedMapInitialData<TData>): IUseSharedMapResults<TData>;
|
|
25
|
+
//# 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,mBAAmB,CAAC;AAU/E;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,YAAY,CAAC,KAAK,GAAG,GAAG,EACpC,SAAS,EAAE,MAAM,EACjB,WAAW,CAAC,EAAE,oBAAoB,CAAC,KAAK,CAAC,GAC1C,oBAAoB,CAAC,KAAK,CAAC,CAyH7B"}
|
|
@@ -0,0 +1,134 @@
|
|
|
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.useSharedMap = useSharedMap;
|
|
11
|
+
const react_1 = __importDefault(require("react"));
|
|
12
|
+
const index_js_1 = require("../utils/index.js");
|
|
13
|
+
const useDynamicDDS_js_1 = require("./useDynamicDDS.js");
|
|
14
|
+
const legacy_1 = require("fluid-framework/legacy");
|
|
15
|
+
const errors_js_1 = require("../internal/errors.js");
|
|
16
|
+
const AzureProvider_js_1 = require("../providers/AzureProvider.js");
|
|
17
|
+
/**
|
|
18
|
+
* @deprecated use {@link useSharedTree} instead.
|
|
19
|
+
*
|
|
20
|
+
* React hook for using a Fluid `SharedMap`.
|
|
21
|
+
*
|
|
22
|
+
* @remarks
|
|
23
|
+
* The primary benefit of using the `useSharedMap` hook rather than the Fluid `SharedMap`
|
|
24
|
+
* directly is that it integrates nicely with React state and automates repetitive tasks.
|
|
25
|
+
* If you want to use `SharedMap` this hook creates directly, you can do that as well.
|
|
26
|
+
* This hook can only be used in a child component of `<LiveShareProvider>` or `<AzureProvider>`.
|
|
27
|
+
*
|
|
28
|
+
* @template TData Optional typing for objects stored in the SharedMap. Default is `any` type.
|
|
29
|
+
* @param uniqueKey the unique key for the `SharedMap`. If one does not yet exist, a new `SharedMap`
|
|
30
|
+
* will be created, otherwise it will use the existing one.
|
|
31
|
+
* @param initialData a JS Map, entries array, or JSON object to insert into the `SharedMap` when creating
|
|
32
|
+
* the DDS for the first time.
|
|
33
|
+
* @returns the Fluid `sharedMap`.
|
|
34
|
+
*/
|
|
35
|
+
function useSharedMap(uniqueKey, initialData) {
|
|
36
|
+
const onFirstInitialize = react_1.default.useCallback((newDDS) => {
|
|
37
|
+
/**
|
|
38
|
+
* Callback method to set the `initialData` into the map when the `SharedMap` is first created.
|
|
39
|
+
* Only should be used as a prop to useDynamicDDS.
|
|
40
|
+
*/
|
|
41
|
+
getInitialData(initialData).forEach((value, key) => {
|
|
42
|
+
newDDS.set(key, value);
|
|
43
|
+
});
|
|
44
|
+
}, [initialData]);
|
|
45
|
+
/**
|
|
46
|
+
* User facing: dynamically load the SharedMap DDS for the given unique key.
|
|
47
|
+
*/
|
|
48
|
+
const { dds: sharedMap } = (0, useDynamicDDS_js_1.useDynamicDDS)(uniqueKey, legacy_1.SharedMap, onFirstInitialize);
|
|
49
|
+
const { container } = (0, AzureProvider_js_1.useFluidObjectsContext)();
|
|
50
|
+
/**
|
|
51
|
+
* User facing: get a value from the Fluid `SharedMap`.
|
|
52
|
+
*/
|
|
53
|
+
const getEntry = react_1.default.useCallback((key) => {
|
|
54
|
+
if (!container) {
|
|
55
|
+
throw new errors_js_1.ActionContainerNotJoinedError("sharedMap", "getEntry");
|
|
56
|
+
}
|
|
57
|
+
if (sharedMap === undefined) {
|
|
58
|
+
throw new errors_js_1.ActionLiveDataObjectUndefinedError("sharedMap", "getEntry");
|
|
59
|
+
}
|
|
60
|
+
return sharedMap.get(key);
|
|
61
|
+
}, [container, sharedMap]);
|
|
62
|
+
/**
|
|
63
|
+
* User facing: set a value to the Fluid `SharedMap`.
|
|
64
|
+
*/
|
|
65
|
+
const setEntry = react_1.default.useCallback((key, value) => {
|
|
66
|
+
if (!container) {
|
|
67
|
+
throw new errors_js_1.ActionContainerNotJoinedError("sharedMap", "setEntry");
|
|
68
|
+
}
|
|
69
|
+
if (sharedMap === undefined) {
|
|
70
|
+
throw new errors_js_1.ActionLiveDataObjectUndefinedError("sharedMap", "setEntry");
|
|
71
|
+
}
|
|
72
|
+
sharedMap.set(key, value);
|
|
73
|
+
}, [container, sharedMap]);
|
|
74
|
+
/**
|
|
75
|
+
* User facing: delete a value from the Fluid `SharedMap`.
|
|
76
|
+
*/
|
|
77
|
+
const deleteEntry = react_1.default.useCallback((key) => {
|
|
78
|
+
if (!container) {
|
|
79
|
+
throw new errors_js_1.ActionContainerNotJoinedError("sharedMap", "deleteEntry");
|
|
80
|
+
}
|
|
81
|
+
if (sharedMap === undefined) {
|
|
82
|
+
throw new errors_js_1.ActionLiveDataObjectUndefinedError("sharedMap", "deleteEntry");
|
|
83
|
+
}
|
|
84
|
+
sharedMap.delete(key);
|
|
85
|
+
}, [container, sharedMap]);
|
|
86
|
+
const [sharedMapProxy, setSharedMapProxy] = react_1.default.useState();
|
|
87
|
+
// Setup change listeners, initial values, etc.
|
|
88
|
+
react_1.default.useEffect(() => {
|
|
89
|
+
if (!sharedMap)
|
|
90
|
+
return;
|
|
91
|
+
setSharedMapProxy(sharedMap);
|
|
92
|
+
class SharedMapProxyHandler {
|
|
93
|
+
}
|
|
94
|
+
// Register valueChanged listener for `SharedMap`.
|
|
95
|
+
const onValueChanged = () => {
|
|
96
|
+
setSharedMapProxy(new Proxy(sharedMap, new SharedMapProxyHandler()));
|
|
97
|
+
};
|
|
98
|
+
sharedMap.on("valueChanged", onValueChanged);
|
|
99
|
+
// Get initial values from `SharedMap`.
|
|
100
|
+
onValueChanged();
|
|
101
|
+
return () => {
|
|
102
|
+
// Cleanup on component unmount.
|
|
103
|
+
sharedMap === null || sharedMap === void 0 ? void 0 : sharedMap.off("valueChanged", onValueChanged);
|
|
104
|
+
};
|
|
105
|
+
}, [sharedMap]);
|
|
106
|
+
return {
|
|
107
|
+
sharedMap: sharedMapProxy,
|
|
108
|
+
getEntry,
|
|
109
|
+
setEntry,
|
|
110
|
+
deleteEntry,
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Helper method for converting different initial data props into a Map<string, TData> to insert into the Fluid SharedMap
|
|
115
|
+
* @template TData Optional typing for objects stored in the SharedMap. Default is `object` type.
|
|
116
|
+
* @param initialData a JS Map, entries array, or JSON object.
|
|
117
|
+
* @returns A Map<string, TData> with the entries provided.
|
|
118
|
+
*/
|
|
119
|
+
function getInitialData(initialData) {
|
|
120
|
+
if ((0, index_js_1.isMap)(initialData)) {
|
|
121
|
+
return initialData;
|
|
122
|
+
}
|
|
123
|
+
else if ((0, index_js_1.isEntries)(initialData)) {
|
|
124
|
+
return new Map(initialData);
|
|
125
|
+
}
|
|
126
|
+
else if ((0, index_js_1.isJSON)(initialData)) {
|
|
127
|
+
const values = Object.keys(initialData).map((key) => {
|
|
128
|
+
return [key, initialData[key]];
|
|
129
|
+
});
|
|
130
|
+
return new Map(values);
|
|
131
|
+
}
|
|
132
|
+
return new Map();
|
|
133
|
+
}
|
|
134
|
+
//# sourceMappingURL=useSharedMap.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useSharedMap.js","sourceRoot":"","sources":["../../../src/shared-hooks/useSharedMap.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;AAgCH,oCA4HC;AA1JD,kDAA0B;AAC1B,gDAA6D;AAE7D,yDAAmD;AACnD,mDAAmD;AACnD,qDAG+B;AAC/B,oEAAuE;AAGvE;;;;;;;;;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IACN,CAAC,EAAE,CAAC,SAAS,CAAC,CAAC,CAAC;IAEhB,OAAO;QACH,SAAS,EAAE,cAAc;QACzB,QAAQ;QACR,QAAQ;QACR,WAAW;KACd,CAAC;AACN,CAAC;AAED;;;;;GAKG;AACH,SAAS,cAAc,CACnB,WAAwC;IAExC,IAAI,IAAA,gBAAK,EAAC,WAAW,CAAC,EAAE,CAAC;QACrB,OAAO,WAAW,CAAC;IACvB,CAAC;SAAM,IAAI,IAAA,oBAAS,EAAC,WAAW,CAAC,EAAE,CAAC;QAChC,OAAO,IAAI,GAAG,CAAgB,WAAW,CAAC,CAAC;IAC/C,CAAC;SAAM,IAAI,IAAA,iBAAM,EAAC,WAAW,CAAC,EAAE,CAAC;QAC7B,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;IAC1C,CAAC;IACD,OAAO,IAAI,GAAG,EAAiB,CAAC;AACpC,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 { DisposeSharedStateAction, SetSharedStateAction } from "../types/index.js";
|
|
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
|
+
* This hook can only be used in a child component of `<LiveShareProvider>` or `<AzureProvider>`.
|
|
14
|
+
*
|
|
15
|
+
* @template S Typing for objects stored associated with the `uniqueKey`.
|
|
16
|
+
* @param uniqueKey the unique key for a `SharedMap`. If you use the same key for multiple components, those components will reference the same state.
|
|
17
|
+
* @param initialState a default state for the `SharedMap`.
|
|
18
|
+
*
|
|
19
|
+
* @returns a stateful value, the function to update it, and an optional dispose method to delete it from the `SharedMap`.
|
|
20
|
+
*/
|
|
21
|
+
export declare function useSharedState<S = any>(uniqueKey: string, initialState: S): [S, SetSharedStateAction<S>, DisposeSharedStateAction];
|
|
22
|
+
//# 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,EACH,wBAAwB,EACxB,oBAAoB,EACvB,MAAM,mBAAmB,CAAC;AAI3B;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,cAAc,CAAC,CAAC,GAAG,GAAG,EAClC,SAAS,EAAE,MAAM,EACjB,YAAY,EAAE,CAAC,GAChB,CAAC,CAAC,EAAE,oBAAoB,CAAC,CAAC,CAAC,EAAE,wBAAwB,CAAC,CAkExD"}
|
|
@@ -0,0 +1,80 @@
|
|
|
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.useSharedState = useSharedState;
|
|
11
|
+
const react_1 = __importDefault(require("react"));
|
|
12
|
+
const index_js_1 = require("../providers/index.js");
|
|
13
|
+
const uuid_1 = require("uuid");
|
|
14
|
+
const index_js_2 = require("../internal/index.js");
|
|
15
|
+
/**
|
|
16
|
+
* Inspired by React's `useState` hook, `useSharedState` makes it easy to synchronize state in your app.
|
|
17
|
+
*
|
|
18
|
+
* @remarks
|
|
19
|
+
* Values set through this state is automatically attached to a `SharedMap` that the `AzureProvider`
|
|
20
|
+
* creates. If you are synchronizing complex data structures that multiple users will be setting simultaneously,
|
|
21
|
+
* consider using an optimized hook for your data structure (e.g., `useSharedMap`, `useSharedString`, etc.).
|
|
22
|
+
* This hook can only be used in a child component of `<LiveShareProvider>` or `<AzureProvider>`.
|
|
23
|
+
*
|
|
24
|
+
* @template S Typing for objects stored associated with the `uniqueKey`.
|
|
25
|
+
* @param uniqueKey the unique key for a `SharedMap`. If you use the same key for multiple components, those components will reference the same state.
|
|
26
|
+
* @param initialState a default state for the `SharedMap`.
|
|
27
|
+
*
|
|
28
|
+
* @returns a stateful value, the function to update it, and an optional dispose method to delete it from the `SharedMap`.
|
|
29
|
+
*/
|
|
30
|
+
function useSharedState(uniqueKey, initialState) {
|
|
31
|
+
/**
|
|
32
|
+
* User facing: stateful value and non-user facing setter.
|
|
33
|
+
*/
|
|
34
|
+
const [localState, setLocalState] = react_1.default.useState(initialState);
|
|
35
|
+
/**
|
|
36
|
+
* Unique ID reference for the component.
|
|
37
|
+
*/
|
|
38
|
+
const componentIdRef = react_1.default.useRef((0, uuid_1.v4)());
|
|
39
|
+
/**
|
|
40
|
+
* Register set state callbacks from AzureProvider and update/delete callbacks for initial object's `stateMap`.
|
|
41
|
+
*/
|
|
42
|
+
const { registerSharedSetStateAction, unregisterSharedSetStateAction, updateSharedState, deleteSharedState, } = (0, index_js_1.useFluidObjectsContext)();
|
|
43
|
+
/**
|
|
44
|
+
* User facing: callback to change the shared state.
|
|
45
|
+
*/
|
|
46
|
+
const setSharedState = react_1.default.useCallback((state) => {
|
|
47
|
+
setLocalState((prevState) => {
|
|
48
|
+
const valueToSet = (0, index_js_2.isPrevStateCallback)(state)
|
|
49
|
+
? state(prevState)
|
|
50
|
+
: state;
|
|
51
|
+
updateSharedState(uniqueKey, valueToSet);
|
|
52
|
+
return valueToSet;
|
|
53
|
+
});
|
|
54
|
+
}, [uniqueKey, setLocalState, updateSharedState]);
|
|
55
|
+
/**
|
|
56
|
+
* User facing: callback to dispose the shared state from the `stateMap`.
|
|
57
|
+
*/
|
|
58
|
+
const disposeSharedState = react_1.default.useCallback(() => {
|
|
59
|
+
deleteSharedState(uniqueKey);
|
|
60
|
+
}, [uniqueKey, deleteSharedState]);
|
|
61
|
+
/**
|
|
62
|
+
* Once container is available, this effect will register the setter method so that the `S` value
|
|
63
|
+
* from `stateMap` that matches `uniqueKey` can be passed back to this hook whenever changed.
|
|
64
|
+
*
|
|
65
|
+
* @see registerSharedSetStateAction to see how new values from `stateMap` are passed to this hook.
|
|
66
|
+
* @see unregisterSharedSetStateAction to see how this component stops listening to changes in the `stateMap`.
|
|
67
|
+
*/
|
|
68
|
+
react_1.default.useEffect(() => {
|
|
69
|
+
registerSharedSetStateAction(uniqueKey, componentIdRef.current, setLocalState);
|
|
70
|
+
return () => {
|
|
71
|
+
unregisterSharedSetStateAction(uniqueKey, componentIdRef.current);
|
|
72
|
+
};
|
|
73
|
+
}, [
|
|
74
|
+
uniqueKey,
|
|
75
|
+
registerSharedSetStateAction,
|
|
76
|
+
unregisterSharedSetStateAction,
|
|
77
|
+
]);
|
|
78
|
+
return [localState, setSharedState, disposeSharedState];
|
|
79
|
+
}
|
|
80
|
+
//# sourceMappingURL=useSharedState.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useSharedState.js","sourceRoot":"","sources":["../../../src/shared-hooks/useSharedState.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;AA0BH,wCAqEC;AA7FD,kDAA0B;AAC1B,oDAA+D;AAK/D,+BAAkC;AAClC,mDAA2D;AAE3D;;;;;;;;;;;;;;GAcG;AACH,SAAgB,cAAc,CAC1B,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AA8B;KACjC,CAAC,CAAC;IAEH,OAAO,CAAC,UAAU,EAAE,cAAc,EAAE,kBAAkB,CAAC,CAAC;AAC5D,CAAC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
* Licensed under the Microsoft Live Share SDK License.
|
|
4
|
+
*/
|
|
5
|
+
import { DeleteSharedStateAction, IAzureContainerResults, RegisterSharedSetStateAction, UnregisterSharedSetStateAction, UpdateSharedStateAction } from "../types/index.js";
|
|
6
|
+
/**
|
|
7
|
+
* Response for the {@link useSharedStateRegistry} hook.
|
|
8
|
+
*/
|
|
9
|
+
export interface ISharedStateRegistryResponse {
|
|
10
|
+
/**
|
|
11
|
+
* Register a set state action callback
|
|
12
|
+
*/
|
|
13
|
+
registerSharedSetStateAction: RegisterSharedSetStateAction;
|
|
14
|
+
/**
|
|
15
|
+
* Unregister a set state action callback
|
|
16
|
+
*/
|
|
17
|
+
unregisterSharedSetStateAction: UnregisterSharedSetStateAction;
|
|
18
|
+
/**
|
|
19
|
+
* Setter callback to update the shared state
|
|
20
|
+
*/
|
|
21
|
+
updateSharedState: UpdateSharedStateAction;
|
|
22
|
+
/**
|
|
23
|
+
* Delete a shared state value
|
|
24
|
+
*/
|
|
25
|
+
deleteSharedState: DeleteSharedStateAction;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* 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.
|
|
29
|
+
*
|
|
30
|
+
* @remarks
|
|
31
|
+
* Use this if you are building a custom `LiveShareProvider` or `AzureProvider` implementation in your app.
|
|
32
|
+
*
|
|
33
|
+
* @param results IAzureContainerResults response or undefined
|
|
34
|
+
* @returns ISharedStateRegistryResponse object
|
|
35
|
+
*/
|
|
36
|
+
export declare const useSharedStateRegistry: (results: IAzureContainerResults | undefined) => ISharedStateRegistryResponse;
|
|
37
|
+
//# sourceMappingURL=useSharedStateRegistry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useSharedStateRegistry.d.ts","sourceRoot":"","sources":["../../../src/shared-hooks/useSharedStateRegistry.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAQH,OAAO,EACH,uBAAuB,EACvB,sBAAsB,EACtB,4BAA4B,EAE5B,8BAA8B,EAC9B,uBAAuB,EAC1B,MAAM,mBAAmB,CAAC;AAQ3B;;GAEG;AACH,MAAM,WAAW,4BAA4B;IACzC;;OAEG;IACH,4BAA4B,EAAE,4BAA4B,CAAC;IAC3D;;OAEG;IACH,8BAA8B,EAAE,8BAA8B,CAAC;IAC/D;;OAEG;IACH,iBAAiB,EAAE,uBAAuB,CAAC;IAC3C;;OAEG;IACH,iBAAiB,EAAE,uBAAuB,CAAC;CAC9C;AAED;;;;;;;;GAQG;AACH,eAAO,MAAM,sBAAsB,YACtB,sBAAsB,GAAG,SAAS,KAC5C,4BAgHF,CAAC"}
|