From 970ad28ecaa03e9a0943a0381fab117667aa6625 Mon Sep 17 00:00:00 2001 From: streamich Date: Sun, 10 Nov 2024 14:36:35 +0100 Subject: [PATCH] =?UTF-8?q?style:=20=F0=9F=92=84=20fix=20linter=20suggesti?= =?UTF-8?q?ons?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../peritext/block/Inline.ts | 6 ++- .../peritext/editor/Editor.ts | 23 +++++++----- .../components/ButtonGroup/index.tsx | 6 +-- .../plugins/debug/Console/index.tsx | 20 +++++++--- .../plugins/debug/RenderPeritext.tsx | 37 ++++++++++--------- .../plugins/debug/context.ts | 2 +- .../plugins/minimal/Chrome/index.tsx | 2 +- .../plugins/minimal/TopToolbar/index.tsx | 2 +- .../plugins/minimal/index.ts | 2 +- .../react/PeritextView.tsx | 6 ++- 10 files changed, 60 insertions(+), 46 deletions(-) diff --git a/src/json-crdt-extensions/peritext/block/Inline.ts b/src/json-crdt-extensions/peritext/block/Inline.ts index 34fd3b63af..a9e2b6f77e 100644 --- a/src/json-crdt-extensions/peritext/block/Inline.ts +++ b/src/json-crdt-extensions/peritext/block/Inline.ts @@ -271,13 +271,15 @@ export class Inline extends Range implements Printable { printTree( tab, attrKeys.map((key) => () => { - return formatType(key) + + return ( + formatType(key) + ' = ' + stringify( attr[key].map((attr) => attr.slice instanceof Cursor ? [attr.slice.type, attr.slice.data()] : attr.slice.data(), ), - ); + ) + ); }), ), !this.texts.length diff --git a/src/json-crdt-extensions/peritext/editor/Editor.ts b/src/json-crdt-extensions/peritext/editor/Editor.ts index 6a40e9b67e..fe349f07b9 100644 --- a/src/json-crdt-extensions/peritext/editor/Editor.ts +++ b/src/json-crdt-extensions/peritext/editor/Editor.ts @@ -139,8 +139,7 @@ export class Editor implements Printable { const start = cursor.start.clone(); start.step(-text.length); const range = this.txt.range(start, cursor.end.clone()); - for (const [type, data] of pending) - this.toggleRangeExclFmt(range, type, data); + for (const [type, data] of pending) this.toggleRangeExclFmt(range, type, data); } } } @@ -515,7 +514,12 @@ export class Editor implements Printable { return; } - protected toggleRangeExclFmt(range: Range, type: CommonSliceType | string | number, data?: unknown, store: EditorSlices = this.saved): void { + protected toggleRangeExclFmt( + range: Range, + type: CommonSliceType | string | number, + data?: unknown, + store: EditorSlices = this.saved, + ): void { if (range.isCollapsed()) throw new Error('Range is collapsed'); const txt = this.txt; const overlay = txt.overlay; @@ -551,7 +555,11 @@ export class Editor implements Printable { } } - public toggleExclFmt(type: CommonSliceType | string | number, data?: unknown, store: EditorSlices = this.saved): void { + public toggleExclFmt( + type: CommonSliceType | string | number, + data?: unknown, + store: EditorSlices = this.saved, + ): void { // TODO: handle mutually exclusive slices (, ) this.txt.overlay.refresh(); CURSORS: for (let i = this.cursors0(), cursor = i(); cursor; cursor = i()) { @@ -627,11 +635,6 @@ export class Editor implements Printable { const pending = this.pending.value; const pendingFormatted = {} as any; for (const [type, data] of pending) pendingFormatted[formatType(type)] = data; - return ( - `Editor` + - printTree(tab, [ - () => `pending ${stringify(pendingFormatted)}` - ]) - ); + return 'Editor' + printTree(tab, [() => `pending ${stringify(pendingFormatted)}`]); } } diff --git a/src/json-crdt-peritext-ui/components/ButtonGroup/index.tsx b/src/json-crdt-peritext-ui/components/ButtonGroup/index.tsx index c90d3e6089..873ab2d22d 100644 --- a/src/json-crdt-peritext-ui/components/ButtonGroup/index.tsx +++ b/src/json-crdt-peritext-ui/components/ButtonGroup/index.tsx @@ -20,9 +20,5 @@ export interface ButtonGroup { } export const ButtonGroup: React.FC = ({children}) => { - return ( -
- {children} -
- ); + return
{children}
; }; diff --git a/src/json-crdt-peritext-ui/plugins/debug/Console/index.tsx b/src/json-crdt-peritext-ui/plugins/debug/Console/index.tsx index d803beefc8..53d9b03f30 100644 --- a/src/json-crdt-peritext-ui/plugins/debug/Console/index.tsx +++ b/src/json-crdt-peritext-ui/plugins/debug/Console/index.tsx @@ -1,3 +1,4 @@ +// biome-ignore lint: React is used for JSX import * as React from 'react'; import {rule} from 'nano-theme'; import {useDebugCtx} from '../context'; @@ -14,7 +15,8 @@ const consoleClass = rule({ bdrad: '8px', }); -export interface ConsoleProps {} +// biome-ignore lint: empty interface +export type ConsoleProps = {}; export const Console: React.FC = () => { const {ctx, flags} = useDebugCtx(); @@ -28,10 +30,18 @@ export const Console: React.FC = () => { return (
- - - - + + + + {!!dom &&
{ctx.dom + ''}
} {!!editor &&
{ctx.peritext.editor + ''}
} diff --git a/src/json-crdt-peritext-ui/plugins/debug/RenderPeritext.tsx b/src/json-crdt-peritext-ui/plugins/debug/RenderPeritext.tsx index 4d72a57fac..6621d3978d 100644 --- a/src/json-crdt-peritext-ui/plugins/debug/RenderPeritext.tsx +++ b/src/json-crdt-peritext-ui/plugins/debug/RenderPeritext.tsx @@ -32,30 +32,31 @@ export interface RenderPeritextProps extends PeritextViewProps { ctx?: PeritextSurfaceContextValue; } -export const RenderPeritext: React.FC = ({ - enabled: enabledProp = true, - ctx, - children, -}) => { +export const RenderPeritext: React.FC = ({enabled: enabledProp = true, ctx, children}) => { const theme = useTheme(); const [enabled, setEnabled] = React.useState(enabledProp); - const value = React.useMemo(() => ({ - enabled, - ctx, - flags: { - dom: new ValueSyncStore(true), - editor: new ValueSyncStore(true), - peritext: new ValueSyncStore(true), - model: new ValueSyncStore(false), - }, - }), [enabled, ctx]); + const value = React.useMemo( + () => ({ + enabled, + ctx, + flags: { + dom: new ValueSyncStore(true), + editor: new ValueSyncStore(true), + peritext: new ValueSyncStore(true), + model: new ValueSyncStore(false), + }, + }), + [enabled, ctx], + ); return (
-
+
diff --git a/src/json-crdt-peritext-ui/plugins/debug/context.ts b/src/json-crdt-peritext-ui/plugins/debug/context.ts index 7805fe623c..7e112061fe 100644 --- a/src/json-crdt-peritext-ui/plugins/debug/context.ts +++ b/src/json-crdt-peritext-ui/plugins/debug/context.ts @@ -1,5 +1,5 @@ import * as React from 'react'; -import {ValueSyncStore} from '../../../util/events/sync-store'; +import type {ValueSyncStore} from '../../../util/events/sync-store'; import type {PeritextSurfaceContextValue} from '../../react'; export interface DebugRenderersContextValue { diff --git a/src/json-crdt-peritext-ui/plugins/minimal/Chrome/index.tsx b/src/json-crdt-peritext-ui/plugins/minimal/Chrome/index.tsx index db77b62a38..495ba0cfe7 100644 --- a/src/json-crdt-peritext-ui/plugins/minimal/Chrome/index.tsx +++ b/src/json-crdt-peritext-ui/plugins/minimal/Chrome/index.tsx @@ -21,7 +21,7 @@ export interface ChromeProps { export const Chrome: React.FC = ({children}) => { const {ctx} = useDefaultCtx(); - + return (
{!!ctx && } diff --git a/src/json-crdt-peritext-ui/plugins/minimal/TopToolbar/index.tsx b/src/json-crdt-peritext-ui/plugins/minimal/TopToolbar/index.tsx index fea6103786..2b0e63606d 100644 --- a/src/json-crdt-peritext-ui/plugins/minimal/TopToolbar/index.tsx +++ b/src/json-crdt-peritext-ui/plugins/minimal/TopToolbar/index.tsx @@ -8,7 +8,7 @@ import type {PeritextSurfaceContextValue} from '../../../react'; export interface TopToolbarProps { ctx: PeritextSurfaceContextValue; -}; +} export const TopToolbar: React.FC = ({ctx}) => { const pending = useSyncStore(ctx.peritext.editor.pending); diff --git a/src/json-crdt-peritext-ui/plugins/minimal/index.ts b/src/json-crdt-peritext-ui/plugins/minimal/index.ts index 72373cb93e..6d1b93b2ff 100644 --- a/src/json-crdt-peritext-ui/plugins/minimal/index.ts +++ b/src/json-crdt-peritext-ui/plugins/minimal/index.ts @@ -22,7 +22,7 @@ export const renderers: PeritextPlugin = { if (attrs[CommonSliceType.i]) style.fontStyle = 'italic'; if (attrs[CommonSliceType.u]) textDecoration = 'underline'; if (attrs[CommonSliceType.s]) textDecoration = textDecoration ? textDecoration + ' line-through' : 'line-through'; - if (attr = attrs[CommonSliceType.col]) style.color = attr[0].slice.data() + ''; + if ((attr = attrs[CommonSliceType.col])) style.color = attr[0].slice.data() + ''; style.textDecoration = textDecoration; diff --git a/src/json-crdt-peritext-ui/react/PeritextView.tsx b/src/json-crdt-peritext-ui/react/PeritextView.tsx index 6164c3646d..d048e95daf 100644 --- a/src/json-crdt-peritext-ui/react/PeritextView.tsx +++ b/src/json-crdt-peritext-ui/react/PeritextView.tsx @@ -66,12 +66,14 @@ export const PeritextView: React.FC = React.memo((props) => { [peritext], ); - const ctx: undefined | PeritextSurfaceContextValue = React.useMemo(() => dom ? {peritext, dom, renderers, rerender} : undefined, [peritext, dom, renderers, rerender]); + const ctx: undefined | PeritextSurfaceContextValue = React.useMemo( + () => (dom ? {peritext, dom, renderers, rerender} : undefined), + [peritext, dom, renderers, rerender], + ); const block = peritext.blocks.root; if (!block) return null; - let children: React.ReactNode = (
{!!dom && (