Skip to content

Commit 227f3fe

Browse files
committed
style: 💄 run formatter
1 parent 9378426 commit 227f3fe

File tree

13 files changed

+146
-68
lines changed

13 files changed

+146
-68
lines changed

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

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -630,7 +630,10 @@ export class Editor<T = string> implements Printable {
630630

631631
// --------------------------------------------------------------- formatting
632632

633-
public eraseFormatting(store: EditorSlices<T> = this.saved, selection: Range<T>[] | IterableIterator<Range<T>> = this.cursors()): void {
633+
public eraseFormatting(
634+
store: EditorSlices<T> = this.saved,
635+
selection: Range<T>[] | IterableIterator<Range<T>> = this.cursors(),
636+
): void {
634637
const overlay = this.txt.overlay;
635638
for (const range of selection) {
636639
overlay.refresh();
@@ -658,7 +661,10 @@ export class Editor<T = string> implements Printable {
658661
}
659662
}
660663

661-
public clearFormatting(store: EditorSlices<T> = this.saved, selection: Range<T>[] | IterableIterator<Range<T>> = this.cursors()): void {
664+
public clearFormatting(
665+
store: EditorSlices<T> = this.saved,
666+
selection: Range<T>[] | IterableIterator<Range<T>> = this.cursors(),
667+
): void {
662668
const overlay = this.txt.overlay;
663669
overlay.refresh();
664670
for (const range of selection) {
@@ -853,7 +859,12 @@ export class Editor<T = string> implements Printable {
853859
return true;
854860
}
855861

856-
public split(type?: SliceType, data?: unknown, selection: Range<T>[] | IterableIterator<Range<T>> = this.cursors(), slices: EditorSlices<T> = this.saved): void {
862+
public split(
863+
type?: SliceType,
864+
data?: unknown,
865+
selection: Range<T>[] | IterableIterator<Range<T>> = this.cursors(),
866+
slices: EditorSlices<T> = this.saved,
867+
): void {
857868
if (type === void 0) {
858869
for (const range of selection) {
859870
this.collapseCursor(range);
@@ -924,8 +935,7 @@ export class Editor<T = string> implements Printable {
924935
slices: EditorSlices<T> = this.saved,
925936
def: SliceTypeStep = SliceTypeCon.p,
926937
): void {
927-
for (const range of selection)
928-
this.tglMarkerAt(range.start, type, data, slices, def);
938+
for (const range of selection) this.tglMarkerAt(range.start, type, data, slices, def);
929939
}
930940

931941
/**
@@ -936,9 +946,13 @@ export class Editor<T = string> implements Printable {
936946
* @param slices The slices set to use, if new marker is inserted at the start
937947
* of the document.
938948
*/
939-
public updMarker(type: SliceType, data?: unknown, selection: Range<T>[] | IterableIterator<Range<T>> = this.cursors(), slices: EditorSlices<T> = this.saved): void {
940-
for (const range of selection)
941-
this.updMarkerAt(range.start, type, data, slices);
949+
public updMarker(
950+
type: SliceType,
951+
data?: unknown,
952+
selection: Range<T>[] | IterableIterator<Range<T>> = this.cursors(),
953+
slices: EditorSlices<T> = this.saved,
954+
): void {
955+
for (const range of selection) this.updMarkerAt(range.start, type, data, slices);
942956
}
943957

944958
public delMarker(selection: Range<T>[] | IterableIterator<Range<T>> = this.cursors()): void {

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

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@ import type {Slices} from '../slice/Slices';
66
import type {ITimestampStruct} from '../../../json-crdt-patch';
77
import type {Range} from '../rga/Range';
88

9-
const forEachRange = <T, S extends PersistedSlice<T>>(selection: Range<T>[] | IterableIterator<Range<T>>, callback: (range: Range<T>) => S): S[] => {
9+
const forEachRange = <T, S extends PersistedSlice<T>>(
10+
selection: Range<T>[] | IterableIterator<Range<T>>,
11+
callback: (range: Range<T>) => S,
12+
): S[] => {
1013
const slices: S[] = [];
1114
for (const cursor of selection) {
1215
const slice = callback(cursor);
@@ -21,25 +24,42 @@ export class EditorSlices<T = string> {
2124
public readonly slices: Slices<T>,
2225
) {}
2326

24-
public insStack(type: SliceType, data?: unknown | ITimestampStruct, selection?: Range<T>[] | IterableIterator<Range<T>>): PersistedSlice<T>[] {
27+
public insStack(
28+
type: SliceType,
29+
data?: unknown | ITimestampStruct,
30+
selection?: Range<T>[] | IterableIterator<Range<T>>,
31+
): PersistedSlice<T>[] {
2532
const {slices, txt} = this;
2633
selection ||= txt.editor.cursors();
2734
return forEachRange(selection, (range) => slices.insStack(range.range(), type, data));
2835
}
2936

30-
public insOne(type: SliceType, data?: unknown | ITimestampStruct, selection?: Range<T>[] | IterableIterator<Range<T>>): PersistedSlice<T>[] {
37+
public insOne(
38+
type: SliceType,
39+
data?: unknown | ITimestampStruct,
40+
selection?: Range<T>[] | IterableIterator<Range<T>>,
41+
): PersistedSlice<T>[] {
3142
const {slices, txt} = this;
3243
selection ||= txt.editor.cursors();
3344
return forEachRange(selection, (range) => slices.insOne(range.range(), type, data));
3445
}
3546

36-
public insErase(type: SliceType, data?: unknown | ITimestampStruct, selection?: Range<T>[] | IterableIterator<Range<T>>): PersistedSlice<T>[] {
47+
public insErase(
48+
type: SliceType,
49+
data?: unknown | ITimestampStruct,
50+
selection?: Range<T>[] | IterableIterator<Range<T>>,
51+
): PersistedSlice<T>[] {
3752
const {slices, txt} = this;
3853
selection ||= txt.editor.cursors();
3954
return forEachRange(selection, (range) => slices.insErase(range.range(), type, data));
4055
}
4156

42-
public insMarker(type: SliceType, data?: unknown, separator?: string, selection?: Range<T>[] | IterableIterator<Range<T>>): MarkerSlice<T>[] {
57+
public insMarker(
58+
type: SliceType,
59+
data?: unknown,
60+
separator?: string,
61+
selection?: Range<T>[] | IterableIterator<Range<T>>,
62+
): MarkerSlice<T>[] {
4363
const {slices, txt} = this;
4464
const editor = txt.editor;
4565
selection ||= txt.editor.cursors();

src/json-crdt-peritext-ui/__demos__/components/App.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const markdown =
1919
'This is code block:' +
2020
'\n\n' +
2121
'```\n' +
22-
'console.log(123);\n' +
22+
'console.log(123);\n' +
2323
'```\n' +
2424
'\n\n' +
2525
'A `ClipboardEvent` is dispatched for copy, cut, and paste events, and it contains ' +

src/json-crdt-peritext-ui/events/PeritextEventTarget.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ export class PeritextEventTarget extends SubscriptionEventTarget<PeritextEventMa
4848
edge: SelectionMoveInstruction[0],
4949
unit: SelectionMoveInstruction[1],
5050
len?: SelectionMoveInstruction[2],
51-
collapse?: SelectionMoveInstruction[3]
51+
collapse?: SelectionMoveInstruction[3],
5252
): void;
5353
public delete(detail?: DeleteDetail): void;
5454
public delete(a: any = {}, b?: any, len?: any, collapse?: any): void {
@@ -68,7 +68,7 @@ export class PeritextEventTarget extends SubscriptionEventTarget<PeritextEventMa
6868
edge: SelectionMoveInstruction[0],
6969
unit: SelectionMoveInstruction[1],
7070
len?: SelectionMoveInstruction[2],
71-
collapse?: SelectionMoveInstruction[3]
71+
collapse?: SelectionMoveInstruction[3],
7272
): void;
7373
public move(move?: CursorDetail['move'], at?: CursorDetail['at']): void;
7474
public move(a?: any, b?: any, len?: any, collapse?: any): void {

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

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,12 @@ const getEdge = (start: Point, end: Point, anchor: CursorAnchor, edge: events.Se
2121
: edge === 'end'
2222
? end
2323
: edge === 'focus'
24-
? anchor === CursorAnchor.Start ? end : start
25-
: anchor === CursorAnchor.Start ? start : end;
24+
? anchor === CursorAnchor.Start
25+
? end
26+
: start
27+
: anchor === CursorAnchor.Start
28+
? start
29+
: end;
2630

2731
export interface PeritextEventDefaultsOpts {
2832
clipboard?: PeritextClipboard;
@@ -89,13 +93,18 @@ export class PeritextEventDefaults implements PeritextEventHandlerMap {
8993
let anchor: CursorAnchor = selection instanceof Cursor ? selection.anchorSide : CursorAnchor.End;
9094
for (const [edge, to, len, collapse] of move) {
9195
const point = getEdge(start, end, anchor, edge);
92-
const point2 = typeof to === 'string'
93-
? (len ? txt.editor.skip(point, len, to ?? 'char', editorUi) : point.clone())
94-
: txt.editor.pos2point(to);
95-
if (point === start) start = point2; else end = point2;
96+
const point2 =
97+
typeof to === 'string'
98+
? len
99+
? txt.editor.skip(point, len, to ?? 'char', editorUi)
100+
: point.clone()
101+
: txt.editor.pos2point(to);
102+
if (point === start) start = point2;
103+
else end = point2;
96104
if (collapse) {
97105
if (to !== 'point') point2.refAfter();
98-
if (point === start) end = point2.clone(); else start = point2.clone();
106+
if (point === start) end = point2.clone();
107+
else start = point2.clone();
99108
}
100109
}
101110
if (start.cmpSpatial(end) > 0) {
@@ -408,10 +417,11 @@ export class PeritextEventDefaults implements PeritextEventHandlerMap {
408417
}
409418
if (!data) data = await clipboard.readData();
410419
const inserted = transfer.fromClipboard(range, data);
411-
if (inserted && editor.cursorCard() === 1) this.et.move([
412-
['start', 'char', inserted],
413-
['end', 'char', inserted],
414-
]);
420+
if (inserted && editor.cursorCard() === 1)
421+
this.et.move([
422+
['start', 'char', inserted],
423+
['end', 'char', inserted],
424+
]);
415425
this.et.change();
416426
}
417427
}

src/json-crdt-peritext-ui/events/types.ts

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export interface ChangeDetail {
1515
/**
1616
* The {@link SelectionDetailPart} interface allows to specify a range of text
1717
* selection or a single caret position in the document.
18-
*
18+
*
1919
* If the `at` field is specified, the selection set will contain one selection,
2020
* the one created at the specified position. If the `at` field is not specified,
2121
* the selection set will contain all cursors in the document at their current
@@ -27,11 +27,11 @@ export interface SelectionDetailPart {
2727
* operation is applied over all cursors in the document at their current
2828
* positions. Or if operation is specified only for one cursor, it will be
2929
* applied to the first (main) cursor.
30-
*
30+
*
3131
* If specified, a new temporary selection is created which is used to perform
3232
* the operation on. Then, if specified, this selection is used to create a
3333
* new main cursor, while all other cursors are removed.
34-
*
34+
*
3535
* @default undefined
3636
*/
3737
at?: Selection;
@@ -57,7 +57,7 @@ export interface SelectionMoveDetailPart {
5757
export type SelectionMoveInstruction = [
5858
/**
5959
* Specifies the selection edge to perform the operation on.
60-
*
60+
*
6161
* - `'start'`: The start edge of the selection.
6262
* - `'end'`: The end edge of the selection.
6363
* - `'focus'`: The focus edge of the selection. If the selection does not have
@@ -66,11 +66,10 @@ export type SelectionMoveInstruction = [
6666
* - `'anchor'`: The anchor edge of the selection. If the selection does not
6767
* have an anchor edge (i.e. it is a {@link Range}, not a {@link Cursor}), the
6868
* anchor is assumed to be the `'start'` edge of the selection.
69-
*
69+
*
7070
* @default 'focus'
7171
*/
7272
edge: 'start' | 'end' | 'focus' | 'anchor',
73-
7473
/**
7574
* Absolute position is specified using {@link Position} type. In which case
7675
* the next `len` field is ignored.
@@ -94,21 +93,19 @@ export type SelectionMoveInstruction = [
9493
* - `'block'`: Moves to the beginning or end of block, i.e. paragraph,
9594
* blockquote, etc.
9695
* - `'all'`: Moves to the beginning or end of the document.
97-
*
96+
*
9897
* @todo Introduce 'vline', "visual line" - soft line break.
9998
*/
10099
to: Position | 'point' | 'char' | 'word' | 'line' | 'vline' | 'vert' | 'block' | 'all',
101-
102100
/**
103101
* Specify the length of the movement (the number of steps) in units
104102
* specified by the `to` field. If not specified, the default value is `0`,
105103
* which results in no movement. If the value is negative, the movement will
106104
* be backwards. If positive, the movement will be forwards.
107-
*
105+
*
108106
* @default 0
109107
*/
110108
len?: number,
111-
112109
/**
113110
* If `true`, the selection will be collapsed to a single point. The other
114111
* edge of the selection will be moved to the same position as the specified
@@ -122,11 +119,11 @@ export type SelectionMoveInstruction = [
122119
* which apply change to a range (selection) of text in the document. Usually,
123120
* the events will apply changes to all ranges in the selection, some event may
124121
* use only the first range in the selection (like the "buffer" event).
125-
*
122+
*
126123
* Selection-based events work by first constructing a *selection set*, which
127124
* is a list of {@link Range} or {@link Cursor} instances. They then apply the
128125
* event to each selection in the selection set.
129-
*
126+
*
130127
* The selection set is constructed by using the `at` field to specify a single
131128
* {@link Range} or, if not specified, all {@link Cursor} instances in the
132129
* document are used. Then the `move` field is used to specify one or more move
@@ -155,7 +152,7 @@ export interface DeleteDetail extends RangeEventDetail {}
155152
* The `cursor` event is emitted when caret or selection is changed. The event
156153
* is applied to all cursors in the document. If the `at` field is specified,
157154
* a new cursor is created at that position, and all other cursors are removed.
158-
*
155+
*
159156
* The `at` field allows to insert a new cursors at a specified location in the
160157
* document and remove all other cursors. The `move` fields allows to perform
161158
* one or more move operations to all cursors in the document.
@@ -197,10 +194,10 @@ export interface DeleteDetail extends RangeEventDetail {}
197194
* ```ts
198195
* {move: [['anchor', 'line', -1]]}
199196
* ```
200-
*
197+
*
201198
* Move *anchor* edge of the selection exactly to after the second character in
202199
* the document:
203-
*
200+
*
204201
* ```ts
205202
* {move: [['anchor', 2]]}
206203
* ```
@@ -216,9 +213,9 @@ export interface DeleteDetail extends RangeEventDetail {}
216213
* ```ts
217214
* {at: [0], move: [['focus', 'all', 1]]}
218215
* ```
219-
*
216+
*
220217
* or
221-
*
218+
*
222219
* ```ts
223220
* {move: [
224221
* ['start', 'all', -1],
@@ -240,7 +237,7 @@ export interface CursorDetail extends RangeEventDetail {
240237
* a new cursor will be inserted at the specified position into the document.
241238
* Otherwise, the selection specified by the `at` field will be used to
242239
* replace all other cursors in the document.
243-
*
240+
*
244241
* @default false
245242
*/
246243
add?: boolean;

src/json-crdt-peritext-ui/plugins/blocks/RenderBlock/Codeblock.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,9 @@ export interface CodeblockProps extends BlockViewProps {
1919
}
2020

2121
export const Codeblock: React.FC<CodeblockProps> = ({block, children}) => {
22-
return <pre className={blockClass}><code>{children}</code></pre>;
22+
return (
23+
<pre className={blockClass}>
24+
<code>{children}</code>
25+
</pre>
26+
);
2327
};

src/json-crdt-peritext-ui/plugins/toolbar/block/LeafBlockFrame/AutoExpandableToolbar.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,12 @@ export interface AutoExpandableToolbarProps extends ExpandableToolbarProps {
99
onPopupClose?: () => void;
1010
}
1111

12-
export const AutoExpandableToolbar: React.FC<AutoExpandableToolbarProps> = ({menu, disabled, onPopupClose, ...rest}) => {
12+
export const AutoExpandableToolbar: React.FC<AutoExpandableToolbarProps> = ({
13+
menu,
14+
disabled,
15+
onPopupClose,
16+
...rest
17+
}) => {
1318
const expandPoint = React.useRef<AnchorPoint>({x: 32, y: 32, dx: 1, dy: 1});
1419

1520
return (

src/json-crdt-peritext-ui/plugins/toolbar/block/LeafBlockFrame/ExpandableToolbar.tsx

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,17 @@ export const ExpandableToolbar: React.FC<ExpandableToolbarProps> = (props) => {
4646
);
4747
}
4848

49-
return <ToolbarMenu {...rest} more={{...more, onClick: expandPoint ? (e) => {
50-
setView('context');
51-
} : undefined}} />;
49+
return (
50+
<ToolbarMenu
51+
{...rest}
52+
more={{
53+
...more,
54+
onClick: expandPoint
55+
? (e) => {
56+
setView('context');
57+
}
58+
: undefined,
59+
}}
60+
/>
61+
);
5262
};

src/json-crdt-peritext-ui/plugins/toolbar/block/LeafBlockFrame/index.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,14 @@ const topRightOverlay = rule({
2525
r: '-16px',
2626
});
2727

28-
export interface LeafBlockFrameProps extends RenderBlockProps {
29-
}
28+
export interface LeafBlockFrameProps extends RenderBlockProps {}
3029

3130
export const LeafBlockFrame: React.FC<LeafBlockFrameProps> = ({block, children}) => {
3231
const {toolbar} = useToolbarPlugin();
3332
const activeLeafBlockId = useBehaviorSubject(toolbar.activeLeafBlockId$);
3433
const menu = React.useMemo(() => toolbar.leafBlockSmallMenu({block}), [toolbar, block]);
3534

36-
const isBlockActive = !!activeLeafBlockId && (compare(activeLeafBlockId, block.marker?.id ?? block.txt.str.id) === 0);
35+
const isBlockActive = !!activeLeafBlockId && compare(activeLeafBlockId, block.marker?.id ?? block.txt.str.id) === 0;
3736

3837
return (
3938
<div className={blockClass}>

0 commit comments

Comments
 (0)