206 lines
3.8 KiB
TypeScript
Raw Permalink Normal View History

declare global {
interface Window {
editor: ClassicEditor;
}
}
import '@esi_package/ckeditor5-mathlive/mathlive.bundle.js';
import {
ClassicEditor,
Autoformat,
Base64UploadAdapter,
BlockQuote,
Bold,
Code,
CodeBlock,
Essentials,
Heading,
Image,
ImageCaption,
ImageStyle,
ImageToolbar,
ImageUpload,
Indent,
Italic,
Link,
List,
MediaEmbed,
Paragraph,
Table,
TableToolbar,
FontFamily,
FontColor,
FontSize,
2025-01-07 09:47:55 +07:00
FontBackgroundColor,
Alignment,
Underline
} from 'ckeditor5';
import { Mathlive, MathlivePanelview } from '@esi_package/ckeditor5-mathlive';
import CKEditorInspector from '@ckeditor/ckeditor5-inspector';
import Export from '../src/export.js';
import 'ckeditor5/ckeditor5.css';
import '@esi_package/ckeditor5-mathlive/mathlive.bundle.css';
import '@esi_package/ckeditor5-mathlive/index.css';
ClassicEditor
.create( document.getElementById( 'editor' )!, {
plugins: [
Export,
Essentials,
Autoformat,
BlockQuote,
Bold,
Heading,
Image,
ImageCaption,
ImageStyle,
ImageToolbar,
ImageUpload,
Indent,
Italic,
Link,
List,
MediaEmbed,
Paragraph,
Table,
TableToolbar,
CodeBlock,
Code,
Base64UploadAdapter,
FontFamily,
FontColor,
FontSize,
2025-01-07 09:47:55 +07:00
FontBackgroundColor,
Alignment,
Underline,
Mathlive
],
toolbar: [
'undo',
'redo',
'|',
'downloadDocx',
'mathlive',
'|',
'heading',
'|',
2025-01-07 09:47:55 +07:00
'alignment',
'|',
'underline',
'bold',
'italic',
'link',
'code',
'bulletedList',
'numberedList',
'|',
'outdent',
'indent',
'|',
'uploadImage',
'blockQuote',
'insertTable',
'mediaEmbed',
'codeBlock',
'|',
'fontFamily',
'fontColor',
'fontSize',
'fontBackgroundColor'
],
image: {
toolbar: [
'imageStyle:inline',
'imageStyle:block',
'imageStyle:side',
'|',
'imageTextAlternative'
]
},
table: {
contentToolbar: [
'tableColumn',
'tableRow',
'mergeTableCells'
]
2025-01-07 09:47:55 +07:00
},
fontSize: {
options: [
generatePtSetting( 14 ),
generatePtSetting( 16 ),
generatePtSetting( 18 ),
2025-01-08 13:16:10 +07:00
generatePtSetting( 20 )
]
},
fontFamily: {
options: [
'default',
'Arial, sans-serif',
'Georgia, serif',
'Impact, Charcoal, sans-serif',
'Lucida Console, Monaco, monospace',
'Lucida Sans Unicode, Lucida Grande, sans-serif',
'Tahoma, Geneva, sans-serif',
'Times New Roman, Times, serif',
'Trebuchet MS, Helvetica, sans-serif',
'Verdana, Geneva, sans-serif',
'TH Sarabun New, sans-serif',
'Angsana New, serif',
2025-01-08 13:16:10 +07:00
'EucrosiaUPC, serif',
'Noto Sans Thai, sans-serif'
]
},
mathlive: {
renderMathPanel( element ) {
let panelView: MathlivePanelview | null = new MathlivePanelview();
panelView.setTextForInsertButton( 'สอดแทรกเลย!' );
panelView.setTextForPanelHeader( 'เครื่องมือคณิตศาสตร์' );
panelView.setSpawnPanelOnLeft( false ); // default is false, set to true to spawn on the left
panelView.setSpawnPanelOnTop( false ); // default is false, set to true to spawn on top
panelView.mount( element );
return () => {
panelView?.destroy();
panelView = null;
2025-01-08 13:16:10 +07:00
};
},
mathPanelDestroyOnClose: true,
2025-01-08 13:16:10 +07:00
openPanelWhenEquationSelected: false
},
fontColor: {
colorPicker: {
2025-01-08 13:16:10 +07:00
format: 'hex'
}
},
fontBackgroundColor: {
colorPicker: {
2025-01-08 13:16:10 +07:00
format: 'hex'
}
2025-01-08 13:16:10 +07:00
}
} )
.then( editor => {
window.editor = editor;
CKEditorInspector.attach( editor );
window.console.log( 'CKEditor 5 is ready.', editor );
} )
.catch( err => {
window.console.error( err.stack );
} );
2025-01-07 09:47:55 +07:00
function generatePtSetting( size: number ): any {
return {
model: size,
title: `${ size }pt`,
view: {
name: 'span',
styles: {
'font-size': `${ size }pt`
}
}
};
}