@ckeditor/ckeditor5-code-block 45.2.1-alpha.9 → 46.0.0-alpha.0

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 e={21:e=>{"use strict";e.exports=function(e,t){Object.keys(t).forEach(function(n){e.setAttribute(n,t[n])})}},51:e=>{"use strict";e.exports=function(e){var t=document.createElement("style");return e.setAttributes(t,e.attributes),e.insert(t,e.options),t}},128:e=>{"use strict";var t={};e.exports=function(e,n){var o=function(e){if(void 0===t[e]){var n=document.querySelector(e);if(window.HTMLIFrameElement&&n instanceof window.HTMLIFrameElement)try{n=n.contentDocument.head}catch(e){n=null}t[e]=n}return t[e]}(e);if(!o)throw new Error("Couldn't find a style target. This probably means that the value for the 'insert' parameter is invalid.");o.appendChild(n)}},237:e=>{"use strict";e.exports=CKEditor5.dll},311:(e,t,n)=>{e.exports=n(237)("./src/ui.js")},331:(e,t,n)=>{e.exports=n(237)("./src/clipboard.js")},355:(e,t,n)=>{e.exports=n(237)("./src/icons.js")},507:(e,t,n)=>{e.exports=n(237)("./src/enter.js")},535:(e,t,n)=>{"use strict";n.d(t,{A:()=>s});var o=n(758),i=n.n(o),r=n(935),c=n.n(r)()(i());c.push([e.id,".ck-content pre{background:hsla(0,0%,78%,.3);border:1px solid #c4c4c4;border-radius:2px;color:#353535;direction:ltr;font-style:normal;min-width:200px;padding:1em;tab-size:4;text-align:left;white-space:pre-wrap}.ck-content pre code{background:unset;border-radius:0;padding:0}.ck.ck-editor__editable pre{position:relative}.ck.ck-editor__editable pre[data-language]:after{content:attr(data-language);position:absolute}:root{--ck-color-code-block-label-background:#757575}.ck.ck-editor__editable pre[data-language]:after{background:var(--ck-color-code-block-label-background);color:#fff;font-family:var(--ck-font-face);font-size:10px;line-height:16px;padding:var(--ck-spacing-tiny) var(--ck-spacing-medium);right:10px;top:-1px;white-space:nowrap}.ck.ck-code-block-dropdown .ck-dropdown__panel{max-height:250px;overflow-x:hidden;overflow-y:auto}",""]);const s=c},584:(e,t,n)=>{e.exports=n(237)("./src/utils.js")},591:e=>{"use strict";var t=[];function n(e){for(var n=-1,o=0;o<t.length;o++)if(t[o].identifier===e){n=o;break}return n}function o(e,o){for(var r={},c=[],s=0;s<e.length;s++){var a=e[s],l=o.base?a[0]+o.base:a[0],u=r[l]||0,d="".concat(l," ").concat(u);r[l]=u+1;var g=n(d),p={css:a[1],media:a[2],sourceMap:a[3],supports:a[4],layer:a[5]};if(-1!==g)t[g].references++,t[g].updater(p);else{var f=i(p,o);o.byIndex=s,t.splice(s,0,{identifier:d,updater:f,references:1})}c.push(d)}return c}function i(e,t){var n=t.domAPI(t);n.update(e);return function(t){if(t){if(t.css===e.css&&t.media===e.media&&t.sourceMap===e.sourceMap&&t.supports===e.supports&&t.layer===e.layer)return;n.update(e=t)}else n.remove()}}e.exports=function(e,i){var r=o(e=e||[],i=i||{});return function(e){e=e||[];for(var c=0;c<r.length;c++){var s=n(r[c]);t[s].references--}for(var a=o(e,i),l=0;l<r.length;l++){var u=n(r[l]);0===t[u].references&&(t[u].updater(),t.splice(u,1))}r=a}}},639:e=>{"use strict";var t,n=(t=[],function(e,n){return t[e]=n,t.filter(Boolean).join("\n")});function o(e,t,o,i){var r;if(o)r="";else{r="",i.supports&&(r+="@supports (".concat(i.supports,") {")),i.media&&(r+="@media ".concat(i.media," {"));var c=void 0!==i.layer;c&&(r+="@layer".concat(i.layer.length>0?" ".concat(i.layer):""," {")),r+=i.css,c&&(r+="}"),i.media&&(r+="}"),i.supports&&(r+="}")}if(e.styleSheet)e.styleSheet.cssText=n(t,r);else{var s=document.createTextNode(r),a=e.childNodes;a[t]&&e.removeChild(a[t]),a.length?e.insertBefore(s,a[t]):e.appendChild(s)}}var i={singleton:null,singletonCounter:0};e.exports=function(e){if("undefined"==typeof document)return{update:function(){},remove:function(){}};var t=i.singletonCounter++,n=i.singleton||(i.singleton=e.insertStyleElement(e));return{update:function(e){o(n,t,!1,e)},remove:function(e){o(n,t,!0,e)}}}},758:e=>{"use strict";e.exports=function(e){return e[1]}},782:(e,t,n)=>{e.exports=n(237)("./src/core.js")},783:(e,t,n)=>{e.exports=n(237)("./src/engine.js")},935:e=>{"use strict";e.exports=function(e){var t=[];return t.toString=function(){return this.map(function(t){var n="",o=void 0!==t[5];return t[4]&&(n+="@supports (".concat(t[4],") {")),t[2]&&(n+="@media ".concat(t[2]," {")),o&&(n+="@layer".concat(t[5].length>0?" ".concat(t[5]):""," {")),n+=e(t),o&&(n+="}"),t[2]&&(n+="}"),t[4]&&(n+="}"),n}).join("")},t.i=function(e,n,o,i,r){"string"==typeof e&&(e=[[null,e,void 0]]);var c={};if(o)for(var s=0;s<this.length;s++){var a=this[s][0];null!=a&&(c[a]=!0)}for(var l=0;l<e.length;l++){var u=[].concat(e[l]);o&&c[u[0]]||(void 0!==r&&(void 0===u[5]||(u[1]="@layer".concat(u[5].length>0?" ".concat(u[5]):""," {").concat(u[1],"}")),u[5]=r),n&&(u[2]?(u[1]="@media ".concat(u[2]," {").concat(u[1],"}"),u[2]=n):u[2]=n),i&&(u[4]?(u[1]="@supports (".concat(u[4],") {").concat(u[1],"}"),u[4]=i):u[4]="".concat(i)),t.push(u))}},t}}},t={};function n(o){var i=t[o];if(void 0!==i)return i.exports;var r=t[o]={id:o,exports:{}};return e[o](r,r.exports,n),r.exports}n.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return n.d(t,{a:t}),t},n.d=(e,t)=>{for(var o in t)n.o(t,o)&&!n.o(e,o)&&Object.defineProperty(e,o,{enumerable:!0,get:t[o]})},n.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),n.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var o={};(()=>{"use strict";n.r(o),n.d(o,{CodeBlock:()=>q,CodeBlockEditing:()=>x,CodeBlockUI:()=>V});var e=n(782),t=n(507),i=n(783),r=n(331),c=n(584);function s(e){const t=e.t,n=e.config.get("codeBlock.languages");for(const e of n)"Plain text"===e.label&&(e.label=t("Plain text")),void 0===e.class&&(e.class=`language-${e.language}`);return n}function a(e,t,n){const o={};for(const i of e)if("class"===t){o[i[t].split(" ").shift()]=i[n]}else o[i[t]]=i[n];return o}function l(e){return e.data.match(/^(\s*)/)[0]}function u(e){const t=e.document.selection,n=[];if(t.isCollapsed)return[t.anchor];const o=t.getFirstRange().getWalker({ignoreElementEnd:!0,direction:"backward"});for(const{item:t}of o){let o=t.is("$textProxy")?t.textNode:t;const i=o.parent;if(!i.is("element","codeBlock")||o.is("element","softBreak"))continue;for(;o.previousSibling&&!o.previousSibling.is("element","softBreak");)o=o.previousSibling;const r=o.is("$text")?o.startOffset+l(o).length:o.startOffset,c=e.createPositionAt(i,r);n.every(e=>!e.isEqual(c))&&n.push(c)}return n}function d(e){const t=(0,c.first)(e.getSelectedBlocks());return!!t&&t.is("element","codeBlock")}function g(e,t){return!t.is("rootElement")&&!e.isLimit(t)&&e.checkChild(t.parent,"codeBlock")}function p(e,t,n,o){const i=a(t,"language","label"),r=n.getAttribute("language");if(r in i){const t=i[r];return e("enter"===o?"Entering %0 code snippet":"Leaving %0 code snippet",t)}return e("enter"===o?"Entering code snippet":"Leaving code snippet")}function f(e,t){for(e.textNode&&(e=t.createPositionBefore(e.textNode));e.nodeBefore&&!e.nodeBefore.is("element","softBreak");)e=t.createPositionBefore(e.nodeBefore);const n=e.nodeAfter;return n&&n.is("$text")?n:null}class m extends e.Command{_lastLanguage;constructor(e){super(e),this._lastLanguage=null}refresh(){this.value=this._getValue(),this.isEnabled=this._checkEnabled()}execute(e={}){const t=this.editor,n=t.model,o=n.document.selection,i=s(t)[0],r=Array.from(o.getSelectedBlocks()),c=null==e.forceValue?!this.value:e.forceValue,a=function(e,t,n){if(e.language)return e.language;if(e.usePreviousLanguageChoice&&t)return t;return n}(e,this._lastLanguage,i.language);n.change(e=>{c?this._applyCodeBlock(e,r,a):this._removeCodeBlock(e,r)})}_getValue(){const e=this.editor.model.document.selection,t=(0,c.first)(e.getSelectedBlocks());return!!!!t?.is("element","codeBlock")&&t.getAttribute("language")}_checkEnabled(){if(this.value)return!0;const e=this.editor.model.document.selection,t=this.editor.model.schema,n=(0,c.first)(e.getSelectedBlocks());return!!n&&g(t,n)}_applyCodeBlock(e,t,n){this._lastLanguage=n;const o=this.editor.model.schema,i=t.filter(e=>g(o,e));for(const t of i)e.rename(t,"codeBlock"),e.setAttribute("language",n,t),o.removeDisallowedAttributes([t],e),Array.from(t.getChildren()).filter(e=>!o.checkChild(t,e)).forEach(t=>e.remove(t));i.reverse().forEach((t,n)=>{const o=i[n+1];t.previousSibling===o&&(e.appendElement("softBreak",o),e.merge(e.createPositionBefore(t)))})}_removeCodeBlock(e,t){const n=t.filter(e=>e.is("element","codeBlock"));for(const t of n){const n=e.createRangeOn(t);for(const t of Array.from(n.getItems()).reverse())if(t.is("element","softBreak")&&t.parent.is("element","codeBlock")){const{position:n}=e.split(e.createPositionBefore(t)),o=n.nodeAfter;e.rename(o,"paragraph"),e.removeAttribute("language",o),e.remove(t)}e.rename(t,"paragraph"),e.removeAttribute("language",t)}}}class h extends e.Command{_indentSequence;constructor(e){super(e),this._indentSequence=e.config.get("codeBlock.indentSequence")}refresh(){this.isEnabled=this._checkEnabled()}execute(){const e=this.editor.model;e.change(t=>{const n=u(e);for(const o of n){const n=t.createText(this._indentSequence);e.insertContent(n,o)}})}_checkEnabled(){return!!this._indentSequence&&d(this.editor.model.document.selection)}}class b extends e.Command{_indentSequence;constructor(e){super(e),this._indentSequence=e.config.get("codeBlock.indentSequence")}refresh(){this.isEnabled=this._checkEnabled()}execute(){const e=this.editor.model;e.change(()=>{const t=u(e);for(const n of t){const t=v(e,n,this._indentSequence);t&&e.deleteContent(e.createSelection(t))}})}_checkEnabled(){if(!this._indentSequence)return!1;const e=this.editor.model;return!!d(e.document.selection)&&u(e).some(t=>v(e,t,this._indentSequence))}}function v(e,t,n){const o=f(t,e);if(!o)return null;const i=l(o),r=i.lastIndexOf(n);if(r+n.length!==i.length)return null;if(-1===r)return null;const{parent:c,startOffset:s}=o;return e.createRange(e.createPositionAt(c,s+r),e.createPositionAt(c,s+r+n.length))}function k(e,t,n=!1){const o=a(t,"language","class"),i=a(t,"language","label");return(t,r,c)=>{const{writer:s,mapper:a,consumable:l}=c;if(!l.consume(r.item,"insert"))return;const u=r.item.getAttribute("language"),d=a.toViewPosition(e.createPositionBefore(r.item)),g={};n&&(g["data-language"]=i[u],g.spellcheck="false");const p=o[u]?{class:o[u]}:void 0,f=s.createContainerElement("code",p),m=s.createContainerElement("pre",g,f);s.insert(d,m),a.bindElements(r.item,f)}}const B="paragraph";class x extends e.Plugin{static get pluginName(){return"CodeBlockEditing"}static get isOfficialPlugin(){return!0}static get requires(){return[t.ShiftEnter]}constructor(e){super(e),e.config.define("codeBlock",{languages:[{language:"plaintext",label:"Plain text"},{language:"c",label:"C"},{language:"cs",label:"C#"},{language:"cpp",label:"C++"},{language:"css",label:"CSS"},{language:"diff",label:"Diff"},{language:"go",label:"Go"},{language:"html",label:"HTML"},{language:"java",label:"Java"},{language:"javascript",label:"JavaScript"},{language:"php",label:"PHP"},{language:"python",label:"Python"},{language:"ruby",label:"Ruby"},{language:"typescript",label:"TypeScript"},{language:"xml",label:"XML"}],indentSequence:"\t"})}init(){const e=this.editor,t=e.model.schema,n=e.model,o=e.editing.view,c=s(e);e.commands.add("codeBlock",new m(e)),e.commands.add("indentCodeBlock",new h(e)),e.commands.add("outdentCodeBlock",new b(e)),this.listenTo(o.document,"tab",(t,n)=>{const o=n.shiftKey?"outdentCodeBlock":"indentCodeBlock";e.commands.get(o).isEnabled&&(e.execute(o),n.stopPropagation(),n.preventDefault(),t.stop())},{context:"pre"}),t.register("codeBlock",{allowWhere:"$block",allowChildren:"$text",disallowChildren:"$inlineObject",allowAttributes:["language"],allowAttributesOf:"$listItem",isBlock:!0}),t.addAttributeCheck((e,n)=>{const o=e.getItem(e.length-2);if(t.getAttributeProperties(n).isFormatting&&o&&"codeBlock"==o.name)return!1}),e.editing.downcastDispatcher.on("insert:codeBlock",k(n,c,!0)),e.data.downcastDispatcher.on("insert:codeBlock",k(n,c)),e.data.downcastDispatcher.on("insert:softBreak",function(e){return(t,n,o)=>{if("codeBlock"!==n.item.parent.name)return;const{writer:i,mapper:r,consumable:c}=o;if(!c.consume(n.item,"insert"))return;const s=r.toViewPosition(e.createPositionBefore(n.item));i.insert(s,i.createText("\n"))}}(n),{priority:"high"}),e.data.upcastDispatcher.on("element:code",function(e,t){const n=a(t,"class","language"),o=t[0].language;return(e,t,i)=>{const r=t.viewItem,c=r.parent;if(!c||!c.is("element","pre"))return;if(t.modelCursor.findAncestor("codeBlock"))return;const{consumable:s,writer:a}=i;if(!s.test(r,{name:!0}))return;const l=a.createElement("codeBlock"),u=[...r.getClassNames()];u.length||u.push("");for(const e of u){const t=n[e];if(t){a.setAttribute("language",t,l);break}}l.hasAttribute("language")||a.setAttribute("language",o,l),i.convertChildren(r,l),i.safeInsert(l,t.modelCursor)&&(s.consume(r,{name:!0}),i.updateConversionResult(l,t))}}(0,c)),e.data.upcastDispatcher.on("text",(e,t,{consumable:n,writer:o})=>{let i=t.modelCursor;if(!n.test(t.viewItem))return;if(!i.findAncestor("codeBlock"))return;n.consume(t.viewItem);const r=t.viewItem.data.split("\n").map(e=>o.createText(e)),c=r[r.length-1];for(const e of r)if(o.insert(e,i),i=i.getShiftedBy(e.offsetSize),e!==c){const e=o.createElement("softBreak");o.insert(e,i),i=o.createPositionAfter(e)}t.modelRange=o.createRange(t.modelCursor,i),t.modelCursor=i}),e.data.upcastDispatcher.on("element:pre",(e,t,{consumable:n})=>{const o=t.viewItem;if(o.findAncestor("pre"))return;const i=Array.from(o.getChildren()),r=i.find(e=>e.is("element","code"));if(r)for(const e of i)e!==r&&e.is("$text")&&n.consume(e,{name:!0})},{priority:"high"}),this.listenTo(e.editing.view.document,"clipboardInput",(t,o)=>{let r=n.createRange(n.document.selection.anchor);if(o.targetRanges&&(r=e.editing.mapper.toModelRange(o.targetRanges[0])),!r.start.parent.is("element","codeBlock"))return;const c=o.dataTransfer.getData("text/plain"),s=new i.UpcastWriter(e.editing.view.document);o.content=function(e,t){const n=e.createDocumentFragment(),o=t.split("\n"),i=o.reduce((t,n,i)=>(t.push(n),i<o.length-1&&t.push(e.createElement("br")),t),[]);return e.appendChild(i,n),n}(s,c)}),e.plugins.has("ClipboardPipeline")&&e.plugins.get(r.ClipboardPipeline).on("contentInsertion",(n,o)=>{const i=e.model,r=i.document.selection;r.anchor.parent.is("element","codeBlock")&&i.change(e=>{const n=e.createRangeIn(o.content);for(const o of[...n.getItems()])o.is("node")&&!t.checkChild(r.anchor,o)&&e.remove(o)})}),this.listenTo(n,"getSelectedContent",(e,[o])=>{const i=o.anchor;!o.isCollapsed&&i.parent.is("element","codeBlock")&&i.hasSameParentAs(o.focus)&&n.change(n=>{const r=e.return;if(i.parent.is("element")&&(r.childCount>1||o.containsEntireContent(i.parent))){const t=n.createElement("codeBlock",i.parent.getAttributes());n.append(r,t);const o=n.createDocumentFragment();return n.append(t,o),void(e.return=o)}const c=r.getChild(0);t.checkAttribute(c,"code")&&n.setAttribute("code",!0,c)})})}afterInit(){const e=this.editor,t=e.commands,n=t.get("indent"),o=t.get("outdent");n&&n.registerChildCommand(t.get("indentCodeBlock"),{priority:"highest"}),o&&o.registerChildCommand(t.get("outdentCodeBlock")),this.listenTo(e.editing.view.document,"enter",(t,n)=>{e.model.document.selection.getLastPosition().parent.is("element","codeBlock")&&(function(e,t){const n=e.model,o=n.document,i=e.editing.view,r=o.selection.getLastPosition(),c=r.nodeAfter;if(t||!o.selection.isCollapsed||!r.isAtStart)return!1;if(!C(c))return!1;return e.model.change(t=>{e.execute("enter");const n=o.selection.anchor.parent.previousSibling;t.rename(n,B),t.setSelection(n,"in"),e.model.schema.removeDisallowedAttributes([n],t),t.remove(c)}),i.scrollToTheSelection(),!0}(e,n.isSoft)||function(e,t){const n=e.model,o=n.document,i=e.editing.view,r=o.selection.getLastPosition(),c=r.nodeBefore;let s;if(t||!o.selection.isCollapsed||!r.isAtEnd||!c||!c.previousSibling)return!1;if(C(c)&&C(c.previousSibling))s=n.createRange(n.createPositionBefore(c.previousSibling),n.createPositionAfter(c));else if(w(c)&&C(c.previousSibling)&&C(c.previousSibling.previousSibling))s=n.createRange(n.createPositionBefore(c.previousSibling.previousSibling),n.createPositionAfter(c));else{if(!(w(c)&&C(c.previousSibling)&&w(c.previousSibling.previousSibling)&&c.previousSibling.previousSibling&&C(c.previousSibling.previousSibling.previousSibling)))return!1;s=n.createRange(n.createPositionBefore(c.previousSibling.previousSibling.previousSibling),n.createPositionAfter(c))}return e.model.change(t=>{t.remove(s),e.execute("enter");const n=o.selection.anchor.parent;t.rename(n,B),e.model.schema.removeDisallowedAttributes([n],t)}),i.scrollToTheSelection(),!0}(e,n.isSoft)||function(e){const t=e.model,n=t.document;let o;const i=f(n.selection.getLastPosition(),t);i&&i.is("$text")&&(o=l(i));e.model.change(t=>{e.execute("shiftEnter"),o&&t.insertText(o,n.selection.anchor)})}(e),n.preventDefault(),t.stop())},{context:"pre"}),this._initAriaAnnouncements()}_initAriaAnnouncements(){const{model:e,ui:t,t:n}=this.editor,o=s(this.editor);let i=null;e.document.selection.on("change:range",()=>{const r=e.document.selection.focus.parent;t&&i!==r&&r.is("element")&&(i&&i.is("element","codeBlock")&&t.ariaLiveAnnouncer.announce(p(n,o,i,"leave")),r.is("element","codeBlock")&&t.ariaLiveAnnouncer.announce(p(n,o,r,"enter")),i=r)})}}function w(e){return e&&e.is("$text")&&!e.data.match(/\S/)}function C(e){return e&&e.is("element","softBreak")}var S=n(311),y=n(355),A=n(591),E=n.n(A),P=n(639),_=n.n(P),L=n(128),I=n.n(L),T=n(21),O=n.n(T),D=n(51),M=n.n(D),j=n(535),R={attributes:{"data-cke":!0}};R.setAttributes=O(),R.insert=I().bind(null,"head"),R.domAPI=_(),R.insertStyleElement=M();E()(j.A,R);j.A&&j.A.locals&&j.A.locals;class V extends e.Plugin{static get pluginName(){return"CodeBlockUI"}static get isOfficialPlugin(){return!0}init(){const e=this.editor,t=e.t,n=e.ui.componentFactory,o=s(e),i=this._getLanguageListItemDefinitions(o),r=e.commands.get("codeBlock");n.add("codeBlock",n=>{const o=(0,S.createDropdown)(n,S.SplitButtonView),c=o.buttonView,s=t("Insert code block");return c.set({label:s,tooltip:!0,icon:y.IconCodeBlock,isToggleable:!0}),c.bind("isOn").to(r,"value",e=>!!e),c.on("execute",()=>{e.execute("codeBlock",{usePreviousLanguageChoice:!0}),e.editing.view.focus()}),o.on("execute",t=>{e.execute("codeBlock",{language:t.source._codeBlockLanguage,forceValue:!0}),e.editing.view.focus()}),o.class="ck-code-block-dropdown",o.bind("isEnabled").to(r),(0,S.addListToDropdown)(o,i,{role:"menu",ariaLabel:s}),o}),n.add("menuBar:codeBlock",n=>{const o=new S.MenuBarMenuView(n);o.buttonView.set({role:"menuitem",label:t("Code block"),icon:y.IconCodeBlock}),o.bind("isEnabled").to(r);const c=new S.MenuBarMenuListView(n);c.set({ariaLabel:t("Insert code block")});for(const t of i){const i=new S.MenuBarMenuListItemView(n,o),s=new S.MenuBarMenuListItemButtonView(n);s.bind(...Object.keys(t.model)).to(t.model),s.set({isToggleable:!0,role:"menuitemcheckbox"}),s.delegate("execute").to(o),s.on("execute",()=>{e.execute("codeBlock",{language:t.model._codeBlockLanguage,forceValue:r.value!=t.model._codeBlockLanguage}),e.editing.view.focus()}),i.children.add(s),c.items.add(i)}return o.panelView.children.add(c),o})}_getLanguageListItemDefinitions(e){const t=this.editor.commands.get("codeBlock"),n=new c.Collection;for(const o of e){const e={type:"button",model:new S.ViewModel({_codeBlockLanguage:o.language,label:o.label,role:"menuitemradio",withText:!0})};e.model.bind("isOn").to(t,"value",t=>t===e.model._codeBlockLanguage),n.add(e)}return n}}class q extends e.Plugin{static get requires(){return[x,V]}static get pluginName(){return"CodeBlock"}static get isOfficialPlugin(){return!0}}})(),(window.CKEditor5=window.CKEditor5||{}).codeBlock=o})();
5
+ */(()=>{var e={21:e=>{"use strict";e.exports=function(e,t){Object.keys(t).forEach(function(n){e.setAttribute(n,t[n])})}},51:e=>{"use strict";e.exports=function(e){var t=document.createElement("style");return e.setAttributes(t,e.attributes),e.insert(t,e.options),t}},128:e=>{"use strict";var t={};e.exports=function(e,n){var o=function(e){if(void 0===t[e]){var n=document.querySelector(e);if(window.HTMLIFrameElement&&n instanceof window.HTMLIFrameElement)try{n=n.contentDocument.head}catch(e){n=null}t[e]=n}return t[e]}(e);if(!o)throw new Error("Couldn't find a style target. This probably means that the value for the 'insert' parameter is invalid.");o.appendChild(n)}},237:e=>{"use strict";e.exports=CKEditor5.dll},311:(e,t,n)=>{e.exports=n(237)("./src/ui.js")},331:(e,t,n)=>{e.exports=n(237)("./src/clipboard.js")},355:(e,t,n)=>{e.exports=n(237)("./src/icons.js")},507:(e,t,n)=>{e.exports=n(237)("./src/enter.js")},535:(e,t,n)=>{"use strict";n.d(t,{A:()=>s});var o=n(758),i=n.n(o),r=n(935),c=n.n(r)()(i());c.push([e.id,".ck-content pre{background:hsla(0,0%,78%,.3);border:1px solid #c4c4c4;border-radius:2px;color:#353535;direction:ltr;font-style:normal;min-width:200px;padding:1em;tab-size:4;text-align:left;white-space:pre-wrap}.ck-content pre code{background:unset;border-radius:0;padding:0}.ck.ck-editor__editable pre{position:relative}.ck.ck-editor__editable pre[data-language]:after{content:attr(data-language);position:absolute}:root{--ck-color-code-block-label-background:#757575}.ck.ck-editor__editable pre[data-language]:after{background:var(--ck-color-code-block-label-background);color:#fff;font-family:var(--ck-font-face);font-size:10px;line-height:16px;padding:var(--ck-spacing-tiny) var(--ck-spacing-medium);right:10px;top:-1px;white-space:nowrap}.ck.ck-code-block-dropdown .ck-dropdown__panel{max-height:250px;overflow-x:hidden;overflow-y:auto}",""]);const s=c},584:(e,t,n)=>{e.exports=n(237)("./src/utils.js")},591:e=>{"use strict";var t=[];function n(e){for(var n=-1,o=0;o<t.length;o++)if(t[o].identifier===e){n=o;break}return n}function o(e,o){for(var r={},c=[],s=0;s<e.length;s++){var a=e[s],l=o.base?a[0]+o.base:a[0],d=r[l]||0,u="".concat(l," ").concat(d);r[l]=d+1;var g=n(u),f={css:a[1],media:a[2],sourceMap:a[3],supports:a[4],layer:a[5]};if(-1!==g)t[g].references++,t[g].updater(f);else{var p=i(f,o);o.byIndex=s,t.splice(s,0,{identifier:u,updater:p,references:1})}c.push(u)}return c}function i(e,t){var n=t.domAPI(t);n.update(e);return function(t){if(t){if(t.css===e.css&&t.media===e.media&&t.sourceMap===e.sourceMap&&t.supports===e.supports&&t.layer===e.layer)return;n.update(e=t)}else n.remove()}}e.exports=function(e,i){var r=o(e=e||[],i=i||{});return function(e){e=e||[];for(var c=0;c<r.length;c++){var s=n(r[c]);t[s].references--}for(var a=o(e,i),l=0;l<r.length;l++){var d=n(r[l]);0===t[d].references&&(t[d].updater(),t.splice(d,1))}r=a}}},639:e=>{"use strict";var t,n=(t=[],function(e,n){return t[e]=n,t.filter(Boolean).join("\n")});function o(e,t,o,i){var r;if(o)r="";else{r="",i.supports&&(r+="@supports (".concat(i.supports,") {")),i.media&&(r+="@media ".concat(i.media," {"));var c=void 0!==i.layer;c&&(r+="@layer".concat(i.layer.length>0?" ".concat(i.layer):""," {")),r+=i.css,c&&(r+="}"),i.media&&(r+="}"),i.supports&&(r+="}")}if(e.styleSheet)e.styleSheet.cssText=n(t,r);else{var s=document.createTextNode(r),a=e.childNodes;a[t]&&e.removeChild(a[t]),a.length?e.insertBefore(s,a[t]):e.appendChild(s)}}var i={singleton:null,singletonCounter:0};e.exports=function(e){if("undefined"==typeof document)return{update:function(){},remove:function(){}};var t=i.singletonCounter++,n=i.singleton||(i.singleton=e.insertStyleElement(e));return{update:function(e){o(n,t,!1,e)},remove:function(e){o(n,t,!0,e)}}}},758:e=>{"use strict";e.exports=function(e){return e[1]}},782:(e,t,n)=>{e.exports=n(237)("./src/core.js")},783:(e,t,n)=>{e.exports=n(237)("./src/engine.js")},935:e=>{"use strict";e.exports=function(e){var t=[];return t.toString=function(){return this.map(function(t){var n="",o=void 0!==t[5];return t[4]&&(n+="@supports (".concat(t[4],") {")),t[2]&&(n+="@media ".concat(t[2]," {")),o&&(n+="@layer".concat(t[5].length>0?" ".concat(t[5]):""," {")),n+=e(t),o&&(n+="}"),t[2]&&(n+="}"),t[4]&&(n+="}"),n}).join("")},t.i=function(e,n,o,i,r){"string"==typeof e&&(e=[[null,e,void 0]]);var c={};if(o)for(var s=0;s<this.length;s++){var a=this[s][0];null!=a&&(c[a]=!0)}for(var l=0;l<e.length;l++){var d=[].concat(e[l]);o&&c[d[0]]||(void 0!==r&&(void 0===d[5]||(d[1]="@layer".concat(d[5].length>0?" ".concat(d[5]):""," {").concat(d[1],"}")),d[5]=r),n&&(d[2]?(d[1]="@media ".concat(d[2]," {").concat(d[1],"}"),d[2]=n):d[2]=n),i&&(d[4]?(d[1]="@supports (".concat(d[4],") {").concat(d[1],"}"),d[4]=i):d[4]="".concat(i)),t.push(d))}},t}}},t={};function n(o){var i=t[o];if(void 0!==i)return i.exports;var r=t[o]={id:o,exports:{}};return e[o](r,r.exports,n),r.exports}n.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return n.d(t,{a:t}),t},n.d=(e,t)=>{for(var o in t)n.o(t,o)&&!n.o(e,o)&&Object.defineProperty(e,o,{enumerable:!0,get:t[o]})},n.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),n.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var o={};(()=>{"use strict";n.r(o),n.d(o,{CodeBlock:()=>K,CodeBlockCommand:()=>h,CodeBlockEditing:()=>_,CodeBlockUI:()=>z,IndentCodeBlockCommand:()=>b,OutdentCodeBlockCommand:()=>k,_canBeCodeBlock:()=>f,_dataViewToModelCodeBlockInsertion:()=>w,_dataViewToModelCodeBlockOrphanNodeConsumer:()=>S,_dataViewToModelCodeBlockTextNewlinesInsertion:()=>x,_getCodeBlockAriaAnnouncement:()=>p,_getCodeBlockIndentOutdentPositions:()=>u,_getCodeBlockLeadingWhiteSpaces:()=>l,_getCodeBlockPropertyAssociation:()=>a,_getCodeBlockTextNodeAtLineStart:()=>m,_getNormalizedAndLocalizedCodeBlockLanguageDefinitions:()=>s,_isModelSelectionInCodeBlock:()=>g,_modelToDataViewCodeBlockSoftBreakInsertion:()=>C,_modelToViewCodeBlockInsertion:()=>B,_rawCodeBlockSnippetTextToViewDocumentFragment:()=>d});var e=n(782),t=n(507),i=n(783),r=n(331),c=n(584);function s(e){const t=e.t,n=e.config.get("codeBlock.languages");for(const e of n)"Plain text"===e.label&&(e.label=t("Plain text")),void 0===e.class&&(e.class=`language-${e.language}`);return n}function a(e,t,n){const o={};for(const i of e)if("class"===t){o[i[t].split(" ").shift()]=i[n]}else o[i[t]]=i[n];return o}function l(e){return e.data.match(/^(\s*)/)[0]}function d(e,t){const n=e.createDocumentFragment(),o=t.split("\n"),i=o.reduce((t,n,i)=>(t.push(n),i<o.length-1&&t.push(e.createElement("br")),t),[]);return e.appendChild(i,n),n}function u(e){const t=e.document.selection,n=[];if(t.isCollapsed)return[t.anchor];const o=t.getFirstRange().getWalker({ignoreElementEnd:!0,direction:"backward"});for(const{item:t}of o){let o=t.is("$textProxy")?t.textNode:t;const i=o.parent;if(!i.is("element","codeBlock")||o.is("element","softBreak"))continue;for(;o.previousSibling&&!o.previousSibling.is("element","softBreak");)o=o.previousSibling;const r=o.is("$text")?o.startOffset+l(o).length:o.startOffset,c=e.createPositionAt(i,r);n.every(e=>!e.isEqual(c))&&n.push(c)}return n}function g(e){const t=(0,c.first)(e.getSelectedBlocks());return!!t&&t.is("element","codeBlock")}function f(e,t){return!t.is("rootElement")&&!e.isLimit(t)&&e.checkChild(t.parent,"codeBlock")}function p(e,t,n,o){const i=a(t,"language","label"),r=n.getAttribute("language");if(r in i){const t=i[r];return e("enter"===o?"Entering %0 code snippet":"Leaving %0 code snippet",t)}return e("enter"===o?"Entering code snippet":"Leaving code snippet")}function m(e,t){for(e.textNode&&(e=t.createPositionBefore(e.textNode));e.nodeBefore&&!e.nodeBefore.is("element","softBreak");)e=t.createPositionBefore(e.nodeBefore);const n=e.nodeAfter;return n&&n.is("$text")?n:null}class h extends e.Command{_lastLanguage;constructor(e){super(e),this._lastLanguage=null}refresh(){this.value=this._getValue(),this.isEnabled=this._checkEnabled()}execute(e={}){const t=this.editor,n=t.model,o=n.document.selection,i=s(t)[0],r=Array.from(o.getSelectedBlocks()),c=null==e.forceValue?!this.value:e.forceValue,a=function(e,t,n){if(e.language)return e.language;if(e.usePreviousLanguageChoice&&t)return t;return n}(e,this._lastLanguage,i.language);n.change(e=>{c?this._applyCodeBlock(e,r,a):this._removeCodeBlock(e,r)})}_getValue(){const e=this.editor.model.document.selection,t=(0,c.first)(e.getSelectedBlocks());return!!!!t?.is("element","codeBlock")&&t.getAttribute("language")}_checkEnabled(){if(this.value)return!0;const e=this.editor.model.document.selection,t=this.editor.model.schema,n=(0,c.first)(e.getSelectedBlocks());return!!n&&f(t,n)}_applyCodeBlock(e,t,n){this._lastLanguage=n;const o=this.editor.model.schema,i=t.filter(e=>f(o,e));for(const t of i)e.rename(t,"codeBlock"),e.setAttribute("language",n,t),o.removeDisallowedAttributes([t],e),Array.from(t.getChildren()).filter(e=>!o.checkChild(t,e)).forEach(t=>e.remove(t));i.reverse().forEach((t,n)=>{const o=i[n+1];t.previousSibling===o&&(e.appendElement("softBreak",o),e.merge(e.createPositionBefore(t)))})}_removeCodeBlock(e,t){const n=t.filter(e=>e.is("element","codeBlock"));for(const t of n){const n=e.createRangeOn(t);for(const t of Array.from(n.getItems()).reverse())if(t.is("element","softBreak")&&t.parent.is("element","codeBlock")){const{position:n}=e.split(e.createPositionBefore(t)),o=n.nodeAfter;e.rename(o,"paragraph"),e.removeAttribute("language",o),e.remove(t)}e.rename(t,"paragraph"),e.removeAttribute("language",t)}}}class b extends e.Command{_indentSequence;constructor(e){super(e),this._indentSequence=e.config.get("codeBlock.indentSequence")}refresh(){this.isEnabled=this._checkEnabled()}execute(){const e=this.editor.model;e.change(t=>{const n=u(e);for(const o of n){const n=t.createText(this._indentSequence);e.insertContent(n,o)}})}_checkEnabled(){return!!this._indentSequence&&g(this.editor.model.document.selection)}}class k extends e.Command{_indentSequence;constructor(e){super(e),this._indentSequence=e.config.get("codeBlock.indentSequence")}refresh(){this.isEnabled=this._checkEnabled()}execute(){const e=this.editor.model;e.change(()=>{const t=u(e);for(const n of t){const t=v(e,n,this._indentSequence);t&&e.deleteContent(e.createSelection(t))}})}_checkEnabled(){if(!this._indentSequence)return!1;const e=this.editor.model;return!!g(e.document.selection)&&u(e).some(t=>v(e,t,this._indentSequence))}}function v(e,t,n){const o=m(t,e);if(!o)return null;const i=l(o),r=i.lastIndexOf(n);if(r+n.length!==i.length)return null;if(-1===r)return null;const{parent:c,startOffset:s}=o;return e.createRange(e.createPositionAt(c,s+r),e.createPositionAt(c,s+r+n.length))}function B(e,t,n=!1){const o=a(t,"language","class"),i=a(t,"language","label");return(t,r,c)=>{const{writer:s,mapper:a,consumable:l}=c;if(!l.consume(r.item,"insert"))return;const d=r.item.getAttribute("language"),u=a.toViewPosition(e.createPositionBefore(r.item)),g={};n&&(g["data-language"]=i[d],g.spellcheck="false");const f=o[d]?{class:o[d]}:void 0,p=s.createContainerElement("code",f),m=s.createContainerElement("pre",g,p);s.insert(u,m),a.bindElements(r.item,p)}}function C(e){return(t,n,o)=>{if("codeBlock"!==n.item.parent.name)return;const{writer:i,mapper:r,consumable:c}=o;if(!c.consume(n.item,"insert"))return;const s=r.toViewPosition(e.createPositionBefore(n.item));i.insert(s,i.createText("\n"))}}function w(e,t){const n=a(t,"class","language"),o=t[0].language;return(e,t,i)=>{const r=t.viewItem,c=r.parent;if(!c||!c.is("element","pre"))return;if(t.modelCursor.findAncestor("codeBlock"))return;const{consumable:s,writer:a}=i;if(!s.test(r,{name:!0}))return;const l=a.createElement("codeBlock"),d=[...r.getClassNames()];d.length||d.push("");for(const e of d){const t=n[e];if(t){s.consume(r,{classes:[e]}),a.setAttribute("language",t,l);break}}l.hasAttribute("language")||a.setAttribute("language",o,l),i.convertChildren(r,l),i.safeInsert(l,t.modelCursor)&&(s.consume(r,{name:!0}),i.updateConversionResult(l,t))}}function x(){return(e,t,{consumable:n,writer:o})=>{let i=t.modelCursor;if(!n.test(t.viewItem))return;if(!i.findAncestor("codeBlock"))return;n.consume(t.viewItem);const r=t.viewItem.data.split("\n").map(e=>o.createText(e)),c=r[r.length-1];for(const e of r)if(o.insert(e,i),i=i.getShiftedBy(e.offsetSize),e!==c){const e=o.createElement("softBreak");o.insert(e,i),i=o.createPositionAfter(e)}t.modelRange=o.createRange(t.modelCursor,i),t.modelCursor=i}}function S(){return(e,t,{consumable:n})=>{const o=t.viewItem;if(o.findAncestor("pre"))return;const i=Array.from(o.getChildren()),r=i.find(e=>e.is("element","code"));if(r)for(const e of i)e!==r&&e.is("$text")&&n.consume(e,{name:!0})}}const A="paragraph";class _ extends e.Plugin{static get pluginName(){return"CodeBlockEditing"}static get isOfficialPlugin(){return!0}static get requires(){return[t.ShiftEnter]}constructor(e){super(e),e.config.define("codeBlock",{languages:[{language:"plaintext",label:"Plain text"},{language:"c",label:"C"},{language:"cs",label:"C#"},{language:"cpp",label:"C++"},{language:"css",label:"CSS"},{language:"diff",label:"Diff"},{language:"go",label:"Go"},{language:"html",label:"HTML"},{language:"java",label:"Java"},{language:"javascript",label:"JavaScript"},{language:"php",label:"PHP"},{language:"python",label:"Python"},{language:"ruby",label:"Ruby"},{language:"typescript",label:"TypeScript"},{language:"xml",label:"XML"}],indentSequence:"\t"})}init(){const e=this.editor,t=e.model.schema,n=e.model,o=e.editing.view,c=s(e);e.commands.add("codeBlock",new h(e)),e.commands.add("indentCodeBlock",new b(e)),e.commands.add("outdentCodeBlock",new k(e)),this.listenTo(o.document,"tab",(t,n)=>{const o=n.shiftKey?"outdentCodeBlock":"indentCodeBlock";e.commands.get(o).isEnabled&&(e.execute(o),n.stopPropagation(),n.preventDefault(),t.stop())},{context:"pre"}),t.register("codeBlock",{allowWhere:"$block",allowChildren:"$text",disallowChildren:"$inlineObject",allowAttributes:["language"],allowAttributesOf:"$listItem",isBlock:!0}),t.addAttributeCheck((e,n)=>{const o=e.getItem(e.length-2);if(t.getAttributeProperties(n).isFormatting&&o&&"codeBlock"==o.name)return!1}),e.editing.downcastDispatcher.on("insert:codeBlock",B(n,c,!0)),e.data.downcastDispatcher.on("insert:codeBlock",B(n,c)),e.data.downcastDispatcher.on("insert:softBreak",C(n),{priority:"high"}),e.data.upcastDispatcher.on("element:code",w(0,c)),e.data.upcastDispatcher.on("text",(e,t,{consumable:n,writer:o})=>{let i=t.modelCursor;if(!n.test(t.viewItem))return;if(!i.findAncestor("codeBlock"))return;n.consume(t.viewItem);const r=t.viewItem.data.split("\n").map(e=>o.createText(e)),c=r[r.length-1];for(const e of r)if(o.insert(e,i),i=i.getShiftedBy(e.offsetSize),e!==c){const e=o.createElement("softBreak");o.insert(e,i),i=o.createPositionAfter(e)}t.modelRange=o.createRange(t.modelCursor,i),t.modelCursor=i}),e.data.upcastDispatcher.on("element:pre",S(),{priority:"high"}),this.listenTo(e.editing.view.document,"clipboardInput",(t,o)=>{let r=n.createRange(n.document.selection.anchor);if(o.targetRanges&&(r=e.editing.mapper.toModelRange(o.targetRanges[0])),!r.start.parent.is("element","codeBlock"))return;const c=o.dataTransfer.getData("text/plain"),s=new i.ViewUpcastWriter(e.editing.view.document);o.content=d(s,c)}),e.plugins.has("ClipboardPipeline")&&e.plugins.get(r.ClipboardPipeline).on("contentInsertion",(n,o)=>{const i=e.model,r=i.document.selection;r.anchor.parent.is("element","codeBlock")&&i.change(e=>{const n=e.createRangeIn(o.content);for(const o of[...n.getItems()])o.is("node")&&!t.checkChild(r.anchor,o)&&e.remove(o)})}),this.listenTo(n,"getSelectedContent",(e,[o])=>{const i=o.anchor;!o.isCollapsed&&i.parent.is("element","codeBlock")&&i.hasSameParentAs(o.focus)&&n.change(n=>{const r=e.return;if(i.parent.is("element")&&(r.childCount>1||o.containsEntireContent(i.parent))){const t=n.createElement("codeBlock",i.parent.getAttributes());n.append(r,t);const o=n.createDocumentFragment();return n.append(t,o),void(e.return=o)}const c=r.getChild(0);t.checkAttribute(c,"code")&&n.setAttribute("code",!0,c)})})}afterInit(){const e=this.editor,t=e.commands,n=t.get("indent"),o=t.get("outdent");n&&n.registerChildCommand(t.get("indentCodeBlock"),{priority:"highest"}),o&&o.registerChildCommand(t.get("outdentCodeBlock")),this.listenTo(e.editing.view.document,"enter",(t,n)=>{e.model.document.selection.getLastPosition().parent.is("element","codeBlock")&&(function(e,t){const n=e.model,o=n.document,i=e.editing.view,r=o.selection.getLastPosition(),c=r.nodeAfter;if(t||!o.selection.isCollapsed||!r.isAtStart)return!1;if(!P(c))return!1;return e.model.change(t=>{e.execute("enter");const n=o.selection.anchor.parent.previousSibling;t.rename(n,A),t.setSelection(n,"in"),e.model.schema.removeDisallowedAttributes([n],t),t.remove(c)}),i.scrollToTheSelection(),!0}(e,n.isSoft)||function(e,t){const n=e.model,o=n.document,i=e.editing.view,r=o.selection.getLastPosition(),c=r.nodeBefore;let s;if(t||!o.selection.isCollapsed||!r.isAtEnd||!c||!c.previousSibling)return!1;if(P(c)&&P(c.previousSibling))s=n.createRange(n.createPositionBefore(c.previousSibling),n.createPositionAfter(c));else if(y(c)&&P(c.previousSibling)&&P(c.previousSibling.previousSibling))s=n.createRange(n.createPositionBefore(c.previousSibling.previousSibling),n.createPositionAfter(c));else{if(!(y(c)&&P(c.previousSibling)&&y(c.previousSibling.previousSibling)&&c.previousSibling.previousSibling&&P(c.previousSibling.previousSibling.previousSibling)))return!1;s=n.createRange(n.createPositionBefore(c.previousSibling.previousSibling.previousSibling),n.createPositionAfter(c))}return e.model.change(t=>{t.remove(s),e.execute("enter");const n=o.selection.anchor.parent;t.rename(n,A),e.model.schema.removeDisallowedAttributes([n],t)}),i.scrollToTheSelection(),!0}(e,n.isSoft)||function(e){const t=e.model,n=t.document;let o;const i=m(n.selection.getLastPosition(),t);i&&i.is("$text")&&(o=l(i));e.model.change(t=>{e.execute("shiftEnter"),o&&t.insertText(o,n.selection.anchor)})}(e),n.preventDefault(),t.stop())},{context:"pre"}),this._initAriaAnnouncements()}_initAriaAnnouncements(){const{model:e,ui:t,t:n}=this.editor,o=s(this.editor);let i=null;e.document.selection.on("change:range",()=>{const r=e.document.selection.focus.parent;t&&i!==r&&r.is("element")&&(i&&i.is("element","codeBlock")&&t.ariaLiveAnnouncer.announce(p(n,o,i,"leave")),r.is("element","codeBlock")&&t.ariaLiveAnnouncer.announce(p(n,o,r,"enter")),i=r)})}}function y(e){return e&&e.is("$text")&&!e.data.match(/\S/)}function P(e){return e&&e.is("element","softBreak")}var E=n(311),I=n(355),L=n(591),T=n.n(L),O=n(639),D=n.n(O),M=n(128),V=n.n(M),R=n(21),j=n.n(R),N=n(51),q=n.n(N),$=n(535),F={attributes:{"data-cke":!0}};F.setAttributes=j(),F.insert=V().bind(null,"head"),F.domAPI=D(),F.insertStyleElement=q();T()($.A,F);$.A&&$.A.locals&&$.A.locals;class z extends e.Plugin{static get pluginName(){return"CodeBlockUI"}static get isOfficialPlugin(){return!0}init(){const e=this.editor,t=e.t,n=e.ui.componentFactory,o=s(e),i=this._getLanguageListItemDefinitions(o),r=e.commands.get("codeBlock");n.add("codeBlock",n=>{const o=(0,E.createDropdown)(n,E.SplitButtonView),c=o.buttonView,s=t("Insert code block");return c.set({label:s,tooltip:!0,icon:I.IconCodeBlock,isToggleable:!0}),c.bind("isOn").to(r,"value",e=>!!e),c.on("execute",()=>{e.execute("codeBlock",{usePreviousLanguageChoice:!0}),e.editing.view.focus()}),o.on("execute",t=>{e.execute("codeBlock",{language:t.source._codeBlockLanguage,forceValue:!0}),e.editing.view.focus()}),o.class="ck-code-block-dropdown",o.bind("isEnabled").to(r),(0,E.addListToDropdown)(o,i,{role:"menu",ariaLabel:s}),o}),n.add("menuBar:codeBlock",n=>{const o=new E.MenuBarMenuView(n);o.buttonView.set({role:"menuitem",label:t("Code block"),icon:I.IconCodeBlock}),o.bind("isEnabled").to(r);const c=new E.MenuBarMenuListView(n);c.set({ariaLabel:t("Insert code block")});for(const t of i){const i=new E.MenuBarMenuListItemView(n,o),s=new E.MenuBarMenuListItemButtonView(n);s.bind(...Object.keys(t.model)).to(t.model),s.set({isToggleable:!0,role:"menuitemcheckbox"}),s.delegate("execute").to(o),s.on("execute",()=>{e.execute("codeBlock",{language:t.model._codeBlockLanguage,forceValue:r.value!=t.model._codeBlockLanguage}),e.editing.view.focus()}),i.children.add(s),c.items.add(i)}return o.panelView.children.add(c),o})}_getLanguageListItemDefinitions(e){const t=this.editor.commands.get("codeBlock"),n=new c.Collection;for(const o of e){const e={type:"button",model:new E.UIModel({_codeBlockLanguage:o.language,label:o.label,role:"menuitemradio",withText:!0})};e.model.bind("isOn").to(t,"value",t=>t===e.model._codeBlockLanguage),n.add(e)}return n}}class K extends e.Plugin{static get requires(){return[_,z]}static get pluginName(){return"CodeBlock"}static get isOfficialPlugin(){return!0}}})(),(window.CKEditor5=window.CKEditor5||{}).codeBlock=o})();
package/dist/index.js CHANGED
@@ -4,10 +4,10 @@
4
4
  */
5
5
  import { Command, Plugin } from '@ckeditor/ckeditor5-core/dist/index.js';
6
6
  import { ShiftEnter } from '@ckeditor/ckeditor5-enter/dist/index.js';
7
- import { UpcastWriter } from '@ckeditor/ckeditor5-engine/dist/index.js';
7
+ import { ViewUpcastWriter } from '@ckeditor/ckeditor5-engine/dist/index.js';
8
8
  import { ClipboardPipeline } from '@ckeditor/ckeditor5-clipboard/dist/index.js';
9
9
  import { first, Collection } from '@ckeditor/ckeditor5-utils/dist/index.js';
10
- import { createDropdown, SplitButtonView, addListToDropdown, MenuBarMenuView, MenuBarMenuListView, MenuBarMenuListItemView, MenuBarMenuListItemButtonView, ViewModel } from '@ckeditor/ckeditor5-ui/dist/index.js';
10
+ import { createDropdown, SplitButtonView, addListToDropdown, MenuBarMenuView, MenuBarMenuListView, MenuBarMenuListItemView, MenuBarMenuListItemButtonView, UIModel } from '@ckeditor/ckeditor5-ui/dist/index.js';
11
11
  import { IconCodeBlock } from '@ckeditor/ckeditor5-icons/dist/index.js';
12
12
 
13
13
  /**
@@ -18,6 +18,8 @@ import { IconCodeBlock } from '@ckeditor/ckeditor5-icons/dist/index.js';
18
18
  * configuration is defined because the editor does not exist yet.
19
19
  * * To make sure each definition has a CSS class associated with it even if not specified
20
20
  * in the original configuration.
21
+ *
22
+ * @internal
21
23
  */ function getNormalizedAndLocalizedLanguageDefinitions(editor) {
22
24
  const t = editor.t;
23
25
  const languageDefs = editor.config.get('codeBlock.languages');
@@ -68,6 +70,8 @@ import { IconCodeBlock } from '@ckeditor/ckeditor5-icons/dist/index.js';
68
70
  * 'javascript': 'JavaScript'
69
71
  * }
70
72
  * ```
73
+ *
74
+ * @internal
71
75
  */ function getPropertyAssociation(languageDefs, key, value) {
72
76
  const association = {};
73
77
  for (const def of languageDefs){
@@ -84,6 +88,8 @@ import { IconCodeBlock } from '@ckeditor/ckeditor5-icons/dist/index.js';
84
88
  /**
85
89
  * For a given model text node, it returns white spaces that precede other characters in that node.
86
90
  * This corresponds to the indentation part of the code block line.
91
+ *
92
+ * @internal
87
93
  */ function getLeadingWhiteSpaces(textNode) {
88
94
  return textNode.data.match(/^(\s*)/)[0];
89
95
  }
@@ -109,6 +115,7 @@ import { IconCodeBlock } from '@ckeditor/ckeditor5-icons/dist/index.js';
109
115
  * ```
110
116
  *
111
117
  * @param text The raw code text to be converted.
118
+ * @internal
112
119
  */ function rawSnippetTextToViewDocumentFragment(writer, text) {
113
120
  const fragment = writer.createDocumentFragment();
114
121
  const textLines = text.split('\n');
@@ -158,6 +165,8 @@ import { IconCodeBlock } from '@ckeditor/ckeditor5-icons/dist/index.js';
158
165
  * the writer inserts or removes elements at the same time.
159
166
  *
160
167
  * **Note:** The position is located after the leading white spaces in the text node.
168
+ *
169
+ * @internal
161
170
  */ function getIndentOutdentPositions(model) {
162
171
  const selection = model.document.selection;
163
172
  const positions = [];
@@ -198,16 +207,19 @@ import { IconCodeBlock } from '@ckeditor/ckeditor5-icons/dist/index.js';
198
207
  }
199
208
  /**
200
209
  * Checks if any of the blocks within the model selection is a code block.
210
+ *
211
+ * @internal
201
212
  */ function isModelSelectionInCodeBlock(selection) {
202
213
  const firstBlock = first(selection.getSelectedBlocks());
203
214
  return !!firstBlock && firstBlock.is('element', 'codeBlock');
204
215
  }
205
216
  /**
206
- * Checks if an {@link module:engine/model/element~Element Element} can become a code block.
217
+ * Checks if an {@link module:engine/model/element~ModelElement Element} can become a code block.
207
218
  *
208
219
  * @param schema Model's schema.
209
220
  * @param element The element to be checked.
210
221
  * @returns Check result.
222
+ * @internal
211
223
  */ function canBeCodeBlock(schema, element) {
212
224
  if (element.is('rootElement') || schema.isLimit(element)) {
213
225
  return false;
@@ -216,6 +228,8 @@ import { IconCodeBlock } from '@ckeditor/ckeditor5-icons/dist/index.js';
216
228
  }
217
229
  /**
218
230
  * Get the translated message read by the screen reader when you enter or exit an element with your cursor.
231
+ *
232
+ * @internal
219
233
  */ function getCodeBlockAriaAnnouncement(t, languageDefs, element, direction) {
220
234
  const languagesToLabels = getPropertyAssociation(languageDefs, 'language', 'label');
221
235
  const codeBlockLanguage = element.getAttribute('language');
@@ -263,6 +277,8 @@ import { IconCodeBlock } from '@ckeditor/ckeditor5-icons/dist/index.js';
263
277
  * <codeBlock>foo<softBreak />bar<element />^</codeBlock> -> <codeBlock>foo<softBreak />[bar]<element /></codeBlock>
264
278
  * <codeBlock>foo<softBreak /><element />ba^r</codeBlock> -> null
265
279
  * ```
280
+ *
281
+ * @internal
266
282
  */ function getTextNodeAtLineStart(position, model) {
267
283
  // First, move position before a text node, if it is inside a text node.
268
284
  if (position.textNode) {
@@ -565,9 +581,9 @@ import { IconCodeBlock } from '@ckeditor/ckeditor5-icons/dist/index.js';
565
581
  // <codeBlock> ^foo bar</codeBlock> -> <codeBlock>[ ]foo bar</codeBlock>
566
582
  //
567
583
  // @param {<module:engine/model/model~Model>} model
568
- // @param {<module:engine/model/position~Position>} position
584
+ // @param {<module:engine/model/position~ModelPosition>} position
569
585
  // @param {String} sequence
570
- // @returns {<module:engine/model/range~Range>|null}
586
+ // @returns {<module:engine/model/range~ModelRange>|null}
571
587
  function getLastOutdentableSequenceRange(model, position, sequence) {
572
588
  // Positions start before each text node (code line). Get the node corresponding to the position.
573
589
  const nodeAtPosition = getTextNodeAtLineStart(position, model);
@@ -626,6 +642,7 @@ function getLastOutdentableSequenceRange(model, position, sequence) {
626
642
  * @param useLabels When `true`, the `<pre>` element will get a `data-language` attribute with a
627
643
  * human–readable label of the language. Used only in the editing.
628
644
  * @returns Returns a conversion callback.
645
+ * @internal
629
646
  */ function modelToViewCodeBlockInsertion(model, languageDefs, useLabels = false) {
630
647
  // Language CSS classes:
631
648
  //
@@ -683,6 +700,7 @@ function getLastOutdentableSequenceRange(model, position, sequence) {
683
700
  * ```
684
701
  *
685
702
  * @returns Returns a conversion callback.
703
+ * @internal
686
704
  */ function modelToDataViewSoftBreakInsertion(model) {
687
705
  return (evt, data, conversionApi)=>{
688
706
  if (data.item.parent.name !== 'codeBlock') {
@@ -713,6 +731,7 @@ function getLastOutdentableSequenceRange(model, position, sequence) {
713
731
  *
714
732
  * @param languageDefs The normalized language configuration passed to the feature.
715
733
  * @returns Returns a conversion callback.
734
+ * @internal
716
735
  */ function dataViewToModelCodeBlockInsertion(editingView, languageDefs) {
717
736
  // Language names associated with CSS classes:
718
737
  //
@@ -755,6 +774,11 @@ function getLastOutdentableSequenceRange(model, position, sequence) {
755
774
  for (const className of viewChildClasses){
756
775
  const language = classesToLanguages[className];
757
776
  if (language) {
777
+ consumable.consume(viewCodeElement, {
778
+ classes: [
779
+ className
780
+ ]
781
+ });
758
782
  writer.setAttribute('language', language, codeBlock);
759
783
  break;
760
784
  }
@@ -792,6 +816,7 @@ function getLastOutdentableSequenceRange(model, position, sequence) {
792
816
  * ```
793
817
  *
794
818
  * @returns {Function} Returns a conversion callback.
819
+ * @internal
795
820
  */ function dataViewToModelTextNewlinesInsertion() {
796
821
  return (evt, data, { consumable, writer })=>{
797
822
  let position = data.modelCursor;
@@ -852,6 +877,7 @@ function getLastOutdentableSequenceRange(model, position, sequence) {
852
877
  * ```
853
878
  *
854
879
  * @returns Returns a conversion callback.
880
+ * @internal
855
881
  */ function dataViewToModelOrphanNodeConsumer() {
856
882
  return (evt, data, { consumable })=>{
857
883
  const preElement = data.viewItem;
@@ -1043,7 +1069,7 @@ const DEFAULT_ELEMENT = 'paragraph';
1043
1069
  return;
1044
1070
  }
1045
1071
  const text = data.dataTransfer.getData('text/plain');
1046
- const writer = new UpcastWriter(editor.editing.view.document);
1072
+ const writer = new ViewUpcastWriter(editor.editing.view.document);
1047
1073
  // Pass the view fragment to the default clipboardInput handler.
1048
1074
  data.content = rawSnippetTextToViewDocumentFragment(writer, text);
1049
1075
  });
@@ -1413,7 +1439,7 @@ function isSoftBreakNode(node) {
1413
1439
  for (const languageDef of normalizedLanguageDefs){
1414
1440
  const definition = {
1415
1441
  type: 'button',
1416
- model: new ViewModel({
1442
+ model: new UIModel({
1417
1443
  _codeBlockLanguage: languageDef.language,
1418
1444
  label: languageDef.label,
1419
1445
  role: 'menuitemradio',
@@ -1458,5 +1484,5 @@ function isSoftBreakNode(node) {
1458
1484
  }
1459
1485
  }
1460
1486
 
1461
- export { CodeBlock, CodeBlockEditing, CodeBlockUI };
1487
+ export { CodeBlock, CodeBlockCommand, CodeBlockEditing, CodeBlockUI, IndentCodeBlockCommand, OutdentCodeBlockCommand, canBeCodeBlock as _canBeCodeBlock, dataViewToModelCodeBlockInsertion as _dataViewToModelCodeBlockInsertion, dataViewToModelOrphanNodeConsumer as _dataViewToModelCodeBlockOrphanNodeConsumer, dataViewToModelTextNewlinesInsertion as _dataViewToModelCodeBlockTextNewlinesInsertion, getCodeBlockAriaAnnouncement as _getCodeBlockAriaAnnouncement, getIndentOutdentPositions as _getCodeBlockIndentOutdentPositions, getLeadingWhiteSpaces as _getCodeBlockLeadingWhiteSpaces, getPropertyAssociation as _getCodeBlockPropertyAssociation, getTextNodeAtLineStart as _getCodeBlockTextNodeAtLineStart, getNormalizedAndLocalizedLanguageDefinitions as _getNormalizedAndLocalizedCodeBlockLanguageDefinitions, isModelSelectionInCodeBlock as _isModelSelectionInCodeBlock, modelToDataViewSoftBreakInsertion as _modelToDataViewCodeBlockSoftBreakInsertion, modelToViewCodeBlockInsertion as _modelToViewCodeBlockInsertion, rawSnippetTextToViewDocumentFragment as _rawCodeBlockSnippetTextToViewDocumentFragment };
1462
1488
  //# sourceMappingURL=index.js.map