Skip to content

Commit df3bd42

Browse files
committed
style: 💄 fix linter issues
1 parent e3a1855 commit df3bd42

File tree

16 files changed

+123
-108
lines changed

16 files changed

+123
-108
lines changed

src/json-crdt-extensions/peritext/block/Inline.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ export class Inline<T = string> extends Range<T> implements Printable {
324324
stringify(
325325
attr[key].map((attr) => {
326326
const slice = attr.slice;
327-
return slice instanceof Cursor ? [slice.type(), slice.data()] : slice.data()
327+
return slice instanceof Cursor ? [slice.type(), slice.data()] : slice.data();
328328
}),
329329
);
330330
}),

src/json-crdt-extensions/peritext/editor/Editor.ts

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -951,21 +951,18 @@ export class Editor<T = string> implements Printable {
951951
}
952952
}
953953

954-
public updMarkerSlice(
955-
marker: MarkerSlice<T>,
956-
target: MarkerUpdateTarget,
957-
ops: ApiOperation[],
958-
): void {
959-
const node = target === 'type'
960-
? marker.nestedType().asArr()
961-
: target[0] === 'tag'
962-
? marker.nestedType().tag(target[1]).asVec()
963-
: target[0] === 'data'
964-
? marker.nestedType().tag(target[1])?.data()
965-
: void 0;
954+
public updMarkerSlice(marker: MarkerSlice<T>, target: MarkerUpdateTarget, ops: ApiOperation[]): void {
955+
const node =
956+
target === 'type'
957+
? marker.nestedType().asArr()
958+
: target[0] === 'tag'
959+
? marker.nestedType().tag(target[1]).asVec()
960+
: target[0] === 'data'
961+
? marker.nestedType().tag(target[1])?.data()
962+
: void 0;
966963
if (!node) return;
967964
for (const op of ops) node.op(op);
968-
if (target === 'type' && node instanceof ArrApi && node.length() === 0) marker.del();
965+
if (target === 'type' && node instanceof ArrApi && node.length() === 0) marker.del();
969966
}
970967

971968
public updMarkerAt(
@@ -977,13 +974,13 @@ export class Editor<T = string> implements Printable {
977974
const overlay = this.txt.overlay;
978975
const markerPoint = overlay.getOrNextLowerMarker(point);
979976
const marker: MarkerSlice<T> = markerPoint?.marker ?? this.setStartMarker([SliceTypeCon.p], void 0, slices);
980-
return this.updMarkerSlice(marker, target, ops);
977+
this.updMarkerSlice(marker, target, ops);
981978
}
982979

983980
public updMarker(
984-
selection: Range<T>[] | IterableIterator<Range<T>> = this.cursors(),
985981
target: MarkerUpdateTarget,
986982
ops: ApiOperation[],
983+
selection: Range<T>[] | IterableIterator<Range<T>> = this.cursors(),
987984
slices: EditorSlices<T> = this.saved,
988985
): void {
989986
for (const range of selection) this.updMarkerAt(range.start, target, ops, slices);

src/json-crdt-extensions/peritext/events/__tests__/format.spec.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ const testSuite = (getKit: () => Kit) => {
184184
kit.et.cursor({at: [10, 20]});
185185
kit.et.format({action: 'ins', type: SliceTypeCon.col, data: ['data']});
186186
expect(kit.toHtml()).toBe('<p>abcdefghij<col data-attr=\'["data"]\'>klmnopqrst</col>uvwxyz</p>');
187-
const slice = kit.peritext.savedSlices.each().find(slice => slice.type() === SliceTypeCon.col)!;
187+
const slice = kit.peritext.savedSlices.each().find((slice) => slice.type() === SliceTypeCon.col)!;
188188
expect(slice.data()).toEqual(['data']);
189189
kit.et.format({action: 'upd', slice, data: {color: 'green', opacity: 1}});
190190
expect(slice.data()).toEqual({color: 'green', opacity: 1});
@@ -195,7 +195,7 @@ const testSuite = (getKit: () => Kit) => {
195195
kit.et.cursor({at: [10, 20]});
196196
kit.et.format({action: 'ins', type: SliceTypeCon.col, data: {color: 'red'}});
197197
expect(kit.toHtml()).toBe('<p>abcdefghij<col data-attr=\'{"color":"red"}\'>klmnopqrst</col>uvwxyz</p>');
198-
const slice = kit.peritext.savedSlices.each().find(slice => slice.type() === SliceTypeCon.col)!;
198+
const slice = kit.peritext.savedSlices.each().find((slice) => slice.type() === SliceTypeCon.col)!;
199199
expect(slice.data()).toEqual({color: 'red'});
200200
kit.et.format({action: 'upd', slice, data: 'test'});
201201
expect(slice.data()).toEqual('test');
@@ -210,7 +210,7 @@ const testSuite = (getKit: () => Kit) => {
210210
expect(kit.toHtml()).toBe(
211211
'<p>abcdefghij<col data-attr=\'{"color":"green","opacity":0.5}\'>klmnopqrst</col>uvwxyz</p>',
212212
);
213-
const slice = kit.peritext.savedSlices.each().find(slice => slice.type() === SliceTypeCon.col)!;
213+
const slice = kit.peritext.savedSlices.each().find((slice) => slice.type() === SliceTypeCon.col)!;
214214
expect(slice.data()).toEqual({color: 'green', opacity: 0.5});
215215
kit.et.format({action: 'set', slice, data: {color: 'red'}});
216216
expect(slice.data()).toEqual({color: 'red'});
@@ -223,7 +223,7 @@ const testSuite = (getKit: () => Kit) => {
223223
expect(kit.toHtml()).toBe(
224224
'<p>abcdefghij<col data-attr=\'{"color":"green","opacity":0.5}\'>klmnopqrst</col>uvwxyz</p>',
225225
);
226-
const slice = kit.peritext.savedSlices.each().find(slice => slice.type() === SliceTypeCon.col)!;
226+
const slice = kit.peritext.savedSlices.each().find((slice) => slice.type() === SliceTypeCon.col)!;
227227
expect(slice.data()).toEqual({color: 'green', opacity: 0.5});
228228
kit.et.format({action: 'set', slice, data: 123});
229229
expect(slice.data()).toEqual(123);
@@ -234,7 +234,7 @@ const testSuite = (getKit: () => Kit) => {
234234
kit.et.cursor({at: [10, 20]});
235235
kit.et.format({action: 'ins', type: SliceTypeCon.col, data: true});
236236
expect(kit.toHtml()).toBe("<p>abcdefghij<col data-attr='true'>klmnopqrst</col>uvwxyz</p>");
237-
const slice = kit.peritext.savedSlices.each().find(slice => slice.type() === SliceTypeCon.col)!;
237+
const slice = kit.peritext.savedSlices.each().find((slice) => slice.type() === SliceTypeCon.col)!;
238238
expect(slice.data()).toEqual(true);
239239
kit.et.format({action: 'set', slice, data: {col: '#fff'}});
240240
expect(slice.data()).toEqual({col: '#fff'});
@@ -247,7 +247,7 @@ const testSuite = (getKit: () => Kit) => {
247247
kit.et.cursor({at: [10, 20]});
248248
kit.et.format({action: 'ins', type: SliceTypeCon.col, data: {color: 'red'}});
249249
expect(kit.toHtml()).toBe('<p>abcdefghij<col data-attr=\'{"color":"red"}\'>klmnopqrst</col>uvwxyz</p>');
250-
const slice = kit.peritext.savedSlices.each().find(slice => slice.type() === SliceTypeCon.col)!;
250+
const slice = kit.peritext.savedSlices.each().find((slice) => slice.type() === SliceTypeCon.col)!;
251251
expect(slice.data()).toEqual({color: 'red'});
252252
const obj = slice.dataNode()!;
253253
expect(obj instanceof ObjApi).toBe(true);
@@ -265,7 +265,7 @@ const testSuite = (getKit: () => Kit) => {
265265
kit.et.cursor({at: [10, 20]});
266266
kit.et.format({action: 'ins', type: SliceTypeCon.col, data: 'red'});
267267
expect(kit.toHtml()).toBe('<p>abcdefghij<col data-attr=\'"red"\'>klmnopqrst</col>uvwxyz</p>');
268-
const slice = kit.peritext.savedSlices.each().find(slice => slice.type() === SliceTypeCon.col)!;
268+
const slice = kit.peritext.savedSlices.each().find((slice) => slice.type() === SliceTypeCon.col)!;
269269
expect(slice.data()).toEqual('red');
270270
const obj = slice.dataNode()!;
271271
expect(obj.view()).toEqual('red');
@@ -276,7 +276,7 @@ const testSuite = (getKit: () => Kit) => {
276276
kit.et.cursor({at: [10, 20]});
277277
kit.et.format({action: 'ins', type: SliceTypeCon.col, data: ['green', 'red']});
278278
expect(kit.toHtml()).toBe('<p>abcdefghij<col data-attr=\'["green","red"]\'>klmnopqrst</col>uvwxyz</p>');
279-
const slice = kit.peritext.savedSlices.each().find(slice => slice.type() === SliceTypeCon.col)!;
279+
const slice = kit.peritext.savedSlices.each().find((slice) => slice.type() === SliceTypeCon.col)!;
280280
expect(slice.data()).toEqual(['green', 'red']);
281281
const api = slice.dataNode()!;
282282
expect(api instanceof ArrApi).toBe(true);

src/json-crdt-extensions/peritext/events/__tests__/marker.spec.ts

Lines changed: 30 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,9 @@ const testSuite = (getKit: () => Kit) => {
5757
kit.et.marker({action: 'ins', type: [[SliceTypeCon.blockquote, 1], SliceTypeCon.p]});
5858
kit.peritext.refresh();
5959
const html = kit.toHtml();
60-
expect(html).toBe('<p>abcde</p><blockquote><p>fghi</p></blockquote><blockquote><p>jklmnopqrstuvwxyz</p></blockquote>');
60+
expect(html).toBe(
61+
'<p>abcde</p><blockquote><p>fghi</p></blockquote><blockquote><p>jklmnopqrstuvwxyz</p></blockquote>',
62+
);
6163
});
6264
});
6365

@@ -92,36 +94,29 @@ const testSuite = (getKit: () => Kit) => {
9294
kit.et.marker({
9395
action: 'upd',
9496
target: 'type',
95-
ops: [
96-
['add', '/-', SliceTypeCon.p],
97-
],
97+
ops: [['add', '/-', SliceTypeCon.p]],
9898
});
9999
expect(kit.toHtml()).toBe('<p>abcdefgh</p><blockquote><p>ijklmnopqrstuvwxyz</p></blockquote>');
100100
kit.et.marker({
101101
action: 'upd',
102102
target: 'type',
103-
ops: [
104-
['add', '/2', [
105-
[SliceTypeCon.ul, 0, {type: 'tasks'}],
106-
SliceTypeCon.li,
107-
]],
108-
],
103+
ops: [['add', '/2', [[SliceTypeCon.ul, 0, {type: 'tasks'}], SliceTypeCon.li]]],
109104
});
110-
expect(kit.toHtml()).toBe('<p>abcdefgh</p><blockquote><p><ul data-attr=\'{"type":"tasks"}\'><li>ijklmnopqrstuvwxyz</li></ul></p></blockquote>');
105+
expect(kit.toHtml()).toBe(
106+
'<p>abcdefgh</p><blockquote><p><ul data-attr=\'{"type":"tasks"}\'><li>ijklmnopqrstuvwxyz</li></ul></p></blockquote>',
107+
);
111108
kit.et.marker({
112109
action: 'upd',
113110
target: 'type',
114-
ops: [
115-
['remove', [1]],
116-
],
111+
ops: [['remove', [1]]],
117112
});
118-
expect(kit.toHtml()).toBe('<p>abcdefgh</p><blockquote><ul data-attr=\'{"type":"tasks"}\'><li>ijklmnopqrstuvwxyz</li></ul></blockquote>');
113+
expect(kit.toHtml()).toBe(
114+
'<p>abcdefgh</p><blockquote><ul data-attr=\'{"type":"tasks"}\'><li>ijklmnopqrstuvwxyz</li></ul></blockquote>',
115+
);
119116
kit.et.marker({
120117
action: 'upd',
121118
target: 'type',
122-
ops: [
123-
['remove', '/1', 2],
124-
],
119+
ops: [['remove', '/1', 2]],
125120
});
126121
expect(kit.toHtml()).toBe('<p>abcdefgh</p><blockquote>ijklmnopqrstuvwxyz</blockquote>');
127122
});
@@ -134,9 +129,7 @@ const testSuite = (getKit: () => Kit) => {
134129
kit.et.marker({
135130
action: 'upd',
136131
target: 'type',
137-
ops: [
138-
['remove', '/0'],
139-
],
132+
ops: [['remove', '/0']],
140133
});
141134
expect(kit.toHtml()).toBe('<p>abcdefghijklmnopqrstuvwxyz</p>');
142135
});
@@ -151,9 +144,7 @@ const testSuite = (getKit: () => Kit) => {
151144
kit.et.marker({
152145
action: 'upd',
153146
target: ['tag', 0],
154-
ops: [
155-
['replace', '/0', SliceTypeCon.p],
156-
],
147+
ops: [['replace', '/0', SliceTypeCon.p]],
157148
});
158149
expect(kit.toHtml()).toBe('<p>abcdefgh</p><p>ijklmnopqrstuvwxyz</p>');
159150
});
@@ -169,9 +160,7 @@ const testSuite = (getKit: () => Kit) => {
169160
kit.et.marker({
170161
action: 'upd',
171162
target: ['tag', 0],
172-
ops: [
173-
['replace', '/1', 1],
174-
],
163+
ops: [['replace', '/1', 1]],
175164
});
176165
expect(slice?.nestedType().tag(0).discriminant()).toBe(1);
177166
slice?.nestedType().tag(0).setDiscriminant(2);
@@ -193,18 +182,26 @@ const testSuite = (getKit: () => Kit) => {
193182
['add', '/source', 'Journal of Hunchbacks'],
194183
],
195184
});
196-
expect(kit.toHtml()).toBe('<p>abcdefgh</p><blockquote data-attr=\'{"author":"Quasimodo","source":"Journal of Hunchbacks"}\'>ijklmnopqrstuvwxyz</blockquote>');
185+
expect(kit.toHtml()).toBe(
186+
'<p>abcdefgh</p><blockquote data-attr=\'{"author":"Quasimodo","source":"Journal of Hunchbacks"}\'>ijklmnopqrstuvwxyz</blockquote>',
187+
);
197188
kit.et.marker({
198189
action: 'upd',
199190
target: ['data', 0],
200191
ops: [
201-
['merge', '', {
202-
author: 'Pierre Gringoire',
203-
source: 'Journal of Hunchbacks',
204-
}],
192+
[
193+
'merge',
194+
'',
195+
{
196+
author: 'Pierre Gringoire',
197+
source: 'Journal of Hunchbacks',
198+
},
199+
],
205200
],
206201
});
207-
expect(kit.toHtml()).toBe('<p>abcdefgh</p><blockquote data-attr=\'{"author":"Pierre Gringoire","source":"Journal of Hunchbacks"}\'>ijklmnopqrstuvwxyz</blockquote>');
202+
expect(kit.toHtml()).toBe(
203+
'<p>abcdefgh</p><blockquote data-attr=\'{"author":"Pierre Gringoire","source":"Journal of Hunchbacks"}\'>ijklmnopqrstuvwxyz</blockquote>',
204+
);
208205
});
209206
});
210207
});

