Skip to content

Commit 4612bd4

Browse files
committed
feat(json-crdt-extensions): 🎸 implement OverlayPointMarker
1 parent 70207da commit 4612bd4

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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 {SplitSlice} from '../slice/SplitSlice';
7+
8+
export class OverlayPointMarker extends OverlayPoint {
9+
/**
10+
* Hash value of the preceding text contents, up until the next marker.
11+
*/
12+
public textHash: number = 0;
13+
14+
/** @todo splice can always be set, maybe? */
15+
constructor(protected readonly rga: AbstractRga<string>, id: ITimestampStruct, anchor: Anchor, public readonly slice: SplitSlice | undefined) {
16+
super(rga, id, anchor);
17+
}
18+
19+
/** @todo Rename or access it directly. */
20+
public markerHash(): number {
21+
return this.slice ? this.slice.hash : 0;
22+
}
23+
24+
public tag(): SliceType | 0 {
25+
if (!this.slice) return 0;
26+
return this.slice.type;
27+
}
28+
29+
public data(): unknown {
30+
if (!this.slice) return undefined;
31+
return this.slice.data();
32+
}
33+
34+
// ---------------------------------------------------------------- Printable
35+
36+
public toStringName(tab: string, lite?: boolean): string {
37+
const hash = lite ? '' : `#${this.textHash.toString(36).slice(-4)}`;
38+
const tag = lite ? '' : `, ${JSON.stringify((this.tag() as any)[1])}`;
39+
return `${super.toStringName(tab, lite)}${lite ? '' : ' '}${hash}${tag}`;
40+
}
41+
}

0 commit comments

Comments
 (0)