@@ -7,9 +7,11 @@ import { assert } from "@fluidframework/core-utils/internal";
7
7
8
8
import {
9
9
CursorLocationType ,
10
+ type ExclusiveMapTree ,
10
11
type FieldAnchor ,
11
12
type FieldKey ,
12
13
type FieldUpPath ,
14
+ type ITreeCursorSynchronous ,
13
15
type ITreeSubscriptionCursor ,
14
16
type TreeNavigationResult ,
15
17
inCursorNode ,
@@ -37,7 +39,6 @@ import {
37
39
type FlexTreeTypedField ,
38
40
type FlexTreeTypedNodeUnion ,
39
41
type FlexTreeUnboxNodeUnion ,
40
- type FlexibleNodeContent ,
41
42
TreeStatus ,
42
43
flexTreeMarker ,
43
44
flexTreeSlot ,
@@ -54,7 +55,7 @@ import { type LazyTreeNode, makeTree } from "./lazyNode.js";
54
55
import { unboxedUnion } from "./unboxed.js" ;
55
56
import { indexForAt , treeStatusFromAnchorCache } from "./utilities.js" ;
56
57
import { UsageError } from "@fluidframework/telemetry-utils/internal" ;
57
- import { cursorForMapTreeNode } from "../mapTreeCursor.js" ;
58
+ import { cursorForMapTreeField , cursorForMapTreeNode } from "../mapTreeCursor.js" ;
58
59
59
60
/**
60
61
* Reuse fields.
@@ -297,10 +298,21 @@ export class LazySequence<TTypes extends FlexAllowedTypes>
297
298
return this . map ( ( x ) => x ) ;
298
299
}
299
300
300
- public sequenceEditor ( ) : SequenceFieldEditBuilder {
301
+ public editor : SequenceFieldEditBuilder < ExclusiveMapTree [ ] > = {
302
+ insert : ( index , newContent ) => {
303
+ this . sequenceEditor ( ) . insert ( index , cursorForMapTreeField ( newContent ) ) ;
304
+ } ,
305
+ remove : ( index , count ) => {
306
+ this . sequenceEditor ( ) . remove ( index , count ) ;
307
+ } ,
308
+ move : ( sourceIndex , count , destIndex ) => {
309
+ this . sequenceEditor ( ) . move ( sourceIndex , count , destIndex ) ;
310
+ } ,
311
+ } ;
312
+
313
+ private sequenceEditor ( ) : SequenceFieldEditBuilder < ITreeCursorSynchronous > {
301
314
const fieldPath = this . getFieldPathForEditing ( ) ;
302
- const fieldEditor = this . context . checkout . editor . sequenceField ( fieldPath ) ;
303
- return fieldEditor ;
315
+ return this . context . checkout . editor . sequenceField ( fieldPath ) ;
304
316
}
305
317
}
306
318
@@ -317,13 +329,15 @@ export class ReadonlyLazyValueField<TTypes extends FlexAllowedTypes>
317
329
super ( context , schema , cursor , fieldAnchor ) ;
318
330
}
319
331
332
+ public editor : ValueFieldEditBuilder < ExclusiveMapTree > = {
333
+ set : ( newContent ) => {
334
+ assert ( false , "Unexpected set of readonly field" ) ;
335
+ } ,
336
+ } ;
337
+
320
338
public get content ( ) : FlexTreeUnboxNodeUnion < TTypes > {
321
339
return this . atIndex ( 0 ) ;
322
340
}
323
-
324
- public set content ( newContent : FlexibleNodeContent ) {
325
- fail ( "cannot set content in readonly field" ) ;
326
- }
327
341
}
328
342
329
343
export class LazyValueField < TTypes extends FlexAllowedTypes >
@@ -339,7 +353,13 @@ export class LazyValueField<TTypes extends FlexAllowedTypes>
339
353
super ( context , schema , cursor , fieldAnchor ) ;
340
354
}
341
355
342
- private valueFieldEditor ( ) : ValueFieldEditBuilder {
356
+ public override editor : ValueFieldEditBuilder < ExclusiveMapTree > = {
357
+ set : ( newContent ) => {
358
+ this . valueFieldEditor ( ) . set ( cursorForMapTreeNode ( newContent ) ) ;
359
+ } ,
360
+ } ;
361
+
362
+ private valueFieldEditor ( ) : ValueFieldEditBuilder < ITreeCursorSynchronous > {
343
363
const fieldPath = this . getFieldPathForEditing ( ) ;
344
364
const fieldEditor = this . context . checkout . editor . valueField ( fieldPath ) ;
345
365
return fieldEditor ;
@@ -348,11 +368,6 @@ export class LazyValueField<TTypes extends FlexAllowedTypes>
348
368
public override get content ( ) : FlexTreeUnboxNodeUnion < TTypes > {
349
369
return this . atIndex ( 0 ) ;
350
370
}
351
-
352
- public override set content ( newContent : FlexibleNodeContent ) {
353
- assert ( newContent !== undefined , "Cannot set a required field to undefined" ) ;
354
- this . valueFieldEditor ( ) . set ( cursorForMapTreeNode ( newContent ) ) ;
355
- }
356
371
}
357
372
358
373
export class LazyIdentifierField < TTypes extends FlexAllowedTypes >
@@ -382,7 +397,16 @@ export class LazyOptionalField<TTypes extends FlexAllowedTypes>
382
397
super ( context , schema , cursor , fieldAnchor ) ;
383
398
}
384
399
385
- private optionalEditor ( ) : OptionalFieldEditBuilder {
400
+ public editor : OptionalFieldEditBuilder < ExclusiveMapTree > = {
401
+ set : ( newContent , wasEmpty ) => {
402
+ this . optionalEditor ( ) . set (
403
+ newContent !== undefined ? cursorForMapTreeNode ( newContent ) : newContent ,
404
+ wasEmpty ,
405
+ ) ;
406
+ } ,
407
+ } ;
408
+
409
+ private optionalEditor ( ) : OptionalFieldEditBuilder < ITreeCursorSynchronous > {
386
410
const fieldPath = this . getFieldPathForEditing ( ) ;
387
411
const fieldEditor = this . context . checkout . editor . optionalField ( fieldPath ) ;
388
412
return fieldEditor ;
@@ -391,13 +415,6 @@ export class LazyOptionalField<TTypes extends FlexAllowedTypes>
391
415
public get content ( ) : FlexTreeUnboxNodeUnion < TTypes > | undefined {
392
416
return this . length === 0 ? undefined : this . atIndex ( 0 ) ;
393
417
}
394
-
395
- public set content ( newContent : FlexibleNodeContent | undefined ) {
396
- this . optionalEditor ( ) . set (
397
- newContent !== undefined ? cursorForMapTreeNode ( newContent ) : undefined ,
398
- this . length === 0 ,
399
- ) ;
400
- }
401
418
}
402
419
403
420
export class LazyForbiddenField < TTypes extends FlexAllowedTypes > extends LazyField <
0 commit comments