-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.tsx
45 lines (39 loc) · 1.31 KB
/
config.tsx
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import { PlatePluginComponent } from '@udecode/plate'
import { useContextMenu } from 'react-contexify'
import { useEditorPlugins, PluginOptionType } from '../../Plugins/index'
import { ComboboxConfig } from '../../Types/MultiCombobox'
import { MENU_ID } from '../BlockContextMenu'
import useMultiComboboxOnChange from '../MultiCombobox/useMultiComboboxChange'
import useMultiComboboxOnKeyDown from '../MultiCombobox/useMultiComboboxOnKeyDown'
export const useComboboxConfig = (
editorId: string,
config: ComboboxConfig,
components: Record<string, PlatePluginComponent<any | undefined>> = {},
pluginOptions: PluginOptionType = { exclude: { dnd: false } }
) => {
const pluginConfigs = {
combobox: {
onChange: useMultiComboboxOnChange(editorId, config.onChangeConfig),
onKeyDown: useMultiComboboxOnKeyDown(config.onKeyDownConfig)
}
}
const { show } = useContextMenu({ id: MENU_ID })
const prePlugins = useEditorPlugins(components, pluginOptions)
const plugins = [
...prePlugins,
{
key: 'MULTI_COMBOBOX',
handlers: {
onContextMenu: () => (ev) => {
show(ev)
},
onChange: pluginConfigs.combobox.onChange,
onKeyDown: pluginConfigs.combobox.onKeyDown
}
}
]
return {
plugins,
comboConfigData: config.onKeyDownConfig
}
}