-
I want to fix #239 (comment) But I found it hard to get underlying dom node, as the component doesn't accept ianstormtaylor/slate#3618 is possibly related, but how to do const editorRef = useRef()
useEffect(()=> {
editorRef.current = ReactEditor.toDOMNode(editor, editor)
, []} in plate? |
Beta Was this translation helpful? Give feedback.
Answered by
zbeyens
Apr 25, 2022
Replies: 2 comments
-
Easiest would be to open a PR to add |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
linonetwo
-
Warp the export function App(props: IEditorAppProps & IDefaultWidgetProps): JSX.Element {
return (
<PlateProvider id={props.currentTiddler}>
<ParentWidgetContext.Provider value={props.parentWidget}>
<GlobalStyle />
<DndProvider backend={HTML5Backend}>
<Editor {...props} />
</DndProvider>
</ParentWidgetContext.Provider>
</PlateProvider>
);
} export function Editor(props: IEditorAppProps & IDefaultWidgetProps): JSX.Element {
const editorID = props.currentTiddler;
// get it here
const editorReference = usePlateEditorRef(editorID);
const onChange = useCallback(
(newValue: TElement[]) => {
// DEBUG: console
console.log(`onChange`, editorReference, newValue);
currentAstReference.current = newValue;
// check isComposing and if user is just set_selection
// check isComposing like this
if (editorReference === null || ReactEditor.isComposing(editorReference as ReactEditor)) {
return;
}
if (editorReference.operations.every((op) => op.type === 'set_selection')) {
return;
}
props.saver.lock();
debouncedSaver(newValue);
},
[debouncedSaver, editorReference, props.saver],
);
if (typeof document === 'undefined') {
return <div>Loading...</div>;
}
return (
<Plate id={editorID} initialValue={currentAstReference.current} plugins={plugins} onChange={onChange} editableProps={{ ...CONFIG.editableProps, onBlur }}>
<BallonToolbar />
<SnippetCombobox id={editorID} pluginKey="/" />
<WikiLinkCombobox id={editorID} pluginKey="[[" />
<WikiLinkCombobox id={editorID} pluginKey="{{" />
<MacrosCombobox id={editorID} pluginKey="<<" />
<WidgetCombobox id={editorID} pluginKey="<$" />
</Plate>
);
} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Easiest would be to open a PR to add
editableRef
prop toPlateProps