@fluidframework/tree 2.2.0 → 2.3.0-288113
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/api-report/tree.alpha.api.md +39 -3
- package/api-report/tree.beta.api.md +8 -3
- package/api-report/tree.public.api.md +8 -3
- package/dist/beta.d.ts +1 -0
- package/dist/core/tree/anchorSet.d.ts +4 -6
- package/dist/core/tree/anchorSet.d.ts.map +1 -1
- package/dist/core/tree/anchorSet.js +11 -1
- package/dist/core/tree/anchorSet.js.map +1 -1
- package/dist/events/events.d.ts +7 -1
- package/dist/events/events.d.ts.map +1 -1
- package/dist/events/events.js +5 -2
- package/dist/events/events.js.map +1 -1
- package/dist/feature-libraries/flex-map-tree/mapTreeNode.d.ts +0 -2
- package/dist/feature-libraries/flex-map-tree/mapTreeNode.d.ts.map +1 -1
- package/dist/feature-libraries/flex-map-tree/mapTreeNode.js +0 -12
- package/dist/feature-libraries/flex-map-tree/mapTreeNode.js.map +1 -1
- package/dist/feature-libraries/flex-tree/flexTreeTypes.d.ts +4 -95
- package/dist/feature-libraries/flex-tree/flexTreeTypes.d.ts.map +1 -1
- package/dist/feature-libraries/flex-tree/flexTreeTypes.js +1 -30
- package/dist/feature-libraries/flex-tree/flexTreeTypes.js.map +1 -1
- package/dist/feature-libraries/flex-tree/index.d.ts +2 -2
- package/dist/feature-libraries/flex-tree/index.d.ts.map +1 -1
- package/dist/feature-libraries/flex-tree/index.js +1 -3
- package/dist/feature-libraries/flex-tree/index.js.map +1 -1
- package/dist/feature-libraries/flex-tree/lazyField.d.ts +0 -1
- package/dist/feature-libraries/flex-tree/lazyField.d.ts.map +1 -1
- package/dist/feature-libraries/flex-tree/lazyField.js +0 -3
- package/dist/feature-libraries/flex-tree/lazyField.js.map +1 -1
- package/dist/feature-libraries/flex-tree/lazyNode.d.ts +3 -10
- package/dist/feature-libraries/flex-tree/lazyNode.d.ts.map +1 -1
- package/dist/feature-libraries/flex-tree/lazyNode.js +2 -87
- package/dist/feature-libraries/flex-tree/lazyNode.js.map +1 -1
- package/dist/feature-libraries/index.d.ts +1 -1
- package/dist/feature-libraries/index.d.ts.map +1 -1
- package/dist/feature-libraries/index.js +2 -4
- package/dist/feature-libraries/index.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +36 -31
- package/dist/index.js.map +1 -1
- package/dist/packageVersion.d.ts +1 -1
- package/dist/packageVersion.d.ts.map +1 -1
- package/dist/packageVersion.js +1 -1
- package/dist/packageVersion.js.map +1 -1
- package/dist/public.d.ts +1 -0
- package/dist/simple-tree/api/treeNodeApi.d.ts +1 -1
- package/dist/simple-tree/api/treeNodeApi.d.ts.map +1 -1
- package/dist/simple-tree/api/treeNodeApi.js +30 -2
- package/dist/simple-tree/api/treeNodeApi.js.map +1 -1
- package/dist/simple-tree/arrayNode.d.ts.map +1 -1
- package/dist/simple-tree/arrayNode.js +5 -19
- package/dist/simple-tree/arrayNode.js.map +1 -1
- package/dist/simple-tree/core/index.d.ts +1 -1
- package/dist/simple-tree/core/index.d.ts.map +1 -1
- package/dist/simple-tree/core/index.js.map +1 -1
- package/dist/simple-tree/core/treeNodeKernel.d.ts +18 -5
- package/dist/simple-tree/core/treeNodeKernel.d.ts.map +1 -1
- package/dist/simple-tree/core/treeNodeKernel.js +57 -21
- package/dist/simple-tree/core/treeNodeKernel.js.map +1 -1
- package/dist/simple-tree/core/types.d.ts +28 -10
- package/dist/simple-tree/core/types.d.ts.map +1 -1
- package/dist/simple-tree/core/types.js.map +1 -1
- package/dist/simple-tree/index.d.ts +1 -1
- package/dist/simple-tree/index.d.ts.map +1 -1
- package/dist/simple-tree/index.js.map +1 -1
- package/lib/beta.d.ts +1 -0
- package/lib/core/tree/anchorSet.d.ts +4 -6
- package/lib/core/tree/anchorSet.d.ts.map +1 -1
- package/lib/core/tree/anchorSet.js +11 -1
- package/lib/core/tree/anchorSet.js.map +1 -1
- package/lib/events/events.d.ts +7 -1
- package/lib/events/events.d.ts.map +1 -1
- package/lib/events/events.js +5 -2
- package/lib/events/events.js.map +1 -1
- package/lib/feature-libraries/flex-map-tree/mapTreeNode.d.ts +0 -2
- package/lib/feature-libraries/flex-map-tree/mapTreeNode.d.ts.map +1 -1
- package/lib/feature-libraries/flex-map-tree/mapTreeNode.js +0 -12
- package/lib/feature-libraries/flex-map-tree/mapTreeNode.js.map +1 -1
- package/lib/feature-libraries/flex-tree/flexTreeTypes.d.ts +4 -95
- package/lib/feature-libraries/flex-tree/flexTreeTypes.d.ts.map +1 -1
- package/lib/feature-libraries/flex-tree/flexTreeTypes.js +0 -29
- package/lib/feature-libraries/flex-tree/flexTreeTypes.js.map +1 -1
- package/lib/feature-libraries/flex-tree/index.d.ts +2 -2
- package/lib/feature-libraries/flex-tree/index.d.ts.map +1 -1
- package/lib/feature-libraries/flex-tree/index.js +1 -1
- package/lib/feature-libraries/flex-tree/index.js.map +1 -1
- package/lib/feature-libraries/flex-tree/lazyField.d.ts +0 -1
- package/lib/feature-libraries/flex-tree/lazyField.d.ts.map +1 -1
- package/lib/feature-libraries/flex-tree/lazyField.js +0 -3
- package/lib/feature-libraries/flex-tree/lazyField.js.map +1 -1
- package/lib/feature-libraries/flex-tree/lazyNode.d.ts +3 -10
- package/lib/feature-libraries/flex-tree/lazyNode.d.ts.map +1 -1
- package/lib/feature-libraries/flex-tree/lazyNode.js +3 -86
- package/lib/feature-libraries/flex-tree/lazyNode.js.map +1 -1
- package/lib/feature-libraries/index.d.ts +1 -1
- package/lib/feature-libraries/index.d.ts.map +1 -1
- package/lib/feature-libraries/index.js +1 -1
- package/lib/feature-libraries/index.js.map +1 -1
- package/lib/index.d.ts +2 -2
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +4 -0
- package/lib/index.js.map +1 -1
- package/lib/packageVersion.d.ts +1 -1
- package/lib/packageVersion.d.ts.map +1 -1
- package/lib/packageVersion.js +1 -1
- package/lib/packageVersion.js.map +1 -1
- package/lib/public.d.ts +1 -0
- package/lib/simple-tree/api/treeNodeApi.d.ts +1 -1
- package/lib/simple-tree/api/treeNodeApi.d.ts.map +1 -1
- package/lib/simple-tree/api/treeNodeApi.js +30 -2
- package/lib/simple-tree/api/treeNodeApi.js.map +1 -1
- package/lib/simple-tree/arrayNode.d.ts.map +1 -1
- package/lib/simple-tree/arrayNode.js +5 -19
- package/lib/simple-tree/arrayNode.js.map +1 -1
- package/lib/simple-tree/core/index.d.ts +1 -1
- package/lib/simple-tree/core/index.d.ts.map +1 -1
- package/lib/simple-tree/core/index.js.map +1 -1
- package/lib/simple-tree/core/treeNodeKernel.d.ts +18 -5
- package/lib/simple-tree/core/treeNodeKernel.d.ts.map +1 -1
- package/lib/simple-tree/core/treeNodeKernel.js +58 -22
- package/lib/simple-tree/core/treeNodeKernel.js.map +1 -1
- package/lib/simple-tree/core/types.d.ts +28 -10
- package/lib/simple-tree/core/types.d.ts.map +1 -1
- package/lib/simple-tree/core/types.js.map +1 -1
- package/lib/simple-tree/index.d.ts +1 -1
- package/lib/simple-tree/index.d.ts.map +1 -1
- package/lib/simple-tree/index.js.map +1 -1
- package/package.json +22 -32
- package/src/core/tree/anchorSet.ts +20 -9
- package/src/events/events.ts +10 -2
- package/src/feature-libraries/flex-map-tree/mapTreeNode.ts +0 -21
- package/src/feature-libraries/flex-tree/flexTreeTypes.ts +3 -170
- package/src/feature-libraries/flex-tree/index.ts +1 -17
- package/src/feature-libraries/flex-tree/lazyField.ts +0 -6
- package/src/feature-libraries/flex-tree/lazyNode.ts +3 -154
- package/src/feature-libraries/index.ts +0 -14
- package/src/index.ts +8 -0
- package/src/packageVersion.ts +1 -1
- package/src/simple-tree/api/treeNodeApi.ts +37 -5
- package/src/simple-tree/arrayNode.ts +3 -12
- package/src/simple-tree/core/index.ts +1 -0
- package/src/simple-tree/core/treeNodeKernel.ts +88 -29
- package/src/simple-tree/core/types.ts +35 -9
- package/src/simple-tree/index.ts +1 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"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C,WAAW,EAAE,QAAQ,CAAC,CAAC,CAAC,IAAI,GAAG,EAAE,EAAE;YACtD,MAAM,EAAE,KAAK;YACb,KAAK,EAAE,CAAC;SACR,CAAqC,CAAC;IACxC,CAAC;IACD,IAAI,WAAW,CAAC,IAAI,KAAK,UAAU,CAAC,QAAQ,EAAE,CAAC;QAC9C,OAAO,CACN,QAAQ,CAAC,MAAM,GAAG,CAAC;YAClB,CAAC,CAAC,YAAY,CAAC,WAAW,EAAE,QAAQ,CAAC,CAAC,CAAC,IAAI,GAAG,EAAE,EAAE;gBAChD,MAAM,EAAE,KAAK;gBACb,KAAK,EAAE,CAAC;aACR,CAAC;YACH,CAAC,CAAC,SAAS,CACwB,CAAC;IACvC,CAAC;IAED,OAAO,gBAAgB,CAAC,UAAU,EAAE,GAAG,EAAE,WAAW,CAAqC,CAAC;AAC3F,CAAC;AAED,4CAA4C;AAE5C,MAAM,UAAU,qBAAqB,CAAC,OAAgB;IACrD,OAAO,IAAI,UAAU,CACpB,GACC,OAAO,IAAI,WACZ,4EAA4E,CAC5E,CAAC;AACH,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert, oob } from \"@fluidframework/core-utils/internal\";\nimport {\n\ttype AnchorNode,\n\tEmptyKey,\n\ttype ExclusiveMapTree,\n\ttype FieldKey,\n\ttype FieldUpPath,\n\ttype MapTree,\n\ttype TreeNodeSchemaIdentifier,\n\ttype TreeValue,\n\ttype Value,\n} from \"../../core/index.js\";\nimport { brand, fail, getOrCreate, mapIterable } from \"../../util/index.js\";\nimport {\n\tFlexTreeEntityKind,\n\ttype FlexTreeField,\n\ttype FlexTreeLeafNode,\n\ttype FlexTreeMapNode,\n\ttype FlexTreeNode,\n\ttype FlexTreeOptionalField,\n\ttype FlexTreeRequiredField,\n\ttype FlexTreeSequenceField,\n\ttype FlexTreeTypedField,\n\ttype FlexTreeTypedNode,\n\ttype FlexTreeTypedNodeUnion,\n\ttype FlexTreeUnboxField,\n\ttype FlexTreeUnboxNodeUnion,\n\tflexTreeMarker,\n\tindexForAt,\n} from \"../flex-tree/index.js\";\nimport {\n\ttype FlexAllowedTypes,\n\tFlexFieldSchema,\n\ttype FlexMapNodeSchema,\n\ttype FlexTreeNodeSchema,\n\ttype LeafNodeSchema,\n\tisLazy,\n\tschemaIsLeaf,\n\tschemaIsMap,\n\tschemaIsObjectNode,\n} from \"../typed-schema/index.js\";\nimport { type FlexImplicitAllowedTypes, normalizeAllowedTypes } from \"../schemaBuilderBase.js\";\nimport type { FlexFieldKind } from \"../modular-schema/index.js\";\nimport { FieldKinds, type SequenceFieldEditBuilder } from \"../default-schema/index.js\";\nimport { UsageError } from \"@fluidframework/telemetry-utils/internal\";\n\n// #region Nodes\n\n/**\n * A readonly {@link FlexTreeNode} which wraps a {@link MapTree}.\n * @remarks Reading data from the MapTreeNode will read the corresponding data from the {@link MapTree}.\n * Create a `MapTreeNode` by calling {@link getOrCreateMapTreeNode}.\n */\nexport interface MapTreeNode extends FlexTreeNode {\n\treadonly mapTree: MapTree;\n}\n\n/**\n * Checks if the given {@link FlexTreeNode} is a {@link MapTreeNode}.\n */\nexport function isMapTreeNode(flexNode: FlexTreeNode): flexNode is MapTreeNode {\n\treturn flexNode instanceof EagerMapTreeNode;\n}\n\n/**\n * Checks if the given {@link FlexTreeField} is a {@link MapTreeSequenceField}.\n */\nexport function isMapTreeSequenceField<T extends FlexAllowedTypes>(\n\tfield: FlexTreeSequenceField<T> | FlexTreeField,\n): field is MapTreeSequenceField<T> {\n\treturn field instanceof EagerMapTreeSequenceField;\n}\n\n/**\n * An unhydrated {@link FlexTreeSequenceField}, which has additional editing capabilities.\n * @remarks When doing a removal edit, a {@link MapTreeSequenceField}'s `editor` returns ownership of the removed {@link ExclusiveMapTree}s to the caller.\n */\nexport interface MapTreeSequenceField<T extends FlexAllowedTypes>\n\textends FlexTreeSequenceField<T> {\n\treadonly editor: MapTreeSequenceFieldEditBuilder;\n}\n\ninterface MapTreeSequenceFieldEditBuilder\n\textends SequenceFieldEditBuilder<ExclusiveMapTree[]> {\n\t/**\n\t * Issues a change which removes `count` elements starting at the given `index`.\n\t * @param index - The index of the first removed element.\n\t * @param count - The number of elements to remove.\n\t * @returns the MapTrees that were removed\n\t */\n\tremove(index: number, count: number): ExclusiveMapTree[];\n}\n\n/** A node's parent field and its index in that field */\ninterface LocationInField {\n\treadonly parent: MapTreeField;\n\treadonly index: number;\n}\n\n/**\n * A readonly implementation of {@link FlexTreeNode} which wraps a {@link MapTree}.\n * @remarks Any methods that would mutate the node will fail,\n * as will the querying of data specific to the {@link LazyTreeNode} implementation (e.g. {@link FlexTreeNode.context}).\n * MapTreeNodes are unconditionally cached -\n * when retrieved via {@link getOrCreateNode}, the same {@link MapTree} object will always produce the same `MapTreeNode` object.\n */\nexport class EagerMapTreeNode<TSchema extends FlexTreeNodeSchema> implements MapTreeNode {\n\tpublic readonly [flexTreeMarker] = FlexTreeEntityKind.Node as const;\n\n\t/**\n\t * Create a new MapTreeNode.\n\t * @param location - the parentage of this node, if it is being created underneath an existing node and field, or undefined if not\n\t * @remarks This class (and its subclasses) should not be directly constructed outside of this module.\n\t * Instead, use {@link getOrCreateNode} to create a MapTreeNode from a {@link MapTree}.\n\t * A `MapTreeNode` may never be constructed more than once for the same {@link MapTree} object.\n\t * Instead, it should always be acquired via {@link getOrCreateNode}.\n\t */\n\tpublic constructor(\n\t\tpublic readonly schema: TSchema,\n\t\t/** The underlying {@link MapTree} that this `MapTreeNode` reads its data from */\n\t\tpublic readonly mapTree: ExclusiveMapTree,\n\t\tprivate location = unparentedLocation,\n\t) {\n\t\tassert(!nodeCache.has(mapTree), 0x98b /* A node already exists for the given MapTree */);\n\t\tnodeCache.set(mapTree, this);\n\n\t\t// Fully demand the tree to ensure that parent pointers are present and accurate on all nodes.\n\t\t// When a MapTreeNode is constructed, its MapTree may contain nodes (anywhere below) that map (via the `nodeCache`) to pre-existing MapTreeNodes.\n\t\t// Put another way, for a given MapTree, some ancestor MapTreeNode can be created after any number of its descendant MapTreeNodes already exist.\n\t\t// In such a case, the spine of nodes between the descendant and ancestor need to exist in order for the ancestor to be able to walk upwards via the `parentField` property.\n\t\t// This needs to happen for all MapTreeNodes that are descendants of the ancestor MapTreeNode.\n\t\t// Demanding the entire tree is overkill to solve this problem since not all descendant MapTree nodes will have corresponding MapTreeNodes.\n\t\t// However, demanding the full tree also lets us eagerly validate that there are no duplicate MapTrees (i.e. same MapTree object) anywhere in the tree.\n\t\tthis.walkTree();\n\t}\n\n\tpublic get type(): TreeNodeSchemaIdentifier {\n\t\treturn this.schema.name;\n\t}\n\n\t/**\n\t * Set this node's parentage (see {@link FlexTreeNode.parentField}).\n\t * @remarks The node may be given a parent if it has none, or may have its parent removed (by passing `undefined`).\n\t * However, a node with a parent may not be directly re-assigned a different parent.\n\t * That likely indicates either an attempted multi-parenting or an attempt to \"move\" the node, neither of which are supported.\n\t * Removing a node's parent twice in a row is also not supported, as it likely indicates a bug.\n\t */\n\tpublic adoptBy(parent: undefined): void;\n\tpublic adoptBy(parent: MapTreeField, index: number): void;\n\tpublic adoptBy(parent: MapTreeField | undefined, index?: number): void {\n\t\tif (parent !== undefined) {\n\t\t\tassert(\n\t\t\t\tthis.location === unparentedLocation,\n\t\t\t\t0x98c /* Node may not be adopted if it already has a parent */,\n\t\t\t);\n\t\t\tassert(index !== undefined, 0xa08 /* Expected index */);\n\t\t\tthis.location = { parent, index };\n\t\t} else {\n\t\t\tassert(\n\t\t\t\tthis.location !== unparentedLocation,\n\t\t\t\t0xa09 /* Node may not be un-adopted if it does not have a parent */,\n\t\t\t);\n\t\t\tthis.location = unparentedLocation;\n\t\t}\n\t}\n\n\t/**\n\t * The field this tree is in, and the index within that field.\n\t * @remarks If this node is unparented, this method will return the special {@link unparentedLocation} as the parent.\n\t */\n\tpublic get parentField(): LocationInField {\n\t\treturn this.location;\n\t}\n\n\tpublic is<TSchemaInner extends FlexTreeNodeSchema>(\n\t\tschema: TSchemaInner,\n\t): this is FlexTreeTypedNode<TSchemaInner> {\n\t\treturn (schema as unknown) === this.schema;\n\t}\n\n\tpublic tryGetField(key: FieldKey): EagerMapTreeField<FlexAllowedTypes> | undefined {\n\t\tconst field = this.mapTree.fields.get(key);\n\t\t// Only return the field if it is not empty, in order to fulfill the contract of `tryGetField`.\n\t\tif (field !== undefined && field.length > 0) {\n\t\t\treturn getOrCreateField(this, key, this.schema.getFieldSchema(key));\n\t\t}\n\t}\n\n\tpublic getBoxed(key: string): FlexTreeField {\n\t\tconst fieldKey: FieldKey = brand(key);\n\t\treturn getOrCreateField(this, fieldKey, this.schema.getFieldSchema(fieldKey));\n\t}\n\n\tpublic boxedIterator(): IterableIterator<FlexTreeField> {\n\t\treturn mapIterable(this.mapTree.fields.entries(), ([key]) =>\n\t\t\tgetOrCreateField(this, key, this.schema.getFieldSchema(key)),\n\t\t);\n\t}\n\n\tpublic get value(): Value {\n\t\treturn this.mapTree.value;\n\t}\n\n\tpublic context = undefined;\n\n\tpublic get anchorNode(): AnchorNode {\n\t\t// This API is relevant to `LazyTreeNode`s, but not `MapTreeNode`s.\n\t\t// TODO: Refactor the FlexTreeNode interface so that stubbing this out isn't necessary.\n\t\treturn fail(\"MapTreeNode does not implement anchorNode\");\n\t}\n\n\tprivate walkTree(): void {\n\t\tfor (const [key, mapTrees] of this.mapTree.fields) {\n\t\t\tconst field = getOrCreateField(this, key, this.schema.getFieldSchema(key));\n\t\t\tfor (let index = 0; index < field.length; index++) {\n\t\t\t\tconst child = getOrCreateChild(\n\t\t\t\t\tmapTrees[index] ?? oob(),\n\t\t\t\t\tthis.schema.getFieldSchema(key).allowedTypes,\n\t\t\t\t\t{ parent: field, index },\n\t\t\t\t);\n\t\t\t\t// These next asserts detect the case where `getOrCreateChild` gets a cache hit of a different node than the one we're trying to create\n\t\t\t\tassert(child.location !== undefined, 0x98d /* Expected node to have parent */);\n\t\t\t\tassert(\n\t\t\t\t\tchild.location.parent.parent === this,\n\t\t\t\t\t0x98e /* Node may not be multi-parented */,\n\t\t\t\t);\n\t\t\t\tassert(child.location.index === index, 0x98f /* Node may not be multi-parented */);\n\t\t\t\tchild.walkTree();\n\t\t\t}\n\t\t}\n\t}\n}\n\n/**\n * The implementation of a map node created by {@link getOrCreateNode}.\n */\nexport class EagerMapTreeMapNode<TSchema extends FlexMapNodeSchema>\n\textends EagerMapTreeNode<TSchema>\n\timplements FlexTreeMapNode<TSchema>\n{\n\tpublic keys(): IterableIterator<FieldKey> {\n\t\treturn this.mapTree.fields.keys();\n\t}\n\n\tpublic values(): IterableIterator<FlexTreeUnboxField<TSchema[\"info\"], \"notEmpty\">> {\n\t\treturn mapIterable(\n\t\t\tthis.mapTree.fields.keys(),\n\t\t\t(key) =>\n\t\t\t\tunboxedField(\n\t\t\t\t\tthis.tryGetField(key) ?? fail(\"Unexpected empty map field\"),\n\t\t\t\t\tkey,\n\t\t\t\t\tthis.mapTree,\n\t\t\t\t\tthis,\n\t\t\t\t) as FlexTreeUnboxField<TSchema[\"info\"], \"notEmpty\">,\n\t\t);\n\t}\n\n\tpublic entries(): IterableIterator<\n\t\t[FieldKey, FlexTreeUnboxField<TSchema[\"info\"], \"notEmpty\">]\n\t> {\n\t\treturn mapIterable(this.mapTree.fields.keys(), (key) => [\n\t\t\tkey,\n\t\t\tunboxedField(\n\t\t\t\tthis.tryGetField(key) ?? fail(\"Unexpected empty map field\"),\n\t\t\t\tkey,\n\t\t\t\tthis.mapTree,\n\t\t\t\tthis,\n\t\t\t) as FlexTreeUnboxField<TSchema[\"info\"], \"notEmpty\">,\n\t\t]);\n\t}\n\n\tpublic forEach(\n\t\tcallbackFn: (\n\t\t\tvalue: FlexTreeUnboxField<TSchema[\"info\"], \"notEmpty\">,\n\t\t\tkey: FieldKey,\n\t\t\tmap: FlexTreeMapNode<TSchema>,\n\t\t) => void,\n\t\tthisArg?: unknown,\n\t): void {\n\t\tconst fn = thisArg !== undefined ? callbackFn.bind(thisArg) : callbackFn;\n\t\tfor (const [key, value] of this.entries()) {\n\t\t\tfn(value, key, this);\n\t\t}\n\t}\n\n\tpublic override getBoxed(key: string): FlexTreeTypedField<TSchema[\"info\"]> {\n\t\treturn super.getBoxed(key) as FlexTreeTypedField<TSchema[\"info\"]>;\n\t}\n\n\tpublic [Symbol.iterator](): IterableIterator<\n\t\t[FieldKey, FlexTreeUnboxField<TSchema[\"info\"], \"notEmpty\">]\n\t> {\n\t\treturn this.entries();\n\t}\n\n\tpublic override boxedIterator(): IterableIterator<FlexTreeTypedField<TSchema[\"info\"]>> {\n\t\treturn super.boxedIterator() as IterableIterator<FlexTreeTypedField<TSchema[\"info\"]>>;\n\t}\n}\n\nclass EagerMapTreeLeafNode<TSchema extends LeafNodeSchema>\n\textends EagerMapTreeNode<TSchema>\n\timplements FlexTreeLeafNode<TSchema>\n{\n\tpublic override get value(): TreeValue<TSchema[\"info\"]> {\n\t\treturn super.value as TreeValue<TSchema[\"info\"]>;\n\t}\n}\n\n// #endregion Nodes\n\n// #region Fields\n\n/**\n * A readonly {@link FlexTreeField} which wraps an array of {@link MapTrees}.\n * @remarks Reading data from the MapTreeField will read the corresponding data from the {@link MapTree}s.\n * Create a `MapTreeField` by calling {@link getOrCreateField}.\n */\ninterface MapTreeField extends FlexTreeField {\n\treadonly mapTrees: readonly MapTree[];\n}\n\n/**\n * A special singleton that is the implicit {@link LocationInField} of all un-parented {@link EagerMapTreeNode}s.\n * @remarks This exists because {@link EagerMapTreeNode.parentField} must return a field.\n * If a {@link EagerMapTreeNode} is created without a parent, its {@link EagerMapTreeNode.parentField} property will point to this object.\n * However, this field cannot be used in any practical way because it is empty, i.e. it does not actually contain the children that claim to be parented under it.\n * It has the \"empty\" schema and it will always contain zero children if queried.\n * Any nodes with this location will have a dummy parent index of `-1`.\n */\nconst unparentedLocation: LocationInField = {\n\tparent: {\n\t\t[flexTreeMarker]: FlexTreeEntityKind.Field as const,\n\t\tlength: 0,\n\t\tkey: EmptyKey,\n\t\tparent: undefined,\n\t\tis<TSchema extends FlexFieldSchema>(schema: TSchema) {\n\t\t\treturn schema === (FlexFieldSchema.empty as FlexFieldSchema);\n\t\t},\n\t\tboxedIterator(): IterableIterator<FlexTreeNode> {\n\t\t\treturn [].values();\n\t\t},\n\t\tboxedAt(index: number): FlexTreeNode | undefined {\n\t\t\treturn undefined;\n\t\t},\n\t\tschema: FlexFieldSchema.empty,\n\t\tcontext: undefined,\n\t\tmapTrees: [],\n\t},\n\tindex: -1,\n};\n\nclass EagerMapTreeField<T extends FlexAllowedTypes> implements MapTreeField {\n\tpublic [flexTreeMarker] = FlexTreeEntityKind.Field as const;\n\n\tpublic constructor(\n\t\tpublic readonly schema: FlexFieldSchema<FlexFieldKind, T>,\n\t\tpublic readonly key: FieldKey,\n\t\tpublic readonly parent: EagerMapTreeNode<FlexTreeNodeSchema>,\n\t) {\n\t\tconst fieldKeyCache = getFieldKeyCache(parent);\n\t\tassert(!fieldKeyCache.has(key), 0x990 /* A field already exists for the given MapTrees */);\n\t\tfieldKeyCache.set(key, this);\n\n\t\t// When this field is created (which only happens one time, because it is cached), all the children become parented for the first time.\n\t\t// \"Adopt\" each child by updating its parent information to point to this field.\n\t\tfor (const [i, mapTree] of this.mapTrees.entries()) {\n\t\t\tconst mapTreeNodeChild = nodeCache.get(mapTree);\n\t\t\tif (mapTreeNodeChild !== undefined) {\n\t\t\t\tif (mapTreeNodeChild.parentField !== unparentedLocation) {\n\t\t\t\t\tthrow new UsageError(\"A node may not be in more than one place in the tree\");\n\t\t\t\t}\n\t\t\t\tmapTreeNodeChild.adoptBy(this, i);\n\t\t\t}\n\t\t}\n\t}\n\n\tpublic get mapTrees(): readonly ExclusiveMapTree[] {\n\t\treturn this.parent.mapTree.fields.get(this.key) ?? [];\n\t}\n\n\tpublic get length(): number {\n\t\treturn this.mapTrees.length;\n\t}\n\n\tpublic is<TSchemaInner extends FlexFieldSchema>(\n\t\tschema: TSchemaInner,\n\t): this is FlexTreeTypedField<TSchemaInner> {\n\t\treturn this.schema.equals(schema);\n\t}\n\n\tpublic boxedIterator(): IterableIterator<FlexTreeTypedNodeUnion<T>> {\n\t\treturn this.mapTrees\n\t\t\t.map(\n\t\t\t\t(m, index) =>\n\t\t\t\t\tgetOrCreateChild(m, this.schema.allowedTypes, {\n\t\t\t\t\t\tparent: this,\n\t\t\t\t\t\tindex,\n\t\t\t\t\t}) as FlexTreeNode as FlexTreeTypedNodeUnion<T>,\n\t\t\t)\n\t\t\t.values();\n\t}\n\n\tpublic boxedAt(index: number): FlexTreeTypedNodeUnion<T> | undefined {\n\t\tconst i = indexForAt(index, this.length);\n\t\tif (i === undefined) {\n\t\t\treturn undefined;\n\t\t}\n\t\tconst m = this.mapTrees[i];\n\t\tif (m !== undefined) {\n\t\t\treturn getOrCreateChild(m, this.schema.allowedTypes, {\n\t\t\t\tparent: this,\n\t\t\t\tindex: i,\n\t\t\t}) as FlexTreeNode as FlexTreeTypedNodeUnion<T>;\n\t\t}\n\t}\n\n\tpublic context: undefined;\n\n\t/**\n\t * Mutate this field.\n\t * @param edit - A function which receives the current `MapTree`s that comprise the contents of the field so that it may be mutated.\n\t * The function may mutate the array in place or return a new array.\n\t * If a new array is returned then it will be used as the new contents of the field, otherwise the original array will be continue to be used.\n\t * @remarks All edits to the field (i.e. mutations of the field's MapTrees) should be directed through this function.\n\t * This function ensures that the parent MapTree has no empty fields (which is an invariant of `MapTree`) after the mutation.\n\t */\n\tprotected edit(edit: (mapTrees: ExclusiveMapTree[]) => void | ExclusiveMapTree[]): void {\n\t\tconst oldMapTrees = this.parent.mapTree.fields.get(this.key) ?? [];\n\t\tconst newMapTrees = edit(oldMapTrees) ?? oldMapTrees;\n\t\tif (newMapTrees.length > 0) {\n\t\t\tthis.parent.mapTree.fields.set(this.key, newMapTrees);\n\t\t} else {\n\t\t\tthis.parent.mapTree.fields.delete(this.key);\n\t\t}\n\t}\n}\n\nclass EagerMapTreeOptionalField<T extends FlexAllowedTypes>\n\textends EagerMapTreeField<T>\n\timplements FlexTreeOptionalField<T>\n{\n\tpublic readonly editor = {\n\t\tset: (newContent: ExclusiveMapTree | undefined): void => {\n\t\t\t// If the new content is a MapTreeNode, it needs to have its parent pointer updated\n\t\t\tif (newContent !== undefined) {\n\t\t\t\tnodeCache.get(newContent)?.adoptBy(this, 0);\n\t\t\t}\n\t\t\t// If the old content is a MapTreeNode, it needs to have its parent pointer unset\n\t\t\tconst oldContent = this.mapTrees[0];\n\t\t\tif (oldContent !== undefined) {\n\t\t\t\tnodeCache.get(oldContent)?.adoptBy(undefined);\n\t\t\t}\n\n\t\t\tthis.edit((mapTrees) => {\n\t\t\t\tif (newContent !== undefined) {\n\t\t\t\t\tmapTrees[0] = newContent;\n\t\t\t\t} else {\n\t\t\t\t\tmapTrees.length = 0;\n\t\t\t\t}\n\t\t\t});\n\t\t},\n\t};\n\n\tpublic get content(): FlexTreeUnboxNodeUnion<T> | undefined {\n\t\tconst value = this.mapTrees[0];\n\t\tif (value !== undefined) {\n\t\t\treturn unboxedUnion(this.schema, value, {\n\t\t\t\tparent: this,\n\t\t\t\tindex: 0,\n\t\t\t});\n\t\t}\n\n\t\treturn undefined;\n\t}\n}\n\nclass EagerMapTreeRequiredField<T extends FlexAllowedTypes>\n\textends EagerMapTreeOptionalField<T>\n\timplements FlexTreeRequiredField<T>\n{\n\tpublic override get content(): FlexTreeUnboxNodeUnion<T> {\n\t\treturn super.content ?? fail(\"Expected EagerMapTree required field to have a value\");\n\t}\n}\n\nclass EagerMapTreeSequenceField<T extends FlexAllowedTypes>\n\textends EagerMapTreeField<T>\n\timplements FlexTreeSequenceField<T>\n{\n\tpublic readonly editor: MapTreeSequenceFieldEditBuilder = {\n\t\tinsert: (index, newContent): void => {\n\t\t\tfor (let i = 0; i < newContent.length; i++) {\n\t\t\t\tconst c = newContent[i];\n\t\t\t\tassert(c !== undefined, 0xa0a /* Unexpected sparse array content */);\n\t\t\t\tnodeCache.get(c)?.adoptBy(this, index + i);\n\t\t\t}\n\t\t\tthis.edit((mapTrees) => {\n\t\t\t\tif (newContent.length < 1000) {\n\t\t\t\t\t// For \"smallish arrays\" (`1000` is not empirically derived), the `splice` function is appropriate...\n\t\t\t\t\tmapTrees.splice(index, 0, ...newContent);\n\t\t\t\t} else {\n\t\t\t\t\t// ...but we avoid using `splice` + spread for very large input arrays since there is a limit on how many elements can be spread (too many will overflow the stack).\n\t\t\t\t\treturn mapTrees.slice(0, index).concat(newContent, mapTrees.slice(index));\n\t\t\t\t}\n\t\t\t});\n\t\t},\n\t\tremove: (index, count): ExclusiveMapTree[] => {\n\t\t\tfor (let i = index; i < index + count; i++) {\n\t\t\t\tconst c = this.mapTrees[i];\n\t\t\t\tassert(c !== undefined, 0xa0b /* Unexpected sparse array */);\n\t\t\t\tnodeCache.get(c)?.adoptBy(undefined);\n\t\t\t}\n\t\t\tlet removed: ExclusiveMapTree[] | undefined;\n\t\t\tthis.edit((mapTrees) => {\n\t\t\t\tremoved = mapTrees.splice(index, count);\n\t\t\t});\n\t\t\treturn removed ?? fail(\"Expected removed to be set by edit\");\n\t\t},\n\t};\n\n\tpublic at(index: number): FlexTreeUnboxNodeUnion<T> | undefined {\n\t\tconst i = indexForAt(index, this.length);\n\t\tif (i === undefined) {\n\t\t\treturn undefined;\n\t\t}\n\t\treturn unboxedUnion(this.schema, this.mapTrees[i] ?? oob(), { parent: this, index: i });\n\t}\n\tpublic map<U>(callbackfn: (value: FlexTreeUnboxNodeUnion<T>, index: number) => U): U[] {\n\t\treturn Array.from(this, callbackfn);\n\t}\n\tpublic mapBoxed<U>(callbackfn: (value: FlexTreeTypedNodeUnion<T>, index: number) => U): U[] {\n\t\treturn Array.from(this.boxedIterator(), callbackfn);\n\t}\n\n\tpublic *[Symbol.iterator](): IterableIterator<FlexTreeUnboxNodeUnion<T>> {\n\t\tfor (const [i, mapTree] of this.mapTrees.entries()) {\n\t\t\tyield unboxedUnion(this.schema, mapTree, { parent: this, index: i });\n\t\t}\n\t}\n\n\tpublic getFieldPath(): FieldUpPath {\n\t\tthrow unsupportedUsageError(\"Editing an array\");\n\t}\n}\n\n// #endregion Fields\n\n// #region Caching and unboxing utilities\n\nconst nodeCache = new WeakMap<MapTree, EagerMapTreeNode<FlexTreeNodeSchema>>();\n/** Node Parent -\\> Field Key -\\> Field */\nconst fieldCache = new WeakMap<\n\tMapTreeNode,\n\tMap<FieldKey, EagerMapTreeField<FlexAllowedTypes>>\n>();\nfunction getFieldKeyCache(\n\tparent: MapTreeNode,\n): WeakMap<FieldKey, EagerMapTreeField<FlexAllowedTypes>> {\n\treturn getOrCreate(fieldCache, parent, () => new Map());\n}\n\n/**\n * If there exists a {@link EagerMapTreeNode} for the given {@link MapTree}, returns it, otherwise returns `undefined`.\n * @remarks {@link EagerMapTreeNode | MapTreeNodes} are created via {@link getOrCreateNode}.\n */\nexport function tryGetMapTreeNode(mapTree: MapTree): MapTreeNode | undefined {\n\treturn nodeCache.get(mapTree);\n}\n\n/**\n * Create a {@link EagerMapTreeNode} that wraps the given {@link MapTree}, or get the node that already exists for that {@link MapTree} if there is one.\n * @param nodeSchema - the {@link FlexTreeNodeSchema | schema} that the node conforms to\n * @param mapTree - the {@link MapTree} containing the data for this node.\n * @remarks It must conform to the `nodeSchema`.\n */\nexport function getOrCreateMapTreeNode(\n\tnodeSchema: FlexTreeNodeSchema,\n\tmapTree: ExclusiveMapTree,\n): EagerMapTreeNode<FlexTreeNodeSchema> {\n\treturn nodeCache.get(mapTree) ?? createNode(nodeSchema, mapTree, undefined);\n}\n\n/** Helper for creating a `MapTreeNode` given the parent field (e.g. when \"walking down\") */\nfunction getOrCreateChild(\n\tmapTree: ExclusiveMapTree,\n\timplicitAllowedTypes: FlexImplicitAllowedTypes,\n\tparent: LocationInField | undefined,\n): EagerMapTreeNode<FlexTreeNodeSchema> {\n\tconst cached = nodeCache.get(mapTree);\n\tif (cached !== undefined) {\n\t\treturn cached;\n\t}\n\n\tconst allowedTypes = normalizeAllowedTypes(implicitAllowedTypes);\n\tconst nodeSchema =\n\t\tallowedTypes\n\t\t\t.map((t) => (isLazy(t) ? t() : t))\n\t\t\t.find((t): t is FlexTreeNodeSchema => {\n\t\t\t\tassert(t !== \"Any\", 0x993 /* 'Any' type is not supported */);\n\t\t\t\treturn t.name === mapTree.type;\n\t\t\t}) ?? fail(\"Unsupported node schema\");\n\n\treturn createNode(nodeSchema, mapTree, parent);\n}\n\n/** Always constructs a new node, therefore may not be called twice for the same `MapTree`. */\nfunction createNode<TSchema extends FlexTreeNodeSchema>(\n\tnodeSchema: TSchema,\n\tmapTree: ExclusiveMapTree,\n\tparentField: LocationInField | undefined,\n): EagerMapTreeNode<TSchema> {\n\tif (schemaIsLeaf(nodeSchema)) {\n\t\treturn new EagerMapTreeLeafNode(nodeSchema, mapTree, parentField);\n\t}\n\tif (schemaIsMap(nodeSchema)) {\n\t\treturn new EagerMapTreeMapNode(nodeSchema, mapTree, parentField);\n\t}\n\tif (schemaIsObjectNode(nodeSchema)) {\n\t\treturn new EagerMapTreeNode(nodeSchema, mapTree, parentField);\n\t}\n\tassert(false, 0x994 /* Unrecognized node kind */);\n}\n\n/** Creates a field with the given attributes, or returns a cached field if there is one */\nfunction getOrCreateField(\n\tparent: EagerMapTreeNode<FlexTreeNodeSchema>,\n\tkey: FieldKey,\n\tschema: FlexFieldSchema,\n): EagerMapTreeField<FlexFieldSchema[\"allowedTypes\"]> {\n\tconst cached = getFieldKeyCache(parent).get(key);\n\tif (cached !== undefined) {\n\t\treturn cached;\n\t}\n\n\tif (\n\t\tschema.kind.identifier === FieldKinds.required.identifier ||\n\t\tschema.kind.identifier === FieldKinds.identifier.identifier\n\t) {\n\t\treturn new EagerMapTreeRequiredField(schema, key, parent);\n\t}\n\n\tif (schema.kind.identifier === FieldKinds.optional.identifier) {\n\t\treturn new EagerMapTreeOptionalField(schema, key, parent);\n\t}\n\n\tif (schema.kind.identifier === FieldKinds.sequence.identifier) {\n\t\treturn new EagerMapTreeSequenceField(schema, key, parent);\n\t}\n\n\treturn new EagerMapTreeField(schema, key, parent);\n}\n\n/** Unboxes non-polymorphic leaf nodes to their values, if applicable */\nfunction unboxedUnion<TTypes extends FlexAllowedTypes>(\n\tschema: FlexFieldSchema<FlexFieldKind, TTypes>,\n\tmapTree: ExclusiveMapTree,\n\tparent: LocationInField,\n): FlexTreeUnboxNodeUnion<TTypes> {\n\tconst type = schema.monomorphicChildType;\n\tif (type !== undefined) {\n\t\tif (schemaIsLeaf(type)) {\n\t\t\treturn mapTree.value as FlexTreeUnboxNodeUnion<TTypes>;\n\t\t}\n\t\treturn getOrCreateChild(mapTree, type, parent) as FlexTreeUnboxNodeUnion<TTypes>;\n\t}\n\n\treturn getOrCreateChild(\n\t\tmapTree,\n\t\tschema.allowedTypes,\n\t\tparent,\n\t) as FlexTreeUnboxNodeUnion<TTypes>;\n}\n\n/** Unboxes non-polymorphic required and optional fields holding leaf nodes to their values, if applicable */\nfunction unboxedField<TFieldSchema extends FlexFieldSchema>(\n\tfield: EagerMapTreeField<FlexAllowedTypes>,\n\tkey: FieldKey,\n\tmapTree: ExclusiveMapTree,\n\tparentNode: EagerMapTreeNode<FlexTreeNodeSchema>,\n): FlexTreeUnboxField<TFieldSchema> {\n\tconst fieldSchema = field.schema;\n\tconst mapTrees =\n\t\tmapTree.fields.get(key) ?? fail(\"Key does not exist in unhydrated map tree\");\n\n\tif (fieldSchema.kind === FieldKinds.required) {\n\t\treturn unboxedUnion(fieldSchema, mapTrees[0] ?? oob(), {\n\t\t\tparent: field,\n\t\t\tindex: 0,\n\t\t}) as FlexTreeUnboxField<TFieldSchema>;\n\t}\n\tif (fieldSchema.kind === FieldKinds.optional) {\n\t\treturn (\n\t\t\tmapTrees.length > 0\n\t\t\t\t? unboxedUnion(fieldSchema, mapTrees[0] ?? oob(), {\n\t\t\t\t\t\tparent: field,\n\t\t\t\t\t\tindex: 0,\n\t\t\t\t\t})\n\t\t\t\t: undefined\n\t\t) as FlexTreeUnboxField<TFieldSchema>;\n\t}\n\n\treturn getOrCreateField(parentNode, key, fieldSchema) as FlexTreeUnboxField<TFieldSchema>;\n}\n\n// #endregion Caching and unboxing utilities\n\nexport function unsupportedUsageError(message?: string): Error {\n\treturn new UsageError(\n\t\t`${\n\t\t\tmessage ?? \"Operation\"\n\t\t} is not supported for content that has not yet been inserted into the tree`,\n\t);\n}\n"]}
|
|
1
|
+
{"version":3,"file":"mapTreeNode.js","sourceRoot":"","sources":["../../../src/feature-libraries/flex-map-tree/mapTreeNode.ts"],"names":[],"mappings":"AAAA;;;GAGG;;AAEH,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,qCAAqC,CAAC;AAClE,OAAO,EAEN,QAAQ,GAQR,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAC5E,OAAO,EACN,kBAAkB,EAalB,cAAc,EACd,UAAU,GACV,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAEN,eAAe,EAIf,MAAM,EACN,YAAY,EACZ,WAAW,EACX,kBAAkB,GAClB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAiC,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAE/F,OAAO,EAAE,UAAU,EAAiC,MAAM,4BAA4B,CAAC;AACvF,OAAO,EAAE,UAAU,EAAE,MAAM,0CAA0C,CAAC;AAatE;;GAEG;AACH,MAAM,UAAU,aAAa,CAAC,QAAsB;IACnD,OAAO,QAAQ,YAAY,gBAAgB,CAAC;AAC7C,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,sBAAsB,CACrC,KAA+C;IAE/C,OAAO,KAAK,YAAY,yBAAyB,CAAC;AACnD,CAAC;AA4BD;;;;;;GAMG;AACH,MAAM,OAAO,gBAAgB;IAG5B;;;;;;;OAOG;IACH,YACiB,MAAe;IAC/B,iFAAiF;IACjE,OAAyB,EACjC,WAAW,kBAAkB;QAHrB,WAAM,GAAN,MAAM,CAAS;QAEf,YAAO,GAAP,OAAO,CAAkB;QACj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AAE,EAAE;gBAChD,MAAM,EAAE,KAAK;gBACb,KAAK,EAAE,CAAC;aACR,CAAC;YACH,CAAC,CAAC,SAAS,CACwB,CAAC;IACvC,CAAC;IAED,OAAO,gBAAgB,CAAC,UAAU,EAAE,GAAG,EAAE,WAAW,CAAqC,CAAC;AAC3F,CAAC;AAED,4CAA4C;AAE5C,MAAM,UAAU,qBAAqB,CAAC,OAAgB;IACrD,OAAO,IAAI,UAAU,CACpB,GACC,OAAO,IAAI,WACZ,4EAA4E,CAC5E,CAAC;AACH,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert, oob } from \"@fluidframework/core-utils/internal\";\nimport {\n\ttype AnchorNode,\n\tEmptyKey,\n\ttype ExclusiveMapTree,\n\ttype FieldKey,\n\ttype FieldUpPath,\n\ttype MapTree,\n\ttype TreeNodeSchemaIdentifier,\n\ttype TreeValue,\n\ttype Value,\n} from \"../../core/index.js\";\nimport { brand, fail, getOrCreate, mapIterable } from \"../../util/index.js\";\nimport {\n\tFlexTreeEntityKind,\n\ttype FlexTreeField,\n\ttype FlexTreeLeafNode,\n\ttype FlexTreeMapNode,\n\ttype FlexTreeNode,\n\ttype FlexTreeOptionalField,\n\ttype FlexTreeRequiredField,\n\ttype FlexTreeSequenceField,\n\ttype FlexTreeTypedField,\n\ttype FlexTreeTypedNode,\n\ttype FlexTreeTypedNodeUnion,\n\ttype FlexTreeUnboxField,\n\ttype FlexTreeUnboxNodeUnion,\n\tflexTreeMarker,\n\tindexForAt,\n} from \"../flex-tree/index.js\";\nimport {\n\ttype FlexAllowedTypes,\n\tFlexFieldSchema,\n\ttype FlexMapNodeSchema,\n\ttype FlexTreeNodeSchema,\n\ttype LeafNodeSchema,\n\tisLazy,\n\tschemaIsLeaf,\n\tschemaIsMap,\n\tschemaIsObjectNode,\n} from \"../typed-schema/index.js\";\nimport { type FlexImplicitAllowedTypes, normalizeAllowedTypes } from \"../schemaBuilderBase.js\";\nimport type { FlexFieldKind } from \"../modular-schema/index.js\";\nimport { FieldKinds, type SequenceFieldEditBuilder } from \"../default-schema/index.js\";\nimport { UsageError } from \"@fluidframework/telemetry-utils/internal\";\n\n// #region Nodes\n\n/**\n * A readonly {@link FlexTreeNode} which wraps a {@link MapTree}.\n * @remarks Reading data from the MapTreeNode will read the corresponding data from the {@link MapTree}.\n * Create a `MapTreeNode` by calling {@link getOrCreateMapTreeNode}.\n */\nexport interface MapTreeNode extends FlexTreeNode {\n\treadonly mapTree: MapTree;\n}\n\n/**\n * Checks if the given {@link FlexTreeNode} is a {@link MapTreeNode}.\n */\nexport function isMapTreeNode(flexNode: FlexTreeNode): flexNode is MapTreeNode {\n\treturn flexNode instanceof EagerMapTreeNode;\n}\n\n/**\n * Checks if the given {@link FlexTreeField} is a {@link MapTreeSequenceField}.\n */\nexport function isMapTreeSequenceField<T extends FlexAllowedTypes>(\n\tfield: FlexTreeSequenceField<T> | FlexTreeField,\n): field is MapTreeSequenceField<T> {\n\treturn field instanceof EagerMapTreeSequenceField;\n}\n\n/**\n * An unhydrated {@link FlexTreeSequenceField}, which has additional editing capabilities.\n * @remarks When doing a removal edit, a {@link MapTreeSequenceField}'s `editor` returns ownership of the removed {@link ExclusiveMapTree}s to the caller.\n */\nexport interface MapTreeSequenceField<T extends FlexAllowedTypes>\n\textends FlexTreeSequenceField<T> {\n\treadonly editor: MapTreeSequenceFieldEditBuilder;\n}\n\ninterface MapTreeSequenceFieldEditBuilder\n\textends SequenceFieldEditBuilder<ExclusiveMapTree[]> {\n\t/**\n\t * Issues a change which removes `count` elements starting at the given `index`.\n\t * @param index - The index of the first removed element.\n\t * @param count - The number of elements to remove.\n\t * @returns the MapTrees that were removed\n\t */\n\tremove(index: number, count: number): ExclusiveMapTree[];\n}\n\n/** A node's parent field and its index in that field */\ninterface LocationInField {\n\treadonly parent: MapTreeField;\n\treadonly index: number;\n}\n\n/**\n * A readonly implementation of {@link FlexTreeNode} which wraps a {@link MapTree}.\n * @remarks Any methods that would mutate the node will fail,\n * as will the querying of data specific to the {@link LazyTreeNode} implementation (e.g. {@link FlexTreeNode.context}).\n * MapTreeNodes are unconditionally cached -\n * when retrieved via {@link getOrCreateNode}, the same {@link MapTree} object will always produce the same `MapTreeNode` object.\n */\nexport class EagerMapTreeNode<TSchema extends FlexTreeNodeSchema> implements MapTreeNode {\n\tpublic readonly [flexTreeMarker] = FlexTreeEntityKind.Node as const;\n\n\t/**\n\t * Create a new MapTreeNode.\n\t * @param location - the parentage of this node, if it is being created underneath an existing node and field, or undefined if not\n\t * @remarks This class (and its subclasses) should not be directly constructed outside of this module.\n\t * Instead, use {@link getOrCreateNode} to create a MapTreeNode from a {@link MapTree}.\n\t * A `MapTreeNode` may never be constructed more than once for the same {@link MapTree} object.\n\t * Instead, it should always be acquired via {@link getOrCreateNode}.\n\t */\n\tpublic constructor(\n\t\tpublic readonly schema: TSchema,\n\t\t/** The underlying {@link MapTree} that this `MapTreeNode` reads its data from */\n\t\tpublic readonly mapTree: ExclusiveMapTree,\n\t\tprivate location = unparentedLocation,\n\t) {\n\t\tassert(!nodeCache.has(mapTree), 0x98b /* A node already exists for the given MapTree */);\n\t\tnodeCache.set(mapTree, this);\n\n\t\t// Fully demand the tree to ensure that parent pointers are present and accurate on all nodes.\n\t\t// When a MapTreeNode is constructed, its MapTree may contain nodes (anywhere below) that map (via the `nodeCache`) to pre-existing MapTreeNodes.\n\t\t// Put another way, for a given MapTree, some ancestor MapTreeNode can be created after any number of its descendant MapTreeNodes already exist.\n\t\t// In such a case, the spine of nodes between the descendant and ancestor need to exist in order for the ancestor to be able to walk upwards via the `parentField` property.\n\t\t// This needs to happen for all MapTreeNodes that are descendants of the ancestor MapTreeNode.\n\t\t// Demanding the entire tree is overkill to solve this problem since not all descendant MapTree nodes will have corresponding MapTreeNodes.\n\t\t// However, demanding the full tree also lets us eagerly validate that there are no duplicate MapTrees (i.e. same MapTree object) anywhere in the tree.\n\t\tthis.walkTree();\n\t}\n\n\tpublic get type(): TreeNodeSchemaIdentifier {\n\t\treturn this.schema.name;\n\t}\n\n\t/**\n\t * Set this node's parentage (see {@link FlexTreeNode.parentField}).\n\t * @remarks The node may be given a parent if it has none, or may have its parent removed (by passing `undefined`).\n\t * However, a node with a parent may not be directly re-assigned a different parent.\n\t * That likely indicates either an attempted multi-parenting or an attempt to \"move\" the node, neither of which are supported.\n\t * Removing a node's parent twice in a row is also not supported, as it likely indicates a bug.\n\t */\n\tpublic adoptBy(parent: undefined): void;\n\tpublic adoptBy(parent: MapTreeField, index: number): void;\n\tpublic adoptBy(parent: MapTreeField | undefined, index?: number): void {\n\t\tif (parent !== undefined) {\n\t\t\tassert(\n\t\t\t\tthis.location === unparentedLocation,\n\t\t\t\t0x98c /* Node may not be adopted if it already has a parent */,\n\t\t\t);\n\t\t\tassert(index !== undefined, 0xa08 /* Expected index */);\n\t\t\tthis.location = { parent, index };\n\t\t} else {\n\t\t\tassert(\n\t\t\t\tthis.location !== unparentedLocation,\n\t\t\t\t0xa09 /* Node may not be un-adopted if it does not have a parent */,\n\t\t\t);\n\t\t\tthis.location = unparentedLocation;\n\t\t}\n\t}\n\n\t/**\n\t * The field this tree is in, and the index within that field.\n\t * @remarks If this node is unparented, this method will return the special {@link unparentedLocation} as the parent.\n\t */\n\tpublic get parentField(): LocationInField {\n\t\treturn this.location;\n\t}\n\n\tpublic is<TSchemaInner extends FlexTreeNodeSchema>(\n\t\tschema: TSchemaInner,\n\t): this is FlexTreeTypedNode<TSchemaInner> {\n\t\treturn (schema as unknown) === this.schema;\n\t}\n\n\tpublic tryGetField(key: FieldKey): EagerMapTreeField<FlexAllowedTypes> | undefined {\n\t\tconst field = this.mapTree.fields.get(key);\n\t\t// Only return the field if it is not empty, in order to fulfill the contract of `tryGetField`.\n\t\tif (field !== undefined && field.length > 0) {\n\t\t\treturn getOrCreateField(this, key, this.schema.getFieldSchema(key));\n\t\t}\n\t}\n\n\tpublic getBoxed(key: string): FlexTreeField {\n\t\tconst fieldKey: FieldKey = brand(key);\n\t\treturn getOrCreateField(this, fieldKey, this.schema.getFieldSchema(fieldKey));\n\t}\n\n\tpublic boxedIterator(): IterableIterator<FlexTreeField> {\n\t\treturn mapIterable(this.mapTree.fields.entries(), ([key]) =>\n\t\t\tgetOrCreateField(this, key, this.schema.getFieldSchema(key)),\n\t\t);\n\t}\n\n\tpublic get value(): Value {\n\t\treturn this.mapTree.value;\n\t}\n\n\tpublic context = undefined;\n\n\tpublic get anchorNode(): AnchorNode {\n\t\t// This API is relevant to `LazyTreeNode`s, but not `MapTreeNode`s.\n\t\t// TODO: Refactor the FlexTreeNode interface so that stubbing this out isn't necessary.\n\t\treturn fail(\"MapTreeNode does not implement anchorNode\");\n\t}\n\n\tprivate walkTree(): void {\n\t\tfor (const [key, mapTrees] of this.mapTree.fields) {\n\t\t\tconst field = getOrCreateField(this, key, this.schema.getFieldSchema(key));\n\t\t\tfor (let index = 0; index < field.length; index++) {\n\t\t\t\tconst child = getOrCreateChild(\n\t\t\t\t\tmapTrees[index] ?? oob(),\n\t\t\t\t\tthis.schema.getFieldSchema(key).allowedTypes,\n\t\t\t\t\t{ parent: field, index },\n\t\t\t\t);\n\t\t\t\t// These next asserts detect the case where `getOrCreateChild` gets a cache hit of a different node than the one we're trying to create\n\t\t\t\tassert(child.location !== undefined, 0x98d /* Expected node to have parent */);\n\t\t\t\tassert(\n\t\t\t\t\tchild.location.parent.parent === this,\n\t\t\t\t\t0x98e /* Node may not be multi-parented */,\n\t\t\t\t);\n\t\t\t\tassert(child.location.index === index, 0x98f /* Node may not be multi-parented */);\n\t\t\t\tchild.walkTree();\n\t\t\t}\n\t\t}\n\t}\n}\n\n/**\n * The implementation of a map node created by {@link getOrCreateNode}.\n */\nexport class EagerMapTreeMapNode<TSchema extends FlexMapNodeSchema>\n\textends EagerMapTreeNode<TSchema>\n\timplements FlexTreeMapNode<TSchema>\n{\n\tpublic keys(): IterableIterator<FieldKey> {\n\t\treturn this.mapTree.fields.keys();\n\t}\n\n\tpublic values(): IterableIterator<FlexTreeUnboxField<TSchema[\"info\"], \"notEmpty\">> {\n\t\treturn mapIterable(\n\t\t\tthis.mapTree.fields.keys(),\n\t\t\t(key) =>\n\t\t\t\tunboxedField(\n\t\t\t\t\tthis.tryGetField(key) ?? fail(\"Unexpected empty map field\"),\n\t\t\t\t\tkey,\n\t\t\t\t\tthis.mapTree,\n\t\t\t\t\tthis,\n\t\t\t\t) as FlexTreeUnboxField<TSchema[\"info\"], \"notEmpty\">,\n\t\t);\n\t}\n\n\tpublic entries(): IterableIterator<\n\t\t[FieldKey, FlexTreeUnboxField<TSchema[\"info\"], \"notEmpty\">]\n\t> {\n\t\treturn mapIterable(this.mapTree.fields.keys(), (key) => [\n\t\t\tkey,\n\t\t\tunboxedField(\n\t\t\t\tthis.tryGetField(key) ?? fail(\"Unexpected empty map field\"),\n\t\t\t\tkey,\n\t\t\t\tthis.mapTree,\n\t\t\t\tthis,\n\t\t\t) as FlexTreeUnboxField<TSchema[\"info\"], \"notEmpty\">,\n\t\t]);\n\t}\n\n\tpublic override getBoxed(key: string): FlexTreeTypedField<TSchema[\"info\"]> {\n\t\treturn super.getBoxed(key) as FlexTreeTypedField<TSchema[\"info\"]>;\n\t}\n\n\tpublic [Symbol.iterator](): IterableIterator<\n\t\t[FieldKey, FlexTreeUnboxField<TSchema[\"info\"], \"notEmpty\">]\n\t> {\n\t\treturn this.entries();\n\t}\n}\n\nclass EagerMapTreeLeafNode<TSchema extends LeafNodeSchema>\n\textends EagerMapTreeNode<TSchema>\n\timplements FlexTreeLeafNode<TSchema>\n{\n\tpublic override get value(): TreeValue<TSchema[\"info\"]> {\n\t\treturn super.value as TreeValue<TSchema[\"info\"]>;\n\t}\n}\n\n// #endregion Nodes\n\n// #region Fields\n\n/**\n * A readonly {@link FlexTreeField} which wraps an array of {@link MapTrees}.\n * @remarks Reading data from the MapTreeField will read the corresponding data from the {@link MapTree}s.\n * Create a `MapTreeField` by calling {@link getOrCreateField}.\n */\ninterface MapTreeField extends FlexTreeField {\n\treadonly mapTrees: readonly MapTree[];\n}\n\n/**\n * A special singleton that is the implicit {@link LocationInField} of all un-parented {@link EagerMapTreeNode}s.\n * @remarks This exists because {@link EagerMapTreeNode.parentField} must return a field.\n * If a {@link EagerMapTreeNode} is created without a parent, its {@link EagerMapTreeNode.parentField} property will point to this object.\n * However, this field cannot be used in any practical way because it is empty, i.e. it does not actually contain the children that claim to be parented under it.\n * It has the \"empty\" schema and it will always contain zero children if queried.\n * Any nodes with this location will have a dummy parent index of `-1`.\n */\nconst unparentedLocation: LocationInField = {\n\tparent: {\n\t\t[flexTreeMarker]: FlexTreeEntityKind.Field as const,\n\t\tlength: 0,\n\t\tkey: EmptyKey,\n\t\tparent: undefined,\n\t\tis<TSchema extends FlexFieldSchema>(schema: TSchema) {\n\t\t\treturn schema === (FlexFieldSchema.empty as FlexFieldSchema);\n\t\t},\n\t\tboxedIterator(): IterableIterator<FlexTreeNode> {\n\t\t\treturn [].values();\n\t\t},\n\t\tboxedAt(index: number): FlexTreeNode | undefined {\n\t\t\treturn undefined;\n\t\t},\n\t\tschema: FlexFieldSchema.empty,\n\t\tcontext: undefined,\n\t\tmapTrees: [],\n\t},\n\tindex: -1,\n};\n\nclass EagerMapTreeField<T extends FlexAllowedTypes> implements MapTreeField {\n\tpublic [flexTreeMarker] = FlexTreeEntityKind.Field as const;\n\n\tpublic constructor(\n\t\tpublic readonly schema: FlexFieldSchema<FlexFieldKind, T>,\n\t\tpublic readonly key: FieldKey,\n\t\tpublic readonly parent: EagerMapTreeNode<FlexTreeNodeSchema>,\n\t) {\n\t\tconst fieldKeyCache = getFieldKeyCache(parent);\n\t\tassert(!fieldKeyCache.has(key), 0x990 /* A field already exists for the given MapTrees */);\n\t\tfieldKeyCache.set(key, this);\n\n\t\t// When this field is created (which only happens one time, because it is cached), all the children become parented for the first time.\n\t\t// \"Adopt\" each child by updating its parent information to point to this field.\n\t\tfor (const [i, mapTree] of this.mapTrees.entries()) {\n\t\t\tconst mapTreeNodeChild = nodeCache.get(mapTree);\n\t\t\tif (mapTreeNodeChild !== undefined) {\n\t\t\t\tif (mapTreeNodeChild.parentField !== unparentedLocation) {\n\t\t\t\t\tthrow new UsageError(\"A node may not be in more than one place in the tree\");\n\t\t\t\t}\n\t\t\t\tmapTreeNodeChild.adoptBy(this, i);\n\t\t\t}\n\t\t}\n\t}\n\n\tpublic get mapTrees(): readonly ExclusiveMapTree[] {\n\t\treturn this.parent.mapTree.fields.get(this.key) ?? [];\n\t}\n\n\tpublic get length(): number {\n\t\treturn this.mapTrees.length;\n\t}\n\n\tpublic is<TSchemaInner extends FlexFieldSchema>(\n\t\tschema: TSchemaInner,\n\t): this is FlexTreeTypedField<TSchemaInner> {\n\t\treturn this.schema.equals(schema);\n\t}\n\n\tpublic boxedIterator(): IterableIterator<FlexTreeTypedNodeUnion<T>> {\n\t\treturn this.mapTrees\n\t\t\t.map(\n\t\t\t\t(m, index) =>\n\t\t\t\t\tgetOrCreateChild(m, this.schema.allowedTypes, {\n\t\t\t\t\t\tparent: this,\n\t\t\t\t\t\tindex,\n\t\t\t\t\t}) as FlexTreeNode as FlexTreeTypedNodeUnion<T>,\n\t\t\t)\n\t\t\t.values();\n\t}\n\n\tpublic boxedAt(index: number): FlexTreeTypedNodeUnion<T> | undefined {\n\t\tconst i = indexForAt(index, this.length);\n\t\tif (i === undefined) {\n\t\t\treturn undefined;\n\t\t}\n\t\tconst m = this.mapTrees[i];\n\t\tif (m !== undefined) {\n\t\t\treturn getOrCreateChild(m, this.schema.allowedTypes, {\n\t\t\t\tparent: this,\n\t\t\t\tindex: i,\n\t\t\t}) as FlexTreeNode as FlexTreeTypedNodeUnion<T>;\n\t\t}\n\t}\n\n\tpublic context: undefined;\n\n\t/**\n\t * Mutate this field.\n\t * @param edit - A function which receives the current `MapTree`s that comprise the contents of the field so that it may be mutated.\n\t * The function may mutate the array in place or return a new array.\n\t * If a new array is returned then it will be used as the new contents of the field, otherwise the original array will be continue to be used.\n\t * @remarks All edits to the field (i.e. mutations of the field's MapTrees) should be directed through this function.\n\t * This function ensures that the parent MapTree has no empty fields (which is an invariant of `MapTree`) after the mutation.\n\t */\n\tprotected edit(edit: (mapTrees: ExclusiveMapTree[]) => void | ExclusiveMapTree[]): void {\n\t\tconst oldMapTrees = this.parent.mapTree.fields.get(this.key) ?? [];\n\t\tconst newMapTrees = edit(oldMapTrees) ?? oldMapTrees;\n\t\tif (newMapTrees.length > 0) {\n\t\t\tthis.parent.mapTree.fields.set(this.key, newMapTrees);\n\t\t} else {\n\t\t\tthis.parent.mapTree.fields.delete(this.key);\n\t\t}\n\t}\n}\n\nclass EagerMapTreeOptionalField<T extends FlexAllowedTypes>\n\textends EagerMapTreeField<T>\n\timplements FlexTreeOptionalField<T>\n{\n\tpublic readonly editor = {\n\t\tset: (newContent: ExclusiveMapTree | undefined): void => {\n\t\t\t// If the new content is a MapTreeNode, it needs to have its parent pointer updated\n\t\t\tif (newContent !== undefined) {\n\t\t\t\tnodeCache.get(newContent)?.adoptBy(this, 0);\n\t\t\t}\n\t\t\t// If the old content is a MapTreeNode, it needs to have its parent pointer unset\n\t\t\tconst oldContent = this.mapTrees[0];\n\t\t\tif (oldContent !== undefined) {\n\t\t\t\tnodeCache.get(oldContent)?.adoptBy(undefined);\n\t\t\t}\n\n\t\t\tthis.edit((mapTrees) => {\n\t\t\t\tif (newContent !== undefined) {\n\t\t\t\t\tmapTrees[0] = newContent;\n\t\t\t\t} else {\n\t\t\t\t\tmapTrees.length = 0;\n\t\t\t\t}\n\t\t\t});\n\t\t},\n\t};\n\n\tpublic get content(): FlexTreeUnboxNodeUnion<T> | undefined {\n\t\tconst value = this.mapTrees[0];\n\t\tif (value !== undefined) {\n\t\t\treturn unboxedUnion(this.schema, value, {\n\t\t\t\tparent: this,\n\t\t\t\tindex: 0,\n\t\t\t});\n\t\t}\n\n\t\treturn undefined;\n\t}\n}\n\nclass EagerMapTreeRequiredField<T extends FlexAllowedTypes>\n\textends EagerMapTreeOptionalField<T>\n\timplements FlexTreeRequiredField<T>\n{\n\tpublic override get content(): FlexTreeUnboxNodeUnion<T> {\n\t\treturn super.content ?? fail(\"Expected EagerMapTree required field to have a value\");\n\t}\n}\n\nclass EagerMapTreeSequenceField<T extends FlexAllowedTypes>\n\textends EagerMapTreeField<T>\n\timplements FlexTreeSequenceField<T>\n{\n\tpublic readonly editor: MapTreeSequenceFieldEditBuilder = {\n\t\tinsert: (index, newContent): void => {\n\t\t\tfor (let i = 0; i < newContent.length; i++) {\n\t\t\t\tconst c = newContent[i];\n\t\t\t\tassert(c !== undefined, 0xa0a /* Unexpected sparse array content */);\n\t\t\t\tnodeCache.get(c)?.adoptBy(this, index + i);\n\t\t\t}\n\t\t\tthis.edit((mapTrees) => {\n\t\t\t\tif (newContent.length < 1000) {\n\t\t\t\t\t// For \"smallish arrays\" (`1000` is not empirically derived), the `splice` function is appropriate...\n\t\t\t\t\tmapTrees.splice(index, 0, ...newContent);\n\t\t\t\t} else {\n\t\t\t\t\t// ...but we avoid using `splice` + spread for very large input arrays since there is a limit on how many elements can be spread (too many will overflow the stack).\n\t\t\t\t\treturn mapTrees.slice(0, index).concat(newContent, mapTrees.slice(index));\n\t\t\t\t}\n\t\t\t});\n\t\t},\n\t\tremove: (index, count): ExclusiveMapTree[] => {\n\t\t\tfor (let i = index; i < index + count; i++) {\n\t\t\t\tconst c = this.mapTrees[i];\n\t\t\t\tassert(c !== undefined, 0xa0b /* Unexpected sparse array */);\n\t\t\t\tnodeCache.get(c)?.adoptBy(undefined);\n\t\t\t}\n\t\t\tlet removed: ExclusiveMapTree[] | undefined;\n\t\t\tthis.edit((mapTrees) => {\n\t\t\t\tremoved = mapTrees.splice(index, count);\n\t\t\t});\n\t\t\treturn removed ?? fail(\"Expected removed to be set by edit\");\n\t\t},\n\t};\n\n\tpublic at(index: number): FlexTreeUnboxNodeUnion<T> | undefined {\n\t\tconst i = indexForAt(index, this.length);\n\t\tif (i === undefined) {\n\t\t\treturn undefined;\n\t\t}\n\t\treturn unboxedUnion(this.schema, this.mapTrees[i] ?? oob(), { parent: this, index: i });\n\t}\n\tpublic map<U>(callbackfn: (value: FlexTreeUnboxNodeUnion<T>, index: number) => U): U[] {\n\t\treturn Array.from(this, callbackfn);\n\t}\n\n\tpublic *[Symbol.iterator](): IterableIterator<FlexTreeUnboxNodeUnion<T>> {\n\t\tfor (const [i, mapTree] of this.mapTrees.entries()) {\n\t\t\tyield unboxedUnion(this.schema, mapTree, { parent: this, index: i });\n\t\t}\n\t}\n\n\tpublic getFieldPath(): FieldUpPath {\n\t\tthrow unsupportedUsageError(\"Editing an array\");\n\t}\n}\n\n// #endregion Fields\n\n// #region Caching and unboxing utilities\n\nconst nodeCache = new WeakMap<MapTree, EagerMapTreeNode<FlexTreeNodeSchema>>();\n/** Node Parent -\\> Field Key -\\> Field */\nconst fieldCache = new WeakMap<\n\tMapTreeNode,\n\tMap<FieldKey, EagerMapTreeField<FlexAllowedTypes>>\n>();\nfunction getFieldKeyCache(\n\tparent: MapTreeNode,\n): WeakMap<FieldKey, EagerMapTreeField<FlexAllowedTypes>> {\n\treturn getOrCreate(fieldCache, parent, () => new Map());\n}\n\n/**\n * If there exists a {@link EagerMapTreeNode} for the given {@link MapTree}, returns it, otherwise returns `undefined`.\n * @remarks {@link EagerMapTreeNode | MapTreeNodes} are created via {@link getOrCreateNode}.\n */\nexport function tryGetMapTreeNode(mapTree: MapTree): MapTreeNode | undefined {\n\treturn nodeCache.get(mapTree);\n}\n\n/**\n * Create a {@link EagerMapTreeNode} that wraps the given {@link MapTree}, or get the node that already exists for that {@link MapTree} if there is one.\n * @param nodeSchema - the {@link FlexTreeNodeSchema | schema} that the node conforms to\n * @param mapTree - the {@link MapTree} containing the data for this node.\n * @remarks It must conform to the `nodeSchema`.\n */\nexport function getOrCreateMapTreeNode(\n\tnodeSchema: FlexTreeNodeSchema,\n\tmapTree: ExclusiveMapTree,\n): EagerMapTreeNode<FlexTreeNodeSchema> {\n\treturn nodeCache.get(mapTree) ?? createNode(nodeSchema, mapTree, undefined);\n}\n\n/** Helper for creating a `MapTreeNode` given the parent field (e.g. when \"walking down\") */\nfunction getOrCreateChild(\n\tmapTree: ExclusiveMapTree,\n\timplicitAllowedTypes: FlexImplicitAllowedTypes,\n\tparent: LocationInField | undefined,\n): EagerMapTreeNode<FlexTreeNodeSchema> {\n\tconst cached = nodeCache.get(mapTree);\n\tif (cached !== undefined) {\n\t\treturn cached;\n\t}\n\n\tconst allowedTypes = normalizeAllowedTypes(implicitAllowedTypes);\n\tconst nodeSchema =\n\t\tallowedTypes\n\t\t\t.map((t) => (isLazy(t) ? t() : t))\n\t\t\t.find((t): t is FlexTreeNodeSchema => {\n\t\t\t\tassert(t !== \"Any\", 0x993 /* 'Any' type is not supported */);\n\t\t\t\treturn t.name === mapTree.type;\n\t\t\t}) ?? fail(\"Unsupported node schema\");\n\n\treturn createNode(nodeSchema, mapTree, parent);\n}\n\n/** Always constructs a new node, therefore may not be called twice for the same `MapTree`. */\nfunction createNode<TSchema extends FlexTreeNodeSchema>(\n\tnodeSchema: TSchema,\n\tmapTree: ExclusiveMapTree,\n\tparentField: LocationInField | undefined,\n): EagerMapTreeNode<TSchema> {\n\tif (schemaIsLeaf(nodeSchema)) {\n\t\treturn new EagerMapTreeLeafNode(nodeSchema, mapTree, parentField);\n\t}\n\tif (schemaIsMap(nodeSchema)) {\n\t\treturn new EagerMapTreeMapNode(nodeSchema, mapTree, parentField);\n\t}\n\tif (schemaIsObjectNode(nodeSchema)) {\n\t\treturn new EagerMapTreeNode(nodeSchema, mapTree, parentField);\n\t}\n\tassert(false, 0x994 /* Unrecognized node kind */);\n}\n\n/** Creates a field with the given attributes, or returns a cached field if there is one */\nfunction getOrCreateField(\n\tparent: EagerMapTreeNode<FlexTreeNodeSchema>,\n\tkey: FieldKey,\n\tschema: FlexFieldSchema,\n): EagerMapTreeField<FlexFieldSchema[\"allowedTypes\"]> {\n\tconst cached = getFieldKeyCache(parent).get(key);\n\tif (cached !== undefined) {\n\t\treturn cached;\n\t}\n\n\tif (\n\t\tschema.kind.identifier === FieldKinds.required.identifier ||\n\t\tschema.kind.identifier === FieldKinds.identifier.identifier\n\t) {\n\t\treturn new EagerMapTreeRequiredField(schema, key, parent);\n\t}\n\n\tif (schema.kind.identifier === FieldKinds.optional.identifier) {\n\t\treturn new EagerMapTreeOptionalField(schema, key, parent);\n\t}\n\n\tif (schema.kind.identifier === FieldKinds.sequence.identifier) {\n\t\treturn new EagerMapTreeSequenceField(schema, key, parent);\n\t}\n\n\treturn new EagerMapTreeField(schema, key, parent);\n}\n\n/** Unboxes non-polymorphic leaf nodes to their values, if applicable */\nfunction unboxedUnion<TTypes extends FlexAllowedTypes>(\n\tschema: FlexFieldSchema<FlexFieldKind, TTypes>,\n\tmapTree: ExclusiveMapTree,\n\tparent: LocationInField,\n): FlexTreeUnboxNodeUnion<TTypes> {\n\tconst type = schema.monomorphicChildType;\n\tif (type !== undefined) {\n\t\tif (schemaIsLeaf(type)) {\n\t\t\treturn mapTree.value as FlexTreeUnboxNodeUnion<TTypes>;\n\t\t}\n\t\treturn getOrCreateChild(mapTree, type, parent) as FlexTreeUnboxNodeUnion<TTypes>;\n\t}\n\n\treturn getOrCreateChild(\n\t\tmapTree,\n\t\tschema.allowedTypes,\n\t\tparent,\n\t) as FlexTreeUnboxNodeUnion<TTypes>;\n}\n\n/** Unboxes non-polymorphic required and optional fields holding leaf nodes to their values, if applicable */\nfunction unboxedField<TFieldSchema extends FlexFieldSchema>(\n\tfield: EagerMapTreeField<FlexAllowedTypes>,\n\tkey: FieldKey,\n\tmapTree: ExclusiveMapTree,\n\tparentNode: EagerMapTreeNode<FlexTreeNodeSchema>,\n): FlexTreeUnboxField<TFieldSchema> {\n\tconst fieldSchema = field.schema;\n\tconst mapTrees =\n\t\tmapTree.fields.get(key) ?? fail(\"Key does not exist in unhydrated map tree\");\n\n\tif (fieldSchema.kind === FieldKinds.required) {\n\t\treturn unboxedUnion(fieldSchema, mapTrees[0] ?? oob(), {\n\t\t\tparent: field,\n\t\t\tindex: 0,\n\t\t}) as FlexTreeUnboxField<TFieldSchema>;\n\t}\n\tif (fieldSchema.kind === FieldKinds.optional) {\n\t\treturn (\n\t\t\tmapTrees.length > 0\n\t\t\t\t? unboxedUnion(fieldSchema, mapTrees[0] ?? oob(), {\n\t\t\t\t\t\tparent: field,\n\t\t\t\t\t\tindex: 0,\n\t\t\t\t\t})\n\t\t\t\t: undefined\n\t\t) as FlexTreeUnboxField<TFieldSchema>;\n\t}\n\n\treturn getOrCreateField(parentNode, key, fieldSchema) as FlexTreeUnboxField<TFieldSchema>;\n}\n\n// #endregion Caching and unboxing utilities\n\nexport function unsupportedUsageError(message?: string): Error {\n\treturn new UsageError(\n\t\t`${\n\t\t\tmessage ?? \"Operation\"\n\t\t} is not supported for content that has not yet been inserted into the tree`,\n\t);\n}\n"]}
|
|
@@ -3,10 +3,10 @@
|
|
|
3
3
|
* Licensed under the MIT License.
|
|
4
4
|
*/
|
|
5
5
|
import { type AnchorNode, type ExclusiveMapTree, type FieldKey, type FieldUpPath, type TreeValue } from "../../core/index.js";
|
|
6
|
-
import type { Assume
|
|
6
|
+
import type { Assume } from "../../util/index.js";
|
|
7
7
|
import type { FieldKinds, SequenceFieldEditBuilder, ValueFieldEditBuilder, OptionalFieldEditBuilder } from "../default-schema/index.js";
|
|
8
8
|
import type { FlexFieldKind } from "../modular-schema/index.js";
|
|
9
|
-
import type { Any, FlexAllowedTypes, FlexFieldSchema, FlexList, FlexListToUnion, FlexMapNodeSchema,
|
|
9
|
+
import type { Any, FlexAllowedTypes, FlexFieldSchema, FlexList, FlexListToUnion, FlexMapNodeSchema, FlexObjectNodeSchema, FlexTreeNodeSchema, LazyItem, LeafNodeSchema } from "../typed-schema/index.js";
|
|
10
10
|
import type { FlexTreeContext } from "./context.js";
|
|
11
11
|
/**
|
|
12
12
|
* An anchor slot which records the {@link FlexTreeNode} associated with that anchor, if there is one.
|
|
@@ -245,23 +245,6 @@ export interface FlexTreeMapNode<in out TSchema extends FlexMapNodeSchema> exten
|
|
|
245
245
|
* No guarantees are made regarding the order of the entries returned.
|
|
246
246
|
*/
|
|
247
247
|
entries(): IterableIterator<[FieldKey, FlexTreeUnboxField<TSchema["info"], "notEmpty">]>;
|
|
248
|
-
/**
|
|
249
|
-
* Executes a provided function once per each key/value pair in the map.
|
|
250
|
-
* @param callbackFn - The function to run for each map entry
|
|
251
|
-
* @param thisArg - If present, `callbackFn` will be bound to `thisArg`
|
|
252
|
-
*
|
|
253
|
-
* @privateRemarks
|
|
254
|
-
* TODO: This should run over fields in insertion order if we want to match the javascript foreach spec.
|
|
255
|
-
*/
|
|
256
|
-
forEach(callbackFn: (value: FlexTreeUnboxField<TSchema["info"], "notEmpty">, key: FieldKey, map: FlexTreeMapNode<TSchema>) => void, thisArg?: any): void;
|
|
257
|
-
/**
|
|
258
|
-
* Iterate through all fields in the map.
|
|
259
|
-
*
|
|
260
|
-
* @remarks
|
|
261
|
-
* No mutations to the current view of the shared tree are permitted during iteration.
|
|
262
|
-
* To iterate over the unboxed values of the map, use `Symbol.Iterator()`.
|
|
263
|
-
*/
|
|
264
|
-
boxedIterator(): IterableIterator<FlexTreeTypedField<TSchema["info"]>>;
|
|
265
248
|
[Symbol.iterator](): IterableIterator<[
|
|
266
249
|
FieldKey,
|
|
267
250
|
FlexTreeUnboxField<TSchema["info"], "notEmpty">
|
|
@@ -274,7 +257,6 @@ export interface FlexTreeMapNode<in out TSchema extends FlexMapNodeSchema> exten
|
|
|
274
257
|
*
|
|
275
258
|
* @remarks
|
|
276
259
|
* ObjectNodes require complex typing, and have been split into two parts for implementation purposes.
|
|
277
|
-
* See {@link FlexTreeObjectNodeTyped} for the schema aware extensions to this that provide access to the fields.
|
|
278
260
|
*
|
|
279
261
|
* These "Objects" resemble "Structs" from a wide variety of programming languages
|
|
280
262
|
* (Including Algol 68, C, Go, Rust, C# etc.).
|
|
@@ -303,74 +285,6 @@ export interface FlexTreeLeafNode<in out TSchema extends LeafNodeSchema> extends
|
|
|
303
285
|
*/
|
|
304
286
|
readonly value: TreeValue<TSchema["info"]>;
|
|
305
287
|
}
|
|
306
|
-
/**
|
|
307
|
-
* An {@link FlexTreeObjectNode} with schema aware accessors for its fields.
|
|
308
|
-
*
|
|
309
|
-
* @privateRemarks
|
|
310
|
-
*
|
|
311
|
-
* The corresponding implementation logic for this lives in `LazyTree.ts` under `buildStructClass`.
|
|
312
|
-
* If you change the signature here, you will need to update that logic to match.
|
|
313
|
-
*/
|
|
314
|
-
export type FlexTreeObjectNodeTyped<TSchema extends FlexObjectNodeSchema> = FlexObjectNodeSchema extends TSchema ? FlexTreeObjectNode : FlexTreeObjectNode & FlexTreeObjectNodeFields<TSchema["info"]>;
|
|
315
|
-
/**
|
|
316
|
-
* Properties to access an object node's fields. See {@link FlexTreeObjectNodeTyped}.
|
|
317
|
-
*
|
|
318
|
-
* @privateRemarks
|
|
319
|
-
* TODO: Support custom field keys.
|
|
320
|
-
*/
|
|
321
|
-
export type FlexTreeObjectNodeFields<TFields extends FlexObjectNodeFields> = FlexTreeObjectNodeFieldsInner<FlattenKeys<{
|
|
322
|
-
[key in keyof TFields as key extends PropertyNameFromFieldKey<key & string> ? key : never]: TFields[key];
|
|
323
|
-
} & {
|
|
324
|
-
[key in keyof TFields as key extends PropertyNameFromFieldKey<key & string> ? never : PropertyNameFromFieldKey<key & string>]: TFields[key];
|
|
325
|
-
}>>;
|
|
326
|
-
/**
|
|
327
|
-
* Properties to access an object node's fields. See {@link FlexTreeObjectNodeTyped}.
|
|
328
|
-
*
|
|
329
|
-
* @privateRemarks
|
|
330
|
-
* TODO: Do we keep assignment operator + "setFoo" methods, or just use methods?
|
|
331
|
-
* Inconsistency in the API experience could confusing for consumers.
|
|
332
|
-
*/
|
|
333
|
-
export type FlexTreeObjectNodeFieldsInner<TFields extends FlexObjectNodeFields> = FlattenKeys<{
|
|
334
|
-
readonly [key in keyof TFields as `boxed${Capitalize<key & string>}`]: FlexTreeTypedField<TFields[key]>;
|
|
335
|
-
} & {
|
|
336
|
-
readonly [key in keyof TFields as TFields[key]["kind"] extends AssignableFieldKinds ? never : key]: FlexTreeUnboxField<TFields[key]>;
|
|
337
|
-
} & {
|
|
338
|
-
-readonly [key in keyof TFields as TFields[key]["kind"] extends AssignableFieldKinds ? key : never]: FlexTreeUnboxField<TFields[key]>;
|
|
339
|
-
} & {
|
|
340
|
-
readonly [key in keyof TFields as TFields[key]["kind"] extends AssignableFieldKinds ? `set${Capitalize<key & string>}` : never]: (content: FlexibleNodeContent) => void;
|
|
341
|
-
}>;
|
|
342
|
-
/**
|
|
343
|
-
* Reserved object node field property names to avoid collisions with the rest of the object node API.
|
|
344
|
-
*/
|
|
345
|
-
export declare const reservedObjectNodeFieldPropertyNames: readonly ["anchorNode", "constructor", "context", "is", "parentField", "schema", "tryGetField", "type", "value", "boxedIterator", "iterator", "getBoxed"];
|
|
346
|
-
/**
|
|
347
|
-
* Reserved object node field property names prefixes.
|
|
348
|
-
* These are reserved to avoid collisions with properties derived from field other field names.
|
|
349
|
-
*
|
|
350
|
-
* Field names starting with these must be followed by a lowercase letter, or be escaped.
|
|
351
|
-
*/
|
|
352
|
-
export declare const reservedObjectNodeFieldPropertyNamePrefixes: readonly ["set", "boxed", "field", "Field"];
|
|
353
|
-
/**
|
|
354
|
-
* {@link reservedObjectNodeFieldPropertyNamePrefixes} as a type union.
|
|
355
|
-
*/
|
|
356
|
-
export type ReservedObjectNodeFieldPropertyNames = (typeof reservedObjectNodeFieldPropertyNames)[number];
|
|
357
|
-
/**
|
|
358
|
-
* {@link reservedObjectNodeFieldPropertyNamePrefixes} as a type union.
|
|
359
|
-
*/
|
|
360
|
-
export type ReservedObjectNodeFieldPropertyNamePrefixes = (typeof reservedObjectNodeFieldPropertyNamePrefixes)[number];
|
|
361
|
-
/**
|
|
362
|
-
* Convert an object node's field key into an escaped string usable as a property name.
|
|
363
|
-
*
|
|
364
|
-
* @privateRemarks
|
|
365
|
-
* TODO:
|
|
366
|
-
* Collisions are still possible.
|
|
367
|
-
* For example fields named "foo" and "Foo" would both produce a setter "setFoo".
|
|
368
|
-
* Consider naming schemes to avoid this, ensure that there is a good workaround for these cases.
|
|
369
|
-
* Another approach would be to support custom field names (separate from keys),
|
|
370
|
-
* and do the escaping (if needed) when creating the flex tree schema (both when manually creating them and when doing so automatically):
|
|
371
|
-
* this would enable better intellisense for escaped fields, as well as allow the feature of custom field property names.
|
|
372
|
-
*/
|
|
373
|
-
export type PropertyNameFromFieldKey<T extends string> = T extends ReservedObjectNodeFieldPropertyNames ? `field${Capitalize<T>}` : T extends `${ReservedObjectNodeFieldPropertyNamePrefixes}${Capitalize<string>}` ? `field${Capitalize<T>}` : T;
|
|
374
288
|
/**
|
|
375
289
|
* Field kinds that allow value assignment.
|
|
376
290
|
*/
|
|
@@ -434,11 +348,6 @@ export interface FlexTreeSequenceField<in out TTypes extends FlexAllowedTypes> e
|
|
|
434
348
|
* @param callbackfn - A function that accepts the child and its index.
|
|
435
349
|
*/
|
|
436
350
|
map<U>(callbackfn: (value: FlexTreeUnboxNodeUnion<TTypes>, index: number) => U): U[];
|
|
437
|
-
/**
|
|
438
|
-
* Calls the provided callback function on each child of this sequence, and returns an array that contains the results.
|
|
439
|
-
* @param callbackfn - A function that accepts the child and its index.
|
|
440
|
-
*/
|
|
441
|
-
mapBoxed<U>(callbackfn: (value: FlexTreeTypedNodeUnion<TTypes>, index: number) => U): U[];
|
|
442
351
|
readonly length: number;
|
|
443
352
|
/**
|
|
444
353
|
* Get an editor for this sequence.
|
|
@@ -493,7 +402,7 @@ export type FlexTreeTypedNodeUnion<T extends FlexAllowedTypes> = T extends FlexL
|
|
|
493
402
|
/**
|
|
494
403
|
* Schema aware specialization of {@link FlexTreeNode} for a given {@link FlexTreeNodeSchema}.
|
|
495
404
|
*/
|
|
496
|
-
export type FlexTreeTypedNode<TSchema extends FlexTreeNodeSchema> = TSchema extends LeafNodeSchema ? FlexTreeLeafNode<TSchema> : TSchema extends FlexMapNodeSchema ? FlexTreeMapNode<TSchema> : TSchema extends FlexObjectNodeSchema ?
|
|
405
|
+
export type FlexTreeTypedNode<TSchema extends FlexTreeNodeSchema> = TSchema extends LeafNodeSchema ? FlexTreeLeafNode<TSchema> : TSchema extends FlexMapNodeSchema ? FlexTreeMapNode<TSchema> : TSchema extends FlexObjectNodeSchema ? FlexTreeObjectNode : FlexTreeNode;
|
|
497
406
|
/**
|
|
498
407
|
* Schema aware unboxed field.
|
|
499
408
|
* @remarks
|
|
@@ -526,7 +435,7 @@ export type IsArrayOfOne<T extends readonly unknown[]> = T["length"] extends 1 ?
|
|
|
526
435
|
* Unboxes if the node kind does unboxing.
|
|
527
436
|
* Recursively unboxes that content as well if it does unboxing.
|
|
528
437
|
*/
|
|
529
|
-
export type FlexTreeUnboxNode<TSchema extends FlexTreeNodeSchema> = TSchema extends LeafNodeSchema ? TreeValue<TSchema["info"]> : TSchema extends FlexMapNodeSchema ? FlexTreeMapNode<TSchema> : TSchema extends FlexObjectNodeSchema ?
|
|
438
|
+
export type FlexTreeUnboxNode<TSchema extends FlexTreeNodeSchema> = TSchema extends LeafNodeSchema ? TreeValue<TSchema["info"]> : TSchema extends FlexMapNodeSchema ? FlexTreeMapNode<TSchema> : TSchema extends FlexObjectNodeSchema ? FlexTreeObjectNode : FlexTreeUnknownUnboxed;
|
|
530
439
|
/**
|
|
531
440
|
* Unboxed tree type for unknown schema cases.
|
|
532
441
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"flexTreeTypes.d.ts","sourceRoot":"","sources":["../../../src/feature-libraries/flex-tree/flexTreeTypes.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EACN,KAAK,UAAU,EACf,KAAK,gBAAgB,EACrB,KAAK,QAAQ,EACb,KAAK,WAAW,EAChB,KAAK,SAAS,EAEd,MAAM,qBAAqB,CAAC;AAC7B,OAAO,KAAK,EAAE,MAAM,EAAE,
|
|
1
|
+
{"version":3,"file":"flexTre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AS,CAAC,GAEpF,OAAO,CAAC;AAEZ;;;;;GAKG;AACH,MAAM,MAAM,sBAAsB,CAAC,MAAM,SAAS,gBAAgB,IAAI,MAAM,SAAS,SAAS;IAC7F,QAAQ,CAAC,MAAM,SAAS,CAAC;CACzB,GACE,SAAS,SAAS,kBAAkB,GACnC,iBAAiB,CAAC,SAAS,CAAC,GAC5B,SAAS,SAAS,GAAG,GACpB,YAAY,GAEb,OAAO,GACR,OAAO,SAAS,YAAY,CAAC,MAAM,CAAC,GACnC,sBAAsB,GACtB,sBAAsB,CAAC,MAAM,CAAC,CAAC;AAEnC;;;;GAIG;AACH,MAAM,MAAM,YAAY,CAAC,CAAC,SAAS,SAAS,OAAO,EAAE,IAAI,CAAC,CAAC,QAAQ,CAAC,SAAS,CAAC,GAC3E,IAAI,GACJ,CAAC,SAAS,CAAC,CAAC,QAAQ,CAAC,GACpB,OAAO,GACP,KAAK,CAAC;AAEV;;;;;GAKG;AACH,MAAM,MAAM,iBAAiB,CAAC,OAAO,SAAS,kBAAkB,IAC/D,OAAO,SAAS,cAAc,GAC3B,SAAS,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,GAC1B,OAAO,SAAS,iBAAiB,GAChC,eAAe,CAAC,OAAO,CAAC,GACxB,OAAO,SAAS,oBAAoB,GACnC,kBAAkB,GAClB,sBAAsB,CAAC;AAE7B;;GAEG;AACH,MAAM,MAAM,sBAAsB,GAAG,SAAS,GAAG,YAAY,CAAC"}
|
|
@@ -48,34 +48,5 @@ export var TreeStatus;
|
|
|
48
48
|
*/
|
|
49
49
|
TreeStatus[TreeStatus["New"] = 3] = "New";
|
|
50
50
|
})(TreeStatus || (TreeStatus = {}));
|
|
51
|
-
/**
|
|
52
|
-
* Reserved object node field property names to avoid collisions with the rest of the object node API.
|
|
53
|
-
*/
|
|
54
|
-
export const reservedObjectNodeFieldPropertyNames = [
|
|
55
|
-
"anchorNode",
|
|
56
|
-
"constructor",
|
|
57
|
-
"context",
|
|
58
|
-
"is",
|
|
59
|
-
"parentField",
|
|
60
|
-
"schema",
|
|
61
|
-
"tryGetField",
|
|
62
|
-
"type",
|
|
63
|
-
"value",
|
|
64
|
-
"boxedIterator",
|
|
65
|
-
"iterator",
|
|
66
|
-
"getBoxed",
|
|
67
|
-
];
|
|
68
|
-
/**
|
|
69
|
-
* Reserved object node field property names prefixes.
|
|
70
|
-
* These are reserved to avoid collisions with properties derived from field other field names.
|
|
71
|
-
*
|
|
72
|
-
* Field names starting with these must be followed by a lowercase letter, or be escaped.
|
|
73
|
-
*/
|
|
74
|
-
export const reservedObjectNodeFieldPropertyNamePrefixes = [
|
|
75
|
-
"set",
|
|
76
|
-
"boxed",
|
|
77
|
-
"field",
|
|
78
|
-
"Field",
|
|
79
|
-
];
|
|
80
51
|
// #endregion
|
|
81
52
|
//# sourceMappingURL=flexTreeTypes.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"flexTreeTypes.js","sourceRoot":"","sources":["../../../src/feature-libraries/flex-tree/flexTreeTypes.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAMN,UAAU,GACV,MAAM,qBAAqB,CAAC;AAyB7B;;;GAGG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,UAAU,EAAgB,CAAC;AAEvD;;GAEG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,MAAM,CAAC,gBAAgB,CAAC,CAAC;AAEvD,MAAM,UAAU,gBAAgB,CAAC,CAAU;IAC1C,OAAO,OAAO,CAAC,KAAK,QAAQ,IAAI,CAAC,KAAK,IAAI,IAAI,cAAc,IAAI,CAAC,CAAC;AACnE,CAAC;AAED,MAAM,UAAU,cAAc,CAAC,CAAU;IACxC,OAAO,gBAAgB,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,cAAc,CAAC,KAAK,kBAAkB,CAAC,IAAI,CAAC;AAC7E,CAAC;AAED;GACG;AACH,MAAM,CAAN,IAAY,kBAGX;AAHD,WAAY,kBAAkB;IAC7B,2DAAI,CAAA;IACJ,6DAAK,CAAA;AACN,CAAC,EAHW,kBAAkB,KAAlB,kBAAkB,QAG7B;AA4CD;;;GAGG;AACH,MAAM,CAAN,IAAY,UAoBX;AApBD,WAAY,UAAU;IACrB;;OAEG;IACH,uDAAc,CAAA;IAEd;;OAEG;IACH,iDAAW,CAAA;IAEX;;OAEG;IACH,iDAAW,CAAA;IAEX;;OAEG;IACH,yCAAO,CAAA;AACR,CAAC,EApBW,UAAU,KAAV,UAAU,QAoBrB;AAmUD;;GAEG;AACH,MAAM,CAAC,MAAM,oCAAoC,GAAG;IACnD,YAAY;IACZ,aAAa;IACb,SAAS;IACT,IAAI;IACJ,aAAa;IACb,QAAQ;IACR,aAAa;IACb,MAAM;IACN,OAAO;IACP,eAAe;IACf,UAAU;IACV,UAAU;CACD,CAAC;AAEX;;;;;GAKG;AACH,MAAM,CAAC,MAAM,2CAA2C,GAAG;IAC1D,KAAK;IACL,OAAO;IACP,OAAO;IACP,OAAO;CACE,CAAC;AAqSX,aAAa","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport {\n\ttype AnchorNode,\n\ttype ExclusiveMapTree,\n\ttype FieldKey,\n\ttype FieldUpPath,\n\ttype TreeValue,\n\tanchorSlot,\n} from \"../../core/index.js\";\nimport type { Assume, FlattenKeys } from \"../../util/index.js\";\nimport type {\n\tFieldKinds,\n\tSequenceFieldEditBuilder,\n\tValueFieldEditBuilder,\n\tOptionalFieldEditBuilder,\n} from \"../default-schema/index.js\";\nimport type { FlexFieldKind } from \"../modular-schema/index.js\";\nimport type {\n\tAny,\n\tFlexAllowedTypes,\n\tFlexFieldSchema,\n\tFlexList,\n\tFlexListToUnion,\n\tFlexMapNodeSchema,\n\tFlexObjectNodeFields,\n\tFlexObjectNodeSchema,\n\tFlexTreeNodeSchema,\n\tLazyItem,\n\tLeafNodeSchema,\n} from \"../typed-schema/index.js\";\n\nimport type { FlexTreeContext } from \"./context.js\";\n\n/**\n * An anchor slot which records the {@link FlexTreeNode} associated with that anchor, if there is one.\n * @remarks This always points to a \"real\" {@link FlexTreeNode} (i.e. a `LazyTreeNode`), never to a \"raw\" node.\n */\nexport const flexTreeSlot = anchorSlot<FlexTreeNode>();\n\n/**\n * Indicates that an object is a flex tree.\n */\nexport const flexTreeMarker = Symbol(\"flexTreeMarker\");\n\nexport function isFlexTreeEntity(t: unknown): t is FlexTreeEntity {\n\treturn typeof t === \"object\" && t !== null && flexTreeMarker in t;\n}\n\nexport function isFlexTreeNode(t: unknown): t is FlexTreeNode {\n\treturn isFlexTreeEntity(t) && t[flexTreeMarker] === FlexTreeEntityKind.Node;\n}\n\n/**\n */\nexport enum FlexTreeEntityKind {\n\tNode,\n\tField,\n}\n\n/**\n * Part of a tree.\n * Iterates over children.\n *\n * @privateRemarks\n * This exists mainly as a place to share common members between nodes and fields.\n * It is not expected to be useful or common to write code which handles this type directly.\n * If this assumption turns out to be false, and generically processing `UntypedEntity`s is useful,\n * then this interface should probably be extended with some down casting functionality (like `is`).\n *\n * TODO:\n * Design and document iterator invalidation rules and ordering rules.\n * Providing a custom iterator type with place anchor semantics would be a good approach.\n */\nexport interface FlexTreeEntity<out TSchema = unknown> {\n\t/**\n\t * Indicates that an object is a specific kind of flex tree FlexTreeEntity.\n\t * This makes it possible to both down cast FlexTreeEntities safely as well as validate if an object is or is not a FlexTreeEntity.\n\t */\n\treadonly [flexTreeMarker]: FlexTreeEntityKind;\n\n\t/**\n\t * Schema for this entity.\n\t * If well-formed, it must follow this schema.\n\t */\n\treadonly schema: TSchema;\n\n\t/**\n\t * A common context of a \"forest\" of FlexTrees.\n\t * @remarks This is `undefined` for unhydrated nodes or fields that have not yet been inserted into the tree.\n\t */\n\treadonly context?: FlexTreeContext;\n\n\t/**\n\t * Iterate through all nodes/fields in this field/node.\n\t *\n\t * @remarks\n\t * No mutations to the current view of the shared tree are permitted during iteration.\n\t */\n\tboxedIterator(): IterableIterator<FlexTreeEntity>;\n}\n\n/**\n * Status of the tree that a particular node belongs to.\n * @public\n */\nexport enum TreeStatus {\n\t/**\n\t * Is parented under the root field.\n\t */\n\tInDocument = 0,\n\n\t/**\n\t * Is not parented under the root field, but can be added back to the original document tree.\n\t */\n\tRemoved = 1,\n\n\t/**\n\t * Is removed and cannot be added back to the original document tree.\n\t */\n\tDeleted = 2,\n\n\t/**\n\t * Is created but has not yet been inserted into the tree.\n\t */\n\tNew = 3,\n}\n\n/**\n * Generic tree node API.\n *\n * Nodes are (shallowly) immutable and have a logical identity, a type and either a value or fields under string keys.\n *\n * This \"logical identity\" is exposed as the object identity: if a node is moved within a document,\n * the same {@link FlexTreeNode} instance will be used in the new location.\n * Similarly, edits applied to a node's sub-tree concurrently with the move of the node will still be applied to its subtree in its new location.\n *\n *\n * @remarks\n * Down-casting (via {@link FlexTreeNode#is}) is required to access Schema-Aware APIs, including editing.\n * All content in the tree is accessible without down-casting, but if the schema is known,\n * the schema aware API may be more ergonomic.\n * All editing is actually done via {@link FlexTreeField}s: the nodes are immutable other than that they contain mutable fields.\n */\nexport interface FlexTreeNode extends FlexTreeEntity<FlexTreeNodeSchema> {\n\treadonly [flexTreeMarker]: FlexTreeEntityKind.Node;\n\n\t/**\n\t * Value stored on this node.\n\t */\n\treadonly value?: TreeValue;\n\n\t/**\n\t * Gets a field of this node, if it is not empty.\n\t */\n\ttryGetField(key: FieldKey): undefined | FlexTreeField;\n\n\t/**\n\t * Get the field for `key`.\n\t * @param key - which entry to look up.\n\t *\n\t * @remarks\n\t * All fields implicitly exist, so `getBoxed` can be called with any key and will always return a field.\n\t * Even if the field is empty, it will still be returned, and can be edited to insert content if allowed by the field kind.\n\t * See {@link FlexTreeNode.tryGetField} for a variant that does not allocate afield in the empty case.\n\t */\n\tgetBoxed(key: FieldKey): FlexTreeField;\n\n\t/**\n\t * The field this tree is in, and the index within that field.\n\t */\n\treadonly parentField: { readonly parent: FlexTreeField; readonly index: number };\n\n\t/**\n\t * Type guard for narrowing / down-casting to a specific schema.\n\t */\n\tis<TSchema extends FlexTreeNodeSchema>(schema: TSchema): this is FlexTreeTypedNode<TSchema>;\n\n\tboxedIterator(): IterableIterator<FlexTreeField>;\n\n\t/**\n\t * The anchor node associated with this node\n\t *\n\t * @remarks\n\t * The ref count keeping this alive is owned by the FlexTreeNode:\n\t * if holding onto this anchor for longer than the FlexTreeNode might be alive,\n\t * a separate Anchor (and thus ref count) must be allocated to keep it alive.\n\t */\n\treadonly anchorNode: AnchorNode;\n}\n\n/**\n * A collaboratively editable collection of nodes within a {@link FlexTreeEntity}.\n *\n * Fields are inherently part of their parent, and thus cannot be moved.\n * Instead their content can be moved, deleted or created.\n *\n * Editing operations are only valid on trees with the {@link TreeStatus#InDocument} `TreeStatus`.\n *\n * @remarks\n * Fields are used wherever an editable collection of nodes is required.\n * This is required in two places:\n * 1. To hold the children of non-leaf {@link FlexTreeNode}s.\n * 2. As the root of a {@link FlexTreeEntity}.\n *\n * Down-casting (via {@link FlexTreeField.is}) is required to access Schema-Aware APIs, including editing.\n * All content in the tree is accessible without down-casting, but if the schema is known,\n * the schema aware API may be more ergonomic.\n */\nexport interface FlexTreeField extends FlexTreeEntity<FlexFieldSchema> {\n\treadonly [flexTreeMarker]: FlexTreeEntityKind.Field;\n\n\t/**\n\t * The number of nodes in this field\n\t */\n\treadonly length: number;\n\n\t/**\n\t * The `FieldKey` this field is under.\n\t * Defines what part of its parent this field makes up.\n\t */\n\treadonly key: FieldKey;\n\n\t/**\n\t * The node which has this field on it under `fieldKey`.\n\t * `undefined` iff this field is a detached field.\n\t */\n\treadonly parent?: FlexTreeNode;\n\n\t/**\n\t * Type guard for narrowing / down-casting to a specific schema.\n\t */\n\tis<TSchema extends FlexFieldSchema>(schema: TSchema): this is FlexTreeTypedField<TSchema>;\n\n\tboxedIterator(): IterableIterator<FlexTreeNode>;\n\n\t/**\n\t * Gets a node of this field by its index without unboxing.\n\t * @param index - Zero-based index of the item to retrieve. Negative values are interpreted from the end of the sequence.\n\t *\n\t * @returns The element in the sequence matching the given index. Always returns undefined if index \\< -sequence.length\n\t * or index \\>= sequence.length.\n\t *\n\t * @remarks\n\t * Semantics match {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/at | Array.at}.\n\t */\n\tboxedAt(index: number): FlexTreeNode | undefined;\n}\n\n// #region Node Kinds\n\n/**\n * A {@link FlexTreeNode} that behaves like a `Map<string, Field>` for a specific `Field` type.\n *\n * @remarks\n * Unlike TypeScript Map type, {@link FlexTreeMapNode.get} always provides a reference to any field looked up, even if it has never been set.\n *\n * This means that, for example, a `MapNode` of {@link FlexTreeSequenceField} fields will return an empty sequence when a previously unused key is looked up,\n * and that sequence can be used to insert new items into the field.\n * Additionally empty fields (those containing no nodes) are not distinguished from fields which do not exist.\n * This differs from JavaScript Maps which have a subtle distinction between storing undefined as a value in the map and deleting an entry from the map.\n */\nexport interface FlexTreeMapNode<in out TSchema extends FlexMapNodeSchema>\n\textends FlexTreeNode {\n\treadonly schema: TSchema;\n\n\t/**\n\t * Get the field for `key`.\n\t * @param key - which map entry to look up.\n\t *\n\t * @remarks\n\t * All fields under a map implicitly exist, so `get` can be called with any key and will always return a field.\n\t * Even if the field is empty, it will still be returned, and can be edited to insert content into the map.\n\t */\n\tgetBoxed(key: string): FlexTreeTypedField<TSchema[\"info\"]>;\n\n\t/**\n\t * Returns an iterable of keys in the map.\n\t *\n\t * @remarks\n\t * All fields under a map implicitly exist, but `keys` will yield only the keys of fields which contain one or more nodes.\n\t *\n\t * No guarantees are made regarding the order of the keys returned.\n\t */\n\tkeys(): IterableIterator<FieldKey>;\n\n\t/**\n\t * Returns an iterable of values in the map.\n\t *\n\t * @remarks\n\t * All fields under a map implicitly exist, but `values` will yield only the fields containing one or more nodes.\n\t *\n\t * No guarantees are made regarding the order of the values returned.\n\t */\n\tvalues(): IterableIterator<FlexTreeUnboxField<TSchema[\"info\"], \"notEmpty\">>;\n\n\t/**\n\t * Returns an iterable of key, value pairs for every entry in the map.\n\t *\n\t * @remarks\n\t * All fields under a map implicitly exist, but `entries` will yield only the entries whose fields contain one or more nodes.\n\t *\n\t * This iteration provided by `entries()` is equivalent to that provided by direct iteration of the {@link FlexTreeMapNode} (a.k.a. `[Symbol.Iterator]()`).\n\t *\n\t * No guarantees are made regarding the order of the entries returned.\n\t */\n\tentries(): IterableIterator<[FieldKey, FlexTreeUnboxField<TSchema[\"info\"], \"notEmpty\">]>;\n\n\t/**\n\t * Executes a provided function once per each key/value pair in the map.\n\t * @param callbackFn - The function to run for each map entry\n\t * @param thisArg - If present, `callbackFn` will be bound to `thisArg`\n\t *\n\t * @privateRemarks\n\t * TODO: This should run over fields in insertion order if we want to match the javascript foreach spec.\n\t */\n\tforEach(\n\t\tcallbackFn: (\n\t\t\tvalue: FlexTreeUnboxField<TSchema[\"info\"], \"notEmpty\">,\n\t\t\tkey: FieldKey,\n\t\t\tmap: FlexTreeMapNode<TSchema>,\n\t\t) => void,\n\t\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\t\tthisArg?: any,\n\t): void;\n\n\t/**\n\t * Iterate through all fields in the map.\n\t *\n\t * @remarks\n\t * No mutations to the current view of the shared tree are permitted during iteration.\n\t * To iterate over the unboxed values of the map, use `Symbol.Iterator()`.\n\t */\n\tboxedIterator(): IterableIterator<FlexTreeTypedField<TSchema[\"info\"]>>;\n\n\t[Symbol.iterator](): IterableIterator<\n\t\t[FieldKey, FlexTreeUnboxField<TSchema[\"info\"], \"notEmpty\">]\n\t>;\n}\n\n/**\n * A {@link FlexTreeNode} that behaves like an \"object\" or \"struct\", providing properties to access its fields.\n *\n * ObjectNodes consist of a finite collection of fields, each with their own (distinct) key and {@link FlexFieldSchema}.\n *\n * @remarks\n * ObjectNodes require complex typing, and have been split into two parts for implementation purposes.\n * See {@link FlexTreeObjectNodeTyped} for the schema aware extensions to this that provide access to the fields.\n *\n * These \"Objects\" resemble \"Structs\" from a wide variety of programming languages\n * (Including Algol 68, C, Go, Rust, C# etc.).\n * ObjectNodes also somewhat resemble JavaScript objects: this analogy is less precise (objects don't have a fixed schema for example),\n * but for consistency with other systems in the JavaScript ecosystem (like JSON) is \"ObjectNodes\" nodes are named \"Objects\".\n *\n * Another common name for this abstraction is [record](https://en.wikipedia.org/wiki/Record_(computer_science)).\n * The name \"Record\" is avoided (in favor of Object) here because it has less precise connotations for most TypeScript developers.\n * For example, TypeScript has a built in `Record` type, but it requires all of the fields to have the same type,\n * putting its semantics half way between this library's \"Object\" schema and {@link FlexTreeMapNode}.\n */\nexport interface FlexTreeObjectNode extends FlexTreeNode {\n\treadonly schema: FlexObjectNodeSchema;\n}\n\n/**\n * Leaf holding a value.\n *\n * @remarks\n * Leaves are immutable and have no children.\n * Leaf unboxes its content, so in schema aware APIs which do unboxing, the Leaf itself will be skipped over and its value will be returned directly.\n */\nexport interface FlexTreeLeafNode<in out TSchema extends LeafNodeSchema> extends FlexTreeNode {\n\treadonly schema: TSchema;\n\n\t/**\n\t * Value stored on this node.\n\t */\n\treadonly value: TreeValue<TSchema[\"info\"]>;\n}\n\n/**\n * An {@link FlexTreeObjectNode} with schema aware accessors for its fields.\n *\n * @privateRemarks\n *\n * The corresponding implementation logic for this lives in `LazyTree.ts` under `buildStructClass`.\n * If you change the signature here, you will need to update that logic to match.\n */\nexport type FlexTreeObjectNodeTyped<TSchema extends FlexObjectNodeSchema> =\n\tFlexObjectNodeSchema extends TSchema\n\t\t? FlexTreeObjectNode\n\t\t: FlexTreeObjectNode & FlexTreeObjectNodeFields<TSchema[\"info\"]>;\n\n/**\n * Properties to access an object node's fields. See {@link FlexTreeObjectNodeTyped}.\n *\n * @privateRemarks\n * TODO: Support custom field keys.\n */\nexport type FlexTreeObjectNodeFields<TFields extends FlexObjectNodeFields> =\n\tFlexTreeObjectNodeFieldsInner<\n\t\tFlattenKeys<\n\t\t\t{\n\t\t\t\t// When the key does not need to be escaped, map it from the input TFields in a way that doesn't break navigate to declaration\n\t\t\t\t[key in keyof TFields as key extends PropertyNameFromFieldKey<key & string>\n\t\t\t\t\t? key\n\t\t\t\t\t: never]: TFields[key];\n\t\t\t} & {\n\t\t\t\t[key in keyof TFields as key extends PropertyNameFromFieldKey<key & string>\n\t\t\t\t\t? never\n\t\t\t\t\t: PropertyNameFromFieldKey<key & string>]: TFields[key];\n\t\t\t}\n\t\t>\n\t>;\n\n/**\n * Properties to access an object node's fields. See {@link FlexTreeObjectNodeTyped}.\n *\n * @privateRemarks\n * TODO: Do we keep assignment operator + \"setFoo\" methods, or just use methods?\n * Inconsistency in the API experience could confusing for consumers.\n */\nexport type FlexTreeObjectNodeFieldsInner<TFields extends FlexObjectNodeFields> = FlattenKeys<\n\t{\n\t\t// boxed fields (TODO: maybe remove these when same as non-boxed version?)\n\t\treadonly [key in keyof TFields as `boxed${Capitalize<key & string>}`]: FlexTreeTypedField<\n\t\t\tTFields[key]\n\t\t>;\n\t} & {\n\t\t// Add getter only (make property readonly) when the field is **not** of a kind that has a logical set operation.\n\t\t// If we could map to getters and setters separately, we would preferably do that, but we can't.\n\t\t// See https://github.com/microsoft/TypeScript/issues/43826 for more details on this limitation.\n\t\treadonly [key in keyof TFields as TFields[key][\"kind\"] extends AssignableFieldKinds\n\t\t\t? never\n\t\t\t: key]: FlexTreeUnboxField<TFields[key]>;\n\t} & {\n\t\t// Add setter (make property writable) when the field is of a kind that has a logical set operation.\n\t\t// If we could map to getters and setters separately, we would preferably do that, but we can't.\n\t\t// See https://github.com/microsoft/TypeScript/issues/43826 for more details on this limitation.\n\t\t-readonly [key in keyof TFields as TFields[key][\"kind\"] extends AssignableFieldKinds\n\t\t\t? key\n\t\t\t: never]: FlexTreeUnboxField<TFields[key]>;\n\t} & {\n\t\t// Setter method (when the field is of a kind that has a logical set operation).\n\t\treadonly [key in keyof TFields as TFields[key][\"kind\"] extends AssignableFieldKinds\n\t\t\t? `set${Capitalize<key & string>}`\n\t\t\t: never]: (content: FlexibleNodeContent) => void;\n\t}\n>;\n\n/**\n * Reserved object node field property names to avoid collisions with the rest of the object node API.\n */\nexport const reservedObjectNodeFieldPropertyNames = [\n\t\"anchorNode\",\n\t\"constructor\",\n\t\"context\",\n\t\"is\",\n\t\"parentField\",\n\t\"schema\",\n\t\"tryGetField\",\n\t\"type\",\n\t\"value\",\n\t\"boxedIterator\",\n\t\"iterator\",\n\t\"getBoxed\",\n] as const;\n\n/**\n * Reserved object node field property names prefixes.\n * These are reserved to avoid collisions with properties derived from field other field names.\n *\n * Field names starting with these must be followed by a lowercase letter, or be escaped.\n */\nexport const reservedObjectNodeFieldPropertyNamePrefixes = [\n\t\"set\",\n\t\"boxed\",\n\t\"field\",\n\t\"Field\",\n] as const;\n\n/**\n * {@link reservedObjectNodeFieldPropertyNamePrefixes} as a type union.\n */\nexport type ReservedObjectNodeFieldPropertyNames =\n\t(typeof reservedObjectNodeFieldPropertyNames)[number];\n\n/**\n * {@link reservedObjectNodeFieldPropertyNamePrefixes} as a type union.\n */\nexport type ReservedObjectNodeFieldPropertyNamePrefixes =\n\t(typeof reservedObjectNodeFieldPropertyNamePrefixes)[number];\n\n/**\n * Convert an object node's field key into an escaped string usable as a property name.\n *\n * @privateRemarks\n * TODO:\n * Collisions are still possible.\n * For example fields named \"foo\" and \"Foo\" would both produce a setter \"setFoo\".\n * Consider naming schemes to avoid this, ensure that there is a good workaround for these cases.\n * Another approach would be to support custom field names (separate from keys),\n * and do the escaping (if needed) when creating the flex tree schema (both when manually creating them and when doing so automatically):\n * this would enable better intellisense for escaped fields, as well as allow the feature of custom field property names.\n */\nexport type PropertyNameFromFieldKey<T extends string> =\n\tT extends ReservedObjectNodeFieldPropertyNames\n\t\t? `field${Capitalize<T>}`\n\t\t: T extends `${ReservedObjectNodeFieldPropertyNamePrefixes}${Capitalize<string>}`\n\t\t\t? `field${Capitalize<T>}`\n\t\t\t: T;\n\n/**\n * Field kinds that allow value assignment.\n */\nexport type AssignableFieldKinds = typeof FieldKinds.optional | typeof FieldKinds.required;\n\n// #endregion\n\n// #region Field Kinds\n\n/**\n * Typed tree for inserting as the content of a field.\n */\nexport type FlexibleFieldContent = ExclusiveMapTree[];\n\n/**\n * Tree for inserting as a node.\n */\nexport type FlexibleNodeContent = ExclusiveMapTree;\n\n/**\n * Tree for inserting a subsequence of nodes.\n *\n * Used to insert a batch of 0 or more nodes into some location in a {@link FlexTreeSequenceField}.\n */\nexport type FlexibleNodeSubSequence = ExclusiveMapTree[];\n\n/**\n * Type to ensures two types overlap in at least one way.\n * It evaluates to the input type if this is true, and never otherwise.\n * Examples:\n * CheckTypesOverlap\\<number | boolean, number | object\\> = number | boolean\n * CheckTypesOverlap\\<number | boolean, string | object\\> = never\n */\nexport type CheckTypesOverlap<T, TCheck> = [Extract<T, TCheck> extends never ? never : T][0];\n\n/**\n * {@link FlexTreeField} that stores a sequence of children.\n *\n * Sequence fields can contain an ordered sequence any number of {@link FlexTreeNode}s which must be of the {@link FlexAllowedTypes} from the {@link FlexFieldSchema}).\n *\n * @remarks\n * Allows for concurrent editing based on index, adjusting the locations of indexes as needed so they apply to the same logical place in the sequence when rebased and merged.\n *\n * Edits to sequence fields are anchored relative to their surroundings, so concurrent edits can result in the indexes of nodes and edits getting shifted.\n * To hold onto locations in sequence across an edit, use anchors.\n *\n * @privateRemarks\n * TODO:\n * Add anchor API that can actually hold onto locations in a sequence.\n * Currently only nodes can be held onto with anchors, and this does not replicate the behavior implemented for editing.\n */\nexport interface FlexTreeSequenceField<in out TTypes extends FlexAllowedTypes>\n\textends FlexTreeField {\n\t/**\n\t * Gets a node of this field by its index with unboxing.\n\t * @param index - Zero-based index of the item to retrieve. Negative values are interpreted from the end of the sequence.\n\t *\n\t * @returns The element in the sequence matching the given index. Always returns undefined if index \\< -sequence.length\n\t * or index \\>= array.length.\n\t *\n\t * @remarks\n\t * Semantics match {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/at | Array.at}.\n\t */\n\tat(index: number): FlexTreeUnboxNodeUnion<TTypes> | undefined;\n\n\t/**\n\t * {@inheritdoc FlexTreeField.boxedAt}\n\t */\n\tboxedAt(index: number): FlexTreeTypedNodeUnion<TTypes> | undefined;\n\n\t/**\n\t * Calls the provided callback function on each child of this sequence, and returns an array that contains the results.\n\t * @param callbackfn - A function that accepts the child and its index.\n\t */\n\tmap<U>(callbackfn: (value: FlexTreeUnboxNodeUnion<TTypes>, index: number) => U): U[];\n\n\t/**\n\t * Calls the provided callback function on each child of this sequence, and returns an array that contains the results.\n\t * @param callbackfn - A function that accepts the child and its index.\n\t */\n\tmapBoxed<U>(callbackfn: (value: FlexTreeTypedNodeUnion<TTypes>, index: number) => U): U[];\n\n\treadonly length: number;\n\n\t/**\n\t * Get an editor for this sequence.\n\t */\n\treadonly editor: SequenceFieldEditBuilder<FlexibleFieldContent>;\n\n\tboxedIterator(): IterableIterator<FlexTreeTypedNodeUnion<TTypes>>;\n\n\t/**\n\t * Gets the FieldUpPath of a field.\n\t */\n\tgetFieldPath(): FieldUpPath;\n\n\t[Symbol.iterator](): IterableIterator<FlexTreeUnboxNodeUnion<TTypes>>;\n}\n\n/**\n * Field that stores exactly one child.\n *\n * @remarks\n * Unboxes its content, so in schema aware APIs which do unboxing, the RequiredField itself will be skipped over and its content will be returned directly.\n */\nexport interface FlexTreeRequiredField<in out TTypes extends FlexAllowedTypes>\n\textends FlexTreeField {\n\tget content(): FlexTreeUnboxNodeUnion<TTypes>;\n\n\treadonly editor: ValueFieldEditBuilder<FlexibleNodeContent>;\n}\n\n/**\n * Field that stores zero or one child.\n *\n * @remarks\n * Unboxes its content, so in schema aware APIs which do unboxing, the OptionalField itself will be skipped over and its content will be returned directly.\n *\n * @privateRemarks\n * TODO: Document merge semitics\n * TODO: Allow Optional fields to be used with last write wins OR first write wins merge resolution.\n * TODO:\n * Better centralize the documentation about what kinds of merge semantics are available for field kinds.\n * Maybe link editor?\n */\nexport interface FlexTreeOptionalField<in out TTypes extends FlexAllowedTypes>\n\textends FlexTreeField {\n\tget content(): FlexTreeUnboxNodeUnion<TTypes> | undefined;\n\n\treadonly editor: OptionalFieldEditBuilder<FlexibleNodeContent>;\n}\n\n// #endregion\n\n// #region Typed\n\n/**\n * Schema aware specialization of {@link FlexTreeField}.\n */\nexport type FlexTreeTypedField<TSchema extends FlexFieldSchema> = FlexTreeTypedFieldInner<\n\tTSchema[\"kind\"],\n\tTSchema[\"allowedTypes\"]\n>;\n\n/**\n * Helper for implementing {@link FlexTreeTypedField}.\n */\nexport type FlexTreeTypedFieldInner<\n\tKind extends FlexFieldKind,\n\tTypes extends FlexAllowedTypes,\n> = Kind extends typeof FieldKinds.sequence\n\t? FlexTreeSequenceField<Types>\n\t: Kind extends typeof FieldKinds.required\n\t\t? FlexTreeRequiredField<Types>\n\t\t: Kind extends typeof FieldKinds.optional\n\t\t\t? FlexTreeOptionalField<Types>\n\t\t\t: FlexTreeField;\n\n/**\n * Schema aware specialization of {@link FlexTreeNode} for a given {@link FlexAllowedTypes}.\n */\nexport type FlexTreeTypedNodeUnion<T extends FlexAllowedTypes> =\n\tT extends FlexList<FlexTreeNodeSchema>\n\t\t? FlexTreeTypedNode<Assume<FlexListToUnion<T>, FlexTreeNodeSchema>>\n\t\t: FlexTreeNode;\n\n/**\n * Schema aware specialization of {@link FlexTreeNode} for a given {@link FlexTreeNodeSchema}.\n */\nexport type FlexTreeTypedNode<TSchema extends FlexTreeNodeSchema> =\n\tTSchema extends LeafNodeSchema\n\t\t? FlexTreeLeafNode<TSchema>\n\t\t: TSchema extends FlexMapNodeSchema\n\t\t\t? FlexTreeMapNode<TSchema>\n\t\t\t: TSchema extends FlexObjectNodeSchema\n\t\t\t\t? FlexTreeObjectNodeTyped<TSchema>\n\t\t\t\t: FlexTreeNode;\n\n// #endregion\n\n// #region Unbox\n\n/**\n * Schema aware unboxed field.\n * @remarks\n * Unboxes fields to their content if appropriate for the kind.\n * Recursively unboxes that content (then its content etc.) as well if the node union does unboxing.\n */\nexport type FlexTreeUnboxField<\n\tTSchema extends FlexFieldSchema,\n\t// If \"notEmpty\", then optional fields will unbox to their content (not their content | undefined)\n\tEmptiness extends \"maybeEmpty\" | \"notEmpty\" = \"maybeEmpty\",\n> = FlexTreeUnboxFieldInner<TSchema[\"kind\"], TSchema[\"allowedTypes\"], Emptiness>;\n\n/**\n * Helper for implementing FlexTreeUnboxField.\n */\nexport type FlexTreeUnboxFieldInner<\n\tKind extends FlexFieldKind,\n\tTTypes extends FlexAllowedTypes,\n\tEmptiness extends \"maybeEmpty\" | \"notEmpty\",\n> = Kind extends typeof FieldKinds.sequence\n\t? FlexTreeSequenceField<TTypes>\n\t: Kind extends typeof FieldKinds.required\n\t\t? FlexTreeUnboxNodeUnion<TTypes>\n\t\t: Kind extends typeof FieldKinds.optional\n\t\t\t? FlexTreeUnboxNodeUnion<TTypes> | (Emptiness extends \"notEmpty\" ? never : undefined)\n\t\t\t: // TODO: forbidden\n\t\t\t\tunknown;\n\n/**\n * Schema aware unboxed union of tree types.\n * @remarks\n * Unboxes when not polymorphic.\n * Recursively unboxes that content as well if the node kind does unboxing.\n */\nexport type FlexTreeUnboxNodeUnion<TTypes extends FlexAllowedTypes> = TTypes extends readonly [\n\tLazyItem<infer InnerType>,\n]\n\t? InnerType extends FlexTreeNodeSchema\n\t\t? FlexTreeUnboxNode<InnerType>\n\t\t: InnerType extends Any\n\t\t\t? FlexTreeNode\n\t\t\t: // This case should not occur. If the result ever ends up unknown, look at places like this to debug.\n\t\t\t\tunknown\n\t: boolean extends IsArrayOfOne<TTypes>\n\t\t? FlexTreeUnknownUnboxed // Unknown if this will unbox. This should mainly happen when TTypes is AllowedTypes.\n\t\t: FlexTreeTypedNodeUnion<TTypes>; // Known to not be a single type, so known not to unbox.\n\n/**\n * `true` if T is known to be an array of one item.\n * `false` if T is known not to be an array of one item.\n * `boolean` if it is unknown if T is an array of one item or not.\n */\nexport type IsArrayOfOne<T extends readonly unknown[]> = T[\"length\"] extends 1\n\t? true\n\t: 1 extends T[\"length\"]\n\t\t? boolean\n\t\t: false;\n\n/**\n * Schema aware unboxed tree type.\n * @remarks\n * Unboxes if the node kind does unboxing.\n * Recursively unboxes that content as well if it does unboxing.\n */\nexport type FlexTreeUnboxNode<TSchema extends FlexTreeNodeSchema> =\n\tTSchema extends LeafNodeSchema\n\t\t? TreeValue<TSchema[\"info\"]>\n\t\t: TSchema extends FlexMapNodeSchema\n\t\t\t? FlexTreeMapNode<TSchema>\n\t\t\t: TSchema extends FlexObjectNodeSchema\n\t\t\t\t? FlexTreeObjectNodeTyped<TSchema>\n\t\t\t\t: FlexTreeUnknownUnboxed;\n\n/**\n * Unboxed tree type for unknown schema cases.\n */\nexport type FlexTreeUnknownUnboxed = TreeValue | FlexTreeNode;\n\n// #endregion\n"]}
|
|
1
|
+
{"version":3,"file":"flexTreeTypes.js","sourceRoot":"","sources":["../../../src/feature-libraries/flex-tree/flexTreeTypes.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAMN,UAAU,GACV,MAAM,qBAAqB,CAAC;AAwB7B;;;GAGG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,UAAU,EAAgB,CAAC;AAEvD;;GAEG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,MAAM,CAAC,gBAAgB,CAAC,CAAC;AAEvD,MAAM,UAAU,gBAAgB,CAAC,CAAU;IAC1C,OAAO,OAAO,CAAC,KAAK,QAAQ,IAAI,CAAC,KAAK,IAAI,IAAI,cAAc,IAAI,CAAC,CAAC;AACnE,CAAC;AAED,MAAM,UAAU,cAAc,CAAC,CAAU;IACxC,OAAO,gBAAgB,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,cAAc,CAAC,KAAK,kBAAkB,CAAC,IAAI,CAAC;AAC7E,CAAC;AAED;GACG;AACH,MAAM,CAAN,IAAY,kBAGX;AAHD,WAAY,kBAAkB;IAC7B,2DAAI,CAAA;IACJ,6DAAK,CAAA;AACN,CAAC,EAHW,kBAAkB,KAAlB,kBAAkB,QAG7B;AA4CD;;;GAGG;AACH,MAAM,CAAN,IAAY,UAoBX;AApBD,WAAY,UAAU;IACrB;;OAEG;IACH,uDAAc,CAAA;IAEd;;OAEG;IACH,iDAAW,CAAA;IAEX;;OAEG;IACH,iDAAW,CAAA;IAEX;;OAEG;IACH,yCAAO,CAAA;AACR,CAAC,EApBW,UAAU,KAAV,UAAU,QAoBrB;AA+dD,aAAa","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport {\n\ttype AnchorNode,\n\ttype ExclusiveMapTree,\n\ttype FieldKey,\n\ttype FieldUpPath,\n\ttype TreeValue,\n\tanchorSlot,\n} from \"../../core/index.js\";\nimport type { Assume } from \"../../util/index.js\";\nimport type {\n\tFieldKinds,\n\tSequenceFieldEditBuilder,\n\tValueFieldEditBuilder,\n\tOptionalFieldEditBuilder,\n} from \"../default-schema/index.js\";\nimport type { FlexFieldKind } from \"../modular-schema/index.js\";\nimport type {\n\tAny,\n\tFlexAllowedTypes,\n\tFlexFieldSchema,\n\tFlexList,\n\tFlexListToUnion,\n\tFlexMapNodeSchema,\n\tFlexObjectNodeSchema,\n\tFlexTreeNodeSchema,\n\tLazyItem,\n\tLeafNodeSchema,\n} from \"../typed-schema/index.js\";\n\nimport type { FlexTreeContext } from \"./context.js\";\n\n/**\n * An anchor slot which records the {@link FlexTreeNode} associated with that anchor, if there is one.\n * @remarks This always points to a \"real\" {@link FlexTreeNode} (i.e. a `LazyTreeNode`), never to a \"raw\" node.\n */\nexport const flexTreeSlot = anchorSlot<FlexTreeNode>();\n\n/**\n * Indicates that an object is a flex tree.\n */\nexport const flexTreeMarker = Symbol(\"flexTreeMarker\");\n\nexport function isFlexTreeEntity(t: unknown): t is FlexTreeEntity {\n\treturn typeof t === \"object\" && t !== null && flexTreeMarker in t;\n}\n\nexport function isFlexTreeNode(t: unknown): t is FlexTreeNode {\n\treturn isFlexTreeEntity(t) && t[flexTreeMarker] === FlexTreeEntityKind.Node;\n}\n\n/**\n */\nexport enum FlexTreeEntityKind {\n\tNode,\n\tField,\n}\n\n/**\n * Part of a tree.\n * Iterates over children.\n *\n * @privateRemarks\n * This exists mainly as a place to share common members between nodes and fields.\n * It is not expected to be useful or common to write code which handles this type directly.\n * If this assumption turns out to be false, and generically processing `UntypedEntity`s is useful,\n * then this interface should probably be extended with some down casting functionality (like `is`).\n *\n * TODO:\n * Design and document iterator invalidation rules and ordering rules.\n * Providing a custom iterator type with place anchor semantics would be a good approach.\n */\nexport interface FlexTreeEntity<out TSchema = unknown> {\n\t/**\n\t * Indicates that an object is a specific kind of flex tree FlexTreeEntity.\n\t * This makes it possible to both down cast FlexTreeEntities safely as well as validate if an object is or is not a FlexTreeEntity.\n\t */\n\treadonly [flexTreeMarker]: FlexTreeEntityKind;\n\n\t/**\n\t * Schema for this entity.\n\t * If well-formed, it must follow this schema.\n\t */\n\treadonly schema: TSchema;\n\n\t/**\n\t * A common context of a \"forest\" of FlexTrees.\n\t * @remarks This is `undefined` for unhydrated nodes or fields that have not yet been inserted into the tree.\n\t */\n\treadonly context?: FlexTreeContext;\n\n\t/**\n\t * Iterate through all nodes/fields in this field/node.\n\t *\n\t * @remarks\n\t * No mutations to the current view of the shared tree are permitted during iteration.\n\t */\n\tboxedIterator(): IterableIterator<FlexTreeEntity>;\n}\n\n/**\n * Status of the tree that a particular node belongs to.\n * @public\n */\nexport enum TreeStatus {\n\t/**\n\t * Is parented under the root field.\n\t */\n\tInDocument = 0,\n\n\t/**\n\t * Is not parented under the root field, but can be added back to the original document tree.\n\t */\n\tRemoved = 1,\n\n\t/**\n\t * Is removed and cannot be added back to the original document tree.\n\t */\n\tDeleted = 2,\n\n\t/**\n\t * Is created but has not yet been inserted into the tree.\n\t */\n\tNew = 3,\n}\n\n/**\n * Generic tree node API.\n *\n * Nodes are (shallowly) immutable and have a logical identity, a type and either a value or fields under string keys.\n *\n * This \"logical identity\" is exposed as the object identity: if a node is moved within a document,\n * the same {@link FlexTreeNode} instance will be used in the new location.\n * Similarly, edits applied to a node's sub-tree concurrently with the move of the node will still be applied to its subtree in its new location.\n *\n *\n * @remarks\n * Down-casting (via {@link FlexTreeNode#is}) is required to access Schema-Aware APIs, including editing.\n * All content in the tree is accessible without down-casting, but if the schema is known,\n * the schema aware API may be more ergonomic.\n * All editing is actually done via {@link FlexTreeField}s: the nodes are immutable other than that they contain mutable fields.\n */\nexport interface FlexTreeNode extends FlexTreeEntity<FlexTreeNodeSchema> {\n\treadonly [flexTreeMarker]: FlexTreeEntityKind.Node;\n\n\t/**\n\t * Value stored on this node.\n\t */\n\treadonly value?: TreeValue;\n\n\t/**\n\t * Gets a field of this node, if it is not empty.\n\t */\n\ttryGetField(key: FieldKey): undefined | FlexTreeField;\n\n\t/**\n\t * Get the field for `key`.\n\t * @param key - which entry to look up.\n\t *\n\t * @remarks\n\t * All fields implicitly exist, so `getBoxed` can be called with any key and will always return a field.\n\t * Even if the field is empty, it will still be returned, and can be edited to insert content if allowed by the field kind.\n\t * See {@link FlexTreeNode.tryGetField} for a variant that does not allocate afield in the empty case.\n\t */\n\tgetBoxed(key: FieldKey): FlexTreeField;\n\n\t/**\n\t * The field this tree is in, and the index within that field.\n\t */\n\treadonly parentField: { readonly parent: FlexTreeField; readonly index: number };\n\n\t/**\n\t * Type guard for narrowing / down-casting to a specific schema.\n\t */\n\tis<TSchema extends FlexTreeNodeSchema>(schema: TSchema): this is FlexTreeTypedNode<TSchema>;\n\n\tboxedIterator(): IterableIterator<FlexTreeField>;\n\n\t/**\n\t * The anchor node associated with this node\n\t *\n\t * @remarks\n\t * The ref count keeping this alive is owned by the FlexTreeNode:\n\t * if holding onto this anchor for longer than the FlexTreeNode might be alive,\n\t * a separate Anchor (and thus ref count) must be allocated to keep it alive.\n\t */\n\treadonly anchorNode: AnchorNode;\n}\n\n/**\n * A collaboratively editable collection of nodes within a {@link FlexTreeEntity}.\n *\n * Fields are inherently part of their parent, and thus cannot be moved.\n * Instead their content can be moved, deleted or created.\n *\n * Editing operations are only valid on trees with the {@link TreeStatus#InDocument} `TreeStatus`.\n *\n * @remarks\n * Fields are used wherever an editable collection of nodes is required.\n * This is required in two places:\n * 1. To hold the children of non-leaf {@link FlexTreeNode}s.\n * 2. As the root of a {@link FlexTreeEntity}.\n *\n * Down-casting (via {@link FlexTreeField.is}) is required to access Schema-Aware APIs, including editing.\n * All content in the tree is accessible without down-casting, but if the schema is known,\n * the schema aware API may be more ergonomic.\n */\nexport interface FlexTreeField extends FlexTreeEntity<FlexFieldSchema> {\n\treadonly [flexTreeMarker]: FlexTreeEntityKind.Field;\n\n\t/**\n\t * The number of nodes in this field\n\t */\n\treadonly length: number;\n\n\t/**\n\t * The `FieldKey` this field is under.\n\t * Defines what part of its parent this field makes up.\n\t */\n\treadonly key: FieldKey;\n\n\t/**\n\t * The node which has this field on it under `fieldKey`.\n\t * `undefined` iff this field is a detached field.\n\t */\n\treadonly parent?: FlexTreeNode;\n\n\t/**\n\t * Type guard for narrowing / down-casting to a specific schema.\n\t */\n\tis<TSchema extends FlexFieldSchema>(schema: TSchema): this is FlexTreeTypedField<TSchema>;\n\n\tboxedIterator(): IterableIterator<FlexTreeNode>;\n\n\t/**\n\t * Gets a node of this field by its index without unboxing.\n\t * @param index - Zero-based index of the item to retrieve. Negative values are interpreted from the end of the sequence.\n\t *\n\t * @returns The element in the sequence matching the given index. Always returns undefined if index \\< -sequence.length\n\t * or index \\>= sequence.length.\n\t *\n\t * @remarks\n\t * Semantics match {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/at | Array.at}.\n\t */\n\tboxedAt(index: number): FlexTreeNode | undefined;\n}\n\n// #region Node Kinds\n\n/**\n * A {@link FlexTreeNode} that behaves like a `Map<string, Field>` for a specific `Field` type.\n *\n * @remarks\n * Unlike TypeScript Map type, {@link FlexTreeMapNode.get} always provides a reference to any field looked up, even if it has never been set.\n *\n * This means that, for example, a `MapNode` of {@link FlexTreeSequenceField} fields will return an empty sequence when a previously unused key is looked up,\n * and that sequence can be used to insert new items into the field.\n * Additionally empty fields (those containing no nodes) are not distinguished from fields which do not exist.\n * This differs from JavaScript Maps which have a subtle distinction between storing undefined as a value in the map and deleting an entry from the map.\n */\nexport interface FlexTreeMapNode<in out TSchema extends FlexMapNodeSchema>\n\textends FlexTreeNode {\n\treadonly schema: TSchema;\n\n\t/**\n\t * Get the field for `key`.\n\t * @param key - which map entry to look up.\n\t *\n\t * @remarks\n\t * All fields under a map implicitly exist, so `get` can be called with any key and will always return a field.\n\t * Even if the field is empty, it will still be returned, and can be edited to insert content into the map.\n\t */\n\tgetBoxed(key: string): FlexTreeTypedField<TSchema[\"info\"]>;\n\n\t/**\n\t * Returns an iterable of keys in the map.\n\t *\n\t * @remarks\n\t * All fields under a map implicitly exist, but `keys` will yield only the keys of fields which contain one or more nodes.\n\t *\n\t * No guarantees are made regarding the order of the keys returned.\n\t */\n\tkeys(): IterableIterator<FieldKey>;\n\n\t/**\n\t * Returns an iterable of values in the map.\n\t *\n\t * @remarks\n\t * All fields under a map implicitly exist, but `values` will yield only the fields containing one or more nodes.\n\t *\n\t * No guarantees are made regarding the order of the values returned.\n\t */\n\tvalues(): IterableIterator<FlexTreeUnboxField<TSchema[\"info\"], \"notEmpty\">>;\n\n\t/**\n\t * Returns an iterable of key, value pairs for every entry in the map.\n\t *\n\t * @remarks\n\t * All fields under a map implicitly exist, but `entries` will yield only the entries whose fields contain one or more nodes.\n\t *\n\t * This iteration provided by `entries()` is equivalent to that provided by direct iteration of the {@link FlexTreeMapNode} (a.k.a. `[Symbol.Iterator]()`).\n\t *\n\t * No guarantees are made regarding the order of the entries returned.\n\t */\n\tentries(): IterableIterator<[FieldKey, FlexTreeUnboxField<TSchema[\"info\"], \"notEmpty\">]>;\n\n\t[Symbol.iterator](): IterableIterator<\n\t\t[FieldKey, FlexTreeUnboxField<TSchema[\"info\"], \"notEmpty\">]\n\t>;\n}\n\n/**\n * A {@link FlexTreeNode} that behaves like an \"object\" or \"struct\", providing properties to access its fields.\n *\n * ObjectNodes consist of a finite collection of fields, each with their own (distinct) key and {@link FlexFieldSchema}.\n *\n * @remarks\n * ObjectNodes require complex typing, and have been split into two parts for implementation purposes.\n *\n * These \"Objects\" resemble \"Structs\" from a wide variety of programming languages\n * (Including Algol 68, C, Go, Rust, C# etc.).\n * ObjectNodes also somewhat resemble JavaScript objects: this analogy is less precise (objects don't have a fixed schema for example),\n * but for consistency with other systems in the JavaScript ecosystem (like JSON) is \"ObjectNodes\" nodes are named \"Objects\".\n *\n * Another common name for this abstraction is [record](https://en.wikipedia.org/wiki/Record_(computer_science)).\n * The name \"Record\" is avoided (in favor of Object) here because it has less precise connotations for most TypeScript developers.\n * For example, TypeScript has a built in `Record` type, but it requires all of the fields to have the same type,\n * putting its semantics half way between this library's \"Object\" schema and {@link FlexTreeMapNode}.\n */\nexport interface FlexTreeObjectNode extends FlexTreeNode {\n\treadonly schema: FlexObjectNodeSchema;\n}\n\n/**\n * Leaf holding a value.\n *\n * @remarks\n * Leaves are immutable and have no children.\n * Leaf unboxes its content, so in schema aware APIs which do unboxing, the Leaf itself will be skipped over and its value will be returned directly.\n */\nexport interface FlexTreeLeafNode<in out TSchema extends LeafNodeSchema> extends FlexTreeNode {\n\treadonly schema: TSchema;\n\n\t/**\n\t * Value stored on this node.\n\t */\n\treadonly value: TreeValue<TSchema[\"info\"]>;\n}\n\n/**\n * Field kinds that allow value assignment.\n */\nexport type AssignableFieldKinds = typeof FieldKinds.optional | typeof FieldKinds.required;\n\n// #endregion\n\n// #region Field Kinds\n\n/**\n * Typed tree for inserting as the content of a field.\n */\nexport type FlexibleFieldContent = ExclusiveMapTree[];\n\n/**\n * Tree for inserting as a node.\n */\nexport type FlexibleNodeContent = ExclusiveMapTree;\n\n/**\n * Tree for inserting a subsequence of nodes.\n *\n * Used to insert a batch of 0 or more nodes into some location in a {@link FlexTreeSequenceField}.\n */\nexport type FlexibleNodeSubSequence = ExclusiveMapTree[];\n\n/**\n * Type to ensures two types overlap in at least one way.\n * It evaluates to the input type if this is true, and never otherwise.\n * Examples:\n * CheckTypesOverlap\\<number | boolean, number | object\\> = number | boolean\n * CheckTypesOverlap\\<number | boolean, string | object\\> = never\n */\nexport type CheckTypesOverlap<T, TCheck> = [Extract<T, TCheck> extends never ? never : T][0];\n\n/**\n * {@link FlexTreeField} that stores a sequence of children.\n *\n * Sequence fields can contain an ordered sequence any number of {@link FlexTreeNode}s which must be of the {@link FlexAllowedTypes} from the {@link FlexFieldSchema}).\n *\n * @remarks\n * Allows for concurrent editing based on index, adjusting the locations of indexes as needed so they apply to the same logical place in the sequence when rebased and merged.\n *\n * Edits to sequence fields are anchored relative to their surroundings, so concurrent edits can result in the indexes of nodes and edits getting shifted.\n * To hold onto locations in sequence across an edit, use anchors.\n *\n * @privateRemarks\n * TODO:\n * Add anchor API that can actually hold onto locations in a sequence.\n * Currently only nodes can be held onto with anchors, and this does not replicate the behavior implemented for editing.\n */\nexport interface FlexTreeSequenceField<in out TTypes extends FlexAllowedTypes>\n\textends FlexTreeField {\n\t/**\n\t * Gets a node of this field by its index with unboxing.\n\t * @param index - Zero-based index of the item to retrieve. Negative values are interpreted from the end of the sequence.\n\t *\n\t * @returns The element in the sequence matching the given index. Always returns undefined if index \\< -sequence.length\n\t * or index \\>= array.length.\n\t *\n\t * @remarks\n\t * Semantics match {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/at | Array.at}.\n\t */\n\tat(index: number): FlexTreeUnboxNodeUnion<TTypes> | undefined;\n\n\t/**\n\t * {@inheritdoc FlexTreeField.boxedAt}\n\t */\n\tboxedAt(index: number): FlexTreeTypedNodeUnion<TTypes> | undefined;\n\n\t/**\n\t * Calls the provided callback function on each child of this sequence, and returns an array that contains the results.\n\t * @param callbackfn - A function that accepts the child and its index.\n\t */\n\tmap<U>(callbackfn: (value: FlexTreeUnboxNodeUnion<TTypes>, index: number) => U): U[];\n\n\treadonly length: number;\n\n\t/**\n\t * Get an editor for this sequence.\n\t */\n\treadonly editor: SequenceFieldEditBuilder<FlexibleFieldContent>;\n\n\tboxedIterator(): IterableIterator<FlexTreeTypedNodeUnion<TTypes>>;\n\n\t/**\n\t * Gets the FieldUpPath of a field.\n\t */\n\tgetFieldPath(): FieldUpPath;\n\n\t[Symbol.iterator](): IterableIterator<FlexTreeUnboxNodeUnion<TTypes>>;\n}\n\n/**\n * Field that stores exactly one child.\n *\n * @remarks\n * Unboxes its content, so in schema aware APIs which do unboxing, the RequiredField itself will be skipped over and its content will be returned directly.\n */\nexport interface FlexTreeRequiredField<in out TTypes extends FlexAllowedTypes>\n\textends FlexTreeField {\n\tget content(): FlexTreeUnboxNodeUnion<TTypes>;\n\n\treadonly editor: ValueFieldEditBuilder<FlexibleNodeContent>;\n}\n\n/**\n * Field that stores zero or one child.\n *\n * @remarks\n * Unboxes its content, so in schema aware APIs which do unboxing, the OptionalField itself will be skipped over and its content will be returned directly.\n *\n * @privateRemarks\n * TODO: Document merge semitics\n * TODO: Allow Optional fields to be used with last write wins OR first write wins merge resolution.\n * TODO:\n * Better centralize the documentation about what kinds of merge semantics are available for field kinds.\n * Maybe link editor?\n */\nexport interface FlexTreeOptionalField<in out TTypes extends FlexAllowedTypes>\n\textends FlexTreeField {\n\tget content(): FlexTreeUnboxNodeUnion<TTypes> | undefined;\n\n\treadonly editor: OptionalFieldEditBuilder<FlexibleNodeContent>;\n}\n\n// #endregion\n\n// #region Typed\n\n/**\n * Schema aware specialization of {@link FlexTreeField}.\n */\nexport type FlexTreeTypedField<TSchema extends FlexFieldSchema> = FlexTreeTypedFieldInner<\n\tTSchema[\"kind\"],\n\tTSchema[\"allowedTypes\"]\n>;\n\n/**\n * Helper for implementing {@link FlexTreeTypedField}.\n */\nexport type FlexTreeTypedFieldInner<\n\tKind extends FlexFieldKind,\n\tTypes extends FlexAllowedTypes,\n> = Kind extends typeof FieldKinds.sequence\n\t? FlexTreeSequenceField<Types>\n\t: Kind extends typeof FieldKinds.required\n\t\t? FlexTreeRequiredField<Types>\n\t\t: Kind extends typeof FieldKinds.optional\n\t\t\t? FlexTreeOptionalField<Types>\n\t\t\t: FlexTreeField;\n\n/**\n * Schema aware specialization of {@link FlexTreeNode} for a given {@link FlexAllowedTypes}.\n */\nexport type FlexTreeTypedNodeUnion<T extends FlexAllowedTypes> =\n\tT extends FlexList<FlexTreeNodeSchema>\n\t\t? FlexTreeTypedNode<Assume<FlexListToUnion<T>, FlexTreeNodeSchema>>\n\t\t: FlexTreeNode;\n\n/**\n * Schema aware specialization of {@link FlexTreeNode} for a given {@link FlexTreeNodeSchema}.\n */\nexport type FlexTreeTypedNode<TSchema extends FlexTreeNodeSchema> =\n\tTSchema extends LeafNodeSchema\n\t\t? FlexTreeLeafNode<TSchema>\n\t\t: TSchema extends FlexMapNodeSchema\n\t\t\t? FlexTreeMapNode<TSchema>\n\t\t\t: TSchema extends FlexObjectNodeSchema\n\t\t\t\t? FlexTreeObjectNode\n\t\t\t\t: FlexTreeNode;\n\n// #endregion\n\n// #region Unbox\n\n/**\n * Schema aware unboxed field.\n * @remarks\n * Unboxes fields to their content if appropriate for the kind.\n * Recursively unboxes that content (then its content etc.) as well if the node union does unboxing.\n */\nexport type FlexTreeUnboxField<\n\tTSchema extends FlexFieldSchema,\n\t// If \"notEmpty\", then optional fields will unbox to their content (not their content | undefined)\n\tEmptiness extends \"maybeEmpty\" | \"notEmpty\" = \"maybeEmpty\",\n> = FlexTreeUnboxFieldInner<TSchema[\"kind\"], TSchema[\"allowedTypes\"], Emptiness>;\n\n/**\n * Helper for implementing FlexTreeUnboxField.\n */\nexport type FlexTreeUnboxFieldInner<\n\tKind extends FlexFieldKind,\n\tTTypes extends FlexAllowedTypes,\n\tEmptiness extends \"maybeEmpty\" | \"notEmpty\",\n> = Kind extends typeof FieldKinds.sequence\n\t? FlexTreeSequenceField<TTypes>\n\t: Kind extends typeof FieldKinds.required\n\t\t? FlexTreeUnboxNodeUnion<TTypes>\n\t\t: Kind extends typeof FieldKinds.optional\n\t\t\t? FlexTreeUnboxNodeUnion<TTypes> | (Emptiness extends \"notEmpty\" ? never : undefined)\n\t\t\t: // TODO: forbidden\n\t\t\t\tunknown;\n\n/**\n * Schema aware unboxed union of tree types.\n * @remarks\n * Unboxes when not polymorphic.\n * Recursively unboxes that content as well if the node kind does unboxing.\n */\nexport type FlexTreeUnboxNodeUnion<TTypes extends FlexAllowedTypes> = TTypes extends readonly [\n\tLazyItem<infer InnerType>,\n]\n\t? InnerType extends FlexTreeNodeSchema\n\t\t? FlexTreeUnboxNode<InnerType>\n\t\t: InnerType extends Any\n\t\t\t? FlexTreeNode\n\t\t\t: // This case should not occur. If the result ever ends up unknown, look at places like this to debug.\n\t\t\t\tunknown\n\t: boolean extends IsArrayOfOne<TTypes>\n\t\t? FlexTreeUnknownUnboxed // Unknown if this will unbox. This should mainly happen when TTypes is AllowedTypes.\n\t\t: FlexTreeTypedNodeUnion<TTypes>; // Known to not be a single type, so known not to unbox.\n\n/**\n * `true` if T is known to be an array of one item.\n * `false` if T is known not to be an array of one item.\n * `boolean` if it is unknown if T is an array of one item or not.\n */\nexport type IsArrayOfOne<T extends readonly unknown[]> = T[\"length\"] extends 1\n\t? true\n\t: 1 extends T[\"length\"]\n\t\t? boolean\n\t\t: false;\n\n/**\n * Schema aware unboxed tree type.\n * @remarks\n * Unboxes if the node kind does unboxing.\n * Recursively unboxes that content as well if it does unboxing.\n */\nexport type FlexTreeUnboxNode<TSchema extends FlexTreeNodeSchema> =\n\tTSchema extends LeafNodeSchema\n\t\t? TreeValue<TSchema[\"info\"]>\n\t\t: TSchema extends FlexMapNodeSchema\n\t\t\t? FlexTreeMapNode<TSchema>\n\t\t\t: TSchema extends FlexObjectNodeSchema\n\t\t\t\t? FlexTreeObjectNode\n\t\t\t\t: FlexTreeUnknownUnboxed;\n\n/**\n * Unboxed tree type for unknown schema cases.\n */\nexport type FlexTreeUnknownUnboxed = TreeValue | FlexTreeNode;\n\n// #endregion\n"]}
|
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
3
|
* Licensed under the MIT License.
|
|
4
4
|
*/
|
|
5
|
-
export { type FlexTreeField, type FlexTreeNode, type FlexTreeEntity, type FlexTreeTypedField, type FlexibleFieldContent, type FlexibleNodeContent, type FlexTreeLeafNode, type FlexTreeMapNode, type FlexTreeOptionalField, type FlexTreeRequiredField, type FlexTreeSequenceField, type FlexTreeObjectNode, type
|
|
5
|
+
export { type FlexTreeField, type FlexTreeNode, type FlexTreeEntity, type FlexTreeTypedField, type FlexibleFieldContent, type FlexibleNodeContent, type FlexTreeLeafNode, type FlexTreeMapNode, type FlexTreeOptionalField, type FlexTreeRequiredField, type FlexTreeSequenceField, type FlexTreeObjectNode, type AssignableFieldKinds, type FlexTreeTypedNode, type FlexTreeTypedNodeUnion, type CheckTypesOverlap, TreeStatus, type FlexTreeUnknownUnboxed, type FlexTreeUnboxField, flexTreeMarker, FlexTreeEntityKind, isFlexTreeNode, flexTreeSlot, } from "./flexTreeTypes.js";
|
|
6
6
|
export { visitBipartiteIterableTree, Skip, visitBipartiteIterableTreeWithState, visitIterableTree, visitIterableTreeWithState, } from "./navigation.js";
|
|
7
7
|
export { getTreeContext, type FlexTreeContext, Context, ContextSlot } from "./context.js";
|
|
8
8
|
export { type FlexTreeNodeEvents } from "./treeEvents.js";
|
|
9
|
-
export type {
|
|
9
|
+
export type { FlexTreeUnboxNodeUnion } from "./flexTreeTypes.js";
|
|
10
10
|
export { assertFlexTreeEntityNotFreed, isFreedSymbol, LazyEntity, } from "./lazyEntity.js";
|
|
11
11
|
export { getSchemaAndPolicy, indexForAt } from "./utilities.js";
|
|
12
12
|
export { treeStatusFromAnchorCache } from "./utilities.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/feature-libraries/flex-tree/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EACN,KAAK,aAAa,EAClB,KAAK,YAAY,EACjB,KAAK,cAAc,EACnB,KAAK,kBAAkB,EACvB,KAAK,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AAgB,CAAC"}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
3
|
* Licensed under the MIT License.
|
|
4
4
|
*/
|
|
5
|
-
export { TreeStatus, flexTreeMarker, FlexTreeEntityKind, isFlexTreeNode,
|
|
5
|
+
export { TreeStatus, flexTreeMarker, FlexTreeEntityKind, isFlexTreeNode, flexTreeSlot, } from "./flexTreeTypes.js";
|
|
6
6
|
export { visitBipartiteIterableTree, Skip, visitBipartiteIterableTreeWithState, visitIterableTree, visitIterableTreeWithState, } from "./navigation.js";
|
|
7
7
|
export { getTreeContext, Context, ContextSlot } from "./context.js";
|
|
8
8
|
export { assertFlexTreeEntityNotFreed, isFreedSymbol, LazyEntity, } from "./lazyEntity.js";
|