mirror of
https://github.com/outline/outline.git
synced 2026-11-20 21:23:06 +03:00
* chore: Prune redundant comments and normalize lint directives Removes comments that restate the following line and stale TODOs, drops the passive event listener feature check now that all supported browsers support it, and renames eslint directives to oxlint. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01BehTjuZwKbN5csMCp3H4QH * fix: Evaluate restricted team domains at validation time The restricted email provider list was captured when the model loaded, so it could not follow the hosting environment and the tests that covered it never reached the model. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01BehTjuZwKbN5csMCp3H4QH * chore: Replace type suppressions with accurate types Adds a Concrete helper type for registries of abstract classes, declares missing Sequelize and refractor typings, uses public ProseMirror APIs, a typed mock context helper in middleware tests, and a StaticLink component for sidebar rows being edited. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01BehTjuZwKbN5csMCp3H4QH --------- Co-authored-by: Claude <noreply@anthropic.com>
108 lines
3.7 KiB
TypeScript
108 lines
3.7 KiB
TypeScript
import { wrappingInputRule, InputRule } from "prosemirror-inputrules";
|
|
import type {
|
|
NodeType,
|
|
Node as ProsemirrorNode,
|
|
Attrs,
|
|
} from "prosemirror-model";
|
|
import { TextSelection } from "prosemirror-state";
|
|
import toggleList from "../commands/toggleList";
|
|
import { findParentNodeClosestToPos } from "../queries/findParentNode";
|
|
import { isInHeading } from "../queries/isInHeading";
|
|
import { isList } from "../queries/isList";
|
|
|
|
/**
|
|
* A wrapper for wrappingInputRule that prevents execution inside heading nodes.
|
|
* This fixes the bug where typing list triggers ("* ", "- ", "1. ", etc.) inside
|
|
* a heading would trigger list conversion.
|
|
*/
|
|
export function listWrappingInputRule(
|
|
regexp: RegExp,
|
|
nodeType: NodeType,
|
|
getAttrs?: (match: RegExpMatchArray) => Attrs | null,
|
|
joinPredicate?: (match: RegExpMatchArray, node: ProsemirrorNode) => boolean
|
|
): InputRule {
|
|
const rule = wrappingInputRule(regexp, nodeType, getAttrs, joinPredicate);
|
|
|
|
// Wrap the original rule to check if we're inside a heading
|
|
return new InputRule(regexp, (state, match, start, end) => {
|
|
// Don't apply the rule if we're inside a heading
|
|
if (isInHeading(state)) {
|
|
return null;
|
|
}
|
|
|
|
const { $from } = state.selection;
|
|
const itemType = state.schema.nodes.list_item;
|
|
const parent = $from.node(-1);
|
|
if (itemType && parent.type === itemType && $from.index(-1) === 0) {
|
|
// Wrapping a list item's first block creates an empty parent item whose
|
|
// marker overlaps the nested list marker. Convert or exit the current
|
|
// list instead.
|
|
const tr = state.tr.delete(start, end);
|
|
const after = state.apply(tr);
|
|
let handled = false;
|
|
let selection = after.selection;
|
|
toggleList(nodeType, itemType)(after, (toggleTr) => {
|
|
toggleTr.steps.forEach((step) => tr.step(step));
|
|
selection = toggleTr.selection;
|
|
handled = true;
|
|
});
|
|
|
|
if (!handled) {
|
|
return null;
|
|
}
|
|
|
|
tr.setSelection(
|
|
TextSelection.near(
|
|
tr.doc.resolve(Math.min(selection.from, tr.doc.content.size))
|
|
)
|
|
);
|
|
return tr;
|
|
}
|
|
|
|
// Otherwise, execute the original wrappingInputRule handler
|
|
// oxlint-disable-next-line @typescript-eslint/no-explicit-any
|
|
return (rule as any).handler(state, match, start, end);
|
|
});
|
|
}
|
|
|
|
/**
|
|
* An input rule that converts an existing plain list (bullet or ordered) to a
|
|
* checklist when the checkbox marker is typed at the start of a list item,
|
|
* preserving any nested list structure.
|
|
*
|
|
* @param regexp the pattern matching the checkbox marker, e.g. "[ ] ".
|
|
* @param listType the checkbox list node type to convert to.
|
|
* @param itemType the checkbox item node type to convert items to.
|
|
* @returns the input rule.
|
|
*/
|
|
export function checkboxListInputRule(
|
|
regexp: RegExp,
|
|
listType: NodeType,
|
|
itemType: NodeType
|
|
): InputRule {
|
|
return new InputRule(regexp, (state, _match, start, end) => {
|
|
const { schema } = state;
|
|
|
|
// Only act when the selection sits inside a plain (non-checkbox) list —
|
|
// converting a paragraph is already handled by listWrappingInputRule.
|
|
const list = findParentNodeClosestToPos(state.selection.$from, (node) =>
|
|
isList(node, schema)
|
|
);
|
|
if (!list || list.node.type === listType) {
|
|
return null;
|
|
}
|
|
|
|
// Remove the typed marker, then convert the list in place.
|
|
const tr = state.tr.delete(start, end);
|
|
const after = state.apply(tr);
|
|
toggleList(listType, itemType)(after, (toggleTr) => {
|
|
toggleTr.steps.forEach((step) => tr.step(step));
|
|
});
|
|
|
|
// Place the cursor at the start of the converted item, where the marker
|
|
// was, so the user can continue typing.
|
|
tr.setSelection(TextSelection.near(tr.doc.resolve(start)));
|
|
return tr;
|
|
});
|
|
}
|