import Editor from 'tinymce/core/api/Editor'; import { EditorOptions } from 'tinymce/core/api/OptionTypes'; const option: { (name: K): (editor: Editor) => EditorOptions[K]; (name: string): (editor: Editor) => T; } = (name: string) => (editor: Editor) => editor.options.get(name); const register = (editor: Editor): void => { const registerOption = editor.options.register; registerOption('insertdatetime_dateformat', { processor: 'string', default: editor.translate('%Y-%m-%d') }); registerOption('insertdatetime_timeformat', { processor: 'string', default: editor.translate('%H:%M:%S') }); registerOption('insertdatetime_formats', { processor: 'string[]', default: [ '%H:%M:%S', '%Y-%m-%d', '%I:%M:%S %p', '%D' ] }); registerOption('insertdatetime_element', { processor: 'boolean', default: false }); }; const getDateFormat = option('insertdatetime_dateformat'); const getTimeFormat = option('insertdatetime_timeformat'); const getFormats = option('insertdatetime_formats'); const shouldInsertTimeElement = option('insertdatetime_element'); const getDefaultDateTime = (editor: Editor): string => { const formats = getFormats(editor); return formats.length > 0 ? formats[0] : getTimeFormat(editor); }; export { register, getDateFormat, getTimeFormat, getFormats, getDefaultDateTime, shouldInsertTimeElement };