Skip to content

[@lexical/selection] Feature: yield target to style patch fn - #6472

Merged
etrepum merged 2 commits into
meta:mainfrom
mrdivyansh:patch_style_taget
Aug 12, 2024
Merged

etrepum merged 2 commits into
meta:mainfrom
mrdivyansh:patch_style_taget

Conversation

@mrdivyansh

Copy link
Copy Markdown
Contributor

Description

$patchStyleText doesn't expose the target to the CSS property patch function. However, it can be very helpful when the next style value may depend on the target node/selection.

Test plan

Added unit tests

Before

function $patchStyleText(
  selection: BaseSelection,
  patch: Record<
    string,
    | string
    | null
    | (( currentStyleValue: string | null) => string)
  >,
): void

After

function $patchStyleText(
  selection: BaseSelection,
  patch: Record<
    string,
    | string
    | null
    | ((currentStyleValue: string | null, target: TextNode | RangeSelection ) => string)
  >,
): void

@vercel

vercel Bot commented Jul 29, 2024 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
lexical ✅ Ready (Inspect) Visit Preview 💬 Add feedback Aug 12, 2024 3:31pm
lexical-playground ✅ Ready (Inspect) Visit Preview 💬 Add feedback Aug 12, 2024 3:31pm

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Jul 29, 2024
@github-actions

github-actions Bot commented Jul 29, 2024 •

Copy link
Copy Markdown

size-limit report 📦

Path Size
lexical - cjs 29.39 KB (0%)
lexical - esm 29.17 KB (0%)
@lexical/rich-text - cjs 37.74 KB (0%)
@lexical/rich-text - esm 31.02 KB (0%)
@lexical/plain-text - cjs 36.32 KB (0%)
@lexical/plain-text - esm 28.37 KB (0%)
@lexical/react - cjs 39.65 KB (0%)
@lexical/react - esm 32.47 KB (0%)

string | null | ((currentStyleValue: string | null) => string)
| string
| null
| ((currentStyleValue: string | null, _target: typeof target) => string)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a need to underscore this parameter name? Does it get caught by the eslint shadow rule?

Suggested change
| ((currentStyleValue: string | null, _target: typeof target) => string)
| ((currentStyleValue: string | null, target: typeof target) => string)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, shadow rule complains.

Screenshot 2024-08-01 at 5 24 59 PM

@etrepum etrepum left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, it seems reasonable to pass this information along and it's great that you've also added tests for this feature! One thing that might be a bit counter-intuitive is that the target is not necessarily the same target that is passed to $patchStyle since it will only be a RangeSelection when the given selection is collapsed

@mrdivyansh

Copy link
Copy Markdown
Contributor Author

@etrepum , is there anything I need to do to get this PR merged? Thanks for approving the PR.

This branch was successfully deployed

2 active deployments
Preview – lexical-playground — f0b76645 Deployed Aug 12, 2024 by vercel[bot]
Preview – lexical — f0b76645 Deployed Aug 12, 2024 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants