mirror of
https://github.com/laurent22/joplin.git
synced 2024-12-18 09:35:20 +02:00
16 lines
702 B
TypeScript
16 lines
702 B
TypeScript
|
import { useMemo } from 'react';
|
||
|
import { PluginStates } from '@joplin/lib/services/plugins/reducer';
|
||
|
import getActivePluginEditorView from '@joplin/lib/services/plugins/utils/getActivePluginEditorView';
|
||
|
|
||
|
// If a plugin editor should be shown for the current note, this function will return the plugin and
|
||
|
// associated view.
|
||
|
export default (plugins: PluginStates, shownEditorViewIds: string[]) => {
|
||
|
return useMemo(() => {
|
||
|
const { editorPlugin, editorView } = getActivePluginEditorView(plugins);
|
||
|
if (editorView) {
|
||
|
if (!shownEditorViewIds.includes(editorView.id)) return { editorPlugin: null, editorView: null };
|
||
|
}
|
||
|
return { editorPlugin, editorView };
|
||
|
}, [plugins, shownEditorViewIds]);
|
||
|
};
|