Skip to content

Commit 22252d9

Browse files
authored
Merge pull request #606 from streamich/overlay-2
Peritext Overlay marker points
2 parents 70207da + 0c245f9 commit 22252d9

File tree

9 files changed

+76
-23
lines changed

9 files changed

+76
-23
lines changed

CHANGELOG.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
# [15.6.0](https://github.com/streamich/json-joy/compare/v15.5.0...v15.6.0) (2024-04-28)
22

3-
43
### Bug Fixes
54

6-
* **json-crdt:** 🐛 store golbal session in clock vector ([407c383](https://github.com/streamich/json-joy/commit/407c38321ea43916cc8ccd0ce0ff3f678e5be76e))
7-
5+
- **json-crdt:** 🐛 store golbal session in clock vector ([407c383](https://github.com/streamich/json-joy/commit/407c38321ea43916cc8ccd0ce0ff3f678e5be76e))
86

97
### Features
108

11-
* **json-crdt:** 🎸 use SESSION.GLOBAL for default value and schema setup ([4813bc9](https://github.com/streamich/json-joy/commit/4813bc99d91e5a7287fc23b51ad29b0a37a18d91))
9+
- **json-crdt:** 🎸 use SESSION.GLOBAL for default value and schema setup ([4813bc9](https://github.com/streamich/json-joy/commit/4813bc99d91e5a7287fc23b51ad29b0a37a18d91))
1210

1311
# [15.5.0](https://github.com/streamich/json-joy/compare/v15.4.1...v15.5.0) (2024-04-26)
1412

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import {OverlayPoint} from './OverlayPoint';
2+
import {SliceType} from '../types';
3+
import type {Anchor} from '../rga/constants';
4+
import type {AbstractRga} from '../../../json-crdt/nodes/rga';
5+
import type {ITimestampStruct} from '../../../json-crdt-patch/clock';
6+
import type {MarkerSlice} from '../slice/MarkerSlice';
7+
import {printTree} from 'sonic-forest/lib/print/printTree';
8+
9+
export class MarkerOverlayPoint extends OverlayPoint {
10+
/**
11+
* Hash value of the preceding text contents, up until the next marker.
12+
*/
13+
public textHash: number = 0;
14+
15+
constructor(
16+
protected readonly rga: AbstractRga<string>,
17+
id: ITimestampStruct,
18+
anchor: Anchor,
19+
public readonly marker: MarkerSlice,
20+
) {
21+
super(rga, id, anchor);
22+
}
23+
24+
/**
25+
* @todo Rename or access it directly.
26+
* @deprecated
27+
*/
28+
public markerHash(): number {
29+
return this.marker ? this.marker.hash : 0;
30+
}
31+
32+
public type(): SliceType {
33+
return this.marker && this.marker.type;
34+
}
35+
36+
public data(): unknown {
37+
return this.marker && this.marker.data();
38+
}
39+
40+
// ---------------------------------------------------------------- Printable
41+
42+
public toStringName(tab: string, lite?: boolean): string {
43+
const hash = lite ? '' : `#${this.textHash.toString(36).slice(-4)}`;
44+
const tag = lite ? '' : `, type = ${JSON.stringify(this.type() as any)}`;
45+
return `${super.toStringName(tab, lite)}${lite ? '' : ' '}${hash}${tag}`;
46+
}
47+
48+
public toString(tab: string = '', lite?: boolean): string {
49+
return super.toString(tab, lite) + (lite ? '' : printTree(tab, [(tab) => this.marker.toString(tab)]));
50+
}
51+
}

src/json-crdt-extensions/peritext/overlay/OverlayPoint.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import {Point} from '../rga/Point';
22
import {compare} from '../../../json-crdt-patch/clock';
33
import {OverlayRef, OverlayRefSliceEnd, OverlayRefSliceStart} from './refs';
44
import {printTree} from 'sonic-forest/lib/print/printTree';
5-
import type {SplitSlice} from '../slice/SplitSlice';
5+
import type {MarkerSlice} from '../slice/MarkerSlice';
66
import type {HeadlessNode} from 'sonic-forest/lib/types';
77
import type {Printable} from '../../../util/print/types';
88
import type {Slice} from '../slice/types';
@@ -157,7 +157,7 @@ export class OverlayPoint extends Point implements Printable, HeadlessNode {
157157
*
158158
* @param slice A marker (split slice).
159159
*/
160-
public addMarkerRef(slice: SplitSlice): void {
160+
public addMarkerRef(slice: MarkerSlice): void {
161161
this.refs.push(slice);
162162
this.addMarker(slice);
163163
}

src/json-crdt-extensions/peritext/overlay/refs.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type {SplitSlice} from '../slice/SplitSlice';
1+
import type {MarkerSlice} from '../slice/MarkerSlice';
22
import type {Slice} from '../slice/types';
33

44
/**
@@ -8,7 +8,7 @@ import type {Slice} from '../slice/types';
88
* and one to the end slice.
99
*/
1010
export type OverlayRef =
11-
| SplitSlice // Ref to a *marker* slice
11+
| MarkerSlice // Ref to a *marker*
1212
| OverlayRefSliceStart // Ref to the start of an annotation slice
1313
| OverlayRefSliceEnd; // Ref to the end of an annotation slice
1414

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import {PersistedSlice} from './PersistedSlice';
2+
3+
/**
4+
* Represents a block split in the text, i.e. it is a *marker* that shows
5+
* where a block was split.
6+
*
7+
* @deprecated
8+
*/
9+
export class MarkerSlice extends PersistedSlice {}

src/json-crdt-extensions/peritext/slice/PersistedSlice.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import {VecNode} from '../../../json-crdt/nodes';
1010
import {prettyOneLine} from '../../../json-pretty';
1111
import {validateType} from './util';
1212
import {s} from '../../../json-crdt-patch';
13-
import type {JsonNode} from '../../../json-crdt/nodes';
1413
import type {ITimestampStruct} from '../../../json-crdt-patch/clock';
1514
import type {ArrChunk} from '../../../json-crdt/nodes';
1615
import type {MutableSlice, SliceUpdateParams} from './types';

src/json-crdt-extensions/peritext/slice/Slices.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {updateRga} from '../../../json-crdt/hash';
55
import {CONST, updateNum} from '../../../json-hash';
66
import {printTree} from '../../../util/print/printTree';
77
import {SliceBehavior, SliceHeaderShift, SliceTupleIndex} from './constants';
8-
import {SplitSlice} from './SplitSlice';
8+
import {MarkerSlice} from './MarkerSlice';
99
import {VecNode} from '../../../json-crdt/nodes';
1010
import {AvlMap} from 'sonic-forest/lib/avl/AvlMap';
1111
import type {Slice} from './types';
@@ -56,14 +56,17 @@ export class Slices implements Stateful, Printable {
5656
const txt = this.txt;
5757
const slice =
5858
behavior === SliceBehavior.Split
59-
? new SplitSlice(txt, txt.str, chunk, tuple, behavior, type, start, end)
59+
? new MarkerSlice(txt, txt.str, chunk, tuple, behavior, type, start, end)
6060
: new PersistedSlice(txt, txt.str, chunk, tuple, behavior, type, start, end);
6161
this.list.set(chunk.id, slice);
6262
return slice;
6363
}
6464

65-
public insSplit(range: Range, type: SliceType, data?: unknown): SplitSlice {
66-
return this.ins(range, SliceBehavior.Split, type, data) as SplitSlice;
65+
/**
66+
* @todo Rename to `insMarker`.
67+
*/
68+
public insSplit(range: Range, type: SliceType, data?: unknown): MarkerSlice {
69+
return this.ins(range, SliceBehavior.Split, type, data) as MarkerSlice;
6770
}
6871

6972
public insStack(range: Range, type: SliceType, data?: unknown): PersistedSlice {
@@ -89,7 +92,7 @@ export class Slices implements Stateful, Printable {
8992
let slice = PersistedSlice.deserialize(txt, rga, chunk, tuple);
9093
// TODO: Simplify, remove `SplitSlice` class.
9194
if (slice.isSplit())
92-
slice = new SplitSlice(txt, rga, chunk, tuple, slice.behavior, slice.type, slice.start, slice.end);
95+
slice = new MarkerSlice(txt, rga, chunk, tuple, slice.behavior, slice.type, slice.start, slice.end);
9396
return slice;
9497
}
9598

src/json-crdt-extensions/peritext/slice/SplitSlice.ts

Lines changed: 0 additions & 9 deletions
This file was deleted.

src/json-crdt-extensions/peritext/slice/constants.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ export const enum SliceBehavior {
2727
/**
2828
* A Split slice, which is used to mark a block split position in the document.
2929
* For example, paragraph, heading, blockquote, etc.
30+
*
31+
* @todo Rename to `Marker`.
3032
*/
3133
Split = 0b000,
3234

0 commit comments

Comments
 (0)