Skip to content

Commit dd287cb

Browse files
committed
feat(webapp): move a TOC section like a folder on drag
A drop between two rows names a parent and an index. The planner derives the level from that slot. Every sub-heading shifts by the same step and stops at H6. A move never pulls the following headings into the section, which overturns R2 for TOC moves. The Title row is fixed, a locked pad shows no grips, and the caret moves with the moved text. The level picker and the sideways offset are gone. The rail of the landing list turns primary (DS-12). The TOC also goes back to the stock daisyUI nest rails, so a row fill no longer covers the indent guide. A desktop leaf row drops its blank fold slot, which updates the #373 ruling for desktop. Refs #499 Refs #520
1 parent 91aeeaa commit dd287cb

32 files changed

Lines changed: 998 additions & 786 deletions

‎.cursor/docs/design-system.md‎

Lines changed: 24 additions & 24 deletions
Large diffs are not rendered by default.

‎README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ Sign in with Google or an email link when you need more. You need an account to
4848

4949
**A chatroom on every heading.** Ask a question under a section, and the answer stays with that section. Nobody has to guess which part you meant. On desktop, select a passage to comment on it, and the comment posts in that heading's chatroom. Reply in thread turns a message into a new heading. [Open a chatroom in the demo](https://docs.plus/demo/notifications).
5050

