@@ -79,6 +79,11 @@ class Document {
7979 return replica
8080 }
8181
82+ /*
83+ Public: Get operations integrated in the document.
84+
85+ Returns an {Array} of operations and marker updates.
86+ */
8287 getOperations ( ) {
8388 const markerOperations = [ ]
8489 this . markerLayersBySiteId . forEach ( ( layersById , siteId ) => {
@@ -101,6 +106,20 @@ class Document {
101106 return this . operations . concat ( markerOperations )
102107 }
103108
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+ */
104123 setTextInRange ( start , end , text , options ) {
105124 const spliceId = { site : this . siteId , seq : this . nextSequenceNumber }
106125 const operation = { type : 'splice' , spliceId}
@@ -120,6 +139,15 @@ class Document {
120139 return [ operation ]
121140 }
122141
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+ */
123151 getMarkers ( ) {
124152 const result = { }
125153 this . markerLayersBySiteId . forEach ( ( layersById , siteId ) => {
@@ -139,6 +167,18 @@ class Document {
139167 return result
140168 }
141169
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+ */
142182 updateMarkers ( layerUpdatesById ) {
143183 const operation = {
144184 type : 'markers-update' ,
@@ -195,6 +235,23 @@ class Document {
195235 return [ operation ]
196236 }
197237
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+ */
198255 undo ( ) {
199256 let spliceIndex = null
200257 let operationsToUndo = [ ]
@@ -221,6 +278,23 @@ class Document {
221278 }
222279 }
223280
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+ */
224298 redo ( ) {
225299 let spliceIndex = null
226300 let operationsToRedo = [ ]
@@ -257,6 +331,11 @@ class Document {
257331 this . redoStack . length = 0
258332 }
259333
334+ /*
335+ Public: Sets the interval for grouping transactions.
336+
337+ * `groupingInterval` {Number} of milliseconds
338+ */
260339 applyGroupingInterval ( groupingInterval ) {
261340 const topEntry = this . undoStack [ this . undoStack . length - 1 ]
262341 const previousEntry = this . undoStack [ this . undoStack . length - 2 ]
@@ -284,6 +363,15 @@ class Document {
284363 return Date . now ( )
285364 }
286365
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+ */
287375 createCheckpoint ( options ) {
288376 const checkpoint = new Checkpoint (
289377 this . nextCheckpointId ++ ,
@@ -328,6 +416,27 @@ class Document {
328416 }
329417 }
330418
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+ */
331440 revertToCheckpoint ( checkpointId , options ) {
332441 if ( this . isBarrierPresentBeforeCheckpoint ( checkpointId ) ) return false
333442
@@ -341,6 +450,19 @@ class Document {
341450 }
342451 }
343452
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+ */
344466 getChangesSinceCheckpoint ( checkpointId ) {
345467 const result = this . collectOperationsSinceCheckpoint ( checkpointId , false , false )
346468 if ( result ) {
@@ -379,6 +501,11 @@ class Document {
379501 }
380502 }
381503
504+ /*
505+ Public: Groups the last changes on the undo stack.
506+
507+ Returns true if a grouping was made, else false.
508+ */
382509 groupLastChanges ( ) {
383510 let lastTransaction
384511
@@ -406,6 +533,63 @@ class Document {
406533 return false
407534 }
408535
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+ */
409593 getHistory ( maxEntries ) {
410594 const originalUndoCounts = new Map ( this . undoCountsBySpliceId )
411595
@@ -600,6 +784,26 @@ class Document {
600784 }
601785 }
602786
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+ */
603807 integrateOperations ( operations ) {
604808 const integratedOperations = [ ]
605809 let oldUndoCounts
@@ -1093,6 +1297,11 @@ class Document {
10931297 }
10941298 }
10951299
1300+ /*
1301+ Public: Get the text of the Document.
1302+
1303+ Returns {String}
1304+ */
10961305 getText ( ) {
10971306 let text = ''
10981307 const segments = this . documentTree . getSegments ( )
0 commit comments