-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.tsx
78 lines (72 loc) · 2.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import { PlatePlugin, PlatePluginComponent } from '@udecode/plate'
import useMemoizedPlugins, { generatePlugins } from '../../plugins'
import { QuickLinkComboboxItem } from '../../plugins/QuickLink/components/QuickLinkComboboxItem'
import { ELEMENT_ILINK, ELEMENT_TAG } from '@mexit/core'
import useMultiComboboxOnChange from '../MultiCombobox/useMultiComboboxChange'
import useMultiComboboxOnKeyDown from '../MultiCombobox/useMultiComboboxOnKeyDown'
import { SlashComboboxItem } from '../SlashCommands/SlashComboboxItem'
import { TagComboboxItem } from '../Tags/TagComboboxItem'
import { ComboboxConfig, ComboboxKey, ComboboxKeyDownConfig, ComboboxOnChangeConfig } from './types'
export const useComboboxConfig = (
editorId: string,
config: ComboboxConfig,
components: Record<string, PlatePluginComponent<any | undefined>> = {},
customPlugins?: Array<PlatePlugin>
) => {
const keys = config.onKeyDownConfig.keys
const comboOnKeydownConfig: ComboboxKeyDownConfig = {
keys: {
ilink: {
slateElementType: ELEMENT_ILINK,
newItemHandler: keys.ilink.newItemHandler,
itemRenderer: QuickLinkComboboxItem
},
tag: {
slateElementType: ELEMENT_TAG,
newItemHandler: keys.tag.newItemHandler,
itemRenderer: TagComboboxItem
},
slash_command: {
slateElementType: 'slash_command',
newItemHandler: keys.slash_command.newItemHandler,
itemRenderer: SlashComboboxItem
}
},
slashCommands: config.onKeyDownConfig.slashCommands
}
const comboOnChangeConfig: ComboboxOnChangeConfig = {
ilink: {
cbKey: ComboboxKey.ILINK,
trigger: '[[',
data: []
},
tag: {
cbKey: ComboboxKey.TAG,
trigger: '#',
data: [],
icon: 'ri:hashtag'
},
slash_command: {
cbKey: ComboboxKey.SLASH_COMMAND,
trigger: '/',
icon: 'ri:flask-line',
data: []
},
...(config.onChangeConfig as any)
}
const prePlugins = useMemoizedPlugins(customPlugins ?? generatePlugins(), components)
const plugins = [
...prePlugins,
{
key: 'MULTI_COMBOBOX',
handlers: {
onChange: useMultiComboboxOnChange(editorId, comboOnChangeConfig),
onKeyDown: useMultiComboboxOnKeyDown(comboOnKeydownConfig)
}
}
]
return {
plugins,
comboOnKeydownConfig
}
}