Deduplicate config for the two editor types

This commit is contained in:
Elian Doran 2024-11-09 15:39:40 +02:00
parent 8945b5ab69
commit 169e65f0ef
3 changed files with 113 additions and 206 deletions

View File

@ -7,7 +7,7 @@
import { BalloonEditor as BalloonEditorBase } from '@ckeditor/ckeditor5-editor-balloon';
import { BlockToolbar } from '@ckeditor/ckeditor5-ui';
import '../theme/theme.css';
import { COMMON_PLUGINS } from './config';
import { COMMON_PLUGINS, COMMON_SETTINGS } from './config';
export default class BalloonEditor extends BalloonEditorBase {
public static override builtinPlugins = [
@ -16,6 +16,8 @@ export default class BalloonEditor extends BalloonEditorBase {
];
public static override defaultConfig = {
...COMMON_SETTINGS,
toolbar: {
items: [
'fontSize',
@ -34,85 +36,7 @@ export default class BalloonEditor extends BalloonEditorBase {
'cuttonote'
]
},
image: {
styles: {
options: [
'inline',
'alignBlockLeft',
'alignCenter',
'alignBlockRight',
'alignLeft',
'alignRight',
'full', // full and side are for BC since the old images have been created with these styles
'side'
]
},
resizeOptions: [
{
name: 'imageResize:original',
value: null,
icon: 'original'
},
{
name: 'imageResize:25',
value: '25',
icon: 'small'
},
{
name: 'imageResize:50',
value: '50',
icon: 'medium'
},
{
name: 'imageResize:75',
value: '75',
icon: 'medium'
}
],
toolbar: [
// Image styles, see https://ckeditor.com/docs/ckeditor5/latest/features/images/images-styles.html#demo.
'imageStyle:inline',
'imageStyle:alignCenter',
{
name: "imageStyle:wrapText",
title: "Wrap text",
items: [
'imageStyle:alignLeft',
'imageStyle:alignRight',
],
defaultItem: 'imageStyle:alignRight'
},
{
name: "imageStyle:block",
title: "Block align",
items: [
'imageStyle:alignBlockLeft',
'imageStyle:alignBlockRight'
],
defaultItem: "imageStyle:alignBlockLeft",
},
'|',
'imageResize:25',
'imageResize:50',
'imageResize:original',
'|',
'toggleImageCaption'
],
upload: {
types: [ 'jpeg', 'png', 'gif', 'bmp', 'webp', 'tiff', 'svg', 'svg+xml', 'avif' ]
}
},
heading: {
options: [
{ model: 'paragraph' as const, title: 'Paragraph', class: 'ck-heading_paragraph' },
// // heading1 is not used since that should be a note's title
{ model: 'heading2' as const, view: 'h2', title: 'Heading 2', class: 'ck-heading_heading2' },
{ model: 'heading3' as const, view: 'h3', title: 'Heading 3', class: 'ck-heading_heading3' },
{ model: 'heading4' as const, view: 'h4', title: 'Heading 4', class: 'ck-heading_heading4' },
{ model: 'heading5' as const, view: 'h5', title: 'Heading 5', class: 'ck-heading_heading5' },
{ model: 'heading6' as const, view: 'h6', title: 'Heading 6', class: 'ck-heading_heading6' }
]
},
blockToolbar: [
'heading',
'|',
@ -126,28 +50,6 @@ export default class BalloonEditor extends BalloonEditorBase {
'markdownImport',
'findAndReplace',
'specialCharacters'
],
table: {
contentToolbar: [
'tableColumn',
'tableRow',
'mergeTableCells',
'tableProperties',
'tableCellProperties',
'toggleTableCaption'
]
},
list: {
properties: {
styles: true,
startIndex: true,
reversed: true
}
},
link: {
defaultProtocol: 'https://'
},
// This value must be kept in sync with the language defined in webpack.config.js.
language: 'en'
};
}

View File

@ -6,7 +6,7 @@
// The editor creator to use.
import { DecoupledEditor as DecoupledEditorBase } from '@ckeditor/ckeditor5-editor-decoupled';
import '../theme/theme.css';
import { COMMON_PLUGINS } from './config';
import { COMMON_PLUGINS, COMMON_SETTINGS } from './config';
export default class DecoupledEditor extends DecoupledEditorBase {
public static override builtinPlugins = [
@ -14,6 +14,8 @@ export default class DecoupledEditor extends DecoupledEditorBase {
];
public static override defaultConfig = {
...COMMON_SETTINGS,
// For nested toolbars, refer to https://ckeditor.com/docs/ckeditor5/latest/getting-started/setup/toolbar.html#grouping-toolbar-items-in-dropdowns-nested-toolbars.
toolbar: {
items: [
@ -64,107 +66,6 @@ export default class DecoupledEditor extends DecoupledEditorBase {
'markdownImport',
'cuttonote'
]
},
image: {
styles: {
options: [
'inline',
'alignBlockLeft',
'alignCenter',
'alignBlockRight',
'alignLeft',
'alignRight',
'full', // full and side are for BC since the old images have been created with these styles
'side'
]
},
resizeOptions: [
{
name: 'imageResize:original',
value: null,
icon: 'original'
},
{
name: 'imageResize:25',
value: '25',
icon: 'small'
},
{
name: 'imageResize:50',
value: '50',
icon: 'medium'
},
{
name: 'imageResize:75',
value: '75',
icon: 'medium'
}
],
toolbar: [
// Image styles, see https://ckeditor.com/docs/ckeditor5/latest/features/images/images-styles.html#demo.
'imageStyle:inline',
'imageStyle:alignCenter',
{
name: "imageStyle:wrapText",
title: "Wrap text",
items: [
'imageStyle:alignLeft',
'imageStyle:alignRight',
],
defaultItem: 'imageStyle:alignRight'
},
{
name: "imageStyle:block",
title: "Block align",
items: [
'imageStyle:alignBlockLeft',
'imageStyle:alignBlockRight'
],
defaultItem: "imageStyle:alignBlockLeft",
},
'|',
'imageResize:25',
'imageResize:50',
'imageResize:original',
'|',
'toggleImageCaption'
],
upload: {
types: [ 'jpeg', 'png', 'gif', 'bmp', 'webp', 'tiff', 'svg', 'svg+xml', 'avif' ]
}
},
heading: {
options: [
{ model: 'paragraph' as const, title: 'Paragraph', class: 'ck-heading_paragraph' },
// // heading1 is not used since that should be a note's title
{ model: 'heading2' as const, view: 'h2', title: 'Heading 2', class: 'ck-heading_heading2' },
{ model: 'heading3' as const, view: 'h3', title: 'Heading 3', class: 'ck-heading_heading3' },
{ model: 'heading4' as const, view: 'h4', title: 'Heading 4', class: 'ck-heading_heading4' },
{ model: 'heading5' as const, view: 'h5', title: 'Heading 5', class: 'ck-heading_heading5' },
{ model: 'heading6' as const, view: 'h6', title: 'Heading 6', class: 'ck-heading_heading6' }
]
},
table: {
contentToolbar: [
'tableColumn',
'tableRow',
'mergeTableCells',
'tableProperties',
'tableCellProperties',
'toggleTableCaption'
]
},
list: {
properties: {
styles: true,
startIndex: true,
reversed: true
}
},
link: {
defaultProtocol: 'https://'
},
// This value must be kept in sync with the language defined in webpack.config.js.
language: 'en'
};
}

View File

@ -134,3 +134,107 @@ export const COMMON_PLUGINS = [
Math,
AutoformatMath
];
export const COMMON_SETTINGS = {
image: {
styles: {
options: [
'inline',
'alignBlockLeft',
'alignCenter',
'alignBlockRight',
'alignLeft',
'alignRight',
'full', // full and side are for BC since the old images have been created with these styles
'side'
]
},
resizeOptions: [
{
name: 'imageResize:original',
value: null,
icon: 'original'
},
{
name: 'imageResize:25',
value: '25',
icon: 'small'
},
{
name: 'imageResize:50',
value: '50',
icon: 'medium'
},
{
name: 'imageResize:75',
value: '75',
icon: 'medium'
}
],
toolbar: [
// Image styles, see https://ckeditor.com/docs/ckeditor5/latest/features/images/images-styles.html#demo.
'imageStyle:inline',
'imageStyle:alignCenter',
{
name: "imageStyle:wrapText",
title: "Wrap text",
items: [
'imageStyle:alignLeft',
'imageStyle:alignRight',
],
defaultItem: 'imageStyle:alignRight'
},
{
name: "imageStyle:block",
title: "Block align",
items: [
'imageStyle:alignBlockLeft',
'imageStyle:alignBlockRight'
],
defaultItem: "imageStyle:alignBlockLeft",
},
'|',
'imageResize:25',
'imageResize:50',
'imageResize:original',
'|',
'toggleImageCaption'
],
upload: {
types: [ 'jpeg', 'png', 'gif', 'bmp', 'webp', 'tiff', 'svg', 'svg+xml', 'avif' ]
}
},
heading: {
options: [
{ model: 'paragraph' as const, title: 'Paragraph', class: 'ck-heading_paragraph' },
// // heading1 is not used since that should be a note's title
{ model: 'heading2' as const, view: 'h2', title: 'Heading 2', class: 'ck-heading_heading2' },
{ model: 'heading3' as const, view: 'h3', title: 'Heading 3', class: 'ck-heading_heading3' },
{ model: 'heading4' as const, view: 'h4', title: 'Heading 4', class: 'ck-heading_heading4' },
{ model: 'heading5' as const, view: 'h5', title: 'Heading 5', class: 'ck-heading_heading5' },
{ model: 'heading6' as const, view: 'h6', title: 'Heading 6', class: 'ck-heading_heading6' }
]
},
table: {
contentToolbar: [
'tableColumn',
'tableRow',
'mergeTableCells',
'tableProperties',
'tableCellProperties',
'toggleTableCaption'
]
},
list: {
properties: {
styles: true,
startIndex: true,
reversed: true
}
},
link: {
defaultProtocol: 'https://'
},
// This value must be kept in sync with the language defined in webpack.config.js.
language: 'en'
};