From 627f1f305c325601feea44a909e2ab2822abe7a5 Mon Sep 17 00:00:00 2001 From: Fabian Braun Date: Wed, 11 Dec 2024 09:20:14 +0100 Subject: [PATCH] fix: remove cke5 code --- .../ckeditor5-cmsplugins/icons/cmsplugins.png | Bin 1205 -> 0 bytes .../ckeditor5-cmsplugins/icons/cmsplugins.psd | Bin 29726 -> 0 bytes .../ckeditor5-cmsplugins/src/cmsplugin.js | 30 -- .../src/cmsplugincommand.js | 33 -- .../src/cmspluginediting.js | 101 ---- .../ckeditor5-cmsplugins/src/cmspluginui.js | 162 ------ .../ckeditor5-cmsplugins/src/index.js | 11 - .../ckeditor5-cmsplugins/src/modal/modalui.js | 471 ------------------ .../ckeditor5-cmsplugins/theme/icons/link.svg | 1 - .../theme/icons/puzzle.svg | 23 - .../theme/icons/unlink.svg | 1 - private/js/ckeditor5_plugins/cms.plugin.js | 91 ---- private/js/cms.ckeditor5.js | 267 ---------- 13 files changed, 1191 deletions(-) delete mode 100644 private/js/ckeditor5_plugins/ckeditor5-cmsplugins/icons/cmsplugins.png delete mode 100644 private/js/ckeditor5_plugins/ckeditor5-cmsplugins/icons/cmsplugins.psd delete mode 100644 private/js/ckeditor5_plugins/ckeditor5-cmsplugins/src/cmsplugin.js delete mode 100644 private/js/ckeditor5_plugins/ckeditor5-cmsplugins/src/cmsplugincommand.js delete mode 100644 private/js/ckeditor5_plugins/ckeditor5-cmsplugins/src/cmspluginediting.js delete mode 100644 private/js/ckeditor5_plugins/ckeditor5-cmsplugins/src/cmspluginui.js delete mode 100644 private/js/ckeditor5_plugins/ckeditor5-cmsplugins/src/index.js delete mode 100644 private/js/ckeditor5_plugins/ckeditor5-cmsplugins/src/modal/modalui.js delete mode 100644 private/js/ckeditor5_plugins/ckeditor5-cmsplugins/theme/icons/link.svg delete mode 100755 private/js/ckeditor5_plugins/ckeditor5-cmsplugins/theme/icons/puzzle.svg delete mode 100644 private/js/ckeditor5_plugins/ckeditor5-cmsplugins/theme/icons/unlink.svg delete mode 100644 private/js/ckeditor5_plugins/cms.plugin.js delete mode 100644 private/js/cms.ckeditor5.js diff --git a/private/js/ckeditor5_plugins/ckeditor5-cmsplugins/icons/cmsplugins.png b/private/js/ckeditor5_plugins/ckeditor5-cmsplugins/icons/cmsplugins.png deleted file mode 100644 index 18d784fd44da4274323447420ee80a5e7912bdfe..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1205 zcmbVMTWHfz7|u44=@bTnPMz#5f+#M{rES{A)vasVu4w1zDh^R-nw+(9%f;ku?e;Ld zz3A}59z;G8|L%vd zksvB^YN``;CN>MQp}8an<0@z-W)nnXQ^AzvZiqkzW>q~%ju&r|Kvja|HgAGSm|>Vx zTL&!IG0>Kh2fF2eLN;v#jRgSM{fahJT$IJ6<1K=2zqZxej6zdVZyukUu%tc~rmeM68#psMJyb6*zgiL{^ z^ZC3h?{*nhmSzKifTO{26h=^XzmB8=rQ54Z3L>;+OEr;d=)h5wGDa^7lGxMf5HvH9 zm=)ITnMC1~(FMt*Srv)3R7GICew;<0hw*U??`K&*$AuzcJ{k&nm;l3tOB!== zMZeqUW7vor!&x@MwFJ0mi@r!(53Q*KH)}GA!9uvE3Q2_)o47wxEOzD`glx zr3z@z8OX46h6%zQJXo8MWL0-I);R|>9j^#2wGS#$%h147h6QyF4??Uz>W&5?Z1``H zPji+3$r_EFp`G&hqg+Z`xCWi+Z1Lm8Z2LeR_l$*`ga5v97jCRqaWRxCJk2QC>}MsN zK2dddc+rKuubWSgReD~Y9336KaOqM*{CZu};MkS?_>0#K;MB;-$nwb_-(tgMAP8=N zikivEA4BKT@19*V`z(uV+kb0*_0?5p8xK`2rM4f~`uO{oiQ8z$j@rSB%Cerftz7!e zlaaJQlI6v++S=Om*9S-I#Nxbr1WnV!H}++2-9NnY{jLMo9zB14#;i$C92pv_8e9e{ zVzJoy%-#jZ+nZ~Y^^0CD*)LTS*)X_kaIvy1U`kt#K-oAuFynwJfR3 zrlA{6#j{viJFC1}KdVVU(hxT$J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h&3>9lVjQgHVwQ)Vkcu_3-%+Dg)WnXP=%PMfp=Z-9lw%6jOiup;tw!W z*V1T5n9X?6hzt5iYMX;X%+FjOKTX>DNZY9;EtnnbHZV(e`@RRrHo#lD6TvMHVaK2^K5jm9Rw}8ZOKM1;JR0 z3kXbKGeeN)e@9=IKoUYOMdlU(`n-bb0?gDlL6WHPj+-DzRH{Ax#yjMNpkF z%V0O);ot~3C4Bz`R4bgMuYx-{u%yLdRv~Jui^T^wiG!264*obeX)U5-@Q;_o<3^ZC zfFY-dX@%keVLX-Nj-9+z_2wIVF!;A541!4U%z}$&;zJE5p-4nPdFUmP4FWH5Wc742 zt~%u;m@A8rO`JI#jgUzandgj$Wb0OvC7cXT9}*h=p9E-)!B~YjcK$o5z8>NPObPE7px*&8FUsvL04V- zf8|rCM>jo*hmEvPzp8ew^>yK_L$2V*UsB(iV6d9QW1E2YXU>?p~U_d;Oo^ zOK-S#FHOPJo&x&e&VLHzN0pp7+fJP*K_||%qZ6mwJO2^ilhoLgAp6g;(7Si8PvD-e zy7uosM1umbk--nIwc(#1^1Fhrv|mR2^;a06;Pbrm{%bpSUFmRko|p6OSO5Mcl2CQA zvq~y { - // Create a elment with the "name" attribute (and all the selection attributes)... - const placeholder = writer.createElement( 'cms-plugin', { - ...Object.fromEntries( selection.getAttributes() ), - plugin_type: value - } ); - - // ... and insert it into the document. - editor.model.insertContent( placeholder ); - - // Put the selection on the inserted element. - writer.setSelection( placeholder, 'on' ); - } ); - } - - refresh() { - const model = this.editor.model; - const selection = model.document.selection; - - const isAllowed = model.schema.checkChild( selection.focus.parent, 'cms-plugin' ); - - this.isEnabled = isAllowed; - } -} diff --git a/private/js/ckeditor5_plugins/ckeditor5-cmsplugins/src/cmspluginediting.js b/private/js/ckeditor5_plugins/ckeditor5-cmsplugins/src/cmspluginediting.js deleted file mode 100644 index 0e217d7f..00000000 --- a/private/js/ckeditor5_plugins/ckeditor5-cmsplugins/src/cmspluginediting.js +++ /dev/null @@ -1,101 +0,0 @@ - - -import Plugin from '@ckeditor/ckeditor5-core/src/plugin'; - -import { toWidget } from '@ckeditor/ckeditor5-widget/src/utils'; -import Widget from '@ckeditor/ckeditor5-widget/src/widget'; -import CMSPluginCommand from "./cmsplugincommand"; - - -export default class CMSPluginEditing extends Plugin { - static get requires() { - return [ Widget ]; - } - - init() { - console.log( 'CMSPluginEditing#init() got called' ); - this._defineSchema(); - this._defineConverters(); - this.editor.commands.add( 'cms-plugin', new CMSPluginCommand( this.editor ) ); - } - - _defineSchema() { // ADDED - const schema = this.editor.model.schema; - - schema.register( 'cms-plugin', { - // Allow wherever text is allowed: - allowWhere: '$text', - - // The placeholder will act as an inline node: - isInline: true, - - // The inline widget is self-contained so it cannot be split by the caret and can be selected: - isObject: true, - - // The inline widget can have the same attributes as text (for example linkHref, bold). - allowAttributesOf: '$text', - - // The placeholder can have many types, like date, name, surname, etc: - allowAttributes: [ 'id', 'plugin_type', 'content' ] - } ); - } - - _defineConverters() { // ADDED - const conversion = this.editor.conversion; - - conversion.for( 'upcast' ).elementToElement( { - view: { - name: 'cms-plugin', - }, - model: ( viewElement, { writer: modelWriter } ) => { - // Extract the "name" from "{name}". - const plugin_type = viewElement.getAttribute("plugin-type") ; //viewElement.getChild( 0 ).attr("plugin-type"); - var content = viewElement.getChild(0); - content = content ? content.data : 'XXX'; - return modelWriter.createElement( 'cms-plugin', { - id: viewElement.getAttribute("id"), - plugin_type: viewElement.getAttribute("plugin-type"), - content: content - } ); - } - } ); - - conversion.for( 'editingDowncast' ).elementToElement( { - model: 'cms-plugin', - view: ( modelItem, { writer: viewWriter } ) => { - const widgetElement = createCMSPluginView( modelItem, viewWriter ); - - // Enable widget handling on a cms-plugion element inside the editing view. - return toWidget( widgetElement, viewWriter ); - } - } ); - - conversion.for( 'dataDowncast' ).elementToElement( { - model: 'cms-plugin', - view: ( modelItem, { writer: viewWriter } ) => createCMSPluginView( modelItem, viewWriter ) - } ); - - // Helper method for both downcast converters. - function createCMSPluginView( modelItem, viewWriter ) { - const plugin_type = modelItem.getAttribute( 'plugin_type' ); - const plugin_id = modelItem.getAttribute( 'id' ); - const content = modelItem.getAttribute( 'content', 'XXX' ); - - const cmsPluginView = viewWriter.createContainerElement( 'cms-plugin', { - plugin_type: plugin_type, - id: plugin_id, - } ); - - // Insert the placeholder name (as a text). - const innerHTML = viewWriter.createRawElement( - 'span', { - class: 'badge bg-warning' - }, function( domElement ) { - domElement.innerHTML = content; - } ); - viewWriter.insert( viewWriter.createPositionAt( cmsPluginView, 0 ), innerHTML ); - - return cmsPluginView; - } - } -} diff --git a/private/js/ckeditor5_plugins/ckeditor5-cmsplugins/src/cmspluginui.js b/private/js/ckeditor5_plugins/ckeditor5-cmsplugins/src/cmspluginui.js deleted file mode 100644 index e7245648..00000000 --- a/private/js/ckeditor5_plugins/ckeditor5-cmsplugins/src/cmspluginui.js +++ /dev/null @@ -1,162 +0,0 @@ -/** - * @module userstyle/userstyle - */ - -import { Plugin } from 'ckeditor5/src/core'; -import { Collection } from 'ckeditor5/src/utils'; -import { Model, createDropdown, addListToDropdown } from 'ckeditor5/src/ui'; -import ButtonView from '@ckeditor/ckeditor5-ui/src/button/buttonview'; - -import cmsPluginIcon from './../theme/icons/puzzle.svg'; -import { Modal } from './modal/modalui'; -import {addLinkProtocolIfApplicable} from "@ckeditor/ckeditor5-link/src/utils"; - -export default class CMSPluginUI extends Plugin { - /** - * @inheritDoc - */ - static get pluginName() { - return 'CMSPluginUI'; - } - - /** - * @inheritDoc - */ - init() { - const editor = this.editor; - const t = editor.t; - - // The "placeholder" dropdown must be registered among the UI components of the editor - // to be displayed in the toolbar. - editor.ui.componentFactory.add('cms-plugin', locale => { - const dropdownView = createDropdown(locale); - - // Populate the list in the dropdown with items. - addListToDropdown(dropdownView, getDropdownItemsDefinitions(editor)); - - dropdownView.buttonView.set({ - // The t() function helps localize the editor. All strings enclosed in t() can be - // translated and change when the language of the editor changes. - label: editor.config.get('cmsPlugin.lang.toolbar', t('CMS Plugins')), - icon: cmsPluginIcon, - tooltip: true, - withText: false, - }); - - // Disable the placeholder button when the command is disabled. - const command = editor.commands.get('cms-plugin'); - dropdownView.bind('isEnabled').to(command); - - // Execute the command when the dropdown item is clicked (executed). - this.listenTo(dropdownView, 'execute', evt => { - editor.execute('cms-plugin', {value: evt.source.commandParam}); - editor.editing.view.focus(); - }); - - return dropdownView; - }); - - for ( const plugin of editor.config.get('cmsPlugin.installed_plugins') ) { - if (plugin.icon) { - - editor.ui.componentFactory.add(plugin.value, locale => { - const buttonView = new ButtonView(locale); - - buttonView.set({ - // The t() function helps localize the editor. All strings enclosed in t() can be - // translated and change when the language of the editor changes. - label: plugin.name, - icon: plugin.icon, - tooltip: true, - withText: false, - commandParam: plugin.value, - }); - - // Disable the placeholder button when the command is disabled. - const command = editor.commands.get('cms-plugin'); - buttonView.bind('isEnabled').to(command); - - // Execute the command when the dropdown item is clicked (executed). - this.listenTo(buttonView, 'execute', evt => { - this.addPlugin(plugin, editor) - // editor.execute('cms-plugin', {value: evt.source.commandParam}); - // editor.editing.view.focus(); - }); - - return buttonView; - }); - } - } - console.log("UI", editor.ui.view.locale); - this.modal = new Modal(editor.ui.view.locale, editor.commands.get('cms-plugin')); - } - - /** - * @inheritDoc - */ - destroy() { - super.destroy(); - - // Destroy created UI components as they are not automatically destroyed (see ckeditor5#1341). - this.modal.destroy(); - } - - handleEdit (event) { - - } - - editPlugin () { - - } - - addPlugin (plugin, editor) { - const selection = editor.model.document.selection; - const config = editor.config.get("cmsPlugin"); - - console.log("Selection", selection); - const data = { - placeholder_id: config.placeholder, - plugin_type: plugin.value, - plugin_parent: config.pk, - plugin_position: config.plugin_position + 1, // after the current plugin - cms_path: window.parent.location.pathname, - cms_history: 0, - plugin_language: config.plugin_language - }; - - this.modal.open( { - title: `${config.lang.add} ${plugin.name}`, - url: config.urls.add_plugin + '?' + CMS.$.param(data), - onClose: false - }); - } - - setupDialog() { - - } -} - -function getDropdownItemsDefinitions( editor ) { - const itemDefinitions = new Collection(); - - console.log("getDropdownItemsDefinitions", editor); - for ( const plugin of editor.config.get('cmsPlugin.installed_plugins') ) { - if (!plugin.icon) { - // only collect items in dropdown that do not have an own icon - const definition = { - type: 'button', - model: new Model( { - commandParam: plugin.value, - label: plugin.name, - withText: true - } ) - }; - - // Add the item definition to the collection. - itemDefinitions.add( definition ); - } - - } - return itemDefinitions; -} - diff --git a/private/js/ckeditor5_plugins/ckeditor5-cmsplugins/src/index.js b/private/js/ckeditor5_plugins/ckeditor5-cmsplugins/src/index.js deleted file mode 100644 index d36892d7..00000000 --- a/private/js/ckeditor5_plugins/ckeditor5-cmsplugins/src/index.js +++ /dev/null @@ -1,11 +0,0 @@ -/** - * @license Copyright (c) 2003-2022, Django-CMS Association - */ - -/** - * @module cmsplugin - */ - -export { default as CMSPlugin } from './cmsplugin'; -export { default as CMSPluginEditing } from './cmspluginediting'; -export { default as CMSPluginUI } from './cmspluginui'; diff --git a/private/js/ckeditor5_plugins/ckeditor5-cmsplugins/src/modal/modalui.js b/private/js/ckeditor5_plugins/ckeditor5-cmsplugins/src/modal/modalui.js deleted file mode 100644 index 60d6f5b7..00000000 --- a/private/js/ckeditor5_plugins/ckeditor5-cmsplugins/src/modal/modalui.js +++ /dev/null @@ -1,471 +0,0 @@ -/** - * @license Copyright (c) 2003-2022, CKSource Holding sp. z o.o. All rights reserved. - * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license - */ - -/** - * @module link/ui/linkformview - */ - -/*jshint esversion: 6 */ - -import { - ButtonView, - IframeView, - FocusCycler, - LabeledFieldView, - SwitchButtonView, - View, - ViewCollection, - createLabeledInputText, - injectCssTransitionDisabler, - submitHandler -} from 'ckeditor5/src/ui'; -import BalloonPanelView from '@ckeditor/ckeditor5-ui/src/panel/balloon/balloonpanelview'; -import toUnit from '@ckeditor/ckeditor5-utils/src/dom/tounit'; - -import { FocusTracker, KeystrokeHandler } from 'ckeditor5/src/utils'; -import { icons } from 'ckeditor5/src/core'; - -// See: #8833. -// eslint-disable-next-line ckeditor5-rules/ckeditor-imports -import '@ckeditor/ckeditor5-ui/theme/components/responsive-form/responsiveform.css'; - -const toPx = toUnit( 'px' ); - - -export class Modal { - constructor( locale, editCommand ) { - this.modalView = new ModalView(locale, editCommand); - this.editor = editCommand.editor; - this.editingView = editCommand.editor.editing.view; - // this.contextualBalloon = editCommand.editor.plugins.get( ContextualBalloon ); - console.log("editComand", editCommand); - } - - destroy() { - this.modalView.destroy(); - super.destroy(); - } - - open( options ) { - console.log("Modal open", options); - console.log("Modal", this.modalView); - - this.modalView.open (options.url); - this.modalView.show(); - } - - close() { - this.modalView.close() - } -} - - -/** - * The link form view controller class. - * - * See {@link module:link/ui/linkformview~LinkFormView}. - * - * @extends module:ui/view~View - */ -export class ModalView extends BalloonPanelView { - /** - * Creates an instance of the {@link module:cmsplugins/modal/modalui~ModalFormView} class. - * - * Also see {@link #render}. - * - * @param {module:utils/locale~Locale} [locale] The localization services instance. - * @param {module:link/linkcommand~LinkCommand} editCommand Reference to {@link module:link/linkcommand~LinkCommand}. - * @param {String} [protocol] A value of a protocol to be displayed in the input's placeholder. - */ - constructor( locale, editCommand ) { - super( locale ); - - this.title_bar = this.createCollection(); - this.action_bar = this.createCollection(); - - const bind = this.bindTemplate; - - let width = parseInt(window.innerWidth * 0.6); - let height = parseInt(window.innerHeight * 0.6); - if (width < 640 || height < 400) { - width = window.innerWidth-2; - height = window.innerHeight-60-2; - } - this.set("top", (window.innerWidth-width) / 2); - this.set("left", (window.innerHeight-height) / 2); - this.set("width", width); - this.set("height", height); - this.setTemplate( { - tag: 'div', - attributes: { - class: [ - 'ck', - 'ck-balloon-panel', - bind.if( 'isVisible', 'ck-balloon-panel_visible' ), - bind.to( 'class' ) - ], - - style: { - top: bind.to( 'top', toPx ), - left: bind.to( 'left', toPx ), - width: bind.to( 'width', toPx ), - height: bind.to( 'height', toPx ) - } - }, - - children: [ - { - tag: 'div', - attributes: {class: ['ck-cms-panel-title']}, - children: this.title_bar - }, - { - tag: 'div', - attributes: {class: ['ck-cms-panel-body']}, - children: this.content - }, - { - tag: 'div', - attributes: {class: ['ck-cms-panel-action-bar', 'ck', 'ck-responsive-form']}, - children: this.action_bar - }, - ] - } ); - console.log("template", this.template.attributes.style); - - const t = locale.t; - - /** - * Tracks information about DOM focus in the form. - * - * @readonly - * @member {module:utils/focustracker~FocusTracker} - */ - - this.focusTracker = new FocusTracker(); - - /** - * An instance of the {@link module:utils/keystrokehandler~KeystrokeHandler}. - * - * @readonly - * @member {module:utils/keystrokehandler~KeystrokeHandler} - */ - this.keystrokes = new KeystrokeHandler(); - - /** - * The URL input view. - * - * @member {module:ui/labeledfield/labeledfieldview~LabeledFieldView} - */ - - this.set( { - isEnabled: false, - }); - - this.iframeView = new IframeView(); - this.content.add( this.iframeView ); - - /** - * The Save button view. - * - * @member {module:ui/button/buttonview~ButtonView} - */ - this.saveButtonView = this._createButton( t( 'Save' ), icons.check, 'ck-button-save' ); - this.saveButtonView.type = 'submit'; - - /** - * The Cancel button view. - * - * @member {module:ui/button/buttonview~ButtonView} - */ - this.cancelButtonView = this._createButton( t( 'Cancel' ), icons.cancel, 'ck-button-cancel', 'cancel' ); - - this.action_bar.add( this.cancelButtonView ); - this.action_bar.add( this.saveButtonView ); - - this.render(); - if (!this.added_to_dom) { - document.body.appendChild(this.element); - this.added_to_dom = true; - } - return; - /** - * A collection of {@link module:ui/button/switchbuttonview~SwitchButtonView}, - * which corresponds to {@link module:link/linkcommand~LinkCommand#manualDecorators manual decorators} - * configured in the editor. - * - * @private - * @readonly - * @type {module:ui/viewcollection~ViewCollection} - */ - this._manualDecoratorSwitches = this._createManualDecoratorSwitches( linkCommand ); - - /** - * A collection of child views in the form. - * - * @readonly - * @type {module:ui/viewcollection~ViewCollection} - */ - this.children = this._createFormChildren( linkCommand.manualDecorators ); - - /** - * A collection of views that can be focused in the form. - * - * @readonly - * @protected - * @member {module:ui/viewcollection~ViewCollection} - */ - this._focusables = new ViewCollection(); - - /** - * Helps cycling over {@link #_focusables} in the form. - * - * @readonly - * @protected - * @member {module:ui/focuscycler~FocusCycler} - */ - this._focusCycler = new FocusCycler( { - focusables: this._focusables, - focusTracker: this.focusTracker, - keystrokeHandler: this.keystrokes, - actions: { - // Navigate form fields backwards using the Shift + Tab keystroke. - focusPrevious: 'shift + tab', - - // Navigate form fields forwards using the Tab key. - focusNext: 'tab' - } - } ); - - const classList = [ 'ck', 'ck-link-form', 'ck-responsive-form' ]; - - if ( editCommand.manualDecorators.length ) { - classList.push( 'ck-link-form_layout-vertical', 'ck-vertical-form' ); - } - - this.setTemplate( { - tag: 'form', - - attributes: { - class: classList, - - // https://github.com/ckeditor/ckeditor5-link/issues/90 - tabindex: '-1' - }, - - children: this.children - } ); - - injectCssTransitionDisabler( this ); - } - - open(url) { - this.url = url; - this.iframeView.element.src = url; - this.iframeView.on( 'loaded', () => { - for (let element of this.iframeView.element.contentWindow - .document.getElementsByClassName("submit-row")) { - element.setAttribute("style", "display: none;"); - } - console.log( 'The iframe has loaded', this.iframeView ); - } ); - // this.iframeView.style("display: block;"); - this.cancelButtonView.on('click', () => this.close() ); - } - - close() { - console.log('close'); - this.cancelButtonView.off('click'); - this.hide(); - } - /** - * Obtains the state of the {@link module:ui/button/switchbuttonview~SwitchButtonView switch buttons} representing - * {@link module:link/linkcommand~LinkCommand#manualDecorators manual link decorators} - * in the {@link module:link/ui/linkformview~LinkFormView}. - * - * @returns {Object.} Key-value pairs, where the key is the name of the decorator and the value is - * its state. - */ - getDecoratorSwitchesState() { - return Array.from( this._manualDecoratorSwitches ).reduce( ( accumulator, switchButton ) => { - accumulator[ switchButton.name ] = switchButton.isOn; - return accumulator; - }, {} ); - } - - /** - * @inheritDoc - */ - renderx() { - super.render(); - - submitHandler( { - view: this - } ); - - const childViews = [ - this.urlInputView, - ...this._manualDecoratorSwitches, - this.saveButtonView, - this.cancelButtonView - ]; - - childViews.forEach( v => { - // Register the view as focusable. - this._focusables.add( v ); - - // Register the view in the focus tracker. - this.focusTracker.add( v.element ); - } ); - - // Start listening for the keystrokes coming from #element. - this.keystrokes.listenTo( this.element ); - } - - /** - * @inheritDoc - */ - destroy() { - super.destroy(); - - this.focusTracker.destroy(); - this.keystrokes.destroy(); - } - - /** - * Focuses the fist {@link #_focusables} in the form. - */ - focus() { - this._focusCycler.focusFirst(); - } - - /** - * Creates a button view. - * - * @private - * @param {String} label The button label. - * @param {String} icon The button icon. - * @param {String} className The additional button CSS class name. - * @param {String} [eventName] An event name that the `ButtonView#execute` event will be delegated to. - * @returns {module:ui/button/buttonview~ButtonView} The button view instance. - */ - _createButton( label, icon, className, eventName ) { - const button = new ButtonView( this.locale ); - - button.set( { - label, - icon, - tooltip: true - } ); - - button.extendTemplate( { - attributes: { - class: className - } - } ); - - if ( eventName ) { - button.delegate( 'execute' ).to( this, eventName ); - } - - return button; - } - - /** - * Populates {@link module:ui/viewcollection~ViewCollection} of {@link module:ui/button/switchbuttonview~SwitchButtonView} - * made based on {@link module:link/linkcommand~LinkCommand#manualDecorators}. - * - * @private - * @param {module:link/linkcommand~LinkCommand} linkCommand A reference to the link command. - * @returns {module:ui/viewcollection~ViewCollection} of switch buttons. - */ - _createManualDecoratorSwitches( linkCommand ) { - const switches = this.createCollection(); - - for ( const manualDecorator of linkCommand.manualDecorators ) { - const switchButton = new SwitchButtonView( this.locale ); - - switchButton.set( { - name: manualDecorator.id, - label: manualDecorator.label, - withText: true - } ); - - switchButton.bind( 'isOn' ).toMany( [ manualDecorator, linkCommand ], 'value', ( decoratorValue, commandValue ) => { - return commandValue === undefined && decoratorValue === undefined ? manualDecorator.defaultValue : decoratorValue; - } ); - - switchButton.on( 'execute', () => { - manualDecorator.set( 'value', !switchButton.isOn ); - } ); - - switches.add( switchButton ); - } - - return switches; - } - - /** - * Populates the {@link #children} collection of the form. - * - * If {@link module:link/linkcommand~LinkCommand#manualDecorators manual decorators} are configured in the editor, it creates an - * additional `View` wrapping all {@link #_manualDecoratorSwitches} switch buttons corresponding - * to these decorators. - * - * @private - * @param {module:utils/collection~Collection} manualDecorators A reference to - * the collection of manual decorators stored in the link command. - * @returns {module:ui/viewcollection~ViewCollection} The children of link form view. - */ - _createFormChildren( manualDecorators ) { - const children = this.createCollection(); - - children.add( this.urlInputView ); - - if ( manualDecorators.length ) { - const additionalButtonsView = new View(); - - additionalButtonsView.setTemplate( { - tag: 'ul', - children: this._manualDecoratorSwitches.map( switchButton => ( { - tag: 'li', - children: [ switchButton ], - attributes: { - class: [ - 'ck', - 'ck-list__item' - ] - } - } ) ), - attributes: { - class: [ - 'ck', - 'ck-reset', - 'ck-list' - ] - } - } ); - children.add( additionalButtonsView ); - } - - children.add( this.saveButtonView ); - children.add( this.cancelButtonView ); - - return children; - } -} - -/** - * Fired when the form view is submitted (when one of the children triggered the submit event), - * for example with a click on {@link #saveButtonView}. - * - * @event submit - */ - -/** - * Fired when the form view is canceled, for example with a click on {@link #cancelButtonView}. - * - * @event cancel - */ diff --git a/private/js/ckeditor5_plugins/ckeditor5-cmsplugins/theme/icons/link.svg b/private/js/ckeditor5_plugins/ckeditor5-cmsplugins/theme/icons/link.svg deleted file mode 100644 index a3a08999..00000000 --- a/private/js/ckeditor5_plugins/ckeditor5-cmsplugins/theme/icons/link.svg +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/private/js/ckeditor5_plugins/ckeditor5-cmsplugins/theme/icons/puzzle.svg b/private/js/ckeditor5_plugins/ckeditor5-cmsplugins/theme/icons/puzzle.svg deleted file mode 100755 index 1cadca9b..00000000 --- a/private/js/ckeditor5_plugins/ckeditor5-cmsplugins/theme/icons/puzzle.svg +++ /dev/null @@ -1,23 +0,0 @@ - - - - - diff --git a/private/js/ckeditor5_plugins/ckeditor5-cmsplugins/theme/icons/unlink.svg b/private/js/ckeditor5_plugins/ckeditor5-cmsplugins/theme/icons/unlink.svg deleted file mode 100644 index dc287331..00000000 --- a/private/js/ckeditor5_plugins/ckeditor5-cmsplugins/theme/icons/unlink.svg +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/private/js/ckeditor5_plugins/cms.plugin.js b/private/js/ckeditor5_plugins/cms.plugin.js deleted file mode 100644 index 72e878fd..00000000 --- a/private/js/ckeditor5_plugins/cms.plugin.js +++ /dev/null @@ -1,91 +0,0 @@ -/* eslint-env es6 */ -/* jshint esversion: 6 */ -import Plugin from '@ckeditor/ckeditor5-core/src/plugin'; -import Widget from '@ckeditor/ckeditor5-widget/src/widget'; -import { toWidget } from '@ckeditor/ckeditor5-widget/src/utils'; - -class CmsPlugin extends Plugin { - static get requires() { - return [ Widget ]; - } - - init() { - this._defineSchema(); - this._defineConverters(); - this._attachEventListeners(); - } - - _defineSchema() { - const schema = this.editor.model.schema; - schema.register( 'cmsPlugin', { - // CmsPlugin element is an object. - isObject: true, - // The CmsPlugin element is allowed inside a root element. - allowWhere: '$root', - // The CmsPlugin can have text inside. - isBlock: true, - allowContentOf: '$block' - } ); - } - - _defineConverters() { - const conversion = this.editor.conversion; - - conversion.for( 'upcast' ).elementToElement({ - view: { - name: 'cms-plugin' - }, - model: ( viewElement, modelWriter ) => { - // Read the "content" attribute from the view. - const content = viewElement.getChild( 0 ).data; - - // Return a model representation of the view element. - return modelWriter.createElement( 'cmsPlugin', { content } ); - } - }); - - conversion.for( 'editingDowncast' ).elementToElement({ - model: 'cmsPlugin', - view: ( modelElement, viewWriter ) => { - const cmsPlugin = viewWriter.createUIElement( 'cms-plugin', - { - // Prevent widget from being selectable because it's content is not editable. - 'contenteditable': 'false' - } ); - - return toWidget( cmsPlugin, viewWriter ); - } - }); - - conversion.for( 'dataDowncast' ).elementToElement({ - model: 'cmsPlugin', - view: 'cms-plugin' - }); - - } - - _attachEventListeners() { - // Defines the double click event to edit the content. - - this.editor.editing.view.document.on('dblclick', ( evt, data ) => { - const modelElement = this.editor.editing.mapper.toModelElement( data.target ); - - if ( !modelElement || !modelElement.is( 'cmsPlugin' ) ) { - return; - } - - const content = prompt( 'Insert content', modelElement.getAttribute( 'content' ) ); - - if ( content !== null ) { - this.editor.model.change( writer => { - writer.setAttribute( 'content', content, modelElement ); - } ); - } - - data.preventDefault(); - } ); - - } -} - -export default CmsPlugin; diff --git a/private/js/cms.ckeditor5.js b/private/js/cms.ckeditor5.js deleted file mode 100644 index 93e424dd..00000000 --- a/private/js/cms.ckeditor5.js +++ /dev/null @@ -1,267 +0,0 @@ -/* eslint-env es6 */ -/* jshint esversion: 6 */ -/* global document, window, console */ - - -// The editor creator to use. -import ClassicEditorBase from '@ckeditor/ckeditor5-editor-classic/src/classiceditor'; -import InlineEditorBase from '@ckeditor/ckeditor5-editor-inline/src/inlineeditor'; -import BalloonEditorBase from '@ckeditor/ckeditor5-editor-balloon/src/ballooneditor'; -import BlockToolbar from '@ckeditor/ckeditor5-ui/src/toolbar/block/blocktoolbar'; - - -import Essentials from '@ckeditor/ckeditor5-essentials/src/essentials'; -// import UploadAdapter from '@ckeditor/ckeditor5-adapter-ckfinder/src/uploadadapter'; -import Autoformat from '@ckeditor/ckeditor5-autoformat/src/autoformat'; -import Autosave from '@ckeditor/ckeditor5-autosave/src/autosave'; -import Alignment from '@ckeditor/ckeditor5-alignment/src/alignment'; -import Bold from '@ckeditor/ckeditor5-basic-styles/src/bold'; -import Italic from '@ckeditor/ckeditor5-basic-styles/src/italic'; -import Underline from '@ckeditor/ckeditor5-basic-styles/src/underline'; -import Strikethrough from '@ckeditor/ckeditor5-basic-styles/src/strikethrough'; -import Code from '@ckeditor/ckeditor5-basic-styles/src/code'; -import Subscript from '@ckeditor/ckeditor5-basic-styles/src/subscript'; -import Superscript from '@ckeditor/ckeditor5-basic-styles/src/superscript'; -import Font from '@ckeditor/ckeditor5-font/src/font'; -import BlockQuote from '@ckeditor/ckeditor5-block-quote/src/blockquote'; -import CodeBlock from '@ckeditor/ckeditor5-code-block/src/codeblock'; -import Heading from '@ckeditor/ckeditor5-heading/src/heading'; -import HeadingButtonsUI from '@ckeditor/ckeditor5-heading/src/headingbuttonsui'; -// import Base64UploadAdapter from '@ckeditor/ckeditor5-upload/src/adapters/base64uploadadapter'; -// import Image from '@ckeditor/ckeditor5-image/src/image'; -// import ImageCaption from '@ckeditor/ckeditor5-image/src/imagecaption'; -// import ImageStyle from '@ckeditor/ckeditor5-image/src/imagestyle'; -// import ImageToolbar from '@ckeditor/ckeditor5-image/src/imagetoolbar'; -// import ImageUpload from '@ckeditor/ckeditor5-image/src/imageupload'; -import Indent from '@ckeditor/ckeditor5-indent/src/indent'; -import Link from '@ckeditor/ckeditor5-link/src/link'; -import List from '@ckeditor/ckeditor5-list/src/list'; -import MediaEmbed from '@ckeditor/ckeditor5-media-embed/src/mediaembed'; -import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph'; -import ParagraphButtonUI from '@ckeditor/ckeditor5-paragraph/src/paragraphbuttonui'; -import PasteFromOffice from '@ckeditor/ckeditor5-paste-from-office/src/pastefromoffice'; -import Table from '@ckeditor/ckeditor5-table/src/table'; -import TableToolbar from '@ckeditor/ckeditor5-table/src/tabletoolbar'; -import TextTransformation from '@ckeditor/ckeditor5-typing/src/texttransformation'; -import SourceEditing from '@ckeditor/ckeditor5-source-editing/src/sourceediting'; -//import HorizontalLine from './ckeditor5-horizontal-line/src/horizontalline'; -//import UserStyle from './ckeditor5-user-style/src/userstyle'; - -import CmsPlugin from './ckeditor5_plugins/cms.plugin'; - -class ClassicEditor extends ClassicEditorBase {} -// class InlineEditor extends InlineEditorBase {} -class BalloonEditor extends BalloonEditorBase {} - -// Plugins to include in the build. -var builtinPlugins = [ - Essentials, - // UploadAdapter, - Autoformat, - Autosave, - Alignment, - BlockToolbar, - Bold, - Italic, - Underline, - Strikethrough, - Code, - Subscript, - Superscript, - Font, - CodeBlock, - BlockQuote, - Heading, - HeadingButtonsUI, - //HorizontalLine, - // Base64UploadAdapter, - Image, - // ImageCaption, - // ImageStyle, - // ImageToolbar, - // ImageUpload, - Indent, - Link, - List, - MediaEmbed, - Paragraph, - ParagraphButtonUI, - PasteFromOffice, - SourceEditing, - Table, - TableToolbar, - TextTransformation, - // UserStyle, - // CmsPlugin -]; - -ClassicEditor.builtinPlugins = builtinPlugins; -// InlineEditor.builtinPlugins = builtinPlugins; -BalloonEditor.builtinPlugins = builtinPlugins; - -// Editor configuration. -var defaultConfig = { - toolbar: { - items: [ - 'heading', '|', - 'bold', 'italic', 'alignment', '|', - 'link', '|', - 'bulletedList', 'numberedList', 'outdent', 'indent', '|', - 'code', 'codeblock', '|', - 'fontFamily', 'fontSize', 'fontColor', '|', - 'mediaEmbed', 'insertTable', // 'horizontalLine', 'blockQuote', - ], - shouldNotGroupWhenFull: true - }, - heading: { - options: [ - { model: 'paragraph', title: 'Paragraph', class: '' }, - { model: 'heading1', view: 'h1', title: 'Heading 1', class: '' }, - { model: 'heading2', view: 'h2', title: 'Heading 2', class: '' }, - { model: 'heading3', view: 'h3', title: 'Heading 3', class: '' }, - { model: 'heading4', view: 'h4', title: 'Heading 4', class: '' }, - { model: 'heading5', view: 'h5', title: 'Heading 5', class: '' } - ] - }, - blockquote: { - options: { - classes: 'blockquote' - } - }, - table: { - contentToolbar: [ - 'tableColumn', - 'tableRow', - 'mergeTableCells' - ] - }, - // This value must be kept in sync with the language defined in webpack.config.js. - language: 'en' -}; - -ClassicEditor.defaultConfig = Object.assign({}, defaultConfig); -ClassicEditor.defaultConfig.toolbar.items.push('|', 'sourceEditing'); -// InlineEditor.defaultConfig = defaultConfig; -BalloonEditor.defaultConfig = { - heading: defaultConfig.heading, - table: defaultConfig.table, - language: defaultConfig.language, - image: defaultConfig.image, - blockquote: defaultConfig.blockquote, - toolbar: { - items: [ - 'bold', 'italic', 'alignment', '|', - 'link', '|', - 'code', '|', // 'userstyle', - 'fontFamily', 'fontSize', 'fontColor', '|', - ] - }, - blockToolbar: { - items: [ - 'paragraph', 'heading2', 'heading3', 'heading4', 'heading5', - '|', - 'bulletedList', 'numberedList', 'outdent', 'indent', '|', - // 'cms-plugin', '|', 'LinkPlugin', - 'codeblock', '|', - 'mediaEmbed', 'insertTable', // 'horizontalLine', 'blockQuote', - ], - shouldNotGroupWhenFull: true - } -}; - - -class CMSCKEditor5Plugin { - constructor(props) { - this._editors = {}; - this._CSS = []; - } - - // initializes the editor on the target element, with the given html code - create (el, inModal, content, options, save_callback) { - if (!(el.id in this._editors)) { - const inline = el.tagName !== 'TEXTAREA'; - if (!inline) { - ClassicEditor.create(el).then( editor => { - this._editors[el.id] = editor; - }); - } else { - BalloonEditor.create(el).then( editor => { - el.classList.remove('ck-content'); // remove Ckeditor 5 default styles - this._editors[el.id] = editor; - const initialContent = editor.getData(); - editor.model.document.on('change:data', () => el.dataset.changed='true'); - editor.ui.focusTracker.on( 'change:isFocused', ( evt, name, isFocused ) => { - el.classList.remove('ck-content'); // remove Ckeditor 5 default styles - if ( !isFocused ) { - // change:data event is not reliable, so we need to double-check - if (el.dataset.changed !== 'true' && editor.getData() !== initialContent) { - el.dataset.changed='true'; - } - save_callback(); - } - } ); - const styles = document.querySelectorAll('style[data-cke="true"]'); - if (styles.length > 0) { - // Styles are installed in the document head, but we need to clone them - // for later recovery - styles.forEach((style) => { - if (this._CSS.indexOf(style) === -1) { - this._CSS.push(style.cloneNode(true)); - } - } - ); - } else { - this._CSS.forEach((style) => document.head.appendChild(style)); - } - }); - } - } - } - - // returns the edited html code - getHTML (el) { - if (el.id in this._editors) { - return this._editors[el.id].getData(); - } - return undefined; - } - - // returns the edited content as json - // currently not supported by CKEditor 5 - getJSON (el) { - return undefined; - } - - // destroy the editor - destroyEditor (el) { - if (el.id in this._editors) { - this._editors[el.id].destroy(); - delete this._editors[el.id]; - } - } - - _init() { - this.editor.ui.componentFactory.add('cms-plugin', locale => { - const view = new ButtonView(locale); - view.set({ - label: 'CMS Plugin', - icon: pluginIcon, - tooltip: true - }); - // Callback executed once the image is clicked. - view.on('execute', () => { - const selection = this.editor.model.document.selection; - const selectedElement = selection.getSelectedElement(); - if (selectedElement && selectedElement.name === 'cms-plugin') { - this.editor.execute('link', { url: selectedElement.getAttribute('url') }); - } else { - this.editor.execute('link', { url: 'https://www.django-cms.org' }); - } - }); - return view; - }); - } -} - - -window.cms_editor_plugin = new CMSCKEditor5Plugin({});