Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.
TypeScript agentaiai-agentsall-in-onecrmcrm-systememaillinearmcpmessagingnotesnotionofficerustslackslack-alternativestartupstartup-toolstypescriptworkspace
feat(web): swipe to indent list items on mobile (#6314)
Wolf Mermelsteine554fe383c5f
diff --git a/apps/web/src/features/block-md/component/MarkdownEditor.tsx b/apps/web/src/features/block-md/component/MarkdownEditor.tsxindex 3a5deffb7f..366f01282d 100644--- a/apps/web/src/features/block-md/component/MarkdownEditor.tsx+++ b/apps/web/src/features/block-md/component/MarkdownEditor.tsx@@ -60,6 +60,7 @@ import {generatePlugin,horizontalRulePlugin,keyboardShortcutsPlugin,+ listSwipeIndentPlugin,listToTablePlugin,markdownPastePlugin,mentionsPlugin,@@ -545,6 +546,7 @@ export function MarkdownEditor(props: {.state<EditorState>(setState, 'json').history(400, props.loroManager).use(tabIndentationPlugin())+ .use(listSwipeIndentPlugin(isContentEditable)).use(selectionDataPlugin(lexicalWrapper)).use(horizontalRulePlugin()).use(diff --git a/apps/web/src/lib/core/component/LexicalMarkdown/builder/buildHandleFromConfig.ts b/apps/web/src/lib/core/component/LexicalMarkdown/builder/buildHandleFromConfig.tsindex 6426c6ad0d..b3dd7477fb 100644--- a/apps/web/src/lib/core/component/LexicalMarkdown/builder/buildHandleFromConfig.ts+++ b/apps/web/src/lib/core/component/LexicalMarkdown/builder/buildHandleFromConfig.ts@@ -17,6 +17,7 @@ import {filePastePlugin,horizontalRulePlugin,keyboardFocusPlugin,+ listSwipeIndentPlugin,markdownPastePlugin,mediaPlugin,mentionsPlugin,@@ -160,6 +161,11 @@ export function buildHandleFromConfig(config: EditorConfig): EditorHandle {plugins.use(tabIndentationPlugin());}+ // Touch swipe indent/outdent for list items (Apple Notes-style).+ if (config.type !== 'plain-text' && !config.singleLine) {+ plugins.use(listSwipeIndentPlugin(isInteractable));+ }+// Horizontal rules & normalize-enter (full multi-line markdown only)if (config.type !== 'plain-text' && !config.singleLine) {plugins.use(horizontalRulePlugin());diff --git a/apps/web/src/lib/core/component/LexicalMarkdown/component/core/MarkdownTextarea.tsx b/apps/web/src/lib/core/component/LexicalMarkdown/component/core/MarkdownTextarea.tsxindex 864ed57d64..fe9a809a81 100644--- a/apps/web/src/lib/core/component/LexicalMarkdown/component/core/MarkdownTextarea.tsx+++ b/apps/web/src/lib/core/component/LexicalMarkdown/component/core/MarkdownTextarea.tsx@@ -41,6 +41,7 @@ import {type ItemMention,iosCursorScrollPlugin,keyboardFocusPlugin,+ listSwipeIndentPlugin,mediaPlugin,mentionsPlugin,type SelectionData,@@ -232,6 +233,7 @@ export function MarkdownTextarea(props: MarkdownTextareaProps) {: selectionDataPlugin(lexicalWrapper)).use(tabIndentationPlugin())+ .use(listSwipeIndentPlugin(props.editable)).use(textPastePlugin()).use(mentionsPlugin({diff --git a/apps/web/src/lib/core/component/LexicalMarkdown/component/debug/MarkdownParseTestPage.tsx b/apps/web/src/lib/core/component/LexicalMarkdown/component/debug/MarkdownParseTestPage.tsxindex 3280cf31e2..08648cfe42 100644--- a/apps/web/src/lib/core/component/LexicalMarkdown/component/debug/MarkdownParseTestPage.tsx+++ b/apps/web/src/lib/core/component/LexicalMarkdown/component/debug/MarkdownParseTestPage.tsx@@ -17,6 +17,7 @@ import {import {codePlugin,createAccessoryStore,+ listSwipeIndentPlugin,mediaPlugin,mentionsPlugin,tabIndentationPlugin,@@ -211,6 +212,7 @@ export function TestEditor(props: {.delete().history(400).use(tabIndentationPlugin())+ .use(listSwipeIndentPlugin(() => false)).use(mentionsPlugin({})).use(mediaPlugin()).use(tablePlugin({}))diff --git a/apps/web/src/lib/core/component/LexicalMarkdown/plugins/index.ts b/apps/web/src/lib/core/component/LexicalMarkdown/plugins/index.tsindex 8b659fda5a..a8d61c51aa 100644--- a/apps/web/src/lib/core/component/LexicalMarkdown/plugins/index.ts+++ b/apps/web/src/lib/core/component/LexicalMarkdown/plugins/index.ts@@ -23,6 +23,7 @@ export * from './katex';export * from './keyboard-focus';export * from './keyboard-shortcuts';export * from './links';+export * from './list-swipe-indent';export * from './location';export * from './markdown-paste';export * from './media';diff --git a/apps/web/src/lib/core/component/LexicalMarkdown/plugins/list-swipe-indent/index.ts b/apps/web/src/lib/core/component/LexicalMarkdown/plugins/list-swipe-indent/index.tsnew file mode 100644index 0000000000..13c8d0d0f0--- /dev/null+++ b/apps/web/src/lib/core/component/LexicalMarkdown/plugins/list-swipe-indent/index.ts@@ -0,0 +1 @@+export { listSwipeIndentPlugin } from './listSwipeIndentPlugin';diff --git a/apps/web/src/lib/core/component/LexicalMarkdown/plugins/list-swipe-indent/listSwipeIndentPlugin.test.ts b/apps/web/src/lib/core/component/LexicalMarkdown/plugins/list-swipe-indent/listSwipeIndentPlugin.test.tsnew file mode 100644index 0000000000..5acb5fb360--- /dev/null+++ b/apps/web/src/lib/core/component/LexicalMarkdown/plugins/list-swipe-indent/listSwipeIndentPlugin.test.ts@@ -0,0 +1,648 @@+import { createEmptyHistoryState, registerHistory } from '@lexical/history';+import {+ $createListItemNode,+ $createListNode,+ $isListItemNode,+ $isListNode,+ ListItemNode,+ ListNode,+ type ListType,+ registerList,+} from '@lexical/list';+import { registerRichText } from '@lexical/rich-text';+import {+ $createTextNode,+ $getRoot,+ $getSelection,+ createEditor,+ type LexicalEditor,+ REDO_COMMAND,+ UNDO_COMMAND,+} from 'lexical';+import { afterEach, describe, expect, it, vi } from 'vitest';+import {+ $indentListItem,+ $outdentListItem,+ listSwipeIndentPlugin,+} from './listSwipeIndentPlugin';++class PolyfillPointerEvent extends MouseEvent {+ pointerId: number;+ pointerType: string;+ isPrimary: boolean;+ constructor(+ type: string,+ init: MouseEventInit & {+ pointerId?: number;+ pointerType?: string;+ isPrimary?: boolean;+ } = {}+ ) {+ super(type, init);+ this.pointerId = init.pointerId ?? 0;+ this.pointerType = init.pointerType ?? '';+ this.isPrimary = init.isPrimary ?? true;+ }+}+if (typeof globalThis.PointerEvent === 'undefined') {+ globalThis.PointerEvent =+ PolyfillPointerEvent as unknown as typeof PointerEvent;+}++function createTestEditorWithCleanup(isInteractable = () => true) {+ const editor = createEditor({+ namespace: 'list-swipe-indent-test',+ nodes: [ListNode, ListItemNode],+ onError: (error) => {+ throw error;+ },+ });+ const root = document.createElement('div');+ root.contentEditable = 'true';+ document.body.appendChild(root);+ editor.setRootElement(root);+ registerRichText(editor);+ const unregister = listSwipeIndentPlugin(isInteractable)(editor);+ return { editor, unregister };+}++function createTestEditor(isInteractable = () => true): LexicalEditor {+ return createTestEditorWithCleanup(isInteractable).editor;+}++function $buildList(+ items: Array<{ text: string; indent?: number }>,+ listType: ListType = 'bullet'+) {+ const list = $createListNode(listType);+ const nodes = items.map((item) => {+ const node = $createListItemNode();+ node.append($createTextNode(item.text));+ list.append(node);+ return node;+ });+ $getRoot().clear().append(list);+ // Apply indent after attach so ListItemNode.setIndent can rewrite the tree.+ nodes.forEach((node, index) => {+ const indent = items[index].indent;+ if (indent) node.setIndent(indent);+ });+}++function readIndents(editor: LexicalEditor): number[] {+ return editor.getEditorState().read(() =>+ $getRoot()+ .getAllTextNodes()+ .map((text) => {+ const parent = text.getParent();+ return $isListItemNode(parent) ? parent.getIndent() : -1;+ })+ );+}++function itemElement(editor: LexicalEditor, text: string): HTMLElement {+ return editor.getEditorState().read(() => {+ const textNode = $getRoot()+ .getAllTextNodes()+ .find((node) => node.getTextContent() === text);+ if (!textNode) throw new Error(`no text node "${text}"`);+ const item = textNode.getParent();+ if (!$isListItemNode(item)) throw new Error(`"${text}" is not a list item`);+ const elem = editor.getElementByKey(item.getKey());+ if (!elem) throw new Error(`no element for "${text}"`);+ return elem;+ });+}++function pointerEvent(+ type: string,+ init: {+ clientX?: number;+ clientY?: number;+ pointerType?: string;+ } = {}+): PointerEvent {+ return new PolyfillPointerEvent(type, {+ bubbles: true,+ cancelable: true,+ clientX: init.clientX ?? 80,+ clientY: init.clientY ?? 40,+ isPrimary: true,+ pointerId: 1,+ pointerType: init.pointerType ?? 'touch',+ }) as unknown as PointerEvent;+}++async function update(editor: LexicalEditor, fn: () => void): Promise<void> {+ await new Promise<void>((resolve) => {+ editor.update(fn, { onUpdate: () => resolve() });+ });+}++async function swipe(+ editor: LexicalEditor,+ text: string,+ dx: number,+ dy = 0,+ pointerType = 'touch'+) {+ const elem = itemElement(editor, text);+ const startX = 80;+ const startY = 40;+ elem.dispatchEvent(+ pointerEvent('pointerdown', {+ clientX: startX,+ clientY: startY,+ pointerType,+ })+ );+ const beforeMove = editor.getRootElement()?.innerHTML;+ document.dispatchEvent(+ pointerEvent('pointermove', {+ clientX: startX + dx,+ clientY: startY + dy,+ pointerType,+ })+ );+ // The entire group stays visually unchanged until the finger is released.+ expect(editor.getRootElement()?.innerHTML).toBe(beforeMove);+ document.dispatchEvent(+ pointerEvent('pointerup', {+ clientX: startX + dx,+ clientY: startY + dy,+ pointerType,+ })+ );+ await Promise.resolve();+}++afterEach(() => {+ vi.restoreAllMocks();+ document.dispatchEvent(pointerEvent('pointercancel'));+ document.body.innerHTML = '';+});++describe('list swipe indent cleanup', () => {+ it('removes the document listener and cancels an active swipe when unregistered with a mounted root', async () => {+ const addListener = vi.spyOn(document, 'addEventListener');+ const removeListener = vi.spyOn(document, 'removeEventListener');+ const { editor, unregister } = createTestEditorWithCleanup();+ const pointerDown = addListener.mock.calls.find(+ ([type, , options]) => type === 'pointerdown' && options === true+ )?.[1];+ expect(pointerDown).toBeDefined();+ await update(editor, () => {+ $buildList([{ text: 'one' }, { text: 'two' }]);+ });+ const root = editor.getRootElement();+ itemElement(editor, 'two').dispatchEvent(pointerEvent('pointerdown'));+ document.dispatchEvent(pointerEvent('pointermove', { clientX: 130 }));++ unregister();++ expect(root?.isConnected).toBe(true);+ expect(editor.getRootElement()).toBe(root);+ expect(removeListener).toHaveBeenCalledWith(+ 'pointerdown',+ pointerDown,+ true+ );+ const touchMove = new Event('touchmove', { cancelable: true });+ document.dispatchEvent(touchMove);+ expect(touchMove.defaultPrevented).toBe(false);+ document.dispatchEvent(pointerEvent('pointerup', { clientX: 130 }));+ await Promise.resolve();+ expect(readIndents(editor)).toEqual([0, 0]);+ await swipe(editor, 'two', 50);+ expect(readIndents(editor)).toEqual([0, 0]);+ });++ it('removes the previous root listener while enabling swipes on a replacement root', async () => {+ const addListener = vi.spyOn(document, 'addEventListener');+ const removeListener = vi.spyOn(document, 'removeEventListener');+ const { editor, unregister } = createTestEditorWithCleanup();+ const pointerDown = addListener.mock.calls.find(+ ([type, , options]) => type === 'pointerdown' && options === true+ )?.[1];+ expect(pointerDown).toBeDefined();+ await update(editor, () => {+ $buildList([{ text: 'one' }, { text: 'two' }]);+ });+ const root = document.createElement('div');+ root.contentEditable = 'true';+ document.body.appendChild(root);++ editor.setRootElement(root);++ expect(removeListener).toHaveBeenCalledWith(+ 'pointerdown',+ pointerDown,+ true+ );+ await swipe(editor, 'two', 50);+ expect(readIndents(editor)).toEqual([0, 1]);+ unregister();+ });+});++describe('$indentListItem / $outdentListItem', () => {+ it('indents an item under the previous sibling', async () => {+ const editor = createTestEditor();+ await update(editor, () => {+ $buildList([{ text: 'one' }, { text: 'two' }]);+ const two = $getRoot()+ .getAllTextNodes()+ .find((node) => node.getTextContent() === 'two')+ ?.getParent();+ if ($isListItemNode(two)) expect($indentListItem(two)).toBe(true);+ });+ expect(readIndents(editor)).toEqual([0, 1]);+ });++ it('indents the only item in a list', async () => {+ const editor = createTestEditor();+ registerList(editor);+ await update(editor, () => {+ $buildList([{ text: 'one' }]);+ const one = $getRoot().getAllTextNodes()[0].getParent();+ if ($isListItemNode(one)) expect($indentListItem(one)).toBe(true);+ });+ expect(readIndents(editor)).toEqual([1]);+ });++ it('outdents a nested item', async () => {+ const editor = createTestEditor();+ await update(editor, () => {+ $buildList([{ text: 'one' }, { text: 'two', indent: 1 }]);+ const two = $getRoot()+ .getAllTextNodes()+ .find((node) => node.getTextContent() === 'two')+ ?.getParent();+ if ($isListItemNode(two)) expect($outdentListItem(two)).toBe(true);+ });+ expect(readIndents(editor)).toEqual([0, 0]);+ });++ it('does not outdent an item already at the root', async () => {+ const editor = createTestEditor();+ await update(editor, () => {+ $buildList([{ text: 'one' }]);+ const one = $getRoot().getAllTextNodes()[0]?.getParent();+ if ($isListItemNode(one)) expect($outdentListItem(one)).toBe(false);+ });+ expect(readIndents(editor)).toEqual([0]);+ });++ it.each(['parent', ''])(+ 'outdent fallback preserves parent content %j and removes empty wrappers',+ async (parentText) => {+ const editor = createTestEditor();+ await update(editor, () => {+ const list = $createListNode('bullet');+ const parent = $createListItemNode();+ if (parentText) parent.append($createTextNode(parentText));+ const nested = $createListNode('bullet');+ const child = $createListItemNode().append($createTextNode('child'));+ parent.append(nested.append(child));+ $getRoot().clear().append(list.append(parent));++ // Exercise the fallback for a setIndent call that leaves the tree unchanged.+ const setIndent = vi.spyOn(child, 'setIndent').mockReturnValue(child);+ expect($outdentListItem(child)).toBe(true);+ setIndent.mockRestore();++ expect(nested.isAttached()).toBe(false);+ expect(list.getChildren()).toEqual(+ parentText ? [parent, child] : [child]+ );+ });+ editor.read(() => {+ expect(+ $getRoot()+ .getAllTextNodes()+ .map((node) => node.getTextContent())+ ).toEqual(parentText ? [parentText, 'child'] : ['child']);+ });+ expect(readIndents(editor)).toEqual(parentText ? [0, 0] : [0]);+ }+ );+});++describe('list swipe indent gesture', () => {+ it('does not mutate a comment-only editor that Lexical marks editable', async () => {+ const editor = createTestEditor(() => false);+ await update(editor, () => {+ $buildList([{ text: 'one' }, { text: 'two', indent: 1 }]);+ });+ expect(editor.isEditable()).toBe(true);+ const before = editor.getEditorState().toJSON();+ const updateSpy = vi.spyOn(editor, 'update');++ await swipe(editor, 'two', 50);+ await swipe(editor, 'two', -50);++ expect(updateSpy).not.toHaveBeenCalled();+ expect(editor.getEditorState().toJSON()).toEqual(before);+ });++ it.each(['during swipe', 'after release'] as const)(+ 'does not queue an editor update when edit permission is revoked %s',+ async (when) => {+ let canEdit = true;+ const editor = createTestEditor(() => canEdit);+ await update(editor, () => {+ $buildList([{ text: 'one' }, { text: 'two' }]);+ });+ const elem = itemElement(editor, 'two');+ const updateSpy = vi.spyOn(editor, 'update');+ elem.dispatchEvent(pointerEvent('pointerdown'));+ document.dispatchEvent(pointerEvent('pointermove', { clientX: 130 }));+ if (when === 'during swipe') canEdit = false;+ document.dispatchEvent(pointerEvent('pointerup', { clientX: 130 }));+ canEdit = false;+ await Promise.resolve();++ expect(editor.isEditable()).toBe(true);+ expect(updateSpy).not.toHaveBeenCalled();+ expect(readIndents(editor)).toEqual([0, 0]);+ }+ );++ it('requires a new swipe if edit permission is granted after pointer-down', async () => {+ let canEdit = false;+ const editor = createTestEditor(() => canEdit);+ await update(editor, () => {+ $buildList([{ text: 'one' }, { text: 'two' }]);+ });+ itemElement(editor, 'two').dispatchEvent(pointerEvent('pointerdown'));+ canEdit = true;+ document.dispatchEvent(pointerEvent('pointermove', { clientX: 130 }));+ document.dispatchEvent(pointerEvent('pointerup', { clientX: 130 }));+ await Promise.resolve();+ expect(readIndents(editor)).toEqual([0, 0]);++ await swipe(editor, 'two', 50);+ expect(readIndents(editor)).toEqual([0, 1]);+ });++ it('indents a list item on a right swipe', async () => {+ const editor = createTestEditor();+ await update(editor, () => {+ $buildList([{ text: 'one' }, { text: 'two' }]);+ });++ await swipe(editor, 'two', 50);++ expect(readIndents(editor)).toEqual([0, 1]);+ });++ it('outdents a list item on a left swipe', async () => {+ const editor = createTestEditor();+ await update(editor, () => {+ $buildList([{ text: 'one' }, { text: 'two', indent: 1 }]);+ });++ await swipe(editor, 'two', -50);++ expect(readIndents(editor)).toEqual([0, 0]);+ });++ it('does not indent on a vertical swipe', async () => {+ const editor = createTestEditor();+ await update(editor, () => {+ $buildList([{ text: 'one' }, { text: 'two' }]);+ });++ await swipe(editor, 'two', 10, 60);++ expect(readIndents(editor)).toEqual([0, 0]);+ });++ it('does not indent on a mouse drag', async () => {+ const editor = createTestEditor();+ await update(editor, () => {+ $buildList([{ text: 'one' }, { text: 'two' }]);+ });++ await swipe(editor, 'two', 50, 0, 'mouse');++ expect(readIndents(editor)).toEqual([0, 0]);+ });++ it('does not indent when the swipe is shorter than the commit threshold', async () => {+ const editor = createTestEditor();+ await update(editor, () => {+ $buildList([{ text: 'one' }, { text: 'two' }]);+ });++ await swipe(editor, 'two', 20);++ expect(readIndents(editor)).toEqual([0, 0]);+ });++ it('indents the first item without moving the following sibling', async () => {+ const editor = createTestEditor();+ registerList(editor);+ await update(editor, () => {+ $buildList([{ text: 'one' }, { text: 'two' }]);+ });++ await swipe(editor, 'one', 50);++ expect(readIndents(editor)).toEqual([1, 0]);+ await swipe(editor, 'one', -50);+ expect(readIndents(editor)).toEqual([0, 0]);+ });++ it('does not indent when the editor is read-only', async () => {+ const editor = createTestEditor();+ editor.setEditable(false);+ await update(editor, () => {+ $buildList([{ text: 'one' }, { text: 'two' }]);+ });++ await swipe(editor, 'two', 50);++ expect(readIndents(editor)).toEqual([0, 0]);+ });+});++describe('list swipe indent with registerList', () => {+ it('creates a nested list for the group and undoes the move as one edit', async () => {+ const editor = createTestEditor();+ registerList(editor);+ registerHistory(editor, createEmptyHistoryState(), 400);+ await update(editor, () =>+ $buildList([+ { text: 'before' },+ { text: 'parent' },+ { text: 'child', indent: 1 },+ { text: 'grandchild', indent: 2 },+ { text: 'after' },+ ])+ );++ await swipe(editor, 'parent', 50);+ expect(readIndents(editor)).toEqual([0, 1, 2, 3, 0]);+ editor.dispatchCommand(UNDO_COMMAND, undefined);+ await Promise.resolve();+ expect(readIndents(editor)).toEqual([0, 0, 1, 2, 0]);+ editor.dispatchCommand(REDO_COMMAND, undefined);+ await Promise.resolve();+ expect(readIndents(editor)).toEqual([0, 1, 2, 3, 0]);+ });++ it.each(['bullet', 'number', 'check'] as const)(+ 'moves descendants with their parent in a %s list',+ async (listType) => {+ const editor = createTestEditor();+ registerList(editor);+ const items = [+ { text: 'before' },+ { text: 'existing child', indent: 1 },+ { text: 'parent' },+ { text: 'child', indent: 1 },+ { text: 'grandchild', indent: 2 },+ { text: 'another child', indent: 1 },+ { text: 'after' },+ { text: 'unrelated child', indent: 1 },+ ];+ let selectedKey = '';+ await update(editor, () => {+ $buildList(items, listType);+ const grandchild = $getRoot().getAllTextNodes()[4];+ selectedKey = grandchild.getKey();+ grandchild.select(2, 5);+ if (listType === 'check') {+ const child = $getRoot().getAllTextNodes()[3].getParent();+ if ($isListItemNode(child)) child.setChecked(true);+ }+ });+ expect(readIndents(editor)).toEqual([0, 1, 0, 1, 2, 1, 0, 1]);++ await swipe(editor, 'parent', 50);+ expect(readIndents(editor)).toEqual([0, 1, 1, 2, 3, 2, 0, 1]);+ editor.read(() => {+ expect($getSelection()).toMatchObject({+ anchor: { key: selectedKey, offset: 2 },+ focus: { key: selectedKey, offset: 5 },+ });+ });++ await swipe(editor, 'parent', -50);+ expect(readIndents(editor)).toEqual([0, 1, 0, 1, 2, 1, 0, 1]);+ editor.read(() => {+ const textNodes = $getRoot().getAllTextNodes();+ expect(textNodes.map((node) => node.getTextContent())).toEqual(+ items.map((item) => item.text)+ );+ for (const node of textNodes) {+ const list = node.getParentOrThrow().getParent();+ expect($isListNode(list) && list.getListType()).toBe(listType);+ }+ expect($getSelection()).toMatchObject({+ anchor: { key: selectedKey, offset: 2 },+ focus: { key: selectedKey, offset: 5 },+ });+ if (listType === 'check') {+ const child = textNodes[3].getParent();+ expect($isListItemNode(child) && child.getChecked()).toBe(true);+ }+ });+ }+ );++ it.each(['first', 'middle', 'last'] as const)(+ 'outdents a %s sibling with its descendants',+ async (position) => {+ const editor = createTestEditor();+ registerList(editor);+ const preceding =+ position === 'first' ? [] : [{ text: 'before', indent: 1 }];+ const following =+ position === 'last' ? [] : [{ text: 'after', indent: 1 }];+ await update(editor, () =>+ $buildList([+ { text: 'root' },+ ...preceding,+ { text: 'parent', indent: 1 },+ { text: 'child', indent: 2 },+ { text: 'grandchild', indent: 3 },+ ...following,+ { text: 'next root' },+ ])+ );++ await swipe(editor, 'parent', -50);+ expect(readIndents(editor)).toEqual([+ 0,+ ...preceding.map(() => 1),+ 0,+ 1,+ 2,+ ...following.map(() => 1),+ 0,+ ]);+ editor.read(() => {+ expect(+ $getRoot()+ .getAllTextNodes()+ .map((node) => node.getTextContent())+ ).toEqual([+ 'root',+ ...preceding.map((item) => item.text),+ 'parent',+ 'child',+ 'grandchild',+ ...following.map((item) => item.text),+ 'next root',+ ]);+ });+ }+ );++ it.each(['bullet', 'number', 'check'] as const)(+ 'indents and outdents the first %s item with its descendants',+ async (listType) => {+ const editor = createTestEditor();+ registerList(editor);+ await update(editor, () =>+ $buildList(+ [+ { text: 'parent' },+ { text: 'child', indent: 1 },+ { text: 'grandchild', indent: 2 },+ { text: 'after' },+ ],+ listType+ )+ );+ const before = editor.getEditorState().toJSON();++ await swipe(editor, 'parent', -50);+ expect(editor.getEditorState().toJSON()).toEqual(before);+ await swipe(editor, 'parent', 50);+ expect(readIndents(editor)).toEqual([1, 2, 3, 0]);+ await swipe(editor, 'parent', 50);+ expect(readIndents(editor)).toEqual([2, 3, 4, 0]);+ await swipe(editor, 'parent', -50);+ expect(readIndents(editor)).toEqual([1, 2, 3, 0]);+ await swipe(editor, 'parent', -50);+ expect(editor.getEditorState().toJSON()).toEqual(before);+ }+ );++ it('indents and outdents after list transforms run', async () => {+ const editor = createTestEditor();+ registerList(editor);+ await update(editor, () => {+ $buildList([{ text: 'one' }, { text: 'two' }]);+ });++ await swipe(editor, 'two', 50);+ expect(readIndents(editor)).toEqual([0, 1]);++ await swipe(editor, 'two', -50);+ expect(readIndents(editor)).toEqual([0, 0]);+ });+});diff --git a/apps/web/src/lib/core/component/LexicalMarkdown/plugins/list-swipe-indent/listSwipeIndentPlugin.ts b/apps/web/src/lib/core/component/LexicalMarkdown/plugins/list-swipe-indent/listSwipeIndentPlugin.tsnew file mode 100644index 0000000000..04d658cbd5--- /dev/null+++ b/apps/web/src/lib/core/component/LexicalMarkdown/plugins/list-swipe-indent/listSwipeIndentPlugin.ts@@ -0,0 +1,269 @@+/**+ * @file Apple Notes-style swipe indent for list items on touch.+ *+ * A mostly-horizontal finger swipe on a list row indents (right) or outdents+ * (left) that item one level on release, taking nested children with it.+ * Items stay still while the finger is down. Vertical pans+ * stay scrolling; taps and mouse drags are left alone. The first item can+ * indent without a preceding sibling; other items keep the same sibling+ * depth limit as tab indentation.+ */+import {+ $createListNode,+ $isListItemNode,+ $isListNode,+ type ListItemNode,+} from '@lexical/list';+import { $findMatchingParent } from '@lexical/utils';+import {+ $getNearestNodeFromDOMNode,+ $getNodeByKey,+ $isElementNode,+ type LexicalEditor,+} from 'lexical';+import { $collectNestedGroup } from '../draggable-block/draggableBlockPlugin';++/** Movement below this is a tap or scroll jitter, not a swipe. */+const SLOP_PX = 12;+/** Release past this distance commits one indent/outdent. */+const COMMIT_PX = 40;+/** Ignore swipes that start on the iOS back-gesture edge. */+const EDGE_GUARD_PX = 16;++export function $canIndentListItem(item: ListItemNode): boolean {+ if (!item.canIndent()) return false;+ const prev = item.getPreviousSibling();+ if (prev === null) return true;+ if (!$isElementNode(prev)) return false;+ return item.getIndent() < prev.getIndent() + 1;+}++export function $canOutdentListItem(item: ListItemNode): boolean {+ return item.getIndent() > 0;+}++/**+ * Lexical's ListItemNode.setIndent no-ops on nesting wrappers (a list item+ * whose only child is a list). Prefer the inner text item.+ */+function $unwrapNestedListItem(item: ListItemNode): ListItemNode {+ let current = item;+ while (true) {+ const child = current.getFirstChild();+ if (!$isListNode(child)) break;+ const inner = child.getFirstChild();+ if (!$isListItemNode(inner)) break;+ current = inner;+ }+ return current;+}++/**+ * Rewrite used when ListItemNode.setIndent claims success but the tree+ * didn't change (its loop increments even if $handleIndent is a no-op).+ */+function $nestUnderPreviousSibling(item: ListItemNode): boolean {+ const parent = item.getParent();+ if (!$isListNode(parent)) return false;+ const prev = item.getPreviousSibling();+ if (!$isListItemNode(prev)) return false;+ const existing = prev.getChildren().find($isListNode);+ if (existing) {+ existing.append(item);+ return true;+ }+ const nested = $createListNode(parent.getListType());+ prev.append(nested);+ nested.append(item);+ return true;+}++function $unnestFromParentList(item: ListItemNode): boolean {+ const parent = item.getParent();+ if (!$isListNode(parent)) return false;+ const grand = parent.getParent();+ if (!$isListItemNode(grand)) return false;+ grand.insertAfter(item);+ if (parent.getChildrenSize() === 0) {+ parent.remove();+ if (grand.getChildrenSize() === 0) grand.remove();+ }+ return true;+}++/** Keep child-list wrappers out of Lexical's single-item split/merge operation. */+function $moveWithNestedGroup(+ item: ListItemNode,+ move: () => boolean+): boolean {+ const parent = item.getParent();+ if (!$isListNode(parent)) return false;+ const nested = $collectNestedGroup(item).slice(1);+ if (nested.length === 0) return move();++ // Moving into a temporary list preserves the nodes and their selection points.+ // Leaving wrappers beside the item lets setIndent merge their children into+ // the destination list as siblings, losing their relationship to this item.+ $createListNode(parent.getListType()).append(...nested);+ const moved = move();+ let anchor = item;+ for (const node of nested) {+ anchor.insertAfter(node);+ anchor = node;+ }+ return moved;+}++/** Indent a list item and its nested group by one level. */+export function $indentListItem(item: ListItemNode): boolean {+ const target = $unwrapNestedListItem(item);+ if (!$canIndentListItem(target)) return false;+ return $moveWithNestedGroup(target, () => {+ const before = target.getIndent();+ target.setIndent(before + 1);+ return target.getIndent() > before || $nestUnderPreviousSibling(target);+ });+}++/** Outdent a list item and its nested group by one level. */+export function $outdentListItem(item: ListItemNode): boolean {+ const target = $unwrapNestedListItem(item);+ if (!$canOutdentListItem(target)) return false;+ return $moveWithNestedGroup(target, () => {+ const before = target.getIndent();+ target.setIndent(before - 1);+ return target.getIndent() < before || $unnestFromParentList(target);+ });+}++function listItemFromTarget(target: EventTarget | null): ListItemNode | null {+ if (!(target instanceof Node)) return null;+ const nearest = $getNearestNodeFromDOMNode(target);+ if (!nearest) return null;+ const item = $isListItemNode(nearest)+ ? nearest+ : $findMatchingParent(nearest, $isListItemNode);+ if (!item) return null;+ return $unwrapNestedListItem(item);+}++function registerListSwipeIndent(+ editor: LexicalEditor,+ isInteractable: () => boolean+): () => void {+ let endGesture: (() => void) | null = null;+ let detachRoot: (() => void) | null = null;++ const attach = (root: HTMLElement): (() => void) => {+ const onPointerDown = (down: PointerEvent) => {+ if (down.pointerType !== 'touch') return;+ if (down.isPrimary === false) return;+ if (!isInteractable() || !editor.isEditable()) return;+ if (down.clientX < EDGE_GUARD_PX) return;+ const eventTarget = down.target;+ if (!(eventTarget instanceof Node) || !root.contains(eventTarget)) return;+ endGesture?.();++ let canIndent = false;+ let canOutdent = false;++ const itemKey = editor.read(() => {+ const item = listItemFromTarget(eventTarget);+ if (!item) return null;+ canIndent = $canIndentListItem(item);+ canOutdent = $canOutdentListItem(item);+ return item.getKey();+ });+ if (itemKey == null) return;++ const { clientX: startX, clientY: startY, pointerId } = down;+ let claimed = false;+ let lastDx = 0;++ const cleanup = () => {+ document.removeEventListener('pointermove', onMove);+ document.removeEventListener('pointerup', onUp);+ document.removeEventListener('pointercancel', cleanup);+ document.removeEventListener('touchmove', blockScroll);+ endGesture = null;+ };++ const blockScroll = (event: TouchEvent) => event.preventDefault();++ const claim = () => {+ if (claimed) return;+ claimed = true;+ document.addEventListener('touchmove', blockScroll, { passive: false });+ try {+ root.setPointerCapture(pointerId);+ } catch {+ // synthetic pointers cannot be captured+ }+ };++ const onMove = (move: PointerEvent) => {+ if (move.pointerId !== pointerId) return;+ const dx = move.clientX - startX;+ const dy = move.clientY - startY;+ lastDx = dx;+ if (!claimed) {+ if (Math.abs(dx) < SLOP_PX && Math.abs(dy) < SLOP_PX) return;+ // Mostly vertical: this is a scroll, abandon the gesture.+ if (Math.abs(dy) >= Math.abs(dx)) {+ cleanup();+ return;+ }+ claim();+ }+ };++ const onUp = (up: PointerEvent) => {+ if (up.pointerId !== pointerId) return;+ cleanup();+ if (!claimed) return;++ const commitIndent = lastDx >= COMMIT_PX && canIndent;+ const commitOutdent = lastDx <= -COMMIT_PX && canOutdent;+ if (!commitIndent && !commitOutdent) return;++ const key = itemKey;+ const apply = commitIndent ? $indentListItem : $outdentListItem;+ // Apply after the pointer event so Lexical isn't mid-selection update.+ queueMicrotask(() => {+ if (!isInteractable() || !editor.isEditable()) return;+ editor.update(() => {+ const item = $getNodeByKey(key);+ if (!$isListItemNode(item)) return;+ apply(item);+ });+ });+ };++ document.addEventListener('pointermove', onMove);+ document.addEventListener('pointerup', onUp);+ document.addEventListener('pointercancel', cleanup);+ endGesture = cleanup;+ };++ // Capture on document so a parent stopPropagation cannot hide the swipe.+ document.addEventListener('pointerdown', onPointerDown, true);+ return () => {+ endGesture?.();+ document.removeEventListener('pointerdown', onPointerDown, true);+ };+ };++ return editor.registerRootListener((root, prevRoot) => {+ if (prevRoot) {+ detachRoot?.();+ detachRoot = null;+ }+ if (root) detachRoot = attach(root);+ });+}++/** isInteractable must represent permission to edit content, not to comment. */+export function listSwipeIndentPlugin(isInteractable: () => boolean) {+ return (editor: LexicalEditor) =>+ registerListSwipeIndent(editor, isInteractable);+}diff --git a/docs/AGENT_GUIDE/documents.md b/docs/AGENT_GUIDE/documents.mdindex 2ee1cfe547..4576f4b503 100644--- a/docs/AGENT_GUIDE/documents.md+++ b/docs/AGENT_GUIDE/documents.md@@ -21,6 +21,18 @@ Markdown auto-format works while typing (`#` heading, `[]` checklist, `>` quote)text and inline mention chips (tasks, docs, channels, skills, …) by the titleshown on the chip.+On a touch device, swipe a list item right to indent one level (Apple Notes+style) or left to outdent. Nested children move with the parent. The first+item can indent too, even in a single-item list. Vertical scrolling and taps+are unchanged.+Items stay still during the swipe and change indentation only when a+successful swipe is released; short or blocked swipes leave them in place.+Swiping requires permission to edit the document; comment-only access does+not allow indentation changes. Losing edit permission during a swipe cancels it.+To verify nesting, give a list item a child and grandchild, then swipe the+parent right and left: all three should shift one level together, preserving+their relative depths and order.+## Reference hover previewsHover a document reference chip to open its preview without navigating. With