@ckeditor/ckeditor5-autoformat 45.2.1-alpha.3 → 45.2.1-alpha.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,4 +2,4 @@
2
2
  /*!
3
3
  * @license Copyright (c) 2003-2025, CKSource Holding sp. z o.o. All rights reserved.
4
4
  * For licensing, see LICENSE.md.
5
- */(()=>{var t={237:t=>{"use strict";t.exports=CKEditor5.dll},584:(t,e,o)=>{t.exports=o(237)("./src/utils.js")},782:(t,e,o)=>{t.exports=o(237)("./src/core.js")},783:(t,e,o)=>{t.exports=o(237)("./src/engine.js")},834:(t,e,o)=>{t.exports=o(237)("./src/typing.js")}},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,blockAutoformatEditing:()=>r,inlineAutoformatEditing:()=>a});var t=o(782),e=o(834),s=o(783),n=o(584);function r(t,e,o,i){let r,a=null;"function"==typeof i?r=i:(a=t.commands.get(i),r=()=>{t.execute(i)}),t.model.document.on("change:data",((d,c)=>{if(a&&!a.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()),g=u[0];if(1!=u.length||"insert"!==g.type||"$text"!=g.name||1!=g.length)return;const h=g.position.parent;if(h.is("element","codeBlock"))return;if(h.is("element","listItem")&&"function"!=typeof i&&!["numberedList","bulletedList","todoList"].includes(i))return;if(a&&!0===a.value)return;const m=h.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(h,0),i=e.createPositionAt(h,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(h);!h.isEmpty||i.isEqual(o)||i.containsRange(o,!0)||e.remove(h)}n.detach(),t.model.enqueueChange((()=>{t.plugins.get("Delete").requestUndoOnBackspace()}))}))}))}function a(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 a=s+n+r;t+=e[0].length-a.length;const d=[t,t+s.length],c=[t+s.length+n.length,t+s.length+n.length+r.length];o.push(d),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,a=r.document.selection;if(!a.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=a.focus,g=u.parent,{text:h,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(g,0),u),r),f=n(h),p=d(m.start,f.format,r),b=d(m.start,f.remove,r);p.length&&b.length&&r.enqueueChange((e=>{if(!1!==i(e,p)){for(const t of b.reverse())e.remove(t);r.enqueueChange((()=>{t.plugins.get("Delete").requestUndoOnBackspace()}))}}))}))}function d(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"}static get isOfficialPlugin(){return!0}afterInit(){const t=this.editor,e=this.editor.t;this._addListAutoformats(),this._addBasicStylesAutoformats(),this._addHeadingAutoformats(),this._addBlockQuoteAutoformats(),this._addCodeBlockAutoformats(),this._addHorizontalLineAutoformats(),t.accessibility.addKeystrokeInfos({keystrokes:[{label:e("Revert autoformatting action"),keystroke:"Backspace"}]})}_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");a(this.editor,this,/(?:^|\s)(\*\*)([^*]+)(\*\*)$/g,t),a(this.editor,this,/(?:^|\s)(__)([^_]+)(__)$/g,t)}if(t.get("italic")){const t=l(this.editor,"italic");a(this.editor,this,/(?:^|\s)(\*)([^*_]+)(\*)$/g,t),a(this.editor,this,/(?:^|\s)(_)([^_]+)(_)$/g,t)}if(t.get("code")){const t=l(this.editor,"code");a(this.editor,this,/(`)([^`]+)(`)$/g,t)}if(t.get("strikethrough")){const t=l(this.editor,"strikethrough");a(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})();
5
+ */(()=>{var t={237:t=>{"use strict";t.exports=CKEditor5.dll},584:(t,e,o)=>{t.exports=o(237)("./src/utils.js")},782:(t,e,o)=>{t.exports=o(237)("./src/core.js")},783:(t,e,o)=>{t.exports=o(237)("./src/engine.js")},834:(t,e,o)=>{t.exports=o(237)("./src/typing.js")}},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,blockAutoformatEditing:()=>r,inlineAutoformatEditing:()=>a});var t=o(782),e=o(834),s=o(783),n=o(584);function r(t,e,o,i){let r,a=null;"function"==typeof i?r=i:(a=t.commands.get(i),r=()=>{t.execute(i)}),t.model.document.on("change:data",(d,c)=>{if(a&&!a.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()),g=u[0];if(1!=u.length||"insert"!==g.type||"$text"!=g.name||1!=g.length)return;const h=g.position.parent;if(h.is("element","codeBlock"))return;if(h.is("element","listItem")&&"function"!=typeof i&&!["numberedList","bulletedList","todoList"].includes(i))return;if(a&&!0===a.value)return;const m=h.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(h,0),i=e.createPositionAt(h,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(h);!h.isEmpty||i.isEqual(o)||i.containsRange(o,!0)||e.remove(h)}n.detach(),t.model.enqueueChange(()=>{t.plugins.get("Delete").requestUndoOnBackspace()})})})}function a(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 a=s+n+r;t+=e[0].length-a.length;const d=[t,t+s.length],c=[t+s.length+n.length,t+s.length+n.length+r.length];o.push(d),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,a=r.document.selection;if(!a.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=a.focus,g=u.parent,{text:h,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(g,0),u),r),f=n(h),p=d(m.start,f.format,r),b=d(m.start,f.remove,r);p.length&&b.length&&r.enqueueChange(e=>{if(!1!==i(e,p)){for(const t of b.reverse())e.remove(t);r.enqueueChange(()=>{t.plugins.get("Delete").requestUndoOnBackspace()})}})})}function d(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"}static get isOfficialPlugin(){return!0}afterInit(){const t=this.editor,e=this.editor.t;this._addListAutoformats(),this._addBasicStylesAutoformats(),this._addHeadingAutoformats(),this._addBlockQuoteAutoformats(),this._addCodeBlockAutoformats(),this._addHorizontalLineAutoformats(),t.accessibility.addKeystrokeInfos({keystrokes:[{label:e("Revert autoformatting action"),keystroke:"Backspace"}]})}_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");a(this.editor,this,/(?:^|\s)(\*\*)([^*]+)(\*\*)$/g,t),a(this.editor,this,/(?:^|\s)(__)([^_]+)(__)$/g,t)}if(t.get("italic")){const t=l(this.editor,"italic");a(this.editor,this,/(?:^|\s)(\*)([^*_]+)(\*)$/g,t),a(this.editor,this,/(?:^|\s)(_)([^_]+)(_)$/g,t)}if(t.get("code")){const t=l(this.editor,"code");a(this.editor,this,/(`)([^`]+)(`)$/g,t)}if(t.get("strikethrough")){const t=l(this.editor,"strikethrough");a(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})();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ckeditor/ckeditor5-autoformat",
3
- "version": "45.2.1-alpha.3",
3
+ "version": "45.2.1-alpha.5",
4
4
  "description": "Autoformatting feature for CKEditor 5.",
