Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from
Aug 12, 2024

Conversation

mrdivyansh
Copy link
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

Copy link

vercel bot commented Jul 29, 2024

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
Copy link

github-actions bot commented Jul 29, 2024

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
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
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

Copy link
Collaborator

@etrepum etrepum left a comment

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
Contributor Author

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

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