pdfme / pdfme

A TypeScript based PDF generator library, made with React.
https://pdfme.com
MIT License
2.19k stars 194 forks source link

changeSchemas function when used on custom widgets in extends text plugin removing all other properties of text applied to it. #416

Closed vpn-dev closed 3 months ago

vpn-dev commented 4 months ago

Describe the bug

I extended text plugin with some extra properties like backgroundColorFromTheme in which colors are shown in select menu, i added onChange handle for this select in propPanel which uses changeSchemas function to update value of original background color property but it also changes other properties of text which are not commited to earlier version.

To Reproduce

Expected behavior

It should only change shemas that are provided in function params not all ...

Your Environment

- pdfme package(@pdfme/generator or @pdfme/ui): all packages 3.2.1
- pdfme version: 3.2.1
- Operating system: Ubuntu 22
- Node.js version or Browser name & version: node 18.19.0 chrome

Your Error Log

No error log its, just wrong output kind of thing

Additional context

No response

vpn-dev commented 4 months ago

@hand-dot can you have a look at this? we can discuss this issue..

hand-dot commented 4 months ago

Hey @vpn-dev,

Could you show me the code?

vpn-dev commented 4 months ago

Absolutely, here is screenshot of code of my extended property on schema in propPanel for textPlugin font-color-plugin

vpn-dev commented 4 months ago

@hand-dot as you can see in the above code snippet i have extended text schema with fontColorFromTheme property, on which I have added onChange to change actual fontColor property of text schema but this is causing all active changes to schema go away. if none is selected from fontColorFromTheme property I am just resetting the fontColor Value otherwise I am extracting the value from my theme object which is a material ui theme object , I am doing this to use same template for multiple themes.

I tried other way as well by assigning value to schema.fontColor in uiRender function but this change is not immediate there.

Ideally it should work, as in UseDynamicSizeWidget you have done the same thing by calling changeSchemas on onChange of checkbox.

Can you suggest better way

hand-dot commented 4 months ago

@vpn-dev

The code looks good, and I understand what you are trying to achieve.

Please share a screenshot or the executable code to show exactly what behavior you are experiencing. It would be helpful if you could share it using a service like the one below, as it makes it easier to test.

Could you fork the following code, install the latest pdfme 3.2.2, incorporate your plugin, and then share it with me? https://stackblitz.com/~/github.com/pdfme/pdfme-playground

vpn-dev commented 4 months ago

@hand-dot I have made fork of this repo with my changes in it https://stackblitz.com/~/github.com/vpn-dev/pdfme-playground

vpn-dev commented 4 months ago

Kazam_screencast_00004.webm @hand-dot you can see the issue in above video as I said when I am changing newly added select widgets i/e backgroundFromTheme and fontColorFromTheme other active changes on text but which are not committed yet are lost

hand-dot commented 4 months ago

@vpn-dev Thank you. I was able to observe the same behavior on my computer as well. This is a bug. I will investigate the cause and aim to fix it.

hand-dot commented 4 months ago

@vpn-dev Can you check bellow?


It seems that overriding onChange and calling changeSchemas disrupts the existing change processes. The UseDynamicSizeWidget is operating as intended by skipping the existing change processes entirely due to bind: false.

In this fix, rather than overriding onChange, I have set it up to reflect the theme color during the initialization of propPanel.schema.

vpn-dev commented 4 months ago

Hey @hand-dot thanks a lot, this solution completely works.. :100: