Commit 0132a97
authored
feat(ui): story-aware selection state and capture/restore (SD-2954) (#3166)
* feat(ui): add ui.viewport.getHost and positionAt (SD-2943)
Two primitives consumers building custom UI keep reaching for and not
finding on the public surface:
ui.viewport.getHost() returns the editor's painted host element so
custom-UI components scope DOM listeners to the editor without a CSS
class filter. The information already lives on
presentationEditor.visibleHost; this lifts it onto the controller.
ui.viewport.positionAt({ x, y }) resolves a viewport coordinate to a
caret position on the routed editor's PM document, returning both the
SelectionPoint and the SelectionTarget shapes so consumers can pass
the result straight to editor.doc.insert / replace / etc. The natural
pair to entityAt: while entityAt answers "what entity is under this
point?", positionAt answers "what caret position is under this
point?" — the missing primitive that lets right-click menus offer
"Paste here" / "Insert at this point" honestly, instead of dispatching
against the user's previous selection.
Both methods scope to the controller's painted host: a multi-instance
page can't have one controller's positionAt return positions in
another's PM doc, and post-destroy calls return null.
Tests cover the happy path, the no-editor-mounted case, and the
missing-posAtCoords stub case.
* fix(ui): canonical sdBlockId fallback + story scope on positionAt (SD-2943)
readBlockId now uses the sdBlockId ?? id ?? blockId fallback the
selection resolver already applies, so positionAt resolves paragraph
clicks instead of returning null. Adds PresentationEditor.getActiveStoryLocator
(unifies story-session and header/footer-session locators) and threads
the result onto SelectionPoint.story / SelectionTarget.story so doc-api
operations route to the active story instead of falling back to body.
* feat(ui): story-aware selection state and capture/restore (SD-2954)
The controller stamps the active story locator onto the live
TextTarget when the routed editor is a header/footer/footnote/endnote,
so state.selection.target / selectionTarget and ui.selection.capture()
all carry the same routing information ui.viewport.positionAt got in
SD-2943. ui.selection.restore now compares the captured story against
the active surface and returns a typed 'stale' on mismatch instead of
falling through to a less-specific resolver failure. Captures with no
story keep the prior body/default behavior.
The fix is scoped to the controller surface. Direct
editor.doc.selection.current() calls still return body-scoped targets;
threading story through the lower-level resolver is a separate change.
* fix(ui): jsdoc placement + restore guard order (SD-2954)
Move readActiveStoryLocator and attachStoryToTextTarget below
textTargetToSelectionTarget so the existing JSDoc reattaches to its
function (it was orphaned between two JSDoc blocks).
Move the SD-2954 story-mismatch check after the isEditable / setTextSelection
guards so a header capture restored against a viewing-mode editor
still surfaces 'read-only', matching what body captures already see
in the same condition. Adds a regression test covering the read-only
+ story-capture path.
* fix(ui): resolve story locator via resolveToolbarSources for SD-2954
readActiveStoryLocator was reading hostEditor.presentationEditor
directly, missing the legacy _presentationEditor field and the
superdocStore.documents[].getPresentationEditor() lookup that
resolveToolbarSources covers. Mounts using either fallback would still
report body-scoped selection state and return 'stale' for valid story
captures.
Route the locator lookup through resolveToolbarSources so all three
documented presentation-resolution paths surface the active story.
Selection-restore drops its duplicate helper and accepts the
pre-resolved locator from the controller, removing the separate code
path. Adds a regression test covering the _presentationEditor fallback.1 parent ef85846 commit 0132a97
4 files changed
Lines changed: 398 additions & 6 deletions
File tree
- packages/super-editor/src/ui
Lines changed: 167 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
552 | 552 | | |
553 | 553 | | |
554 | 554 | | |
| 555 | + | |
| 556 | + | |
| 557 | + | |
| 558 | + | |
| 559 | + | |
| 560 | + | |
| 561 | + | |
| 562 | + | |
| 563 | + | |
| 564 | + | |
| 565 | + | |
| 566 | + | |
| 567 | + | |
| 568 | + | |
| 569 | + | |
| 570 | + | |
| 571 | + | |
| 572 | + | |
| 573 | + | |
| 574 | + | |
| 575 | + | |
| 576 | + | |
| 577 | + | |
| 578 | + | |
| 579 | + | |
| 580 | + | |
| 581 | + | |
| 582 | + | |
| 583 | + | |
| 584 | + | |
| 585 | + | |
| 586 | + | |
| 587 | + | |
| 588 | + | |
| 589 | + | |
| 590 | + | |
| 591 | + | |
| 592 | + | |
| 593 | + | |
| 594 | + | |
| 595 | + | |
| 596 | + | |
| 597 | + | |
| 598 | + | |
| 599 | + | |
| 600 | + | |
| 601 | + | |
| 602 | + | |
| 603 | + | |
| 604 | + | |
| 605 | + | |
| 606 | + | |
| 607 | + | |
| 608 | + | |
| 609 | + | |
| 610 | + | |
| 611 | + | |
| 612 | + | |
| 613 | + | |
| 614 | + | |
| 615 | + | |
| 616 | + | |
| 617 | + | |
| 618 | + | |
| 619 | + | |
| 620 | + | |
| 621 | + | |
| 622 | + | |
| 623 | + | |
| 624 | + | |
| 625 | + | |
| 626 | + | |
| 627 | + | |
| 628 | + | |
| 629 | + | |
| 630 | + | |
| 631 | + | |
| 632 | + | |
| 633 | + | |
| 634 | + | |
| 635 | + | |
| 636 | + | |
| 637 | + | |
| 638 | + | |
| 639 | + | |
| 640 | + | |
| 641 | + | |
| 642 | + | |
| 643 | + | |
| 644 | + | |
| 645 | + | |
| 646 | + | |
| 647 | + | |
| 648 | + | |
| 649 | + | |
| 650 | + | |
| 651 | + | |
| 652 | + | |
| 653 | + | |
| 654 | + | |
| 655 | + | |
| 656 | + | |
| 657 | + | |
| 658 | + | |
| 659 | + | |
| 660 | + | |
| 661 | + | |
| 662 | + | |
| 663 | + | |
| 664 | + | |
| 665 | + | |
| 666 | + | |
| 667 | + | |
| 668 | + | |
| 669 | + | |
| 670 | + | |
| 671 | + | |
| 672 | + | |
| 673 | + | |
| 674 | + | |
| 675 | + | |
| 676 | + | |
| 677 | + | |
| 678 | + | |
| 679 | + | |
| 680 | + | |
| 681 | + | |
| 682 | + | |
| 683 | + | |
| 684 | + | |
| 685 | + | |
| 686 | + | |
| 687 | + | |
| 688 | + | |
| 689 | + | |
| 690 | + | |
| 691 | + | |
| 692 | + | |
| 693 | + | |
| 694 | + | |
| 695 | + | |
| 696 | + | |
| 697 | + | |
| 698 | + | |
| 699 | + | |
| 700 | + | |
| 701 | + | |
| 702 | + | |
| 703 | + | |
| 704 | + | |
| 705 | + | |
| 706 | + | |
| 707 | + | |
| 708 | + | |
| 709 | + | |
| 710 | + | |
| 711 | + | |
| 712 | + | |
| 713 | + | |
| 714 | + | |
| 715 | + | |
| 716 | + | |
| 717 | + | |
| 718 | + | |
| 719 | + | |
| 720 | + | |
| 721 | + | |
555 | 722 | | |
556 | 723 | | |
557 | 724 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
302 | 302 | | |
303 | 303 | | |
304 | 304 | | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
305 | 358 | | |
306 | 359 | | |
307 | 360 | | |
| |||
605 | 658 | | |
606 | 659 | | |
607 | 660 | | |
608 | | - | |
| 661 | + | |
| 662 | + | |
| 663 | + | |
| 664 | + | |
| 665 | + | |
| 666 | + | |
| 667 | + | |
| 668 | + | |
| 669 | + | |
| 670 | + | |
| 671 | + | |
| 672 | + | |
| 673 | + | |
| 674 | + | |
609 | 675 | | |
610 | 676 | | |
611 | 677 | | |
| |||
1761 | 1827 | | |
1762 | 1828 | | |
1763 | 1829 | | |
| 1830 | + | |
| 1831 | + | |
| 1832 | + | |
| 1833 | + | |
| 1834 | + | |
| 1835 | + | |
| 1836 | + | |
1764 | 1837 | | |
1765 | | - | |
| 1838 | + | |
| 1839 | + | |
| 1840 | + | |
| 1841 | + | |
1766 | 1842 | | |
1767 | 1843 | | |
1768 | 1844 | | |
| |||
0 commit comments