ruilisi / fortune-sheet

A drop-in javascript spreadsheet library that provides rich features like Excel and Google Sheets
https://ruilisi.github.io/fortune-sheet-docs/
MIT License
2.54k stars 227 forks source link

表格 粘贴功能 beforePaste 【BUG】 #592

Closed Rio-shuai closed 1 month ago

Rio-shuai commented 2 months ago

组件设置拦截粘贴操作,并手动处理数据。 <Workbook hooks={{ beforePaste:()=>{ return false; } }}/> 粘贴功能 1.【符合预期】使用键盘 C+V 粘贴,发现被拦截。
2.【BUG】右键菜单栏 -> 点击粘贴 发现直接被粘贴进单元格,没有被拦截。

sanchit3008 commented 2 months ago

thanks for reporting, looking into this

Rio-shuai commented 2 months ago

感谢回复,看代码改动应该可以解决我的问题,我需要等新的版本发布后安装才会生效吗,我尝试重新安装 v0.19.14 ,如果是的话请告诉我大概多久会发布新版本。

Thank you for your reply, I think the code change can solve my problem, do I need to wait for the new version to be released before the installation takes effect? I will try to reinstall v0.19.14, if yes, please tell me how long it will take to release the new version.

sanchit3008 commented 2 months ago

im checking if i can get a few more fixes in before releasing, looking to release by weekend.

sanchit3008 commented 1 month ago

Sorry why was this reopened

Rio-shuai commented 1 month ago

目前 beforePaste 可以拦截粘贴操作了,但是不满足我的使用场景。 我需要获取剪切板中的内容,然后根据我自己的规则判断是否允许粘贴,其中获取剪切板的内容是异步操作。 我异步返回false时 仍然会将数据粘贴进去。 示例代码:

<Workbook
    {...config}
    hooks={{
        beforePaste: async ()=>{
            const pasteText = await navigator.clipboard.readText();
            const allowPaste = pasteText === '123';
            return allowPaste
        }
    }}
/>

Current beforePaste can block paste operations, but it does not meet my usage scenario. I need to get the contents of the clipboard and then decide whether to allow pasting according to my own rules, where getting the contents of the clipboard is an asynchronous operation. Even if false is returned, the data will still be pasted in. Sample code:

<Workbook
    {...config}
    hooks={{
        beforePaste: async ()=>{
            const pasteText = await navigator.clipboard.readText();
            const allowPaste = pasteText === '123';
            return allowPaste
        }
    }}
/>
Rio-shuai commented 1 month ago

我希望组件可以兼容异步返回的场景 I want the component to be compatible with asynchronously returned scenarios

sanchit3008 commented 1 month ago

This is a new feature request to be honest. Can you please open a new issue for this as the original ask of the issue was resolved. Will be easier to track.