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

Support for nested richText fields #191

Open
carstenblt opened this issue Aug 20, 2024 · 1 comment
Open

Support for nested richText fields #191

carstenblt opened this issue Aug 20, 2024 · 1 comment

Comments

@carstenblt
Copy link

carstenblt commented Aug 20, 2024

Currently, a

richText {
  Block {
    richText
  }
}

structure fails, because findField cannot resolve the lexical editorConfig.

I don't really feel comfortable suggesting a fix, as I don't completely understand what's going on. I am also not sure the dotNotation always works as expected. I have the following field in my doc:

{
  name: "content",
  type: "richText",
  localized: true,
  editor: lexicalEditor({
    BlocksFeature({
      blocks: [{
        slug: "Accordion",
          fields: [
            {
              name: "items",
              type: "array",
              fields: [
                {
                  name: "title",
                  type: "text",
                },
               {
                 name: "content",
                 type: "richText",
                 editor: lexicalEditor({}),
               },
             ],
           },
        ],
      }],
    }),
   ],
  }),
}

In my case this results in blocks.65c822753102c86d651d3512.Accordion.items.65c8227d3102c86d651d3513.content. Now this does not contain the full hierarchy - I might have fields content1 and content2, that contain similar richText. findField would then not be able to differentiate between them, as the toplevel field name is not included in the notation and we do not check the ids in the document.

Then, getLocalizedFields does not contain the nested richText field, (and it does not contain information about hierarchy, that would have to match hierarchy information from the dotNotation). In my case, getLocalizedFields returns the toplevel content field (and also the toplevel title field that I have additionally...) and not the required nested fields.

@thompsonsj
Copy link
Owner

thompsonsj commented Oct 28, 2024

Finally got this working 😅

It was one of the trickier aspects of the plugin functionality. In case it's of interest, changes such as #161, #194 and #215 make a change where Lexical block fields are treated as a separate 'document' that looks like:

{
  blocks: [
      // blocks filtered from the Lexical field
    ]
}

A subfolder is created on Crowdin to contain translation files for blocks extracted from a Lexical field. To keep track of these translations, a new document is created in CrowdinArticleDirectories with a parent of CrowdinArticleDirectories document to keep track of its position in the hierarchy.

By using the above approach, a lot of plugin logic is reused.

The code is getting messy for sure but the tests are proving robust. Hopefully will have time to refactor and get the code back to making sense!

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

No branches or pull requests

2 participants