Skip to content

Commit

Permalink
style: 💄 fix linter suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
streamich committed Nov 10, 2024
1 parent e79ec1b commit 970ad28
Show file tree
Hide file tree
Showing 10 changed files with 60 additions and 46 deletions.
6 changes: 4 additions & 2 deletions src/json-crdt-extensions/peritext/block/Inline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 13 additions & 10 deletions src/json-crdt-extensions/peritext/editor/Editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,7 @@ export class Editor<T = string> 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);
}
}
}
Expand Down Expand Up @@ -515,7 +514,12 @@ export class Editor<T = string> implements Printable {
return;
}

protected toggleRangeExclFmt(range: Range<T>, type: CommonSliceType | string | number, data?: unknown, store: EditorSlices<T> = this.saved): void {
protected toggleRangeExclFmt(
range: Range<T>,
type: CommonSliceType | string | number,
data?: unknown,
store: EditorSlices<T> = this.saved,
): void {
if (range.isCollapsed()) throw new Error('Range is collapsed');
const txt = this.txt;
const overlay = txt.overlay;
Expand Down Expand Up @@ -551,7 +555,11 @@ export class Editor<T = string> implements Printable {
}
}

public toggleExclFmt(type: CommonSliceType | string | number, data?: unknown, store: EditorSlices<T> = this.saved): void {
public toggleExclFmt(
type: CommonSliceType | string | number,
data?: unknown,
store: EditorSlices<T> = this.saved,
): void {
// TODO: handle mutually exclusive slices (<sub>, <sub>)
this.txt.overlay.refresh();
CURSORS: for (let i = this.cursors0(), cursor = i(); cursor; cursor = i()) {
Expand Down Expand Up @@ -627,11 +635,6 @@ export class Editor<T = string> 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)}`]);
}
}
6 changes: 1 addition & 5 deletions src/json-crdt-peritext-ui/components/ButtonGroup/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,5 @@ export interface ButtonGroup {
}

export const ButtonGroup: React.FC<ButtonGroup> = ({children}) => {
return (
<div className={blockClass}>
{children}
</div>
);
return <div className={blockClass}>{children}</div>;
};
20 changes: 15 additions & 5 deletions src/json-crdt-peritext-ui/plugins/debug/Console/index.tsx
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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<ConsoleProps> = () => {
const {ctx, flags} = useDebugCtx();
Expand All @@ -28,10 +30,18 @@ export const Console: React.FC<ConsoleProps> = () => {
return (
<div className={consoleClass}>
<ButtonGroup>
<Button small active={dom} onClick={() => flags.dom.next(!dom)}>DOM</Button>
<Button small active={editor} onClick={() => flags.editor.next(!editor)}>Editor</Button>
<Button small active={peritext} onClick={() => flags.peritext.next(!peritext)}>Peritext</Button>
<Button small active={model} onClick={() => flags.model.next(!model)}>Model</Button>
<Button small active={dom} onClick={() => flags.dom.next(!dom)}>
DOM
</Button>
<Button small active={editor} onClick={() => flags.editor.next(!editor)}>
Editor
</Button>
<Button small active={peritext} onClick={() => flags.peritext.next(!peritext)}>
Peritext
</Button>
<Button small active={model} onClick={() => flags.model.next(!model)}>
Model
</Button>
</ButtonGroup>
{!!dom && <pre>{ctx.dom + ''}</pre>}
{!!editor && <pre>{ctx.peritext.editor + ''}</pre>}
Expand Down
37 changes: 19 additions & 18 deletions src/json-crdt-peritext-ui/plugins/debug/RenderPeritext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,30 +32,31 @@ export interface RenderPeritextProps extends PeritextViewProps {
ctx?: PeritextSurfaceContextValue;
}

export const RenderPeritext: React.FC<RenderPeritextProps> = ({
enabled: enabledProp = true,
ctx,
children,
}) => {
export const RenderPeritext: React.FC<RenderPeritextProps> = ({enabled: enabledProp = true, ctx, children}) => {
const theme = useTheme();
const [enabled, setEnabled] = React.useState(enabledProp);
const value = React.useMemo(() => ({
enabled,
ctx,
flags: {
dom: new ValueSyncStore<boolean>(true),
editor: new ValueSyncStore<boolean>(true),
peritext: new ValueSyncStore<boolean>(true),
model: new ValueSyncStore<boolean>(false),
},
}), [enabled, ctx]);
const value = React.useMemo(
() => ({
enabled,
ctx,
flags: {
dom: new ValueSyncStore<boolean>(true),
editor: new ValueSyncStore<boolean>(true),
peritext: new ValueSyncStore<boolean>(true),
model: new ValueSyncStore<boolean>(false),
},
}),
[enabled, ctx],
);

return (
<context.Provider value={value}>
<div className={blockClass}>
<div className={btnClass({
bg: theme.bg,
})}>
<div
className={btnClass({
bg: theme.bg,
})}
>
<Button small active={enabled} onClick={() => setEnabled((x) => !x)}>
Debug
</Button>
Expand Down
2 changes: 1 addition & 1 deletion src/json-crdt-peritext-ui/plugins/debug/context.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion src/json-crdt-peritext-ui/plugins/minimal/Chrome/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export interface ChromeProps {

export const Chrome: React.FC<ChromeProps> = ({children}) => {
const {ctx} = useDefaultCtx();

return (
<div className={blockClass}>
{!!ctx && <TopToolbar ctx={ctx} />}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import type {PeritextSurfaceContextValue} from '../../../react';

export interface TopToolbarProps {
ctx: PeritextSurfaceContextValue;
};
}

export const TopToolbar: React.FC<TopToolbarProps> = ({ctx}) => {
const pending = useSyncStore(ctx.peritext.editor.pending);
Expand Down
2 changes: 1 addition & 1 deletion src/json-crdt-peritext-ui/plugins/minimal/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
6 changes: 4 additions & 2 deletions src/json-crdt-peritext-ui/react/PeritextView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,14 @@ export const PeritextView: React.FC<PeritextViewProps> = 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 = (
<div ref={ref} className={CssClass.Editor}>
{!!dom && (
Expand Down

0 comments on commit 970ad28

Please sign in to comment.