@fluidframework/react 0.41.4 → 2.63.0-358419
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
|
@@ -0,0 +1,327 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import {
|
|
7
|
+
PureDataObjectFactory,
|
|
8
|
+
TreeDataObject,
|
|
9
|
+
createDataObjectKind,
|
|
10
|
+
} from "@fluidframework/aqueduct/internal";
|
|
11
|
+
import type { IFluidLoadable } from "@fluidframework/core-interfaces";
|
|
12
|
+
import type { IFluidDataStoreFactory } from "@fluidframework/runtime-definitions/internal";
|
|
13
|
+
import type { SharedObjectKind } from "@fluidframework/shared-object-base";
|
|
14
|
+
import type {
|
|
15
|
+
SchemaCompatibilityStatus,
|
|
16
|
+
TreeViewConfiguration,
|
|
17
|
+
TreeFieldFromImplicitField,
|
|
18
|
+
TreeView,
|
|
19
|
+
ImplicitFieldSchema,
|
|
20
|
+
InsertableTreeFieldFromImplicitField,
|
|
21
|
+
} from "@fluidframework/tree";
|
|
22
|
+
import { configuredSharedTree, FormatValidatorBasic } from "@fluidframework/tree/internal";
|
|
23
|
+
import * as React from "react";
|
|
24
|
+
|
|
25
|
+
import { toPropTreeNode, type PropTreeValue } from "./propNode.js";
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Opt into extra validation to detect encoding bugs and data corruption.
|
|
29
|
+
* As long as this is an experimental package, opting into extra validation (at a small perf and bundle size cost) seems reasonable.
|
|
30
|
+
*/
|
|
31
|
+
const SharedTree = configuredSharedTree({
|
|
32
|
+
jsonValidator: FormatValidatorBasic,
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Defines a DataObject for a {@link @fluidframework/tree#SharedTree} with a built in {@link @fluidframework/tree#TreeViewConfiguration}.
|
|
37
|
+
* @param treeConfiguration - See {@link IReactTreeDataObject.config}.
|
|
38
|
+
* @param createInitialTree - Function which populates the tree with initial data on document create.
|
|
39
|
+
* @returns A {@link @fluidframework/fluid-static#DataObjectClass} to allow easy use of a SharedTree in a ContainerSchema.
|
|
40
|
+
* @alpha
|
|
41
|
+
*/
|
|
42
|
+
export function treeDataObject<TSchema extends ImplicitFieldSchema>(
|
|
43
|
+
treeConfiguration: TreeViewConfiguration<TSchema>,
|
|
44
|
+
createInitialTree: () => InsertableTreeFieldFromImplicitField<TSchema>,
|
|
45
|
+
): SharedObjectKind<IReactTreeDataObject<TSchema> & IFluidLoadable> {
|
|
46
|
+
return treeDataObjectInternal(treeConfiguration, createInitialTree);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Defines a DataObject for a {@link @fluidframework/tree#SharedTree} with a built in {@link @fluidframework/tree#TreeViewConfiguration}.
|
|
51
|
+
* @param treeConfiguration - See {@link IReactTreeDataObject.config}.
|
|
52
|
+
* @param createInitialTree - Function which populates the tree with initial data on document create.
|
|
53
|
+
* @returns A {@link @fluidframework/fluid-static#DataObjectClass} to allow easy use of a SharedTree in a ContainerSchema.
|
|
54
|
+
* @internal
|
|
55
|
+
*/
|
|
56
|
+
export function treeDataObjectInternal<TSchema extends ImplicitFieldSchema>(
|
|
57
|
+
treeConfiguration: TreeViewConfiguration<TSchema>,
|
|
58
|
+
createInitialTree: () => InsertableTreeFieldFromImplicitField<TSchema>,
|
|
59
|
+
): SharedObjectKind<IReactTreeDataObject<TSchema> & IFluidLoadable & TreeDataObject> & {
|
|
60
|
+
readonly factory: IFluidDataStoreFactory;
|
|
61
|
+
} {
|
|
62
|
+
class SchemaAwareTreeDataObject extends ReactTreeDataObject<TSchema> {
|
|
63
|
+
public override readonly config = treeConfiguration;
|
|
64
|
+
|
|
65
|
+
public static readonly factory = new PureDataObjectFactory<ReactTreeDataObject<TSchema>>(
|
|
66
|
+
`TreeDataObject`,
|
|
67
|
+
SchemaAwareTreeDataObject,
|
|
68
|
+
[SharedTree.getFactory()],
|
|
69
|
+
{},
|
|
70
|
+
);
|
|
71
|
+
|
|
72
|
+
#treeView: TreeView<TSchema> | undefined;
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* The schema-aware view of the tree.
|
|
76
|
+
*/
|
|
77
|
+
public get treeView(): TreeView<TSchema> {
|
|
78
|
+
if (this.#treeView === undefined) {
|
|
79
|
+
throw new Error("treeView has not been initialized.");
|
|
80
|
+
}
|
|
81
|
+
return this.#treeView;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Converts the underlying ITree into a typed TreeView using the provided schema configuration.
|
|
86
|
+
*
|
|
87
|
+
* @param tree - The ITree instance to view.
|
|
88
|
+
* @returns A typed TreeView using the TodoList schema.
|
|
89
|
+
*/
|
|
90
|
+
private initializeView(): void {
|
|
91
|
+
this.#treeView = this.tree.viewWith(this.config);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
protected override async initializingFirstTime(): Promise<void> {
|
|
95
|
+
this.initializeView();
|
|
96
|
+
this.treeView.initialize(createInitialTree());
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
protected override async initializingFromExisting(): Promise<void> {
|
|
100
|
+
this.initializeView();
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
return createDataObjectKind(SchemaAwareTreeDataObject);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* A schema-aware tree-backed DataObject, extended with a React Component to view the tree.
|
|
108
|
+
* @remarks Allows for the Tree's schema to be baked into the container schema.
|
|
109
|
+
* @sealed @alpha
|
|
110
|
+
*/
|
|
111
|
+
export interface IReactTreeDataObject<TSchema extends ImplicitFieldSchema> {
|
|
112
|
+
/**
|
|
113
|
+
* The configuration used to initialize new documents, as well as to interpret (schematize) existing ones.
|
|
114
|
+
*
|
|
115
|
+
* @remarks
|
|
116
|
+
* The fact that a single view schema is provided here (on the data object) makes it impossible to try and apply multiple different schema.
|
|
117
|
+
* Since the view schema currently does not provide any adapters for handling differences between view and stored schema,
|
|
118
|
+
* it's also impossible for this single view schema to handle multiple different stored schema.
|
|
119
|
+
* Therefore, with this current API, two different applications (or different versions of the same application)
|
|
120
|
+
* with differing stored schema requirements (as implied by their view schema) can not collaborate on the same tree.
|
|
121
|
+
* The only schema evolution that's currently possible is upgrading the schema to one that supports a superset of what the old schema allowed,
|
|
122
|
+
* and collaborating between clients which have view schema that exactly correspond to that stored schema.
|
|
123
|
+
* Future work on tree as well as these utilities should address this limitation.
|
|
124
|
+
*/
|
|
125
|
+
readonly config: TreeViewConfiguration<TSchema>;
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* The schema-aware view of the tree.
|
|
129
|
+
*/
|
|
130
|
+
readonly treeView: TreeView<TSchema>;
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* React component which handles schematizing trees.
|
|
134
|
+
* This includes displaying errors when the document can not be viewed using the view schema.
|
|
135
|
+
*
|
|
136
|
+
* @privateRemarks
|
|
137
|
+
* This is exposed as a member rather than a free function since type inference for the schema doesn't work when used as a free function,
|
|
138
|
+
* and thus making it a member avoids the user of this from having to explicitly provide the type parameter.
|
|
139
|
+
* This is an arrow function not a method so it gets the correct this when not called as a member.
|
|
140
|
+
*/
|
|
141
|
+
readonly TreeViewComponent: (props: TreeViewProps<TSchema>) => React.JSX.Element;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* React props for viewing a tree.
|
|
146
|
+
* @input @alpha
|
|
147
|
+
*/
|
|
148
|
+
export interface TreeViewProps<TSchema extends ImplicitFieldSchema> {
|
|
149
|
+
/**
|
|
150
|
+
* Component to display the tree content.
|
|
151
|
+
*/
|
|
152
|
+
readonly viewComponent: React.FC<{
|
|
153
|
+
root: PropTreeValue<TreeFieldFromImplicitField<TSchema>>;
|
|
154
|
+
}>;
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* Component to display instead of the {@link TreeViewProps.viewComponent}
|
|
158
|
+
* when tree content is not compatible with the {@link @fluidframework/tree#TreeViewConfiguration}.
|
|
159
|
+
*
|
|
160
|
+
* @defaultValue Component which describes the situation (in English) and allows the user to upgrade the schema to match the {@link @fluidframework/tree#TreeViewConfiguration} if possible.
|
|
161
|
+
*/
|
|
162
|
+
readonly errorComponent?: React.FC<SchemaIncompatibleProps>;
|
|
163
|
+
|
|
164
|
+
// TODO: Once its possible to query the status of individual schema upgrades, provide more options here for handling such cases.
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* Generic DataObject for shared trees.
|
|
169
|
+
* @internal
|
|
170
|
+
*/
|
|
171
|
+
export abstract class ReactTreeDataObject<
|
|
172
|
+
TSchema extends ImplicitFieldSchema = ImplicitFieldSchema,
|
|
173
|
+
>
|
|
174
|
+
extends TreeDataObject
|
|
175
|
+
implements IReactTreeDataObject<TSchema>
|
|
176
|
+
{
|
|
177
|
+
public abstract readonly config: TreeViewConfiguration<TSchema>;
|
|
178
|
+
|
|
179
|
+
#treeView: TreeView<TSchema> | undefined;
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* The schema-aware view of the tree.
|
|
183
|
+
*/
|
|
184
|
+
public get treeView(): TreeView<TSchema> {
|
|
185
|
+
if (this.#treeView === undefined) {
|
|
186
|
+
throw new Error("treeView has not been initialized.");
|
|
187
|
+
}
|
|
188
|
+
return this.#treeView;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/explicit-function-return-type
|
|
192
|
+
public readonly TreeViewComponent = ({
|
|
193
|
+
viewComponent,
|
|
194
|
+
errorComponent,
|
|
195
|
+
}: TreeViewProps<TSchema>) =>
|
|
196
|
+
TreeViewComponent<TSchema>({
|
|
197
|
+
tree: this,
|
|
198
|
+
viewComponent,
|
|
199
|
+
errorComponent,
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
function useViewCompatibility<TSchema extends ImplicitFieldSchema>(
|
|
204
|
+
view: TreeView<TSchema>,
|
|
205
|
+
): SchemaCompatibilityStatus {
|
|
206
|
+
const [compatibility, setCompatibility] = React.useState<SchemaCompatibilityStatus>(
|
|
207
|
+
view.compatibility,
|
|
208
|
+
);
|
|
209
|
+
|
|
210
|
+
React.useEffect(() => {
|
|
211
|
+
const updateCompatibility = (): void => {
|
|
212
|
+
setCompatibility(view.compatibility);
|
|
213
|
+
};
|
|
214
|
+
|
|
215
|
+
updateCompatibility();
|
|
216
|
+
return view.events.on("schemaChanged", updateCompatibility);
|
|
217
|
+
}, [view]);
|
|
218
|
+
|
|
219
|
+
return compatibility;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
function useViewRoot<TSchema extends ImplicitFieldSchema>(
|
|
223
|
+
view: TreeView<TSchema>,
|
|
224
|
+
): TreeFieldFromImplicitField<TSchema> | undefined {
|
|
225
|
+
const [root, setRoot] = React.useState<TreeFieldFromImplicitField<TSchema> | undefined>(
|
|
226
|
+
undefined,
|
|
227
|
+
);
|
|
228
|
+
|
|
229
|
+
React.useEffect(() => {
|
|
230
|
+
const updateRoot = (): void => {
|
|
231
|
+
if (view.compatibility.canView) {
|
|
232
|
+
setRoot(view.root);
|
|
233
|
+
} else {
|
|
234
|
+
setRoot(undefined);
|
|
235
|
+
}
|
|
236
|
+
};
|
|
237
|
+
|
|
238
|
+
updateRoot();
|
|
239
|
+
return view.events.on("rootChanged", updateRoot);
|
|
240
|
+
}, [view]);
|
|
241
|
+
|
|
242
|
+
return root;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
/**
|
|
246
|
+
* React component which handles schematizing trees.
|
|
247
|
+
* This includes displaying errors when the document can not be schematized.
|
|
248
|
+
* @alpha
|
|
249
|
+
*/
|
|
250
|
+
export function TreeViewComponent<TSchema extends ImplicitFieldSchema>({
|
|
251
|
+
tree,
|
|
252
|
+
viewComponent: ViewComponent,
|
|
253
|
+
errorComponent,
|
|
254
|
+
}: TreeViewProps<TSchema> & {
|
|
255
|
+
tree: Pick<IReactTreeDataObject<TSchema>, "treeView">;
|
|
256
|
+
}): React.JSX.Element {
|
|
257
|
+
const view = tree.treeView;
|
|
258
|
+
|
|
259
|
+
const compatibility = useViewCompatibility(view);
|
|
260
|
+
const root = useViewRoot(view);
|
|
261
|
+
const upgradeSchema = React.useCallback((): void => view.upgradeSchema(), [view]);
|
|
262
|
+
|
|
263
|
+
// Note: this policy is on the stricter side and ensures that clients will only be able to submit edits when their view schema
|
|
264
|
+
// supports exactly the same documents as the stored schema.
|
|
265
|
+
// A realistic production application using this strategy would need to take steps to attempt to open the document using
|
|
266
|
+
// several different view schemas in order to ensure that their users don't temporarily lose access to documents while
|
|
267
|
+
// code rollout is in progress.
|
|
268
|
+
// Alternative policies can be implemented, see "Schema Evolvability" in SharedTree's README for more information.
|
|
269
|
+
if (!compatibility.isEquivalent) {
|
|
270
|
+
const Error = errorComponent ?? TreeErrorComponent;
|
|
271
|
+
return <Error compatibility={compatibility} upgradeSchema={upgradeSchema} />;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
if (root === undefined) {
|
|
275
|
+
return <div>View not set</div>;
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
return <ViewComponent root={toPropTreeNode(root)} />;
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
/**
|
|
282
|
+
* React Props for displaying when the opened document is incompatible with the required view schema.
|
|
283
|
+
* @alpha
|
|
284
|
+
*/
|
|
285
|
+
export interface SchemaIncompatibleProps {
|
|
286
|
+
/**
|
|
287
|
+
* Information about the view schema's compatibility with the stored schema.
|
|
288
|
+
*/
|
|
289
|
+
readonly compatibility: SchemaCompatibilityStatus;
|
|
290
|
+
/**
|
|
291
|
+
* Callback to request that the stored schema in the document be upgraded.
|
|
292
|
+
*/
|
|
293
|
+
readonly upgradeSchema: () => void;
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
/**
|
|
297
|
+
* React component which displays schema errors and allows upgrading schema when possible.
|
|
298
|
+
*/
|
|
299
|
+
function TreeErrorComponent({
|
|
300
|
+
compatibility,
|
|
301
|
+
upgradeSchema,
|
|
302
|
+
}: {
|
|
303
|
+
compatibility: SchemaCompatibilityStatus;
|
|
304
|
+
upgradeSchema: () => void;
|
|
305
|
+
}): React.JSX.Element {
|
|
306
|
+
// eslint-disable-next-line unicorn/prefer-ternary
|
|
307
|
+
if (compatibility.canUpgrade) {
|
|
308
|
+
return (
|
|
309
|
+
<div>
|
|
310
|
+
<div>
|
|
311
|
+
Document is incompatible with current version of the application, but the document
|
|
312
|
+
format can be updated. This may prevent other versions of the application from
|
|
313
|
+
opening this document.
|
|
314
|
+
</div>
|
|
315
|
+
<button onClick={upgradeSchema}>Upgrade</button>;
|
|
316
|
+
</div>
|
|
317
|
+
);
|
|
318
|
+
} else {
|
|
319
|
+
return (
|
|
320
|
+
<div>
|
|
321
|
+
Document is incompatible with current version of the application, and the document
|
|
322
|
+
format cannot be updated. The document is likely from a newer or otherwise incompatible
|
|
323
|
+
version of the application, or a different application.
|
|
324
|
+
</div>
|
|
325
|
+
);
|
|
326
|
+
}
|
|
327
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
let counter = 0;
|
|
7
|
+
|
|
8
|
+
const idMap = new WeakMap<object, number>();
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Associates a unique number with an object.
|
|
12
|
+
* @remarks
|
|
13
|
+
* The ID number is tied to the object identity, not the object's contents; modifying the object will not cause it to get a different ID.
|
|
14
|
+
*
|
|
15
|
+
* This can be handy for generating {@link https://react.dev/learn/rendering-lists#where-to-get-your-key | keys for React lists} from TreeNodes.
|
|
16
|
+
*
|
|
17
|
+
* Most cases which could use this function should just use the objects themselves instead of getting IDs from them, since the objects will have the same equality as the IDs.
|
|
18
|
+
* For example, if storing data associated with the objects in a map, using the object as the key is more efficient than getting an ID from it and using that.
|
|
19
|
+
* This functions exists to deal with the edge case where you would like to use object identity, but you can't.
|
|
20
|
+
* React keys are an examples of such a case, since React does not allow objects as keys.
|
|
21
|
+
* @alpha
|
|
22
|
+
*/
|
|
23
|
+
export function objectIdNumber(object: object): number {
|
|
24
|
+
const id = idMap.get(object);
|
|
25
|
+
if (id !== undefined) {
|
|
26
|
+
return id;
|
|
27
|
+
}
|
|
28
|
+
counter++;
|
|
29
|
+
idMap.set(object, counter);
|
|
30
|
+
return counter;
|
|
31
|
+
}
|