51-
**Find the busy sections.** The table of contents shows a message count beside each heading with messages. Sign in, and each count shows only what you have not read. On desktop, faces show who has each chatroom open, and you can drag a row to move its whole section. Drag it sideways to change its level. [Try it in the demo](https://docs.plus/demo/invisible).
51+
**Find the busy sections.** The table of contents shows a message count beside each heading with messages. Sign in, and each count shows only what you have not read. On desktop, faces show who has each chatroom open, and you can drag a row to move its whole section. The slot you drop it in sets its level. [Try it in the demo](https://docs.plus/demo/invisible).
5252

5353
**Send the exact view you mean.** Filter a document by a word, and it folds to the sections that contain it. The filter is part of the link, so you can send that view to someone. Here is [the demo, filtered to "spotify"](https://docs.plus/demo/spotify).
5454

‎apps/webapp/CHANGELOG.md‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,14 @@ plus the house order in [`RELEASE_POLICY.md`](../../RELEASE_POLICY.md).
128128

129129
### Changed
130130

131+
- A desktop TOC drag now moves a section like a folder in a file manager
132+
([#499](https://github.com/docs-plus/docs.plus/issues/499)). Let go between two rows, and
133+
the slot sets the level. Every sub-heading shifts by the same step and stops at H6. A move
134+
never pulls the headings that follow into the section. The sideways level offset and the
135+
level picker are gone. The title row has no grip, nothing lands above it, and a locked pad
136+
starts no drag. While a drop is allowed, the rail of the list it joins turns blue. A refused
137+
slot shows no line and the "no drop" cursor. The drag card now hangs below the pointer, so
138+
the line stays in view.
131139
- Links in posted chat messages show the same icons as links in the document
132140
([#516](https://github.com/docs-plus/docs.plus/issues/516)). A click on a
133141
message link opens the link preview: a popover on a computer, the Link sheet on a phone.
@@ -181,6 +189,10 @@ plus the house order in [`RELEASE_POLICY.md`](../../RELEASE_POLICY.md).
181189

182190
### Fixed
183191

192+
- A caret inside a section you drag in the TOC now moves with the section. Before, it stayed
193+
at the old place, and the next key typed into the following heading
194+
([#520](https://github.com/docs-plus/docs.plus/issues/520)).
195+
- A TOC drop below a folded row now lands after that row's whole section, not inside it.
184196
- A `/new` link in a pad now says what it does. Its click preview shows a "New document"
185197
chip that reads "Opens a blank document in a new tab", on desktop, in the phone sheet and in
186198
the chat composer dialog. The chip opens `/new` in a new tab, so the reader keeps their

‎apps/webapp/CLAUDE.md‎

Lines changed: 3 additions & 3 deletions
Large diffs are not rendered by default.
Lines changed: 195 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,195 @@
1+
/* eslint-disable no-undef */
2+
3+
import { section, heading, paragraph } from '../../../fixtures/docMaker'
4+
5+
const moveOpts = { keepMouseDownButton: 'left', scrollBehavior: false }
6+
7+
const row = (text) => cy.getTocItem(text).find('> .toc__row')
8+
const grip = (text) => row(text).find('.toc-drag-handle')
9+
10+
/** Presses the grip and moves past dnd-kit's 5px start distance. */
11+
const pickUp = (text) => {
12+
row(text).realHover({ scrollBehavior: false })
13+
grip(text).then(($grip) => {
14+
const box = $grip[0].getBoundingClientRect()
15+
grip(text).realMouseDown({ position: 'center', scrollBehavior: false })
16+
cy.get('body').realMouseMove(box.left + box.width / 2, box.top + box.height / 2 + 12, moveOpts)
17+
})
18+
cy.get('.toc__list.is-dragging').should('exist')
19+
}
20+
21+
/** Rects are read after pickup, because the ghosted rows grow. */
22+
const hoverAbove = (text) =>
23+
row(text).then(($row) => {
24+
const box = $row[0].getBoundingClientRect()
25+
cy.get('body').realMouseMove(box.left + 40, box.top + 3, moveOpts)
26+
})
27+
28+
const hoverBelow = (text) =>
29+
row(text).then(($row) => {
30+
const box = $row[0].getBoundingClientRect()
31+
cy.get('body').realMouseMove(box.left + 40, box.bottom - 3, moveOpts)
32+
})
33+
34+
const drop = () =>
35+
cy.get('.toc-drop-indicator-portal').then(($line) => {
36+
const y = Number($line.attr('data-y'))
37+
cy.get('body').realMouseUp({ x: 60, y, scrollBehavior: false })
38+
})
39+
40+
const outline = () =>
41+
cy.window().then((win) => {
42+
const out = []
43+
win._editor.state.doc.forEach((node) => {
44+
if (node.type.name === 'heading') out.push(`${node.attrs.level}:${node.textContent}`)
45+
})
46+
return out
47+
})
48+
49+
describe('TOC drag by pointer', () => {
50+
beforeEach(() => {
51+
cy.visitEditor()
52+
cy.createDocument({
53+
sections: [
54+
section('Pointer Title', [
55+
heading(2, 'Alpha', [
56+
paragraph('alpha body'),
57+
heading(3, 'Alpha One', [
58+
paragraph('alpha one body'),
59+
heading(4, 'Alpha One Deep', [paragraph('deep body')])
60+
])
61+
]),
62+
heading(2, 'Bravo', [
63+
paragraph('bravo body'),
64+
heading(3, 'Bravo One', [paragraph('bravo one body')])
65+
]),
66+
heading(2, 'Charlie', [paragraph('charlie body')])
67+
])
68+
]
69+
})
70+
cy.waitForToc()
71+
})
72+
73+
it('gives the Title row no grip', () => {
74+
row('Pointer Title').should('exist').find('.toc-drag-handle').should('not.exist')
75+
grip('Bravo').should('exist')
76+
})
77+
78+
it('derives the level from the gap and moves sub-headings with a demoted section', () => {
79+
pickUp('Bravo')
80+
hoverAbove('Alpha One')
81+
// DS-12: the landing parent's rail turns primary; every other rail stays stock.
82+
cy.getTocItem('Alpha')
83+
.find('> ul.toc__children')
84+
.should('have.class', 'is-drop-parent')
85+
.then(($ul) => {
86+
const win = $ul[0].ownerDocument.defaultView
87+
const rail = win.getComputedStyle($ul[0], '::before')
88+
const stock = win.getComputedStyle(
89+
$ul[0].ownerDocument.querySelector('ul.toc__children:not(.is-drop-parent)'),
90+
'::before'
91+
)
92+
expect(rail.opacity).to.equal('1')
93+
expect(stock.opacity).not.to.equal('1')
94+
expect(rail.backgroundColor).not.to.equal(stock.backgroundColor)
95+
})
96+
cy.get('ul.toc__children.is-drop-parent').should('have.length', 1)
97+
drop()
98+
99+
cy.get('ul.toc__children.is-drop-parent').should('not.exist')
100+
outline().should('deep.equal', [
101+
'1:Pointer Title',
102+
'2:Alpha',
103+
'3:Bravo',
104+
'4:Bravo One',
105+
'3:Alpha One',
106+
'4:Alpha One Deep',
107+
'2:Charlie'
108+
])
109+
})
110+
111+
it('moves sub-headings with a promoted section', () => {
112+
pickUp('Alpha One')
113+
hoverAbove('Bravo')
114+
// A root-level child of the Title lands under the Title's own rail.
115+
cy.getTocItem('Pointer Title').find('> ul.toc__children').should('have.class', 'is-drop-parent')
116+
drop()
117+
118+
outline().should('deep.equal', [
119+
'1:Pointer Title',
120+
'2:Alpha',
121+
'2:Alpha One',
122+
'3:Alpha One Deep',
123+
'2:Bravo',
124+
'3:Bravo One',
125+
'2:Charlie'
126+
])
127+
})
128+
129+
it('keeps the caret in the moved text', () => {
130+
cy.window().then((win) => {
131+
const editor = win._editor
132+
let caret = null
133+
editor.state.doc.descendants((node, pos) => {
134+
if (caret === null && node.isText && node.text === 'bravo body') caret = pos + 3
135+
})
136+
editor.commands.setTextSelection(caret)
137+
})
138+
139+
pickUp('Bravo')
140+
hoverAbove('Alpha')
141+
drop()
142+
143+
outline().should('deep.equal', [
144+
'1:Pointer Title',
145+
'2:Bravo',
146+
'3:Bravo One',
147+
'2:Alpha',
148+
'3:Alpha One',
149+
'4:Alpha One Deep',
150+
'2:Charlie'
151+
])
152+
cy.window().then((win) => {
153+
const { $from } = win._editor.state.selection
154+
expect($from.parent.textContent).to.equal('bravo body')
155+
expect($from.parentOffset).to.equal(3)
156+
})
157+
})
158+
159+
it('lands a drop below a folded row after its whole section', () => {
160+
row('Alpha').find('button.toc__fold-btn').click({ force: true })
161+
row('Alpha One').should('not.be.visible')
162+
163+
pickUp('Charlie')
164+
hoverBelow('Alpha')
165+
drop()
166+
167+
outline().should('deep.equal', [
168+
'1:Pointer Title',
169+
'2:Alpha',
170+
'3:Alpha One',
171+
'4:Alpha One Deep',
172+
'2:Charlie',
173+
'2:Bravo',
174+
'3:Bravo One'
175+
])
176+
})
177+
178+
it('shows no grip on a locked pad', () => {
179+
grip('Bravo').should('exist')
180+
cy.window().then((win) => {
181+
win._store.getState().setWorkspaceSetting('authorizedScope', 'readonly')
182+
})
183+
cy.get('.toc__list .toc-drag-handle').should('not.exist')
184+
})
185+
186+
it('refuses a drop above the Title', () => {
187+
pickUp('Charlie')
188+
hoverAbove('Pointer Title')
189+
cy.get('.toc-drop-indicator-portal').should('not.exist')
190+
cy.get('body').should('have.css', 'cursor', 'no-drop')
191+
cy.get('body').realMouseUp({ x: 60, y: 5, scrollBehavior: false })
192+
cy.get('body').should('not.have.css', 'cursor', 'no-drop')
193+
outline().its(1).should('equal', '2:Alpha')
194+
})
195+
})

‎apps/webapp/cypress/e2e/editor/toc/toc-row-alignment.cy.js‎

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,22 @@ const rowLink = ($list, text) => {
88
return link.closest('.toc__row-link')
99
}
1010

11-
// Retries until the row in `state` has its class and both titles start at one x.
11+
// Retries until the row in `state` has its class and the leaf title starts one
12+
// fold width left of the parent title (desktop leaf has no slot, #373 update 2026-11-04).
1213
const shouldAlign = (state) =>
1314
cy.get('.toc__list').should(($list) => {
1415
if (state) {
1516
expect(rowLink($list, state.text).closest('.toc__row'), state.text).to.have.class(state.cls)
1617
}
17-
const parentX = rowLink($list, 'Parent Row').getBoundingClientRect().left
18+
const parent = rowLink($list, 'Parent Row')
19+
const foldWidth = parent
20+
.closest('.toc__row')
21+
.querySelector('button.toc__fold-btn')
22+
.getBoundingClientRect().width
23+
const parentX = parent.getBoundingClientRect().left
1824
const leafX = rowLink($list, 'Leaf Row').getBoundingClientRect().left
19-
expect(Math.abs(parentX - leafX)).to.be.below(0.5)
25+
expect(foldWidth).to.be.above(0)
26+
expect(parentX - leafX).to.be.closeTo(foldWidth, 0.5)
2027
})
2128

2229
describe('TOC row alignment', () => {
@@ -36,7 +43,7 @@ describe('TOC row alignment', () => {
3643
cy.waitForToc()
3744
})
3845

39-
it('starts a leaf title where a parent title of the same level starts, in every row state', () => {
46+
it('starts a leaf title one fold width left of a parent title, in every row state', () => {
4047
shouldAlign()
4148
cy.getTocItem('Parent Row')
4249
.find('> .toc__row button.toc__fold-btn')

‎apps/webapp/cypress/support/commands.ts‎

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,8 @@ interface EditorWindow {
88
_editor?: import('@tiptap/core').Editor
99
/** Programmatic document builder – set in editor.tsx */
1010
_createDocumentFromStructure?: (doc: Record<string, unknown>) => boolean
11-
/** Programmatic heading move – set in editor.tsx */
12-
_moveHeading?: (
13-
sourceId: string,
14-
targetId: string,
15-
position: 'before' | 'after',
16-
level?: number
17-
) => boolean
11+
/** Programmatic heading move – set in editor.tsx; the slot sets the level */
12+
_moveHeading?: (sourceId: string, targetId: string, position: 'before' | 'after') => boolean
1813
/** Hierarchical selection helpers – set in Controllers.tsx */
1914
_editorSelect?: (level: SelectionLevel) => void
2015
_editorSelectAndCopy?: (level: SelectionLevel) => void
@@ -924,7 +919,6 @@ declare global {
924919
targetText: string,
925920
options?: {
926921
position?: 'before' | 'after'
927-
level?: number
928922
}
929923
): Chainable<void>
930924

@@ -952,12 +946,8 @@ Cypress.Commands.add('getTocItem', (headingText: string) => {
952946
/** Calls the editor directly via `window._moveHeading` to bypass dnd-kit. */
953947
Cypress.Commands.add(
954948
'dragTocItem',
955-
(
956-
sourceText: string,
957-
targetText: string,
958-
options: { position?: 'before' | 'after'; level?: number } = {}
959-
) => {
960-
const { position = 'after', level } = options
949+
(sourceText: string, targetText: string, options: { position?: 'before' | 'after' } = {}) => {
950+
const { position = 'after' } = options
961951

962952
cy.getTocItem(sourceText).then(($source) => {
963953
const sourceId = $source.attr('data-id')
@@ -977,7 +967,7 @@ Cypress.Commands.add(
977967
throw new Error('window._moveHeading is not available. Make sure editor is loaded.')
978968
}
979969

980-
const success = win._moveHeading(sourceId, targetId, position, level)
970+
const success = win._moveHeading(sourceId, targetId, position)
981971
if (!success) {
982972
throw new Error(`Failed to move heading "${sourceText}" to "${targetText}"`)
983973
}

‎apps/webapp/src/components/TipTap/CLAUDE.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ bun run migrate:nested-to-flat
2828
- Editor uses a flat heading schema: `heading block*`.
2929
- Sections are decoration-based.
3030
- `attrs['toc-id']` renders as `data-toc-id`.
31-
- Section reorder is TOC-only via `useTocDrag` / `moveHeading` + `moveSection`. There is no in-editor heading drag handle extension.
31+
- Section reorder is TOC-only via `useTocDrag` / `planTreeMove` + `applyTreeMove`, which calls `moveSection` (delete first, then insert). There is no in-editor heading drag handle extension.
3232
- Toolbar **Block style** (Title / Subtitle / H1–H6 / Normal) is outline role. Read and apply it through `TipTap/block-style/blockStyle`. Do not treat the H number as font size — that is HeadingScale. Names: [CONTEXT.md](../../../../../CONTEXT.md) §Pad outline.
3333
- **Clear formatting never changes Block style** (#392). One command, `ClearFormatting` in `TipTap/clearFormatting.ts`, serves the pad toolbar, the mobile format drawer, the chat composer and `Mod-\`. It removes every mark except `hyperlink` and `link`, in one transaction. A collapsed caret changes no text. It sets the stored marks to the caret's link marks only, so the next typed text is plain and a link is not split. Never call `clearNodes`, `setNode` or `lift` from it: a demoted heading loses its section, TOC row and Heading chat. The disabled state is `editor.can().clearFormatting()`. A selection or caret that holds only a link counts as nothing to clear. The pad and the composer both load it next to `ListGapJoin`.
3434

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,19 @@
1-
import type { Node as PMNode } from '@tiptap/pm/model'
1+
import type { Fragment } from '@tiptap/pm/model'
22
import type { Transaction } from '@tiptap/pm/state'
33

44
/**
5-
* One transaction (one undo). Insert-then-delete when moving up;
6-
* delete-then-insert when moving down so ProseMirror mapping stays valid.
5+
* One transaction (one undo). Always delete first: inserting first briefly holds
6+
* two copies of every `toc-id`. Returns the start of the inserted content.
77
*/
88
export function moveSection(
99
tr: Transaction,
10-
doc: PMNode,
1110
sectionFrom: number,
1211
sectionTo: number,
13-
targetPos: number
14-
): Transaction {
15-
const slice = doc.slice(sectionFrom, sectionTo)
16-
17-
if (targetPos < sectionFrom) {
18-
tr.insert(targetPos, slice.content)
19-
tr.delete(tr.mapping.map(sectionFrom), tr.mapping.map(sectionTo))
20-
} else {
21-
tr.delete(sectionFrom, sectionTo)
22-
tr.insert(tr.mapping.map(targetPos), slice.content)
23-
}
24-
25-
return tr
12+
targetPos: number,
13+
content: Fragment
14+
): number {
15+
tr.delete(sectionFrom, sectionTo)
16+
const insertAt = tr.mapping.map(targetPos)
17+
tr.insert(insertAt, content)
18+
return insertAt
2619
}

0 commit comments

Comments
 (0)