@microsoft/live-share-react 2.0.0-internal.1 → 2.0.0-internal.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +64 -61
- package/README.md +173 -168
- 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.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.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/{internal → cjs/internal}/type-guards.d.ts +1 -1
- 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/{live-hooks → cjs/live-hooks}/useLiveEvent.d.ts +37 -1
- 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/{live-hooks → cjs/live-hooks}/useLiveState.d.ts +46 -1
- 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/{live-hooks → cjs/live-hooks}/useLiveTimer.d.ts +56 -1
- 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/{providers → cjs/providers}/AzureProvider.d.ts +9 -9
- 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/{providers → cjs/providers}/LiveShareProvider.d.ts +106 -4
- 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/{shared-hooks → cjs/shared-hooks}/useDynamicDDS.d.ts +4 -4
- 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/{shared-hooks → cjs/shared-hooks}/useSharedMap.d.ts +4 -2
- 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/{shared-hooks → cjs/shared-hooks}/useSharedState.d.ts +1 -1
- 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/{shared-hooks → cjs/shared-hooks}/useSharedStateRegistry.d.ts +1 -1
- 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/{types → cjs/types}/ActionTypes.d.ts +7 -7
- 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/{types → cjs/types}/ResultTypes.d.ts +50 -18
- 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.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.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.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.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/{live-hooks → esm/live-hooks}/useLiveEvent.js +41 -5
- 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/{live-hooks → esm/live-hooks}/useLiveFollowMode.js +148 -5
- 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/{live-hooks → esm/live-hooks}/useLivePresence.js +71 -13
- 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/{live-hooks → esm/live-hooks}/useLiveState.js +54 -5
- 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/{live-hooks → esm/live-hooks}/useLiveTimer.js +58 -3
- 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/{live-hooks → esm/live-hooks}/useMediaSynchronizer.js +66 -5
- 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/{providers → esm/providers}/AzureProvider.js +10 -10
- 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/{providers → esm/providers}/LiveShareProvider.js +111 -9
- 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/{shared-hooks → esm/shared-hooks}/useDynamicDDS.js +20 -11
- 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/{shared-hooks → esm/shared-hooks}/useSharedMap.js +27 -13
- 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/{shared-hooks → esm/shared-hooks}/useSharedState.js +2 -2
- 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/{shared-hooks → esm/shared-hooks}/useSharedStateRegistry.js +27 -19
- 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.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.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.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.map +1 -0
- package/package.json +61 -47
- package/src/index.ts +6 -6
- package/src/interfaces/index.ts +1 -1
- package/src/internal/index.ts +2 -2
- package/src/internal/type-guards.ts +1 -1
- package/src/live-hooks/index.ts +7 -7
- package/src/live-hooks/useLiveCanvas.ts +154 -82
- package/src/live-hooks/useLiveEvent.ts +43 -7
- package/src/live-hooks/useLiveFollowMode.ts +149 -6
- package/src/live-hooks/useLivePresence.ts +80 -17
- package/src/live-hooks/useLiveState.ts +54 -6
- package/src/live-hooks/useLiveTimer.ts +59 -4
- package/src/live-hooks/useMediaSynchronizer.ts +71 -6
- package/src/providers/AzureProvider.tsx +21 -21
- package/src/providers/LiveShareProvider.tsx +115 -13
- package/src/providers/index.ts +2 -2
- package/src/shared-hooks/index.ts +6 -4
- package/src/shared-hooks/internals/tree-node-constants.ts +2 -0
- package/src/shared-hooks/internals/tree-node-types.ts +26 -0
- package/src/shared-hooks/internals/tree-node-utils.ts +269 -0
- package/src/shared-hooks/useDynamicDDS.ts +28 -17
- package/src/shared-hooks/useSharedMap.ts +42 -17
- package/src/shared-hooks/useSharedState.ts +6 -3
- package/src/shared-hooks/useSharedStateRegistry.ts +44 -22
- package/src/shared-hooks/useSharedTree.ts +144 -0
- package/src/shared-hooks/useTreeNode.ts +147 -0
- package/src/types/ActionTypes.ts +13 -9
- package/src/types/PropTypes.ts +57 -0
- package/src/types/ResultTypes.ts +71 -17
- package/src/types/index.ts +3 -3
- package/src/utils/index.ts +1 -1
- package/tsconfig.cjs.json +14 -0
- package/tsconfig.json +65 -70
- package/.nycrc.json +0 -10
- 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.map +0 -1
- 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.map +0 -1
- 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.map +0 -1
- 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.map +0 -1
- 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.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.map +0 -1
- package/bin/live-hooks/useLiveState.d.ts.map +0 -1
- package/bin/live-hooks/useLiveState.js.map +0 -1
- package/bin/live-hooks/useLiveTimer.d.ts.map +0 -1
- 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.map +0 -1
- package/bin/providers/AzureProvider.d.ts.map +0 -1
- package/bin/providers/AzureProvider.js.map +0 -1
- package/bin/providers/LiveShareProvider.d.ts.map +0 -1
- 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.map +0 -1
- package/bin/shared-hooks/useDynamicDDS.js.map +0 -1
- package/bin/shared-hooks/useSharedMap.d.ts.map +0 -1
- package/bin/shared-hooks/useSharedMap.js.map +0 -1
- package/bin/shared-hooks/useSharedState.d.ts.map +0 -1
- package/bin/shared-hooks/useSharedState.js.map +0 -1
- package/bin/shared-hooks/useSharedStateRegistry.d.ts.map +0 -1
- package/bin/shared-hooks/useSharedStateRegistry.js.map +0 -1
- package/bin/types/ActionTypes.d.ts.map +0 -1
- 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.map +0 -1
- package/bin/types/ResultTypes.d.ts.map +0 -1
- 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.map +0 -1
- package/bin/utils/type-check.js.map +0 -1
- package/tsconfig.build.json +0 -6
- /package/bin/{interfaces → cjs/interfaces}/LiveInterfaceExtensions.d.ts +0 -0
- /package/bin/{internal → cjs/internal}/errors.d.ts +0 -0
- /package/bin/{utils → cjs/utils}/type-check.d.ts +0 -0
- /package/bin/{interfaces → esm/interfaces}/LiveInterfaceExtensions.js +0 -0
- /package/bin/{internal → esm/internal}/errors.js +0 -0
- /package/bin/{internal → esm/internal}/type-guards.js +0 -0
- /package/bin/{types → esm/types}/ActionTypes.js +0 -0
- /package/bin/{types → esm/types}/PropTypes.js +0 -0
- /package/bin/{types → esm/types}/ResultTypes.js +0 -0
- /package/bin/{utils → esm/utils}/type-check.js +0 -0
|
@@ -3,21 +3,19 @@
|
|
|
3
3
|
* Licensed under the Microsoft Live Share SDK License.
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
import {
|
|
6
|
+
import { ContainerSchema, IFluidContainer } from "fluid-framework";
|
|
7
7
|
import React from "react";
|
|
8
8
|
import {
|
|
9
9
|
AzureClientProps,
|
|
10
10
|
AzureContainerServices,
|
|
11
11
|
} from "@fluidframework/azure-client";
|
|
12
|
-
import { IAzureContainerResults } from "../types";
|
|
12
|
+
import { IAzureContainerResults } from "../types/index.js";
|
|
13
13
|
import {
|
|
14
14
|
ISharedStateRegistryResponse,
|
|
15
15
|
useSharedStateRegistry,
|
|
16
|
-
} from "../shared-hooks";
|
|
17
|
-
import {
|
|
18
|
-
|
|
19
|
-
IFluidTurboClient,
|
|
20
|
-
} from "@microsoft/live-share-turbo";
|
|
16
|
+
} from "../shared-hooks/index.js";
|
|
17
|
+
import { AzureLiveShareClient } from "@microsoft/live-share";
|
|
18
|
+
import { BaseLiveShareClient } from "@microsoft/live-share/internal";
|
|
21
19
|
|
|
22
20
|
/**
|
|
23
21
|
* React Context provider values for `<AzureProvider>` and `<LiveShareProvider>`.
|
|
@@ -29,7 +27,7 @@ export interface IFluidContext extends ISharedStateRegistryResponse {
|
|
|
29
27
|
/**
|
|
30
28
|
* The Fluid Turbo client used for connecting to the Fluid container.
|
|
31
29
|
*/
|
|
32
|
-
clientRef: React.MutableRefObject<
|
|
30
|
+
clientRef: React.MutableRefObject<BaseLiveShareClient>;
|
|
33
31
|
/**
|
|
34
32
|
* Stateful Fluid container.
|
|
35
33
|
*/
|
|
@@ -54,7 +52,7 @@ export interface IFluidContext extends ISharedStateRegistryResponse {
|
|
|
54
52
|
*/
|
|
55
53
|
getContainer: (
|
|
56
54
|
containerId: string,
|
|
57
|
-
|
|
55
|
+
fluidContainerSchema?: ContainerSchema
|
|
58
56
|
) => Promise<IAzureContainerResults>;
|
|
59
57
|
/**
|
|
60
58
|
* React callback function to create and connect to a new Fluid container.
|
|
@@ -67,7 +65,7 @@ export interface IFluidContext extends ISharedStateRegistryResponse {
|
|
|
67
65
|
* @returns promise that returns a results object once complete (e.g., container, services, etc.)
|
|
68
66
|
*/
|
|
69
67
|
createContainer: (
|
|
70
|
-
|
|
68
|
+
fluidContainerSchema?: ContainerSchema,
|
|
71
69
|
onInitializeContainer?: (container: IFluidContainer) => void
|
|
72
70
|
) => Promise<IAzureContainerResults>;
|
|
73
71
|
}
|
|
@@ -125,9 +123,9 @@ export interface IAzureProviderProps {
|
|
|
125
123
|
*/
|
|
126
124
|
createOnLoad?: boolean;
|
|
127
125
|
/**
|
|
128
|
-
* The initial
|
|
126
|
+
* The initial schema to use when {@link joinOnLoad} or {@link createOnLoad} is true.
|
|
129
127
|
*/
|
|
130
|
-
|
|
128
|
+
fluidContainerSchema?: ContainerSchema;
|
|
131
129
|
/**
|
|
132
130
|
* Flag to control whether or not to connect to an existing container on first mount.
|
|
133
131
|
*
|
|
@@ -142,8 +140,8 @@ export interface IAzureProviderProps {
|
|
|
142
140
|
*/
|
|
143
141
|
export const AzureProvider: React.FC<IAzureProviderProps> = (props) => {
|
|
144
142
|
const startedRef = React.useRef<boolean>(false);
|
|
145
|
-
const clientRef = React.useRef<
|
|
146
|
-
new
|
|
143
|
+
const clientRef = React.useRef<AzureLiveShareClient>(
|
|
144
|
+
new AzureLiveShareClient(props.clientOptions)
|
|
147
145
|
);
|
|
148
146
|
const [results, setResults] = React.useState<
|
|
149
147
|
IAzureContainerResults | undefined
|
|
@@ -158,14 +156,14 @@ export const AzureProvider: React.FC<IAzureProviderProps> = (props) => {
|
|
|
158
156
|
const getContainer = React.useCallback(
|
|
159
157
|
async (
|
|
160
158
|
containerId: string,
|
|
161
|
-
|
|
159
|
+
fluidContainerSchema?: ContainerSchema
|
|
162
160
|
): Promise<IAzureContainerResults> => {
|
|
163
161
|
return new Promise(async (resolve, reject) => {
|
|
164
162
|
try {
|
|
165
163
|
const results: IAzureContainerResults =
|
|
166
164
|
await clientRef.current.getContainer(
|
|
167
165
|
containerId,
|
|
168
|
-
|
|
166
|
+
fluidContainerSchema
|
|
169
167
|
);
|
|
170
168
|
setResults(results);
|
|
171
169
|
resolve(results);
|
|
@@ -185,13 +183,15 @@ export const AzureProvider: React.FC<IAzureProviderProps> = (props) => {
|
|
|
185
183
|
*/
|
|
186
184
|
const createContainer = React.useCallback(
|
|
187
185
|
async (
|
|
188
|
-
|
|
186
|
+
fluidContainerSchema?: ContainerSchema,
|
|
189
187
|
onInitializeContainer?: (container: IFluidContainer) => void
|
|
190
188
|
): Promise<IAzureContainerResults> => {
|
|
191
189
|
return new Promise(async (resolve, reject) => {
|
|
192
190
|
try {
|
|
193
191
|
const results: IAzureContainerResults =
|
|
194
|
-
await clientRef.current.createContainer(
|
|
192
|
+
await clientRef.current.createContainer(
|
|
193
|
+
fluidContainerSchema
|
|
194
|
+
);
|
|
195
195
|
if (onInitializeContainer) {
|
|
196
196
|
onInitializeContainer(results.container);
|
|
197
197
|
}
|
|
@@ -225,16 +225,16 @@ export const AzureProvider: React.FC<IAzureProviderProps> = (props) => {
|
|
|
225
225
|
return;
|
|
226
226
|
startedRef.current = true;
|
|
227
227
|
if (props.containerId && props.joinOnLoad) {
|
|
228
|
-
getContainer(props.containerId, props.
|
|
228
|
+
getContainer(props.containerId, props.fluidContainerSchema);
|
|
229
229
|
} else if (!props.containerId && props.createOnLoad) {
|
|
230
|
-
createContainer(props.
|
|
230
|
+
createContainer(props.fluidContainerSchema);
|
|
231
231
|
}
|
|
232
232
|
}, [
|
|
233
233
|
results?.container?.connectionState,
|
|
234
234
|
props.containerId,
|
|
235
235
|
props.createOnLoad,
|
|
236
236
|
props.joinOnLoad,
|
|
237
|
-
props.
|
|
237
|
+
props.fluidContainerSchema,
|
|
238
238
|
getContainer,
|
|
239
239
|
createContainer,
|
|
240
240
|
]);
|
|
@@ -3,18 +3,18 @@
|
|
|
3
3
|
* Licensed under the Microsoft Live Share SDK License.
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
import {
|
|
6
|
+
import { ContainerSchema, IFluidContainer } from "fluid-framework";
|
|
7
7
|
import React from "react";
|
|
8
|
-
import { useSharedStateRegistry } from "../shared-hooks";
|
|
8
|
+
import { useSharedStateRegistry } from "../shared-hooks/index.js";
|
|
9
9
|
import {
|
|
10
10
|
ILiveShareClientOptions,
|
|
11
11
|
ILiveShareHost,
|
|
12
12
|
ILiveShareJoinResults,
|
|
13
13
|
ITimestampProvider,
|
|
14
|
+
LiveShareClient,
|
|
14
15
|
} from "@microsoft/live-share";
|
|
15
|
-
import { FluidContext, useFluidObjectsContext } from "./AzureProvider";
|
|
16
|
-
import {
|
|
17
|
-
import { isITeamsJsSdkError } from "../internal";
|
|
16
|
+
import { FluidContext, useFluidObjectsContext } from "./AzureProvider.js";
|
|
17
|
+
import { isITeamsJsSdkError } from "../internal/index.js";
|
|
18
18
|
|
|
19
19
|
/**
|
|
20
20
|
* React Context provider values for `<LiveShareProvider>`.
|
|
@@ -52,7 +52,7 @@ export interface ILiveShareContext {
|
|
|
52
52
|
* @returns Promise with `ILiveShareJoinResults`, which includes the Fluid container
|
|
53
53
|
*/
|
|
54
54
|
join: (
|
|
55
|
-
|
|
55
|
+
fluidContainerSchema?: ContainerSchema,
|
|
56
56
|
onInitializeContainer?: (container: IFluidContainer) => void
|
|
57
57
|
) => Promise<ILiveShareJoinResults>;
|
|
58
58
|
}
|
|
@@ -72,6 +72,57 @@ export const LiveShareContext = React.createContext<ILiveShareContext>(
|
|
|
72
72
|
* See `useFluidObjectsContext` for other information related to the Live Share session, such as the `container`.
|
|
73
73
|
*
|
|
74
74
|
* @returns current state of `LiveShareContext`
|
|
75
|
+
*
|
|
76
|
+
* @example
|
|
77
|
+
```jsx
|
|
78
|
+
// LiveShareApp.jsx
|
|
79
|
+
import { LiveShareProvider } from "@microsoft/live-share-react";
|
|
80
|
+
import { LiveShareHost } from "@microsoft/teams-js";
|
|
81
|
+
|
|
82
|
+
const host = LiveShareHost.create();
|
|
83
|
+
|
|
84
|
+
export function LiveShareApp() {
|
|
85
|
+
// Call app.initialize() from teams-js before rendering LiveShareProvider
|
|
86
|
+
|
|
87
|
+
return (
|
|
88
|
+
<LiveShareProvider
|
|
89
|
+
joinOnLoad={true}
|
|
90
|
+
host={host}
|
|
91
|
+
>
|
|
92
|
+
<LiveShareLoader>
|
|
93
|
+
<LiveCheckbox />
|
|
94
|
+
</LiveShareLoader>
|
|
95
|
+
</LiveShareProvider>
|
|
96
|
+
);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// LiveShareLoader.jsx
|
|
100
|
+
import { useLiveShareContext } from "@microsoft/live-share-react";
|
|
101
|
+
|
|
102
|
+
export function LiveShareLoader({ children }) {
|
|
103
|
+
const { joined, joinError } = useLiveShareContext();
|
|
104
|
+
|
|
105
|
+
if (joinError) return <>{joinError.message}</>;
|
|
106
|
+
if (!joined) return <>Joining Live Share session...</>;
|
|
107
|
+
return <>{children}</>
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
// LiveCheckbox.jsx
|
|
111
|
+
import { useLiveState } from "@microsoft/live-share-react";
|
|
112
|
+
|
|
113
|
+
export function LiveCheckbox() {
|
|
114
|
+
const [checked, setChecked] = useLiveState("MY-UNIQUE-ID", false);
|
|
115
|
+
return (
|
|
116
|
+
<input
|
|
117
|
+
type="checkbox"
|
|
118
|
+
checked={checked}
|
|
119
|
+
onChange={() => {
|
|
120
|
+
setChecked(!checked);
|
|
121
|
+
}}
|
|
122
|
+
/>
|
|
123
|
+
);
|
|
124
|
+
}
|
|
125
|
+
```
|
|
75
126
|
*/
|
|
76
127
|
export const useLiveShareContext = (): ILiveShareContext => {
|
|
77
128
|
const context = React.useContext(LiveShareContext);
|
|
@@ -103,9 +154,9 @@ export interface ILiveShareProviderProps {
|
|
|
103
154
|
*/
|
|
104
155
|
host: ILiveShareHost;
|
|
105
156
|
/**
|
|
106
|
-
* The
|
|
157
|
+
* The schema to use when {@link joinOnLoad} is true.
|
|
107
158
|
*/
|
|
108
|
-
|
|
159
|
+
fluidContainerSchema?: ContainerSchema;
|
|
109
160
|
/**
|
|
110
161
|
* Optional. Flag to determine whether to join Fluid container on load.
|
|
111
162
|
*/
|
|
@@ -114,11 +165,62 @@ export interface ILiveShareProviderProps {
|
|
|
114
165
|
|
|
115
166
|
/**
|
|
116
167
|
* React Context provider component for using Live Share data objects & joining a Live Share session using `LiveShareClient`.
|
|
168
|
+
*
|
|
169
|
+
* @example
|
|
170
|
+
```jsx
|
|
171
|
+
// LiveShareApp.jsx
|
|
172
|
+
import { LiveShareProvider } from "@microsoft/live-share-react";
|
|
173
|
+
import { LiveShareHost } from "@microsoft/teams-js";
|
|
174
|
+
|
|
175
|
+
const host = LiveShareHost.create();
|
|
176
|
+
|
|
177
|
+
export function LiveShareApp() {
|
|
178
|
+
// Call app.initialize() from teams-js before rendering LiveShareProvider
|
|
179
|
+
|
|
180
|
+
return (
|
|
181
|
+
<LiveShareProvider
|
|
182
|
+
joinOnLoad={true}
|
|
183
|
+
host={host}
|
|
184
|
+
>
|
|
185
|
+
<LiveShareLoader>
|
|
186
|
+
<LiveCheckbox />
|
|
187
|
+
</LiveShareLoader>
|
|
188
|
+
</LiveShareProvider>
|
|
189
|
+
);
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
// LiveShareLoader.jsx
|
|
193
|
+
import { useLiveShareContext } from "@microsoft/live-share-react";
|
|
194
|
+
|
|
195
|
+
export function LiveShareLoader({ children }) {
|
|
196
|
+
const { joined, joinError } = useLiveShareContext();
|
|
197
|
+
|
|
198
|
+
if (joinError) return <>{joinError.message}</>;
|
|
199
|
+
if (!joined) return <>Joining Live Share session...</>;
|
|
200
|
+
return <>{children}</>
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
// LiveCheckbox.jsx
|
|
204
|
+
import { useLiveState } from "@microsoft/live-share-react";
|
|
205
|
+
|
|
206
|
+
export function LiveCheckbox() {
|
|
207
|
+
const [checked, setChecked] = useLiveState("MY-UNIQUE-ID", false);
|
|
208
|
+
return (
|
|
209
|
+
<input
|
|
210
|
+
type="checkbox"
|
|
211
|
+
checked={checked}
|
|
212
|
+
onChange={() => {
|
|
213
|
+
setChecked(!checked);
|
|
214
|
+
}}
|
|
215
|
+
/>
|
|
216
|
+
);
|
|
217
|
+
}
|
|
218
|
+
```
|
|
117
219
|
*/
|
|
118
220
|
export const LiveShareProvider: React.FC<ILiveShareProviderProps> = (props) => {
|
|
119
221
|
const startedRef = React.useRef(false);
|
|
120
222
|
const clientRef = React.useRef(
|
|
121
|
-
new
|
|
223
|
+
new LiveShareClient(props.host, props.clientOptions)
|
|
122
224
|
);
|
|
123
225
|
const [results, setResults] = React.useState<
|
|
124
226
|
ILiveShareJoinResults | undefined
|
|
@@ -132,12 +234,12 @@ export const LiveShareProvider: React.FC<ILiveShareProviderProps> = (props) => {
|
|
|
132
234
|
*/
|
|
133
235
|
const join = React.useCallback(
|
|
134
236
|
async (
|
|
135
|
-
|
|
237
|
+
fluidContainerSchema?: ContainerSchema,
|
|
136
238
|
onInitializeContainer?: (container: IFluidContainer) => void
|
|
137
239
|
): Promise<ILiveShareJoinResults> => {
|
|
138
240
|
startedRef.current = true;
|
|
139
241
|
const results = await clientRef.current.join(
|
|
140
|
-
|
|
242
|
+
fluidContainerSchema,
|
|
141
243
|
onInitializeContainer
|
|
142
244
|
);
|
|
143
245
|
setResults(results);
|
|
@@ -155,7 +257,7 @@ export const LiveShareProvider: React.FC<ILiveShareProviderProps> = (props) => {
|
|
|
155
257
|
// We are not doing this here for backwards compatibility. View the README for more information.
|
|
156
258
|
if (results !== undefined || startedRef.current || !props.joinOnLoad)
|
|
157
259
|
return;
|
|
158
|
-
join(props.
|
|
260
|
+
join(props.fluidContainerSchema).catch((error) => {
|
|
159
261
|
console.error(error);
|
|
160
262
|
if (error instanceof Error) {
|
|
161
263
|
setJoinError(error);
|
|
@@ -178,7 +280,7 @@ export const LiveShareProvider: React.FC<ILiveShareProviderProps> = (props) => {
|
|
|
178
280
|
);
|
|
179
281
|
}
|
|
180
282
|
});
|
|
181
|
-
}, [results, props.joinOnLoad, props.
|
|
283
|
+
}, [results, props.joinOnLoad, props.fluidContainerSchema, join]);
|
|
182
284
|
|
|
183
285
|
return (
|
|
184
286
|
<LiveShareContext.Provider
|
package/src/providers/index.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from "./AzureProvider";
|
|
2
|
-
export * from "./LiveShareProvider";
|
|
1
|
+
export * from "./AzureProvider.js";
|
|
2
|
+
export * from "./LiveShareProvider.js";
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
export * from "./useSharedState";
|
|
2
|
-
export * from "./useSharedMap";
|
|
3
|
-
export * from "./useDynamicDDS";
|
|
4
|
-
export * from "./useSharedStateRegistry";
|
|
1
|
+
export * from "./useSharedState.js";
|
|
2
|
+
export * from "./useSharedMap.js";
|
|
3
|
+
export * from "./useDynamicDDS.js";
|
|
4
|
+
export * from "./useSharedStateRegistry.js";
|
|
5
|
+
export * from "./useSharedTree.js";
|
|
6
|
+
export * from "./useTreeNode.js";
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { TreeNode, Tree } from "fluid-framework";
|
|
2
|
+
import { proxiedChildrenKey, rawTNodeKey } from "./tree-node-constants.js";
|
|
3
|
+
|
|
4
|
+
export interface ICustomProxyHandler<TNode extends TreeNode = TreeNode> {
|
|
5
|
+
[rawTNodeKey]: TNode;
|
|
6
|
+
[proxiedChildrenKey]: Record<string, TreeNode>;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export function isProxy(value: any): value is typeof Proxy {
|
|
10
|
+
return value && value["[[Handler]]"];
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function isCustomProxyHandler<TNode extends TreeNode = TreeNode>(
|
|
14
|
+
value: any
|
|
15
|
+
): value is ICustomProxyHandler<TNode> {
|
|
16
|
+
return value?.[rawTNodeKey] !== undefined;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function isTreeNode(value: any): value is TreeNode {
|
|
20
|
+
try {
|
|
21
|
+
Tree.schema(value);
|
|
22
|
+
return true;
|
|
23
|
+
} catch (_) {
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
import { proxiedChildrenKey, rawTNodeKey } from "./tree-node-constants.js";
|
|
2
|
+
import {
|
|
3
|
+
ICustomProxyHandler,
|
|
4
|
+
isCustomProxyHandler,
|
|
5
|
+
isTreeNode,
|
|
6
|
+
isProxy,
|
|
7
|
+
} from "./tree-node-types.js";
|
|
8
|
+
import { TreeNode, Tree } from "fluid-framework";
|
|
9
|
+
import { Dispatch, SetStateAction } from "react";
|
|
10
|
+
|
|
11
|
+
// Exported utils
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* @internal
|
|
15
|
+
* Build a proxied version of a node and set its value to the treeMap provided
|
|
16
|
+
*
|
|
17
|
+
* @param rawNode the raw proxy node exposed by Fluid
|
|
18
|
+
* @param treeMap a map where Fluid's proxy node is mapped to our proxied node
|
|
19
|
+
* @returns TNode instance
|
|
20
|
+
*/
|
|
21
|
+
export function buildProxy<TNode extends TreeNode = TreeNode>(
|
|
22
|
+
rawNode: TNode,
|
|
23
|
+
treeMap: WeakMap<TreeNode, TreeNode>
|
|
24
|
+
): TNode {
|
|
25
|
+
const previousProxy = treeMap.get(rawNode);
|
|
26
|
+
const previousProxyHandler = previousProxy
|
|
27
|
+
? getCustomProxyHandler(previousProxy)
|
|
28
|
+
: undefined;
|
|
29
|
+
const proxyHandler: ProxyHandler<TreeNode> & ICustomProxyHandler<TNode> = {
|
|
30
|
+
// Add some extra stuff into the handler so we can store the original Fluid TreeNode and access it later
|
|
31
|
+
// Without overriding the rest of the getters in the object.
|
|
32
|
+
[rawTNodeKey]: rawNode,
|
|
33
|
+
[proxiedChildrenKey]: previousProxyHandler?.[proxiedChildrenKey] ?? {},
|
|
34
|
+
get: (target, prop, _) => {
|
|
35
|
+
if (prop === "[[Handler]]") {
|
|
36
|
+
return proxyHandler;
|
|
37
|
+
}
|
|
38
|
+
if (
|
|
39
|
+
typeof prop === "string" &&
|
|
40
|
+
proxyHandler[proxiedChildrenKey][prop]
|
|
41
|
+
) {
|
|
42
|
+
return proxyHandler[proxiedChildrenKey][prop];
|
|
43
|
+
}
|
|
44
|
+
// pass in the rawNode so Fluid doesn't get confused by our proxy object and can find the flex node
|
|
45
|
+
const value = Reflect.get(target, prop, rawNode);
|
|
46
|
+
return typeof value === "function" &&
|
|
47
|
+
typeof prop === "string" &&
|
|
48
|
+
// TODO: need a better way of identifying which types of functions need to be proxied
|
|
49
|
+
// This is because if a developer uses an array prototype function, we need to return proxied
|
|
50
|
+
// objects so React can detect changes to those nodes...
|
|
51
|
+
!["map", "flatMap", "filter", "find", "indexOf"].includes(prop)
|
|
52
|
+
? value.bind(rawNode)
|
|
53
|
+
: value;
|
|
54
|
+
},
|
|
55
|
+
set(target, p, newValue, _) {
|
|
56
|
+
return Reflect.set(target, p, newValue, rawNode);
|
|
57
|
+
},
|
|
58
|
+
};
|
|
59
|
+
const proxy = new Proxy(rawNode, proxyHandler);
|
|
60
|
+
// Track the proxy for the rawNode
|
|
61
|
+
treeMap.set(rawNode, proxy);
|
|
62
|
+
// Set raw node getter so we can access it before things like Tree.on
|
|
63
|
+
return proxy as TNode;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* @internal
|
|
68
|
+
* Set up listeners for a given TreeNode.
|
|
69
|
+
* Will recursively call this function for all children nodes of each children until there are no more child nodes.
|
|
70
|
+
*
|
|
71
|
+
* @param parentRawNode raw parent node
|
|
72
|
+
* @param rootNodeForListener root node being listened to in useTreeNode
|
|
73
|
+
* @param treeMap a map where Fluid's proxy node is mapped to our proxied node
|
|
74
|
+
* @param unsubscribeListeners list of unsubscribe listeners, where we set the unsubscribe callbacks
|
|
75
|
+
* @param setProxyNode setter to set the root proxy node listened to in useTreeNode
|
|
76
|
+
*/
|
|
77
|
+
export function setUpListenersForNodeChildren<
|
|
78
|
+
TNode extends TreeNode = TreeNode,
|
|
79
|
+
>(
|
|
80
|
+
parentRawNode: TreeNode,
|
|
81
|
+
rootNodeForListener: TreeNode,
|
|
82
|
+
treeMap: WeakMap<TreeNode, TreeNode>,
|
|
83
|
+
unsubscribeListeners: (() => void)[],
|
|
84
|
+
setProxyNode: Dispatch<SetStateAction<TNode>>
|
|
85
|
+
) {
|
|
86
|
+
let entries = Object.entries(parentRawNode);
|
|
87
|
+
for (let i = 0; i < entries.length; i++) {
|
|
88
|
+
const [key, entry] = entries[i];
|
|
89
|
+
if (
|
|
90
|
+
!entry ||
|
|
91
|
+
["string", "boolean", "number", "function"].includes(
|
|
92
|
+
typeof entry
|
|
93
|
+
) ||
|
|
94
|
+
!isTreeNode(entry)
|
|
95
|
+
) {
|
|
96
|
+
continue;
|
|
97
|
+
}
|
|
98
|
+
const rawEntry = getRawNode(entry);
|
|
99
|
+
const onNodeChanged = () => {
|
|
100
|
+
onTreeNodeChanged(
|
|
101
|
+
key,
|
|
102
|
+
rawEntry,
|
|
103
|
+
rootNodeForListener,
|
|
104
|
+
treeMap,
|
|
105
|
+
setProxyNode
|
|
106
|
+
);
|
|
107
|
+
};
|
|
108
|
+
const unsubscribe = Tree.on(rawEntry, "nodeChanged", onNodeChanged);
|
|
109
|
+
unsubscribeListeners.push(unsubscribe);
|
|
110
|
+
// Recursively listen to children nodes of this node
|
|
111
|
+
setUpListenersForNodeChildren(
|
|
112
|
+
rawEntry,
|
|
113
|
+
rootNodeForListener,
|
|
114
|
+
treeMap,
|
|
115
|
+
unsubscribeListeners,
|
|
116
|
+
setProxyNode
|
|
117
|
+
);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* @internal
|
|
123
|
+
* Fluid only knows how to work with their proxied version of a TreeNode.
|
|
124
|
+
* We store a reference to that node in our proxied instances so we can easily use it when working with Fluid APIs.
|
|
125
|
+
*
|
|
126
|
+
* @param node get the raw node from the proxy
|
|
127
|
+
* @returns the raw proxied node that Fluid expects
|
|
128
|
+
*/
|
|
129
|
+
export function getRawNode<TNode extends TreeNode | undefined = TreeNode>(
|
|
130
|
+
node: TNode
|
|
131
|
+
): TNode {
|
|
132
|
+
if (isProxy(node)) {
|
|
133
|
+
return getRawNodeFromProxy(node) as TNode;
|
|
134
|
+
}
|
|
135
|
+
return node;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
// Non public utils
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Callback for when a tree node changed
|
|
142
|
+
*
|
|
143
|
+
* @param key key where the object is stored in the parent
|
|
144
|
+
* @param rawNode the raw node that changed
|
|
145
|
+
* @param rootNodeForListener the root node that is being listened to in useTreeNode
|
|
146
|
+
* @param treeMap a map where Fluid's proxy node is mapped to our proxied node
|
|
147
|
+
* @param setProxyNode setter to set the root proxy node listened to in useTreeNode
|
|
148
|
+
*/
|
|
149
|
+
function onTreeNodeChanged<TNode extends TreeNode = TreeNode>(
|
|
150
|
+
key: string,
|
|
151
|
+
rawNode: TreeNode,
|
|
152
|
+
rootNodeForListener: TreeNode,
|
|
153
|
+
treeMap: WeakMap<TreeNode, TreeNode>,
|
|
154
|
+
setProxyNode: Dispatch<SetStateAction<TNode>>
|
|
155
|
+
) {
|
|
156
|
+
const proxyNode = buildProxy(rawNode, treeMap);
|
|
157
|
+
const parent = Tree.parent(rawNode);
|
|
158
|
+
if (!parent) {
|
|
159
|
+
throw new Error(
|
|
160
|
+
"useTreeNode onTreeNodeChanged: no parent found for rawParentNode"
|
|
161
|
+
);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
proxyParentForNode(
|
|
165
|
+
key,
|
|
166
|
+
parent,
|
|
167
|
+
proxyNode,
|
|
168
|
+
rootNodeForListener,
|
|
169
|
+
treeMap,
|
|
170
|
+
setProxyNode
|
|
171
|
+
);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* Proxies the parent and sets reference to the child node that changed.
|
|
176
|
+
*
|
|
177
|
+
* @param key key where the object is referenced in its parent node
|
|
178
|
+
* @param rawParentNode raw parent tree node
|
|
179
|
+
* @param proxyNode proxied instance of the node that changed
|
|
180
|
+
* @param rootNodeForListener root node listened to in useTreeNode
|
|
181
|
+
* @param treeMap a map where Fluid's proxy node is mapped to our proxied node
|
|
182
|
+
* @param setProxyNode setter to set the root proxy node listened to in useTreeNode
|
|
183
|
+
*/
|
|
184
|
+
function proxyParentForNode<TNode extends TreeNode = TreeNode>(
|
|
185
|
+
key: string,
|
|
186
|
+
rawParentNode: TreeNode,
|
|
187
|
+
proxyNode: TreeNode,
|
|
188
|
+
rootNodeForListener: TreeNode,
|
|
189
|
+
treeMap: WeakMap<TreeNode, TreeNode>,
|
|
190
|
+
setProxyNode: Dispatch<SetStateAction<TNode>>
|
|
191
|
+
) {
|
|
192
|
+
const parentProxy = buildProxy(rawParentNode, treeMap);
|
|
193
|
+
let parentProxyHandler = getCustomProxyHandler(parentProxy);
|
|
194
|
+
if (!parentProxyHandler) {
|
|
195
|
+
throw new Error(
|
|
196
|
+
"useTreeNode proxyParentForNode: unexpected error, should always find valid proxy handler"
|
|
197
|
+
);
|
|
198
|
+
}
|
|
199
|
+
parentProxyHandler[proxiedChildrenKey][key] = proxyNode;
|
|
200
|
+
if (rawParentNode === rootNodeForListener) {
|
|
201
|
+
setProxyNode(parentProxy as TNode);
|
|
202
|
+
} else {
|
|
203
|
+
const parentOfParent = Tree.parent(rawParentNode);
|
|
204
|
+
if (!parentOfParent) {
|
|
205
|
+
throw new Error(
|
|
206
|
+
"useTreeNode proxyParentForNode: no parent found for rawParentNode"
|
|
207
|
+
);
|
|
208
|
+
}
|
|
209
|
+
const parentKey = findKeyOfNode(rawParentNode, parentOfParent);
|
|
210
|
+
proxyParentForNode(
|
|
211
|
+
parentKey,
|
|
212
|
+
parentOfParent,
|
|
213
|
+
parentProxy,
|
|
214
|
+
rootNodeForListener,
|
|
215
|
+
treeMap,
|
|
216
|
+
setProxyNode
|
|
217
|
+
);
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* Returns key where parent[key] == nodeToCheck
|
|
223
|
+
*
|
|
224
|
+
* @param nodeToCheck tree node to check
|
|
225
|
+
* @param parent parent node where nodeToCheck is a child of
|
|
226
|
+
* @returns the key for node
|
|
227
|
+
*/
|
|
228
|
+
function findKeyOfNode(nodeToCheck: TreeNode, parent: TreeNode): string {
|
|
229
|
+
let entries = Object.entries(parent);
|
|
230
|
+
for (let i = 0; i < entries.length; i++) {
|
|
231
|
+
const [key, entry] = entries[i];
|
|
232
|
+
if (
|
|
233
|
+
!entry ||
|
|
234
|
+
["string", "boolean", "number", "function"].includes(
|
|
235
|
+
typeof entry
|
|
236
|
+
) ||
|
|
237
|
+
!isTreeNode(entry)
|
|
238
|
+
) {
|
|
239
|
+
continue;
|
|
240
|
+
}
|
|
241
|
+
if (entry === nodeToCheck) return key;
|
|
242
|
+
}
|
|
243
|
+
throw new Error("Did not find node as a child of parent");
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
// Type utils
|
|
247
|
+
|
|
248
|
+
/**
|
|
249
|
+
* Gets the proxy handler for a given TreeNode, assuming `isCustomProxyHandler` returns true.
|
|
250
|
+
* @param proxy the proxied TreeNode to get the handler for.
|
|
251
|
+
* @returns the handler if valid, otherwise undefined
|
|
252
|
+
*/
|
|
253
|
+
function getCustomProxyHandler(proxy: TreeNode) {
|
|
254
|
+
const handler = (proxy as any)["[[Handler]]"];
|
|
255
|
+
if (isCustomProxyHandler(handler)) {
|
|
256
|
+
return handler;
|
|
257
|
+
}
|
|
258
|
+
return undefined;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
/**
|
|
262
|
+
* Gets the raw node for a given proxied tree node
|
|
263
|
+
*
|
|
264
|
+
* @param proxy the proxied TreeNode to get the raw node for
|
|
265
|
+
* @returns the raw node if valid, otherwise undefined
|
|
266
|
+
*/
|
|
267
|
+
function getRawNodeFromProxy(proxy: TreeNode) {
|
|
268
|
+
return getCustomProxyHandler(proxy)?.[rawTNodeKey];
|
|
269
|
+
}
|