src/json-crdt-extensions/peritext/events/defaults/PeritextEventDefaults.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ export class PeritextEventDefaults implements PeritextEventHandlerMap {
288288
case 'upd': {
289289
const {target, ops} = detail;
290290
if (target && ops) {
291-
editor.updMarker(selection, target, ops);
291+
editor.updMarker(target, ops, selection);
292292
}
293293
break;
294294
}

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,10 @@ export class MarkerSlice<T = string> extends PersistedSlice<T> {
2323
public del(): void {
2424
super.del();
2525
const txt = this.txt;
26-
const range = txt.range(this.start, this.start.copy(p => p.anchor = Anchor.After));
26+
const range = txt.range(
27+
this.start,
28+
this.start.copy((p) => (p.anchor = Anchor.After)),
29+
);
2730
txt.delStr(range);
2831
}
2932
}

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

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import {s} from "../../../json-crdt-patch";
2-
import {ConApi, ObjApi, VecApi} from "../../../json-crdt/model";
3-
import {ConNode, ObjNode, VecNode} from "../../../json-crdt/nodes";
4-
import type {NestedType} from "./NestedType";
1+
import {s} from '../../../json-crdt-patch';
2+
import {ConApi, ObjApi, VecApi} from '../../../json-crdt/model';
3+
import type {ConNode, ObjNode, VecNode} from '../../../json-crdt/nodes';
4+
import type {NestedType} from './NestedType';
55

66
/**
77
* Represents a single nested tag in a slice type. For example, in a slice type
@@ -10,15 +10,18 @@ import type {NestedType} from "./NestedType";
1010
* contain a discriminant and data.
1111
*/
1212
export class NestedTag<T = string> {
13-
constructor (protected readonly type: NestedType<T>, public readonly index: number) {}
13+
constructor(
14+
protected readonly type: NestedType<T>,
15+
public readonly index: number,
16+
) {}
1417

1518
/**
1619
* Enforces current tag at `index` to be a "vec" node, which contains
1720
* a tag, a discriminant and an object with data.
1821
*/
1922
public asVec(): VecApi<VecNode<[ConNode<number | string>, ConNode<number>, ObjNode]>> {
2023
const arr = this.type.asArr();
21-
let typeLen = arr.length();
24+
const typeLen = arr.length();
2225
let index: number = this.index;
2326
if (typeof index !== 'number' || index > typeLen - 1) index = typeLen - 1;
2427
const vec = arr.get(index);

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import {ArrApi} from "../../../json-crdt/model";
2-
import {NestedTag} from "./NestedTag";
3-
import type {PersistedSlice} from "./PersistedSlice";
1+
import type {ArrApi} from '../../../json-crdt/model';
2+
import {NestedTag} from './NestedTag';
3+
import type {PersistedSlice} from './PersistedSlice';
44
import * as schema from './schema';
5-
import type {SliceTypeSteps} from "./types";
5+
import type {SliceTypeSteps} from './types';
66

77
export class NestedType<T = string> {
8-
constructor (protected slice: PersistedSlice<T>) {}
8+
constructor(protected slice: PersistedSlice<T>) {}
99

1010
/** Enforces slice type to be an "arr" of tags. */
1111
public asArr(): ArrApi {
@@ -18,7 +18,7 @@ export class NestedType<T = string> {
1818
type = api.view();
1919
if (!Array.isArray(type)) type = typeof type === 'number' || typeof type === 'string' ? [type] : [0];
2020
}
21-
slice.update({type: schema.type(type as SliceTypeSteps)})
21+
slice.update({type: schema.type(type as SliceTypeSteps)});
2222
return slice.typeApi() as unknown as ArrApi;
2323
}
2424

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

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,12 @@ import {validateType} from './util';
2020
import {NodeBuilder, s} from '../../../json-crdt-patch';
2121
import * as schema from './schema';
2222
import {JsonCrdtDiff} from '../../../json-crdt-diff/JsonCrdtDiff';
23-
import {ArrApi, ConApi, type Model, NodeApi, ObjApi, VecApi} from '../../../json-crdt/model';
24-
import {ArrNode, ConNode, ObjNode, VecNode} from '../../../json-crdt/nodes';
23+
import {type ArrApi, ConApi, type Model, type NodeApi, ObjApi, VecApi} from '../../../json-crdt/model';
24+
import {ArrNode, ConNode, type ObjNode, type VecNode} from '../../../json-crdt/nodes';
2525
import {NestedType} from './NestedType';
2626
import type {ITimestampStruct} from '../../../json-crdt-patch/clock';
2727
import type {ArrChunk, JsonNode} from '../../../json-crdt/nodes';
28-
import type {
29-
MutableSlice,
30-
SliceView,
31-
SliceType,
32-
SliceUpdateParams,
33-
SliceTypeSteps,
34-
SliceTypeStep,
35-
} from './types';
28+
import type {MutableSlice, SliceView, SliceType, SliceUpdateParams, SliceTypeSteps, SliceTypeStep} from './types';
3629
import type {Stateful} from '../types';
3730
import type {Printable} from 'tree-dump/lib/types';
3831
import type {AbstractRga} from '../../../json-crdt/nodes/rga';
@@ -197,15 +190,13 @@ export class PersistedSlice<T = string> extends Range<T> implements MutableSlice
197190
type = api.view();
198191
if (!Array.isArray(type)) type = typeof type === 'number' || typeof type === 'string' ? [type] : [0];
199192
}
200-
this.tupleApi().set([
201-
[SliceTupleIndex.Type, schema.type(type as SliceTypeSteps)],
202-
]);
193+
this.tupleApi().set([[SliceTupleIndex.Type, schema.type(type as SliceTypeSteps)]]);
203194
return this.typeApi() as unknown as ArrApi;
204195
}
205196

206197
public typeStepAsVec(index?: number): VecApi {
207198
const arr = this.typeAsArr();
208-
let typeLen = arr.length();
199+
const typeLen = arr.length();
209200
if (typeof index !== 'number' || index > typeLen - 1) index = typeLen - 1;
210201
const vec = arr.get(index);
211202
if (vec instanceof VecApi) return vec;

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,7 @@ export class Slices<T = string> implements Stateful, Printable {
128128
const tuple = model.index.get(tupleId);
129129
if (!(tuple instanceof VecNode)) throw new Error('NOT_TUPLE');
130130
let slice = PersistedSlice.deserialize<T>(model, txt, chunk, tuple);
131-
if (slice.isSplit())
132-
slice = new MarkerSlice<T>(model, txt, chunk, tuple, slice.stacking, slice.start, slice.end);
131+
if (slice.isSplit()) slice = new MarkerSlice<T>(model, txt, chunk, tuple, slice.stacking, slice.start, slice.end);
133132
return slice;
134133
}
135134

0 commit comments

Comments
 (0)