@fluidframework/tree 2.101.1 → 2.102.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +4 -0
- package/api-report/tree.alpha.api.md +19 -0
- package/dist/codec/codec.d.ts +22 -53
- package/dist/codec/codec.d.ts.map +1 -1
- package/dist/codec/codec.js +7 -44
- package/dist/codec/codec.js.map +1 -1
- package/dist/codec/index.d.ts +1 -1
- package/dist/codec/index.d.ts.map +1 -1
- package/dist/codec/index.js +2 -2
- package/dist/codec/index.js.map +1 -1
- package/dist/codec/versioned/codec.d.ts +56 -28
- package/dist/codec/versioned/codec.d.ts.map +1 -1
- package/dist/codec/versioned/codec.js +29 -12
- package/dist/codec/versioned/codec.js.map +1 -1
- package/dist/codec/versioned/index.d.ts +1 -1
- package/dist/codec/versioned/index.d.ts.map +1 -1
- package/dist/codec/versioned/index.js +2 -2
- package/dist/codec/versioned/index.js.map +1 -1
- package/dist/core/tree/deltaUtil.d.ts +2 -2
- package/dist/core/tree/deltaUtil.js +2 -2
- package/dist/core/tree/deltaUtil.js.map +1 -1
- package/dist/core/tree/detachedFieldIndexCodecV1.d.ts.map +1 -1
- package/dist/core/tree/detachedFieldIndexCodecV1.js +3 -2
- package/dist/core/tree/detachedFieldIndexCodecV1.js.map +1 -1
- package/dist/core/tree/detachedFieldIndexCodecV2.d.ts.map +1 -1
- package/dist/core/tree/detachedFieldIndexCodecV2.js +4 -2
- package/dist/core/tree/detachedFieldIndexCodecV2.js.map +1 -1
- package/dist/core/tree/detachedFieldIndexCodecs.d.ts +3 -3
- package/dist/core/tree/detachedFieldIndexCodecs.d.ts.map +1 -1
- package/dist/core/tree/detachedFieldIndexCodecs.js +1 -1
- package/dist/core/tree/detachedFieldIndexCodecs.js.map +1 -1
- package/dist/feature-libraries/chunked-forest/chunkTree.d.ts +38 -1
- package/dist/feature-libraries/chunked-forest/chunkTree.d.ts.map +1 -1
- package/dist/feature-libraries/chunked-forest/chunkTree.js +62 -4
- package/dist/feature-libraries/chunked-forest/chunkTree.js.map +1 -1
- package/dist/feature-libraries/chunked-forest/chunkedForest.d.ts.map +1 -1
- package/dist/feature-libraries/chunked-forest/chunkedForest.js +18 -4
- package/dist/feature-libraries/chunked-forest/chunkedForest.js.map +1 -1
- package/dist/feature-libraries/chunked-forest/codec/chunkDecoding.d.ts +34 -2
- package/dist/feature-libraries/chunked-forest/codec/chunkDecoding.d.ts.map +1 -1
- package/dist/feature-libraries/chunked-forest/codec/chunkDecoding.js +106 -3
- package/dist/feature-libraries/chunked-forest/codec/chunkDecoding.js.map +1 -1
- package/dist/feature-libraries/chunked-forest/codec/codecs.d.ts +5 -5
- package/dist/feature-libraries/chunked-forest/codec/codecs.d.ts.map +1 -1
- package/dist/feature-libraries/chunked-forest/codec/codecs.js +2 -2
- package/dist/feature-libraries/chunked-forest/codec/codecs.js.map +1 -1
- package/dist/feature-libraries/chunked-forest/codec/compressedEncode.d.ts +7 -7
- package/dist/feature-libraries/chunked-forest/codec/compressedEncode.d.ts.map +1 -1
- package/dist/feature-libraries/chunked-forest/codec/compressedEncode.js.map +1 -1
- package/dist/feature-libraries/chunked-forest/codec/format/formatV2.d.ts +25 -5
- package/dist/feature-libraries/chunked-forest/codec/format/formatV2.d.ts.map +1 -1
- package/dist/feature-libraries/chunked-forest/codec/format/formatV2.js +9 -3
- package/dist/feature-libraries/chunked-forest/codec/format/formatV2.js.map +1 -1
- package/dist/feature-libraries/chunked-forest/codec/format/formatVText.d.ts +105 -0
- package/dist/feature-libraries/chunked-forest/codec/format/formatVText.d.ts.map +1 -0
- package/dist/feature-libraries/chunked-forest/codec/format/formatVText.js +44 -0
- package/dist/feature-libraries/chunked-forest/codec/format/formatVText.js.map +1 -0
- package/dist/feature-libraries/chunked-forest/codec/format/index.d.ts +2 -1
- package/dist/feature-libraries/chunked-forest/codec/format/index.d.ts.map +1 -1
- package/dist/feature-libraries/chunked-forest/codec/format/index.js +5 -1
- package/dist/feature-libraries/chunked-forest/codec/format/index.js.map +1 -1
- package/dist/feature-libraries/chunked-forest/codec/format/versions.d.ts +38 -4
- package/dist/feature-libraries/chunked-forest/codec/format/versions.d.ts.map +1 -1
- package/dist/feature-libraries/chunked-forest/codec/format/versions.js +7 -1
- package/dist/feature-libraries/chunked-forest/codec/format/versions.js.map +1 -1
- package/dist/feature-libraries/chunked-forest/codec/nodeEncoder.d.ts +7 -7
- package/dist/feature-libraries/chunked-forest/codec/nodeEncoder.d.ts.map +1 -1
- package/dist/feature-libraries/chunked-forest/codec/nodeEncoder.js +1 -2
- package/dist/feature-libraries/chunked-forest/codec/nodeEncoder.js.map +1 -1
- package/dist/feature-libraries/forest-summary/codec.d.ts +5 -4
- package/dist/feature-libraries/forest-summary/codec.d.ts.map +1 -1
- package/dist/feature-libraries/forest-summary/codec.js +2 -2
- package/dist/feature-libraries/forest-summary/codec.js.map +1 -1
- package/dist/feature-libraries/modular-schema/modularChangeTypes.d.ts +1 -1
- package/dist/feature-libraries/modular-schema/modularChangeTypes.d.ts.map +1 -1
- package/dist/feature-libraries/modular-schema/modularChangeTypes.js.map +1 -1
- package/dist/feature-libraries/schema-index/codec.d.ts +2 -2
- package/dist/feature-libraries/schema-index/codec.d.ts.map +1 -1
- package/dist/feature-libraries/schema-index/codec.js +1 -1
- package/dist/feature-libraries/schema-index/codec.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/dist/packageVersion.d.ts +1 -1
- package/dist/packageVersion.js +1 -1
- package/dist/packageVersion.js.map +1 -1
- package/dist/shared-tree/isAuditableFromOutcome.d.ts +20 -0
- package/dist/shared-tree/isAuditableFromOutcome.d.ts.map +1 -0
- package/dist/shared-tree/isAuditableFromOutcome.js +36 -0
- package/dist/shared-tree/isAuditableFromOutcome.js.map +1 -0
- package/dist/shared-tree/treeCheckout.d.ts +2 -0
- package/dist/shared-tree/treeCheckout.d.ts.map +1 -1
- package/dist/shared-tree/treeCheckout.js +37 -8
- package/dist/shared-tree/treeCheckout.js.map +1 -1
- package/dist/shared-tree-core/editManagerCodecs.d.ts +3 -3
- package/dist/shared-tree-core/editManagerCodecs.d.ts.map +1 -1
- package/dist/shared-tree-core/editManagerCodecs.js +2 -2
- package/dist/shared-tree-core/editManagerCodecs.js.map +1 -1
- package/dist/shared-tree-core/messageCodecs.d.ts +3 -3
- package/dist/shared-tree-core/messageCodecs.d.ts.map +1 -1
- package/dist/shared-tree-core/messageCodecs.js +2 -2
- package/dist/shared-tree-core/messageCodecs.js.map +1 -1
- package/dist/simple-tree/core/treeNodeKernel.d.ts.map +1 -1
- package/dist/simple-tree/core/treeNodeKernel.js +25 -11
- package/dist/simple-tree/core/treeNodeKernel.js.map +1 -1
- package/dist/text/codePointUtils.d.ts +48 -0
- package/dist/text/codePointUtils.d.ts.map +1 -0
- package/dist/text/codePointUtils.js +80 -0
- package/dist/text/codePointUtils.js.map +1 -0
- package/dist/text/index.d.ts +1 -0
- package/dist/text/index.d.ts.map +1 -1
- package/dist/text/index.js +4 -1
- package/dist/text/index.js.map +1 -1
- package/dist/text/textDomain.d.ts +93 -1
- package/dist/text/textDomain.d.ts.map +1 -1
- package/dist/text/textDomain.js +65 -8
- package/dist/text/textDomain.js.map +1 -1
- package/dist/text/textDomainFormatted.d.ts +24 -6
- package/dist/text/textDomainFormatted.d.ts.map +1 -1
- package/dist/text/textDomainFormatted.js +29 -1
- package/dist/text/textDomainFormatted.js.map +1 -1
- package/dist/treeFactory.d.ts.map +1 -1
- package/dist/treeFactory.js +9 -7
- package/dist/treeFactory.js.map +1 -1
- package/dist/util/breakable.d.ts +7 -1
- package/dist/util/breakable.d.ts.map +1 -1
- package/dist/util/breakable.js +18 -4
- package/dist/util/breakable.js.map +1 -1
- package/lib/codec/codec.d.ts +22 -53
- package/lib/codec/codec.d.ts.map +1 -1
- package/lib/codec/codec.js +7 -44
- package/lib/codec/codec.js.map +1 -1
- package/lib/codec/index.d.ts +1 -1
- package/lib/codec/index.d.ts.map +1 -1
- package/lib/codec/index.js +1 -1
- package/lib/codec/index.js.map +1 -1
- package/lib/codec/versioned/codec.d.ts +56 -28
- package/lib/codec/versioned/codec.d.ts.map +1 -1
- package/lib/codec/versioned/codec.js +27 -10
- package/lib/codec/versioned/codec.js.map +1 -1
- package/lib/codec/versioned/index.d.ts +1 -1
- package/lib/codec/versioned/index.d.ts.map +1 -1
- package/lib/codec/versioned/index.js +1 -1
- package/lib/codec/versioned/index.js.map +1 -1
- package/lib/core/tree/deltaUtil.d.ts +2 -2
- package/lib/core/tree/deltaUtil.js +2 -2
- package/lib/core/tree/deltaUtil.js.map +1 -1
- package/lib/core/tree/detachedFieldIndexCodecV1.d.ts.map +1 -1
- package/lib/core/tree/detachedFieldIndexCodecV1.js +3 -2
- package/lib/core/tree/detachedFieldIndexCodecV1.js.map +1 -1
- package/lib/core/tree/detachedFieldIndexCodecV2.d.ts.map +1 -1
- package/lib/core/tree/detachedFieldIndexCodecV2.js +5 -3
- package/lib/core/tree/detachedFieldIndexCodecV2.js.map +1 -1
- package/lib/core/tree/detachedFieldIndexCodecs.d.ts +3 -3
- package/lib/core/tree/detachedFieldIndexCodecs.d.ts.map +1 -1
- package/lib/core/tree/detachedFieldIndexCodecs.js +2 -2
- package/lib/core/tree/detachedFieldIndexCodecs.js.map +1 -1
- package/lib/feature-libraries/chunked-forest/chunkTree.d.ts +38 -1
- package/lib/feature-libraries/chunked-forest/chunkTree.d.ts.map +1 -1
- package/lib/feature-libraries/chunked-forest/chunkTree.js +61 -4
- package/lib/feature-libraries/chunked-forest/chunkTree.js.map +1 -1
- package/lib/feature-libraries/chunked-forest/chunkedForest.d.ts.map +1 -1
- package/lib/feature-libraries/chunked-forest/chunkedForest.js +20 -6
- package/lib/feature-libraries/chunked-forest/chunkedForest.js.map +1 -1
- package/lib/feature-libraries/chunked-forest/codec/chunkDecoding.d.ts +34 -2
- package/lib/feature-libraries/chunked-forest/codec/chunkDecoding.d.ts.map +1 -1
- package/lib/feature-libraries/chunked-forest/codec/chunkDecoding.js +102 -2
- package/lib/feature-libraries/chunked-forest/codec/chunkDecoding.js.map +1 -1
- package/lib/feature-libraries/chunked-forest/codec/codecs.d.ts +5 -5
- package/lib/feature-libraries/chunked-forest/codec/codecs.d.ts.map +1 -1
- package/lib/feature-libraries/chunked-forest/codec/codecs.js +3 -3
- package/lib/feature-libraries/chunked-forest/codec/codecs.js.map +1 -1
- package/lib/feature-libraries/chunked-forest/codec/compressedEncode.d.ts +7 -7
- package/lib/feature-libraries/chunked-forest/codec/compressedEncode.d.ts.map +1 -1
- package/lib/feature-libraries/chunked-forest/codec/compressedEncode.js.map +1 -1
- package/lib/feature-libraries/chunked-forest/codec/format/formatV2.d.ts +25 -5
- package/lib/feature-libraries/chunked-forest/codec/format/formatV2.d.ts.map +1 -1
- package/lib/feature-libraries/chunked-forest/codec/format/formatV2.js +8 -2
- package/lib/feature-libraries/chunked-forest/codec/format/formatV2.js.map +1 -1
- package/lib/feature-libraries/chunked-forest/codec/format/formatVText.d.ts +105 -0
- package/lib/feature-libraries/chunked-forest/codec/format/formatVText.d.ts.map +1 -0
- package/lib/feature-libraries/chunked-forest/codec/format/formatVText.js +41 -0
- package/lib/feature-libraries/chunked-forest/codec/format/formatVText.js.map +1 -0
- package/lib/feature-libraries/chunked-forest/codec/format/index.d.ts +2 -1
- package/lib/feature-libraries/chunked-forest/codec/format/index.d.ts.map +1 -1
- package/lib/feature-libraries/chunked-forest/codec/format/index.js +2 -1
- package/lib/feature-libraries/chunked-forest/codec/format/index.js.map +1 -1
- package/lib/feature-libraries/chunked-forest/codec/format/versions.d.ts +38 -4
- package/lib/feature-libraries/chunked-forest/codec/format/versions.d.ts.map +1 -1
- package/lib/feature-libraries/chunked-forest/codec/format/versions.js +6 -0
- package/lib/feature-libraries/chunked-forest/codec/format/versions.js.map +1 -1
- package/lib/feature-libraries/chunked-forest/codec/nodeEncoder.d.ts +7 -7
- package/lib/feature-libraries/chunked-forest/codec/nodeEncoder.d.ts.map +1 -1
- package/lib/feature-libraries/chunked-forest/codec/nodeEncoder.js +2 -3
- package/lib/feature-libraries/chunked-forest/codec/nodeEncoder.js.map +1 -1
- package/lib/feature-libraries/forest-summary/codec.d.ts +5 -4
- package/lib/feature-libraries/forest-summary/codec.d.ts.map +1 -1
- package/lib/feature-libraries/forest-summary/codec.js +3 -3
- package/lib/feature-libraries/forest-summary/codec.js.map +1 -1
- package/lib/feature-libraries/modular-schema/modularChangeTypes.d.ts +1 -1
- package/lib/feature-libraries/modular-schema/modularChangeTypes.d.ts.map +1 -1
- package/lib/feature-libraries/modular-schema/modularChangeTypes.js.map +1 -1
- package/lib/feature-libraries/schema-index/codec.d.ts +2 -2
- package/lib/feature-libraries/schema-index/codec.d.ts.map +1 -1
- package/lib/feature-libraries/schema-index/codec.js +2 -2
- package/lib/feature-libraries/schema-index/codec.js.map +1 -1
- package/lib/index.d.ts +1 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +1 -1
- package/lib/index.js.map +1 -1
- package/lib/packageVersion.d.ts +1 -1
- package/lib/packageVersion.js +1 -1
- package/lib/packageVersion.js.map +1 -1
- package/lib/shared-tree/isAuditableFromOutcome.d.ts +20 -0
- package/lib/shared-tree/isAuditableFromOutcome.d.ts.map +1 -0
- package/lib/shared-tree/isAuditableFromOutcome.js +32 -0
- package/lib/shared-tree/isAuditableFromOutcome.js.map +1 -0
- package/lib/shared-tree/treeCheckout.d.ts +2 -0
- package/lib/shared-tree/treeCheckout.d.ts.map +1 -1
- package/lib/shared-tree/treeCheckout.js +37 -8
- package/lib/shared-tree/treeCheckout.js.map +1 -1
- package/lib/shared-tree-core/editManagerCodecs.d.ts +3 -3
- package/lib/shared-tree-core/editManagerCodecs.d.ts.map +1 -1
- package/lib/shared-tree-core/editManagerCodecs.js +3 -3
- package/lib/shared-tree-core/editManagerCodecs.js.map +1 -1
- package/lib/shared-tree-core/messageCodecs.d.ts +3 -3
- package/lib/shared-tree-core/messageCodecs.d.ts.map +1 -1
- package/lib/shared-tree-core/messageCodecs.js +3 -3
- package/lib/shared-tree-core/messageCodecs.js.map +1 -1
- package/lib/simple-tree/core/treeNodeKernel.d.ts.map +1 -1
- package/lib/simple-tree/core/treeNodeKernel.js +25 -11
- package/lib/simple-tree/core/treeNodeKernel.js.map +1 -1
- package/lib/text/codePointUtils.d.ts +48 -0
- package/lib/text/codePointUtils.d.ts.map +1 -0
- package/lib/text/codePointUtils.js +75 -0
- package/lib/text/codePointUtils.js.map +1 -0
- package/lib/text/index.d.ts +1 -0
- package/lib/text/index.d.ts.map +1 -1
- package/lib/text/index.js +1 -0
- package/lib/text/index.js.map +1 -1
- package/lib/text/textDomain.d.ts +93 -1
- package/lib/text/textDomain.d.ts.map +1 -1
- package/lib/text/textDomain.js +56 -0
- package/lib/text/textDomain.js.map +1 -1
- package/lib/text/textDomainFormatted.d.ts +24 -6
- package/lib/text/textDomainFormatted.d.ts.map +1 -1
- package/lib/text/textDomainFormatted.js +30 -2
- package/lib/text/textDomainFormatted.js.map +1 -1
- package/lib/treeFactory.d.ts.map +1 -1
- package/lib/treeFactory.js +2 -0
- package/lib/treeFactory.js.map +1 -1
- package/lib/util/breakable.d.ts +7 -1
- package/lib/util/breakable.d.ts.map +1 -1
- package/lib/util/breakable.js +18 -4
- package/lib/util/breakable.js.map +1 -1
- package/package.json +24 -24
- package/src/codec/codec.ts +82 -73
- package/src/codec/index.ts +2 -1
- package/src/codec/versioned/codec.ts +173 -73
- package/src/codec/versioned/index.ts +2 -1
- package/src/core/tree/deltaUtil.ts +2 -2
- package/src/core/tree/detachedFieldIndexCodecV1.ts +3 -2
- package/src/core/tree/detachedFieldIndexCodecV2.ts +5 -3
- package/src/core/tree/detachedFieldIndexCodecs.ts +2 -2
- package/src/feature-libraries/chunked-forest/chunkTree.ts +85 -1
- package/src/feature-libraries/chunked-forest/chunkedForest.ts +27 -7
- package/src/feature-libraries/chunked-forest/codec/chunkDecoding.ts +143 -7
- package/src/feature-libraries/chunked-forest/codec/codecs.ts +30 -28
- package/src/feature-libraries/chunked-forest/codec/compressedEncode.ts +7 -7
- package/src/feature-libraries/chunked-forest/codec/format/formatV2.ts +11 -7
- package/src/feature-libraries/chunked-forest/codec/format/formatVText.ts +83 -0
- package/src/feature-libraries/chunked-forest/codec/format/index.ts +6 -1
- package/src/feature-libraries/chunked-forest/codec/format/versions.ts +25 -4
- package/src/feature-libraries/chunked-forest/codec/nodeEncoder.ts +14 -18
- package/src/feature-libraries/forest-summary/codec.ts +9 -4
- package/src/feature-libraries/modular-schema/modularChangeTypes.ts +1 -1
- package/src/feature-libraries/schema-index/codec.ts +2 -5
- package/src/index.ts +6 -1
- package/src/packageVersion.ts +1 -1
- package/src/shared-tree/isAuditableFromOutcome.ts +34 -0
- package/src/shared-tree/treeCheckout.ts +52 -9
- package/src/shared-tree-core/editManagerCodecs.ts +4 -6
- package/src/shared-tree-core/messageCodecs.ts +4 -4
- package/src/simple-tree/core/treeNodeKernel.ts +27 -13
- package/src/text/codePointUtils.ts +81 -0
- package/src/text/index.ts +1 -0
- package/src/text/textDomain.ts +155 -2
- package/src/text/textDomainFormatted.ts +73 -2
- package/src/treeFactory.ts +5 -0
- package/src/util/breakable.ts +27 -6
package/lib/text/textDomain.d.ts
CHANGED
|
@@ -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
|
-
import type { TreeNode, WithType } from "../simple-tree/index.js";
|
|
5
|
+
import type { ArrayNodeDeltaOp, ArrayNodeTreeChangedDeltaOp, TreeNode, WithType } from "../simple-tree/index.js";
|
|
6
6
|
import type { NodeKind, TreeNodeSchema } from "../simple-tree/index.js";
|
|
7
7
|
/**
|
|
8
8
|
* Interpret a string as an iterable of characters.
|
|
@@ -12,6 +12,21 @@ import type { NodeKind, TreeNodeSchema } from "../simple-tree/index.js";
|
|
|
12
12
|
* Additionally using this function consistently will make any refactors to support alternative character boundaries easier.
|
|
13
13
|
*/
|
|
14
14
|
export declare function charactersFromString(value: string): Iterable<string>;
|
|
15
|
+
/**
|
|
16
|
+
* Processes an array-node delta into a {@link TextAsTree.TextOp}[] and calls `callback`.
|
|
17
|
+
* @remarks
|
|
18
|
+
* Shared by both the plain `onCharactersChanged` (from `nodeChanged`) and formatted `onContentChanged`
|
|
19
|
+
* (from `treeChanged`) implementations.
|
|
20
|
+
* @param delta - The raw array-node delta, or `undefined` when no delta is available.
|
|
21
|
+
* When retain ops carry `subtreeChanged` (i.e. delta comes from a `treeChanged` event), the emitted
|
|
22
|
+
* retain ops include an explicit `formattingChanged: boolean`. Otherwise `formattingChanged` is omitted.
|
|
23
|
+
* @param getCharacter - Returns the character string at the given array index in the **post-edit** tree.
|
|
24
|
+
* Only invoked for insert ops, where it must read the inserted character at the given index of the tree
|
|
25
|
+
* after the edit has been applied. Passing an accessor that reads pre-edit content will silently produce wrong text.
|
|
26
|
+
* Return `undefined` if the tree is out of sync with the delta; this triggers a full-reread fallback.
|
|
27
|
+
* @param callback - The user-supplied callback to invoke with the translated ops.
|
|
28
|
+
*/
|
|
29
|
+
export declare function processCharactersChangedDelta(delta: readonly (ArrayNodeDeltaOp | ArrayNodeTreeChangedDeltaOp)[] | undefined, getCharacter: (index: number) => string | undefined, callback: (ops: readonly TextAsTree.TextOp[] | undefined) => void): void;
|
|
15
30
|
/**
|
|
16
31
|
* A collection of text related types, schema and utilities for working with text beyond the basic {@link SchemaStatics.string}.
|
|
17
32
|
* @privateRemarks
|
|
@@ -75,6 +90,67 @@ export declare function charactersFromString(value: string): Iterable<string>;
|
|
|
75
90
|
* @alpha
|
|
76
91
|
*/
|
|
77
92
|
export declare namespace TextAsTree {
|
|
93
|
+
/**
|
|
94
|
+
* A retain op in a character-level delta — a span of unchanged characters that the consumer should skip over.
|
|
95
|
+
* @sealed
|
|
96
|
+
* @alpha
|
|
97
|
+
*/
|
|
98
|
+
interface TextRetainOp {
|
|
99
|
+
/**
|
|
100
|
+
* Discriminator identifying this op as a retain.
|
|
101
|
+
*/
|
|
102
|
+
readonly type: "retain";
|
|
103
|
+
/**
|
|
104
|
+
* The number of Unicode code points to retain.
|
|
105
|
+
*/
|
|
106
|
+
readonly count: number;
|
|
107
|
+
/**
|
|
108
|
+
* Whether at least one character in the retained range had a deep change.
|
|
109
|
+
* @remarks
|
|
110
|
+
* Present only on retain ops delivered by {@link @fluidframework/tree#FormattedTextAsTree.Members.onContentChanged};
|
|
111
|
+
* always absent on retain ops delivered by {@link TextAsTree.Members.onCharactersChanged}.
|
|
112
|
+
* When present, `true` indicates the retained range contained a formatting property update
|
|
113
|
+
* or an atom content edit; `false` indicates no deep change.
|
|
114
|
+
*/
|
|
115
|
+
readonly formattingChanged?: boolean;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* An insert op in a character-level delta — characters newly added to the text.
|
|
119
|
+
* @remarks
|
|
120
|
+
* Carries the inserted text as a single string, which is more convenient for consumers than individual characters.
|
|
121
|
+
* @sealed
|
|
122
|
+
* @alpha
|
|
123
|
+
*/
|
|
124
|
+
interface TextInsertOp {
|
|
125
|
+
/**
|
|
126
|
+
* Discriminator identifying this op as an insert.
|
|
127
|
+
*/
|
|
128
|
+
readonly type: "insert";
|
|
129
|
+
/**
|
|
130
|
+
* The newly inserted characters, concatenated into a single string.
|
|
131
|
+
*/
|
|
132
|
+
readonly text: string;
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* A remove op in a character-level delta — a span of characters that has been deleted from the text.
|
|
136
|
+
* @sealed
|
|
137
|
+
* @alpha
|
|
138
|
+
*/
|
|
139
|
+
interface TextRemoveOp {
|
|
140
|
+
/**
|
|
141
|
+
* Discriminator identifying this op as a remove.
|
|
142
|
+
*/
|
|
143
|
+
readonly type: "remove";
|
|
144
|
+
/**
|
|
145
|
+
* The number of Unicode code points removed.
|
|
146
|
+
*/
|
|
147
|
+
readonly count: number;
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* A single operation in a character-level delta describing an insert, remove, or retain of text.
|
|
151
|
+
* @alpha
|
|
152
|
+
*/
|
|
153
|
+
type TextOp = TextRetainOp | TextInsertOp | TextRemoveOp;
|
|
78
154
|
/**
|
|
79
155
|
* Statics for text nodes.
|
|
80
156
|
* @alpha
|
|
@@ -101,6 +177,7 @@ export declare namespace TextAsTree {
|
|
|
101
177
|
*
|
|
102
178
|
* @see {@link TextAsTree.Statics.fromString} for construction.
|
|
103
179
|
* @see {@link TextAsTree.(Tree:type)} for schema.
|
|
180
|
+
* @sealed
|
|
104
181
|
* @alpha
|
|
105
182
|
*/
|
|
106
183
|
interface Members {
|
|
@@ -145,6 +222,21 @@ export declare namespace TextAsTree {
|
|
|
145
222
|
* See {@link (TreeArrayNode:interface).removeRange} for more details on the behavior.
|
|
146
223
|
*/
|
|
147
224
|
removeRange(startIndex: number | undefined, endIndex: number | undefined): void;
|
|
225
|
+
/**
|
|
226
|
+
* Subscribe to shallow character-level changes on this text node — inserts and removes only.
|
|
227
|
+
* @param callback - Called after each change with a sequence of {@link TextAsTree.TextOp}s describing what changed,
|
|
228
|
+
* or `undefined` when a delta could not be computed (e.g. during a schema upgrade).
|
|
229
|
+
* @returns A cleanup function that unsubscribes the callback when called.
|
|
230
|
+
* @remarks
|
|
231
|
+
* Only fires on shallow changes — inserts and removes.
|
|
232
|
+
* It does not fire on deep changes such as formatting property updates on existing characters.
|
|
233
|
+
* For formatted text, use {@link @fluidframework/tree#FormattedTextAsTree.Members.onContentChanged} to also receive deep changes.
|
|
234
|
+
*
|
|
235
|
+
* All counts in the delivered ops are in Unicode code points, not UTF-16 code units.
|
|
236
|
+
* For characters outside the Basic Multilingual Plane (e.g. emoji), one code point
|
|
237
|
+
* corresponds to two UTF-16 code units — convert before using the counts as string indices.
|
|
238
|
+
*/
|
|
239
|
+
onCharactersChanged(callback: (ops: readonly TextOp[] | undefined) => void): () => void;
|
|
148
240
|
}
|
|
149
241
|
/**
|
|
150
242
|
* Schema for a {@link TextAsTree.(Tree:variable)} node.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"textDomain.d.ts","sourceRoot":"","sources":["../../src/text/textDomain.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAqBH,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"textDomain.d.ts","sourceRoot":"","sources":["../../src/text/textDomain.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAqBH,OAAO,KAAK,EACX,gBAAgB,EAChB,2BAA2B,EAC3B,QAAQ,EACR,QAAQ,EAER,MAAM,yBAAyB,CAAC;AAIjC,OAAO,KAAK,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAsIxE;;;;;;GAMG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,MAAM,GAAG,QAAQ,CAAC,MAAM,CAAC,CAKpE;AAsBD;;;;;;;;;;;;;GAaG;AACH,wBAAgB,6BAA6B,CAC5C,KAAK,EAAE,SAAS,CAAC,gBAAgB,GAAG,2BAA2B,CAAC,EAAE,GAAG,SAAS,EAC9E,YAAY,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,MAAM,GAAG,SAAS,EACnD,QAAQ,EAAE,CAAC,GAAG,EAAE,SAAS,UAAU,CAAC,MAAM,EAAE,GAAG,SAAS,KAAK,IAAI,GAC/D,IAAI,CAqCN;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6DG;AACH,yBAAiB,UAAU,CAAC;IAC3B;;;;OAIG;IACH,UAAiB,YAAY;QAC5B;;WAEG;QACH,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC;QACxB;;WAEG;QACH,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;QACvB;;;;;;;WAOG;QACH,QAAQ,CAAC,iBAAiB,CAAC,EAAE,OAAO,CAAC;KACrC;IAED;;;;;;OAMG;IACH,UAAiB,YAAY;QAC5B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ib/text/textDomain.js
CHANGED
|
@@ -8,6 +8,7 @@ import { buildFunc, exposeMethodsSymbol,
|
|
|
8
8
|
} from "@fluidframework/type-factory/alpha";
|
|
9
9
|
import { typeFactory as tf } from "@fluidframework/type-factory/internal";
|
|
10
10
|
import { EmptyKey, mapCursorField } from "../core/index.js";
|
|
11
|
+
import { TreeAlpha } from "../shared-tree/index.js";
|
|
11
12
|
import { eraseSchemaDetails, getInnerNode, SchemaFactory, SchemaFactoryAlpha, TreeArrayNode, } from "../simple-tree/index.js";
|
|
12
13
|
const sf = new SchemaFactoryAlpha("com.fluidframework.text");
|
|
13
14
|
class TextNode extends sf.object("Text", {
|
|
@@ -73,6 +74,9 @@ class TextNode extends sf.object("Text", {
|
|
|
73
74
|
charactersCopy_reference() {
|
|
74
75
|
return [...this.content];
|
|
75
76
|
}
|
|
77
|
+
onCharactersChanged(callback) {
|
|
78
|
+
return TreeAlpha.on(this.content, "nodeChanged", ({ delta }) => processCharactersChangedDelta(delta, (i) => this.content[i], callback));
|
|
79
|
+
}
|
|
76
80
|
static fromString(value) {
|
|
77
81
|
// Constructing an ArrayNode from an iterator is supported, so creating an array from the iterable of characters seems like its not necessary here,
|
|
78
82
|
// but to reduce the risk of incorrect data interpretation, we actually ban this in the special case where the iterable is a string directly, which is the case here.
|
|
@@ -108,6 +112,58 @@ class StringArray extends sf.array("StringArray", SchemaFactory.string) {
|
|
|
108
112
|
return this.charactersCopy().join("");
|
|
109
113
|
}
|
|
110
114
|
}
|
|
115
|
+
/**
|
|
116
|
+
* Processes an array-node delta into a {@link TextAsTree.TextOp}[] and calls `callback`.
|
|
117
|
+
* @remarks
|
|
118
|
+
* Shared by both the plain `onCharactersChanged` (from `nodeChanged`) and formatted `onContentChanged`
|
|
119
|
+
* (from `treeChanged`) implementations.
|
|
120
|
+
* @param delta - The raw array-node delta, or `undefined` when no delta is available.
|
|
121
|
+
* When retain ops carry `subtreeChanged` (i.e. delta comes from a `treeChanged` event), the emitted
|
|
122
|
+
* retain ops include an explicit `formattingChanged: boolean`. Otherwise `formattingChanged` is omitted.
|
|
123
|
+
* @param getCharacter - Returns the character string at the given array index in the **post-edit** tree.
|
|
124
|
+
* Only invoked for insert ops, where it must read the inserted character at the given index of the tree
|
|
125
|
+
* after the edit has been applied. Passing an accessor that reads pre-edit content will silently produce wrong text.
|
|
126
|
+
* Return `undefined` if the tree is out of sync with the delta; this triggers a full-reread fallback.
|
|
127
|
+
* @param callback - The user-supplied callback to invoke with the translated ops.
|
|
128
|
+
*/
|
|
129
|
+
export function processCharactersChangedDelta(delta, getCharacter, callback) {
|
|
130
|
+
if (delta === undefined) {
|
|
131
|
+
callback(undefined);
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
let readPosition = 0;
|
|
135
|
+
const ops = [];
|
|
136
|
+
for (const op of delta) {
|
|
137
|
+
if (op.type === "retain") {
|
|
138
|
+
// `subtreeChanged` is only present on retain ops from `treeChanged` deltas.
|
|
139
|
+
ops.push("subtreeChanged" in op
|
|
140
|
+
? { type: "retain", count: op.count, formattingChanged: op.subtreeChanged === true }
|
|
141
|
+
: { type: "retain", count: op.count });
|
|
142
|
+
readPosition += op.count;
|
|
143
|
+
}
|
|
144
|
+
else if (op.type === "insert") {
|
|
145
|
+
// Accumulate into an array and join at the end to keep this O(n) for large inserts
|
|
146
|
+
// (paste of long text) instead of O(n^2) from repeated string concatenation.
|
|
147
|
+
const characters = [];
|
|
148
|
+
for (let i = 0; i < op.count; i++) {
|
|
149
|
+
const character = getCharacter(readPosition);
|
|
150
|
+
if (character === undefined) {
|
|
151
|
+
// Tree is out of sync with the delta — fall back to full re-read.
|
|
152
|
+
callback(undefined);
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
155
|
+
characters.push(character);
|
|
156
|
+
readPosition++;
|
|
157
|
+
}
|
|
158
|
+
ops.push({ type: "insert", text: characters.join("") });
|
|
159
|
+
}
|
|
160
|
+
else {
|
|
161
|
+
// Construct explicit remove op so internal fields on the source op don't leak.
|
|
162
|
+
ops.push({ type: "remove", count: op.count });
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
callback(ops);
|
|
166
|
+
}
|
|
111
167
|
/**
|
|
112
168
|
* A collection of text related types, schema and utilities for working with text beyond the basic {@link SchemaStatics.string}.
|
|
113
169
|
* @privateRemarks
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"textDomain.js","sourceRoot":"","sources":["../../src/text/textDomain.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,qCAAqC,CAAC;AACjF,OAAO,EACN,SAAS,EACT,mBAAmB;AAGnB,wDAAwD;EACxD,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EAAE,WAAW,IAAI,EAAE,EAAE,MAAM,uCAAuC,CAAC;AAE1E,OAAO,EAAE,QAAQ,EAAE,cAAc,EAA+B,MAAM,kBAAkB,CAAC;AACzF,OAAO,EACN,kBAAkB,EAClB,YAAY,EACZ,aAAa,EACb,kBAAkB,EAClB,aAAa,GACb,MAAM,yBAAyB,CAAC;AAQjC,MAAM,EAAE,GAAG,IAAI,kBAAkB,CAAC,yBAAyB,CAAC,CAAC;AAE7D,MAAM,QACL,SAAQ,EAAE,CAAC,MAAM,CAAC,MAAM,EAAE;IACzB,OAAO,EAAE,aAAa,CAAC,QAAQ,CAAC,CAAC,GAAG,EAAE,CAAC,WAAW,CAAC,EAAE,EAAE,GAAG,EAAE,QAAQ,EAAE,CAAC;CACvE,CAAC;IAGK,MAAM,CAAC,CAAC,mBAAmB,CAAC,CAAC,OAAuB;QAC1D,OAAO,CAAC,YAAY,CACnB,QAAQ,EACR,UAAU,EACV,SAAS,CACR;YACC,WAAW,EACV,qFAAqF;YACtF,OAAO,EAAE,EAAE,CAAC,IAAI,EAAE;SAClB,EACD,CAAC,OAAO,EAAE,EAAE,CAAC,MAAM,EAAE,CAAC,EACtB,CAAC,sBAAsB,EAAE,EAAE,CAAC,MAAM,EAAE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AA0C;IAC1C,OAAO,KAAK,CAAC;AACd,CAAC;AAED,MAAM,WAAY,SAAQ,EAAE,CAAC,KAAK,CAAC,aAAa,EAAE,aAAa,CAAC,MAAM,CAAC;IAC/D,0BAA0B,CAAI,CAAwC;QAC5E,MAAM,MAAM,GAAG,YAAY,CAAC,IAAI,CAAC,CAAC,YAAY,EAAE,CAAC;QACjD,MAAM,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC;QAC5B,MAAM,MAAM,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC;QACzB,MAAM,CAAC,SAAS,EAAE,CAAC;QACnB,OAAO,MAAM,CAAC;IACf,CAAC;IAEM,cAAc;QACpB,OAAO,IAAI,CAAC,0BAA0B,CAAC,CAAC,MAAM,EAAE,EAAE,CACjD,cAAc,CAAC,MAAM,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,KAAe,CAAC,CACpD,CAAC;IACH,CAAC;IAEM,UAAU;QAChB,OAAO,IAAI,CAAC,cAAc,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IACvC,CAAC;CACD;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6DG;AACH,MAAM,KAAW,UAAU,CA8F1B;AA9FD,WAAiB,UAAU;IA+E1B;;;;;OAKG;IACU,eAAI,GAAG,kBAAkB,EAAoB,CAAC,QAAQ,CAAC,CAAC;AAStE,CAAC,EA9FgB,UAAU,KAAV,UAAU,QA8F1B","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { compareArrays, debugAssert } from \"@fluidframework/core-utils/internal\";\nimport {\n\tbuildFunc,\n\texposeMethodsSymbol,\n\ttype ExposedMethods,\n\ttype IExposedMethods,\n\t// eslint-disable-next-line import-x/no-internal-modules\n} from \"@fluidframework/type-factory/alpha\";\nimport { typeFactory as tf } from \"@fluidframework/type-factory/internal\";\n\nimport { EmptyKey, mapCursorField, type ITreeCursorSynchronous } from \"../core/index.js\";\nimport {\n\teraseSchemaDetails,\n\tgetInnerNode,\n\tSchemaFactory,\n\tSchemaFactoryAlpha,\n\tTreeArrayNode,\n} from \"../simple-tree/index.js\";\n// eslint-disable-next-line import-x/no-duplicates\nimport type { TreeNode, WithType } from \"../simple-tree/index.js\";\n// Add some unused imports which show up in the generated d.ts file.\n// This prevents them from getting inline imports generated, cleaning up the d.ts file and API reports.\n// eslint-disable-next-line @typescript-eslint/no-unused-vars, unused-imports/no-unused-imports, import-x/no-duplicates\nimport type { NodeKind, TreeNodeSchema } from \"../simple-tree/index.js\";\n\nconst sf = new SchemaFactoryAlpha(\"com.fluidframework.text\");\n\nclass TextNode\n\textends sf.object(\"Text\", {\n\t\tcontent: SchemaFactory.required([() => StringArray], { key: EmptyKey }),\n\t})\n\timplements TextAsTree.Members, IExposedMethods\n{\n\tpublic static [exposeMethodsSymbol](methods: ExposedMethods): void {\n\t\tmethods.exposeMethod(\n\t\t\tTextNode,\n\t\t\t\"insertAt\",\n\t\t\tbuildFunc(\n\t\t\t\t{\n\t\t\t\t\tdescription:\n\t\t\t\t\t\t\"Insert characters into the text at the given character index (Unicode code points).\",\n\t\t\t\t\treturns: tf.void(),\n\t\t\t\t},\n\t\t\t\t[\"index\", tf.number()],\n\t\t\t\t[\"additionalCharacters\", tf.string()],\n\t\t\t),\n\t\t);\n\t\tmethods.exposeMethod(\n\t\t\tTextNode,\n\t\t\t\"removeRange\",\n\t\t\tbuildFunc(\n\t\t\t\t{\n\t\t\t\t\tdescription:\n\t\t\t\t\t\t\"Remove a range of characters from the text by character index (Unicode code points). startIndex defaults to 0 and endIndex defaults to the length of the text.\",\n\t\t\t\t\treturns: tf.void(),\n\t\t\t\t},\n\t\t\t\t[\"startIndex\", tf.union([tf.number(), tf.undefined()])],\n\t\t\t\t[\"endIndex\", tf.union([tf.number(), tf.undefined()])],\n\t\t\t),\n\t\t);\n\t\tmethods.exposeMethod(\n\t\t\tTextNode,\n\t\t\t\"fullString\",\n\t\t\tbuildFunc({\n\t\t\t\tdescription: \"Return a copy of this text node's content as a string.\",\n\t\t\t\treturns: tf.string(),\n\t\t\t}),\n\t\t);\n\t\tmethods.exposeMethod(\n\t\t\tTextNode,\n\t\t\t\"characterCount\",\n\t\t\tbuildFunc({\n\t\t\t\tdescription:\n\t\t\t\t\t\"Gets the number of characters (Unicode code points) currently in the text. Joined emojis and other grapheme clusters count as multiple characters.\",\n\t\t\t\treturns: tf.number(),\n\t\t\t}),\n\t\t);\n\t\tmethods.exposeMethod(\n\t\t\tTextNode,\n\t\t\t\"charactersCopy\",\n\t\t\tbuildFunc({\n\t\t\t\tdescription:\n\t\t\t\t\t\"Returns all characters in the text as an array, where each element is a single Unicode code point. Joined emojis and other grapheme clusters are split into separate elements.\",\n\t\t\t\treturns: tf.array(tf.string()),\n\t\t\t}),\n\t\t);\n\t}\n\n\tpublic [exposeMethodsSymbol](methods: ExposedMethods): void {\n\t\tTextNode[exposeMethodsSymbol](methods);\n\t}\n\n\tpublic insertAt(index: number, additionalCharacters: string): void {\n\t\tthis.content.insertAt(\n\t\t\tindex,\n\t\t\tTreeArrayNode.spread(charactersFromString(additionalCharacters)),\n\t\t);\n\t}\n\tpublic removeRange(index: number | undefined, end: number | undefined): void {\n\t\tthis.content.removeRange(index, end);\n\t}\n\tpublic characters(): Iterable<string> {\n\t\treturn this.content[Symbol.iterator]();\n\t}\n\n\tpublic characterCount(): number {\n\t\treturn this.content.length;\n\t}\n\n\tpublic charactersCopy(): string[] {\n\t\tconst result = this.content.charactersCopy();\n\t\tdebugAssert(\n\t\t\t() =>\n\t\t\t\tcompareArrays(result, this.charactersCopy_reference()) ||\n\t\t\t\t\"invalid charactersCopy optimizations\",\n\t\t);\n\t\treturn result;\n\t}\n\n\tpublic fullString(): string {\n\t\tconst result = this.content.fullString();\n\t\tdebugAssert(\n\t\t\t() => result === this.fullString_reference() || \"invalid fullString optimizations\",\n\t\t);\n\t\treturn result;\n\t}\n\n\t/**\n\t * Unoptimized trivially correct implementation of fullString.\n\t */\n\tpublic fullString_reference(): string {\n\t\treturn this.content.join(\"\");\n\t}\n\n\t/**\n\t * Unoptimized trivially correct implementation of charactersCopy.\n\t */\n\tpublic charactersCopy_reference(): string[] {\n\t\treturn [...this.content];\n\t}\n\n\tpublic static fromString(value: string): TextNode {\n\t\t// Constructing an ArrayNode from an iterator is supported, so creating an array from the iterable of characters seems like its not necessary here,\n\t\t// but to reduce the risk of incorrect data interpretation, we actually ban this in the special case where the iterable is a string directly, which is the case here.\n\t\t// Thus the array construction here is necessary to avoid a runtime error.\n\t\treturn new TextNode({ content: [...charactersFromString(value)] });\n\t}\n}\n\n/**\n * Interpret a string as an iterable of characters.\n * @remarks\n * This mostly exists to clearly document where the code is interpreting a string as characters,\n * and provide a centralized place where validation could be added in the future if desired.\n * Additionally using this function consistently will make any refactors to support alternative character boundaries easier.\n */\nexport function charactersFromString(value: string): Iterable<string> {\n\t// Uses the string as an iterable of characters, so utf-16 surrogate pairs get grouped together correctly.\n\t// Might be nice to call isWellFormed or toWellFormed here (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/toWellFormed)\n\t// But those are not widely supported yet.\n\treturn value;\n}\n\nclass StringArray extends sf.array(\"StringArray\", SchemaFactory.string) {\n\tpublic withBorrowedSequenceCursor<T>(f: (cursor: ITreeCursorSynchronous) => T): T {\n\t\tconst cursor = getInnerNode(this).borrowCursor();\n\t\tcursor.enterField(EmptyKey);\n\t\tconst result = f(cursor);\n\t\tcursor.exitField();\n\t\treturn result;\n\t}\n\n\tpublic charactersCopy(): string[] {\n\t\treturn this.withBorrowedSequenceCursor((cursor) =>\n\t\t\tmapCursorField(cursor, () => cursor.value as string),\n\t\t);\n\t}\n\n\tpublic fullString(): string {\n\t\treturn this.charactersCopy().join(\"\");\n\t}\n}\n\n/**\n * A collection of text related types, schema and utilities for working with text beyond the basic {@link SchemaStatics.string}.\n * @privateRemarks\n * Currently this API only supports a really minimal feature set, and has no support for more advanced features like:\n * - Alternative character boundaries (e.g. grapheme clusters, paragraphs, tokens, etc.).\n * We may want to provide either ways to create strings with application controlled character boundaries since there is not a clear single answer on how to break a string into atomic units.\n * - Character attributes (e.g. bold, italic, etc):\n * Properties that can be set on any character independently with optimizations for runs of characters with the same attributes.\n * - Inline objects (e.g. images, embedded components, etc):\n * These would be logically part of the text, generalizing characters to allow inline objects in character ranges.\n * How character attributes apply to inline objects is an open question\n * (there could be a kind of object which gets them, and one that doesn't for example).\n * - Annotations (e.g. comments, suggestions, etc).\n * Objects which can be associated with a range of characters but are not logically part of the text.\n * These would need to have the logical range they apply to updated by edits.\n * How edits which overlap annotation boundaries are handled may require hints from the application for optimal behavior (mainly inserts at the boundaries).\n * These get a lifetime tied to the text node, not any of the characters the annotation covers,\n * however it might be desirable to have a way for a range edit to (optionally) also remove any annotations which are fully covered by the edit.\n * Annotations over an empty range should also be supported and behave well (for example not end up with characters inside the range after edits unless specifically structured so that makes sense).\n * - Anchors (e.g. positions in the text which survive edits).\n * These would be useful for ephemeral state like cursor positions, but should match the behaviors with respect to edits exhibited by the ends of Annotations.\n *\n * How these features will be represented in the schema and API should be determined before any of this is stabilized so the simple more limited version can neatly fit into the larger design.\n *\n * There are various optimizations that should be implemented to make this performant for large texts and common usage patterns.\n * These include:\n * - Optimized persisted format.\n * - Optimized in memory representation (via chunked forest).\n * - Optimized edit persisted format (e.g. combining adjacent inserts/removes into single operations as well as support for efficient attribute editing of ranges).\n * - Optimized edit application (e.g. applying the above noted optimizable edit cases efficiently).\n * This applies to the revision manager, the forest, and any flex or simple-tree nodes and user events.\n *\n * There are also additional features required for ensuring the invariants of collaborative text editing are maintained through concurrent edits.\n * The main challenges here are related to annotations, but some policies for what to do in the case of corrupt/invalid text should also be included.\n * There are quite a few ways invariants could break, including:\n * - concurrent edits without proper constraints.\n * - collaboration with clients using compatible schema with different constraints.\n * - opening documents which contain invalid content (e.g. from older versions of the software, manual edits to the persisted format, or simply an existing corrupt case which was saved).\n * - a user inserting/constructing/importing invalid content.\n *\n * These cases could break constraints causing issues like invalided characters (empty, a utf-16 surrogate pair alone, etc) or\n * annotations which reference out of bounds character ranges.\n * Addressing these issues mainly falls into these categories:\n * - Handling of invalid content on import/construction of unhydrated nodes and/or insertion into the document (hydration).\n * - Handling of invalid content which is already part of the document (live). This should ideally include both detection and repair.\n * - Constraints on edits to prevent invalid content from being created by merges.\n * - Optimization of the constraints to reduce cases in which edits are rejected due to conflicts.\n *\n * Note that these cases of invariant violations are the same cases any component should handle, so ideally there would be a general framework or pattern for documenting and enforcing such constraints.\n *\n * Another area for future work is improved APIs for import, export and non-schema-aware use. This includes a variety of cases, including but not limited to:\n * - Insertable content format (taken by the constructor and import APIs).\n * - Customizable export formats (like a way to make exportVerbose and exportConcise flatten the text nodes to strings automatically).\n * - Customizable toJson behavior (e.g. flattening to strings, possibly via tools or patterns for custom tree stringifier).\n * - Ensure JS object APIs (like iteration, own vs inherited properties, etc) provide a good and consistent experience with respect to other nodes.\n * - Support in generateSchemaFromSimpleSchema for recognizing text nodes and generating the appropriate schema.\n * - Ensure above features work well enough to support important scenarios like AI assisted editing and document indexing for search.\n *\n * Part of that work will be establishing and documenting those patterns so other components with complex encodings can follow them,\n * in addition to implementing them for text.\n * @alpha\n */\nexport namespace TextAsTree {\n\t/**\n\t * Statics for text nodes.\n\t * @alpha\n\t */\n\texport interface Statics {\n\t\t/**\n\t\t * Construct a {@link TextAsTree.(Tree:type)} from a string, where each character (as defined by iterating over the string) becomes a single character in the text node.\n\t\t * This combines pairs of utf-16 surrogate code units into single characters as appropriate.\n\t\t */\n\t\tfromString(value: string): Tree;\n\t}\n\n\t/**\n\t * Interface for a text node.\n\t * @remarks\n\t * The string is broken up into substrings which are referred to as 'characters'.\n\t * Unlike with JavaScript strings, all indexes are by character, not UTF-16 code unit.\n\t * This avoids the problem JavaScript where it can split UTF-16 surrogate pairs producing invalid strings,\n\t * and avoids the issue where indexing a string and iterating it segment the string differently.\n\t * This does NOT mean the characters correspond to user perceived characters (like grapheme clusters try to do):\n\t * applications will likely want to include higher level segmentation logic\n\t * which might differ between operations like delete\n\t * (which often operates on something in between unicode code points and grapheme clusters)\n\t * and navigation/selection (which typically uses grapheme clusters).\n\t *\n\t * @see {@link TextAsTree.Statics.fromString} for construction.\n\t * @see {@link TextAsTree.(Tree:type)} for schema.\n\t * @alpha\n\t */\n\texport interface Members {\n\t\t/**\n\t\t * Gets an iterable over the characters currently in the text.\n\t\t * @remarks\n\t\t * This iterator matches the behavior of {@link (TreeArrayNode:interface)} with respect to edits during iteration.\n\t\t */\n\t\tcharacters(): Iterable<string>;\n\n\t\t/**\n\t\t * Optimized way to get a copy of the {@link TextAsTree.Members.characters} in an array.\n\t\t */\n\t\tcharactersCopy(): string[];\n\n\t\t/**\n\t\t * Gets the number of characters currently in the text.\n\t\t * @remarks\n\t\t * The length of {@link TextAsTree.Members.characters}.\n\t\t * This is not the length of the string returned by {@link TextAsTree.Members.fullString},\n\t\t * as that string may contain characters which are made up of multiple UTF-16 code units.\n\t\t */\n\t\tcharacterCount(): number;\n\n\t\t/**\n\t\t * Copy the content of this node into a string.\n\t\t */\n\t\tfullString(): string;\n\n\t\t/**\n\t\t * Insert a range of characters into the string based on character index.\n\t\t * @remarks\n\t\t * See {@link (TreeArrayNode:interface).insertAt} for more details on the behavior.\n\t\t * See {@link TextAsTree.Statics.fromString} for how the `additionalCharacters` string is broken into characters.\n\t\t * @privateRemarks\n\t\t * If we provide ways to customize character boundaries, that could be handled here by taking in an Iterable<string> instead of a string.\n\t\t * Doing this currently would enable insertion of text with different character boundaries than the existing text,\n\t\t * which would violate the currently documented character boundary invariants.\n\t\t *\n\t\t * Another option would be to take an approach like Table,\n\t\t * where the user of the API uses a factory function to generate the schema, and can inject custom logic, like a string character iterator.\n\t\t */\n\t\tinsertAt(index: number, additionalCharacters: string): void;\n\n\t\t/**\n\t\t * Remove a range from a string based on character index.\n\t\t * See {@link (TreeArrayNode:interface).removeRange} for more details on the behavior.\n\t\t */\n\t\tremoveRange(startIndex: number | undefined, endIndex: number | undefined): void;\n\t}\n\n\t/**\n\t * Schema for a {@link TextAsTree.(Tree:variable)} node.\n\t * @remarks\n\t * See {@link TextAsTree.Statics} for static APIs on this schema, including construction.\n\t * @alpha\n\t */\n\texport const Tree = eraseSchemaDetails<Members, Statics>()(TextNode);\n\n\t/**\n\t * Node for the {@link TextAsTree.(Tree:type)} schema exposing the {@link TextAsTree.Members} API.\n\t * @remarks\n\t * Create using {@link TextAsTree.Statics.fromString}.\n\t * @alpha\n\t */\n\texport type Tree = Members & TreeNode & WithType<\"com.fluidframework.text.Text\">;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"textDomain.js","sourceRoot":"","sources":["../../src/text/textDomain.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,qCAAqC,CAAC;AACjF,OAAO,EACN,SAAS,EACT,mBAAmB;AAGnB,wDAAwD;EACxD,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EAAE,WAAW,IAAI,EAAE,EAAE,MAAM,uCAAuC,CAAC;AAE1E,OAAO,EAAE,QAAQ,EAAE,cAAc,EAA+B,MAAM,kBAAkB,CAAC;AACzF,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AACpD,OAAO,EACN,kBAAkB,EAClB,YAAY,EACZ,aAAa,EACb,kBAAkB,EAClB,aAAa,GACb,MAAM,yBAAyB,CAAC;AAajC,MAAM,EAAE,GAAG,IAAI,kBAAkB,CAAC,yBAAyB,CAAC,CAAC;AAE7D,MAAM,QACL,SAAQ,EAAE,CAAC,MAAM,CAAC,MAAM,EAAE;IACzB,OAAO,EAAE,aAAa,CAAC,QAAQ,CAAC,CAAC,GAAG,EAAE,CAAC,WAAW,CAAC,EAAE,EAAE,GAAG,EAAE,QAAQ,EAAE,CAAC;CACvE,CAAC;IAGK,MAAM,CAAC,CAAC,mBAAmB,CAAC,CAA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AAE,QAAQ,EAAE,IAAI,EAAE,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;QACzD,CAAC;aAAM,CAAC;YACP,+EAA+E;YAC/E,GAAG,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAE,EAAE,CAAC,KAAK,EAAE,CAAC,CAAC;QAC/C,CAAC;IACF,CAAC;IACD,QAAQ,CAAC,GAAG,CAAC,CAAC;AACf,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6DG;AACH,MAAM,KAAW,UAAU,CAgL1B;AAhLD,WAAiB,UAAU;IAiK1B;;;;;OAKG;IACU,eAAI,GAAG,kBAAkB,EAAoB,CAAC,QAAQ,CAAC,CAAC;AAStE,CAAC,EAhLgB,UAAU,KAAV,UAAU,QAgL1B","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { compareArrays, debugAssert } from \"@fluidframework/core-utils/internal\";\nimport {\n\tbuildFunc,\n\texposeMethodsSymbol,\n\ttype ExposedMethods,\n\ttype IExposedMethods,\n\t// eslint-disable-next-line import-x/no-internal-modules\n} from \"@fluidframework/type-factory/alpha\";\nimport { typeFactory as tf } from \"@fluidframework/type-factory/internal\";\n\nimport { EmptyKey, mapCursorField, type ITreeCursorSynchronous } from \"../core/index.js\";\nimport { TreeAlpha } from \"../shared-tree/index.js\";\nimport {\n\teraseSchemaDetails,\n\tgetInnerNode,\n\tSchemaFactory,\n\tSchemaFactoryAlpha,\n\tTreeArrayNode,\n} from \"../simple-tree/index.js\";\nimport type {\n\tArrayNodeDeltaOp,\n\tArrayNodeTreeChangedDeltaOp,\n\tTreeNode,\n\tWithType,\n\t// eslint-disable-next-line import-x/no-duplicates\n} from \"../simple-tree/index.js\";\n// Add some unused imports which show up in the generated d.ts file.\n// This prevents them from getting inline imports generated, cleaning up the d.ts file and API reports.\n// eslint-disable-next-line @typescript-eslint/no-unused-vars, unused-imports/no-unused-imports, import-x/no-duplicates\nimport type { NodeKind, TreeNodeSchema } from \"../simple-tree/index.js\";\n\nconst sf = new SchemaFactoryAlpha(\"com.fluidframework.text\");\n\nclass TextNode\n\textends sf.object(\"Text\", {\n\t\tcontent: SchemaFactory.required([() => StringArray], { key: EmptyKey }),\n\t})\n\timplements TextAsTree.Members, IExposedMethods\n{\n\tpublic static [exposeMethodsSymbol](methods: ExposedMethods): void {\n\t\tmethods.exposeMethod(\n\t\t\tTextNode,\n\t\t\t\"insertAt\",\n\t\t\tbuildFunc(\n\t\t\t\t{\n\t\t\t\t\tdescription:\n\t\t\t\t\t\t\"Insert characters into the text at the given character index (Unicode code points).\",\n\t\t\t\t\treturns: tf.void(),\n\t\t\t\t},\n\t\t\t\t[\"index\", tf.number()],\n\t\t\t\t[\"additionalCharacters\", tf.string()],\n\t\t\t),\n\t\t);\n\t\tmethods.exposeMethod(\n\t\t\tTextNode,\n\t\t\t\"removeRange\",\n\t\t\tbuildFunc(\n\t\t\t\t{\n\t\t\t\t\tdescription:\n\t\t\t\t\t\t\"Remove a range of characters from the text by character index (Unicode code points). startIndex defaults to 0 and endIndex defaults to the length of the text.\",\n\t\t\t\t\treturns: tf.void(),\n\t\t\t\t},\n\t\t\t\t[\"startIndex\", tf.union([tf.number(), tf.undefined()])],\n\t\t\t\t[\"endIndex\", tf.union([tf.number(), tf.undefined()])],\n\t\t\t),\n\t\t);\n\t\tmethods.exposeMethod(\n\t\t\tTextNode,\n\t\t\t\"fullString\",\n\t\t\tbuildFunc({\n\t\t\t\tdescription: \"Return a copy of this text node's content as a string.\",\n\t\t\t\treturns: tf.string(),\n\t\t\t}),\n\t\t);\n\t\tmethods.exposeMethod(\n\t\t\tTextNode,\n\t\t\t\"characterCount\",\n\t\t\tbuildFunc({\n\t\t\t\tdescription:\n\t\t\t\t\t\"Gets the number of characters (Unicode code points) currently in the text. Joined emojis and other grapheme clusters count as multiple characters.\",\n\t\t\t\treturns: tf.number(),\n\t\t\t}),\n\t\t);\n\t\tmethods.exposeMethod(\n\t\t\tTextNode,\n\t\t\t\"charactersCopy\",\n\t\t\tbuildFunc({\n\t\t\t\tdescription:\n\t\t\t\t\t\"Returns all characters in the text as an array, where each element is a single Unicode code point. Joined emojis and other grapheme clusters are split into separate elements.\",\n\t\t\t\treturns: tf.array(tf.string()),\n\t\t\t}),\n\t\t);\n\t}\n\n\tpublic [exposeMethodsSymbol](methods: ExposedMethods): void {\n\t\tTextNode[exposeMethodsSymbol](methods);\n\t}\n\n\tpublic insertAt(index: number, additionalCharacters: string): void {\n\t\tthis.content.insertAt(\n\t\t\tindex,\n\t\t\tTreeArrayNode.spread(charactersFromString(additionalCharacters)),\n\t\t);\n\t}\n\tpublic removeRange(index: number | undefined, end: number | undefined): void {\n\t\tthis.content.removeRange(index, end);\n\t}\n\tpublic characters(): Iterable<string> {\n\t\treturn this.content[Symbol.iterator]();\n\t}\n\n\tpublic characterCount(): number {\n\t\treturn this.content.length;\n\t}\n\n\tpublic charactersCopy(): string[] {\n\t\tconst result = this.content.charactersCopy();\n\t\tdebugAssert(\n\t\t\t() =>\n\t\t\t\tcompareArrays(result, this.charactersCopy_reference()) ||\n\t\t\t\t\"invalid charactersCopy optimizations\",\n\t\t);\n\t\treturn result;\n\t}\n\n\tpublic fullString(): string {\n\t\tconst result = this.content.fullString();\n\t\tdebugAssert(\n\t\t\t() => result === this.fullString_reference() || \"invalid fullString optimizations\",\n\t\t);\n\t\treturn result;\n\t}\n\n\t/**\n\t * Unoptimized trivially correct implementation of fullString.\n\t */\n\tpublic fullString_reference(): string {\n\t\treturn this.content.join(\"\");\n\t}\n\n\t/**\n\t * Unoptimized trivially correct implementation of charactersCopy.\n\t */\n\tpublic charactersCopy_reference(): string[] {\n\t\treturn [...this.content];\n\t}\n\n\tpublic onCharactersChanged(\n\t\tcallback: (ops: readonly TextAsTree.TextOp[] | undefined) => void,\n\t): () => void {\n\t\treturn TreeAlpha.on(this.content, \"nodeChanged\", ({ delta }) =>\n\t\t\tprocessCharactersChangedDelta(delta, (i) => this.content[i], callback),\n\t\t);\n\t}\n\n\tpublic static fromString(value: string): TextNode {\n\t\t// Constructing an ArrayNode from an iterator is supported, so creating an array from the iterable of characters seems like its not necessary here,\n\t\t// but to reduce the risk of incorrect data interpretation, we actually ban this in the special case where the iterable is a string directly, which is the case here.\n\t\t// Thus the array construction here is necessary to avoid a runtime error.\n\t\treturn new TextNode({ content: [...charactersFromString(value)] });\n\t}\n}\n\n/**\n * Interpret a string as an iterable of characters.\n * @remarks\n * This mostly exists to clearly document where the code is interpreting a string as characters,\n * and provide a centralized place where validation could be added in the future if desired.\n * Additionally using this function consistently will make any refactors to support alternative character boundaries easier.\n */\nexport function charactersFromString(value: string): Iterable<string> {\n\t// Uses the string as an iterable of characters, so utf-16 surrogate pairs get grouped together correctly.\n\t// Might be nice to call isWellFormed or toWellFormed here (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/toWellFormed)\n\t// But those are not widely supported yet.\n\treturn value;\n}\n\nclass StringArray extends sf.array(\"StringArray\", SchemaFactory.string) {\n\tpublic withBorrowedSequenceCursor<T>(f: (cursor: ITreeCursorSynchronous) => T): T {\n\t\tconst cursor = getInnerNode(this).borrowCursor();\n\t\tcursor.enterField(EmptyKey);\n\t\tconst result = f(cursor);\n\t\tcursor.exitField();\n\t\treturn result;\n\t}\n\n\tpublic charactersCopy(): string[] {\n\t\treturn this.withBorrowedSequenceCursor((cursor) =>\n\t\t\tmapCursorField(cursor, () => cursor.value as string),\n\t\t);\n\t}\n\n\tpublic fullString(): string {\n\t\treturn this.charactersCopy().join(\"\");\n\t}\n}\n\n/**\n * Processes an array-node delta into a {@link TextAsTree.TextOp}[] and calls `callback`.\n * @remarks\n * Shared by both the plain `onCharactersChanged` (from `nodeChanged`) and formatted `onContentChanged`\n * (from `treeChanged`) implementations.\n * @param delta - The raw array-node delta, or `undefined` when no delta is available.\n * When retain ops carry `subtreeChanged` (i.e. delta comes from a `treeChanged` event), the emitted\n * retain ops include an explicit `formattingChanged: boolean`. Otherwise `formattingChanged` is omitted.\n * @param getCharacter - Returns the character string at the given array index in the **post-edit** tree.\n * Only invoked for insert ops, where it must read the inserted character at the given index of the tree\n * after the edit has been applied. Passing an accessor that reads pre-edit content will silently produce wrong text.\n * Return `undefined` if the tree is out of sync with the delta; this triggers a full-reread fallback.\n * @param callback - The user-supplied callback to invoke with the translated ops.\n */\nexport function processCharactersChangedDelta(\n\tdelta: readonly (ArrayNodeDeltaOp | ArrayNodeTreeChangedDeltaOp)[] | undefined,\n\tgetCharacter: (index: number) => string | undefined,\n\tcallback: (ops: readonly TextAsTree.TextOp[] | undefined) => void,\n): void {\n\tif (delta === undefined) {\n\t\tcallback(undefined);\n\t\treturn;\n\t}\n\tlet readPosition = 0;\n\tconst ops: TextAsTree.TextOp[] = [];\n\tfor (const op of delta) {\n\t\tif (op.type === \"retain\") {\n\t\t\t// `subtreeChanged` is only present on retain ops from `treeChanged` deltas.\n\t\t\tops.push(\n\t\t\t\t\"subtreeChanged\" in op\n\t\t\t\t\t? { type: \"retain\", count: op.count, formattingChanged: op.subtreeChanged === true }\n\t\t\t\t\t: { type: \"retain\", count: op.count },\n\t\t\t);\n\t\t\treadPosition += op.count;\n\t\t} else if (op.type === \"insert\") {\n\t\t\t// Accumulate into an array and join at the end to keep this O(n) for large inserts\n\t\t\t// (paste of long text) instead of O(n^2) from repeated string concatenation.\n\t\t\tconst characters: string[] = [];\n\t\t\tfor (let i = 0; i < op.count; i++) {\n\t\t\t\tconst character = getCharacter(readPosition);\n\t\t\t\tif (character === undefined) {\n\t\t\t\t\t// Tree is out of sync with the delta — fall back to full re-read.\n\t\t\t\t\tcallback(undefined);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tcharacters.push(character);\n\t\t\t\treadPosition++;\n\t\t\t}\n\t\t\tops.push({ type: \"insert\", text: characters.join(\"\") });\n\t\t} else {\n\t\t\t// Construct explicit remove op so internal fields on the source op don't leak.\n\t\t\tops.push({ type: \"remove\", count: op.count });\n\t\t}\n\t}\n\tcallback(ops);\n}\n\n/**\n * A collection of text related types, schema and utilities for working with text beyond the basic {@link SchemaStatics.string}.\n * @privateRemarks\n * Currently this API only supports a really minimal feature set, and has no support for more advanced features like:\n * - Alternative character boundaries (e.g. grapheme clusters, paragraphs, tokens, etc.).\n * We may want to provide either ways to create strings with application controlled character boundaries since there is not a clear single answer on how to break a string into atomic units.\n * - Character attributes (e.g. bold, italic, etc):\n * Properties that can be set on any character independently with optimizations for runs of characters with the same attributes.\n * - Inline objects (e.g. images, embedded components, etc):\n * These would be logically part of the text, generalizing characters to allow inline objects in character ranges.\n * How character attributes apply to inline objects is an open question\n * (there could be a kind of object which gets them, and one that doesn't for example).\n * - Annotations (e.g. comments, suggestions, etc).\n * Objects which can be associated with a range of characters but are not logically part of the text.\n * These would need to have the logical range they apply to updated by edits.\n * How edits which overlap annotation boundaries are handled may require hints from the application for optimal behavior (mainly inserts at the boundaries).\n * These get a lifetime tied to the text node, not any of the characters the annotation covers,\n * however it might be desirable to have a way for a range edit to (optionally) also remove any annotations which are fully covered by the edit.\n * Annotations over an empty range should also be supported and behave well (for example not end up with characters inside the range after edits unless specifically structured so that makes sense).\n * - Anchors (e.g. positions in the text which survive edits).\n * These would be useful for ephemeral state like cursor positions, but should match the behaviors with respect to edits exhibited by the ends of Annotations.\n *\n * How these features will be represented in the schema and API should be determined before any of this is stabilized so the simple more limited version can neatly fit into the larger design.\n *\n * There are various optimizations that should be implemented to make this performant for large texts and common usage patterns.\n * These include:\n * - Optimized persisted format.\n * - Optimized in memory representation (via chunked forest).\n * - Optimized edit persisted format (e.g. combining adjacent inserts/removes into single operations as well as support for efficient attribute editing of ranges).\n * - Optimized edit application (e.g. applying the above noted optimizable edit cases efficiently).\n * This applies to the revision manager, the forest, and any flex or simple-tree nodes and user events.\n *\n * There are also additional features required for ensuring the invariants of collaborative text editing are maintained through concurrent edits.\n * The main challenges here are related to annotations, but some policies for what to do in the case of corrupt/invalid text should also be included.\n * There are quite a few ways invariants could break, including:\n * - concurrent edits without proper constraints.\n * - collaboration with clients using compatible schema with different constraints.\n * - opening documents which contain invalid content (e.g. from older versions of the software, manual edits to the persisted format, or simply an existing corrupt case which was saved).\n * - a user inserting/constructing/importing invalid content.\n *\n * These cases could break constraints causing issues like invalided characters (empty, a utf-16 surrogate pair alone, etc) or\n * annotations which reference out of bounds character ranges.\n * Addressing these issues mainly falls into these categories:\n * - Handling of invalid content on import/construction of unhydrated nodes and/or insertion into the document (hydration).\n * - Handling of invalid content which is already part of the document (live). This should ideally include both detection and repair.\n * - Constraints on edits to prevent invalid content from being created by merges.\n * - Optimization of the constraints to reduce cases in which edits are rejected due to conflicts.\n *\n * Note that these cases of invariant violations are the same cases any component should handle, so ideally there would be a general framework or pattern for documenting and enforcing such constraints.\n *\n * Another area for future work is improved APIs for import, export and non-schema-aware use. This includes a variety of cases, including but not limited to:\n * - Insertable content format (taken by the constructor and import APIs).\n * - Customizable export formats (like a way to make exportVerbose and exportConcise flatten the text nodes to strings automatically).\n * - Customizable toJson behavior (e.g. flattening to strings, possibly via tools or patterns for custom tree stringifier).\n * - Ensure JS object APIs (like iteration, own vs inherited properties, etc) provide a good and consistent experience with respect to other nodes.\n * - Support in generateSchemaFromSimpleSchema for recognizing text nodes and generating the appropriate schema.\n * - Ensure above features work well enough to support important scenarios like AI assisted editing and document indexing for search.\n *\n * Part of that work will be establishing and documenting those patterns so other components with complex encodings can follow them,\n * in addition to implementing them for text.\n * @alpha\n */\nexport namespace TextAsTree {\n\t/**\n\t * A retain op in a character-level delta — a span of unchanged characters that the consumer should skip over.\n\t * @sealed\n\t * @alpha\n\t */\n\texport interface TextRetainOp {\n\t\t/**\n\t\t * Discriminator identifying this op as a retain.\n\t\t */\n\t\treadonly type: \"retain\";\n\t\t/**\n\t\t * The number of Unicode code points to retain.\n\t\t */\n\t\treadonly count: number;\n\t\t/**\n\t\t * Whether at least one character in the retained range had a deep change.\n\t\t * @remarks\n\t\t * Present only on retain ops delivered by {@link @fluidframework/tree#FormattedTextAsTree.Members.onContentChanged};\n\t\t * always absent on retain ops delivered by {@link TextAsTree.Members.onCharactersChanged}.\n\t\t * When present, `true` indicates the retained range contained a formatting property update\n\t\t * or an atom content edit; `false` indicates no deep change.\n\t\t */\n\t\treadonly formattingChanged?: boolean;\n\t}\n\n\t/**\n\t * An insert op in a character-level delta — characters newly added to the text.\n\t * @remarks\n\t * Carries the inserted text as a single string, which is more convenient for consumers than individual characters.\n\t * @sealed\n\t * @alpha\n\t */\n\texport interface TextInsertOp {\n\t\t/**\n\t\t * Discriminator identifying this op as an insert.\n\t\t */\n\t\treadonly type: \"insert\";\n\t\t/**\n\t\t * The newly inserted characters, concatenated into a single string.\n\t\t */\n\t\treadonly text: string;\n\t}\n\n\t/**\n\t * A remove op in a character-level delta — a span of characters that has been deleted from the text.\n\t * @sealed\n\t * @alpha\n\t */\n\texport interface TextRemoveOp {\n\t\t/**\n\t\t * Discriminator identifying this op as a remove.\n\t\t */\n\t\treadonly type: \"remove\";\n\t\t/**\n\t\t * The number of Unicode code points removed.\n\t\t */\n\t\treadonly count: number;\n\t}\n\n\t/**\n\t * A single operation in a character-level delta describing an insert, remove, or retain of text.\n\t * @alpha\n\t */\n\texport type TextOp = TextRetainOp | TextInsertOp | TextRemoveOp;\n\n\t/**\n\t * Statics for text nodes.\n\t * @alpha\n\t */\n\texport interface Statics {\n\t\t/**\n\t\t * Construct a {@link TextAsTree.(Tree:type)} from a string, where each character (as defined by iterating over the string) becomes a single character in the text node.\n\t\t * This combines pairs of utf-16 surrogate code units into single characters as appropriate.\n\t\t */\n\t\tfromString(value: string): Tree;\n\t}\n\n\t/**\n\t * Interface for a text node.\n\t * @remarks\n\t * The string is broken up into substrings which are referred to as 'characters'.\n\t * Unlike with JavaScript strings, all indexes are by character, not UTF-16 code unit.\n\t * This avoids the problem JavaScript where it can split UTF-16 surrogate pairs producing invalid strings,\n\t * and avoids the issue where indexing a string and iterating it segment the string differently.\n\t * This does NOT mean the characters correspond to user perceived characters (like grapheme clusters try to do):\n\t * applications will likely want to include higher level segmentation logic\n\t * which might differ between operations like delete\n\t * (which often operates on something in between unicode code points and grapheme clusters)\n\t * and navigation/selection (which typically uses grapheme clusters).\n\t *\n\t * @see {@link TextAsTree.Statics.fromString} for construction.\n\t * @see {@link TextAsTree.(Tree:type)} for schema.\n\t * @sealed\n\t * @alpha\n\t */\n\texport interface Members {\n\t\t/**\n\t\t * Gets an iterable over the characters currently in the text.\n\t\t * @remarks\n\t\t * This iterator matches the behavior of {@link (TreeArrayNode:interface)} with respect to edits during iteration.\n\t\t */\n\t\tcharacters(): Iterable<string>;\n\n\t\t/**\n\t\t * Optimized way to get a copy of the {@link TextAsTree.Members.characters} in an array.\n\t\t */\n\t\tcharactersCopy(): string[];\n\n\t\t/**\n\t\t * Gets the number of characters currently in the text.\n\t\t * @remarks\n\t\t * The length of {@link TextAsTree.Members.characters}.\n\t\t * This is not the length of the string returned by {@link TextAsTree.Members.fullString},\n\t\t * as that string may contain characters which are made up of multiple UTF-16 code units.\n\t\t */\n\t\tcharacterCount(): number;\n\n\t\t/**\n\t\t * Copy the content of this node into a string.\n\t\t */\n\t\tfullString(): string;\n\n\t\t/**\n\t\t * Insert a range of characters into the string based on character index.\n\t\t * @remarks\n\t\t * See {@link (TreeArrayNode:interface).insertAt} for more details on the behavior.\n\t\t * See {@link TextAsTree.Statics.fromString} for how the `additionalCharacters` string is broken into characters.\n\t\t * @privateRemarks\n\t\t * If we provide ways to customize character boundaries, that could be handled here by taking in an Iterable<string> instead of a string.\n\t\t * Doing this currently would enable insertion of text with different character boundaries than the existing text,\n\t\t * which would violate the currently documented character boundary invariants.\n\t\t *\n\t\t * Another option would be to take an approach like Table,\n\t\t * where the user of the API uses a factory function to generate the schema, and can inject custom logic, like a string character iterator.\n\t\t */\n\t\tinsertAt(index: number, additionalCharacters: string): void;\n\n\t\t/**\n\t\t * Remove a range from a string based on character index.\n\t\t * See {@link (TreeArrayNode:interface).removeRange} for more details on the behavior.\n\t\t */\n\t\tremoveRange(startIndex: number | undefined, endIndex: number | undefined): void;\n\n\t\t/**\n\t\t * Subscribe to shallow character-level changes on this text node — inserts and removes only.\n\t\t * @param callback - Called after each change with a sequence of {@link TextAsTree.TextOp}s describing what changed,\n\t\t * or `undefined` when a delta could not be computed (e.g. during a schema upgrade).\n\t\t * @returns A cleanup function that unsubscribes the callback when called.\n\t\t * @remarks\n\t\t * Only fires on shallow changes — inserts and removes.\n\t\t * It does not fire on deep changes such as formatting property updates on existing characters.\n\t\t * For formatted text, use {@link @fluidframework/tree#FormattedTextAsTree.Members.onContentChanged} to also receive deep changes.\n\t\t *\n\t\t * All counts in the delivered ops are in Unicode code points, not UTF-16 code units.\n\t\t * For characters outside the Basic Multilingual Plane (e.g. emoji), one code point\n\t\t * corresponds to two UTF-16 code units — convert before using the counts as string indices.\n\t\t */\n\t\tonCharactersChanged(callback: (ops: readonly TextOp[] | undefined) => void): () => void;\n\t}\n\n\t/**\n\t * Schema for a {@link TextAsTree.(Tree:variable)} node.\n\t * @remarks\n\t * See {@link TextAsTree.Statics} for static APIs on this schema, including construction.\n\t * @alpha\n\t */\n\texport const Tree = eraseSchemaDetails<Members, Statics>()(TextNode);\n\n\t/**\n\t * Node for the {@link TextAsTree.(Tree:type)} schema exposing the {@link TextAsTree.Members} API.\n\t * @remarks\n\t * Create using {@link TextAsTree.Statics.fromString}.\n\t * @alpha\n\t */\n\texport type Tree = Members & TreeNode & WithType<\"com.fluidframework.text.Text\">;\n}\n"]}
|
|
@@ -31,7 +31,7 @@ export declare namespace FormattedTextAsTree {
|
|
|
31
31
|
/**
|
|
32
32
|
* The underlying text content of this atom.
|
|
33
33
|
* @remarks
|
|
34
|
-
* This is typically a single
|
|
34
|
+
* This is typically a single Unicode code point, and thus may contain multiple UTF-16 surrogate pair code units.
|
|
35
35
|
* Using longer strings is still valid. For example, so users might store whole grapheme clusters here, or even longer sections of text.
|
|
36
36
|
* Anything combined into a single atom will be treated atomically, and can not be partially selected or formatted.
|
|
37
37
|
* Using larger atoms and splitting them as needed is NOT a recommended approach, since this will result in poor merge behavior for concurrent edits.
|
|
@@ -46,7 +46,7 @@ export declare namespace FormattedTextAsTree {
|
|
|
46
46
|
/**
|
|
47
47
|
* The underlying text content of this atom.
|
|
48
48
|
* @remarks
|
|
49
|
-
* This is typically a single
|
|
49
|
+
* This is typically a single Unicode code point, and thus may contain multiple UTF-16 surrogate pair code units.
|
|
50
50
|
* Using longer strings is still valid. For example, so users might store whole grapheme clusters here, or even longer sections of text.
|
|
51
51
|
* Anything combined into a single atom will be treated atomically, and can not be partially selected or formatted.
|
|
52
52
|
* Using larger atoms and splitting them as needed is NOT a recommended approach, since this will result in poor merge behavior for concurrent edits.
|
|
@@ -84,8 +84,8 @@ export declare namespace FormattedTextAsTree {
|
|
|
84
84
|
h4: import("../simple-tree/index.js").TreeNodeSchemaClass<"com.fluidframework.text.formatted.lineTag.h4" | "com.h4", import("../simple-tree/index.js").NodeKind.Object, TreeNode & {
|
|
85
85
|
readonly value: "h4";
|
|
86
86
|
}, Record<string, never>, true, Record<string, never>, undefined>;
|
|
87
|
-
|
|
88
|
-
readonly value: "
|
|
87
|
+
checked: import("../simple-tree/index.js").TreeNodeSchemaClass<"com.fluidframework.text.formatted.lineTag.checked" | "com.checked", import("../simple-tree/index.js").NodeKind.Object, TreeNode & {
|
|
88
|
+
readonly value: "checked";
|
|
89
89
|
}, Record<string, never>, true, Record<string, never>, undefined>;
|
|
90
90
|
h5: import("../simple-tree/index.js").TreeNodeSchemaClass<"com.fluidframework.text.formatted.lineTag.h5" | "com.h5", import("../simple-tree/index.js").NodeKind.Object, TreeNode & {
|
|
91
91
|
readonly value: "h5";
|
|
@@ -93,8 +93,8 @@ export declare namespace FormattedTextAsTree {
|
|
|
93
93
|
li: import("../simple-tree/index.js").TreeNodeSchemaClass<"com.fluidframework.text.formatted.lineTag.li" | "com.li", import("../simple-tree/index.js").NodeKind.Object, TreeNode & {
|
|
94
94
|
readonly value: "li";
|
|
95
95
|
}, Record<string, never>, true, Record<string, never>, undefined>;
|
|
96
|
-
|
|
97
|
-
readonly value: "
|
|
96
|
+
ol: import("../simple-tree/index.js").TreeNodeSchemaClass<"com.fluidframework.text.formatted.lineTag.ol" | "com.ol", import("../simple-tree/index.js").NodeKind.Object, TreeNode & {
|
|
97
|
+
readonly value: "ol";
|
|
98
98
|
}, Record<string, never>, true, Record<string, never>, undefined>;
|
|
99
99
|
unchecked: import("../simple-tree/index.js").TreeNodeSchemaClass<"com.fluidframework.text.formatted.lineTag.unchecked" | "com.unchecked", import("../simple-tree/index.js").NodeKind.Object, TreeNode & {
|
|
100
100
|
readonly value: "unchecked";
|
|
@@ -871,6 +871,24 @@ export declare namespace FormattedTextAsTree {
|
|
|
871
871
|
* @param endIndex - Optional ending index (exclusive). Defaults to the end of the text.
|
|
872
872
|
*/
|
|
873
873
|
getString(startIndex: number, endIndex?: number): string;
|
|
874
|
+
/**
|
|
875
|
+
* Subscribe to all content changes on this text node, including both shallow
|
|
876
|
+
* changes (inserts/removes) and deep changes (formatting updates on existing characters).
|
|
877
|
+
* @param callback - Called after each change with a sequence of {@link TextAsTree.TextOp}s describing what changed,
|
|
878
|
+
* or `undefined` when a delta could not be computed (e.g. during a schema upgrade).
|
|
879
|
+
* @returns A cleanup function that unsubscribes the callback when called.
|
|
880
|
+
* @remarks
|
|
881
|
+
* Unlike {@link TextAsTree.Members.onCharactersChanged} which only fires on
|
|
882
|
+
* shallow changes (inserts and removes), this method also fires on deep changes —
|
|
883
|
+
* formatting property updates on existing characters.
|
|
884
|
+
* The {@link TextAsTree.TextRetainOp.formattingChanged} flag on retain ops
|
|
885
|
+
* indicates which character ranges had formatting updates.
|
|
886
|
+
*
|
|
887
|
+
* All counts in the delivered ops are in Unicode code points, not UTF-16 code units.
|
|
888
|
+
* For characters outside the Basic Multilingual Plane (e.g. emoji), one code point
|
|
889
|
+
* corresponds to two UTF-16 code units — convert before using the counts as string indices.
|
|
890
|
+
*/
|
|
891
|
+
onContentChanged(callback: (ops: readonly TextAsTree.TextOp[] | undefined) => void): () => void;
|
|
874
892
|
}
|
|
875
893
|
/**
|
|
876
894
|
* Schema for a text node.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"textDomainFormatted.d.ts","sourceRoot":"","sources":["../../src/text/textDomainFormatted.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAsBH,OAAO,KAAK,EACX,mBAAmB,EACnB,QAAQ,EACR,gCAAgC,EAChC,QAAQ,EACR,MAAM,yBAAyB,CAAC;AAGjC,OAAO,
|
|
1
|
+
{"version":3,"file":"textDomainFormatted.d.ts","sourceRoot":"","sources":["../../src/text/textDomainFormatted.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAsBH,OAAO,KAAK,EACX,mBAAmB,EACnB,QAAQ,EACR,gCAAgC,EAChC,QAAQ,EACR,MAAM,yBAAyB,CAAC;AAGjC,OAAO,EAGN,KAAK,UAAU,EACf,MAAM,iBAAiB,CAAC;AA4VzB;;;;;;;;GAQG;AACH,yBAAiB,mBAAmB,CAAC;;;;;;;;IACpC;;;OAGG;IACH,MAAM,OAAO,eAAgB,SAAQ,oBAMnC;KAAG;;QAOJ;;;;;;;;;;WAUG;;;;;QAVH;;;;;;;;;;WAUG;;;IAfJ;;;OAGG;IACH,MAAM,OAAO,cAAe,SAAQ,mBAalC;KAAG;IAEL;;;OAGG;IACH,MAAM,CAAC,MAAM,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KAYlB,CAAC;IACH;;;OAGG;IACH,MAAM,MAAM,OAAO,GAAG,gCAAgC,CAAC,OAAO,OAAO,CAAC,MAAM,CAAC,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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,IAAI,SAAS,UAAU,EAAE,CAAC;QAElD;;;;;;;;;;;;WAYG;QACH,sBAAsB,CACrB,KAAK,EAAE,MAAM,EACb,oBAAoB,EAAE,QAAQ,CAAC,mBAAmB,CAAC,OAAO,UAAU,CAAC,CAAC,GACpE,IAAI,CAAC;QAER;;;;;;;WAOG;QACH,WAAW,CACV,UAAU,EAAE,MAAM,GAAG,SAAS,EAC9B,QAAQ,EAAE,MAAM,GAAG,SAAS,EAC5B,MAAM,EAAE,OAAO,CAAC,eAAe,CAAC,GAC9B,IAAI,CAAC;QAER;;;;WAIG;QACH,aAAa,CAAC,UAAU,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;QAC7D;;;;WAIG;QACH,SAAS,CAAC,UAAU,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;QAEzD;;;;;;;;;;;;;;;;WAgBG;QACH,gBAAgB,CACf,QAAQ,EAAE,CAAC,GAAG,EAAE,SAAS,UAAU,CAAC,MAAM,EAAE,GAAG,SAAS,KAAK,IAAI,GAC/D,MAAM,IAAI,CAAC;KACd;IAED;;;;;;OAMG;IACH,MAAM,CAAC,MAAM,IAAI,8RAAmD,CAAC;IACrE,MAAM,MAAM,IAAI,GAAG,OAAO,GAAG,QAAQ,GAAG,QAAQ,CAAC,wCAAwC,CAAC,CAAC;;CAC3F"}
|
|
@@ -9,7 +9,7 @@ import { currentObserver, buildNodeComparator } from "../feature-libraries/index
|
|
|
9
9
|
import { TreeAlpha } from "../shared-tree/index.js";
|
|
10
10
|
import { enumFromStrings, eraseSchemaDetails, getInnerNode, SchemaFactory, SchemaFactoryAlpha, TreeArrayNode, TreeBeta, } from "../simple-tree/index.js";
|
|
11
11
|
import { brand, mapIterable, validateIndex, validateIndexRange } from "../util/index.js";
|
|
12
|
-
import { charactersFromString } from "./textDomain.js";
|
|
12
|
+
import { charactersFromString, processCharactersChangedDelta, } from "./textDomain.js";
|
|
13
13
|
const sf = new SchemaFactoryAlpha("com.fluidframework.text.formatted");
|
|
14
14
|
class TextNode extends sf.object("Text", {
|
|
15
15
|
content: SchemaFactory.required([() => StringArray], { key: EmptyKey }),
|
|
@@ -98,6 +98,15 @@ class TextNode extends sf.object("Text", {
|
|
|
98
98
|
// If this node does not have a corresponding branch, then it is unhydrated.
|
|
99
99
|
// I.e., it is not part of a collaborative session yet.
|
|
100
100
|
// Therefore, we don't need to run the edits as a transaction.
|
|
101
|
+
// Note: for unhydrated nodes each atom edit fires a separate `treeChanged` event,
|
|
102
|
+
// so formatting N atoms will produce N callbacks on `onContentChanged` subscribers
|
|
103
|
+
// instead of the single callback that hydrated (transacted) edits produce.
|
|
104
|
+
// `withBufferedTreeEvents` is not a viable mitigation here: when more than one atom's
|
|
105
|
+
// `format` field changes within the same buffered scope, the kernel's per-field
|
|
106
|
+
// dedup logic discards the delta (see `treeNodeKernel.ts` `#fieldMarksBuffer`),
|
|
107
|
+
// which is worse for incremental consumers than N well-formed callbacks.
|
|
108
|
+
// Use `runTransaction` on a hydrated node (i.e. after inserting into the document)
|
|
109
|
+
// if batched events matter.
|
|
101
110
|
applyFormatting();
|
|
102
111
|
}
|
|
103
112
|
else {
|
|
@@ -107,6 +116,25 @@ class TextNode extends sf.object("Text", {
|
|
|
107
116
|
});
|
|
108
117
|
}
|
|
109
118
|
}
|
|
119
|
+
/**
|
|
120
|
+
* Returns the character string at the given atom index, or `undefined` if out of bounds.
|
|
121
|
+
* @remarks
|
|
122
|
+
* Line atoms expand to `"\n"`; text atoms return their underlying code point(s).
|
|
123
|
+
*/
|
|
124
|
+
getAtomCharacterAt(index) {
|
|
125
|
+
const atom = this.content[index];
|
|
126
|
+
if (atom === undefined)
|
|
127
|
+
return undefined;
|
|
128
|
+
return atom.content instanceof FormattedTextAsTree.StringLineAtom
|
|
129
|
+
? "\n"
|
|
130
|
+
: atom.content.content;
|
|
131
|
+
}
|
|
132
|
+
onCharactersChanged(callback) {
|
|
133
|
+
return TreeAlpha.on(this.content, "nodeChanged", ({ delta }) => processCharactersChangedDelta(delta, (index) => this.getAtomCharacterAt(index), callback));
|
|
134
|
+
}
|
|
135
|
+
onContentChanged(callback) {
|
|
136
|
+
return TreeAlpha.on(this.content, "treeChanged", ({ delta }) => processCharactersChangedDelta(delta, (index) => this.getAtomCharacterAt(index), callback));
|
|
137
|
+
}
|
|
110
138
|
getUniformRun(startIndex, endIndex) {
|
|
111
139
|
return this.content.getUniformRun(startIndex, endIndex);
|
|
112
140
|
}
|
|
@@ -266,7 +294,7 @@ export var FormattedTextAsTree;
|
|
|
266
294
|
/**
|
|
267
295
|
* The underlying text content of this atom.
|
|
268
296
|
* @remarks
|
|
269
|
-
* This is typically a single
|
|
297
|
+
* This is typically a single Unicode code point, and thus may contain multiple UTF-16 surrogate pair code units.
|
|
270
298
|
* Using longer strings is still valid. For example, so users might store whole grapheme clusters here, or even longer sections of text.
|
|
271
299
|
* Anything combined into a single atom will be treated atomically, and can not be partially selected or formatted.
|
|
272
300
|
* Using larger atoms and splitting them as needed is NOT a recommended approach, since this will result in poor merge behavior for concurrent edits.
|