Skip to content

Commit 98f56ec

Browse files
committed
style: 💄 fix linter issues
1 parent f59dac6 commit 98f56ec

File tree

7 files changed

+61
-69
lines changed

7 files changed

+61
-69
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import type {Point} from '../rga/Point';
1919
import type {Range} from '../rga/Range';
2020
import type {CharIterator, CharPredicate, Position, TextRangeUnit, ViewStyle, ViewRange, ViewSlice} from './types';
2121
import type {Printable} from 'tree-dump';
22-
import {MarkerSlice} from '../slice/MarkerSlice';
22+
import type {MarkerSlice} from '../slice/MarkerSlice';
2323

2424
/**
2525
* For inline boolean ("Overwrite") slices, both range endpoints should be

src/json-crdt-extensions/peritext/editor/__tests__/Editor-blocks.spec.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {Kit, runAlphabetKitTestSuite} from '../../__tests__/setup';
1+
import {type Kit, runAlphabetKitTestSuite} from '../../__tests__/setup';
22
import {SliceTypeCon} from '../../slice/constants';
33
import {create} from '../../transfer/create';
44

@@ -12,7 +12,9 @@ const runTests = (setup: () => Kit) => {
1212
peritext.refresh();
1313
const transfer = create(peritext);
1414
const html1 = transfer.toHtml(peritext.rangeAll()!);
15-
expect(html1).toBe('<p>abc</p><blockquote><p>def</p></blockquote><blockquote><p>ghijklmnopqrstuvwxyz</p></blockquote>');
15+
expect(html1).toBe(
16+
'<p>abc</p><blockquote><p>def</p></blockquote><blockquote><p>ghijklmnopqrstuvwxyz</p></blockquote>',
17+
);
1618
editor.cursor.setAt(10);
1719
editor.setBlockType(editor.cursor.start, [SliceTypeCon.blockquote, SliceTypeCon.p]);
1820
peritext.refresh();
@@ -34,7 +36,9 @@ const runTests = (setup: () => Kit) => {
3436
editor.setBlockType(point, [[SliceTypeCon.blockquote, 1], SliceTypeCon.p]);
3537
peritext.refresh();
3638
const html2 = transfer.toHtml(peritext.rangeAll()!);
37-
expect(html2).toBe('<p>abc</p><blockquote><p>def</p></blockquote><blockquote><p>ghijklmnopqrstuvwxyz</p></blockquote>');
39+
expect(html2).toBe(
40+
'<p>abc</p><blockquote><p>def</p></blockquote><blockquote><p>ghijklmnopqrstuvwxyz</p></blockquote>',
41+
);
3842
});
3943
};
4044

src/json-crdt-extensions/peritext/registry/SliceRegistry.ts

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {SliceBehavior, SliceTypeCon} from '../slice/constants';
1+
import {SliceBehavior, type SliceTypeCon} from '../slice/constants';
22
import {CommonSliceType} from '../slice';
33
import type {PeritextMlElement} from '../block/types';
44
import type {NodeBuilder} from '../../../json-crdt-patch';
@@ -14,22 +14,21 @@ export class SliceRegistryEntry<
1414
Tag extends TagType = TagType,
1515
Schema extends NodeBuilder = NodeBuilder,
1616
> {
17-
1817
public isInline(): boolean {
1918
return this.behavior !== SliceBehavior.Marker;
2019
}
21-
20+
2221
constructor(
2322
public readonly behavior: Behavior,
2423

2524
/**
2625
* The tag name of this slice. The tag is one step in the type path of the
2726
* slice. For example, below is a type path composed of three steps:
28-
*
27+
*
2928
* ```js
3029
* ['ul', 'li', 'p']
3130
* ```
32-
*
31+
*
3332
* Tag types are normally numbers of type {@link SliceTypeCon}, however,
3433
* they can also be any arbitrary strings or numbers.
3534
*/
@@ -47,34 +46,48 @@ export class SliceRegistryEntry<
4746
* For example, a `blockquote` is a container for `paragraph` elements,
4847
* however, a `paragraph` is not a container (it can only contain inline
4948
* elements).
50-
*
49+
*
5150
* If the marker slice is of the container sort, they tag can appear in the
5251
* path steps of the type:
53-
*
52+
*
5453
* ```
55-
*
54+
*
5655
* ```
5756
*/
5857
public readonly container: boolean = false,
59-
58+
6059
/**
6160
* Converts a node of this type to HTML representation: returns the HTML tag
6261
* and attributes. The method receives {@link PeritextMlElement} as an
6362
* argument, which is a tuple of internal HTML-like representation of the
6463
* node.
6564
*/
66-
public readonly toHtml: ToHtmlConverter<PeritextMlElement<Tag, JsonNodeView<SchemaToJsonNode<Schema>>, Behavior extends SliceBehavior.Marker ? false : true>> | undefined = void 0,
65+
public readonly toHtml:
66+
| ToHtmlConverter<
67+
PeritextMlElement<
68+
Tag,
69+
JsonNodeView<SchemaToJsonNode<Schema>>,
70+
Behavior extends SliceBehavior.Marker ? false : true
71+
>
72+
>
73+
| undefined = void 0,
6774

6875
/**
6976
* Specifies a mapping of converters from HTML {@link JsonMlElement} to
7077
* {@link PeritextMlElement}. This way a slice type can specify multiple
7178
* HTML tags that are converted to the same slice type.
72-
*
79+
*
7380
* For example, both, `<b>` and `<strong>` tags can be converted to the
7481
* {@link SliceTypeCon.b} slice type.
7582
*/
7683
public readonly fromHtml?: {
77-
[htmlTag: string]: FromHtmlConverter<PeritextMlElement<Tag, JsonNodeView<SchemaToJsonNode<Schema>>, Behavior extends SliceBehavior.Marker ? false : true>>;
84+
[htmlTag: string]: FromHtmlConverter<
85+
PeritextMlElement<
86+
Tag,
87+
JsonNodeView<SchemaToJsonNode<Schema>>,
88+
Behavior extends SliceBehavior.Marker ? false : true
89+
>
90+
>;
7891
},
7992
) {}
8093
}
@@ -85,8 +98,7 @@ export class SliceRegistryEntry<
8598
*/
8699
export class SliceRegistry {
87100
private map: Map<TagType, SliceRegistryEntry> = new Map();
88-
private _fromHtml: Map<string, [entry: SliceRegistryEntry, converter: FromHtmlConverter][]> =
89-
new Map();
101+
private _fromHtml: Map<string, [entry: SliceRegistryEntry, converter: FromHtmlConverter][]> = new Map();
90102

91103
public add(entry: SliceRegistryEntry<any, any, any>): void {
92104
const {tag, fromHtml} = entry;
@@ -100,8 +112,7 @@ export class SliceRegistry {
100112
}
101113
}
102114
const tagStr = CommonSliceType[tag as SliceTypeCon];
103-
if (tagStr && typeof tagStr === 'string')
104-
_fromHtml.set(tagStr, [[entry, () => [tag, null]]]);
115+
if (tagStr && typeof tagStr === 'string') _fromHtml.set(tagStr, [[entry, () => [tag, null]]]);
105116
}
106117

