mirror of
https://github.com/outline/outline.git
synced 2026-11-24 23:00:18 +03:00
* Expanding drag handle to all root level block nodes * wip * looking good * wip * fix, drag video nodes * fix mermaid * Hide drag handle when printing, adjust heading actions for handle gutter Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com> * rtl * Passive scroll listener, avoid dispatch on teardown * Guard drag handle from re-showing mid-drag, use semantic button * Align drag handle to first line, hide on layout images, tidy heading controls * Fix stale drag handle target and drag data, rebuild Mermaid in moved containers, remove unused styles * Extract drag handle target resolution into DragTarget class * Move drag handle styles from inline to global CSS * Use EditorStyleHelper class names and named constants in drag handle, translate its label * Hide drag handle on a table that holds the selection * Remove opacity transition from drag handle * Move heading anchor into drag handle slot when read-only * Move drop cursor class name to EditorStyleHelper * Add empty line above comments, document the rule in AGENTS.md * drag handle --------- Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>
139 lines
3.4 KiB
TypeScript
139 lines
3.4 KiB
TypeScript
import type {
|
|
NodeSpec,
|
|
NodeType,
|
|
Node as ProsemirrorNode,
|
|
} from "prosemirror-model";
|
|
import {
|
|
splitListItem,
|
|
sinkListItem,
|
|
liftListItem,
|
|
} from "prosemirror-schema-list";
|
|
import type { Command } from "prosemirror-state";
|
|
import { TextSelection } from "prosemirror-state";
|
|
import type { MarkdownSerializerState } from "../lib/markdown/serializer";
|
|
import { getParentListItem } from "../queries/getParentListItem";
|
|
import { isInList } from "../queries/isInList";
|
|
import Node from "./Node";
|
|
|
|
export default class ListItem extends Node {
|
|
get name() {
|
|
return "list_item";
|
|
}
|
|
|
|
get schema(): NodeSpec {
|
|
return {
|
|
content: "block+",
|
|
defining: true,
|
|
draggable: true,
|
|
parseDOM: [{ tag: "li" }],
|
|
toDOM: () => ["li", 0],
|
|
};
|
|
}
|
|
|
|
commands({ type }: { type: NodeType }) {
|
|
return {
|
|
indentList: () => sinkListItem(type),
|
|
outdentList: () => liftListItem(type),
|
|
};
|
|
}
|
|
|
|
keys({ type }: { type: NodeType }): Record<string, Command> {
|
|
return {
|
|
Enter: splitListItem(type),
|
|
Tab: sinkListItem(type),
|
|
"Shift-Tab": liftListItem(type),
|
|
"Mod-]": sinkListItem(type),
|
|
"Mod-[": liftListItem(type),
|
|
"Shift-Enter": (state, dispatch) => {
|
|
if (!isInList(state)) {
|
|
return false;
|
|
}
|
|
if (!state.selection.empty) {
|
|
return false;
|
|
}
|
|
|
|
const { tr, selection } = state;
|
|
dispatch?.(tr.split(selection.to));
|
|
return true;
|
|
},
|
|
"Alt-ArrowUp": (state, dispatch) => {
|
|
if (!state.selection.empty) {
|
|
return false;
|
|
}
|
|
const result = getParentListItem(state);
|
|
if (!result) {
|
|
return false;
|
|
}
|
|
|
|
const [li, pos] = result;
|
|
const $pos = state.doc.resolve(pos);
|
|
|
|
if (
|
|
!$pos.nodeBefore ||
|
|
!["list_item", "checkbox_item"].includes($pos.nodeBefore.type.name)
|
|
) {
|
|
return false;
|
|
}
|
|
|
|
const { tr } = state;
|
|
const newPos = pos - $pos.nodeBefore.nodeSize;
|
|
|
|
dispatch?.(
|
|
tr
|
|
.delete(pos, pos + li.nodeSize)
|
|
.insert(newPos, li)
|
|
.setSelection(TextSelection.near(tr.doc.resolve(newPos)))
|
|
);
|
|
return true;
|
|
},
|
|
"Alt-ArrowDown": (state, dispatch) => {
|
|
if (!state.selection.empty) {
|
|
return false;
|
|
}
|
|
const result = getParentListItem(state);
|
|
if (!result) {
|
|
return false;
|
|
}
|
|
|
|
const [li, pos] = result;
|
|
const $pos = state.doc.resolve(pos + li.nodeSize);
|
|
|
|
if (
|
|
!$pos.nodeAfter ||
|
|
!["list_item", "checkbox_item"].includes($pos.nodeAfter.type.name)
|
|
) {
|
|
return false;
|
|
}
|
|
|
|
const { tr } = state;
|
|
const newPos = pos + li.nodeSize + $pos.nodeAfter.nodeSize;
|
|
|
|
dispatch?.(
|
|
tr
|
|
.insert(newPos, li)
|
|
.setSelection(TextSelection.near(tr.doc.resolve(newPos)))
|
|
.delete(pos, pos + li.nodeSize)
|
|
);
|
|
return true;
|
|
},
|
|
};
|
|
}
|
|
|
|
toMarkdown(state: MarkdownSerializerState, node: ProsemirrorNode) {
|
|
if (state.inTable) {
|
|
node.forEach((block, _, i) => {
|
|
if (i > 0) {
|
|
state.append(" ");
|
|
}
|
|
state.renderInline(block);
|
|
});
|
|
return;
|
|
}
|
|
state.renderContent(node);
|
|
}
|
|
|
|
parseMarkdown() {
|
|
return { block: "list_item" };
|
|
}
|
|
}
|