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

Add remark-slate source code to Plate #2175

Merged
merged 1 commit into from
Feb 1, 2023
Merged

Conversation

12joan
Copy link
Collaborator

@12joan 12joan commented Jan 30, 2023

Description

Fixes #2173

Adds a subset of the remark-slate source code to Plate for ease of modification. To comply with remark-slate's MIT license, I've added @hanford's name to Plate's LICENSE file.

Rather than copy over remark-slate's tests, I've added tests for each element type supported by deserializeMd. A few element types produce incorrectly structured (although mostly still usable) Slate nodes. I'll un-skip the relevant tests once those are fixed. Until then, this PR is a draft. Ready for merge.

To do

@changeset-bot
Copy link

changeset-bot bot commented Jan 30, 2023

🦋 Changeset detected

Latest commit: e382038

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

This PR includes changesets to release 4 packages
Name Type
@udecode/plate-serializer-md Minor
@udecode/plate-headless Minor
@udecode/plate Minor
@udecode/plate-ui Minor

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

@vercel
Copy link

vercel bot commented Jan 30, 2023

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

Name Status Preview Comments Updated
plate ✅ Ready (Inspect) Visit Preview 💬 Add your feedback Jan 31, 2023 at 5:11PM (UTC)
plate-examples ✅ Ready (Inspect) Visit Preview 💬 Add your feedback Jan 31, 2023 at 5:11PM (UTC)

@ghost
Copy link

ghost commented Jan 30, 2023

👇 Click on the image for a new way to code review
  • Make big changes easier — review code in small groups of related files

  • Know where to start — see the whole change at a glance

  • Take a code tour — explore the change with an interactive tour

  • Make comments and review — all fully sync’ed with github

    Try it now!

Review these changes using an interactive CodeSee Map

Legend

CodeSee Map Legend

@vercel vercel bot temporarily deployed to Preview – plate-examples January 30, 2023 17:41 Inactive
@vercel vercel bot temporarily deployed to Preview – plate January 30, 2023 17:42 Inactive
Copy link
Member

@zbeyens zbeyens left a comment

Choose a reason for hiding this comment

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

Great! Left a few comments

packages/serializers/md/src/remark-slate/index.ts Outdated Show resolved Hide resolved
packages/serializers/md/src/remark-slate/plugin.ts Outdated Show resolved Hide resolved
packages/serializers/md/src/remark-slate/ast-types.ts Outdated Show resolved Hide resolved
packages/serializers/md/src/remark-slate/deserialize.ts Outdated Show resolved Hide resolved
@vercel vercel bot temporarily deployed to Preview – plate-examples January 30, 2023 20:02 Inactive
@vercel vercel bot temporarily deployed to Preview – plate January 30, 2023 20:03 Inactive
@vercel vercel bot temporarily deployed to Preview – plate-examples January 30, 2023 20:37 Inactive
@vercel vercel bot temporarily deployed to Preview – plate January 30, 2023 20:38 Inactive
@vercel vercel bot temporarily deployed to Preview – plate-examples January 31, 2023 11:14 Inactive
@vercel vercel bot temporarily deployed to Preview – plate January 31, 2023 11:14 Inactive
@12joan
Copy link
Collaborator Author

12joan commented Jan 31, 2023

@zbeyens I've made the requested changes. Element and mark types turned out not to be necessary; TDescendant, TElement and TText sufficed.

I've also refactored the deserialization rules into an options object, which I'll expose in createDeserializeMdPlugin once the code settles down a little. That ought to be helpful for use cases like this one.

This might be a good time for you to take another look at the code and make sure the coding style is consistent with Plate (should I be using a T prefix for the types, for instance?). No hurry though; there's still plenty to do before the PR is ready to merge.

@vercel vercel bot temporarily deployed to Preview – plate January 31, 2023 11:56 Inactive
@vercel vercel bot temporarily deployed to Preview – plate-examples January 31, 2023 12:02 Inactive
@vercel vercel bot temporarily deployed to Preview – plate-examples January 31, 2023 12:36 Inactive
@vercel vercel bot temporarily deployed to Preview – plate January 31, 2023 12:37 Inactive
@vercel vercel bot temporarily deployed to Preview – plate January 31, 2023 12:43 Inactive
@vercel vercel bot temporarily deployed to Preview – plate-examples January 31, 2023 12:51 Inactive
@12joan
Copy link
Collaborator Author

12joan commented Jan 31, 2023

A couple of objects in the refactored remark-slate need to call getPluginType with editor, so I've added editor: PlateEditor<V> where V extends Value to RemarkPluginOptions and various other types and functions. I managed to get it working in commit 5c4cf6f, but I don't know how to get past this error in the latest WIP commit:

Fixed with ({ ... } as unknown) as RemarkPluginOptions<V>. I'm not sure this is the best solution, but it makes the code compile.

zbeyens
zbeyens previously approved these changes Jan 31, 2023
@12joan
Copy link
Collaborator Author

12joan commented Jan 31, 2023

Fixed with ({ ... } as unknown) as RemarkPluginOptions<V>. I'm not sure this is the best solution, but it makes the code compile.

Never mind, things started breaking again the moment I added createDeserializeMdPlugin() to the tests.

    packages/serializers/md/src/deserializer/utils/deserializeMd.spec.tsx:14:15 - error TS2322: Type 'PlatePlugin<DeserializeMdPlugin<Value>, Value, PlateEditor<Value>>' is not assignable to type 'PlatePlugin<AnyObject, Value, PlateEditor<Value>>'.
      Type 'PlatePlugin<DeserializeMdPlugin<Value>, Value, PlateEditor<Value>>' is not assignable to type '{ editor?: Nullable<{ insertData?: PlatePluginInsertData<Value> | undefined; }> | undefined; handlers?: Nullable<DOMHandlers<AnyObject, Value, PlateEditor<...>> & { ...; }> | undefined; ... 6 more ...; type?: string | undefined; }'.
        Types of property 'handlers' are incompatible.
          Type 'Nullable<DOMHandlers<DeserializeMdPlugin<Value>, Value, PlateEditor<Value>> & { onChange?: OnChange<DeserializeMdPlugin<Value>, Value, PlateEditor<...>> | undefined; }> | undefined' is not assignable to type 'Nullable<DOMHandlers<AnyObject, Value, PlateEditor<Value>> & { onChange?: OnChange<AnyObject, Value, PlateEditor<Value>> | undefined; }> | undefined'.
            Type 'Nullable<DOMHandlers<DeserializeMdPlugin<Value>, Value, PlateEditor<Value>> & { onChange?: OnChange<DeserializeMdPlugin<Value>, Value, PlateEditor<...>> | undefined; }>' is not assignable to type 'Nullable<DOMHandlers<AnyObject, Value, PlateEditor<Value>> & { onChange?: OnChange<AnyObject, Value, PlateEditor<Value>> | undefined; }>'.
              Types of property 'onCopy' are incompatible.
                Type 'DOMHandler<DeserializeMdPlugin<Value>, Value, PlateEditor<Value>, ClipboardEvent<Element>> | null | undefined' is not assignable to type 'DOMHandler<AnyObject, Value, PlateEditor<Value>, ClipboardEvent<Element>> | null | undefined'.
                  Type 'DOMHandler<DeserializeMdPlugin<Value>, Value, PlateEditor<Value>, ClipboardEvent<Element>>' is not assignable to type 'DOMHandler<AnyObject, Value, PlateEditor<Value>, ClipboardEvent<Element>>'.

    14     plugins: [createDeserializeMdPlugin()],
                     ~~~~~~~~~~~~~~~~~~~~~~~~~~~

@zbeyens Can you see what's wrong here? I can't tell what's different between this plugin's type and, say, createResetNodePlugin's that might be causing this error.

Relevant files:

@zbeyens
Copy link
Member

zbeyens commented Jan 31, 2023

@12joan you can abuse of as any in test files, this is a less important place. For more context, some plate types are challenging to get right with generics and the plugins array parameter is one of them.

so, plugins: [createDeserializeMdPlugin() as any],

Add tests for deserializeMd

Add relevent parts of remark-slate

Linter fixes

Fix function exports

Move element types out of options

Replace custom types with Plate types

Refactor deserialization rules into options

Fix blockquotes

Drop strikethrough support

Fix images

Fix code blocks

Fix lists

Fix <br>

Fix generics

Make rules configurable through Plate plugin options

Fix images (again)

Add changesets
@12joan 12joan marked this pull request as ready for review January 31, 2023 17:01
@12joan 12joan requested a review from dylans as a code owner January 31, 2023 17:01
@vercel vercel bot temporarily deployed to Preview – plate-examples January 31, 2023 17:10 Inactive
@vercel vercel bot temporarily deployed to Preview – plate January 31, 2023 17:11 Inactive
@12joan 12joan mentioned this pull request Jan 31, 2023
@zbeyens zbeyens merged commit b42d095 into udecode:main Feb 1, 2023
@12joan 12joan deleted the deserialize-md branch February 1, 2023 11:22
@github-actions github-actions bot mentioned this pull request Feb 1, 2023
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.

deserialiseMd created an invalid TElement array
2 participants