fix: Indent/outdent list controls, closes #6974
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { Node } from "prosemirror-model";
|
||||
import { findBlockNodes, NodeWithPos } from "./findChildren";
|
||||
|
||||
export default function findCollapsedNodes(doc: Node): NodeWithPos[] {
|
||||
export function findCollapsedNodes(doc: Node): NodeWithPos[] {
|
||||
const blocks = findBlockNodes(doc);
|
||||
const nodes: NodeWithPos[] = [];
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { ResolvedPos, MarkType } from "prosemirror-model";
|
||||
|
||||
export default function getMarkRange($pos?: ResolvedPos, type?: MarkType) {
|
||||
export function getMarkRange($pos?: ResolvedPos, type?: MarkType) {
|
||||
if (!$pos || !type) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
import { Node } from "prosemirror-model";
|
||||
import { EditorState } from "prosemirror-state";
|
||||
|
||||
export default function getParentListItem(
|
||||
state: EditorState
|
||||
): [Node, number] | void {
|
||||
export function getParentListItem(state: EditorState): [Node, number] | void {
|
||||
const $head = state.selection.$head;
|
||||
for (let d = $head.depth; d > 0; d--) {
|
||||
const node = $head.node(d);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { EditorState } from "prosemirror-state";
|
||||
import isMarkActive from "./isMarkActive";
|
||||
import isNodeActive from "./isNodeActive";
|
||||
import { isMarkActive } from "./isMarkActive";
|
||||
import { isNodeActive } from "./isNodeActive";
|
||||
|
||||
type Options = {
|
||||
/** Only check if the selection is inside a code block. */
|
||||
@@ -16,10 +16,7 @@ type Options = {
|
||||
* @param options The options.
|
||||
* @returns True if the selection is inside a code block or code mark.
|
||||
*/
|
||||
export default function isInCode(
|
||||
state: EditorState,
|
||||
options?: Options
|
||||
): boolean {
|
||||
export function isInCode(state: EditorState, options?: Options): boolean {
|
||||
const { nodes, marks } = state.schema;
|
||||
|
||||
if (!options?.onlyMark) {
|
||||
|
||||
@@ -1,12 +1,19 @@
|
||||
import { EditorState } from "prosemirror-state";
|
||||
|
||||
export default function isInList(state: EditorState) {
|
||||
/**
|
||||
* Check if the current selection is in a list
|
||||
*
|
||||
* @param state - The current editor state
|
||||
* @param options - Optionally check for specific list types
|
||||
*/
|
||||
export function isInList(state: EditorState, options?: { types: string[] }) {
|
||||
const $head = state.selection.$head;
|
||||
for (let d = $head.depth; d > 0; d--) {
|
||||
if (
|
||||
["ordered_list", "bullet_list", "checkbox_list"].includes(
|
||||
$head.node(d).type.name
|
||||
)
|
||||
(options?.types
|
||||
? options.types
|
||||
: ["ordered_list", "bullet_list", "checkbox_list"]
|
||||
).includes($head.node(d).type.name)
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Node, Schema } from "prosemirror-model";
|
||||
|
||||
export default function isList(node: Node, schema: Schema) {
|
||||
export function isList(node: Node, schema: Schema) {
|
||||
return (
|
||||
node.type === schema.nodes.bullet_list ||
|
||||
node.type === schema.nodes.ordered_list ||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { MarkType } from "prosemirror-model";
|
||||
import { EditorState } from "prosemirror-state";
|
||||
|
||||
const isMarkActive =
|
||||
export const isMarkActive =
|
||||
(type: MarkType) =>
|
||||
(state: EditorState): boolean => {
|
||||
if (!type) {
|
||||
@@ -14,5 +14,3 @@ const isMarkActive =
|
||||
? type.isInSet(state.storedMarks || $from.marks())
|
||||
: state.doc.rangeHasMark(from, to, type));
|
||||
};
|
||||
|
||||
export default isMarkActive;
|
||||
|
||||
@@ -3,7 +3,7 @@ import { EditorState } from "prosemirror-state";
|
||||
import { Primitive } from "utility-types";
|
||||
import { findParentNode } from "./findParentNode";
|
||||
|
||||
const isNodeActive =
|
||||
export const isNodeActive =
|
||||
(type: NodeType, attrs: Record<string, Primitive> = {}) =>
|
||||
(state: EditorState) => {
|
||||
if (!type) {
|
||||
@@ -26,5 +26,3 @@ const isNodeActive =
|
||||
|
||||
return node.hasMarkup(type, { ...node.attrs, ...attrs });
|
||||
};
|
||||
|
||||
export default isNodeActive;
|
||||
|
||||
Reference in New Issue
Block a user