Skip to content
New issue

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

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

Already on GitHub? # to your account

Refactor - Migrate to Plate #575

Merged
merged 54 commits into from
Jan 14, 2025

Conversation

kudlajz
Copy link
Contributor

@kudlajz kudlajz commented Nov 13, 2024

This is the first part of the migration to Plate, replacing the main React component and all the code that depends on it with the Plate counterpart or Plate types.

For now, most of the existing plugins (extensions) have been left as-is so the PR doesn't become massive. This should also make sure that the editor behaviour stays the same.

One of the changes I've made has been to the plugins prop of the Editor component, which now accepts an array of PlatePlugin interface, allowing us to provide plugins from the outside, which is something we're planning to do eventually.

In the meantime, when this PR is in review and we can test the editor in Prezly, I'll work on refactoring the plugins to use Plate plugin approach and/or replacing them with existing Plate plugins to get rid of as much custom code as possible.

@kudlajz kudlajz self-assigned this Nov 13, 2024
@kudlajz kudlajz marked this pull request as draft November 13, 2024 19:10
@kudlajz kudlajz force-pushed the feature/dev-14744-explore-migrating-to-plate-editor branch from c150327 to b2d7993 Compare November 21, 2024 11:33
@kudlajz kudlajz requested a review from e1himself January 9, 2025 16:28
@kudlajz
Copy link
Contributor Author

kudlajz commented Jan 9, 2025

Addressed all the remarks and fixed the encountered bugs, so this is ready for a review again 🙂 @e1himself @yuriyyakym

@kudlajz kudlajz marked this pull request as ready for review January 9, 2025 16:33
Comment on lines +126 to +128
editor: createEditorFactory(() =>
createEditor(createSlateEditor(), () => extensions, [withReact, withHistory]),
),
Copy link
Contributor

Choose a reason for hiding this comment

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

Hm... Isn't it weird that the tests hyperscript is not using the Plate's editor implementation? 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

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

A little bit, yes. It is on my roadmap to rework the tests to use Plate (soon). It will be required when we start refactoring plugins/extensions to Plate plugins as otherwise we can't use them in tests.

@@ -25,7 +22,7 @@ import {
} from './plugins';

export function createEditor(
baseEditor: Editor,
baseEditor: SlateEditor,
getExtensions: () => Extension[],
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe not a question for this round of refactoring, but do you know why we pass the extensions as a getter callback? Why not pass it directly as an array?

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Judging from this code, it seems like it's just there so the editor is not recreated when/if extensions array changes? 🤔

Copy link
Contributor

@e1himself e1himself left a comment

Choose a reason for hiding this comment

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

I've checked the updates, everything looks reasonable.
Good job Lukas 👍

I am still struggling with keeping in mind different sources of types and helper functions. Just as an idea (not for this PR probably): what do you think if we introduce an intermediate #types module that would re-export the editor/element/node types to use inside the codebase? This way there will be a single source of types, and hopefully, it will make things less confusing?

@e1himself e1himself changed the title POC - Migrating to Plate Refactor - Migrate to Plate Jan 14, 2025
@kudlajz
Copy link
Contributor Author

kudlajz commented Jan 14, 2025

what do you think if we introduce an intermediate #types module that would re-export the editor/element/node types to use inside the codebase? This way there will be a single source of types, and hopefully, it will make things less confusing?

Can you clarify this a little bit more? Are you saying we would have our Element that would be a re-export of TElement from Plate for example?

@kudlajz kudlajz merged commit c662384 into main Jan 14, 2025
9 checks passed
@kudlajz kudlajz deleted the feature/dev-14744-explore-migrating-to-plate-editor branch January 14, 2025 12:06
# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants