Repository navigation
Expand file tree
/
Copy pathlist.ts
More file actions
65 lines (58 loc) · 1.8 KB
/
Copy pathlist.ts
File metadata and controls
65 lines (58 loc) · 1.8 KB
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
import type { TipTapPluginCommand } from '../schema/plugins.ts'
import { BulletList, OrderedList } from '@tiptap/extension-list'
import { defineTipTapPlugin, parseTipTapPluginYamlConfiguration } from '../configuration.ts'
export default function (unsafeConfig: unknown) {
const config = parseTipTapPluginYamlConfiguration({
pluginId: 'list',
config: unsafeConfig,
getValidationSchema: z => z.object({
types: z.array(
z.enum(['bullet', 'ordered']),
).min(1),
}),
})
const extensions: unknown[] = []
const commands: TipTapPluginCommand[] = []
if (config.types.includes('bullet')) {
extensions.push(BulletList)
commands.push({
id: 'list-bullet',
label: 'Bullet List',
iconIdentifier: 'list-bullet',
position: {
toolbarGroupId: 'formatting',
bubbleMenuGroupId: false,
},
status: {
isActive: ({ editor }) => editor.isActive('bulletList'),
isDisabled: ({ editor }) => !editor.can().toggleBulletList() && !editor.can().toggleOrderedList(),
},
onExecute: ({ editor }) => {
editor.chain().focus().toggleBulletList().run()
},
})
}
if (config.types.includes('ordered')) {
extensions.push(OrderedList)
commands.push({
id: 'list-ordered',
label: 'Ordered List',
iconIdentifier: 'list-ordered',
position: {
toolbarGroupId: 'formatting',
bubbleMenuGroupId: false,
},
status: {
isActive: ({ editor }) => editor.isActive('orderedList'),
isDisabled: ({ editor }) => !editor.can().toggleOrderedList() && !editor.can().toggleBulletList(),
},
onExecute: ({ editor }) => {
editor.chain().focus().toggleOrderedList().run()
},
})
}
return defineTipTapPlugin({
extensions,
commands,
})
}