Skip to content

feat: add getEnclosing to @portabletext/editor/traversal#2709

Open
christianhg wants to merge 2 commits into
mainfrom
feat/get-enclosing
Open

feat: add getEnclosing to @portabletext/editor/traversal#2709
christianhg wants to merge 2 commits into
mainfrom
feat/get-enclosing

Conversation

@christianhg
Copy link
Copy Markdown
Member

Adds a generic getEnclosing(snapshot, path, predicate) to the traversal API. Returns the node at path if it matches the predicate, otherwise walks up ancestors until one matches.

import {getEnclosing} from '@portabletext/editor/traversal'

const row = getEnclosing(snapshot, anyPathInsideRow, isRow)

When predicate is a type predicate, the returned node narrows accordingly.

getEnclosingBlock is now a thin wrapper over getEnclosing. All existing getEnclosingBlock callers and tests are unchanged.

The generic version unblocks consumer behaviors that need "find the nearest X in scope" without writing a manual self-then-ancestor walk.

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented May 29, 2026

🦋 Changeset detected

Latest commit: 70745d9

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 12 packages
Name Type
@portabletext/editor Minor
@portabletext/plugin-character-pair-decorator Patch
@portabletext/plugin-emoji-picker Patch
@portabletext/plugin-input-rule Patch
@portabletext/plugin-markdown-shortcuts Patch
@portabletext/plugin-one-line Patch
@portabletext/plugin-paste-link Patch
@portabletext/plugin-sdk-value Patch
@portabletext/plugin-table Patch
@portabletext/plugin-typeahead-picker Patch
@portabletext/plugin-typography Patch
@portabletext/toolbar Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@vercel
Copy link
Copy Markdown

vercel Bot commented May 29, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
portable-text-editor-documentation Ready Ready Preview, Comment May 29, 2026 8:05pm
portable-text-example-basic Ready Ready Preview, Comment May 29, 2026 8:05pm
portable-text-playground Ready Ready Preview, Comment May 29, 2026 8:05pm
racetrack Ready Ready Preview, Comment May 29, 2026 8:05pm

Request Review

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 29, 2026

📦 Bundle Stats — @portabletext/editor

Compared against main (e0e974e2)

@portabletext/editor

Metric Value vs main (e0e974e)
Internal (raw) 767.0 KB +179 B, +0.0%
Internal (gzip) 147.2 KB +37 B, +0.0%
Bundled (raw) 1.37 MB +163 B, +0.0%
Bundled (gzip) 308.1 KB +29 B, +0.0%
Import time 96ms -1ms, -0.9%

@portabletext/editor/behaviors

Metric Value vs main (e0e974e)
Internal (raw) 467 B -
Internal (gzip) 207 B -
Bundled (raw) 424 B -
Bundled (gzip) 171 B -
Import time 2ms -0ms, -1.1%

@portabletext/editor/plugins

Metric Value vs main (e0e974e)
Internal (raw) 2.7 KB -
Internal (gzip) 894 B -
Bundled (raw) 2.5 KB -
Bundled (gzip) 827 B -
Import time 7ms -0ms, -0.3%

@portabletext/editor/selectors

Metric Value vs main (e0e974e)
Internal (raw) 80.0 KB +179 B, +0.2%
Internal (gzip) 14.6 KB +21 B, +0.1%
Bundled (raw) 76.0 KB +163 B, +0.2%
Bundled (gzip) 13.6 KB +13 B, +0.1%
Import time 8ms -0ms, -0.4%

@portabletext/editor/traversal

Metric Value vs main (e0e974e)
Internal (raw) 20.1 KB +209 B, +1.0%
Internal (gzip) 4.0 KB +19 B, +0.5%
Bundled (raw) 20.5 KB +177 B, +0.8%
Bundled (gzip) 4.0 KB +21 B, +0.5%
Import time 6ms -0ms, -0.6%

@portabletext/editor/utils

Metric Value vs main (e0e974e)
Internal (raw) 30.0 KB -
Internal (gzip) 6.1 KB -
Bundled (raw) 27.9 KB -
Bundled (gzip) 5.7 KB -
Import time 6ms -0ms, -1.0%

🗺️ . · ./behaviors · ./plugins · ./selectors · ./traversal · ./utils · Artifacts

Details
  • Import time regressions over 10% are flagged with ⚠️
  • Sizes shown as raw / gzip 🗜️. Internal bytes = own code only. Total bytes = with all dependencies. Import time = Node.js cold-start median.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant