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

Bug-Refactor-Type-determination-logic-in-turn-into-dropdown-component #3239

Conversation

kumarajay0412
Copy link
Contributor

@kumarajay0412 kumarajay0412 commented Jun 4, 2024

The changes in turn-into-dropdown-component refactor the logic used to determine the type of block in the editor. The new implementation imports additional functions (getNodeEntries, isBlock) and uses them to iterate over block nodes within the editor's selection. It then determines a common type or defaults to 'paragraph' if type differ among nodes. This approach replaces the previous method of finding a single node and checking its type, making the new logic more robust and capable of handling multiple nodes with potentially different types.

I have discussed this topic in detail here

Copy link

changeset-bot bot commented Jun 4, 2024

🦋 Changeset detected

Latest commit: 6bcce76

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

This PR includes changesets to release 1 package
Name Type
@udecode/plate-ui 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

Copy link

vercel bot commented Jun 4, 2024

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

Name Status Preview Comments Updated (UTC)
plate ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 9, 2024 10:40am

@zbeyens
Copy link
Member

zbeyens commented Jun 4, 2024

Thanks! Could you update changelog.mdx?

Comment on lines 119 to 123
if (!isDefined(commonSelection)) {
commonSelection = type;
} else if (commonSelection !== type) {
commonSelection = undefined;
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Thanks for the PR! It looks like this logic might cause the commonSelection variable to flip between undefined and some value. For example, if the types we get are ['typeA', 'typeB', 'typeC', 'typeD', 'typeE'], the value of commonSelection after each step is ['typeA', undefined, 'typeC', undefined, 'typeE'].

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks @12joan will improve this logic which will prevent flip with below logic

Screenshot 2024-06-05 at 12 51 44 AM

Copy link
Collaborator

@12joan 12joan Jun 4, 2024

Choose a reason for hiding this comment

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

This has the same problem.

type    commonSelection     uniqueTypeFound
------------------------------------------
N/A     undefined           false
typeA   typeA               true
typeB   undefined           false
typeC   typeC               true
typeD   undefined           false
typeE   typeE               true

Maybe get the type of the first node and then use nodes.every to check if they all match? I think that code would be easier to read than using mutable variables and nested conditionals.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Screenshot 2024-06-05 at 2 05 16 AM

Comment on lines 112 to 114
const codeBlockEntries = getNodeEntries(editor, {
match: (n) => isBlock(editor, n),
});
Copy link
Collaborator

Choose a reason for hiding this comment

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

Have you tested this for selections containing nested blocks, such as traditional (non-indent) lists?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

By non-indent lists you meant bulleted list and numbered list right if you are it is working on them

Copy link
Collaborator

Choose a reason for hiding this comment

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

Plate has two kinds of lists. Indent lists, like on the main playground, don't use nesting. Traditional lists, which are more accessible and follow the standard UL, OL and LI nesting structure, might pose an issue since your getNodeEntries query will return both the outer list element and all list item elements.

Copy link
Collaborator

@12joan 12joan Jun 4, 2024

Choose a reason for hiding this comment

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

I think passing mode: 'highest' to getNodeEntries might be a workable fix, but you would need to test this on https://platejs.org/docs/list. The 'highest' mode tells getNodeEntries not to descend into the children of any matching node.

Copy link
Contributor Author

@kumarajay0412 kumarajay0412 Jun 4, 2024

Choose a reason for hiding this comment

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

i tested and code is working on https://platejs.org/docs/list.

Hey @12joan thanks a lot for taking out time and PR review would keep you valuable comments in mind for my future pull requests

@kumarajay0412 kumarajay0412 changed the title Bug-Refactor-Type-determination-logic-in-turn-into-dropdown-componet Bug-Refactor-Type-determination-logic-in-turn-into-dropdown-component Jun 4, 2024
@kumarajay0412
Copy link
Contributor Author

Thanks! Could you update changelog.mdx?

@zbeyens I hope have followed the correct format for adding changeset

let commonSelection: string | undefined;
let uniqueTypeFound = false;
let firstNodeType: string = ELEMENT_PARAGRAPH;
let allNodesMatchFirstNode = false;
const codeBlockEntries = getNodeEntries(editor, {
Copy link
Collaborator

Choose a reason for hiding this comment

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

All looks good now. The only other thing I can see is you might want to change this variable name.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@zbeyens
Copy link
Member

zbeyens commented Jun 7, 2024

@kumarajay0412 Looks good, thanks! Could you update changelog.mdx?

@kumarajay0412 kumarajay0412 requested a review from 12joan June 9, 2024 10:36
@zbeyens zbeyens merged commit cd82934 into udecode:main Jun 9, 2024
4 checks passed
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.

3 participants