contentstack / app-sdk

The Contentstack App SDK allows you to customize your applications.
MIT License
1 stars 3 forks source link

IRteParam missing types? #114

Open flippidippi opened 1 month ago

flippidippi commented 1 month ago

It seems like IRteParam is missing types, like rte.getFieldConfig and more. We are trying to create a custom RTE plugin and need to get the field config but need to use @ts-expect-error to access.

abhishek305 commented 3 weeks ago

Hi @flippidippi, We do not have handler support for rte.getFieldConfig(), did you mean rte.getConfig? For rte.getConfig we do not have type support added. This is planned for the next release. Let me know if you have any further questions.

flippidippi commented 3 weeks ago

This is the example I have. If we needed to be able to control the color of the highlight at a field level config.

const Highlight = RTE('highlight', rte => {
    // Get the field config
    // @ts-expect-error
    const fieldConfig = rte.getFieldConfig()

    return {
      title: 'Highlight',
      icon: <Icon style={{ padding: '0 6px' }} icon='Edit' size='original' />,
      display: ['toolbar', 'hoveringToolbar'],
      elementType: ['text'],
      render: (props: any) => {
        return (
          <span style={{ background: fieldConfig?.color ?? 'rgba(251, 243, 219, 1)' }}>
            {props.children}
          </span>
        )
      }
    }
  })
abhishek305 commented 3 weeks ago

Hi @flippidippi Thanks for the snippet, but we do not have any handler support for rte. getFieldConfig Its rte.getConfig and we'll have a fix for type missing for rte.getConfig handler in next release i.e. v2.0.3. Let me know if there's anything I can help with.

flippidippi commented 3 weeks ago

So does rte.getConfig get the config at the field level? Or is there a supported way to do that?

abhishek305 commented 3 weeks ago

So does rte.getConfig get the config at the field level? Or is there a supported way to do that?

Yes, @flippidippi rte.getConfig retrieves the values set in config UI location. For Eg --> If you are saving any color i.e. fieldConfig.color Similar to shown in above comments.

flippidippi commented 2 weeks ago

I actually don't see rte.getConfig in the types either, neither seem to be on IRteParam.

And this is a screenshot of the difference between the data I get back from each. I don't see the field config in the rte.getConfig.

image

abhishek305 commented 2 weeks ago

@flippidippi the type support for rte.getConfig in IRteParam would be a part of next release. An example usage post-release for reference

 const examplePlugin = RTE("testApp", async (rte) => {
       const config = await (rte as IRteParam).getConfig();
}

Where IRteParams would have getConfig as getConfig: <T>() => { [key: string]: T };

Will keep you posted once it is released.