diff --git a/Classes/EventListener/RteConfigEnhancer.php b/Classes/EventListener/RteConfigEnhancer.php index c93ee2c..decc445 100644 --- a/Classes/EventListener/RteConfigEnhancer.php +++ b/Classes/EventListener/RteConfigEnhancer.php @@ -14,19 +14,16 @@ class RteConfigEnhancer { - public function beforeGetExternalPlugins(BeforeGetExternalPluginsEvent $event): void + public function beforePrepareConfiguration(BeforePrepareConfigurationForEditorEvent $event): void { $configuration = $event->getConfiguration(); - $configuration['syntax_code'] = [ - 'resource' => 'EXT:syntax/Resources/Public/CKEditor/Plugins/Code/plugin.js', + $configuration['importModules'][] = [ + 'module' => '@bk2k/syntax/ckeditor5/plugin/syntax.js', + 'exports' => [ + 'Syntax' + ] ]; - $event->setConfiguration($configuration); - } - public function beforePrepareConfiguration(BeforePrepareConfigurationForEditorEvent $event): void - { - $configuration = $event->getConfiguration(); - $configuration['extraPlugins'][] = 'syntax_code'; $event->setConfiguration($configuration); } } diff --git a/Configuration/JavaScriptModules.php b/Configuration/JavaScriptModules.php new file mode 100644 index 0000000..8d4985f --- /dev/null +++ b/Configuration/JavaScriptModules.php @@ -0,0 +1,20 @@ + [ + 'backend.form', + ], + 'dependencies' => [ + 'rte_ckeditor' + ], + 'imports' => [ + '@bk2k/syntax/ckeditor5/plugin/syntax' => 'EXT:syntax/Resources/Public/JavaScript/ckeditor5/plugin/syntax.js', + ], +]; diff --git a/Configuration/Services.yaml b/Configuration/Services.yaml index 8e25db8..de7ae0b 100644 --- a/Configuration/Services.yaml +++ b/Configuration/Services.yaml @@ -1,10 +1,6 @@ services: BK2K\Syntax\EventListener\RteConfigEnhancer: tags: - - name: event.listener - identifier: 'ext-syntax/rteConfigEnhancer' - method: 'beforeGetExternalPlugins' - event: TYPO3\CMS\RteCKEditor\Form\Element\Event\BeforeGetExternalPluginsEvent - name: event.listener identifier: 'ext-syntax/rteConfigEnhancer' method: 'beforePrepareConfiguration' diff --git a/Resources/Public/JavaScript/ckeditor5/plugin/syntax.js b/Resources/Public/JavaScript/ckeditor5/plugin/syntax.js new file mode 100644 index 0000000..1dfd80c --- /dev/null +++ b/Resources/Public/JavaScript/ckeditor5/plugin/syntax.js @@ -0,0 +1,32 @@ +import * as Core from '@ckeditor/ckeditor5-core'; +import * as UI from '@ckeditor/ckeditor5-ui'; + +export class Syntax extends Core.Plugin { + static pluginName = 'Syntax'; + + init() { + const editor = this.editor; + + editor.ui.componentFactory.add('softhyphen', locale => { + const button = new UI.ButtonView(locale); + button.label = 'Code'; + button.icon = ''; + button.tooltip = true; + button.on('execute', () => alert('insert code')); + return button; + }); + + editor.conversion.for('editingDowncast').add(downcastDispatcher => { + downcastDispatcher.on('insert:$text', (evt, data, conversionApi) => { + if (!conversionApi.consumable.consume(data.item, evt.name)) { + return; + } + + console.log('downcast'); + + }, { priority: 'high' }); + }); + } +} + +export default Syntax;