5
5
  "keywords": [
6
6
  "ckeditor",
@@ -13,12 +13,12 @@
13
13
  "type": "module",
14
14
  "main": "src/index.js",
15
15
  "dependencies": {
16
- "@ckeditor/ckeditor5-core": "45.2.1-alpha.3",
17
- "@ckeditor/ckeditor5-engine": "45.2.1-alpha.3",
18
- "@ckeditor/ckeditor5-heading": "45.2.1-alpha.3",
19
- "@ckeditor/ckeditor5-typing": "45.2.1-alpha.3",
20
- "@ckeditor/ckeditor5-utils": "45.2.1-alpha.3",
21
- "ckeditor5": "45.2.1-alpha.3"
16
+ "@ckeditor/ckeditor5-core": "45.2.1-alpha.5",
17
+ "@ckeditor/ckeditor5-engine": "45.2.1-alpha.5",
18
+ "@ckeditor/ckeditor5-heading": "45.2.1-alpha.5",
19
+ "@ckeditor/ckeditor5-typing": "45.2.1-alpha.5",
20
+ "@ckeditor/ckeditor5-utils": "45.2.1-alpha.5",
21
+ "ckeditor5": "45.2.1-alpha.5"
22
22
  },
23
23
  "author": "CKSource (http://cksource.com/)",
24
24
  "license": "SEE LICENSE IN LICENSE.md",