* Header toggling, resizable columns * Allow all blocks in table cells, disable column resizing in read-only * Fixed dynamic scroll shadows * Refactor, scroll styling * fix scrolling, tweaks * fix: Table layout lost on sort * fix: Caching of grip decorators * refactor * stash * fix first render shadows * stash * First add column grip, styles * Just add column/row click handlers left * fix: isTableSelected for single cell table * Refactor mousedown handlers * fix: 'Add row before' command missing on first row * fix overflow on rhs * fix: Error clicking column grip when menu is open * Hide table controls when printing * Restore table header background * fix: Header behavior when adding columns and rows at the edges * Tweak header styling * fix: Serialize and parsing of column attributes when copy/pasting fix: Column width is lost when changing column alignment
55 lines
1.4 KiB
TypeScript
55 lines
1.4 KiB
TypeScript
import { NodeType } from "prosemirror-model";
|
|
import { wrapInList, liftListItem } from "prosemirror-schema-list";
|
|
import { Command } from "prosemirror-state";
|
|
import { chainTransactions } from "../lib/chainTransactions";
|
|
import { findParentNode } from "../queries/findParentNode";
|
|
import isList from "../queries/isList";
|
|
import clearNodes from "./clearNodes";
|
|
|
|
export default function toggleList(
|
|
listType: NodeType,
|
|
itemType: NodeType
|
|
): Command {
|
|
return (state, dispatch) => {
|
|
const { schema, selection } = state;
|
|
const { $from, $to } = selection;
|
|
const range = $from.blockRange($to);
|
|
const { tr } = state;
|
|
|
|
if (!range) {
|
|
return false;
|
|
}
|
|
|
|
const parentList = findParentNode((node) => isList(node, schema))(
|
|
selection
|
|
);
|
|
|
|
if (range.depth >= 1 && parentList && range.depth - parentList.depth <= 1) {
|
|
if (parentList.node.type === listType) {
|
|
return liftListItem(itemType)(state, dispatch);
|
|
}
|
|
|
|
if (
|
|
isList(parentList.node, schema) &&
|
|
listType.validContent(parentList.node.content)
|
|
) {
|
|
tr.setNodeMarkup(parentList.pos, listType);
|
|
|
|
dispatch?.(tr);
|
|
return false;
|
|
}
|
|
}
|
|
|
|
const canWrapInList = wrapInList(listType)(state);
|
|
|
|
if (canWrapInList) {
|
|
return wrapInList(listType)(state, dispatch);
|
|
}
|
|
|
|
return chainTransactions(clearNodes(), wrapInList(listType))(
|
|
state,
|
|
dispatch
|
|
);
|
|
};
|
|
}
|