Skip to content

Converts RichText Package to Typescript #69314

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

Open
wants to merge 15 commits into
base: trunk
Choose a base branch
from

Conversation

margolisj
Copy link
Contributor

@margolisj margolisj commented Feb 25, 2025

What?

Migrating the RichText package to Typescript. I'm working with and there are features that are not documented in the current types. I figured I might as well do the whole thing if allowed.

Why?

Type safety.

How?

Testing Instructions

Typecheck and unit tests.

@margolisj margolisj requested a review from ellatrix as a code owner February 25, 2025 18:31
Copy link

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: margolisj <margolisj@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@margolisj margolisj changed the title Converts Richtext Package to Typescript Converts RichText Package to Typescript Feb 25, 2025
@margolisj margolisj mentioned this pull request Feb 25, 2025
37 tasks
@t-hamano t-hamano added [Type] Code Quality Issues or PRs that relate to code quality [Package] Rich text /packages/rich-text labels Feb 26, 2025
@margolisj
Copy link
Contributor Author

So I've tried to leave everything as 1 to 1 as humanly possible. Currently stuck at a few important type decisions. I'm going to add a review of where I'll need some opinion / guidance. I've also left TODO's in the code at places that are more gnarly.

end: number;
formats: Array< RichTextFormatList | undefined >;
replacements: Array< RichTextFormat | undefined >;
// TODO: Should these really be optional?
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I believe this should be optional based on getting deeper into this problem.

replacements: Array< RichTextFormat >;
start: number;
end: number;
formats: Array< RichTextFormatList | undefined >;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Are formats undefined outside of just the test cases? Same with the replacements below.

*/
export function isFormatEqual( format1, format2 ) {
export function isFormatEqual(
format1: RichTextFormat | null,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Could be undefined instead of null.

@@ -17,7 +12,10 @@ import type { RichTextValue } from './types';
export function isCollapsed( {
start,
end,
}: RichTextValue ): boolean | undefined {
}: {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure if these types will pass when converting the components.

@@ -35,10 +36,11 @@ describe( 'split', () => {
text: 'o three',
},
];
const result = split( deepFreeze( record ), 6, 6 );
// TODO: These were taking too many parameters
const result = split( deepFreeze( record ), 6 );
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unsure about this parameter change.

const doc = document.implementation.createHTMLDocument( '' );
doc.body.innerHTML = HTML;
return doc.body.firstChild;
}

// function createElement( HTML: string ): HTMLElement {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Possibly want to swap to creating HTMLElements. JSDoc values were HTMLElements iirc yet using createNode.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Package] Rich text /packages/rich-text [Type] Code Quality Issues or PRs that relate to code quality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants