Skip to content

Commit 646facb

Browse files
committed
feat(json-crdt-peritext-ui): 🎸 standartize range event details
1 parent 37aed34 commit 646facb

File tree

1 file changed

+23
-6
lines changed
  • src/json-crdt-peritext-ui/events

1 file changed

+23
-6
lines changed

src/json-crdt-peritext-ui/events/types.ts

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -117,10 +117,27 @@ export type SelectionMoveInstruction = [
117117
collapse?: boolean,
118118
];
119119

120+
/**
121+
* The {@link RangeEventDetail} base interface is used by events
122+
* which apply change to a range (selection) of text in the document. Usually,
123+
* the events will apply changes to all ranges in the selection, some event may
124+
* use only the first range in the selection (like the "buffer" event).
125+
*
126+
* Selection-based events work by first constructing a *selection set*, which
127+
* is a list of {@link Range} or {@link Cursor} instances. They then apply the
128+
* event to each selection in the selection set.
129+
*
130+
* The selection set is constructed by using the `at` field to specify a single
131+
* {@link Range} or, if not specified, all {@link Cursor} instances in the
132+
* document are used. Then the `move` field is used to specify one or more move
133+
* operations to be applied to each range in the selection set.
134+
*/
135+
export interface RangeEventDetail extends SelectionDetailPart, SelectionMoveDetailPart {}
136+
120137
/**
121138
* Event dispatched to insert text into the document.
122139
*/
123-
export interface InsertDetail extends SelectionDetailPart, SelectionMoveDetailPart {
140+
export interface InsertDetail extends RangeEventDetail {
124141
text: string;
125142
}
126143

@@ -132,7 +149,7 @@ export interface InsertDetail extends SelectionDetailPart, SelectionMoveDetailPa
132149
* are collapsed to a single point, while deleting all text and any annotations
133150
* contained in the selections.
134151
*/
135-
export interface DeleteDetail extends SelectionDetailPart, SelectionMoveDetailPart {}
152+
export interface DeleteDetail extends RangeEventDetail {}
136153

137154
/**
138155
* The `cursor` event is emitted when caret or selection is changed. The event
@@ -217,7 +234,7 @@ export interface DeleteDetail extends SelectionDetailPart, SelectionMoveDetailPa
217234
* {at: [10], add: true}
218235
* ```
219236
*/
220-
export interface CursorDetail extends SelectionDetailPart, SelectionMoveDetailPart {
237+
export interface CursorDetail extends RangeEventDetail {
221238
/**
222239
* If `true`, the selection will be added to the current selection set, i.e.
223240
* a new cursor will be inserted at the specified position into the document.
@@ -232,7 +249,7 @@ export interface CursorDetail extends SelectionDetailPart, SelectionMoveDetailPa
232249
/**
233250
* Event dispatched to insert an inline rich-text annotation into the document.
234251
*/
235-
export interface FormatDetail extends SelectionDetailPart, SelectionMoveDetailPart {
252+
export interface FormatDetail extends RangeEventDetail {
236253
/**
237254
* Type of the annotation. The type is used to determine the visual style of
238255
* the annotation, for example, the type `'bold'` may render the text in bold.
@@ -299,7 +316,7 @@ export interface FormatDetail extends SelectionDetailPart, SelectionMoveDetailPa
299316
* block. Removing a marker results into a "join" action, which merges two
300317
* adjacent blocks into one.
301318
*/
302-
export interface MarkerDetail extends SelectionDetailPart, SelectionMoveDetailPart {
319+
export interface MarkerDetail extends RangeEventDetail {
303320
/**
304321
* The action to perform.
305322
*
@@ -330,7 +347,7 @@ export interface MarkerDetail extends SelectionDetailPart, SelectionMoveDetailPa
330347
* It can cut/copy the contents in various formats, such as native Peritext
331348
* format, HTML, Markdown, plain text, and other miscellaneous formats.
332349
*/
333-
export interface BufferDetail {
350+
export interface BufferDetail extends RangeEventDetail {
334351
/**
335352
* The action to perform. The `'cut'` and `'copy'` actions generally work
336353
* the same way, the only difference is that the `'cut'` action removes the

0 commit comments

Comments
 (0)