Skip to content

Commit

Permalink
Lint
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathonherbert committed Jan 9, 2025
1 parent e4771d0 commit d48f294
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 15 deletions.
21 changes: 16 additions & 5 deletions demo/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ import {
import type { WindowType } from "./types";

// Enable collaboration and serialisation. Disabling can be useful when measuring performance improvements.
const enableExpensiveFeatures = false;
const enableExpensiveFeatures = true;

// Only show focus when the user is keyboard navigating, not when
// they click a text field.
Expand Down Expand Up @@ -353,6 +353,7 @@ const createEditor = (server: CollabServer) => {
}
});

// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition -- for dev use
const expensivePlugins = enableExpensiveFeatures
? [
collabPlugin,
Expand Down Expand Up @@ -508,12 +509,19 @@ const createEditor = (server: CollabServer) => {
});
btnContainer.appendChild(toggleImageFields);

// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition -- for dev use
if (enableExpensiveFeatures) {
new EditorConnection(view, server, clientID, `User ${clientID}`, (state) => {
if (isFirstEditor) {
set(state.doc);
new EditorConnection(
view,
server,
clientID,
`User ${clientID}`,
(state) => {
if (isFirstEditor) {
set(state.doc);
}
}
});
);
}

editorNo++;
Expand All @@ -524,6 +532,8 @@ const createEditor = (server: CollabServer) => {
const server = new CollabServer();
firstEditor = createEditor(server);
const doc = firstEditor.state.doc;

// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition -- for dev use
if (enableExpensiveFeatures) {
server.init(doc);
}
Expand All @@ -543,6 +553,7 @@ declare global {
interface Window extends WindowType {}
}

// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition -- for dev use
if (enableExpensiveFeatures) {
applyDevTools(firstEditor);
}
Expand Down
1 change: 0 additions & 1 deletion src/plugin/__tests__/plugin.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import type { FieldNameToValueMapWithEmptyValues } from "../helpers/fieldView";
import { createEditorWithElements } from "../helpers/test";
import { elementSelectedNodeAttr } from "../nodeSpec";
import type { FieldDescriptions } from "../types/Element";
import { pluginKey } from "../helpers/constants";

describe("createPlugin", () => {
// Called when our consumer is updated by the plugin.
Expand Down
7 changes: 5 additions & 2 deletions src/plugin/helpers/__tests__/prosemirror.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { defaultPredicate, getValidElementInsertionRange } from "../prosemirror";
import { doc, example, example__caption } from "./fixtures";
import { Node } from "prosemirror-model";
import {
defaultPredicate,
getValidElementInsertionRange,
} from "../prosemirror";
import { doc, example, example__caption } from "./fixtures";

describe("prosemirror utilities", () => {
const a = example("<a>", example__caption("a"));
Expand Down
2 changes: 1 addition & 1 deletion src/plugin/helpers/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// renderers that must be able to uniquely identify children – for example, in

import { PluginKey } from "prosemirror-state";
import { PluginState } from "../plugin";
import type { PluginState } from "../plugin";

// React, where a `key` attribute is expected in arrays of ReactNodes.
export const RepeaterFieldMapIDKey = "__ID";
Expand Down
8 changes: 4 additions & 4 deletions src/plugin/helpers/prosemirror.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,10 @@ export const findAllNodesThatMatchPredicate = (
to: number,
predicate: Predicate
) => {
const result: {
const result: Array<{
node: Node;
pos: number;
}[] = [];
}> = [];
node.nodesBetween(from, to, (iterNode, pos, parent, index) => {
if (predicate(iterNode, pos, parent, index)) {
result.push({ node: iterNode, pos });
Expand All @@ -167,7 +167,7 @@ export const findAllNodesThatMatchPredicate = (
recursion, top-level elements would move inside the list element, often breaking the document
structure. Note this still allows us to move nested elements **within** list elements.
*/
return !result && !anyDescendantFieldIsNestedElementField(iterNode);
return !anyDescendantFieldIsNestedElementField(iterNode);
});

return result;
Expand All @@ -189,7 +189,7 @@ export const getValidElementInsertionRange = (
predicate
);

if (!validNodes.length) {
if (validNodes.length === 0) {
return undefined;
}

Expand Down
10 changes: 8 additions & 2 deletions src/plugin/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,10 @@ const createNodeView = <
let currentDecos = innerDecos;
let currentIsSelected = false;
const pluginState = pluginKey.getState(view.state);
let currentCommandValues = getCommandValues(getPos(), pluginState?.validInsertionRange);
let currentCommandValues = getCommandValues(
getPos(),
pluginState?.validInsertionRange
);
let currentSelection = view.state.selection;
let currentStoredMarks = view.state.storedMarks;

Expand Down Expand Up @@ -291,7 +294,10 @@ const createNodeView = <

const newCommands = commands(getPos, view);
const pluginState = pluginKey.getState(view.state);
const newCommandValues = getCommandValues(getPos(), pluginState?.validInsertionRange);
const newCommandValues = getCommandValues(
getPos(),
pluginState?.validInsertionRange
);

const newSelection = view.state.selection;
const newStoredMarks = view.state.storedMarks;
Expand Down

0 comments on commit d48f294

Please sign in to comment.