Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@ckeditor/ckeditor5-code-block

Package Overview
Dependencies
Maintainers
1
Versions
686
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ckeditor/ckeditor5-code-block - npm Package Compare versions

Comparing version 27.1.0 to 28.0.0

2

build/code-block.js

@@ -5,2 +5,2 @@ /*!

*/
window.CKEditor5=window.CKEditor5||{},window.CKEditor5.codeBlock=function(e){var t={};function n(o){if(t[o])return t[o].exports;var r=t[o]={i:o,l:!1,exports:{}};return e[o].call(r.exports,r,r.exports,n),r.l=!0,r.exports}return n.m=e,n.c=t,n.d=function(e,t,o){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:o})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var o=Object.create(null);if(n.r(o),Object.defineProperty(o,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var r in e)n.d(o,r,function(t){return e[t]}.bind(null,r));return o},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=9)}([function(e,t,n){e.exports=n(2)("./src/core.js")},function(e,t,n){e.exports=n(2)("./src/utils.js")},function(e,t){e.exports=CKEditor5.dll},function(e,t,n){e.exports=n(2)("./src/ui.js")},function(e,t,n){e.exports=n(2)("./src/enter.js")},function(e,t,n){e.exports=n(2)("./src/engine.js")},function(e,t,n){var o=n(7),r=n(8);"string"==typeof(r=r.__esModule?r.default:r)&&(r=[[e.i,r,""]]);var i={injectType:"singletonStyleTag",attributes:{"data-cke":!0},insert:"head",singleton:!0};o(r,i);e.exports=r.locals||{}},function(e,t,n){"use strict";var o,r=function(){return void 0===o&&(o=Boolean(window&&document&&document.all&&!window.atob)),o},i=function(){var e={};return function(t){if(void 0===e[t]){var n=document.querySelector(t);if(window.HTMLIFrameElement&&n instanceof window.HTMLIFrameElement)try{n=n.contentDocument.head}catch(e){n=null}e[t]=n}return e[t]}}(),a=[];function c(e){for(var t=-1,n=0;n<a.length;n++)if(a[n].identifier===e){t=n;break}return t}function s(e,t){for(var n={},o=[],r=0;r<e.length;r++){var i=e[r],s=t.base?i[0]+t.base:i[0],l=n[s]||0,d="".concat(s," ").concat(l);n[s]=l+1;var u=c(d),g={css:i[1],media:i[2],sourceMap:i[3]};-1!==u?(a[u].references++,a[u].updater(g)):a.push({identifier:d,updater:h(g,t),references:1}),o.push(d)}return o}function l(e){var t=document.createElement("style"),o=e.attributes||{};if(void 0===o.nonce){var r=n.nc;r&&(o.nonce=r)}if(Object.keys(o).forEach((function(e){t.setAttribute(e,o[e])})),"function"==typeof e.insert)e.insert(t);else{var a=i(e.insert||"head");if(!a)throw new Error("Couldn't find a style target. This probably means that the value for the 'insert' parameter is invalid.");a.appendChild(t)}return t}var d,u=(d=[],function(e,t){return d[e]=t,d.filter(Boolean).join("\n")});function g(e,t,n,o){var r=n?"":o.media?"@media ".concat(o.media," {").concat(o.css,"}"):o.css;if(e.styleSheet)e.styleSheet.cssText=u(t,r);else{var i=document.createTextNode(r),a=e.childNodes;a[t]&&e.removeChild(a[t]),a.length?e.insertBefore(i,a[t]):e.appendChild(i)}}function f(e,t,n){var o=n.css,r=n.media,i=n.sourceMap;if(r?e.setAttribute("media",r):e.removeAttribute("media"),i&&"undefined"!=typeof btoa&&(o+="\n/*# sourceMappingURL=data:application/json;base64,".concat(btoa(unescape(encodeURIComponent(JSON.stringify(i))))," */")),e.styleSheet)e.styleSheet.cssText=o;else{for(;e.firstChild;)e.removeChild(e.firstChild);e.appendChild(document.createTextNode(o))}}var m=null,p=0;function h(e,t){var n,o,r;if(t.singleton){var i=p++;n=m||(m=l(t)),o=g.bind(null,n,i,!1),r=g.bind(null,n,i,!0)}else n=l(t),o=f.bind(null,n,t),r=function(){!function(e){if(null===e.parentNode)return!1;e.parentNode.removeChild(e)}(n)};return o(e),function(t){if(t){if(t.css===e.css&&t.media===e.media&&t.sourceMap===e.sourceMap)return;o(e=t)}else r()}}e.exports=function(e,t){(t=t||{}).singleton||"boolean"==typeof t.singleton||(t.singleton=r());var n=s(e=e||[],t);return function(e){if(e=e||[],"[object Array]"===Object.prototype.toString.call(e)){for(var o=0;o<n.length;o++){var r=c(n[o]);a[r].references--}for(var i=s(e,t),l=0;l<n.length;l++){var d=c(n[l]);0===a[d].references&&(a[d].updater(),a.splice(d,1))}n=i}}}},function(e,t){e.exports=".ck-content pre{padding:1em;color:#353535;background:hsla(0,0%,78%,.3);border:1px solid #c4c4c4;border-radius:2px;text-align:left;direction:ltr;tab-size:4;white-space:pre-wrap;font-style:normal;min-width:200px}.ck-content pre code{background:unset;padding:0;border-radius: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{top:-1px;right:10px;background:var(--ck-color-code-block-label-background);font-size:10px;font-family:var(--ck-font-face);line-height:16px;padding:var(--ck-spacing-tiny) var(--ck-spacing-medium);color:#fff;white-space:nowrap}.ck.ck-code-block-dropdown .ck-dropdown__panel{max-height:250px;overflow-y:auto;overflow-x:hidden}"},function(e,t,n){"use strict";n.r(t);var o=n(0),r=n(4),i=n(5),a=n(1);function c(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 s(e,t,n){const o={};for(const r of e)"class"===t?o[r[t].split(" ").shift()]=r[n]:o[r[t]]=r[n];return o}function l(e){return e.data.match(/^(\s*)/)[0]}function d(e){const t=e.document.selection,n=[];if(t.isCollapsed)n.push(t.anchor);else{const o=t.getFirstRange().getWalker({ignoreElementEnd:!0,direction:"backward"});for(const{item:t}of o)if(t.is("$textProxy")&&t.parent.is("element","codeBlock")){const o=l(t.textNode),{parent:r,startOffset:i}=t.textNode,a=e.createPositionAt(r,i+o.length);n.push(a)}}return n}function u(e){const t=Object(a.first)(e.getSelectedBlocks());return t&&t.is("element","codeBlock")}class g extends o.Command{refresh(){this.value=this._getValue(),this.isEnabled=this._checkEnabled()}execute(e={}){const t=this.editor,n=t.model,o=n.document.selection,r=c(t)[0],i=Array.from(o.getSelectedBlocks()),a=void 0===e.forceValue?!this.value:e.forceValue,s=e.language||r.language;n.change(e=>{a?this._applyCodeBlock(e,i,s):this._removeCodeBlock(e,i)})}_getValue(){const e=this.editor.model.document.selection,t=Object(a.first)(e.getSelectedBlocks());return!!!(!t||!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=Object(a.first)(e.getSelectedBlocks());return!!n&&f(t,n)}_applyCodeBlock(e,t,n){const o=this.editor.model.schema,r=t.filter(e=>f(o,e));for(const t of r)e.rename(t,"codeBlock"),e.setAttribute("language",n,t),o.removeDisallowedAttributes([t],e);r.reverse().forEach((t,n)=>{const o=r[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));e.rename(n.nodeAfter,"paragraph"),e.removeAttribute("language",n.nodeAfter),e.remove(t)}e.rename(t,"paragraph"),e.removeAttribute("language",t)}}}function f(e,t){return!t.is("rootElement")&&!e.isLimit(t)&&e.checkChild(t.parent,"codeBlock")}class m extends o.Command{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=d(e);for(const e of n)t.insertText(this._indentSequence,e)})}_checkEnabled(){return!!this._indentSequence&&u(this.editor.model.document.selection)}}class p extends o.Command{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=d(e);for(const e of n){const n=h(this.editor.model,e,this._indentSequence);n&&t.remove(n)}})}_checkEnabled(){if(!this._indentSequence)return!1;const e=this.editor.model;return!!u(e.document.selection)&&d(e).some(t=>h(e,t,this._indentSequence))}}function h(e,t,n){const o=function(e){let t=e.parent.getChild(e.index);t&&!t.is("element","softBreak")||(t=e.nodeBefore);if(!t||t.is("element","softBreak"))return null;return t}(t);if(!o)return null;const r=l(o),i=r.lastIndexOf(n);if(i+n.length!==r.length)return null;if(-1===i)return null;const{parent:a,startOffset:c}=o;return e.createRange(e.createPositionAt(a,c+i),e.createPositionAt(a,c+i+n.length))}function b(e,t,n=!1){const o=s(t,"language","class"),r=s(t,"language","label");return(t,i,a)=>{const{writer:c,mapper:s,consumable:l}=a;if(!l.consume(i.item,"insert"))return;const d=i.item.getAttribute("language"),u=s.toViewPosition(e.createPositionBefore(i.item)),g={};n&&(g["data-language"]=r[d],g.spellcheck="false");const f=c.createContainerElement("pre",g),m=c.createContainerElement("code",{class:o[d]||null});c.insert(c.createPositionAt(f,0),m),c.insert(u,f),s.bindElements(i.item,m)}}class k extends o.Plugin{static get pluginName(){return"CodeBlockEditing"}static get requires(){return[r.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:"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=c(e);e.commands.add("codeBlock",new g(e)),e.commands.add("indentCodeBlock",new m(e)),e.commands.add("outdentCodeBlock",new p(e));const r=e=>(t,n)=>{this.editor.commands.get(e).isEnabled&&(this.editor.execute(e),n())};e.keystrokes.set("Tab",r("indentCodeBlock")),e.keystrokes.set("Shift+Tab",r("outdentCodeBlock")),t.register("codeBlock",{allowWhere:"$block",isBlock:!0,allowAttributes:["language"]}),t.extend("$text",{allowIn:"codeBlock"}),t.addAttributeCheck(e=>{if(e.endsWith("codeBlock $text"))return!1}),e.editing.downcastDispatcher.on("insert:codeBlock",b(n,o,!0)),e.data.downcastDispatcher.on("insert:codeBlock",b(n,o)),e.data.downcastDispatcher.on("insert:softBreak",function(e){return(t,n,o)=>{if("codeBlock"!==n.item.parent.name)return;const{writer:r,mapper:i,consumable:a}=o;if(!a.consume(n.item,"insert"))return;const c=i.toViewPosition(e.createPositionBefore(n.item));r.insert(c,r.createText("\n"))}}(n),{priority:"high"}),e.data.upcastDispatcher.on("element:pre",function(e,t){const n=s(t,"class","language"),o=t[0].language;return(t,r,i)=>{const a=r.viewItem,c=a.getChild(0);if(!c||!c.is("element","code"))return;const{consumable:s,writer:l}=i;if(!s.test(a,{name:!0})||!s.test(c,{name:!0}))return;const d=l.createElement("codeBlock"),u=[...c.getClassNames()];u.length||u.push("");for(const e of u){const t=n[e];if(t){l.setAttribute("language",t,d);break}}d.hasAttribute("language")||l.setAttribute("language",o,d);const g=function(e,t){const n=e.createDocumentFragment(),o=t.split("\n").map(t=>e.createText(t)),r=o[o.length-1];for(const t of o)e.append(t,n),t!==r&&e.appendElement("softBreak",n);return n}(l,[...e.createRangeIn(c)].filter(e=>"text"===e.type).map(({item:e})=>e.data).join(""));l.append(g,d),i.safeInsert(d,r.modelCursor)&&(s.consume(a,{name:!0}),s.consume(c,{name:!0}),i.updateConversionResult(d,r))}}(e.editing.view,o)),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 a=o.dataTransfer.getData("text/plain"),c=new i.UpcastWriter(e.editing.view.document);o.content=function(e,t){const n=e.createDocumentFragment(),o=t.split("\n"),r=o.reduce((t,n,r)=>(t.push(n),r<o.length-1&&t.push(e.createElement("br")),t),[]);return e.appendChild(r,n),n}(c,a)}),this.listenTo(n,"getSelectedContent",(e,[o])=>{const r=o.anchor;!o.isCollapsed&&r.parent.is("element","codeBlock")&&r.hasSameParentAs(o.focus)&&n.change(n=>{const i=e.return;if(i.childCount>1||o.containsEntireContent(r.parent)){const t=n.createElement("codeBlock",r.parent.getAttributes());n.append(i,t);const o=n.createDocumentFragment();n.append(t,o),e.return=o}else{const e=i.getChild(0);t.checkAttribute(e,"code")&&n.setAttribute("code",!0,e)}})})}afterInit(){const e=this.editor,t=e.commands,n=t.get("indent"),o=t.get("outdent");n&&n.registerChildCommand(t.get("indentCodeBlock")),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.document,o=e.editing.view,r=n.selection.getLastPosition(),i=r.nodeAfter;if(t||!n.selection.isCollapsed||!r.isAtStart)return!1;if(!i||!i.is("element","softBreak"))return!1;return e.model.change(t=>{e.execute("enter");const o=n.selection.anchor.parent.previousSibling;t.rename(o,"paragraph"),t.setSelection(o,"in"),e.model.schema.removeDisallowedAttributes([o],t),t.remove(i)}),o.scrollToTheSelection(),!0}(e,n.isSoft)||function(e,t){const n=e.model,o=n.document,r=e.editing.view,i=o.selection.getLastPosition(),a=i.nodeBefore;let c;if(t||!o.selection.isCollapsed||!i.isAtEnd||!a)return!1;if(a.is("element","softBreak"))c=n.createRangeOn(a);else{if(!a.is("$text")||a.data.match(/\S/)||!a.previousSibling||!a.previousSibling.is("element","softBreak"))return!1;c=n.createRange(n.createPositionBefore(a.previousSibling),n.createPositionAfter(a))}return e.model.change(t=>{t.remove(c),e.execute("enter");const n=o.selection.anchor.parent;t.rename(n,"paragraph"),e.model.schema.removeDisallowedAttributes([n],t)}),r.scrollToTheSelection(),!0}(e,n.isSoft)||function(e){const t=e.model.document,n=t.selection.getLastPosition(),o=n.nodeBefore||n.textNode;let r;o&&o.is("$text")&&(r=l(o));e.model.change(n=>{e.execute("shiftEnter"),r&&n.insertText(r,t.selection.anchor)})}(e),n.preventDefault(),t.stop())},{context:"pre"})}}var v=n(3);n(6);class B extends o.Plugin{static get pluginName(){return"CodeBlockUI"}init(){const e=this.editor,t=e.t,n=e.ui.componentFactory,o=c(e),r=o[0];n.add("codeBlock",n=>{const i=e.commands.get("codeBlock"),a=Object(v.createDropdown)(n,v.SplitButtonView),c=a.buttonView;return c.set({label:t("Insert code block"),tooltip:!0,icon:'<svg viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg"><path d="M12.87 12.61a.75.75 0 0 1-.089.976l-.085.07-3.154 2.254 3.412 2.414a.75.75 0 0 1 .237.95l-.057.095a.75.75 0 0 1-.95.237l-.096-.058-4.272-3.022-.003-1.223 4.01-2.867a.75.75 0 0 1 1.047.174zm2.795-.231.095.057 4.011 2.867-.003 1.223-4.272 3.022-.095.058a.75.75 0 0 1-.88-.151l-.07-.086-.058-.095a.75.75 0 0 1 .15-.88l.087-.07 3.412-2.414-3.154-2.253-.085-.071a.75.75 0 0 1 .862-1.207zM16 0a2 2 0 0 1 2 2v9.354l-.663-.492-.837-.001V2a.5.5 0 0 0-.5-.5H2a.5.5 0 0 0-.5.5v15a.5.5 0 0 0 .5.5h3.118L7.156 19H2a2 2 0 0 1-2-2V2a2 2 0 0 1 2-2h14zM5.009 15l.003 1H3v-1h2.009zm2.188-2-1.471 1H5v-1h2.197zM10 11v.095L8.668 12H7v-1h3zm4-2v1H7V9h7zm0-2v1H7V7h7zm-4-2v1H5V5h5zM6 3v1H3V3h3z"/></svg>',isToggleable:!0}),c.bind("isOn").to(i,"value",e=>!!e),c.on("execute",()=>{e.execute("codeBlock",{language:r.language}),e.editing.view.focus()}),a.on("execute",t=>{e.execute("codeBlock",{language:t.source._codeBlockLanguage,forceValue:!0}),e.editing.view.focus()}),a.class="ck-code-block-dropdown",a.bind("isEnabled").to(i),Object(v.addListToDropdown)(a,this._getLanguageListItemDefinitions(o)),a})}_getLanguageListItemDefinitions(e){const t=this.editor.commands.get("codeBlock"),n=new a.Collection;for(const o of e){const e={type:"button",model:new v.Model({_codeBlockLanguage:o.language,label:o.label,withText:!0})};e.model.bind("isOn").to(t,"value",t=>t===e.model._codeBlockLanguage),n.add(e)}return n}}class x extends o.Plugin{static get requires(){return[k,B]}static get pluginName(){return"CodeBlock"}}t.default={CodeBlock:x,CodeBlockEditing:k,CodeBlockUI:B}}]).default;
window.CKEditor5=window.CKEditor5||{},window.CKEditor5.codeBlock=function(e){var t={};function n(o){if(t[o])return t[o].exports;var r=t[o]={i:o,l:!1,exports:{}};return e[o].call(r.exports,r,r.exports,n),r.l=!0,r.exports}return n.m=e,n.c=t,n.d=function(e,t,o){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:o})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var o=Object.create(null);if(n.r(o),Object.defineProperty(o,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var r in e)n.d(o,r,function(t){return e[t]}.bind(null,r));return o},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=9)}([function(e,t,n){e.exports=n(2)("./src/core.js")},function(e,t,n){e.exports=n(2)("./src/utils.js")},function(e,t){e.exports=CKEditor5.dll},function(e,t,n){e.exports=n(2)("./src/ui.js")},function(e,t,n){e.exports=n(2)("./src/enter.js")},function(e,t,n){e.exports=n(2)("./src/engine.js")},function(e,t,n){var o=n(7),r=n(8);"string"==typeof(r=r.__esModule?r.default:r)&&(r=[[e.i,r,""]]);var i={injectType:"singletonStyleTag",attributes:{"data-cke":!0},insert:"head",singleton:!0};o(r,i);e.exports=r.locals||{}},function(e,t,n){"use strict";var o,r=function(){return void 0===o&&(o=Boolean(window&&document&&document.all&&!window.atob)),o},i=function(){var e={};return function(t){if(void 0===e[t]){var n=document.querySelector(t);if(window.HTMLIFrameElement&&n instanceof window.HTMLIFrameElement)try{n=n.contentDocument.head}catch(e){n=null}e[t]=n}return e[t]}}(),a=[];function c(e){for(var t=-1,n=0;n<a.length;n++)if(a[n].identifier===e){t=n;break}return t}function s(e,t){for(var n={},o=[],r=0;r<e.length;r++){var i=e[r],s=t.base?i[0]+t.base:i[0],l=n[s]||0,d="".concat(s," ").concat(l);n[s]=l+1;var u=c(d),f={css:i[1],media:i[2],sourceMap:i[3]};-1!==u?(a[u].references++,a[u].updater(f)):a.push({identifier:d,updater:h(f,t),references:1}),o.push(d)}return o}function l(e){var t=document.createElement("style"),o=e.attributes||{};if(void 0===o.nonce){var r=n.nc;r&&(o.nonce=r)}if(Object.keys(o).forEach((function(e){t.setAttribute(e,o[e])})),"function"==typeof e.insert)e.insert(t);else{var a=i(e.insert||"head");if(!a)throw new Error("Couldn't find a style target. This probably means that the value for the 'insert' parameter is invalid.");a.appendChild(t)}return t}var d,u=(d=[],function(e,t){return d[e]=t,d.filter(Boolean).join("\n")});function f(e,t,n,o){var r=n?"":o.media?"@media ".concat(o.media," {").concat(o.css,"}"):o.css;if(e.styleSheet)e.styleSheet.cssText=u(t,r);else{var i=document.createTextNode(r),a=e.childNodes;a[t]&&e.removeChild(a[t]),a.length?e.insertBefore(i,a[t]):e.appendChild(i)}}function g(e,t,n){var o=n.css,r=n.media,i=n.sourceMap;if(r?e.setAttribute("media",r):e.removeAttribute("media"),i&&"undefined"!=typeof btoa&&(o+="\n/*# sourceMappingURL=data:application/json;base64,".concat(btoa(unescape(encodeURIComponent(JSON.stringify(i))))," */")),e.styleSheet)e.styleSheet.cssText=o;else{for(;e.firstChild;)e.removeChild(e.firstChild);e.appendChild(document.createTextNode(o))}}var m=null,p=0;function h(e,t){var n,o,r;if(t.singleton){var i=p++;n=m||(m=l(t)),o=f.bind(null,n,i,!1),r=f.bind(null,n,i,!0)}else n=l(t),o=g.bind(null,n,t),r=function(){!function(e){if(null===e.parentNode)return!1;e.parentNode.removeChild(e)}(n)};return o(e),function(t){if(t){if(t.css===e.css&&t.media===e.media&&t.sourceMap===e.sourceMap)return;o(e=t)}else r()}}e.exports=function(e,t){(t=t||{}).singleton||"boolean"==typeof t.singleton||(t.singleton=r());var n=s(e=e||[],t);return function(e){if(e=e||[],"[object Array]"===Object.prototype.toString.call(e)){for(var o=0;o<n.length;o++){var r=c(n[o]);a[r].references--}for(var i=s(e,t),l=0;l<n.length;l++){var d=c(n[l]);0===a[d].references&&(a[d].updater(),a.splice(d,1))}n=i}}}},function(e,t){e.exports=".ck-content pre{padding:1em;color:#353535;background:hsla(0,0%,78%,.3);border:1px solid #c4c4c4;border-radius:2px;text-align:left;direction:ltr;tab-size:4;white-space:pre-wrap;font-style:normal;min-width:200px}.ck-content pre code{background:unset;padding:0;border-radius: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{top:-1px;right:10px;background:var(--ck-color-code-block-label-background);font-size:10px;font-family:var(--ck-font-face);line-height:16px;padding:var(--ck-spacing-tiny) var(--ck-spacing-medium);color:#fff;white-space:nowrap}.ck.ck-code-block-dropdown .ck-dropdown__panel{max-height:250px;overflow-y:auto;overflow-x:hidden}"},function(e,t,n){"use strict";n.r(t),n.d(t,"CodeBlock",(function(){return x})),n.d(t,"CodeBlockEditing",(function(){return k})),n.d(t,"CodeBlockUI",(function(){return B}));var o=n(0),r=n(4),i=n(5),a=n(1);function c(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 s(e,t,n){const o={};for(const r of e)"class"===t?o[r[t].split(" ").shift()]=r[n]:o[r[t]]=r[n];return o}function l(e){return e.data.match(/^(\s*)/)[0]}function d(e){const t=e.document.selection,n=[];if(t.isCollapsed)n.push(t.anchor);else{const o=t.getFirstRange().getWalker({ignoreElementEnd:!0,direction:"backward"});for(const{item:t}of o)if(t.is("$textProxy")&&t.parent.is("element","codeBlock")){const o=l(t.textNode),{parent:r,startOffset:i}=t.textNode,a=e.createPositionAt(r,i+o.length);n.push(a)}}return n}function u(e){const t=Object(a.first)(e.getSelectedBlocks());return t&&t.is("element","codeBlock")}class f extends o.Command{refresh(){this.value=this._getValue(),this.isEnabled=this._checkEnabled()}execute(e={}){const t=this.editor,n=t.model,o=n.document.selection,r=c(t)[0],i=Array.from(o.getSelectedBlocks()),a=void 0===e.forceValue?!this.value:e.forceValue,s=e.language||r.language;n.change(e=>{a?this._applyCodeBlock(e,i,s):this._removeCodeBlock(e,i)})}_getValue(){const e=this.editor.model.document.selection,t=Object(a.first)(e.getSelectedBlocks());return!!!(!t||!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=Object(a.first)(e.getSelectedBlocks());return!!n&&g(t,n)}_applyCodeBlock(e,t,n){const o=this.editor.model.schema,r=t.filter(e=>g(o,e));for(const t of r)e.rename(t,"codeBlock"),e.setAttribute("language",n,t),o.removeDisallowedAttributes([t],e);r.reverse().forEach((t,n)=>{const o=r[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));e.rename(n.nodeAfter,"paragraph"),e.removeAttribute("language",n.nodeAfter),e.remove(t)}e.rename(t,"paragraph"),e.removeAttribute("language",t)}}}function g(e,t){return!t.is("rootElement")&&!e.isLimit(t)&&e.checkChild(t.parent,"codeBlock")}class m extends o.Command{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=d(e);for(const e of n)t.insertText(this._indentSequence,e)})}_checkEnabled(){return!!this._indentSequence&&u(this.editor.model.document.selection)}}class p extends o.Command{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=d(e);for(const e of n){const n=h(this.editor.model,e,this._indentSequence);n&&t.remove(n)}})}_checkEnabled(){if(!this._indentSequence)return!1;const e=this.editor.model;return!!u(e.document.selection)&&d(e).some(t=>h(e,t,this._indentSequence))}}function h(e,t,n){const o=function(e){let t=e.parent.getChild(e.index);t&&!t.is("element","softBreak")||(t=e.nodeBefore);if(!t||t.is("element","softBreak"))return null;return t}(t);if(!o)return null;const r=l(o),i=r.lastIndexOf(n);if(i+n.length!==r.length)return null;if(-1===i)return null;const{parent:a,startOffset:c}=o;return e.createRange(e.createPositionAt(a,c+i),e.createPositionAt(a,c+i+n.length))}function b(e,t,n=!1){const o=s(t,"language","class"),r=s(t,"language","label");return(t,i,a)=>{const{writer:c,mapper:s,consumable:l}=a;if(!l.consume(i.item,"insert"))return;const d=i.item.getAttribute("language"),u=s.toViewPosition(e.createPositionBefore(i.item)),f={};n&&(f["data-language"]=r[d],f.spellcheck="false");const g=c.createContainerElement("pre",f),m=c.createContainerElement("code",{class:o[d]||null});c.insert(c.createPositionAt(g,0),m),c.insert(u,g),s.bindElements(i.item,m)}}class k extends o.Plugin{static get pluginName(){return"CodeBlockEditing"}static get requires(){return[r.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:"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(e));e.commands.add("codeBlock",new f(e)),e.commands.add("indentCodeBlock",new m(e)),e.commands.add("outdentCodeBlock",new p(e));const r=e=>(t,n)=>{this.editor.commands.get(e).isEnabled&&(this.editor.execute(e),n())};e.keystrokes.set("Tab",r("indentCodeBlock")),e.keystrokes.set("Shift+Tab",r("outdentCodeBlock")),t.register("codeBlock",{allowWhere:"$block",allowChildren:"$text",isBlock:!0,allowAttributes:["language"]}),t.addAttributeCheck(e=>{if(e.endsWith("codeBlock $text"))return!1}),e.editing.downcastDispatcher.on("insert:codeBlock",b(n,o,!0)),e.data.downcastDispatcher.on("insert:codeBlock",b(n,o)),e.data.downcastDispatcher.on("insert:softBreak",function(e){return(t,n,o)=>{if("codeBlock"!==n.item.parent.name)return;const{writer:r,mapper:i,consumable:a}=o;if(!a.consume(n.item,"insert"))return;const c=i.toViewPosition(e.createPositionBefore(n.item));r.insert(c,r.createText("\n"))}}(n),{priority:"high"}),e.data.upcastDispatcher.on("element:code",function(e,t){const n=s(t,"class","language"),o=t[0].language;return(e,t,r)=>{const i=t.viewItem,a=i.parent;if(!a||!a.is("element","pre"))return;if(t.modelCursor.findAncestor("codeBlock"))return;const{consumable:c,writer:s}=r;if(!c.test(i,{name:!0}))return;const l=s.createElement("codeBlock"),d=[...i.getClassNames()];d.length||d.push("");for(const e of d){const t=n[e];if(t){s.setAttribute("language",t,l);break}}l.hasAttribute("language")||s.setAttribute("language",o,l),r.convertChildren(i,l),r.safeInsert(l,t.modelCursor)&&(c.consume(i,{name:!0}),r.updateConversionResult(l,t))}}(0,o)),e.data.upcastDispatcher.on("text",(e,t,{consumable:n,writer:o})=>{let r=t.modelCursor;if(!n.test(t.viewItem))return;if(!r.findAncestor("codeBlock"))return;n.consume(t.viewItem);const i=t.viewItem.data.split("\n").map(e=>o.createText(e)),a=i[i.length-1];for(const e of i)if(o.insert(e,r),r=r.getShiftedBy(e.offsetSize),e!==a){const e=o.createElement("softBreak");o.insert(e,r),r=o.createPositionAfter(e)}t.modelRange=o.createRange(t.modelCursor,r),t.modelCursor=r}),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 a=o.dataTransfer.getData("text/plain"),c=new i.UpcastWriter(e.editing.view.document);o.content=function(e,t){const n=e.createDocumentFragment(),o=t.split("\n"),r=o.reduce((t,n,r)=>(t.push(n),r<o.length-1&&t.push(e.createElement("br")),t),[]);return e.appendChild(r,n),n}(c,a)}),this.listenTo(n,"getSelectedContent",(e,[o])=>{const r=o.anchor;!o.isCollapsed&&r.parent.is("element","codeBlock")&&r.hasSameParentAs(o.focus)&&n.change(n=>{const i=e.return;if(i.childCount>1||o.containsEntireContent(r.parent)){const t=n.createElement("codeBlock",r.parent.getAttributes());n.append(i,t);const o=n.createDocumentFragment();n.append(t,o),e.return=o}else{const e=i.getChild(0);t.checkAttribute(e,"code")&&n.setAttribute("code",!0,e)}})})}afterInit(){const e=this.editor,t=e.commands,n=t.get("indent"),o=t.get("outdent");n&&n.registerChildCommand(t.get("indentCodeBlock")),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.document,o=e.editing.view,r=n.selection.getLastPosition(),i=r.nodeAfter;if(t||!n.selection.isCollapsed||!r.isAtStart)return!1;if(!i||!i.is("element","softBreak"))return!1;return e.model.change(t=>{e.execute("enter");const o=n.selection.anchor.parent.previousSibling;t.rename(o,"paragraph"),t.setSelection(o,"in"),e.model.schema.removeDisallowedAttributes([o],t),t.remove(i)}),o.scrollToTheSelection(),!0}(e,n.isSoft)||function(e,t){const n=e.model,o=n.document,r=e.editing.view,i=o.selection.getLastPosition(),a=i.nodeBefore;let c;if(t||!o.selection.isCollapsed||!i.isAtEnd||!a)return!1;if(a.is("element","softBreak"))c=n.createRangeOn(a);else{if(!a.is("$text")||a.data.match(/\S/)||!a.previousSibling||!a.previousSibling.is("element","softBreak"))return!1;c=n.createRange(n.createPositionBefore(a.previousSibling),n.createPositionAfter(a))}return e.model.change(t=>{t.remove(c),e.execute("enter");const n=o.selection.anchor.parent;t.rename(n,"paragraph"),e.model.schema.removeDisallowedAttributes([n],t)}),r.scrollToTheSelection(),!0}(e,n.isSoft)||function(e){const t=e.model.document,n=t.selection.getLastPosition(),o=n.nodeBefore||n.textNode;let r;o&&o.is("$text")&&(r=l(o));e.model.change(n=>{e.execute("shiftEnter"),r&&n.insertText(r,t.selection.anchor)})}(e),n.preventDefault(),t.stop())},{context:"pre"})}}var v=n(3);n(6);class B extends o.Plugin{static get pluginName(){return"CodeBlockUI"}init(){const e=this.editor,t=e.t,n=e.ui.componentFactory,o=c(e),r=o[0];n.add("codeBlock",n=>{const i=e.commands.get("codeBlock"),a=Object(v.createDropdown)(n,v.SplitButtonView),c=a.buttonView;return c.set({label:t("Insert code block"),tooltip:!0,icon:'<svg viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg"><path d="M12.87 12.61a.75.75 0 0 1-.089.976l-.085.07-3.154 2.254 3.412 2.414a.75.75 0 0 1 .237.95l-.057.095a.75.75 0 0 1-.95.237l-.096-.058-4.272-3.022-.003-1.223 4.01-2.867a.75.75 0 0 1 1.047.174zm2.795-.231.095.057 4.011 2.867-.003 1.223-4.272 3.022-.095.058a.75.75 0 0 1-.88-.151l-.07-.086-.058-.095a.75.75 0 0 1 .15-.88l.087-.07 3.412-2.414-3.154-2.253-.085-.071a.75.75 0 0 1 .862-1.207zM16 0a2 2 0 0 1 2 2v9.354l-.663-.492-.837-.001V2a.5.5 0 0 0-.5-.5H2a.5.5 0 0 0-.5.5v15a.5.5 0 0 0 .5.5h3.118L7.156 19H2a2 2 0 0 1-2-2V2a2 2 0 0 1 2-2h14zM5.009 15l.003 1H3v-1h2.009zm2.188-2-1.471 1H5v-1h2.197zM10 11v.095L8.668 12H7v-1h3zm4-2v1H7V9h7zm0-2v1H7V7h7zm-4-2v1H5V5h5zM6 3v1H3V3h3z"/></svg>',isToggleable:!0}),c.bind("isOn").to(i,"value",e=>!!e),c.on("execute",()=>{e.execute("codeBlock",{language:r.language}),e.editing.view.focus()}),a.on("execute",t=>{e.execute("codeBlock",{language:t.source._codeBlockLanguage,forceValue:!0}),e.editing.view.focus()}),a.class="ck-code-block-dropdown",a.bind("isEnabled").to(i),Object(v.addListToDropdown)(a,this._getLanguageListItemDefinitions(o)),a})}_getLanguageListItemDefinitions(e){const t=this.editor.commands.get("codeBlock"),n=new a.Collection;for(const o of e){const e={type:"button",model:new v.Model({_codeBlockLanguage:o.language,label:o.label,withText:!0})};e.model.bind("isOn").to(t,"value",t=>t===e.model._codeBlockLanguage),n.add(e)}return n}}class x extends o.Plugin{static get requires(){return[k,B]}static get pluginName(){return"CodeBlock"}}}]);
{
"name": "@ckeditor/ckeditor5-code-block",
"version": "27.1.0",
"version": "28.0.0",
"description": "Code Block feature for CKEditor 5.",

@@ -14,21 +14,21 @@ "keywords": [

"dependencies": {
"ckeditor5": "^27.1.0"
"ckeditor5": "^28.0.0"
},
"devDependencies": {
"@ckeditor/ckeditor5-alignment": "^27.1.0",
"@ckeditor/ckeditor5-autoformat": "^27.1.0",
"@ckeditor/ckeditor5-basic-styles": "^27.1.0",
"@ckeditor/ckeditor5-block-quote": "^27.1.0",
"@ckeditor/ckeditor5-clipboard": "^27.1.0",
"@ckeditor/ckeditor5-core": "^27.1.0",
"@ckeditor/ckeditor5-dev-utils": "^24.0.0",
"@ckeditor/ckeditor5-engine": "^27.1.0",
"@ckeditor/ckeditor5-enter": "^27.1.0",
"@ckeditor/ckeditor5-editor-classic": "^27.1.0",
"@ckeditor/ckeditor5-indent": "^27.1.0",
"@ckeditor/ckeditor5-markdown-gfm": "^27.1.0",
"@ckeditor/ckeditor5-paragraph": "^27.1.0",
"@ckeditor/ckeditor5-theme-lark": "^27.1.0",
"@ckeditor/ckeditor5-undo": "^27.1.0",
"@ckeditor/ckeditor5-utils": "^27.1.0",
"@ckeditor/ckeditor5-alignment": "^28.0.0",
"@ckeditor/ckeditor5-autoformat": "^28.0.0",
"@ckeditor/ckeditor5-basic-styles": "^28.0.0",
"@ckeditor/ckeditor5-block-quote": "^28.0.0",
"@ckeditor/ckeditor5-clipboard": "^28.0.0",
"@ckeditor/ckeditor5-core": "^28.0.0",
"@ckeditor/ckeditor5-dev-utils": "^25.0.0",
"@ckeditor/ckeditor5-engine": "^28.0.0",
"@ckeditor/ckeditor5-enter": "^28.0.0",
"@ckeditor/ckeditor5-editor-classic": "^28.0.0",
"@ckeditor/ckeditor5-indent": "^28.0.0",
"@ckeditor/ckeditor5-markdown-gfm": "^28.0.0",
"@ckeditor/ckeditor5-paragraph": "^28.0.0",
"@ckeditor/ckeditor5-theme-lark": "^28.0.0",
"@ckeditor/ckeditor5-undo": "^28.0.0",
"@ckeditor/ckeditor5-utils": "^28.0.0",
"webpack": "^4.43.0",

@@ -35,0 +35,0 @@ "webpack-cli": "^3.3.11"

@@ -116,2 +116,3 @@ /**

allowWhere: '$block',
allowChildren: '$text',
isBlock: true,

@@ -121,6 +122,2 @@ allowAttributes: [ 'language' ]

schema.extend( '$text', {
allowIn: 'codeBlock'
} );
// Disallow all attributes on $text inside `codeBlock`.

@@ -127,0 +124,0 @@ schema.addAttributeCheck( context => {

@@ -10,10 +10,4 @@ /**

import CodeBlock from './codeblock';
import CodeBlockEditing from './codeblockediting';
import CodeBlockUI from './codeblockui';
export default {
CodeBlock,
CodeBlockEditing,
CodeBlockUI
};
export { default as CodeBlock } from './codeblock';
export { default as CodeBlockEditing } from './codeblockediting';
export { default as CodeBlockUI } from './codeblockui';
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc