Hufe921 / canvas-editor

rich text editor by canvas/svg
https://hufe.club/canvas-editor-docs
MIT License
3.43k stars 498 forks source link

是否可以根据 Override paste 的返回值决定是否继续保持 paste 的默认行为呢 #663

Closed junestars closed 2 months ago

junestars commented 2 months ago

What problem does this feature solve?

当只想在特定情况下自定义 paste 行为时,这会很有用。

比如 1、只想自定义控件的 paste 行为,其他内容维持默认 2、只想自定义 pasteByEvent,而不影响 pasteByApi

另外,是否可以向 Override.paste 方法中传入 CanvasEvent,以便更简单的自定义 paste

What does the proposed API look like?

如果您愿意加入这样的功能,也许可以参考下面的思路

if (paste) {
    const continueDefault = paste(evt, host)
    if (isPromise(continueDefault)) {
      continueDefault
        .then(() => {
          handleDefaultPaste()
        })
        .catch(() => {})
    } else if (continueDefault === true) {
      handleDefaultPaste()
    }
    return
}
Hufe921 commented 2 months ago

场景是什么

junestars commented 2 months ago

1、粘贴时,只有粘贴内容包含控件时才做自定义行为(比如更新控件扩展对象中的 id),其他情况仍想复用原有行为。 2、在特定情况下想阻止粘贴行为(禁用粘贴),其他情况仍保持原有行为。