File size: 732 Bytes
1e92f2d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
import type { DataTType } from '@react-page/editor';
import { useEffect, useState } from 'react';
import { useSlate } from 'slate-react';
import type { SlatePluginDefinition } from '../types/slatePluginDefinitions';
export default <T extends DataTType>(
plugin: SlatePluginDefinition<T>
): boolean => {
const editor = useSlate();
const [disabled, setDisabled] = useState(false);
useEffect(() => {
if (plugin.isDisabled) {
try {
plugin.isDisabled(editor).then((d) => {
setDisabled(d);
});
} catch (e) {
// slate sometimes throws when dom node cant be found in undo
}
}
}, [editor.selection, plugin]);
if (!editor) {
return true;
}
return disabled;
};
|