-
Notifications
You must be signed in to change notification settings - Fork 964
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[frontend] Migrate CK Editor to 9.3 (#8151)
Co-authored-by: Landry Trebon <landry.trebon@filigran.io>
- Loading branch information
Showing
11 changed files
with
1,109 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
217 changes: 217 additions & 0 deletions
217
opencti-platform/opencti-front/src/components/CKEditor.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,217 @@ | ||
import { CKEditor as ReactCKEditor } from '@ckeditor/ckeditor5-react'; | ||
import { | ||
Editor, | ||
Alignment, | ||
Autoformat, | ||
AutoImage, | ||
AutoLink, | ||
Base64UploadAdapter, | ||
BlockQuote, | ||
Bold, | ||
ClassicEditor, | ||
Code, | ||
CodeBlock, | ||
Essentials, | ||
FontBackgroundColor, | ||
FontColor, | ||
FontFamily, | ||
FontSize, | ||
Heading, | ||
Highlight, | ||
HorizontalLine, | ||
ImageCaption, | ||
ImageInsert, | ||
ImageResize, | ||
ImageStyle, | ||
ImageToolbar, | ||
Indent, | ||
IndentBlock, | ||
Italic, | ||
Link, | ||
LinkImage, | ||
ListProperties, | ||
Mention, | ||
Paragraph, | ||
PasteFromOffice, | ||
RemoveFormat, | ||
SourceEditing, | ||
SpecialCharacters, | ||
SpecialCharactersCurrency, | ||
SpecialCharactersEssentials, | ||
Strikethrough, | ||
Subscript, | ||
Superscript, | ||
List, | ||
Table, | ||
TodoList, | ||
TableCaption, | ||
TableColumnResize, | ||
TableToolbar, | ||
Underline, | ||
ImageEditing, | ||
ImageBlockEditing, | ||
EditorConfig, | ||
ImageTextAlternative, | ||
} from 'ckeditor5'; | ||
import React from 'react'; | ||
import { useIntl } from 'react-intl'; | ||
|
||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
// @ts-ignore | ||
// eslint-disable-next-line import/extensions | ||
import de from 'ckeditor5/translations/de.js'; | ||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
// @ts-ignore | ||
// eslint-disable-next-line import/extensions | ||
import en from 'ckeditor5/translations/en.js'; | ||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
// @ts-ignore | ||
// eslint-disable-next-line import/extensions | ||
import es from 'ckeditor5/translations/es.js'; | ||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
// @ts-ignore | ||
// eslint-disable-next-line import/extensions | ||
import fr from 'ckeditor5/translations/fr.js'; | ||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
// @ts-ignore | ||
// eslint-disable-next-line import/extensions | ||
import ja from 'ckeditor5/translations/ja.js'; | ||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
// @ts-ignore | ||
// eslint-disable-next-line import/extensions | ||
import ko from 'ckeditor5/translations/ko.js'; | ||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
// @ts-ignore | ||
// eslint-disable-next-line import/extensions | ||
import zh from 'ckeditor5/translations/zh.js'; | ||
|
||
const CKEDITOR_DEFAULT_CONFIG: EditorConfig = { | ||
translations: [de, en, es, fr, ja, ko, zh], | ||
plugins: [ | ||
Alignment, | ||
AutoImage, | ||
Autoformat, | ||
AutoLink, | ||
Base64UploadAdapter, | ||
BlockQuote, | ||
Bold, | ||
Code, | ||
CodeBlock, | ||
Essentials, | ||
FontBackgroundColor, | ||
FontColor, | ||
FontFamily, | ||
FontSize, | ||
Heading, | ||
Highlight, | ||
HorizontalLine, | ||
ImageBlockEditing, | ||
ImageCaption, | ||
ImageEditing, | ||
ImageInsert, | ||
ImageResize, | ||
ImageStyle, | ||
ImageToolbar, | ||
ImageTextAlternative, | ||
Indent, | ||
IndentBlock, | ||
Italic, | ||
Link, | ||
LinkImage, | ||
List, | ||
ListProperties, | ||
Mention, | ||
Paragraph, | ||
PasteFromOffice, | ||
RemoveFormat, | ||
SourceEditing, | ||
SpecialCharacters, | ||
SpecialCharactersCurrency, | ||
SpecialCharactersEssentials, | ||
Strikethrough, | ||
Subscript, | ||
Superscript, | ||
Table, | ||
TableCaption, | ||
TableColumnResize, | ||
TableToolbar, | ||
TodoList, | ||
Underline, | ||
], | ||
toolbar: { | ||
items: [ | ||
'heading', | ||
'fontFamily', | ||
'fontSize', | ||
'alignment', | ||
'|', | ||
'bold', | ||
'italic', | ||
'underline', | ||
'strikethrough', | ||
'link', | ||
'fontColor', | ||
'fontBackgroundColor', | ||
'highlight', | ||
'|', | ||
'bulletedList', | ||
'numberedList', | ||
'outdent', | ||
'indent', | ||
'todoList', | ||
'|', | ||
'imageInsert', | ||
'blockQuote', | ||
'code', | ||
'codeBlock', | ||
'insertTable', | ||
'specialCharacters', | ||
'subscript', | ||
'superscript', | ||
'horizontalLine', | ||
'|', | ||
'sourceEditing', | ||
'removeFormat', | ||
'undo', | ||
'redo', | ||
], | ||
}, | ||
image: { | ||
resizeUnit: 'px', | ||
toolbar: [ | ||
'imageTextAlternative', | ||
'toggleImageCaption', | ||
'imageStyle:block', | ||
'imageStyle:side', | ||
'linkImage', | ||
], | ||
}, | ||
table: { | ||
contentToolbar: [ | ||
'tableColumn', | ||
'tableRow', | ||
'mergeTableCells', | ||
], | ||
}, | ||
}; | ||
|
||
type CKEditorProps<T extends Editor> = Omit<ReactCKEditor<T>['props'], 'editor' | 'config'>; | ||
|
||
const CKEditor = (props: CKEditorProps<ClassicEditor>) => { | ||
const { locale } = useIntl(); | ||
|
||
const config: EditorConfig = { | ||
...CKEDITOR_DEFAULT_CONFIG, | ||
language: locale.slice(0, 2), | ||
}; | ||
|
||
return ( | ||
<ReactCKEditor | ||
editor={ClassicEditor} | ||
config={config} | ||
{...props} | ||
/> | ||
); | ||
}; | ||
|
||
export default CKEditor; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.