Skip to content
Snippets Groups Projects
Verified Commit bd5f9c01 authored by Lauri Timmanee's avatar Lauri Timmanee
Browse files

Issue #3227354 by JeroenT, bnjmnm, Wim Leers, jungle, VladimirAus, lauriii,...

Issue #3227354 by JeroenT, bnjmnm, Wim Leers, jungle, VladimirAus, lauriii, RenatoG, nmangold, Gábor Hojtsy, el7cosmos, catch, mandclu, freelock, ckrina, witeksocha, Reinmar: Add support for ckeditor5-autoformat
parent 7d31a390
Branches
Tags
25 merge requests!54479.5.x SF update,!5014Issue #3071143: Table Render Array Example Is Incorrect,!4868Issue #1428520: Improve menu parent link selection,!4289Issue #1344552 by marcingy, Niklas Fiekas, Ravi.J, aleevas, Eduardo Morales...,!4114Issue #2707291: Disable body-level scrolling when a dialog is open as a modal,!4100Issue #3249600: Add support for PHP 8.1 Enums as allowed values for list_* data types,!2378Issue #2875033: Optimize joins and table selection in SQL entity query implementation,!2334Issue #3228209: Add hasRole() method to AccountInterface,!2062Issue #3246454: Add weekly granularity to views date sort,!1591Issue #3199697: Add JSON:API Translation experimental module,!1484Exposed filters get values from URL when Ajax is on,!1255Issue #3238922: Refactor (if feasible) uses of the jQuery serialize function to use vanillaJS,!1105Issue #3025039: New non translatable field on translatable content throws error,!1073issue #3191727: Focus states on mobile second level navigation items fixed,!10223132456: Fix issue where views instances are emptied before an ajax request is complete,!925Issue #2339235: Remove taxonomy hard dependency on node module,!877Issue #2708101: Default value for link text is not saved,!872Draft: Issue #3221319: Race condition when creating menu links and editing content deletes menu links,!844Resolve #3036010 "Updaters",!617Issue #3043725: Provide a Entity Handler for user cancelation,!579Issue #2230909: Simple decimals fail to pass validation,!560Move callback classRemove outside of the loop,!555Issue #3202493,!485Sets the autocomplete attribute for username/password input field on login form.,!30Issue #3182188: Updates composer usage to point at ./vendor/bin/composer
/*!
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
* For licensing, see LICENSE.md.
*/(()=>{var t={704:(t,e,o)=>{t.exports=o(79)("./src/core.js")},492:(t,e,o)=>{t.exports=o(79)("./src/engine.js")},181:(t,e,o)=>{t.exports=o(79)("./src/typing.js")},209:(t,e,o)=>{t.exports=o(79)("./src/utils.js")},79:t=>{"use strict";t.exports=CKEditor5.dll}},e={};function o(i){var s=e[i];if(void 0!==s)return s.exports;var n=e[i]={exports:{}};return t[i](n,n.exports,o),n.exports}o.d=(t,e)=>{for(var i in e)o.o(e,i)&&!o.o(t,i)&&Object.defineProperty(t,i,{enumerable:!0,get:e[i]})},o.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),o.r=t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})};var i={};(()=>{"use strict";o.r(i),o.d(i,{Autoformat:()=>c});var t=o(704),e=o(181),s=o(492),n=o(209);function r(t,e,o,i){let r,d=null;"function"==typeof i?r=i:(d=t.commands.get(i),r=()=>{t.execute(i)}),t.model.document.on("change:data",((a,c)=>{if(d&&!d.isEnabled||!e.isEnabled)return;const l=(0,n.first)(t.model.document.selection.getRanges());if(!l.isCollapsed)return;if(c.isUndo||!c.isLocal)return;const u=Array.from(t.model.document.differ.getChanges()),h=u[0];if(1!=u.length||"insert"!==h.type||"$text"!=h.name||1!=h.length)return;const g=h.position.parent;if(g.is("element","codeBlock"))return;if(g.is("element","listItem")&&"function"!=typeof i&&!["numberedList","bulletedList","todoList"].includes(i))return;if(d&&!0===d.value)return;const m=g.getChild(0),f=t.model.createRangeOn(m);if(!f.containsRange(l)&&!l.end.isEqual(f.end))return;const p=o.exec(m.data.substr(0,l.end.offset));p&&t.model.enqueueChange((e=>{const o=e.createPositionAt(g,0),i=e.createPositionAt(g,p[0].length),n=new s.LiveRange(o,i);if(!1!==r({match:p})){e.remove(n);const o=t.model.document.selection.getFirstRange(),i=e.createRangeIn(g);!g.isEmpty||i.isEqual(o)||i.containsRange(o,!0)||e.remove(g)}n.detach(),t.model.enqueueChange((()=>{t.plugins.get("Delete").requestUndoOnBackspace()}))}))}))}function d(t,e,o,i){let s,n;o instanceof RegExp?s=o:n=o,n=n||(t=>{let e;const o=[],i=[];for(;null!==(e=s.exec(t))&&!(e&&e.length<4);){let{index:t,1:s,2:n,3:r}=e;const d=s+n+r;t+=e[0].length-d.length;const a=[t,t+s.length],c=[t+s.length+n.length,t+s.length+n.length+r.length];o.push(a),o.push(c),i.push([t+s.length,t+s.length+n.length])}return{remove:o,format:i}}),t.model.document.on("change:data",((o,s)=>{if(s.isUndo||!s.isLocal||!e.isEnabled)return;const r=t.model,d=r.document.selection;if(!d.isCollapsed)return;const c=Array.from(r.document.differ.getChanges()),l=c[0];if(1!=c.length||"insert"!==l.type||"$text"!=l.name||1!=l.length)return;const u=d.focus,h=u.parent,{text:g,range:m}=function(t,e){let o=t.start;const i=Array.from(t.getItems()).reduce(((t,i)=>!i.is("$text")&&!i.is("$textProxy")||i.getAttribute("code")?(o=e.createPositionAfter(i),""):t+i.data),"");return{text:i,range:e.createRange(o,t.end)}}(r.createRange(r.createPositionAt(h,0),u),r),f=n(g),p=a(m.start,f.format,r),x=a(m.start,f.remove,r);p.length&&x.length&&r.enqueueChange((e=>{if(!1!==i(e,p)){for(const t of x.reverse())e.remove(t);r.enqueueChange((()=>{t.plugins.get("Delete").requestUndoOnBackspace()}))}}))}))}function a(t,e,o){return e.filter((t=>void 0!==t[0]&&void 0!==t[1])).map((e=>o.createRange(t.getShiftedBy(e[0]),t.getShiftedBy(e[1]))))}class c extends t.Plugin{static get requires(){return[e.Delete]}static get pluginName(){return"Autoformat"}afterInit(){this._addListAutoformats(),this._addBasicStylesAutoformats(),this._addHeadingAutoformats(),this._addBlockQuoteAutoformats(),this._addCodeBlockAutoformats(),this._addHorizontalLineAutoformats()}_addListAutoformats(){const t=this.editor.commands;t.get("bulletedList")&&r(this.editor,this,/^[*-]\s$/,"bulletedList"),t.get("numberedList")&&r(this.editor,this,/^1[.|)]\s$/,"numberedList"),t.get("todoList")&&r(this.editor,this,/^\[\s?\]\s$/,"todoList"),t.get("checkTodoList")&&r(this.editor,this,/^\[\s?x\s?\]\s$/,(()=>{this.editor.execute("todoList"),this.editor.execute("checkTodoList")}))}_addBasicStylesAutoformats(){const t=this.editor.commands;if(t.get("bold")){const t=l(this.editor,"bold");d(this.editor,this,/(?:^|\s)(\*\*)([^*]+)(\*\*)$/g,t),d(this.editor,this,/(?:^|\s)(__)([^_]+)(__)$/g,t)}if(t.get("italic")){const t=l(this.editor,"italic");d(this.editor,this,/(?:^|\s)(\*)([^*_]+)(\*)$/g,t),d(this.editor,this,/(?:^|\s)(_)([^_]+)(_)$/g,t)}if(t.get("code")){const t=l(this.editor,"code");d(this.editor,this,/(`)([^`]+)(`)$/g,t)}if(t.get("strikethrough")){const t=l(this.editor,"strikethrough");d(this.editor,this,/(~~)([^~]+)(~~)$/g,t)}}_addHeadingAutoformats(){const t=this.editor.commands.get("heading");t&&t.modelElements.filter((t=>t.match(/^heading[1-6]$/))).forEach((e=>{const o=e[7],i=new RegExp(`^(#{${o}})\\s$`);r(this.editor,this,i,(()=>{if(!t.isEnabled||t.value===e)return!1;this.editor.execute("heading",{value:e})}))}))}_addBlockQuoteAutoformats(){this.editor.commands.get("blockQuote")&&r(this.editor,this,/^>\s$/,"blockQuote")}_addCodeBlockAutoformats(){const t=this.editor,e=t.model.document.selection;t.commands.get("codeBlock")&&r(t,this,/^```$/,(()=>{if(e.getFirstPosition().parent.is("element","listItem"))return!1;this.editor.execute("codeBlock",{usePreviousLanguageChoice:!0})}))}_addHorizontalLineAutoformats(){this.editor.commands.get("horizontalLine")&&r(this.editor,this,/^---$/,"horizontalLine")}}function l(t,e){return(o,i)=>{if(!t.commands.get(e).isEnabled)return!1;const s=t.model.schema.getValidRanges(i,e);for(const t of s)o.setAttribute(e,!0,t);o.removeSelectionAttribute(e)}}})(),(window.CKEditor5=window.CKEditor5||{}).autoformat=i})();
\ No newline at end of file
......@@ -314,6 +314,18 @@ ckeditor5.translations:
# are not allowed.
assets/vendor/ckeditor5/translation.js: {}
ckeditor5.autoformat:
remote: https://github.com/ckeditor/ckeditor5
version: "37.1.0"
license:
name: GNU-GPL-2.0-or-later
url: https://raw.githubusercontent.com/ckeditor/ckeditor5/v37.1.0/LICENSE.md
gpl-compatible: true
js:
assets/vendor/ckeditor5/autoformat/autoformat.js: { minified: true }
dependencies:
- core/ckeditor5
css.escape:
version: VERSION
drupalSettings: {}
......
......@@ -63,6 +63,7 @@ autoescape
autoescaped
autoescaping
autofix
autoformat
autogenerator
autoloadable
autoloaded
......
......@@ -441,6 +441,15 @@ ckeditor5_alignment:
elements:
- <$text-container class="text-align-left text-align-center text-align-right text-align-justify">
ckeditor5_autoformat:
ckeditor5:
plugins:
- autoformat.Autoformat
drupal:
label: Autoformat
library: core/ckeditor5.autoformat
elements: false
ckeditor5_removeFormat:
ckeditor5:
plugins: [removeFormat.RemoveFormat]
......
......@@ -22,6 +22,12 @@
* @typedef {module:alignment/alignmentui} module:alignment/alignmentui~AlignmentUI
*/
/**
* Declared in file @ckeditor/ckeditor5-autoformat/src/blockautoformatediting.js
*
* @typedef {module:autoformat/blockautoformatediting} module:autoformat/blockautoformatediting~blockAutoformatEditing
*/
/**
* Declared in file @ckeditor/ckeditor5-basic-styles/src/attributecommand.js
*
......
......@@ -1075,6 +1075,7 @@ public function testEnabledPlugins() {
// Case 1: no extra CKEditor 5 plugins.
$definitions = array_keys($this->manager->getEnabledDefinitions($editor));
$default_plugins = [
'ckeditor5_autoformat',
'ckeditor5_bold',
'ckeditor5_emphasis',
'ckeditor5_essentials',
......@@ -1089,6 +1090,7 @@ public function testEnabledPlugins() {
'ckeditor5/internal.drupal.ckeditor5',
'ckeditor5/internal.drupal.ckeditor5.emphasis',
'ckeditor5/internal.drupal.ckeditor5.htmlEngine',
'core/ckeditor5.autoformat',
'core/ckeditor5.basic',
'core/ckeditor5.essentials',
'core/ckeditor5.htmlSupport',
......@@ -1197,6 +1199,7 @@ public function testEnabledPlugins() {
$definitions = array_keys($this->manager->getEnabledDefinitions($editor));
$default_plugins = [
'ckeditor5_arbitraryHtmlSupport',
'ckeditor5_autoformat',
'ckeditor5_bold',
'ckeditor5_emphasis',
'ckeditor5_essentials',
......@@ -1209,6 +1212,7 @@ public function testEnabledPlugins() {
'ckeditor5/internal.drupal.ckeditor5',
'ckeditor5/internal.drupal.ckeditor5.emphasis',
'ckeditor5/internal.drupal.ckeditor5.htmlEngine',
'core/ckeditor5.autoformat',
'core/ckeditor5.basic',
'core/ckeditor5.essentials',
'core/ckeditor5.htmlSupport',
......
......@@ -33,6 +33,7 @@
},
"devDependencies": {
"@ckeditor/ckeditor5-alignment": "~37.1.0",
"@ckeditor/ckeditor5-autoformat": "~37.1.0",
"@ckeditor/ckeditor5-basic-styles": "~37.1.0",
"@ckeditor/ckeditor5-block-quote": "~37.1.0",
"@ckeditor/ckeditor5-code-block": "~37.1.0",
......
......@@ -30,6 +30,13 @@
dependencies:
ckeditor5 "^37.1.0"
"@ckeditor/ckeditor5-autoformat@~37.1.0":
version "37.1.0"
resolved "https://registry.yarnpkg.com/@ckeditor/ckeditor5-autoformat/-/ckeditor5-autoformat-37.1.0.tgz#a4bfc9435388bb071a6bff019c8cfa961664234c"
integrity sha512-wZSuqsD6oz06fbE2zCn8PUDyax5YUDWFnB/26piLBu0HteRYFXJtIq6s2vA+zBbFfR3FL7362t+DP9VEHGigtw==
dependencies:
ckeditor5 "^37.1.0"
"@ckeditor/ckeditor5-basic-styles@~37.1.0":
version "37.1.0"
resolved "https://registry.yarnpkg.com/@ckeditor/ckeditor5-basic-styles/-/ckeditor5-basic-styles-37.1.0.tgz#d79a8dcf1b21b02bd29f17c6624fce5f627f671e"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment