Skip to content

Commit 0820643

Browse files
committed
style(json-crdt-extensions): 💄 fix linter issues
1 parent ce95148 commit 0820643

File tree

9 files changed

+81
-63
lines changed

9 files changed

+81
-63
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {SliceBehavior} from '../slice/constants';
1+
import type {SliceBehavior} from '../slice/constants';
22

33
export type PeritextMlNode = string | PeritextMlElement;
44

src/json-crdt-extensions/peritext/lazy/__tests__/import-export-html.spec.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,5 @@ test('a single paragraph', () => {
1010
peritext.editor.import(0, rangeView);
1111
peritext.refresh();
1212
const json = peritext.blocks.toJson();
13-
expect(json).toEqual(['', null,
14-
[CommonSliceType.p, null, 'Hello world'],
15-
]);
13+
expect(json).toEqual(['', null, [CommonSliceType.p, null, 'Hello world']]);
1614
});

src/json-crdt-extensions/peritext/lazy/__tests__/import-html.spec.ts

Lines changed: 38 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,13 @@ describe('.fromHtml()', () => {
77
test('a single paragraph', () => {
88
const html = '<p>Hello world</p>';
99
const peritextMl = fromHtml(html);
10-
expect(peritextMl).toEqual([
11-
'',
12-
null,
13-
[CommonSliceType.p, null, 'Hello world'],
14-
]);
10+
expect(peritextMl).toEqual(['', null, [CommonSliceType.p, null, 'Hello world']]);
1511
});
1612

1713
test('a paragraph with trailing text', () => {
1814
const html = '<p>Hello world</p> more text';
1915
const peritextMl = fromHtml(html);
20-
expect(peritextMl).toEqual([
21-
'',
22-
null,
23-
[CommonSliceType.p, null, 'Hello world'],
24-
' more text',
25-
]);
16+
expect(peritextMl).toEqual(['', null, [CommonSliceType.p, null, 'Hello world'], ' more text']);
2617
});
2718

2819
test('text formatted as italic', () => {
@@ -33,10 +24,12 @@ describe('.fromHtml()', () => {
3324
null,
3425
[CommonSliceType.p, null, 'Hello world'],
3526
'\n',
36-
[CommonSliceType.p, null,
37-
[CommonSliceType.i, {behavior: SliceBehavior.One, inline:true}, 'italic'],
27+
[
28+
CommonSliceType.p,
29+
null,
30+
[CommonSliceType.i, {behavior: SliceBehavior.One, inline: true}, 'italic'],
3831
' text, ',
39-
[CommonSliceType.i, {behavior: SliceBehavior.One, inline:true}, 'more italic'],
32+
[CommonSliceType.i, {behavior: SliceBehavior.One, inline: true}, 'more italic'],
4033
],
4134
]);
4235
});
@@ -61,31 +54,47 @@ describe('.toViewRange()', () => {
6154
const html = '<p>Hello world</p><p>Goodbye world</p>';
6255
const peritextMl = fromHtml(html);
6356
const view = toViewRange(peritextMl);
64-
expect(view).toEqual(['\nHello world\nGoodbye world', 0, [
65-
[0, 0, 0, 0],
66-
[0, 12, 12, 0],
67-
]]);
57+
expect(view).toEqual([
58+
'\nHello world\nGoodbye world',
59+
0,
60+
[
61+
[0, 0, 0, 0],
62+
[0, 12, 12, 0],
63+
],
64+
]);
6865
});
6966

7067
test('two paragraphs with whitespace gap', () => {
7168
const html = ' <p>Hello world</p>\n <p>Goodbye world</p>';
7269
const peritextMl = fromHtml(html);
7370
const view = toViewRange(peritextMl);
74-
expect(view).toEqual(['\nHello world\nGoodbye world', 0, [
75-
[0, 0, 0, 0],
76-
[0, 12, 12, 0],
77-
]]);
71+
expect(view).toEqual([
72+
'\nHello world\nGoodbye world',
73+
0,
74+
[
75+
[0, 0, 0, 0],
76+
[0, 12, 12, 0],
77+
],
78+
]);
7879
});
7980

8081
test('single inline annotation', () => {
8182
const html = 'here is some <em>italic</em> text';
8283
const peritextMl = fromHtml(html);
8384
const view = toViewRange(peritextMl);
84-
expect(view).toEqual(['here is some italic text', 0, [
85-
[(SliceBehavior.One << SliceHeaderShift.Behavior) +
86-
(Anchor.Before << SliceHeaderShift.X1Anchor) +
87-
(Anchor.After << SliceHeaderShift.X2Anchor),
88-
13, 19, CommonSliceType.i],
89-
]]);
85+
expect(view).toEqual([
86+
'here is some italic text',
87+
0,
88+
[
89+
[
90+
(SliceBehavior.One << SliceHeaderShift.Behavior) +
91+
(Anchor.Before << SliceHeaderShift.X1Anchor) +
92+
(Anchor.After << SliceHeaderShift.X2Anchor),
93+
13,
94+
19,
95+
CommonSliceType.i,
96+
],
97+
],
98+
]);
9099
});
91-
});
100+
});

src/json-crdt-extensions/peritext/lazy/import-html.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class ViewRangeBuilder {
1818
private text = '';
1919
private slices: ViewSlice[] = [];
2020

21-
constructor (private registry: SliceRegistry) {}
21+
constructor(private registry: SliceRegistry) {}
2222

2323
private build0(node: PeritextMlNode, depth = 0): void {
2424
const skipWhitespace = depth < 2;
@@ -32,7 +32,8 @@ class ViewRangeBuilder {
3232
const length = node.length;
3333
const inline = !!attr?.inline;
3434
if (!!type || type === 0) {
35-
let end: number = 0, header: number = 0;
35+
let end: number = 0,
36+
header: number = 0;
3637
if (!inline) {
3738
this.text += '\n';
3839
end = start;
@@ -48,18 +49,19 @@ class ViewRangeBuilder {
4849
}
4950
for (let i = 2; i < length; i++) this.build0(node[i] as PeritextMlNode, depth + 1);
5051
if (!!type || type === 0) {
51-
let end: number = 0, header: number = 0;
52+
let end: number = 0,
53+
header: number = 0;
5254
if (inline) {
5355
end = this.text.length;
5456
const behavior: SliceBehavior = attr?.behavior ?? SliceBehavior.Many;
5557
header =
5658
(behavior << SliceHeaderShift.Behavior) +
5759
(Anchor.Before << SliceHeaderShift.X1Anchor) +
5860
(Anchor.After << SliceHeaderShift.X2Anchor);
59-
const slice: ViewSlice = [header, start, end, type];
60-
const data = attr?.data;
61-
if (data) slice.push(data);
62-
this.slices.push(slice);
61+
const slice: ViewSlice = [header, start, end, type];
62+
const data = attr?.data;
63+
if (data) slice.push(data);
64+
this.slices.push(slice);
6365
}
6466
}
6567
}
@@ -102,7 +104,7 @@ export const fromJsonMl = (jsonml: JsonMlNode, registry: SliceRegistry = default
102104
node[1] = attr;
103105
}
104106
return node;
105-
}
107+
};
106108

107109
export const fromHast = (hast: THtmlToken, registry?: SliceRegistry): PeritextMlNode => {
108110
const jsonml = _fromHast(hast);

src/json-crdt-extensions/peritext/lazy/import-markdown.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,5 @@ export const fromMdast = (mdast: IRoot, registry: SliceRegistry = defaultRegistr
1515

1616
export const fromMarkdown = (markdown: string, registry?: SliceRegistry): PeritextMlNode => {
1717
const mdast = block.parsef(markdown);
18-
return fromMdast(mdast, registry);
18+
return fromMdast(mdast, registry);
1919
};

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

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
1-
import {PeritextMlElement} from '../block/types';
2-
import {NodeBuilder} from '../../../json-crdt-patch';
1+
import type {PeritextMlElement} from '../block/types';
2+
import type {NodeBuilder} from '../../../json-crdt-patch';
33
import {SliceBehavior} from '../slice/constants';
44
import type {JsonMlElement} from 'very-small-parser/lib/html/json-ml/types';
55
import type {FromHtmlConverter, SliceTypeDefinition, ToHtmlConverter} from './types';
66

77
export class SliceRegistry {
88
private map: Map<string | number, SliceTypeDefinition<any, any, any>> = new Map();
99
private toHtmlMap: Map<string | number, ToHtmlConverter<any>> = new Map();
10-
private fromHtmlMap: Map<string, [def: SliceTypeDefinition<any, any, any>, converter: FromHtmlConverter][]> = new Map();
10+
private fromHtmlMap: Map<string, [def: SliceTypeDefinition<any, any, any>, converter: FromHtmlConverter][]> =
11+
new Map();
1112

12-
public add<Type extends number | string, Schema extends NodeBuilder, Inline extends boolean = true>(def: SliceTypeDefinition<Type, Schema, Inline>): void {
13+
public add<Type extends number | string, Schema extends NodeBuilder, Inline extends boolean = true>(
14+
def: SliceTypeDefinition<Type, Schema, Inline>,
15+
): void {
1316
const {type, toHtml, fromHtml} = def;
1417
this.map.set(type, def);
1518
if (toHtml) this.toHtmlMap.set(type, toHtml);
@@ -47,7 +50,7 @@ export class SliceRegistry {
4750
const result = converter(el);
4851
if (result) {
4952
const attr = result[1] ?? (result[1] = {});
50-
attr.inline = def.inline ?? (def.type < 0);
53+
attr.inline = def.inline ?? def.type < 0;
5154
attr.behavior = !attr.inline ? SliceBehavior.Marker : (def.behavior ?? SliceBehavior.Many);
5255
return result;
5356
}

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import {s} from "../../../json-crdt-patch";
2-
import {JsonNodeView} from "../../../json-crdt/nodes";
3-
import {SchemaToJsonNode} from "../../../json-crdt/schema/types";
4-
import {CommonSliceType} from "../slice";
1+
import {s} from '../../../json-crdt-patch';
2+
import type {JsonNodeView} from '../../../json-crdt/nodes';
3+
import type {SchemaToJsonNode} from '../../../json-crdt/schema/types';
4+
import {CommonSliceType} from '../slice';
55
import {SliceBehavior} from '../slice/constants';
6-
import {SliceRegistry} from "./SliceRegistry";
6+
import {SliceRegistry} from './SliceRegistry';
77

88
const undefSchema = s.con(undefined);
99

@@ -56,12 +56,12 @@ registry.def(CommonSliceType.a, aSchema, SliceBehavior.Many, true, {
5656
title: attr.title ?? '',
5757
};
5858
return [CommonSliceType.a, {data, inline: true}];
59-
}
59+
},
6060
},
6161
});
6262

6363
// TODO: add more default annotations
64-
// comment = SliceTypeCon.comment,
64+
// comment = SliceTypeCon.comment,
6565
// font = SliceTypeCon.font,
6666
// col = SliceTypeCon.col,
6767
// bg = SliceTypeCon.bg,

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

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@ import type {PeritextMlElement} from '../block/types';
55
import type {JsonMlElement} from 'very-small-parser/lib/html/json-ml/types';
66
import type {SliceBehavior} from '../slice/constants';
77

8-
export interface SliceTypeDefinition<Type extends number | string = number | string, Schema extends NodeBuilder = NodeBuilder, Inline extends boolean = true> {
8+
export interface SliceTypeDefinition<
9+
Type extends number | string = number | string,
10+
Schema extends NodeBuilder = NodeBuilder,
11+
Inline extends boolean = true,
12+
> {
913
type: Type;
1014
schema: Schema;
1115
behavior?: SliceBehavior;
@@ -16,8 +20,10 @@ export interface SliceTypeDefinition<Type extends number | string = number | str
1620
};
1721
}
1822

19-
export type ToHtmlConverter<El extends PeritextMlElement<any, any, any> = PeritextMlElement<string | number, unknown, boolean>> =
20-
(element: El) => [tag: string, attr: Record<string, string> | null];
23+
export type ToHtmlConverter<
24+
El extends PeritextMlElement<any, any, any> = PeritextMlElement<string | number, unknown, boolean>,
25+
> = (element: El) => [tag: string, attr: Record<string, string> | null];
2126

22-
export type FromHtmlConverter<El extends PeritextMlElement<any, any, any> = PeritextMlElement<string | number, unknown, boolean>> =
23-
(jsonml: JsonMlElement) => El;
27+
export type FromHtmlConverter<
28+
El extends PeritextMlElement<any, any, any> = PeritextMlElement<string | number, unknown, boolean>,
29+
> = (jsonml: JsonMlElement) => El;

src/json-crdt-patch/builder/schema.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -132,9 +132,9 @@ export namespace nodes {
132132
* age: s.con(0),
133133
* });
134134
* ```
135-
*
135+
*
136136
* Specify optional keys as the second argument:
137-
*
137+
*
138138
* ```ts
139139
* s.obj(
140140
* {
@@ -145,9 +145,9 @@ export namespace nodes {
145145
* },
146146
* )
147147
* ```
148-
*
148+
*
149149
* Or, specify only the type, using the `optional` method:
150-
*
150+
*
151151
* ```ts
152152
* s.obj({
153153
* href: s.str('https://example.com'),

0 commit comments

Comments
 (0)