107118
public toHtml(el: PeritextMlElement): ReturnType<ToHtmlConverter<any>> | undefined {

src/json-crdt-extensions/peritext/registry/registry.ts

Lines changed: 21 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import {s} from '../../../json-crdt-patch';
22
import {SliceBehavior, SliceTypeCon as TAG} from '../slice/constants';
3-
import {SliceRegistry, SliceRegistryEntry, TagType} from './SliceRegistry';
3+
import {SliceRegistry, SliceRegistryEntry, type TagType} from './SliceRegistry';
44
import type {JsonNodeView} from '../../../json-crdt/nodes';
55
import type {SchemaToJsonNode} from '../../../json-crdt/schema/types';
66
import type {PeritextMlElement} from '../block/types';
77

88
/**
99
* Default annotation type registry.
10-
*/
10+
*/
1111
export const registry = new SliceRegistry();
1212

1313
const undefSchema = s.con(undefined);
@@ -18,16 +18,7 @@ const i0 = <Tag extends TagType = TagType>(
1818
tag: Tag,
1919
fromHtml?: SliceRegistryEntry<SliceBehavior.One, Tag, typeof undefSchema>['fromHtml'],
2020
): void => {
21-
registry.add(
22-
new SliceRegistryEntry(
23-
SliceBehavior.One,
24-
tag,
25-
undefSchema,
26-
false,
27-
void 0,
28-
fromHtml,
29-
)
30-
);
21+
registry.add(new SliceRegistryEntry(SliceBehavior.One, tag, undefSchema, false, void 0, fromHtml));
3122
};
3223

3324
const i1 = <Tag extends TagType = TagType>(tag: Tag, htmlTags: string[]): void => {
@@ -56,23 +47,16 @@ const aSchema = s.obj({
5647
title: s.str<string>(''),
5748
});
5849
registry.add(
59-
new SliceRegistryEntry(
60-
SliceBehavior.Many,
61-
TAG.a,
62-
aSchema,
63-
false,
64-
void 0,
65-
{
66-
a: (jsonml) => {
67-
const attr = jsonml[1] || {};
68-
const data: JsonNodeView<SchemaToJsonNode<typeof aSchema>> = {
69-
href: attr.href ?? '',
70-
title: attr.title ?? '',
71-
};
72-
return [TAG.a, {data, inline: true}] as PeritextMlElement<TAG.a, any, true>;
73-
},
50+
new SliceRegistryEntry(SliceBehavior.Many, TAG.a, aSchema, false, void 0, {
51+
a: (jsonml) => {
52+
const attr = jsonml[1] || {};
53+
const data: JsonNodeView<SchemaToJsonNode<typeof aSchema>> = {
54+
href: attr.href ?? '',
55+
title: attr.title ?? '',
56+
};
57+
return [TAG.a, {data, inline: true}] as PeritextMlElement<TAG.a, any, true>;
7458
},
75-
)
59+
}),
7660
);
7761

7862
// TODO: add more default annotations with "Many" behavior
@@ -89,23 +73,16 @@ registry.add(
8973

9074
// --------------------------------------- Block elements with "Marker" behavior
9175

92-
const commonBlockSchema = s.obj({}, {
93-
indent: s.con(0),
94-
align: s.str<'left' | 'center' | 'right' | 'justify'>('left'),
95-
});
76+
const commonBlockSchema = s.obj(
77+
{},
78+
{
79+
indent: s.con(0),
80+
align: s.str<'left' | 'center' | 'right' | 'justify'>('left'),
81+
},
82+
);
9683

97-
const b0 = <Tag extends TagType = TagType>(
98-
tag: Tag,
99-
container: boolean,
100-
) => {
101-
registry.add(
102-
new SliceRegistryEntry(
103-
SliceBehavior.Marker,
104-
tag,
105-
commonBlockSchema,
106-
container,
107-
)
108-
);
84+
const b0 = <Tag extends TagType = TagType>(tag: Tag, container: boolean) => {
85+
registry.add(new SliceRegistryEntry(SliceBehavior.Marker, tag, commonBlockSchema, container));
10986
};
11087

11188
b0(TAG.p, false);

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ import type {Anchor} from '../rga/constants';
3333
* [2]
3434
* [3, 4]
3535
* ```
36-
*
36+
*
3737
* Block split with discriminant, to differentiate between two adjacent blocks:
38-
*
38+
*
3939
* ```ts
4040
* [['<blockquote>', 0], '<p>']
4141
* [['<blockquote>', 1], '<p>']

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,5 +40,5 @@ export const formatType = (step: SliceTypeStep): string => {
4040
tag = step;
4141
}
4242
if (typeof tag === 'number' && Math.abs(tag) <= 64 && SliceTypeName[tag]) tag = SliceTypeName[tag] ?? tag;
43-
return '<' + tag + (discriminant >= 0 ? (':' + discriminant) : '') + '>';
43+
return '<' + tag + (discriminant >= 0 ? ':' + discriminant : '') + '>';
4444
};

src/json-crdt-extensions/peritext/util/commonLength.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ export const commonLength = (a: SliceTypeSteps, b: SliceTypeSteps): number => {
1010
const aTag = Array.isArray(aStep) ? aStep[0] : aStep;
1111
const bTag = Array.isArray(bStep) ? bStep[0] : bStep;
1212
if (aTag !== bTag) break;
13-
let aDiscriminant = Array.isArray(aStep) ? aStep[1] : 0;
14-
let bDiscriminant = Array.isArray(bStep) ? bStep[0] : 0;
13+
const aDiscriminant = Array.isArray(aStep) ? aStep[1] : 0;
14+
const bDiscriminant = Array.isArray(bStep) ? bStep[0] : 0;
1515
if (aDiscriminant !== bDiscriminant) break;
1616
i++;
1717
}

0 commit comments

Comments
 (0)