@@ -79,6 +79,11 @@ class Document {
79
79
return replica
80
80
}
81
81
82
+ /*
83
+ Public: Get operations integrated in the document.
84
+
85
+ Returns an {Array} of operations and marker updates.
86
+ */
82
87
getOperations ( ) {
83
88
const markerOperations = [ ]
84
89
this . markerLayersBySiteId . forEach ( ( layersById , siteId ) => {
@@ -101,6 +106,20 @@ class Document {
101
106
return this . operations . concat ( markerOperations )
102
107
}
103
108
109
+ /*
110
+ Public: Modify the Document's text.
111
+
112
+ The modification can be a deletion, insertion, or both.
113
+ If `end` is after `start` in the document, the operation is a deletion.
114
+ If `text` is passed, the operation is an insertion.
115
+
116
+ * `start` {Point}
117
+ * `end` {Point}
118
+ * `text` {String}
119
+ * `options` unused TODO
120
+
121
+ Returns an {Array} containing the integrated operation.
122
+ */
104
123
setTextInRange ( start , end , text , options ) {
105
124
const spliceId = { site : this . siteId , seq : this . nextSequenceNumber }
106
125
const operation = { type : 'splice' , spliceId}
@@ -120,6 +139,15 @@ class Document {
120
139
return [ operation ]
121
140
}
122
141
142
+ /*
143
+ Public: Get markers present in the Document.
144
+
145
+ Returns an {Object} of shape:
146
+ * {Number} Site ID
147
+ * {Number} Marker layer ID
148
+ * {Number} Marker ID
149
+ * {Marker}
150
+ */
123
151
getMarkers ( ) {
124
152
const result = { }
125
153
this . markerLayersBySiteId . forEach ( ( layersById , siteId ) => {
@@ -139,6 +167,18 @@ class Document {
139
167
return result
140
168
}
141
169
170
+ /*
171
+ Public: Updates markers in the Document.
172
+
173
+ If a Marker exists with the specified ID, its value is updated.
174
+ If no Marker exists with the specified ID, one is created.
175
+
176
+ * `layerUpdatesById` {Object} of shape:
177
+ * {Number} Marker layer ID
178
+ * {Numer} Marker ID
179
+
180
+ Returns an {Array} of the marker update operation.
181
+ */
142
182
updateMarkers ( layerUpdatesById ) {
143
183
const operation = {
144
184
type : 'markers-update' ,
@@ -195,6 +235,23 @@ class Document {
195
235
return [ operation ]
196
236
}
197
237
238
+ /*
239
+ Public: Undoes one or more operations.
240
+
241
+ Returns null or {Object} of shape:
242
+ * `markers` {Object} of shape:
243
+ * {Number} Marker layer ID
244
+ * {Number} Marker ID
245
+ * {Marker}
246
+ * `textUpdates` {Array} of {Object}s of shape:
247
+ * `oldStart` {Point}
248
+ * `oldEnd` {Point}
249
+ * `oldText` {String}
250
+ * `newStart` {Point}
251
+ * `newEnd` {Point}
252
+ * `newText` {String}
253
+ * `operations` {Array} of operations
254
+ */
198
255
undo ( ) {
199
256
let spliceIndex = null
200
257
let operationsToUndo = [ ]
@@ -221,6 +278,23 @@ class Document {
221
278
}
222
279
}
223
280
281
+ /*
282
+ Public: Redoes one or more operations.
283
+
284
+ Returns null or {Object} of shape:
285
+ * `markers` {Object} of shape:
286
+ * {Number} Marker layer ID
287
+ * {Number} Marker ID
288
+ * {Marker}
289
+ * `textUpdates` {Array} of {Object}s of shape:
290
+ * `oldStart: {Point}
291
+ * `oldEnd` {Point}
292
+ * `oldText` {String}
293
+ * `newStart` {Point}
294
+ * `newEnd` {Point}
295
+ * `newText` {String}
296
+ * `operations` {Array} of operations
297
+ */
224
298
redo ( ) {
225
299
let spliceIndex = null
226
300
let operationsToRedo = [ ]
@@ -257,6 +331,11 @@ class Document {
257
331
this . redoStack . length = 0
258
332
}
259
333
334
+ /*
335
+ Public: Sets the interval for grouping transactions.
336
+
337
+ * `groupingInterval` {Number} of milliseconds
338
+ */
260
339
applyGroupingInterval ( groupingInterval ) {
261
340
const topEntry = this . undoStack [ this . undoStack . length - 1 ]
262
341
const previousEntry = this . undoStack [ this . undoStack . length - 2 ]
@@ -284,6 +363,15 @@ class Document {
284
363
return Date . now ( )
285
364
}
286
365
366
+ /*
367
+ Public: Creates a checkpoint in the undo stack.
368
+
369
+ * `options` {Object} of shape:
370
+ * `isBarrier` {Bool}
371
+ * `markers` {Array} of {Marker}s
372
+
373
+ Returns {Number}
374
+ */
287
375
createCheckpoint ( options ) {
288
376
const checkpoint = new Checkpoint (
289
377
this . nextCheckpointId ++ ,
@@ -328,6 +416,27 @@ class Document {
328
416
}
329
417
}
330
418
419
+ /*
420
+ Public: Reverts the document to a checkpoint in the undo stack.
421
+
422
+ * `checkpointId` {Number}
423
+ * `options` {Object} of shape:
424
+ * `deleteCheckpoint` {Bool}
425
+
426
+ Returns false if the revert couldn't be completed, else returns {Object} of shape:
427
+ * `markers` {Object} of shape:
428
+ * {Number} Marker layer ID
429
+ * {Number} Marker ID
430
+ * {Marker}
431
+ * `textUpdates` {Array} of {Object}s of shape:
432
+ * `oldStart` {Point}
433
+ * `oldEnd` {Point}
434
+ * `oldText` {String}
435
+ * `newStart` {Point}
436
+ * `newEnd` {Point}
437
+ * `newText` {String}
438
+ * `operations` {Array} of operations
439
+ */
331
440
revertToCheckpoint ( checkpointId , options ) {
332
441
if ( this . isBarrierPresentBeforeCheckpoint ( checkpointId ) ) return false
333
442
@@ -341,6 +450,19 @@ class Document {
341
450
}
342
451
}
343
452
453
+ /*
454
+ Public: Gets changes performed since a checkpoint.
455
+
456
+ * `checkpointId` {Number}
457
+
458
+ Returns false or {Array} of {Object}s of shape:
459
+ * `oldStart` {Point}
460
+ * `oldEnd` {Point}
461
+ * `oldText` {String}
462
+ * `newStart` {Point}
463
+ * `newEnd` {Point}
464
+ * `newText` {String}
465
+ */
344
466
getChangesSinceCheckpoint ( checkpointId ) {
345
467
const result = this . collectOperationsSinceCheckpoint ( checkpointId , false , false )
346
468
if ( result ) {
@@ -379,6 +501,11 @@ class Document {
379
501
}
380
502
}
381
503
504
+ /*
505
+ Public: Groups the last changes on the undo stack.
506
+
507
+ Returns true if a grouping was made, else false.
508
+ */
382
509
groupLastChanges ( ) {
383
510
let lastTransaction
384
511
@@ -406,6 +533,63 @@ class Document {
406
533
return false
407
534
}
408
535
536
+ /*
537
+ Public: Get history entries from the undo and redo stacks.
538
+
539
+ * `maxEntries` {Number} of history entries to return
540
+
541
+ Returns {Object} of shape:
542
+ * `nextCheckpointId` {Number}
543
+ * `undoStack` {Array} of {Object}s, either of shape:
544
+ * `type` {String} 'transaction'
545
+ * `changes` {Array} of {Object}s of shape:
546
+ * `oldStart` {Point}
547
+ * `oldEnd` {Point}
548
+ * `oldText` {String}
549
+ * `newStart` {Point}
550
+ * `newEnd` {Point}
551
+ * `newText` {String}
552
+ * `markersBefore` {Object} of shape:
553
+ * {Number} Marker layer ID
554
+ * {Number} Marker ID
555
+ * {Marker}
556
+ * `markersAfter` {Object} of shape:
557
+ * {Number} Marker layer ID
558
+ * {Number} Marker ID
559
+ * {Marker}
560
+ or of shape
561
+ * `type` {String} 'checkpoint'
562
+ * `id` {Number}
563
+ * `markers` {Object} of shape:
564
+ * {Number} Marker layer ID
565
+ * {Number} Marker ID
566
+ * {Marker}
567
+ * `redoStack` {Array} of {Object}s, either of shape:
568
+ * `type` {String} 'transaction'
569
+ * `changes` {Array} of {Object}s of shape:
570
+ * `oldStart` {Point}
571
+ * `oldEnd` {Point}
572
+ * `oldText` {String}
573
+ * `newStart` {Point}
574
+ * `newEnd` {Point}
575
+ * `newText` {String}
576
+ * `markersBefore` {Object} of shape:
577
+ * {Number} Marker layer ID
578
+ * {Number} Marker ID
579
+ * {Marker}
580
+ * `markersAfter` {Object} of shape:
581
+ * {Number} Marker layer ID
582
+ * {Number} Marker ID
583
+ * {Marker}
584
+ or of shape
585
+ * `type` {String} 'checkpoint'
586
+ * `id` {Number}
587
+ * `markers` {Object} of shape:
588
+ * {Number} Marker layer ID
589
+ * {Number} Marker ID
590
+ * {Marker}
591
+
592
+ */
409
593
getHistory ( maxEntries ) {
410
594
const originalUndoCounts = new Map ( this . undoCountsBySpliceId )
411
595
@@ -600,6 +784,26 @@ class Document {
600
784
}
601
785
}
602
786
787
+ /*
788
+ Public: Integrate operations locally.
789
+
790
+ * `operations` {Array} of operations.
791
+
792
+ Returns {Object} of shape:
793
+ * `markerUpdates` {Object} of shape:
794
+ // TODO confirm site ID here
795
+ * {Number} Site ID
796
+ * {Number} Marker layer ID
797
+ * {Number} Marker ID
798
+ * {Marker}
799
+ * `textUpdates` {Array} of {Object}s of shape:
800
+ * `oldStart` {Point}
801
+ * `oldEnd` {Point}
802
+ * `oldText` {String}
803
+ * `newStart` {Point}
804
+ * `newEnd` {Point}
805
+ * `newText` {String}
806
+ */
603
807
integrateOperations ( operations ) {
604
808
const integratedOperations = [ ]
605
809
let oldUndoCounts
@@ -1093,6 +1297,11 @@ class Document {
1093
1297
}
1094
1298
}
1095
1299
1300
+ /*
1301
+ Public: Get the text of the Document.
1302
+
1303
+ Returns {String}
1304
+ */
1096
1305
getText ( ) {
1097
1306
let text = ''
1098
1307
const segments = this . documentTree . getSegments ( )
0 commit comments