In v49.2, is it by design that plugin handlers do not include DOM events anymore? #4588
-
Hi! I recently migrated my Editor to the newest version const insertImage = (editor, url, options = {}) => {
const text = { text: "" };
const image = {
children: [text],
type: "img",
url,
};
editor.tf.insertNodes(image, {
nextBlock: true,
...options,
});
};
uploadFile: (file) => {
const imageUrl = URL.createObjectURL(file);
return Promise.resolve(imageUrl);
}
BaseImagePlugin.configure({
handlers: {
onPaste: ({ editor, event }) => {
const files = event.clipboardData?.files;
if (files && files.length > 0) {
event.preventDefault();
event.stopPropagation();
event.nativeEvent?.stopImmediatePropagation?.();
Array.from(files).forEach((file: any) => {
uploadFile(file).then((url) => {
insertImage(editor, url);
});
});
}
},
onDrop: ({ editor, event }) => {
const files = event.dataTransfer?.files;
if (files && files.length > 0) {
event.preventDefault();
event.stopPropagation();
event.nativeEvent?.stopImmediatePropagation?.();
Array.from(files).forEach((file: any) => {
uploadFile(file).then((url) => {
insertImage(editor, url);
});
});
}
},
},
}) Here i override When i now updated to the newest version If i I guess i can have certain edge cases for DOM event placed on the Also want to note down that this is not the only use case, i also do similar actions when working with the Thanks in advance! 😄 Plate version49.2.12 Slate React version0.117.4 BrowsersChrome |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
Yes, this is by design in v49.2. The plugin handler API was changed to only support For custom DOM event logic, the recommended approach is to handle these events at the If you want to keep custom logic organized, you can create small utility functions or hooks for each plugin's logic and call them from your main event handlers at the component level. This keeps things modular and readable, even if the logic isn't colocated in the plugin config itself. Some plugins (like DndPlugin) still expose their own event handler options, but these are specific to those plugins and not part of the general plugin handler API anymore. For most cases, handling DOM events at the component level is now the standard pattern in Plate v49.2+. See the PR and code changes for more details. To reply, just mention @dosu. How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other |
Beta Was this translation helpful? Give feedback.
-
@dosu We still support DOM handlers, but only in the React version of plugins: |
Beta Was this translation helpful? Give feedback.
Correct—DOM event handlers like onPaste and onDrop are still supported, but only in the React version of plugins (PlatePlugin), not in SlatePlugin. In PlatePlugin, you can use the handlers option to add DOM event handlers directly in your plugin config, for example:
This is documented in the plugin event handlers section and enforced in the PlatePlugin TypeScript types. SlatePlugin only supports onNodeChange and onTextChange, so DOM event logic must be handled at the …