You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

71 lines
1.2 KiB

interface BuildVditorOptionsInput {
value: string
isMobile: boolean
onInput: (value: string) => void
uploadHandler: (files: File[]) => Promise<string>
}
const DESKTOP_TOOLBAR: ReadonlyArray<string> = [
'emoji',
'headings',
'bold',
'italic',
'strike',
'|',
'line',
'list',
'ordered-list',
'check',
'quote',
'|',
'code',
'inline-code',
'insert-before',
'insert-after',
'|',
'upload',
'link',
'table',
'|',
'undo',
'redo',
'|',
'fullscreen',
'edit-mode',
]
const MOBILE_TOOLBAR: ReadonlyArray<string> = [
'bold',
'italic',
'headings',
'|',
'list',
'ordered-list',
'|',
'link',
'upload',
'code',
'|',
'preview',
]
export function buildPostBodyMarkdownEditorVditorOptions(input: BuildVditorOptionsInput): Record<string, unknown> {
return {
value: input.value,
cache: { enable: false },
mode: input.isMobile ? 'ir' : 'sv',
toolbar: input.isMobile ? MOBILE_TOOLBAR : DESKTOP_TOOLBAR,
upload: {
accept: 'image/*',
handler: input.uploadHandler,
},
input(value: string) {
input.onInput(value)
},
}
}
export const postBodyMarkdownEditorToolbarPresets = {
desktop: DESKTOP_TOOLBAR,
mobile: MOBILE_TOOLBAR,
}