@fluidframework/react 0.41.3 → 2.62.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/.eslintrc.cjs +11 -0
- package/.mocharc.cjs +15 -0
- package/CHANGELOG.md +282 -0
- package/README.md +122 -273
- package/api-extractor/api-extractor-lint-alpha.cjs.json +5 -0
- package/api-extractor/api-extractor-lint-alpha.esm.json +5 -0
- package/api-extractor/api-extractor-lint-beta.cjs.json +5 -0
- package/api-extractor/api-extractor-lint-beta.esm.json +5 -0
- package/api-extractor/api-extractor-lint-bundle.json +5 -0
- package/api-extractor/api-extractor-lint-public.cjs.json +5 -0
- package/api-extractor/api-extractor-lint-public.esm.json +5 -0
- package/api-extractor-lint.json +4 -0
- package/api-extractor.json +2 -2
- package/api-report/react.alpha.api.md +114 -0
- package/api-report/react.beta.api.md +7 -0
- package/api-report/react.public.api.md +7 -0
- package/biome.jsonc +4 -0
- package/dist/alpha.d.ts +45 -0
- package/dist/beta.d.ts +15 -0
- package/dist/index.d.ts +11 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +19 -17
- package/dist/index.js.map +1 -1
- package/dist/package.json +4 -0
- package/dist/propNode.d.ts +114 -0
- package/dist/propNode.d.ts.map +1 -0
- package/dist/propNode.js +43 -0
- package/dist/propNode.js.map +1 -0
- package/dist/public.d.ts +15 -0
- package/dist/reactSharedTreeView.d.ts +119 -0
- package/dist/reactSharedTreeView.d.ts.map +1 -0
- package/dist/reactSharedTreeView.js +206 -0
- package/dist/reactSharedTreeView.js.map +1 -0
- package/dist/simpleIdentifier.d.ts +19 -0
- package/dist/simpleIdentifier.d.ts.map +1 -0
- package/dist/simpleIdentifier.js +33 -0
- package/dist/simpleIdentifier.js.map +1 -0
- package/dist/useObservation.d.ts +83 -0
- package/dist/useObservation.d.ts.map +1 -0
- package/dist/useObservation.js +295 -0
- package/dist/useObservation.js.map +1 -0
- package/dist/useTree.d.ts +80 -0
- package/dist/useTree.d.ts.map +1 -0
- package/dist/useTree.js +137 -0
- package/dist/useTree.js.map +1 -0
- package/lib/alpha.d.ts +45 -0
- package/lib/beta.d.ts +15 -0
- package/lib/index.d.ts +16 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +4 -7
- package/lib/index.js.map +1 -1
- package/lib/package.json +4 -0
- package/lib/propNode.d.ts +114 -0
- package/lib/propNode.d.ts.map +1 -0
- package/lib/propNode.js +36 -0
- package/lib/propNode.js.map +1 -0
- package/lib/public.d.ts +15 -0
- package/lib/reactSharedTreeView.d.ts +119 -0
- package/lib/reactSharedTreeView.d.ts.map +1 -0
- package/lib/reactSharedTreeView.js +176 -0
- package/lib/reactSharedTreeView.js.map +1 -0
- package/lib/simpleIdentifier.d.ts +19 -0
- package/lib/simpleIdentifier.d.ts.map +1 -0
- package/lib/simpleIdentifier.js +29 -0
- package/lib/simpleIdentifier.js.map +1 -0
- package/lib/test/propNode.spec.js +120 -0
- package/lib/test/propNode.spec.js.map +1 -0
- package/lib/test/reactSharedTreeView.spec.js +71 -0
- package/lib/test/reactSharedTreeView.spec.js.map +1 -0
- package/lib/test/simpleIdentifier.spec.js +18 -0
- package/lib/test/simpleIdentifier.spec.js.map +1 -0
- package/lib/test/useObservation.spec.js +162 -0
- package/lib/test/useObservation.spec.js.map +1 -0
- package/lib/test/useTree.spec.js +165 -0
- package/lib/test/useTree.spec.js.map +1 -0
- package/lib/tsdoc-metadata.json +11 -0
- package/lib/useObservation.d.ts +83 -0
- package/lib/useObservation.d.ts.map +1 -0
- package/lib/useObservation.js +266 -0
- package/lib/useObservation.js.map +1 -0
- package/lib/useTree.d.ts +80 -0
- package/lib/useTree.d.ts.map +1 -0
- package/lib/useTree.js +105 -0
- package/lib/useTree.js.map +1 -0
- package/package.json +150 -51
- package/react.test-files.tar +0 -0
- package/src/index.ts +42 -7
- package/src/propNode.ts +164 -0
- package/src/reactSharedTreeView.tsx +327 -0
- package/src/simpleIdentifier.ts +31 -0
- package/src/useObservation.ts +376 -0
- package/src/useTree.ts +147 -0
- package/tsconfig.cjs.json +7 -0
- package/tsconfig.json +12 -15
- package/tsdoc.json +4 -0
- package/.eslintrc.js +0 -11
- package/dist/createContextFluid.d.ts +0 -7
- package/dist/createContextFluid.d.ts.map +0 -1
- package/dist/createContextFluid.js +0 -46
- package/dist/createContextFluid.js.map +0 -1
- package/dist/helpers/generateFluidObjectSchema.d.ts +0 -16
- package/dist/helpers/generateFluidObjectSchema.d.ts.map +0 -1
- package/dist/helpers/generateFluidObjectSchema.js +0 -75
- package/dist/helpers/generateFluidObjectSchema.js.map +0 -1
- package/dist/helpers/getFluidFromView.d.ts +0 -15
- package/dist/helpers/getFluidFromView.d.ts.map +0 -1
- package/dist/helpers/getFluidFromView.js +0 -30
- package/dist/helpers/getFluidFromView.js.map +0 -1
- package/dist/helpers/getFluidState.d.ts +0 -15
- package/dist/helpers/getFluidState.d.ts.map +0 -1
- package/dist/helpers/getFluidState.js +0 -47
- package/dist/helpers/getFluidState.js.map +0 -1
- package/dist/helpers/getSchema.d.ts +0 -13
- package/dist/helpers/getSchema.d.ts.map +0 -1
- package/dist/helpers/getSchema.js +0 -15
- package/dist/helpers/getSchema.js.map +0 -1
- package/dist/helpers/getViewFromFluid.d.ts +0 -18
- package/dist/helpers/getViewFromFluid.d.ts.map +0 -1
- package/dist/helpers/getViewFromFluid.js +0 -47
- package/dist/helpers/getViewFromFluid.js.map +0 -1
- package/dist/helpers/index.d.ts +0 -16
- package/dist/helpers/index.d.ts.map +0 -1
- package/dist/helpers/index.js +0 -28
- package/dist/helpers/index.js.map +0 -1
- package/dist/helpers/initializeState.d.ts +0 -22
- package/dist/helpers/initializeState.d.ts.map +0 -1
- package/dist/helpers/initializeState.js +0 -77
- package/dist/helpers/initializeState.js.map +0 -1
- package/dist/helpers/internalInterface.d.ts +0 -15
- package/dist/helpers/internalInterface.d.ts.map +0 -1
- package/dist/helpers/internalInterface.js +0 -7
- package/dist/helpers/internalInterface.js.map +0 -1
- package/dist/helpers/rootCallbackListener.d.ts +0 -24
- package/dist/helpers/rootCallbackListener.d.ts.map +0 -1
- package/dist/helpers/rootCallbackListener.js +0 -55
- package/dist/helpers/rootCallbackListener.js.map +0 -1
- package/dist/helpers/setComponentSchema.d.ts +0 -14
- package/dist/helpers/setComponentSchema.d.ts.map +0 -1
- package/dist/helpers/setComponentSchema.js +0 -18
- package/dist/helpers/setComponentSchema.js.map +0 -1
- package/dist/helpers/setFluidState.d.ts +0 -20
- package/dist/helpers/setFluidState.d.ts.map +0 -1
- package/dist/helpers/setFluidState.js +0 -94
- package/dist/helpers/setFluidState.js.map +0 -1
- package/dist/helpers/syncState.d.ts +0 -25
- package/dist/helpers/syncState.d.ts.map +0 -1
- package/dist/helpers/syncState.js +0 -98
- package/dist/helpers/syncState.js.map +0 -1
- package/dist/helpers/updateStateAndFluidObjectMap.d.ts +0 -29
- package/dist/helpers/updateStateAndFluidObjectMap.d.ts.map +0 -1
- package/dist/helpers/updateStateAndFluidObjectMap.js +0 -30
- package/dist/helpers/updateStateAndFluidObjectMap.js.map +0 -1
- package/dist/helpers/utils.d.ts +0 -12
- package/dist/helpers/utils.d.ts.map +0 -1
- package/dist/helpers/utils.js +0 -74
- package/dist/helpers/utils.js.map +0 -1
- package/dist/interface.d.ts +0 -444
- package/dist/interface.d.ts.map +0 -1
- package/dist/interface.js +0 -18
- package/dist/interface.js.map +0 -1
- package/dist/reactView.d.ts +0 -32
- package/dist/reactView.d.ts.map +0 -1
- package/dist/reactView.js +0 -79
- package/dist/reactView.js.map +0 -1
- package/dist/syncedDataObject.d.ts +0 -80
- package/dist/syncedDataObject.d.ts.map +0 -1
- package/dist/syncedDataObject.js +0 -249
- package/dist/syncedDataObject.js.map +0 -1
- package/dist/syncedObjects/array/fluidSyncedArray.d.ts +0 -11
- package/dist/syncedObjects/array/fluidSyncedArray.d.ts.map +0 -1
- package/dist/syncedObjects/array/fluidSyncedArray.js +0 -78
- package/dist/syncedObjects/array/fluidSyncedArray.js.map +0 -1
- package/dist/syncedObjects/array/index.d.ts +0 -7
- package/dist/syncedObjects/array/index.d.ts.map +0 -1
- package/dist/syncedObjects/array/index.js +0 -19
- package/dist/syncedObjects/array/index.js.map +0 -1
- package/dist/syncedObjects/array/interface.d.ts +0 -33
- package/dist/syncedObjects/array/interface.d.ts.map +0 -1
- package/dist/syncedObjects/array/interface.js +0 -3
- package/dist/syncedObjects/array/interface.js.map +0 -1
- package/dist/syncedObjects/array/syncedArray.d.ts +0 -30
- package/dist/syncedObjects/array/syncedArray.d.ts.map +0 -1
- package/dist/syncedObjects/array/syncedArray.js +0 -42
- package/dist/syncedObjects/array/syncedArray.js.map +0 -1
- package/dist/syncedObjects/counter/fluidSyncedCounter.d.ts +0 -11
- package/dist/syncedObjects/counter/fluidSyncedCounter.d.ts.map +0 -1
- package/dist/syncedObjects/counter/fluidSyncedCounter.js +0 -79
- package/dist/syncedObjects/counter/fluidSyncedCounter.js.map +0 -1
- package/dist/syncedObjects/counter/index.d.ts +0 -7
- package/dist/syncedObjects/counter/index.d.ts.map +0 -1
- package/dist/syncedObjects/counter/index.js +0 -19
- package/dist/syncedObjects/counter/index.js.map +0 -1
- package/dist/syncedObjects/counter/interface.d.ts +0 -32
- package/dist/syncedObjects/counter/interface.d.ts.map +0 -1
- package/dist/syncedObjects/counter/interface.js +0 -3
- package/dist/syncedObjects/counter/interface.js.map +0 -1
- package/dist/syncedObjects/counter/syncedCounter.d.ts +0 -29
- package/dist/syncedObjects/counter/syncedCounter.d.ts.map +0 -1
- package/dist/syncedObjects/counter/syncedCounter.js +0 -36
- package/dist/syncedObjects/counter/syncedCounter.js.map +0 -1
- package/dist/syncedObjects/index.d.ts +0 -9
- package/dist/syncedObjects/index.d.ts.map +0 -1
- package/dist/syncedObjects/index.js +0 -21
- package/dist/syncedObjects/index.js.map +0 -1
- package/dist/syncedObjects/object/index.d.ts +0 -7
- package/dist/syncedObjects/object/index.d.ts.map +0 -1
- package/dist/syncedObjects/object/index.js +0 -19
- package/dist/syncedObjects/object/index.js.map +0 -1
- package/dist/syncedObjects/object/interface.d.ts +0 -13
- package/dist/syncedObjects/object/interface.d.ts.map +0 -1
- package/dist/syncedObjects/object/interface.js +0 -7
- package/dist/syncedObjects/object/interface.js.map +0 -1
- package/dist/syncedObjects/object/syncedObject.d.ts +0 -22
- package/dist/syncedObjects/object/syncedObject.d.ts.map +0 -1
- package/dist/syncedObjects/object/syncedObject.js +0 -46
- package/dist/syncedObjects/object/syncedObject.js.map +0 -1
- package/dist/syncedObjects/string/index.d.ts +0 -7
- package/dist/syncedObjects/string/index.d.ts.map +0 -1
- package/dist/syncedObjects/string/index.js +0 -19
- package/dist/syncedObjects/string/index.js.map +0 -1
- package/dist/syncedObjects/string/interface.d.ts +0 -16
- package/dist/syncedObjects/string/interface.d.ts.map +0 -1
- package/dist/syncedObjects/string/interface.js +0 -7
- package/dist/syncedObjects/string/interface.js.map +0 -1
- package/dist/syncedObjects/string/syncedString.d.ts +0 -25
- package/dist/syncedObjects/string/syncedString.d.ts.map +0 -1
- package/dist/syncedObjects/string/syncedString.js +0 -53
- package/dist/syncedObjects/string/syncedString.js.map +0 -1
- package/dist/useReducerFluid.d.ts +0 -7
- package/dist/useReducerFluid.d.ts.map +0 -1
- package/dist/useReducerFluid.js +0 -219
- package/dist/useReducerFluid.js.map +0 -1
- package/dist/useStateFluid.d.ts +0 -10
- package/dist/useStateFluid.d.ts.map +0 -1
- package/dist/useStateFluid.js +0 -67
- package/dist/useStateFluid.js.map +0 -1
- package/lib/createContextFluid.js +0 -23
- package/lib/createContextFluid.js.map +0 -1
- package/lib/helpers/generateFluidObjectSchema.js +0 -71
- package/lib/helpers/generateFluidObjectSchema.js.map +0 -1
- package/lib/helpers/getFluidFromView.js +0 -26
- package/lib/helpers/getFluidFromView.js.map +0 -1
- package/lib/helpers/getFluidState.js +0 -43
- package/lib/helpers/getFluidState.js.map +0 -1
- package/lib/helpers/getSchema.js +0 -11
- package/lib/helpers/getSchema.js.map +0 -1
- package/lib/helpers/getViewFromFluid.js +0 -43
- package/lib/helpers/getViewFromFluid.js.map +0 -1
- package/lib/helpers/index.js +0 -16
- package/lib/helpers/index.js.map +0 -1
- package/lib/helpers/initializeState.js +0 -73
- package/lib/helpers/initializeState.js.map +0 -1
- package/lib/helpers/internalInterface.js +0 -6
- package/lib/helpers/internalInterface.js.map +0 -1
- package/lib/helpers/rootCallbackListener.js +0 -51
- package/lib/helpers/rootCallbackListener.js.map +0 -1
- package/lib/helpers/setComponentSchema.js +0 -14
- package/lib/helpers/setComponentSchema.js.map +0 -1
- package/lib/helpers/setFluidState.js +0 -90
- package/lib/helpers/setFluidState.js.map +0 -1
- package/lib/helpers/syncState.js +0 -94
- package/lib/helpers/syncState.js.map +0 -1
- package/lib/helpers/updateStateAndFluidObjectMap.js +0 -26
- package/lib/helpers/updateStateAndFluidObjectMap.js.map +0 -1
- package/lib/helpers/utils.js +0 -67
- package/lib/helpers/utils.js.map +0 -1
- package/lib/interface.js +0 -8
- package/lib/interface.js.map +0 -1
- package/lib/reactView.js +0 -56
- package/lib/reactView.js.map +0 -1
- package/lib/syncedDataObject.js +0 -245
- package/lib/syncedDataObject.js.map +0 -1
- package/lib/syncedObjects/array/fluidSyncedArray.js +0 -72
- package/lib/syncedObjects/array/fluidSyncedArray.js.map +0 -1
- package/lib/syncedObjects/array/index.js +0 -7
- package/lib/syncedObjects/array/index.js.map +0 -1
- package/lib/syncedObjects/array/interface.js +0 -2
- package/lib/syncedObjects/array/interface.js.map +0 -1
- package/lib/syncedObjects/array/syncedArray.js +0 -37
- package/lib/syncedObjects/array/syncedArray.js.map +0 -1
- package/lib/syncedObjects/counter/fluidSyncedCounter.js +0 -73
- package/lib/syncedObjects/counter/fluidSyncedCounter.js.map +0 -1
- package/lib/syncedObjects/counter/index.js +0 -7
- package/lib/syncedObjects/counter/index.js.map +0 -1
- package/lib/syncedObjects/counter/interface.js +0 -2
- package/lib/syncedObjects/counter/interface.js.map +0 -1
- package/lib/syncedObjects/counter/syncedCounter.js +0 -31
- package/lib/syncedObjects/counter/syncedCounter.js.map +0 -1
- package/lib/syncedObjects/index.js +0 -9
- package/lib/syncedObjects/index.js.map +0 -1
- package/lib/syncedObjects/object/index.js +0 -7
- package/lib/syncedObjects/object/index.js.map +0 -1
- package/lib/syncedObjects/object/interface.js +0 -6
- package/lib/syncedObjects/object/interface.js.map +0 -1
- package/lib/syncedObjects/object/syncedObject.js +0 -41
- package/lib/syncedObjects/object/syncedObject.js.map +0 -1
- package/lib/syncedObjects/string/index.js +0 -7
- package/lib/syncedObjects/string/index.js.map +0 -1
- package/lib/syncedObjects/string/interface.js +0 -6
- package/lib/syncedObjects/string/interface.js.map +0 -1
- package/lib/syncedObjects/string/syncedString.js +0 -48
- package/lib/syncedObjects/string/syncedString.js.map +0 -1
- package/lib/useReducerFluid.js +0 -196
- package/lib/useReducerFluid.js.map +0 -1
- package/lib/useStateFluid.js +0 -44
- package/lib/useStateFluid.js.map +0 -1
- package/src/createContextFluid.tsx +0 -33
- package/src/helpers/generateFluidObjectSchema.ts +0 -95
- package/src/helpers/getFluidFromView.ts +0 -38
- package/src/helpers/getFluidState.ts +0 -67
- package/src/helpers/getSchema.ts +0 -18
- package/src/helpers/getViewFromFluid.ts +0 -68
- package/src/helpers/index.tsx +0 -16
- package/src/helpers/initializeState.ts +0 -162
- package/src/helpers/internalInterface.ts +0 -16
- package/src/helpers/rootCallbackListener.ts +0 -104
- package/src/helpers/setComponentSchema.ts +0 -21
- package/src/helpers/setFluidState.ts +0 -116
- package/src/helpers/syncState.ts +0 -159
- package/src/helpers/updateStateAndFluidObjectMap.ts +0 -85
- package/src/helpers/utils.tsx +0 -109
- package/src/interface.ts +0 -617
- package/src/reactView.tsx +0 -108
- package/src/syncedDataObject.ts +0 -337
- package/src/syncedObjects/array/fluidSyncedArray.ts +0 -126
- package/src/syncedObjects/array/index.ts +0 -7
- package/src/syncedObjects/array/interface.ts +0 -45
- package/src/syncedObjects/array/syncedArray.ts +0 -65
- package/src/syncedObjects/counter/fluidSyncedCounter.ts +0 -122
- package/src/syncedObjects/counter/index.ts +0 -7
- package/src/syncedObjects/counter/interface.ts +0 -44
- package/src/syncedObjects/counter/syncedCounter.ts +0 -64
- package/src/syncedObjects/index.ts +0 -9
- package/src/syncedObjects/object/index.ts +0 -7
- package/src/syncedObjects/object/interface.ts +0 -14
- package/src/syncedObjects/object/syncedObject.ts +0 -55
- package/src/syncedObjects/string/index.ts +0 -7
- package/src/syncedObjects/string/interface.ts +0 -17
- package/src/syncedObjects/string/syncedString.ts +0 -61
- package/src/useReducerFluid.tsx +0 -436
- package/src/useStateFluid.tsx +0 -84
- package/tsconfig.esnext.json +0 -7
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
-
* Licensed under the MIT License.
|
|
4
|
-
*/
|
|
5
|
-
import { SharedString } from "@fluidframework/sequence";
|
|
6
|
-
import { SyncedDataObject } from "../..";
|
|
7
|
-
import { ISyncedStringState } from "./interface";
|
|
8
|
-
/**
|
|
9
|
-
* Function to set the config for a synced string on a syncedDataObject's SharedMap synced state. This
|
|
10
|
-
* will initialize and provide a SharedString for the view to use. This SharedString provided is automatically
|
|
11
|
-
* bound to the state update of the functional view useSyncedString is called in. It can also easily be placed
|
|
12
|
-
* in a CollaborativeInput within a React view.
|
|
13
|
-
* @param syncedDataObject - The Fluid data object on which the synced state config is being set
|
|
14
|
-
* @param syncedStateId - The ID of the view state that this config schema is being set for
|
|
15
|
-
* @param defaultValue - The default string that the SharedString will be initialized as
|
|
16
|
-
*/
|
|
17
|
-
export declare function setSyncedStringConfig(syncedDataObject: SyncedDataObject, syncedStateId: string, defaultValue: string): void;
|
|
18
|
-
/**
|
|
19
|
-
* Function to use the SharedString state that has been prepared for this view
|
|
20
|
-
* @param syncedDataObject - The Fluid data object that holds the synced state config for this view
|
|
21
|
-
* @param syncedStateId - The ID of this view state
|
|
22
|
-
* @returns [the initialized SharedString, a synced setState call for the SharedString]
|
|
23
|
-
*/
|
|
24
|
-
export declare function useSyncedString(syncedDataObject: SyncedDataObject, syncedStateId: string): [SharedString | undefined, (newState: ISyncedStringState) => void];
|
|
25
|
-
//# sourceMappingURL=syncedString.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"syncedString.d.ts","sourceRoot":"","sources":["../../../src/syncedObjects/string/syncedString.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AACxD,OAAO,EAAE,gBAAgB,EAAE,MAAM,OAAO,CAAC;AAEzC,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAEjD;;;;;;;;GAQG;AACH,wBAAgB,qBAAqB,CACjC,gBAAgB,EAAE,gBAAgB,EAClC,aAAa,EAAE,MAAM,EACrB,YAAY,EAAE,MAAM,QAmBvB;AAED;;;;;GAKG;AACH,wBAAgB,eAAe,CAC3B,gBAAgB,EAAE,gBAAgB,EAClC,aAAa,EAAE,MAAM,GACtB,CAAC,YAAY,GAAG,SAAS,EAAE,CAAC,QAAQ,EAAE,kBAAkB,KAAK,IAAI,CAAC,CAQpE"}
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/*!
|
|
3
|
-
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
4
|
-
* Licensed under the MIT License.
|
|
5
|
-
*/
|
|
6
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
exports.useSyncedString = exports.setSyncedStringConfig = void 0;
|
|
8
|
-
const sequence_1 = require("@fluidframework/sequence");
|
|
9
|
-
const useStateFluid_1 = require("../../useStateFluid");
|
|
10
|
-
/**
|
|
11
|
-
* Function to set the config for a synced string on a syncedDataObject's SharedMap synced state. This
|
|
12
|
-
* will initialize and provide a SharedString for the view to use. This SharedString provided is automatically
|
|
13
|
-
* bound to the state update of the functional view useSyncedString is called in. It can also easily be placed
|
|
14
|
-
* in a CollaborativeInput within a React view.
|
|
15
|
-
* @param syncedDataObject - The Fluid data object on which the synced state config is being set
|
|
16
|
-
* @param syncedStateId - The ID of the view state that this config schema is being set for
|
|
17
|
-
* @param defaultValue - The default string that the SharedString will be initialized as
|
|
18
|
-
*/
|
|
19
|
-
function setSyncedStringConfig(syncedDataObject, syncedStateId, defaultValue) {
|
|
20
|
-
syncedDataObject.setConfig(syncedStateId, {
|
|
21
|
-
syncedStateId,
|
|
22
|
-
fluidToView: new Map([
|
|
23
|
-
[
|
|
24
|
-
"value", {
|
|
25
|
-
type: sequence_1.SharedString.name,
|
|
26
|
-
viewKey: "value",
|
|
27
|
-
sharedObjectCreate: (runtime) => {
|
|
28
|
-
const url = sequence_1.SharedString.create(runtime);
|
|
29
|
-
url.insertText(0, defaultValue);
|
|
30
|
-
return url;
|
|
31
|
-
},
|
|
32
|
-
},
|
|
33
|
-
],
|
|
34
|
-
]),
|
|
35
|
-
defaultViewState: {},
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
|
-
exports.setSyncedStringConfig = setSyncedStringConfig;
|
|
39
|
-
/**
|
|
40
|
-
* Function to use the SharedString state that has been prepared for this view
|
|
41
|
-
* @param syncedDataObject - The Fluid data object that holds the synced state config for this view
|
|
42
|
-
* @param syncedStateId - The ID of this view state
|
|
43
|
-
* @returns [the initialized SharedString, a synced setState call for the SharedString]
|
|
44
|
-
*/
|
|
45
|
-
function useSyncedString(syncedDataObject, syncedStateId) {
|
|
46
|
-
const [state, setState] = useStateFluid_1.useStateFluid({
|
|
47
|
-
syncedDataObject,
|
|
48
|
-
syncedStateId,
|
|
49
|
-
}, {});
|
|
50
|
-
return [state.value, setState];
|
|
51
|
-
}
|
|
52
|
-
exports.useSyncedString = useSyncedString;
|
|
53
|
-
//# sourceMappingURL=syncedString.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"syncedString.js","sourceRoot":"","sources":["../../../src/syncedObjects/string/syncedString.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,uDAAwD;AAExD,uDAAoD;AAGpD;;;;;;;;GAQG;AACH,SAAgB,qBAAqB,CACjC,gBAAkC,EAClC,aAAqB,EACrB,YAAoB;IAEpB,gBAAgB,CAAC,SAAS,CAAqB,aAAa,EAAE;QAC1D,aAAa;QACb,WAAW,EAAE,IAAI,GAAG,CAAC;YACjB;gBACI,OAAO,EAAE;oBACL,IAAI,EAAE,uBAAY,CAAC,IAAI;oBACvB,OAAO,EAAE,OAAO;oBAChB,kBAAkB,EAAE,CAAC,OAAO,EAAE,EAAE;wBAC5B,MAAM,GAAG,GAAG,uBAAY,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;wBACzC,GAAG,CAAC,UAAU,CAAC,CAAC,EAAE,YAAY,CAAC,CAAC;wBAChC,OAAO,GAAG,CAAC;oBACf,CAAC;iBACJ;aACJ;SACJ,CAAQ;QACT,gBAAgB,EAAE,EAAE;KACvB,CAAC,CAAC;AACP,CAAC;AAtBD,sDAsBC;AAED;;;;;GAKG;AACH,SAAgB,eAAe,CAC3B,gBAAkC,EAClC,aAAqB;IAErB,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,6BAAa,CACnC;QACI,gBAAgB;QAChB,aAAa;KAChB,EAAE,EAAE,CACR,CAAC;IACF,OAAO,CAAC,KAAK,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;AACnC,CAAC;AAXD,0CAWC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { SharedString } from \"@fluidframework/sequence\";\nimport { SyncedDataObject } from \"../..\";\nimport { useStateFluid } from \"../../useStateFluid\";\nimport { ISyncedStringState } from \"./interface\";\n\n/**\n * Function to set the config for a synced string on a syncedDataObject's SharedMap synced state. This\n * will initialize and provide a SharedString for the view to use. This SharedString provided is automatically\n * bound to the state update of the functional view useSyncedString is called in. It can also easily be placed\n * in a CollaborativeInput within a React view.\n * @param syncedDataObject - The Fluid data object on which the synced state config is being set\n * @param syncedStateId - The ID of the view state that this config schema is being set for\n * @param defaultValue - The default string that the SharedString will be initialized as\n */\nexport function setSyncedStringConfig(\n syncedDataObject: SyncedDataObject,\n syncedStateId: string,\n defaultValue: string,\n) {\n syncedDataObject.setConfig<ISyncedStringState>(syncedStateId, {\n syncedStateId,\n fluidToView: new Map([\n [\n \"value\", {\n type: SharedString.name,\n viewKey: \"value\",\n sharedObjectCreate: (runtime) => {\n const url = SharedString.create(runtime);\n url.insertText(0, defaultValue);\n return url;\n },\n },\n ],\n ]) as any,\n defaultViewState: {},\n });\n}\n\n/**\n * Function to use the SharedString state that has been prepared for this view\n * @param syncedDataObject - The Fluid data object that holds the synced state config for this view\n * @param syncedStateId - The ID of this view state\n * @returns [the initialized SharedString, a synced setState call for the SharedString]\n */\nexport function useSyncedString(\n syncedDataObject: SyncedDataObject,\n syncedStateId: string,\n): [SharedString | undefined, (newState: ISyncedStringState) => void] {\n const [state, setState] = useStateFluid<ISyncedStringState, ISyncedStringState>(\n {\n syncedDataObject,\n syncedStateId,\n }, {},\n );\n return [state.value, setState];\n}\n"]}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
-
* Licensed under the MIT License.
|
|
4
|
-
*/
|
|
5
|
-
import { IViewState, IFluidReducerProps, IFluidDataProps, IFluidState, IFluidReducer, IFluidSelector, ICombinedState } from "./interface";
|
|
6
|
-
export declare function useReducerFluid<SV extends IViewState, SF extends IFluidState, A extends IFluidReducer<SV, SF, C>, B extends IFluidSelector<SV, SF, C>, C extends IFluidDataProps>(props: IFluidReducerProps<SV, SF, A, B, C>, initialViewState: SV): [ICombinedState<SV, SF, C>, A, B];
|
|
7
|
-
//# sourceMappingURL=useReducerFluid.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useReducerFluid.d.ts","sourceRoot":"","sources":["../src/useReducerFluid.tsx"],"names":[],"mappings":"AAAA;;;GAGG;AAKH,OAAO,EACH,UAAU,EACV,kBAAkB,EAClB,eAAe,EAQf,WAAW,EACX,aAAa,EACb,cAAc,EACd,cAAc,EAEjB,MAAM,aAAa,CAAC;AAUrB,wBAAgB,eAAe,CAC3B,EAAE,SAAS,UAAU,EACrB,EAAE,SAAS,WAAW,EACtB,CAAC,SAAS,aAAa,CAAC,EAAE,EAAE,EAAE,EAAE,CAAC,CAAC,EAClC,CAAC,SAAS,cAAc,CAAC,EAAE,EAAE,EAAE,EAAE,CAAC,CAAC,EACnC,CAAC,SAAS,eAAe,EAEzB,KAAK,EAAE,kBAAkB,CAAC,EAAE,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,EAC1C,gBAAgB,EAAE,EAAE,GACrB,CAAC,cAAc,CAAC,EAAE,EAAE,EAAE,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAwYnC"}
|
package/dist/useReducerFluid.js
DELETED
|
@@ -1,219 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/*!
|
|
3
|
-
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
4
|
-
* Licensed under the MIT License.
|
|
5
|
-
*/
|
|
6
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
7
|
-
if (k2 === undefined) k2 = k;
|
|
8
|
-
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.useReducerFluid = void 0;
|
|
27
|
-
const React = __importStar(require("react"));
|
|
28
|
-
const interface_1 = require("./interface");
|
|
29
|
-
const useStateFluid_1 = require("./useStateFluid");
|
|
30
|
-
const helpers_1 = require("./helpers");
|
|
31
|
-
function useReducerFluid(props, initialViewState) {
|
|
32
|
-
var _a, _b;
|
|
33
|
-
const { syncedStateId, reducer, selector, syncedDataObject, } = props;
|
|
34
|
-
const config = syncedDataObject.getConfig(syncedStateId);
|
|
35
|
-
if (config === undefined) {
|
|
36
|
-
throw Error(`Failed to find configuration for synced state ID: ${syncedStateId}`);
|
|
37
|
-
}
|
|
38
|
-
const dataProps = (_a = props.dataProps) !== null && _a !== void 0 ? _a : syncedDataObject.dataProps;
|
|
39
|
-
// Get our combined synced state and setState callbacks from the useStateFluid function
|
|
40
|
-
const [viewState, setState] = useStateFluid_1.useStateFluid({
|
|
41
|
-
syncedStateId,
|
|
42
|
-
syncedDataObject,
|
|
43
|
-
dataProps,
|
|
44
|
-
}, initialViewState);
|
|
45
|
-
const syncedState = syncedDataObject.syncedState;
|
|
46
|
-
const { fluidToView, viewToFluid } = config;
|
|
47
|
-
const schemaHandles = helpers_1.getSchema(syncedStateId, syncedState);
|
|
48
|
-
if ((schemaHandles === null || schemaHandles === void 0 ? void 0 : schemaHandles.storedHandleMapHandle.absolutePath) === undefined) {
|
|
49
|
-
throw Error(`Component schema not initialized prior to render for ${syncedStateId}`);
|
|
50
|
-
}
|
|
51
|
-
const storedHandleMap = (_b = dataProps.fluidObjectMap.get(schemaHandles === null || schemaHandles === void 0 ? void 0 : schemaHandles.storedHandleMapHandle.absolutePath)) === null || _b === void 0 ? void 0 : _b.fluidObject;
|
|
52
|
-
if (storedHandleMap === undefined) {
|
|
53
|
-
throw Error(`Stored handle map not initialized prior to render for ${syncedStateId}`);
|
|
54
|
-
}
|
|
55
|
-
// Dispatch is an in-memory object that will load the reducer actions provided by the user
|
|
56
|
-
// and add updates to the view and Fluid state based off of the type of function and
|
|
57
|
-
// state values that were updated. Think of it as prepping the data in the first
|
|
58
|
-
// stage of dynamic programming. The dispatch functions are copies of the user-defined functions
|
|
59
|
-
// but with the updates to synced state also handled
|
|
60
|
-
const dispatch = React.useCallback((type, dispatchState, ...args) => {
|
|
61
|
-
// Retrieve the current state that is stored on the synced state for this Fluid object ID
|
|
62
|
-
const currentFluidState = helpers_1.getFluidState(syncedStateId, syncedState, dataProps.fluidObjectMap, fluidToView);
|
|
63
|
-
if (currentFluidState === undefined) {
|
|
64
|
-
throw Error("Attempted to dispatch function before fluid state was initialized");
|
|
65
|
-
}
|
|
66
|
-
const combinedDispatchFluidState = Object.assign(Object.assign({}, currentFluidState), dispatchState === null || dispatchState === void 0 ? void 0 : dispatchState.fluidState);
|
|
67
|
-
const combinedDispatchViewState = Object.assign(Object.assign({}, viewState), dispatchState === null || dispatchState === void 0 ? void 0 : dispatchState.viewState);
|
|
68
|
-
const combinedDispatchDataProps = Object.assign(Object.assign({}, dataProps), dispatchState === null || dispatchState === void 0 ? void 0 : dispatchState.dataProps);
|
|
69
|
-
const combinedDispatchState = {
|
|
70
|
-
fluidState: combinedDispatchFluidState,
|
|
71
|
-
viewState: combinedDispatchViewState,
|
|
72
|
-
dataProps: combinedDispatchDataProps,
|
|
73
|
-
};
|
|
74
|
-
const action = reducer[type];
|
|
75
|
-
if (action !== undefined) {
|
|
76
|
-
if (interface_1.instanceOfStateUpdateFunction(action)) {
|
|
77
|
-
// If its a synchronous state update function, call it and inspect the result
|
|
78
|
-
// for new Fluid object handles
|
|
79
|
-
const result = action.function(combinedDispatchState, ...args);
|
|
80
|
-
if (result.newComponentHandles !== undefined) {
|
|
81
|
-
// Fetch any new Fluid objects and add a listener to their synced state.
|
|
82
|
-
// Then update the view state.
|
|
83
|
-
const callback = helpers_1.syncedStateCallbackListener(combinedDispatchDataProps.fluidObjectMap, storedHandleMap, syncedStateId, syncedState, combinedDispatchDataProps.runtime, result.state.viewState, setState, fluidToView, viewToFluid);
|
|
84
|
-
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
|
85
|
-
helpers_1.updateStateAndFluidObjectMap(result.newComponentHandles, combinedDispatchDataProps.fluidObjectMap, storedHandleMap, false, syncedStateId, syncedState, combinedDispatchDataProps.runtime, result.state.viewState, setState, callback, fluidToView, viewToFluid);
|
|
86
|
-
}
|
|
87
|
-
else {
|
|
88
|
-
// Update the state directly
|
|
89
|
-
helpers_1.syncState(false, syncedStateId, syncedState, combinedDispatchDataProps.runtime, result.state.viewState, setState, combinedDispatchDataProps.fluidObjectMap, fluidToView, viewToFluid);
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
else if (interface_1.instanceOfAsyncStateUpdateFunction(action)) {
|
|
93
|
-
// In the case of an async function, the function promise is treated as a Thenable
|
|
94
|
-
// and the returned result is inspected after the function has completed
|
|
95
|
-
action.asyncFunction(combinedDispatchState, ...args).then((result) => {
|
|
96
|
-
const callback = helpers_1.syncedStateCallbackListener(combinedDispatchDataProps.fluidObjectMap, storedHandleMap, syncedStateId, syncedState, combinedDispatchDataProps.runtime, result.state.viewState, setState, fluidToView, viewToFluid);
|
|
97
|
-
if (result.newFluidHandles !== undefined) {
|
|
98
|
-
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
|
99
|
-
helpers_1.updateStateAndFluidObjectMap(result.newFluidHandles, combinedDispatchDataProps.fluidObjectMap, storedHandleMap, false, syncedStateId, syncedState, combinedDispatchDataProps.runtime, result.state.viewState, setState, callback, fluidToView, viewToFluid);
|
|
100
|
-
}
|
|
101
|
-
else {
|
|
102
|
-
helpers_1.syncState(false, syncedStateId, syncedState, combinedDispatchDataProps.runtime, result.state.viewState, setState, combinedDispatchDataProps.fluidObjectMap, fluidToView, viewToFluid);
|
|
103
|
-
}
|
|
104
|
-
});
|
|
105
|
-
}
|
|
106
|
-
else if (interface_1.instanceOfAsyncEffectFunction(action)) {
|
|
107
|
-
action.asyncFunction(combinedDispatchState, ...args).then(() => helpers_1.syncState(false, syncedStateId, syncedState, combinedDispatchDataProps.runtime, combinedDispatchState.viewState, setState, combinedDispatchDataProps.fluidObjectMap, fluidToView, viewToFluid));
|
|
108
|
-
}
|
|
109
|
-
else if (interface_1.instanceOfEffectFunction(action)) {
|
|
110
|
-
action.function(combinedDispatchState, ...args);
|
|
111
|
-
helpers_1.syncState(false, syncedStateId, syncedState, combinedDispatchDataProps.runtime, combinedDispatchState.viewState, setState, combinedDispatchDataProps.fluidObjectMap, fluidToView, viewToFluid);
|
|
112
|
-
}
|
|
113
|
-
else {
|
|
114
|
-
throw new Error(`Action with key ${action} does not match an expected reducer action interface`);
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
else {
|
|
118
|
-
throw new Error(`Action with key ${action} does not
|
|
119
|
-
exist in the reducers provided`);
|
|
120
|
-
}
|
|
121
|
-
}, [reducer, viewState, setState, dataProps]);
|
|
122
|
-
// The combinedReducer is then created using the dispatch functions we created above.
|
|
123
|
-
// This allows us to preserve the reducer interface while injecting Fluid-specific logic
|
|
124
|
-
// into the updating of the state. This is the second phase of DP, using the earlier created
|
|
125
|
-
// in-memory object to access the function the user is trying to use in constant time and then,
|
|
126
|
-
// subsequently performing it, taking the updated state, and applying it both locally and remotely
|
|
127
|
-
const combinedReducer = {};
|
|
128
|
-
Object.entries(reducer).forEach(([functionName, functionItem], i) => {
|
|
129
|
-
if (functionItem.asyncFunction !== undefined) {
|
|
130
|
-
combinedReducer[functionName] = {
|
|
131
|
-
asyncFunction: (dispatchState, ...args) => dispatch(functionName, dispatchState, ...args),
|
|
132
|
-
};
|
|
133
|
-
}
|
|
134
|
-
else {
|
|
135
|
-
combinedReducer[functionName] = {
|
|
136
|
-
function: (dispatchState, ...args) => dispatch(functionName, dispatchState, ...args),
|
|
137
|
-
};
|
|
138
|
-
}
|
|
139
|
-
});
|
|
140
|
-
// Fetch is an in-memory object similar to dispatch, but now made for selector actions.
|
|
141
|
-
// Selectors are NOT used for updating the state but instead to be able to access
|
|
142
|
-
// and add other Fluid Fluid objects using the handle provided. If the handle provided is not available
|
|
143
|
-
// in our Fluid object map, it will be dynamically updated and setState will be called again
|
|
144
|
-
// with the updated Fluid object map available for use.
|
|
145
|
-
// Alternatively, if you would like to pre-load Fluid objects before React is initialized,
|
|
146
|
-
// you can do so and provide them in dataProps.
|
|
147
|
-
// Fetch can also be used to retrieve data from these Fluid objects as they will also be available as a parameter.
|
|
148
|
-
const fetch = React.useCallback((type, fetchState, handle) => {
|
|
149
|
-
// Retrieve the current state that is stored on the syncedState for this Fluid object ID
|
|
150
|
-
const currentFluidState = helpers_1.getFluidState(syncedStateId, syncedState, dataProps.fluidObjectMap, fluidToView);
|
|
151
|
-
if (currentFluidState === undefined) {
|
|
152
|
-
throw Error("Attempted to dispatch function before fluid state was initialized");
|
|
153
|
-
}
|
|
154
|
-
const combinedFetchFluidState = Object.assign(Object.assign({}, currentFluidState), fetchState === null || fetchState === void 0 ? void 0 : fetchState.fluidState);
|
|
155
|
-
const combinedFetchViewState = Object.assign(Object.assign({}, viewState), fetchState === null || fetchState === void 0 ? void 0 : fetchState.viewState);
|
|
156
|
-
const combinedFetchDataProps = Object.assign(Object.assign({}, dataProps), fetchState === null || fetchState === void 0 ? void 0 : fetchState.dataProps);
|
|
157
|
-
const combinedFetchState = {
|
|
158
|
-
fluidState: combinedFetchFluidState,
|
|
159
|
-
viewState: combinedFetchViewState,
|
|
160
|
-
dataProps: combinedFetchDataProps,
|
|
161
|
-
};
|
|
162
|
-
const action = selector[type];
|
|
163
|
-
if (action !== undefined) {
|
|
164
|
-
if (interface_1.instanceOfSelectorFunction(action)) {
|
|
165
|
-
// Add any new handles that were returned by the selector to our list
|
|
166
|
-
// to be loaded to the fluid Fluid object map
|
|
167
|
-
let newHandles = [];
|
|
168
|
-
if (handle !== undefined &&
|
|
169
|
-
interface_1.instanceOfFluidObjectSelectorFunction(action) &&
|
|
170
|
-
combinedFetchDataProps.fluidObjectMap.get(handle.absolutePath) === undefined) {
|
|
171
|
-
newHandles.push(handle);
|
|
172
|
-
}
|
|
173
|
-
const actionResult = action.function(combinedFetchState, handle);
|
|
174
|
-
if (actionResult !== undefined &&
|
|
175
|
-
actionResult.newComponentHandles !== undefined) {
|
|
176
|
-
newHandles = newHandles.concat(actionResult.newComponentHandles);
|
|
177
|
-
}
|
|
178
|
-
// If there are handles, start a call to update the Fluid object map and then call the set state
|
|
179
|
-
// callback when it has finished to provide the updated map in the state
|
|
180
|
-
if (newHandles.length > 0) {
|
|
181
|
-
const callback = helpers_1.syncedStateCallbackListener(combinedFetchDataProps.fluidObjectMap, storedHandleMap, syncedStateId, syncedState, combinedFetchDataProps.runtime, combinedFetchState.viewState, setState, fluidToView, viewToFluid);
|
|
182
|
-
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
|
183
|
-
helpers_1.updateStateAndFluidObjectMap(newHandles, combinedFetchDataProps.fluidObjectMap, storedHandleMap, true, syncedStateId, syncedState, combinedFetchDataProps.runtime, combinedFetchState.viewState, setState, callback, fluidToView, viewToFluid);
|
|
184
|
-
}
|
|
185
|
-
// Always return the result immediately
|
|
186
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
187
|
-
return actionResult;
|
|
188
|
-
}
|
|
189
|
-
else {
|
|
190
|
-
throw new Error(`Action with key ${action} does not match an expected selector action interface`);
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
else {
|
|
194
|
-
throw new Error(`Action with key ${action} does not
|
|
195
|
-
exist in the selectors provided`);
|
|
196
|
-
}
|
|
197
|
-
}, [selector, viewState, setState, dataProps]);
|
|
198
|
-
// The combined selector is then similarly created with the Fluid-specific logic of adding any new Fluid objects
|
|
199
|
-
// to our Fluid object map interjected into the setState logic
|
|
200
|
-
const combinedSelector = {};
|
|
201
|
-
Object.entries(selector).forEach(([functionName, functionItem], i) => {
|
|
202
|
-
combinedSelector[functionName] = {
|
|
203
|
-
function: (fetchState, handle) => fetch(functionName, fetchState, handle),
|
|
204
|
-
};
|
|
205
|
-
});
|
|
206
|
-
// Retrieve the current state that is stored on the syncedState for this Fluid object ID
|
|
207
|
-
const fluidState = helpers_1.getFluidState(syncedStateId, syncedState, dataProps.fluidObjectMap, fluidToView);
|
|
208
|
-
return [
|
|
209
|
-
{
|
|
210
|
-
viewState,
|
|
211
|
-
fluidState,
|
|
212
|
-
dataProps,
|
|
213
|
-
},
|
|
214
|
-
combinedReducer,
|
|
215
|
-
combinedSelector,
|
|
216
|
-
];
|
|
217
|
-
}
|
|
218
|
-
exports.useReducerFluid = useReducerFluid;
|
|
219
|
-
//# sourceMappingURL=useReducerFluid.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useReducerFluid.js","sourceRoot":"","sources":["../src/useReducerFluid.tsx"],"names":[],"mappings":";AAAA;;;GAGG;;;;;;;;;;;;;;;;;;;;;;AAEH,6CAA+B;AAG/B,2CAgBqB;AACrB,mDAAgD;AAChD,uCAMmB;AAEnB,SAAgB,eAAe,CAO3B,KAA0C,EAC1C,gBAAoB;;IAEpB,MAAM,EACF,aAAa,EACb,OAAO,EACP,QAAQ,EACR,gBAAgB,GACnB,GAAG,KAAK,CAAC;IACV,MAAM,MAAM,GAAG,gBAAgB,CAAC,SAAS,CAAC,aAAa,CAAC,CAAC;IACzD,IAAI,MAAM,KAAK,SAAS,EAAE;QACtB,MAAM,KAAK,CAAC,qDAAqD,aAAa,EAAE,CAAC,CAAC;KACrF;IACD,MAAM,SAAS,SAAG,KAAK,CAAC,SAAS,mCAAI,gBAAgB,CAAC,SAAc,CAAC;IACr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E,CAAC,EAAE,EAAE;QACjE,gBAAgB,CAAC,YAAY,CAAC,GAAG;YAC7B,QAAQ,EAAE,CACN,UAAqC,EACrC,MAAqB,EAEvB,EAAE,CAAC,KAAK,CAAC,YAAY,EAAE,UAAU,EAAE,MAAM,CAAC;SAC/C,CAAC;IACN,CAAC,CAAC,CAAC;IAEH,wFAAwF;IACxF,MAAM,UAAU,GAAG,uBAAa,CAC5B,aAAa,EACb,WAAW,EACX,SAAS,CAAC,cAAc,EACxB,WAAW,CACd,CAAC;IAEF,OAAO;QACH;YACI,SAAS;YACT,UAAU;YACV,SAAS;SACZ;QACD,eAAoB;QACpB,gBAAqB;KACxB,CAAC;AACN,CAAC;AAjZD,0CAiZC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport * as React from \"react\";\nimport { IFluidHandle } from \"@fluidframework/core-interfaces\";\nimport { SharedMap } from \"@fluidframework/map\";\nimport {\n IViewState,\n IFluidReducerProps,\n IFluidDataProps,\n instanceOfStateUpdateFunction,\n instanceOfAsyncStateUpdateFunction,\n instanceOfSelectorFunction,\n instanceOfFluidObjectSelectorFunction,\n instanceOfEffectFunction,\n instanceOfAsyncEffectFunction,\n IStateUpdateResult,\n IFluidState,\n IFluidReducer,\n IFluidSelector,\n ICombinedState,\n ISyncedStateConfig,\n} from \"./interface\";\nimport { useStateFluid } from \"./useStateFluid\";\nimport {\n updateStateAndFluidObjectMap,\n syncedStateCallbackListener,\n getFluidState,\n syncState,\n getSchema,\n} from \"./helpers\";\n\nexport function useReducerFluid<\n SV extends IViewState,\n SF extends IFluidState,\n A extends IFluidReducer<SV, SF, C>,\n B extends IFluidSelector<SV, SF, C>,\n C extends IFluidDataProps\n>(\n props: IFluidReducerProps<SV, SF, A, B, C>,\n initialViewState: SV,\n): [ICombinedState<SV, SF, C>, A, B] {\n const {\n syncedStateId,\n reducer,\n selector,\n syncedDataObject,\n } = props;\n const config = syncedDataObject.getConfig(syncedStateId);\n if (config === undefined) {\n throw Error(`Failed to find configuration for synced state ID: ${syncedStateId}`);\n }\n const dataProps = props.dataProps ?? syncedDataObject.dataProps as C;\n // Get our combined synced state and setState callbacks from the useStateFluid function\n const [viewState, setState] = useStateFluid<SV, SF>({\n syncedStateId,\n syncedDataObject,\n dataProps,\n }, initialViewState);\n const syncedState = syncedDataObject.syncedState;\n const { fluidToView, viewToFluid } = config as ISyncedStateConfig<SV, SF>;\n\n const schemaHandles = getSchema(\n syncedStateId,\n syncedState,\n );\n if (schemaHandles?.storedHandleMapHandle.absolutePath === undefined) {\n throw Error(`Component schema not initialized prior to render for ${syncedStateId}`);\n }\n const storedHandleMap = dataProps.fluidObjectMap.get(\n schemaHandles?.storedHandleMapHandle.absolutePath,\n )?.fluidObject as SharedMap;\n if (storedHandleMap === undefined) {\n throw Error(`Stored handle map not initialized prior to render for ${syncedStateId}`);\n }\n\n // Dispatch is an in-memory object that will load the reducer actions provided by the user\n // and add updates to the view and Fluid state based off of the type of function and\n // state values that were updated. Think of it as prepping the data in the first\n // stage of dynamic programming. The dispatch functions are copies of the user-defined functions\n // but with the updates to synced state also handled\n const dispatch = React.useCallback(\n (\n type: keyof A,\n dispatchState?: ICombinedState<SV, SF, C>,\n ...args: any\n ) => {\n // Retrieve the current state that is stored on the synced state for this Fluid object ID\n const currentFluidState = getFluidState(\n syncedStateId,\n syncedState,\n dataProps.fluidObjectMap,\n fluidToView,\n );\n if (currentFluidState === undefined) {\n throw Error(\n \"Attempted to dispatch function before fluid state was initialized\",\n );\n }\n const combinedDispatchFluidState: SF = {\n ...currentFluidState,\n ...dispatchState?.fluidState,\n };\n const combinedDispatchViewState: SV = {\n ...viewState,\n ...dispatchState?.viewState,\n };\n const combinedDispatchDataProps: C = {\n ...dataProps,\n ...dispatchState?.dataProps,\n };\n const combinedDispatchState = {\n fluidState: combinedDispatchFluidState,\n viewState: combinedDispatchViewState,\n dataProps: combinedDispatchDataProps,\n };\n const action = reducer[type];\n if (action !== undefined) {\n if (instanceOfStateUpdateFunction<SV, SF, C>(action)) {\n // If its a synchronous state update function, call it and inspect the result\n // for new Fluid object handles\n const result = (action.function as any)(\n combinedDispatchState,\n ...args,\n );\n if (result.newComponentHandles !== undefined) {\n // Fetch any new Fluid objects and add a listener to their synced state.\n // Then update the view state.\n const callback = syncedStateCallbackListener(\n combinedDispatchDataProps.fluidObjectMap,\n storedHandleMap,\n syncedStateId,\n syncedState,\n combinedDispatchDataProps.runtime,\n result.state.viewState,\n setState,\n fluidToView,\n viewToFluid,\n );\n // eslint-disable-next-line @typescript-eslint/no-floating-promises\n updateStateAndFluidObjectMap(\n result.newComponentHandles,\n combinedDispatchDataProps.fluidObjectMap,\n storedHandleMap,\n false,\n syncedStateId,\n syncedState,\n combinedDispatchDataProps.runtime,\n result.state.viewState,\n setState,\n callback,\n fluidToView,\n viewToFluid,\n );\n } else {\n // Update the state directly\n syncState(\n false,\n syncedStateId,\n syncedState,\n combinedDispatchDataProps.runtime,\n result.state.viewState,\n setState,\n combinedDispatchDataProps.fluidObjectMap,\n fluidToView,\n viewToFluid,\n );\n }\n } else if (instanceOfAsyncStateUpdateFunction<SV, SF, C>(action)) {\n // In the case of an async function, the function promise is treated as a Thenable\n // and the returned result is inspected after the function has completed\n (action.asyncFunction as any)(\n combinedDispatchState,\n ...args,\n ).then((result: IStateUpdateResult<SV, SF, C>) => {\n const callback = syncedStateCallbackListener(\n combinedDispatchDataProps.fluidObjectMap,\n storedHandleMap,\n syncedStateId,\n syncedState,\n combinedDispatchDataProps.runtime,\n result.state.viewState,\n setState,\n fluidToView,\n viewToFluid,\n );\n if (result.newFluidHandles !== undefined) {\n // eslint-disable-next-line @typescript-eslint/no-floating-promises\n updateStateAndFluidObjectMap(\n result.newFluidHandles,\n combinedDispatchDataProps.fluidObjectMap,\n storedHandleMap,\n false,\n syncedStateId,\n syncedState,\n combinedDispatchDataProps.runtime,\n result.state.viewState,\n setState,\n callback,\n fluidToView,\n viewToFluid,\n );\n } else {\n syncState(\n false,\n syncedStateId,\n syncedState,\n combinedDispatchDataProps.runtime,\n result.state.viewState,\n setState,\n combinedDispatchDataProps.fluidObjectMap,\n fluidToView,\n viewToFluid,\n );\n }\n });\n } else if (instanceOfAsyncEffectFunction<SV, SF, C>(action)) {\n (action.asyncFunction as any)(\n combinedDispatchState,\n ...args,\n ).then(() =>\n syncState(\n false,\n syncedStateId,\n syncedState,\n combinedDispatchDataProps.runtime,\n combinedDispatchState.viewState,\n setState,\n combinedDispatchDataProps.fluidObjectMap,\n fluidToView,\n viewToFluid,\n ),\n );\n } else if (instanceOfEffectFunction<SV, SF, C>(action)) {\n (action.function as any)(combinedDispatchState, ...args);\n syncState(\n false,\n syncedStateId,\n syncedState,\n combinedDispatchDataProps.runtime,\n combinedDispatchState.viewState,\n setState,\n combinedDispatchDataProps.fluidObjectMap,\n fluidToView,\n viewToFluid,\n );\n } else {\n throw new Error(\n `Action with key ${action} does not match an expected reducer action interface`,\n );\n }\n } else {\n throw new Error(\n `Action with key ${action} does not\n exist in the reducers provided`,\n );\n }\n },\n [reducer, viewState, setState, dataProps],\n );\n\n // The combinedReducer is then created using the dispatch functions we created above.\n // This allows us to preserve the reducer interface while injecting Fluid-specific logic\n // into the updating of the state. This is the second phase of DP, using the earlier created\n // in-memory object to access the function the user is trying to use in constant time and then,\n // subsequently performing it, taking the updated state, and applying it both locally and remotely\n const combinedReducer = {};\n Object.entries(reducer).forEach(([functionName, functionItem], i) => {\n if ((functionItem as any).asyncFunction !== undefined) {\n combinedReducer[functionName] = {\n asyncFunction: (\n dispatchState: ICombinedState<SV, SF, C>,\n ...args: any\n ) => dispatch(functionName, dispatchState, ...args),\n };\n } else {\n combinedReducer[functionName] = {\n function: (\n dispatchState: ICombinedState<SV, SF, C>,\n ...args: any\n ) => dispatch(functionName, dispatchState, ...args),\n };\n }\n });\n\n // Fetch is an in-memory object similar to dispatch, but now made for selector actions.\n // Selectors are NOT used for updating the state but instead to be able to access\n // and add other Fluid Fluid objects using the handle provided. If the handle provided is not available\n // in our Fluid object map, it will be dynamically updated and setState will be called again\n // with the updated Fluid object map available for use.\n // Alternatively, if you would like to pre-load Fluid objects before React is initialized,\n // you can do so and provide them in dataProps.\n // Fetch can also be used to retrieve data from these Fluid objects as they will also be available as a parameter.\n const fetch = React.useCallback(\n (\n type: keyof B,\n fetchState?: ICombinedState<SV, SF, C>,\n handle?: IFluidHandle,\n ) => {\n // Retrieve the current state that is stored on the syncedState for this Fluid object ID\n const currentFluidState = getFluidState(\n syncedStateId,\n syncedState,\n dataProps.fluidObjectMap,\n fluidToView,\n );\n if (currentFluidState === undefined) {\n throw Error(\n \"Attempted to dispatch function before fluid state was initialized\",\n );\n }\n const combinedFetchFluidState: SF = {\n ...currentFluidState,\n ...fetchState?.fluidState,\n };\n const combinedFetchViewState: SV = {\n ...viewState,\n ...fetchState?.viewState,\n };\n const combinedFetchDataProps: C = {\n ...dataProps,\n ...fetchState?.dataProps,\n };\n const combinedFetchState = {\n fluidState: combinedFetchFluidState,\n viewState: combinedFetchViewState,\n dataProps: combinedFetchDataProps,\n };\n const action = selector[type];\n if (action !== undefined) {\n if (instanceOfSelectorFunction<SV, SF, C>(action)) {\n // Add any new handles that were returned by the selector to our list\n // to be loaded to the fluid Fluid object map\n let newHandles: IFluidHandle[] = [];\n if (\n handle !== undefined &&\n instanceOfFluidObjectSelectorFunction<SV, SF, C>(action) &&\n combinedFetchDataProps.fluidObjectMap.get(\n handle.absolutePath,\n ) === undefined\n ) {\n newHandles.push(handle);\n }\n const actionResult = (action.function as any)(\n combinedFetchState,\n handle,\n );\n if (\n actionResult !== undefined &&\n actionResult.newComponentHandles !== undefined\n ) {\n newHandles = newHandles.concat(\n actionResult.newComponentHandles,\n );\n }\n // If there are handles, start a call to update the Fluid object map and then call the set state\n // callback when it has finished to provide the updated map in the state\n if (newHandles.length > 0) {\n const callback = syncedStateCallbackListener(\n combinedFetchDataProps.fluidObjectMap,\n storedHandleMap,\n syncedStateId,\n syncedState,\n combinedFetchDataProps.runtime,\n combinedFetchState.viewState,\n setState,\n fluidToView,\n viewToFluid,\n );\n // eslint-disable-next-line @typescript-eslint/no-floating-promises\n updateStateAndFluidObjectMap(\n newHandles,\n combinedFetchDataProps.fluidObjectMap,\n storedHandleMap,\n true,\n syncedStateId,\n syncedState,\n combinedFetchDataProps.runtime,\n combinedFetchState.viewState,\n setState,\n callback,\n fluidToView,\n viewToFluid,\n );\n }\n // Always return the result immediately\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return actionResult;\n } else {\n throw new Error(\n `Action with key ${action} does not match an expected selector action interface`,\n );\n }\n } else {\n throw new Error(\n `Action with key ${action} does not\n exist in the selectors provided`,\n );\n }\n },\n [selector, viewState, setState, dataProps],\n );\n\n // The combined selector is then similarly created with the Fluid-specific logic of adding any new Fluid objects\n // to our Fluid object map interjected into the setState logic\n const combinedSelector = {};\n Object.entries(selector).forEach(([functionName, functionItem], i) => {\n combinedSelector[functionName] = {\n function: (\n fetchState: ICombinedState<SV, SF, C>,\n handle?: IFluidHandle,\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n ) => fetch(functionName, fetchState, handle),\n };\n });\n\n // Retrieve the current state that is stored on the syncedState for this Fluid object ID\n const fluidState = getFluidState(\n syncedStateId,\n syncedState,\n dataProps.fluidObjectMap,\n fluidToView,\n );\n\n return [\n {\n viewState,\n fluidState,\n dataProps,\n },\n combinedReducer as A,\n combinedSelector as B,\n ];\n}\n"]}
|
package/dist/useStateFluid.d.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
-
* Licensed under the MIT License.
|
|
4
|
-
*/
|
|
5
|
-
import { IViewState, IFluidProps, IFluidState } from "./interface";
|
|
6
|
-
/**
|
|
7
|
-
* A wrapper around the useState React hook that combines local and Fluid state updates
|
|
8
|
-
*/
|
|
9
|
-
export declare function useStateFluid<SV extends IViewState, SF extends IFluidState>(props: IFluidProps<SV, SF>, initialViewState: SV): [SV, (newState: SV, isSyncedStateUpdate?: boolean) => void];
|
|
10
|
-
//# sourceMappingURL=useStateFluid.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useStateFluid.d.ts","sourceRoot":"","sources":["../src/useStateFluid.tsx"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EACH,UAAU,EACV,WAAW,EACX,WAAW,EAEd,MAAM,aAAa,CAAC;AAGrB;;GAEG;AACH,wBAAgB,aAAa,CACzB,EAAE,SAAS,UAAU,EACrB,EAAE,SAAS,WAAW,EAEtB,KAAK,EAAE,WAAW,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,gBAAgB,EAAE,EAAE,GACjD,CAAC,EAAE,EAAE,CAAC,QAAQ,EAAE,EAAE,EAAE,mBAAmB,CAAC,EAAE,OAAO,KAAK,IAAI,CAAC,CA6D7D"}
|
package/dist/useStateFluid.js
DELETED
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/*!
|
|
3
|
-
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
4
|
-
* Licensed under the MIT License.
|
|
5
|
-
*/
|
|
6
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
7
|
-
if (k2 === undefined) k2 = k;
|
|
8
|
-
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.useStateFluid = void 0;
|
|
27
|
-
const React = __importStar(require("react"));
|
|
28
|
-
const helpers_1 = require("./helpers");
|
|
29
|
-
/**
|
|
30
|
-
* A wrapper around the useState React hook that combines local and Fluid state updates
|
|
31
|
-
*/
|
|
32
|
-
function useStateFluid(props, initialViewState) {
|
|
33
|
-
var _a;
|
|
34
|
-
const { syncedStateId, syncedDataObject, } = props;
|
|
35
|
-
const config = syncedDataObject.getConfig(syncedStateId);
|
|
36
|
-
if (config === undefined) {
|
|
37
|
-
throw Error(`Failed to find configuration for synced state ID: ${syncedStateId}`);
|
|
38
|
-
}
|
|
39
|
-
const syncedState = syncedDataObject.syncedState;
|
|
40
|
-
const dataProps = (_a = props.dataProps) !== null && _a !== void 0 ? _a : syncedDataObject.dataProps;
|
|
41
|
-
const { fluidToView, viewToFluid } = config;
|
|
42
|
-
// Establish the react state and setState functions using the initialViewState passed in
|
|
43
|
-
const [reactState, reactSetState] = React.useState(initialViewState);
|
|
44
|
-
// If this is the first time this function is being called in this session
|
|
45
|
-
// It's okay to disable eslint here as the state will be updated with the initialized values
|
|
46
|
-
// after the async call has finished
|
|
47
|
-
// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
|
|
48
|
-
if (!reactState.isInitialized) {
|
|
49
|
-
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
|
50
|
-
helpers_1.initializeState(syncedStateId, syncedState, dataProps, reactState, reactSetState, fluidToView, viewToFluid);
|
|
51
|
-
}
|
|
52
|
-
// Create the fluidSetState function as a callback that in turn calls either our combined state
|
|
53
|
-
// update to both the local and Fluid state or just the local state respectively based off of
|
|
54
|
-
// if the state update is coming locally, i.e. not from the root
|
|
55
|
-
const fluidSetState = React.useCallback((newState, fromRootUpdate = false, isLocal = false) => {
|
|
56
|
-
const newCombinedState = Object.assign(Object.assign(Object.assign({}, reactState), newState), { isInitialized: true });
|
|
57
|
-
if (isLocal) {
|
|
58
|
-
reactSetState(newCombinedState);
|
|
59
|
-
}
|
|
60
|
-
else {
|
|
61
|
-
helpers_1.syncState(fromRootUpdate, syncedStateId, syncedState, dataProps.runtime, newCombinedState, reactSetState, dataProps.fluidObjectMap, fluidToView, viewToFluid);
|
|
62
|
-
}
|
|
63
|
-
}, [syncedState, viewToFluid, reactState, reactSetState, dataProps]);
|
|
64
|
-
return [reactState, fluidSetState];
|
|
65
|
-
}
|
|
66
|
-
exports.useStateFluid = useStateFluid;
|
|
67
|
-
//# sourceMappingURL=useStateFluid.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useStateFluid.js","sourceRoot":"","sources":["../src/useStateFluid.tsx"],"names":[],"mappings":";AAAA;;;GAGG;;;;;;;;;;;;;;;;;;;;;;AAEH,6CAA+B;AAO/B,uCAAuD;AAEvD;;GAEG;AACH,SAAgB,aAAa,CAIzB,KAA0B,EAAE,gBAAoB;;IAEhD,MAAM,EACF,aAAa,EACb,gBAAgB,GACnB,GAAG,KAAK,CAAC;IACV,MAAM,MAAM,GAAG,gBAAgB,CAAC,SAAS,CAAC,aAAa,CAAC,CAAC;IACzD,IAAI,MAAM,KAAK,SAAS,EAAE;QACtB,MAAM,KAAK,CAAC,qDAAqD,aAAa,EAAE,CAAC,CAAC;KACrF;IACD,MAAM,WAAW,GAAG,gBAAgB,CAAC,WAAW,CAAC;IACjD,MAAM,SAAS,SAAG,KAAK,CAAC,SAAS,mCAAI,gBAAgB,CAAC,SAAS,CAAC;IAChE,MAAM,EAAE,WAAW,EAAE,WAAW,EAAE,GAAG,MAAoC,CAAC;IAC1E,wFAAwF;IACxF,MAAM,CAAC,UAAU,EAAE,aAAa,CAAC,GAAG,KAAK,CAAC,QAAQ,CAAK,gBAAgB,CAAC,CAAC;IAEzE,0EAA0E;IAC1E,4FAA4F;IAC5F,oCAAoC;IACpC,yEAAyE;IACzE,IAAI,CAAC,UAAU,CAAC,aAAa,EAAE;QAC3B,mEAAmE;QACnE,yBAAe,CACX,aAAa,EACb,WAAW,EACX,SAAS,EACT,UAAU,EACV,aAAa,EACb,WAAW,EACX,WAAW,CACd,CAAC;KACL;IAED,+FAA+F;IAC/F,6FAA6F;IAC7F,gEAAgE;IAChE,MAAM,aAAa,GAAG,KAAK,CAAC,WAAW,CACnC,CAAC,QAAqB,EAAE,cAAc,GAAG,KAAK,EAAE,UAAmB,KAAK,EAAE,EAAE;QACxE,MAAM,gBAAgB,iDACf,UAAU,GACV,QAAQ,KACX,aAAa,EAAE,IAAI,GACtB,CAAC;QACF,IAAI,OAAO,EAAE;YACT,aAAa,CAAC,gBAAgB,CAAC,CAAC;SACnC;aAAM;YACH,mBAAS,CACL,cAAc,EACd,aAAa,EACb,WAAW,EACX,SAAS,CAAC,OAAO,EACjB,gBAAgB,EAChB,aAAa,EACb,SAAS,CAAC,cAAc,EACxB,WAAW,EACX,WAAW,CACd,CAAC;SACL;IACL,CAAC,EACD,CAAC,WAAW,EAAE,WAAW,EAAE,UAAU,EAAE,aAAa,EAAE,SAAS,CAAC,CACnE,CAAC;IACF,OAAO,CAAC,UAAU,EAAE,aAAa,CAAC,CAAC;AACvC,CAAC;AAlED,sCAkEC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport * as React from \"react\";\nimport {\n IViewState,\n IFluidProps,\n IFluidState,\n ISyncedStateConfig,\n} from \"./interface\";\nimport { initializeState, syncState } from \"./helpers\";\n\n/**\n * A wrapper around the useState React hook that combines local and Fluid state updates\n */\nexport function useStateFluid<\n SV extends IViewState,\n SF extends IFluidState\n>(\n props: IFluidProps<SV, SF>, initialViewState: SV,\n): [SV, (newState: SV, isSyncedStateUpdate?: boolean) => void] {\n const {\n syncedStateId,\n syncedDataObject,\n } = props;\n const config = syncedDataObject.getConfig(syncedStateId);\n if (config === undefined) {\n throw Error(`Failed to find configuration for synced state ID: ${syncedStateId}`);\n }\n const syncedState = syncedDataObject.syncedState;\n const dataProps = props.dataProps ?? syncedDataObject.dataProps;\n const { fluidToView, viewToFluid } = config as ISyncedStateConfig<SV, SF>;\n // Establish the react state and setState functions using the initialViewState passed in\n const [reactState, reactSetState] = React.useState<SV>(initialViewState);\n\n // If this is the first time this function is being called in this session\n // It's okay to disable eslint here as the state will be updated with the initialized values\n // after the async call has finished\n // eslint-disable-next-line @typescript-eslint/strict-boolean-expressions\n if (!reactState.isInitialized) {\n // eslint-disable-next-line @typescript-eslint/no-floating-promises\n initializeState<SV, SF>(\n syncedStateId,\n syncedState,\n dataProps,\n reactState,\n reactSetState,\n fluidToView,\n viewToFluid,\n );\n }\n\n // Create the fluidSetState function as a callback that in turn calls either our combined state\n // update to both the local and Fluid state or just the local state respectively based off of\n // if the state update is coming locally, i.e. not from the root\n const fluidSetState = React.useCallback(\n (newState: Partial<SV>, fromRootUpdate = false, isLocal: boolean = false) => {\n const newCombinedState = {\n ...reactState,\n ...newState,\n isInitialized: true,\n };\n if (isLocal) {\n reactSetState(newCombinedState);\n } else {\n syncState(\n fromRootUpdate,\n syncedStateId,\n syncedState,\n dataProps.runtime,\n newCombinedState,\n reactSetState,\n dataProps.fluidObjectMap,\n fluidToView,\n viewToFluid,\n );\n }\n },\n [syncedState, viewToFluid, reactState, reactSetState, dataProps],\n );\n return [reactState, fluidSetState];\n}\n"]}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
-
* Licensed under the MIT License.
|
|
4
|
-
*/
|
|
5
|
-
import * as React from "react";
|
|
6
|
-
import { useStateFluid } from "./useStateFluid";
|
|
7
|
-
export function createContextFluid(props, initialViewState) {
|
|
8
|
-
var _a;
|
|
9
|
-
const [state, setState] = useStateFluid(props, initialViewState);
|
|
10
|
-
const PrimedFluidContext = React.createContext({
|
|
11
|
-
state,
|
|
12
|
-
setState,
|
|
13
|
-
reactContext: (_a = props.reactContext) !== null && _a !== void 0 ? _a : {},
|
|
14
|
-
});
|
|
15
|
-
return {
|
|
16
|
-
Provider: PrimedFluidContext.Provider,
|
|
17
|
-
Consumer: PrimedFluidContext.Consumer,
|
|
18
|
-
usePrimedContext: () => React.useContext(PrimedFluidContext),
|
|
19
|
-
state,
|
|
20
|
-
setState,
|
|
21
|
-
};
|
|
22
|
-
}
|
|
23
|
-
//# sourceMappingURL=createContextFluid.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"createContextFluid.js","sourceRoot":"","sources":["../src/createContextFluid.tsx"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAO/B,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAEhD,MAAM,UAAU,kBAAkB,CAIhC,KAAoC,EAAE,gBAAoB;;IACxD,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,aAAa,CAAC,KAAK,EAAE,gBAAgB,CAAC,CAAC;IACjE,MAAM,kBAAkB,GAAG,KAAK,CAAC,aAAa,CAAC;QAC3C,KAAK;QACL,QAAQ;QACR,YAAY,QAAE,KAAK,CAAC,YAAY,mCAAI,EAAE;KACzC,CAAC,CAAC;IACH,OAAO;QACH,QAAQ,EAAE,kBAAkB,CAAC,QAAQ;QACrC,QAAQ,EAAE,kBAAkB,CAAC,QAAQ;QACrC,gBAAgB,EAAE,GAAG,EAAE,CAAC,KAAK,CAAC,UAAU,CAAC,kBAAkB,CAAC;QAC5D,KAAK;QACL,QAAQ;KACX,CAAC;AACN,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport * as React from \"react\";\nimport {\n IViewState,\n IFluidContextProps,\n FluidContext,\n IFluidState,\n} from \"./interface\";\nimport { useStateFluid } from \"./useStateFluid\";\n\nexport function createContextFluid<\n SV extends IViewState,\n SF extends IFluidState,\n C\n>(props: IFluidContextProps<SV, SF, C>, initialViewState: SV): FluidContext<SV, C> {\n const [state, setState] = useStateFluid(props, initialViewState);\n const PrimedFluidContext = React.createContext({\n state,\n setState,\n reactContext: props.reactContext ?? {},\n });\n return {\n Provider: PrimedFluidContext.Provider,\n Consumer: PrimedFluidContext.Consumer,\n usePrimedContext: () => React.useContext(PrimedFluidContext),\n state,\n setState,\n };\n}\n"]}
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
-
* Licensed under the MIT License.
|
|
4
|
-
*/
|
|
5
|
-
import { SharedMap } from "@fluidframework/map";
|
|
6
|
-
/**
|
|
7
|
-
* Identifies which values within the Fluid and view states match
|
|
8
|
-
* The view and Fluid matching map identify if the value in the respective states
|
|
9
|
-
* needs a converter or not
|
|
10
|
-
* @param runtime - The data store runtime used to create the SharedMap objects
|
|
11
|
-
* @param fluidToView - The Fluid to view state conversion mapping
|
|
12
|
-
* @param viewToFluid - The view to Fluid conversion state mapping
|
|
13
|
-
* */
|
|
14
|
-
export function generateFluidObjectSchema(runtime, defaultViewState, fluidToView, viewToFluid) {
|
|
15
|
-
// matching primitives w/ the same key in view and fluid
|
|
16
|
-
// true if needs converter or is a Fluid object, false if not
|
|
17
|
-
const viewMatchingMap = SharedMap.create(runtime);
|
|
18
|
-
const fluidMatchingMap = SharedMap.create(runtime);
|
|
19
|
-
const storedHandleMap = SharedMap.create(runtime);
|
|
20
|
-
for (const fluidStateKey of fluidToView.keys()) {
|
|
21
|
-
const value = fluidToView.get(fluidStateKey);
|
|
22
|
-
if (value === undefined) {
|
|
23
|
-
throw Error("Cannot find fluidToView value");
|
|
24
|
-
}
|
|
25
|
-
const { type, viewKey, viewConverter, } = value;
|
|
26
|
-
const fluidConverter = viewToFluid === null || viewToFluid === void 0 ? void 0 : viewToFluid.get(viewKey);
|
|
27
|
-
if (fluidConverter === undefined) {
|
|
28
|
-
if (defaultViewState[viewKey] !== undefined
|
|
29
|
-
&& typeof (defaultViewState[viewKey]) !== type
|
|
30
|
-
&& type !== "any") {
|
|
31
|
-
throw Error(`Failed to find Fluid converter for key ${viewKey}`);
|
|
32
|
-
}
|
|
33
|
-
else {
|
|
34
|
-
continue;
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
if (type === fluidConverter.type) {
|
|
38
|
-
fluidMatchingMap.set(fluidStateKey, false);
|
|
39
|
-
}
|
|
40
|
-
else if (viewConverter !== undefined) {
|
|
41
|
-
fluidMatchingMap.set(fluidStateKey, true);
|
|
42
|
-
}
|
|
43
|
-
else {
|
|
44
|
-
throw Error(`Failed to find view converter for Fluid key ${fluidStateKey}`);
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
if (viewToFluid !== undefined) {
|
|
48
|
-
for (const viewStateKey of viewToFluid.keys()) {
|
|
49
|
-
const value = viewToFluid.get(viewStateKey);
|
|
50
|
-
if (value === undefined) {
|
|
51
|
-
throw Error("Cannot find viewToFluid value");
|
|
52
|
-
}
|
|
53
|
-
const { type, fluidKey, fluidConverter, } = value;
|
|
54
|
-
const viewConverter = fluidToView.get(fluidKey);
|
|
55
|
-
if (viewConverter === undefined) {
|
|
56
|
-
throw Error(`Failed to find view converter for key ${fluidKey}`);
|
|
57
|
-
}
|
|
58
|
-
if (type === viewConverter.type) {
|
|
59
|
-
viewMatchingMap.set(viewStateKey, false);
|
|
60
|
-
}
|
|
61
|
-
else if (fluidConverter !== undefined) {
|
|
62
|
-
viewMatchingMap.set(viewStateKey, true);
|
|
63
|
-
}
|
|
64
|
-
else {
|
|
65
|
-
throw Error(`Failed to find Fluid converter for view key ${viewStateKey}`);
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
return { viewMatchingMap, fluidMatchingMap, storedHandleMap };
|
|
70
|
-
}
|
|
71
|
-
//# sourceMappingURL=generateFluidObjectSchema.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"generateFluidObjectSchema.js","sourceRoot":"","sources":["../../src/helpers/generateFluidObjectSchema.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAShD;;;;;;;KAOK;AACL,MAAM,UAAU,yBAAyB,CAIrC,OAA+B,EAC/B,gBAAoB,EACpB,WAAmC,EACnC,WAAoC;IAEpC,wDAAwD;IACxD,6DAA6D;IAC7D,MAAM,eAAe,GAAG,SAAS,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IAClD,MAAM,gBAAgB,GAAG,SAAS,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IACnD,MAAM,eAAe,GAAG,SAAS,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IAClD,KAAK,MAAM,aAAa,IAAI,WAAW,CAAC,IAAI,EAAE,EAAE;QAC5C,MAAM,KAAK,GAAG,WAAW,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC;QAC7C,IAAI,KAAK,KAAK,SAAS,EAAE;YACrB,MAAM,KAAK,CAAC,+BAA+B,CAAC,CAAC;SAChD;QACD,MAAM,EACF,IAAI,EACJ,OAAO,EACP,aAAa,GAChB,GAAG,KAAK,CAAC;QACV,MAAM,cAAc,GAAG,WAAW,aAAX,WAAW,uBAAX,WAAW,CAAE,GAAG,CAAC,OAAO,CAAC,CAAC;QACjD,IAAI,cAAc,KAAK,SAAS,EAAE;YAC9B,IACI,gBAAgB,CAAC,OAAO,CAAC,KAAK,SAAS;mBACpC,OAAO,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC,KAAK,IAAI;mBAC3C,IAAI,KAAK,KAAK,EACnB;gBACE,MAAM,KAAK,CAAC,0CAA0C,O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esContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { IFluidDataStoreRuntime } from \"@fluidframework/datastore-definitions\";\nimport { SharedMap } from \"@fluidframework/map\";\nimport {\n IFluidState,\n IViewState,\n ViewToFluidMap,\n FluidToViewMap,\n IFluidSchema,\n} from \"../interface\";\n\n/**\n * Identifies which values within the Fluid and view states match\n * The view and Fluid matching map identify if the value in the respective states\n * needs a converter or not\n * @param runtime - The data store runtime used to create the SharedMap objects\n * @param fluidToView - The Fluid to view state conversion mapping\n * @param viewToFluid - The view to Fluid conversion state mapping\n * */\nexport function generateFluidObjectSchema<\n SV extends IViewState,\n SF extends IFluidState\n>(\n runtime: IFluidDataStoreRuntime,\n defaultViewState: SV,\n fluidToView: FluidToViewMap<SV, SF>,\n viewToFluid?: ViewToFluidMap<SV, SF>,\n): IFluidSchema {\n // matching primitives w/ the same key in view and fluid\n // true if needs converter or is a Fluid object, false if not\n const viewMatchingMap = SharedMap.create(runtime);\n const fluidMatchingMap = SharedMap.create(runtime);\n const storedHandleMap = SharedMap.create(runtime);\n for (const fluidStateKey of fluidToView.keys()) {\n const value = fluidToView.get(fluidStateKey);\n if (value === undefined) {\n throw Error(\"Cannot find fluidToView value\");\n }\n const {\n type,\n viewKey,\n viewConverter,\n } = value;\n const fluidConverter = viewToFluid?.get(viewKey);\n if (fluidConverter === undefined) {\n if (\n defaultViewState[viewKey] !== undefined\n && typeof (defaultViewState[viewKey]) !== type\n && type !== \"any\"\n ) {\n throw Error(`Failed to find Fluid converter for key ${viewKey}`);\n } else {\n continue;\n }\n }\n if (type === fluidConverter.type) {\n fluidMatchingMap.set(fluidStateKey as string, false);\n } else if (viewConverter !== undefined) {\n fluidMatchingMap.set(fluidStateKey as string, true);\n } else {\n throw Error(`Failed to find view converter for Fluid key ${fluidStateKey}`);\n }\n }\n\n if (viewToFluid !== undefined) {\n for (const viewStateKey of viewToFluid.keys()) {\n const value = viewToFluid.get(viewStateKey);\n if (value === undefined) {\n throw Error(\"Cannot find viewToFluid value\");\n }\n const {\n type,\n fluidKey,\n fluidConverter,\n } = value;\n const viewConverter = fluidToView.get(fluidKey);\n if (viewConverter === undefined) {\n throw Error(`Failed to find view converter for key ${fluidKey}`);\n }\n if (type === viewConverter.type) {\n viewMatchingMap.set(viewStateKey as string, false);\n } else if (fluidConverter !== undefined) {\n viewMatchingMap.set(viewStateKey as string, true);\n } else {\n throw Error(`Failed to find Fluid converter for view key ${viewStateKey}`);\n }\n }\n }\n\n return { viewMatchingMap, fluidMatchingMap, storedHandleMap };\n}\n"]}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
-
* Licensed under the MIT License.
|
|
4
|
-
*/
|
|
5
|
-
/**
|
|
6
|
-
* Return a partial Fluid state containing the view state key identified converted into its
|
|
7
|
-
* corresponding Fluid state value in the partial Fluid state returned
|
|
8
|
-
* @param state - The current view state
|
|
9
|
-
* @param viewKey - The view state key that needs to converted to its Fluid state
|
|
10
|
-
* @param viewToFluid - A map of the view state values that need conversion to their Fluid state counterparts and the
|
|
11
|
-
* respective converters
|
|
12
|
-
*/
|
|
13
|
-
export function getFluidFromView(state, viewKey, fluidState, viewToFluid) {
|
|
14
|
-
var _a;
|
|
15
|
-
const fluidConverter = (_a = viewToFluid === null || viewToFluid === void 0 ? void 0 : viewToFluid.get(viewKey)) === null || _a === void 0 ? void 0 : _a.fluidConverter;
|
|
16
|
-
if (fluidConverter !== undefined) {
|
|
17
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
18
|
-
return fluidConverter(state, fluidState);
|
|
19
|
-
}
|
|
20
|
-
else {
|
|
21
|
-
const partialFluidState = {};
|
|
22
|
-
partialFluidState[viewKey] = state[viewKey];
|
|
23
|
-
return partialFluidState;
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
//# sourceMappingURL=getFluidFromView.js.map
|