@ckeditor/ckeditor5-highlight 36.0.0 → 37.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-2023, CKSource Holding sp. z o.o. All rights reserved.
4
4
  * For licensing, see LICENSE.md.
5
- */(()=>{var e={458:(e,t,i)=>{"use strict";i.d(t,{Z:()=>o});var r=i(609),n=i.n(r)()((function(e){return e[1]}));n.push([e.id,":root{--ck-highlight-marker-yellow:#fdfd77;--ck-highlight-marker-green:#62f962;--ck-highlight-marker-pink:#fc7899;--ck-highlight-marker-blue:#72ccfd;--ck-highlight-pen-red:#e71313;--ck-highlight-pen-green:#128a00}.ck-content .marker-yellow{background-color:var(--ck-highlight-marker-yellow)}.ck-content .marker-green{background-color:var(--ck-highlight-marker-green)}.ck-content .marker-pink{background-color:var(--ck-highlight-marker-pink)}.ck-content .marker-blue{background-color:var(--ck-highlight-marker-blue)}.ck-content .pen-red{background-color:transparent;color:var(--ck-highlight-pen-red)}.ck-content .pen-green{background-color:transparent;color:var(--ck-highlight-pen-green)}",""]);const o=n},609:e=>{"use strict";e.exports=function(e){var t=[];return t.toString=function(){return this.map((function(t){var i=e(t);return t[2]?"@media ".concat(t[2]," {").concat(i,"}"):i})).join("")},t.i=function(e,i,r){"string"==typeof e&&(e=[[null,e,""]]);var n={};if(r)for(var o=0;o<this.length;o++){var l=this[o][0];null!=l&&(n[l]=!0)}for(var a=0;a<e.length;a++){var c=[].concat(e[a]);r&&n[c[0]]||(i&&(c[2]?c[2]="".concat(i," and ").concat(c[2]):c[2]=i),t.push(c))}},t}},62:(e,t,i)=>{"use strict";var r,n=function(){return void 0===r&&(r=Boolean(window&&document&&document.all&&!window.atob)),r},o=function(){var e={};return function(t){if(void 0===e[t]){var i=document.querySelector(t);if(window.HTMLIFrameElement&&i instanceof window.HTMLIFrameElement)try{i=i.contentDocument.head}catch(e){i=null}e[t]=i}return e[t]}}(),l=[];function a(e){for(var t=-1,i=0;i<l.length;i++)if(l[i].identifier===e){t=i;break}return t}function c(e,t){for(var i={},r=[],n=0;n<e.length;n++){var o=e[n],c=t.base?o[0]+t.base:o[0],s=i[c]||0,h="".concat(c," ").concat(s);i[c]=s+1;var g=a(h),d={css:o[1],media:o[2],sourceMap:o[3]};-1!==g?(l[g].references++,l[g].updater(d)):l.push({identifier:h,updater:v(d,t),references:1}),r.push(h)}return r}function s(e){var t=document.createElement("style"),r=e.attributes||{};if(void 0===r.nonce){var n=i.nc;n&&(r.nonce=n)}if(Object.keys(r).forEach((function(e){t.setAttribute(e,r[e])})),"function"==typeof e.insert)e.insert(t);else{var l=o(e.insert||"head");if(!l)throw new Error("Couldn't find a style target. This probably means that the value for the 'insert' parameter is invalid.");l.appendChild(t)}return t}var h,g=(h=[],function(e,t){return h[e]=t,h.filter(Boolean).join("\n")});function d(e,t,i,r){var n=i?"":r.media?"@media ".concat(r.media," {").concat(r.css,"}"):r.css;if(e.styleSheet)e.styleSheet.cssText=g(t,n);else{var o=document.createTextNode(n),l=e.childNodes;l[t]&&e.removeChild(l[t]),l.length?e.insertBefore(o,l[t]):e.appendChild(o)}}function u(e,t,i){var r=i.css,n=i.media,o=i.sourceMap;if(n?e.setAttribute("media",n):e.removeAttribute("media"),o&&"undefined"!=typeof btoa&&(r+="\n/*# sourceMappingURL=data:application/json;base64,".concat(btoa(unescape(encodeURIComponent(JSON.stringify(o))))," */")),e.styleSheet)e.styleSheet.cssText=r;else{for(;e.firstChild;)e.removeChild(e.firstChild);e.appendChild(document.createTextNode(r))}}var m=null,p=0;function v(e,t){var i,r,n;if(t.singleton){var o=p++;i=m||(m=s(t)),r=d.bind(null,i,o,!1),n=d.bind(null,i,o,!0)}else i=s(t),r=u.bind(null,i,t),n=function(){!function(e){if(null===e.parentNode)return!1;e.parentNode.removeChild(e)}(i)};return r(e),function(t){if(t){if(t.css===e.css&&t.media===e.media&&t.sourceMap===e.sourceMap)return;r(e=t)}else n()}}e.exports=function(e,t){(t=t||{}).singleton||"boolean"==typeof t.singleton||(t.singleton=n());var i=c(e=e||[],t);return function(e){if(e=e||[],"[object Array]"===Object.prototype.toString.call(e)){for(var r=0;r<i.length;r++){var n=a(i[r]);l[n].references--}for(var o=c(e,t),s=0;s<i.length;s++){var h=a(i[s]);0===l[h].references&&(l[h].updater(),l.splice(h,1))}i=o}}}},704:(e,t,i)=>{e.exports=i(79)("./src/core.js")},273:(e,t,i)=>{e.exports=i(79)("./src/ui.js")},79:e=>{"use strict";e.exports=CKEditor5.dll}},t={};function i(r){var n=t[r];if(void 0!==n)return n.exports;var o=t[r]={id:r,exports:{}};return e[r](o,o.exports,i),o.exports}i.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return i.d(t,{a:t}),t},i.d=(e,t)=>{for(var r in t)i.o(t,r)&&!i.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},i.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),i.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},i.nc=void 0;var r={};(()=>{"use strict";i.r(r),i.d(r,{Highlight:()=>d,HighlightEditing:()=>n,HighlightUI:()=>h});var e=i(704);class t extends e.Command{refresh(){const e=this.editor.model,t=e.document;this.value=t.selection.getAttribute("highlight"),this.isEnabled=e.schema.checkAttributeInSelection(t.selection,"highlight")}execute(e={}){const t=this.editor.model,i=t.document.selection,r=e.value;t.change((e=>{if(i.isCollapsed){const t=i.getFirstPosition();if(i.hasAttribute("highlight")){const i=e=>e.item.hasAttribute("highlight")&&e.item.getAttribute("highlight")===this.value,n=t.getLastMatchingPosition(i,{direction:"backward"}),o=t.getLastMatchingPosition(i),l=e.createRange(n,o);r&&this.value!==r?(t.isEqual(o)||e.setAttribute("highlight",r,l),e.setSelectionAttribute("highlight",r)):(t.isEqual(o)||e.removeAttribute("highlight",l),e.removeSelectionAttribute("highlight"))}else r&&e.setSelectionAttribute("highlight",r)}else{const n=t.schema.getValidRanges(i.getRanges(),"highlight");for(const t of n)r?e.setAttribute("highlight",r,t):e.removeAttribute("highlight",t)}}))}}class n extends e.Plugin{static get pluginName(){return"HighlightEditing"}constructor(e){super(e),e.config.define("highlight",{options:[{model:"yellowMarker",class:"marker-yellow",title:"Yellow marker",color:"var(--ck-highlight-marker-yellow)",type:"marker"},{model:"greenMarker",class:"marker-green",title:"Green marker",color:"var(--ck-highlight-marker-green)",type:"marker"},{model:"pinkMarker",class:"marker-pink",title:"Pink marker",color:"var(--ck-highlight-marker-pink)",type:"marker"},{model:"blueMarker",class:"marker-blue",title:"Blue marker",color:"var(--ck-highlight-marker-blue)",type:"marker"},{model:"redPen",class:"pen-red",title:"Red pen",color:"var(--ck-highlight-pen-red)",type:"pen"},{model:"greenPen",class:"pen-green",title:"Green pen",color:"var(--ck-highlight-pen-green)",type:"pen"}]})}init(){const e=this.editor;e.model.schema.extend("$text",{allowAttributes:"highlight"});const i=e.config.get("highlight.options");e.conversion.attributeToElement(function(e){const t={model:{key:"highlight",values:[]},view:{}};for(const i of e)t.model.values.push(i.model),t.view[i.model]={name:"mark",classes:i.class};return t}(i)),e.commands.add("highlight",new t(e))}}var o=i(273);var l=i(62),a=i.n(l),c=i(458),s={injectType:"singletonStyleTag",attributes:{"data-cke":!0},insert:"head",singleton:!0};a()(c.Z,s);c.Z.locals;class h extends e.Plugin{get localizedOptionTitles(){const e=this.editor.t;return{"Yellow marker":e("Yellow marker"),"Green marker":e("Green marker"),"Pink marker":e("Pink marker"),"Blue marker":e("Blue marker"),"Red pen":e("Red pen"),"Green pen":e("Green pen")}}static get pluginName(){return"HighlightUI"}init(){const e=this.editor.config.get("highlight.options");for(const t of e)this._addHighlighterButton(t);this._addRemoveHighlightButton(),this._addDropdown(e)}_addRemoveHighlightButton(){const t=this.editor.t,i=this.editor.commands.get("highlight");this._addButton("removeHighlight",t("Remove highlight"),e.icons.eraser,null,(e=>{e.bind("isEnabled").to(i,"isEnabled")}))}_addHighlighterButton(e){const t=this.editor.commands.get("highlight");this._addButton("highlight:"+e.model,e.title,g(e.type),e.model,(function(i){i.bind("isEnabled").to(t,"isEnabled"),i.bind("isOn").to(t,"value",(t=>t===e.model)),i.iconView.fillColor=e.color,i.isToggleable=!0}))}_addButton(e,t,i,r,n){const l=this.editor;l.ui.componentFactory.add(e,(e=>{const a=new o.ButtonView(e),c=this.localizedOptionTitles[t]?this.localizedOptionTitles[t]:t;return a.set({label:c,icon:i,tooltip:!0}),a.on("execute",(()=>{l.execute("highlight",{value:r}),l.editing.view.focus()})),n(a),a}))}_addDropdown(e){const t=this.editor,i=t.t,r=t.ui.componentFactory,n=e[0],l=e.reduce(((e,t)=>(e[t.model]=t,e)),{});r.add("highlight",(a=>{const c=t.commands.get("highlight"),s=(0,o.createDropdown)(a,o.SplitButtonView),h=s.buttonView;h.set({label:i("Highlight"),tooltip:!0,lastExecuted:n.model,commandValue:n.model,isToggleable:!0}),h.bind("icon").to(c,"value",(e=>g(d(e,"type")))),h.bind("color").to(c,"value",(e=>d(e,"color"))),h.bind("commandValue").to(c,"value",(e=>d(e,"model"))),h.bind("isOn").to(c,"value",(e=>!!e)),h.delegate("execute").to(s);function d(e,t){const i=e&&e!==h.lastExecuted?e:h.lastExecuted;return l[i][t]}return s.bind("isEnabled").to(c,"isEnabled"),(0,o.addToolbarToDropdown)(s,(()=>{const t=e.map((e=>{const t=r.create("highlight:"+e.model);return this.listenTo(t,"execute",(()=>{s.buttonView.set({lastExecuted:e.model})})),t}));return t.push(new o.ToolbarSeparatorView),t.push(r.create("removeHighlight")),t}),{enableActiveItemFocusOnDropdownOpen:!0,ariaLabel:i("Text highlight toolbar")}),function(e){const t=e.buttonView.actionView;t.iconView.bind("fillColor").to(e.buttonView,"color")}(s),h.on("execute",(()=>{t.execute("highlight",{value:h.commandValue})})),this.listenTo(s,"execute",(()=>{t.editing.view.focus()})),s}))}}function g(e){return"marker"===e?'<svg viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg"><path class="ck-icon__fill" d="M10.798 1.59 3.002 12.875l1.895 1.852 2.521 1.402 6.997-12.194z"/><path d="m2.556 16.727.234-.348c-.297-.151-.462-.293-.498-.426-.036-.137.002-.416.115-.837.094-.25.15-.449.169-.595a4.495 4.495 0 0 0 0-.725c-.209-.621-.303-1.041-.284-1.26.02-.218.178-.506.475-.862l6.77-9.414c.539-.91 1.605-.85 3.199.18 1.594 1.032 2.188 1.928 1.784 2.686l-5.877 10.36c-.158.412-.333.673-.526.782-.193.108-.604.179-1.232.21-.362.131-.608.237-.738.318-.13.081-.305.238-.526.47-.293.265-.504.397-.632.397-.096 0-.27-.075-.524-.226l-.31.41-1.6-1.12zm-.279.415 1.575 1.103-.392.515H1.19l1.087-1.618zm8.1-13.656-4.953 6.9L8.75 12.57l4.247-7.574c.175-.25-.188-.647-1.092-1.192-.903-.546-1.412-.652-1.528-.32zM8.244 18.5 9.59 17h9.406v1.5H8.245z"/></svg>':'<svg viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg"><path class="ck-icon__fill" d="M10.126 2.268 2.002 13.874l1.895 1.852 2.521 1.402L14.47 5.481l-1.543-2.568-2.801-.645z"/><path d="m4.5 18.088-2.645-1.852-.04-2.95-.006-.005.006-.008v-.025l.011.008L8.73 2.97c.165-.233.356-.417.567-.557l-1.212.308L4.604 7.9l-.83-.558 3.694-5.495 2.708-.69 1.65 1.145.046.018.85-1.216 2.16 1.512-.856 1.222c.828.967 1.144 2.141.432 3.158L7.55 17.286l.006.005-3.055.797H4.5zm-.634.166-1.976.516-.026-1.918 2.002 1.402zM9.968 3.817l-.006-.004-6.123 9.184 3.277 2.294 6.108-9.162.005.003c.317-.452-.16-1.332-1.064-1.966-.891-.624-1.865-.776-2.197-.349zM8.245 18.5 9.59 17h9.406v1.5H8.245z"/></svg>'}class d extends e.Plugin{static get requires(){return[n,h]}static get pluginName(){return"Highlight"}}})(),(window.CKEditor5=window.CKEditor5||{}).highlight=r})();
5
+ */(()=>{var e={458:(e,t,i)=>{"use strict";i.d(t,{Z:()=>o});var r=i(609),n=i.n(r)()((function(e){return e[1]}));n.push([e.id,":root{--ck-highlight-marker-yellow:#fdfd77;--ck-highlight-marker-green:#62f962;--ck-highlight-marker-pink:#fc7899;--ck-highlight-marker-blue:#72ccfd;--ck-highlight-pen-red:#e71313;--ck-highlight-pen-green:#128a00}.ck-content .marker-yellow{background-color:var(--ck-highlight-marker-yellow)}.ck-content .marker-green{background-color:var(--ck-highlight-marker-green)}.ck-content .marker-pink{background-color:var(--ck-highlight-marker-pink)}.ck-content .marker-blue{background-color:var(--ck-highlight-marker-blue)}.ck-content .pen-red{background-color:transparent;color:var(--ck-highlight-pen-red)}.ck-content .pen-green{background-color:transparent;color:var(--ck-highlight-pen-green)}",""]);const o=n},609:e=>{"use strict";e.exports=function(e){var t=[];return t.toString=function(){return this.map((function(t){var i=e(t);return t[2]?"@media ".concat(t[2]," {").concat(i,"}"):i})).join("")},t.i=function(e,i,r){"string"==typeof e&&(e=[[null,e,""]]);var n={};if(r)for(var o=0;o<this.length;o++){var l=this[o][0];null!=l&&(n[l]=!0)}for(var a=0;a<e.length;a++){var c=[].concat(e[a]);r&&n[c[0]]||(i&&(c[2]?c[2]="".concat(i," and ").concat(c[2]):c[2]=i),t.push(c))}},t}},62:(e,t,i)=>{"use strict";var r,n=function(){return void 0===r&&(r=Boolean(window&&document&&document.all&&!window.atob)),r},o=function(){var e={};return function(t){if(void 0===e[t]){var i=document.querySelector(t);if(window.HTMLIFrameElement&&i instanceof window.HTMLIFrameElement)try{i=i.contentDocument.head}catch(e){i=null}e[t]=i}return e[t]}}(),l=[];function a(e){for(var t=-1,i=0;i<l.length;i++)if(l[i].identifier===e){t=i;break}return t}function c(e,t){for(var i={},r=[],n=0;n<e.length;n++){var o=e[n],c=t.base?o[0]+t.base:o[0],s=i[c]||0,h="".concat(c," ").concat(s);i[c]=s+1;var g=a(h),d={css:o[1],media:o[2],sourceMap:o[3]};-1!==g?(l[g].references++,l[g].updater(d)):l.push({identifier:h,updater:v(d,t),references:1}),r.push(h)}return r}function s(e){var t=document.createElement("style"),r=e.attributes||{};if(void 0===r.nonce){var n=i.nc;n&&(r.nonce=n)}if(Object.keys(r).forEach((function(e){t.setAttribute(e,r[e])})),"function"==typeof e.insert)e.insert(t);else{var l=o(e.insert||"head");if(!l)throw new Error("Couldn't find a style target. This probably means that the value for the 'insert' parameter is invalid.");l.appendChild(t)}return t}var h,g=(h=[],function(e,t){return h[e]=t,h.filter(Boolean).join("\n")});function d(e,t,i,r){var n=i?"":r.media?"@media ".concat(r.media," {").concat(r.css,"}"):r.css;if(e.styleSheet)e.styleSheet.cssText=g(t,n);else{var o=document.createTextNode(n),l=e.childNodes;l[t]&&e.removeChild(l[t]),l.length?e.insertBefore(o,l[t]):e.appendChild(o)}}function u(e,t,i){var r=i.css,n=i.media,o=i.sourceMap;if(n?e.setAttribute("media",n):e.removeAttribute("media"),o&&"undefined"!=typeof btoa&&(r+="\n/*# sourceMappingURL=data:application/json;base64,".concat(btoa(unescape(encodeURIComponent(JSON.stringify(o))))," */")),e.styleSheet)e.styleSheet.cssText=r;else{for(;e.firstChild;)e.removeChild(e.firstChild);e.appendChild(document.createTextNode(r))}}var m=null,p=0;function v(e,t){var i,r,n;if(t.singleton){var o=p++;i=m||(m=s(t)),r=d.bind(null,i,o,!1),n=d.bind(null,i,o,!0)}else i=s(t),r=u.bind(null,i,t),n=function(){!function(e){if(null===e.parentNode)return!1;e.parentNode.removeChild(e)}(i)};return r(e),function(t){if(t){if(t.css===e.css&&t.media===e.media&&t.sourceMap===e.sourceMap)return;r(e=t)}else n()}}e.exports=function(e,t){(t=t||{}).singleton||"boolean"==typeof t.singleton||(t.singleton=n());var i=c(e=e||[],t);return function(e){if(e=e||[],"[object Array]"===Object.prototype.toString.call(e)){for(var r=0;r<i.length;r++){var n=a(i[r]);l[n].references--}for(var o=c(e,t),s=0;s<i.length;s++){var h=a(i[s]);0===l[h].references&&(l[h].updater(),l.splice(h,1))}i=o}}}},704:(e,t,i)=>{e.exports=i(79)("./src/core.js")},273:(e,t,i)=>{e.exports=i(79)("./src/ui.js")},79:e=>{"use strict";e.exports=CKEditor5.dll}},t={};function i(r){var n=t[r];if(void 0!==n)return n.exports;var o=t[r]={id:r,exports:{}};return e[r](o,o.exports,i),o.exports}i.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return i.d(t,{a:t}),t},i.d=(e,t)=>{for(var r in t)i.o(t,r)&&!i.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},i.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),i.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},i.nc=void 0;var r={};(()=>{"use strict";i.r(r),i.d(r,{Highlight:()=>m,HighlightEditing:()=>n,HighlightUI:()=>d});var e=i(704);class t extends e.Command{refresh(){const e=this.editor.model,t=e.document;this.value=t.selection.getAttribute("highlight"),this.isEnabled=e.schema.checkAttributeInSelection(t.selection,"highlight")}execute(e={}){const t=this.editor.model,i=t.document.selection,r=e.value;t.change((e=>{if(i.isCollapsed){const t=i.getFirstPosition();if(i.hasAttribute("highlight")){const i=e=>e.item.hasAttribute("highlight")&&e.item.getAttribute("highlight")===this.value,n=t.getLastMatchingPosition(i,{direction:"backward"}),o=t.getLastMatchingPosition(i),l=e.createRange(n,o);r&&this.value!==r?(t.isEqual(o)||e.setAttribute("highlight",r,l),e.setSelectionAttribute("highlight",r)):(t.isEqual(o)||e.removeAttribute("highlight",l),e.removeSelectionAttribute("highlight"))}else r&&e.setSelectionAttribute("highlight",r)}else{const n=t.schema.getValidRanges(i.getRanges(),"highlight");for(const t of n)r?e.setAttribute("highlight",r,t):e.removeAttribute("highlight",t)}}))}}class n extends e.Plugin{static get pluginName(){return"HighlightEditing"}constructor(e){super(e),e.config.define("highlight",{options:[{model:"yellowMarker",class:"marker-yellow",title:"Yellow marker",color:"var(--ck-highlight-marker-yellow)",type:"marker"},{model:"greenMarker",class:"marker-green",title:"Green marker",color:"var(--ck-highlight-marker-green)",type:"marker"},{model:"pinkMarker",class:"marker-pink",title:"Pink marker",color:"var(--ck-highlight-marker-pink)",type:"marker"},{model:"blueMarker",class:"marker-blue",title:"Blue marker",color:"var(--ck-highlight-marker-blue)",type:"marker"},{model:"redPen",class:"pen-red",title:"Red pen",color:"var(--ck-highlight-pen-red)",type:"pen"},{model:"greenPen",class:"pen-green",title:"Green pen",color:"var(--ck-highlight-pen-green)",type:"pen"}]})}init(){const e=this.editor;e.model.schema.extend("$text",{allowAttributes:"highlight"});const i=e.config.get("highlight.options");e.conversion.attributeToElement(function(e){const t={model:{key:"highlight",values:[]},view:{}};for(const i of e)t.model.values.push(i.model),t.view[i.model]={name:"mark",classes:i.class};return t}(i)),e.commands.add("highlight",new t(e))}}var o=i(273);const l='<svg viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg"><path class="ck-icon__fill" d="M10.798 1.59 3.002 12.875l1.895 1.852 2.521 1.402 6.997-12.194z"/><path d="m2.556 16.727.234-.348c-.297-.151-.462-.293-.498-.426-.036-.137.002-.416.115-.837.094-.25.15-.449.169-.595a4.495 4.495 0 0 0 0-.725c-.209-.621-.303-1.041-.284-1.26.02-.218.178-.506.475-.862l6.77-9.414c.539-.91 1.605-.85 3.199.18 1.594 1.032 2.188 1.928 1.784 2.686l-5.877 10.36c-.158.412-.333.673-.526.782-.193.108-.604.179-1.232.21-.362.131-.608.237-.738.318-.13.081-.305.238-.526.47-.293.265-.504.397-.632.397-.096 0-.27-.075-.524-.226l-.31.41-1.6-1.12zm-.279.415 1.575 1.103-.392.515H1.19l1.087-1.618zm8.1-13.656-4.953 6.9L8.75 12.57l4.247-7.574c.175-.25-.188-.647-1.092-1.192-.903-.546-1.412-.652-1.528-.32zM8.244 18.5 9.59 17h9.406v1.5H8.245z"/></svg>',a='<svg viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg"><path class="ck-icon__fill" d="M10.126 2.268 2.002 13.874l1.895 1.852 2.521 1.402L14.47 5.481l-1.543-2.568-2.801-.645z"/><path d="m4.5 18.088-2.645-1.852-.04-2.95-.006-.005.006-.008v-.025l.011.008L8.73 2.97c.165-.233.356-.417.567-.557l-1.212.308L4.604 7.9l-.83-.558 3.694-5.495 2.708-.69 1.65 1.145.046.018.85-1.216 2.16 1.512-.856 1.222c.828.967 1.144 2.141.432 3.158L7.55 17.286l.006.005-3.055.797H4.5zm-.634.166-1.976.516-.026-1.918 2.002 1.402zM9.968 3.817l-.006-.004-6.123 9.184 3.277 2.294 6.108-9.162.005.003c.317-.452-.16-1.332-1.064-1.966-.891-.624-1.865-.776-2.197-.349zM8.245 18.5 9.59 17h9.406v1.5H8.245z"/></svg>';var c=i(62),s=i.n(c),h=i(458),g={injectType:"singletonStyleTag",attributes:{"data-cke":!0},insert:"head",singleton:!0};s()(h.Z,g);h.Z.locals;class d extends e.Plugin{get localizedOptionTitles(){const e=this.editor.t;return{"Yellow marker":e("Yellow marker"),"Green marker":e("Green marker"),"Pink marker":e("Pink marker"),"Blue marker":e("Blue marker"),"Red pen":e("Red pen"),"Green pen":e("Green pen")}}static get pluginName(){return"HighlightUI"}init(){const e=this.editor.config.get("highlight.options");for(const t of e)this._addHighlighterButton(t);this._addRemoveHighlightButton(),this._addDropdown(e)}_addRemoveHighlightButton(){const t=this.editor.t,i=this.editor.commands.get("highlight");this._addButton("removeHighlight",t("Remove highlight"),e.icons.eraser,null,(e=>{e.bind("isEnabled").to(i,"isEnabled")}))}_addHighlighterButton(e){const t=this.editor.commands.get("highlight");this._addButton("highlight:"+e.model,e.title,u(e.type),e.model,(function(i){i.bind("isEnabled").to(t,"isEnabled"),i.bind("isOn").to(t,"value",(t=>t===e.model)),i.iconView.fillColor=e.color,i.isToggleable=!0}))}_addButton(e,t,i,r,n){const l=this.editor;l.ui.componentFactory.add(e,(e=>{const a=new o.ButtonView(e),c=this.localizedOptionTitles[t]?this.localizedOptionTitles[t]:t;return a.set({label:c,icon:i,tooltip:!0}),a.on("execute",(()=>{l.execute("highlight",{value:r}),l.editing.view.focus()})),n(a),a}))}_addDropdown(e){const t=this.editor,i=t.t,r=t.ui.componentFactory,n=e[0],l=e.reduce(((e,t)=>(e[t.model]=t,e)),{});r.add("highlight",(a=>{const c=t.commands.get("highlight"),s=(0,o.createDropdown)(a,o.SplitButtonView),h=s.buttonView;h.set({label:i("Highlight"),tooltip:!0,lastExecuted:n.model,commandValue:n.model,isToggleable:!0}),h.bind("icon").to(c,"value",(e=>u(g(e,"type")))),h.bind("color").to(c,"value",(e=>g(e,"color"))),h.bind("commandValue").to(c,"value",(e=>g(e,"model"))),h.bind("isOn").to(c,"value",(e=>!!e)),h.delegate("execute").to(s);function g(e,t){const i=e&&e!==h.lastExecuted?e:h.lastExecuted;return l[i][t]}return s.bind("isEnabled").to(c,"isEnabled"),(0,o.addToolbarToDropdown)(s,(()=>{const t=e.map((e=>{const t=r.create("highlight:"+e.model);return this.listenTo(t,"execute",(()=>{s.buttonView.set({lastExecuted:e.model})})),t}));return t.push(new o.ToolbarSeparatorView),t.push(r.create("removeHighlight")),t}),{enableActiveItemFocusOnDropdownOpen:!0,ariaLabel:i("Text highlight toolbar")}),function(e){const t=e.buttonView.actionView;t.iconView.bind("fillColor").to(e.buttonView,"color")}(s),h.on("execute",(()=>{t.execute("highlight",{value:h.commandValue})})),this.listenTo(s,"execute",(()=>{t.editing.view.focus()})),s}))}}function u(e){return"marker"===e?l:a}class m extends e.Plugin{static get requires(){return[n,d]}static get pluginName(){return"Highlight"}}})(),(window.CKEditor5=window.CKEditor5||{}).highlight=r})();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ckeditor/ckeditor5-highlight",
3
- "version": "36.0.0",
3
+ "version": "37.0.0-alpha.0",
4
4
  "description": "Highlight feature for CKEditor 5.",
5
5
  "keywords": [
6
6
  "ckeditor",
@@ -12,22 +12,22 @@
12
12
  ],
13
13
  "main": "src/index.js",
14
14
  "dependencies": {
15
- "ckeditor5": "^36.0.0"
15
+ "ckeditor5": "^37.0.0-alpha.0"
16
16
  },
17
17
  "devDependencies": {
18
- "@ckeditor/ckeditor5-block-quote": "^36.0.0",
19
- "@ckeditor/ckeditor5-core": "^36.0.0",
20
- "@ckeditor/ckeditor5-dev-utils": "^32.0.0",
21
- "@ckeditor/ckeditor5-editor-classic": "^36.0.0",
22
- "@ckeditor/ckeditor5-engine": "^36.0.0",
23
- "@ckeditor/ckeditor5-enter": "^36.0.0",
24
- "@ckeditor/ckeditor5-heading": "^36.0.0",
25
- "@ckeditor/ckeditor5-image": "^36.0.0",
26
- "@ckeditor/ckeditor5-list": "^36.0.0",
27
- "@ckeditor/ckeditor5-paragraph": "^36.0.0",
28
- "@ckeditor/ckeditor5-theme-lark": "^36.0.0",
29
- "@ckeditor/ckeditor5-typing": "^36.0.0",
30
- "@ckeditor/ckeditor5-utils": "^36.0.0",
18
+ "@ckeditor/ckeditor5-block-quote": "^37.0.0-alpha.0",
19
+ "@ckeditor/ckeditor5-core": "^37.0.0-alpha.0",
20
+ "@ckeditor/ckeditor5-dev-utils": "^34.0.0",
21
+ "@ckeditor/ckeditor5-editor-classic": "^37.0.0-alpha.0",
22
+ "@ckeditor/ckeditor5-engine": "^37.0.0-alpha.0",
23
+ "@ckeditor/ckeditor5-enter": "^37.0.0-alpha.0",
24
+ "@ckeditor/ckeditor5-heading": "^37.0.0-alpha.0",
25
+ "@ckeditor/ckeditor5-image": "^37.0.0-alpha.0",
26
+ "@ckeditor/ckeditor5-list": "^37.0.0-alpha.0",
27
+ "@ckeditor/ckeditor5-paragraph": "^37.0.0-alpha.0",
28
+ "@ckeditor/ckeditor5-theme-lark": "^37.0.0-alpha.0",
29
+ "@ckeditor/ckeditor5-typing": "^37.0.0-alpha.0",
30
+ "@ckeditor/ckeditor5-utils": "^37.0.0-alpha.0",
31
31
  "typescript": "^4.8.4",
32
32
  "webpack": "^5.58.1",
33
33
  "webpack-cli": "^4.9.0"
@@ -47,7 +47,6 @@
47
47
  },
48
48
  "files": [
49
49
  "lang",
50
- "src",
51
50
  "src/**/*.js",
52
51
  "src/**/*.d.ts",
53
52
  "theme",
@@ -59,5 +58,6 @@
59
58
  "dll:build": "webpack",
60
59
  "build": "tsc -p ./tsconfig.release.json",
61
60
  "postversion": "npm run build"
62
- }
61
+ },
62
+ "types": "src/index.d.ts"
63
63
  }
@@ -0,0 +1,31 @@
1
+ /**
2
+ * @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
3
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
+ */
5
+ /**
6
+ * @module highlight/highlight
7
+ */
8
+ import { Plugin, type PluginDependencies } from 'ckeditor5/src/core';
9
+ /**
10
+ * The highlight plugin.
11
+ *
12
+ * For a detailed overview, check the {@glink features/highlight Highlight feature} documentation.
13
+ *
14
+ * This is a "glue" plugin which loads the {@link module:highlight/highlightediting~HighlightEditing} and
15
+ * {@link module:highlight/highlightui~HighlightUI} plugins.
16
+ */
17
+ export default class Highlight extends Plugin {
18
+ /**
19
+ * @inheritDoc
20
+ */
21
+ static get requires(): PluginDependencies;
22
+ /**
23
+ * @inheritDoc
24
+ */
25
+ static get pluginName(): 'Highlight';
26
+ }
27
+ declare module '@ckeditor/ckeditor5-core' {
28
+ interface PluginsMap {
29
+ [Highlight.pluginName]: Highlight;
30
+ }
31
+ }
@@ -0,0 +1,50 @@
1
+ /**
2
+ * @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
3
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
+ */
5
+ /**
6
+ * @module highlight/highlightcommand
7
+ */
8
+ import { Command } from 'ckeditor5/src/core';
9
+ /**
10
+ * The highlight command. It is used by the {@link module:highlight/highlightediting~HighlightEditing highlight feature}
11
+ * to apply the text highlighting.
12
+ *
13
+ * ```ts
14
+ * editor.execute( 'highlight', { value: 'greenMarker' } );
15
+ * ```
16
+ *
17
+ * **Note**: Executing the command without a value removes the attribute from the model. If the selection is collapsed
18
+ * inside a text with the highlight attribute, the command will remove the attribute from the entire range
19
+ * of that text.
20
+ */
21
+ export default class HighlightCommand extends Command {
22
+ /**
23
+ * A value indicating whether the command is active. If the selection has some highlight attribute,
24
+ * it corresponds to the value of that attribute.
25
+ *
26
+ * @observable
27
+ * @readonly
28
+ */
29
+ value: string | undefined;
30
+ /**
31
+ * @inheritDoc
32
+ */
33
+ refresh(): void;
34
+ /**
35
+ * Executes the command.
36
+ *
37
+ * @param options Options for the executed command.
38
+ * @param options.value The value to apply.
39
+ *
40
+ * @fires execute
41
+ */
42
+ execute(options?: {
43
+ value?: string | null;
44
+ }): void;
45
+ }
46
+ declare module '@ckeditor/ckeditor5-core' {
47
+ interface CommandsMap {
48
+ highlight: HighlightCommand;
49
+ }
50
+ }
@@ -0,0 +1,181 @@
1
+ /**
2
+ * @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
3
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
+ */
5
+ /**
6
+ * @module highlight/highlightconfig
7
+ */
8
+ /**
9
+ * The highlight option descriptor. See {@link module:highlight/highlightconfig~HighlightConfig} to learn more.
10
+ *
11
+ * ```ts
12
+ * {
13
+ * model: 'pinkMarker',
14
+ * class: 'marker-pink',
15
+ * title: 'Pink Marker',
16
+ * color: 'var(--ck-highlight-marker-pink)',
17
+ * type: 'marker'
18
+ * }
19
+ * ```
20
+ */
21
+ export interface HighlightOption {
22
+ /**
23
+ * The user-readable title of the option.
24
+ */
25
+ title: string;
26
+ /**
27
+ * The unique attribute value in the model.
28
+ */
29
+ model: string;
30
+ /**
31
+ * The CSS `var()` used for the highlighter. The color is used in the user interface to represent the highlighter.
32
+ * There is a possibility to use the default color format like rgb, hex or hsl, but you need to care about the color of `<mark>`
33
+ * by adding CSS classes definition.
34
+ */
35
+ color: string;
36
+ /**
37
+ * The CSS class used on the `<mark>` element in the view. It should match the `color` setting.
38
+ */
39
+ class: string;
40
+ /**
41
+ * The type of highlighter:
42
+ *
43
+ * * `'marker'` &ndash; Uses the `color` as the `background-color` style,
44
+ * * `'pen'` &ndash; Uses the `color` as the font `color` style.
45
+ */
46
+ type: 'marker' | 'pen';
47
+ }
48
+ /**
49
+ * The configuration of the {@link module:highlight/highlight~Highlight highlight feature}.
50
+ * ```ts
51
+ * ClassicEditor
52
+ * .create( editorElement, {
53
+ * highlight: ... // Highlight feature configuration.
54
+ * } )
55
+ * .then( ... )
56
+ * .catch( ... );
57
+ * ```
58
+ * See {@link module:core/editor/editorconfig~EditorConfig all editor options}.
59
+ */
60
+ export interface HighlightConfig {
61
+ /**
62
+ * The available highlight options. The default value is:
63
+ * ```ts
64
+ * options: [
65
+ * {
66
+ * model: 'yellowMarker',
67
+ * class: 'marker-yellow',
68
+ * title: 'Yellow marker',
69
+ * color: 'var(--ck-highlight-marker-yellow)',
70
+ * type: 'marker'
71
+ * },
72
+ * {
73
+ * model: 'greenMarker',
74
+ * class: 'marker-green',
75
+ * title: 'Green marker',
76
+ * color: 'var(--ck-highlight-marker-green)',
77
+ * type: 'marker'
78
+ * },
79
+ * {
80
+ * model: 'pinkMarker',
81
+ * class: 'marker-pink',
82
+ * title: 'Pink marker',
83
+ * color: 'var(--ck-highlight-marker-pink)',
84
+ * type: 'marker'
85
+ * },
86
+ * {
87
+ * model: 'blueMarker',
88
+ * class: 'marker-blue',
89
+ * title: 'Blue marker',
90
+ * color: 'var(--ck-highlight-marker-blue)',
91
+ * type: 'marker'
92
+ * },
93
+ * {
94
+ * model: 'redPen',
95
+ * class: 'pen-red',
96
+ * title: 'Red pen',
97
+ * color: 'var(--ck-highlight-pen-red)',
98
+ * type: 'pen'
99
+ * },
100
+ * {
101
+ * model: 'greenPen',
102
+ * class: 'pen-green',
103
+ * title: 'Green pen',
104
+ * color: 'var(--ck-highlight-pen-green)',
105
+ * type: 'pen'
106
+ * }
107
+ * ]
108
+ * ```
109
+ *
110
+ * There are two types of highlighters available:
111
+ *
112
+ * * `'marker'` &ndash; Rendered as a `<mark>` element, styled with the `background-color`.
113
+ * * `'pen'` &ndash; Rendered as a `<mark>` element, styled with the font `color`.
114
+ *
115
+ * **Note**: The highlight feature provides a stylesheet with the CSS classes and corresponding colors defined
116
+ * as CSS variables.
117
+ *
118
+ * ```css
119
+ * :root {
120
+ * --ck-highlight-marker-yellow: #fdfd77;
121
+ * --ck-highlight-marker-green: #63f963;
122
+ * --ck-highlight-marker-pink: #fc7999;
123
+ * --ck-highlight-marker-blue: #72cdfd;
124
+ * --ck-highlight-pen-red: #e91313;
125
+ * --ck-highlight-pen-green: #118800;
126
+ * }
127
+ *
128
+ * .marker-yellow { ... }
129
+ * .marker-green { ... }
130
+ * .marker-pink { ... }
131
+ * .marker-blue { ... }
132
+ * .pen-red { ... }
133
+ * .pen-green { ... }
134
+ * ```
135
+ *
136
+ * It is possible to define the `color` property directly as `rgba(R, G, B, A)`,
137
+ * `#RRGGBB[AA]` or `hsla(H, S, L, A)`. In such situation, the color will **only** apply to the UI of
138
+ * the editor and the `<mark>` elements in the content must be styled by custom classes provided by
139
+ * a dedicated stylesheet.
140
+ *
141
+ * **Note**: It is recommended for the `color` property to correspond to the class in the content
142
+ * stylesheet because it represents the highlighter in the user interface of the editor.
143
+ *
144
+ * ```ts
145
+ * ClassicEditor
146
+ * .create( editorElement, {
147
+ * highlight: {
148
+ * options: [
149
+ * {
150
+ * model: 'pinkMarker',
151
+ * class: 'marker-pink',
152
+ * title: 'Pink Marker',
153
+ * color: 'var(--ck-highlight-marker-pink)',
154
+ * type: 'marker'
155
+ * },
156
+ * {
157
+ * model: 'redPen',
158
+ * class: 'pen-red',
159
+ * title: 'Red Pen',
160
+ * color: 'var(--ck-highlight-pen-red)',
161
+ * type: 'pen'
162
+ * },
163
+ * ]
164
+ * }
165
+ * } )
166
+ * .then( ... )
167
+ * .catch( ... );
168
+ * ```
169
+ */
170
+ options: Array<HighlightOption>;
171
+ }
172
+ declare module '@ckeditor/ckeditor5-core' {
173
+ interface EditorConfig {
174
+ /**
175
+ * The configuration of the {@link module:highlight/highlight~Highlight} feature.
176
+ *
177
+ * Read more in {@link module:highlight/highlightconfig~HighlightConfig}.
178
+ */
179
+ highlight?: HighlightConfig;
180
+ }
181
+ }
@@ -0,0 +1,5 @@
1
+ /**
2
+ * @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
3
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
+ */
5
+ export {};
@@ -0,0 +1,33 @@
1
+ /**
2
+ * @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
3
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
+ */
5
+ /**
6
+ * @module highlight/highlightediting
7
+ */
8
+ import { Plugin, type Editor } from 'ckeditor5/src/core';
9
+ /**
10
+ * The highlight editing feature. It introduces the {@link module:highlight/highlightcommand~HighlightCommand command} and the `highlight`
11
+ * attribute in the {@link module:engine/model/model~Model model} which renders in the {@link module:engine/view/view view}
12
+ * as a `<mark>` element with a `class` attribute (`<mark class="marker-green">...</mark>`) depending
13
+ * on the {@link module:highlight/highlightconfig~HighlightConfig configuration}.
14
+ */
15
+ export default class HighlightEditing extends Plugin {
16
+ /**
17
+ * @inheritDoc
18
+ */
19
+ static get pluginName(): 'HighlightEditing';
20
+ /**
21
+ * @inheritDoc
22
+ */
23
+ constructor(editor: Editor);
24
+ /**
25
+ * @inheritDoc
26
+ */
27
+ init(): void;
28
+ }
29
+ declare module '@ckeditor/ckeditor5-core' {
30
+ interface PluginsMap {
31
+ [HighlightEditing.pluginName]: HighlightEditing;
32
+ }
33
+ }
@@ -11,7 +11,7 @@ import HighlightCommand from './highlightcommand';
11
11
  * The highlight editing feature. It introduces the {@link module:highlight/highlightcommand~HighlightCommand command} and the `highlight`
12
12
  * attribute in the {@link module:engine/model/model~Model model} which renders in the {@link module:engine/view/view view}
13
13
  * as a `<mark>` element with a `class` attribute (`<mark class="marker-green">...</mark>`) depending
14
- * on the {@link module:highlight/highlight~HighlightConfig configuration}.
14
+ * on the {@link module:highlight/highlightconfig~HighlightConfig configuration}.
15
15
  */
16
16
  export default class HighlightEditing extends Plugin {
17
17
  /**
@@ -0,0 +1,78 @@
1
+ /**
2
+ * @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
3
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
+ */
5
+ /**
6
+ * @module highlight/highlightui
7
+ */
8
+ import { Plugin } from 'ckeditor5/src/core';
9
+ import './../theme/highlight.css';
10
+ /**
11
+ * The default highlight UI plugin. It introduces:
12
+ *
13
+ * * The `'highlight'` dropdown,
14
+ * * The `'removeHighlight'` and `'highlight:*'` buttons.
15
+ *
16
+ * The default configuration includes the following buttons:
17
+ *
18
+ * * `'highlight:yellowMarker'`
19
+ * * `'highlight:greenMarker'`
20
+ * * `'highlight:pinkMarker'`
21
+ * * `'highlight:blueMarker'`
22
+ * * `'highlight:redPen'`
23
+ * * `'highlight:greenPen'`
24
+ *
25
+ * See the {@link module:highlight/highlightconfig~HighlightConfig#options configuration} to learn more
26
+ * about the defaults.
27
+ */
28
+ export default class HighlightUI extends Plugin {
29
+ /**
30
+ * Returns the localized option titles provided by the plugin.
31
+ *
32
+ * The following localized titles corresponding with default
33
+ * {@link module:highlight/highlightconfig~HighlightConfig#options} are available:
34
+ *
35
+ * * `'Yellow marker'`,
36
+ * * `'Green marker'`,
37
+ * * `'Pink marker'`,
38
+ * * `'Blue marker'`,
39
+ * * `'Red pen'`,
40
+ * * `'Green pen'`.
41
+ */
42
+ get localizedOptionTitles(): Record<string, string>;
43
+ /**
44
+ * @inheritDoc
45
+ */
46
+ static get pluginName(): 'HighlightUI';
47
+ /**
48
+ * @inheritDoc
49
+ */
50
+ init(): void;
51
+ /**
52
+ * Creates the "Remove highlight" button.
53
+ */
54
+ private _addRemoveHighlightButton;
55
+ /**
56
+ * Creates a toolbar button from the provided highlight option.
57
+ */
58
+ private _addHighlighterButton;
59
+ /**
60
+ * Internal method for creating highlight buttons.
61
+ *
62
+ * @param name The name of the button.
63
+ * @param label The label for the button.
64
+ * @param icon The button icon.
65
+ * @param value The `value` property passed to the executed command.
66
+ * @param decorateButton A callback getting ButtonView instance so that it can be further customized.
67
+ */
68
+ private _addButton;
69
+ /**
70
+ * Creates the split button dropdown UI from the provided highlight options.
71
+ */
72
+ private _addDropdown;
73
+ }
74
+ declare module '@ckeditor/ckeditor5-core' {
75
+ interface PluginsMap {
76
+ [HighlightUI.pluginName]: HighlightUI;
77
+ }
78
+ }
@@ -25,7 +25,7 @@ import './../theme/highlight.css';
25
25
  * * `'highlight:redPen'`
26
26
  * * `'highlight:greenPen'`
27
27
  *
28
- * See the {@link module:highlight/highlight~HighlightConfig#options configuration} to learn more
28
+ * See the {@link module:highlight/highlightconfig~HighlightConfig#options configuration} to learn more
29
29
  * about the defaults.
30
30
  */
31
31
  export default class HighlightUI extends Plugin {
@@ -33,7 +33,7 @@ export default class HighlightUI extends Plugin {
33
33
  * Returns the localized option titles provided by the plugin.
34
34
  *
35
35
  * The following localized titles corresponding with default
36
- * {@link module:highlight/highlight~HighlightConfig#options} are available:
36
+ * {@link module:highlight/highlightconfig~HighlightConfig#options} are available:
37
37
  *
38
38
  * * `'Yellow marker'`,
39
39
  * * `'Green marker'`,
@@ -2,11 +2,9 @@
2
2
  * @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
3
3
  * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
4
  */
5
-
6
5
  /**
7
6
  * @module highlight
8
7
  */
9
-
10
8
  export { default as Highlight } from './highlight';
11
9
  export { default as HighlightEditing } from './highlightediting';
12
10
  export { default as HighlightUI } from './highlightui';
package/src/highlight.ts DELETED
@@ -1,225 +0,0 @@
1
- /**
2
- * @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
3
- * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
- */
5
-
6
- /**
7
- * @module highlight/highlight
8
- */
9
-
10
- import { Plugin, type PluginDependencies } from 'ckeditor5/src/core';
11
-
12
- import HighlightEditing from './highlightediting';
13
- import HighlightUI from './highlightui';
14
-
15
- /**
16
- * The highlight plugin.
17
- *
18
- * For a detailed overview, check the {@glink features/highlight Highlight feature} documentation.
19
- *
20
- * This is a "glue" plugin which loads the {@link module:highlight/highlightediting~HighlightEditing} and
21
- * {@link module:highlight/highlightui~HighlightUI} plugins.
22
- */
23
- export default class Highlight extends Plugin {
24
- /**
25
- * @inheritDoc
26
- */
27
- public static get requires(): PluginDependencies {
28
- return [ HighlightEditing, HighlightUI ];
29
- }
30
-
31
- /**
32
- * @inheritDoc
33
- */
34
- public static get pluginName(): 'Highlight' {
35
- return 'Highlight';
36
- }
37
- }
38
-
39
- /**
40
- * The highlight option descriptor. See {@link module:highlight/highlight~HighlightConfig} to learn more.
41
- *
42
- * ```ts
43
- * {
44
- * model: 'pinkMarker',
45
- * class: 'marker-pink',
46
- * title: 'Pink Marker',
47
- * color: 'var(--ck-highlight-marker-pink)',
48
- * type: 'marker'
49
- * }
50
- * ```
51
- */
52
- export interface HighlightOption {
53
-
54
- /**
55
- * The user-readable title of the option.
56
- */
57
- title: string;
58
-
59
- /**
60
- * The unique attribute value in the model.
61
- */
62
- model: string;
63
-
64
- /**
65
- * The CSS `var()` used for the highlighter. The color is used in the user interface to represent the highlighter.
66
- * There is a possibility to use the default color format like rgb, hex or hsl, but you need to care about the color of `<mark>`
67
- * by adding CSS classes definition.
68
- */
69
- color: string;
70
-
71
- /**
72
- * The CSS class used on the `<mark>` element in the view. It should match the `color` setting.
73
- */
74
- class: string;
75
-
76
- /**
77
- * The type of highlighter:
78
- *
79
- * * `'marker'` &ndash; Uses the `color` as the `background-color` style,
80
- * * `'pen'` &ndash; Uses the `color` as the font `color` style.
81
- */
82
- type: 'marker' | 'pen';
83
- }
84
-
85
- /**
86
- * The configuration of the {@link module:highlight/highlight~Highlight highlight feature}.
87
- * ```ts
88
- * ClassicEditor
89
- * .create( editorElement, {
90
- * highlight: ... // Highlight feature configuration.
91
- * } )
92
- * .then( ... )
93
- * .catch( ... );
94
- * ```
95
- * See {@link module:core/editor/editorconfig~EditorConfig all editor options}.
96
- */
97
- export interface HighlightConfig {
98
-
99
- /**
100
- * The available highlight options. The default value is:
101
- * ```ts
102
- * options: [
103
- * {
104
- * model: 'yellowMarker',
105
- * class: 'marker-yellow',
106
- * title: 'Yellow marker',
107
- * color: 'var(--ck-highlight-marker-yellow)',
108
- * type: 'marker'
109
- * },
110
- * {
111
- * model: 'greenMarker',
112
- * class: 'marker-green',
113
- * title: 'Green marker',
114
- * color: 'var(--ck-highlight-marker-green)',
115
- * type: 'marker'
116
- * },
117
- * {
118
- * model: 'pinkMarker',
119
- * class: 'marker-pink',
120
- * title: 'Pink marker',
121
- * color: 'var(--ck-highlight-marker-pink)',
122
- * type: 'marker'
123
- * },
124
- * {
125
- * model: 'blueMarker',
126
- * class: 'marker-blue',
127
- * title: 'Blue marker',
128
- * color: 'var(--ck-highlight-marker-blue)',
129
- * type: 'marker'
130
- * },
131
- * {
132
- * model: 'redPen',
133
- * class: 'pen-red',
134
- * title: 'Red pen',
135
- * color: 'var(--ck-highlight-pen-red)',
136
- * type: 'pen'
137
- * },
138
- * {
139
- * model: 'greenPen',
140
- * class: 'pen-green',
141
- * title: 'Green pen',
142
- * color: 'var(--ck-highlight-pen-green)',
143
- * type: 'pen'
144
- * }
145
- * ]
146
- * ```
147
- *
148
- * There are two types of highlighters available:
149
- *
150
- * * `'marker'` &ndash; Rendered as a `<mark>` element, styled with the `background-color`.
151
- * * `'pen'` &ndash; Rendered as a `<mark>` element, styled with the font `color`.
152
- *
153
- * **Note**: The highlight feature provides a stylesheet with the CSS classes and corresponding colors defined
154
- * as CSS variables.
155
- *
156
- * ```ts
157
- * :root {
158
- * --ck-highlight-marker-yellow: #fdfd77;
159
- * --ck-highlight-marker-green: #63f963;
160
- * --ck-highlight-marker-pink: #fc7999;
161
- * --ck-highlight-marker-blue: #72cdfd;
162
- * --ck-highlight-pen-red: #e91313;
163
- * --ck-highlight-pen-green: #118800;
164
- * }
165
- *
166
- * .marker-yellow { ... }
167
- * .marker-green { ... }
168
- * .marker-pink { ... }
169
- * .marker-blue { ... }
170
- * .pen-red { ... }
171
- * .pen-green { ... }
172
- * ```
173
- *
174
- * It is possible to define the `color` property directly as `rgba(R, G, B, A)`,
175
- * `#RRGGBB[AA]` or `hsla(H, S, L, A)`. In such situation, the color will **only** apply to the UI of
176
- * the editor and the `<mark>` elements in the content must be styled by custom classes provided by
177
- * a dedicated stylesheet.
178
- *
179
- * **Note**: It is recommended for the `color` property to correspond to the class in the content
180
- * stylesheet because it represents the highlighter in the user interface of the editor.
181
- *
182
- * ```ts
183
- * ClassicEditor
184
- * .create( editorElement, {
185
- * highlight: {
186
- * options: [
187
- * {
188
- * model: 'pinkMarker',
189
- * class: 'marker-pink',
190
- * title: 'Pink Marker',
191
- * color: 'var(--ck-highlight-marker-pink)',
192
- * type: 'marker'
193
- * },
194
- * {
195
- * model: 'redPen',
196
- * class: 'pen-red',
197
- * title: 'Red Pen',
198
- * color: 'var(--ck-highlight-pen-red)',
199
- * type: 'pen'
200
- * },
201
- * ]
202
- * }
203
- * } )
204
- * .then( ... )
205
- * .catch( ... );
206
- * ```
207
- */
208
- options: Array<HighlightOption>;
209
- }
210
-
211
- declare module '@ckeditor/ckeditor5-core' {
212
- interface PluginsMap {
213
- [ Highlight.pluginName ]: Highlight;
214
- }
215
-
216
- interface EditorConfig {
217
-
218
- /**
219
- * The configuration of the {@link module:highlight/highlight~Highlight} feature.
220
- *
221
- * Read more in {@link module:highlight/highlight~HighlightConfig}.
222
- */
223
- highlight?: HighlightConfig;
224
- }
225
- }
@@ -1,113 +0,0 @@
1
- /**
2
- * @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
3
- * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
- */
5
-
6
- /**
7
- * @module highlight/highlightcommand
8
- */
9
-
10
- import { Command } from 'ckeditor5/src/core';
11
- import type { TreeWalkerValue } from 'ckeditor5/src/engine';
12
-
13
- /**
14
- * The highlight command. It is used by the {@link module:highlight/highlightediting~HighlightEditing highlight feature}
15
- * to apply the text highlighting.
16
- *
17
- * ```ts
18
- * editor.execute( 'highlight', { value: 'greenMarker' } );
19
- * ```
20
- *
21
- * **Note**: Executing the command without a value removes the attribute from the model. If the selection is collapsed
22
- * inside a text with the highlight attribute, the command will remove the attribute from the entire range
23
- * of that text.
24
- */
25
- export default class HighlightCommand extends Command {
26
- /**
27
- * A value indicating whether the command is active. If the selection has some highlight attribute,
28
- * it corresponds to the value of that attribute.
29
- *
30
- * @observable
31
- * @readonly
32
- */
33
- declare public value: string | undefined;
34
-
35
- /**
36
- * @inheritDoc
37
- */
38
- public override refresh(): void {
39
- const model = this.editor.model;
40
- const doc = model.document;
41
-
42
- this.value = doc.selection.getAttribute( 'highlight' ) as string | undefined;
43
- this.isEnabled = model.schema.checkAttributeInSelection( doc.selection, 'highlight' );
44
- }
45
-
46
- /**
47
- * Executes the command.
48
- *
49
- * @param options Options for the executed command.
50
- * @param options.value The value to apply.
51
- *
52
- * @fires execute
53
- */
54
- public override execute( options: { value?: string | null } = {} ): void {
55
- const model = this.editor.model;
56
- const document = model.document;
57
- const selection = document.selection;
58
-
59
- const highlighter = options.value;
60
-
61
- model.change( writer => {
62
- if ( selection.isCollapsed ) {
63
- const position = selection.getFirstPosition()!;
64
-
65
- // When selection is inside text with `highlight` attribute.
66
- if ( selection.hasAttribute( 'highlight' ) ) {
67
- // Find the full highlighted range.
68
- const isSameHighlight = ( value: TreeWalkerValue ) => {
69
- return value.item.hasAttribute( 'highlight' ) && value.item.getAttribute( 'highlight' ) === this.value;
70
- };
71
-
72
- const highlightStart = position.getLastMatchingPosition( isSameHighlight, { direction: 'backward' } );
73
- const highlightEnd = position.getLastMatchingPosition( isSameHighlight );
74
-
75
- const highlightRange = writer.createRange( highlightStart, highlightEnd );
76
-
77
- // Then depending on current value...
78
- if ( !highlighter || this.value === highlighter ) {
79
- // ...remove attribute when passing highlighter different then current or executing "eraser".
80
-
81
- // If we're at the end of the highlighted range, we don't want to remove highlight of the range.
82
- if ( !position.isEqual( highlightEnd ) ) {
83
- writer.removeAttribute( 'highlight', highlightRange );
84
- }
85
-
86
- writer.removeSelectionAttribute( 'highlight' );
87
- } else {
88
- // ...update `highlight` value.
89
-
90
- // If we're at the end of the highlighted range, we don't want to change the highlight of the range.
91
- if ( !position.isEqual( highlightEnd ) ) {
92
- writer.setAttribute( 'highlight', highlighter, highlightRange );
93
- }
94
-
95
- writer.setSelectionAttribute( 'highlight', highlighter );
96
- }
97
- } else if ( highlighter ) {
98
- writer.setSelectionAttribute( 'highlight', highlighter );
99
- }
100
- } else {
101
- const ranges = model.schema.getValidRanges( selection.getRanges(), 'highlight' );
102
-
103
- for ( const range of ranges ) {
104
- if ( highlighter ) {
105
- writer.setAttribute( 'highlight', highlighter, range );
106
- } else {
107
- writer.removeAttribute( 'highlight', range );
108
- }
109
- }
110
- }
111
- } );
112
- }
113
- }
@@ -1,139 +0,0 @@
1
- /**
2
- * @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
3
- * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
- */
5
-
6
- /**
7
- * @module highlight/highlightediting
8
- */
9
-
10
- import { Plugin, type Editor } from 'ckeditor5/src/core';
11
-
12
- import HighlightCommand from './highlightcommand';
13
- import type { HighlightOption } from './highlight';
14
-
15
- /**
16
- * The highlight editing feature. It introduces the {@link module:highlight/highlightcommand~HighlightCommand command} and the `highlight`
17
- * attribute in the {@link module:engine/model/model~Model model} which renders in the {@link module:engine/view/view view}
18
- * as a `<mark>` element with a `class` attribute (`<mark class="marker-green">...</mark>`) depending
19
- * on the {@link module:highlight/highlight~HighlightConfig configuration}.
20
- */
21
- export default class HighlightEditing extends Plugin {
22
- /**
23
- * @inheritDoc
24
- */
25
- public static get pluginName(): 'HighlightEditing' {
26
- return 'HighlightEditing';
27
- }
28
-
29
- /**
30
- * @inheritDoc
31
- */
32
- constructor( editor: Editor ) {
33
- super( editor );
34
-
35
- editor.config.define( 'highlight', {
36
- options: [
37
- {
38
- model: 'yellowMarker',
39
- class: 'marker-yellow',
40
- title: 'Yellow marker',
41
- color: 'var(--ck-highlight-marker-yellow)',
42
- type: 'marker'
43
- },
44
- {
45
- model: 'greenMarker',
46
- class: 'marker-green',
47
- title: 'Green marker',
48
- color: 'var(--ck-highlight-marker-green)',
49
- type: 'marker'
50
- },
51
- {
52
- model: 'pinkMarker',
53
- class: 'marker-pink',
54
- title: 'Pink marker',
55
- color: 'var(--ck-highlight-marker-pink)',
56
- type: 'marker'
57
- },
58
- {
59
- model: 'blueMarker',
60
- class: 'marker-blue',
61
- title: 'Blue marker',
62
- color: 'var(--ck-highlight-marker-blue)',
63
- type: 'marker'
64
- },
65
- {
66
- model: 'redPen',
67
- class: 'pen-red',
68
- title: 'Red pen',
69
- color: 'var(--ck-highlight-pen-red)',
70
- type: 'pen'
71
- },
72
- {
73
- model: 'greenPen',
74
- class: 'pen-green',
75
- title: 'Green pen',
76
- color: 'var(--ck-highlight-pen-green)',
77
- type: 'pen'
78
- }
79
- ]
80
- } );
81
- }
82
-
83
- /**
84
- * @inheritDoc
85
- */
86
- public init(): void {
87
- const editor = this.editor;
88
-
89
- // Allow highlight attribute on text nodes.
90
- editor.model.schema.extend( '$text', { allowAttributes: 'highlight' } );
91
-
92
- const options = editor.config.get( 'highlight.options' )!;
93
-
94
- // Set-up the two-way conversion.
95
- editor.conversion.attributeToElement( _buildDefinition( options ) );
96
-
97
- editor.commands.add( 'highlight', new HighlightCommand( editor ) );
98
- }
99
- }
100
-
101
- /**
102
- * Converts the options array to a converter definition.
103
- *
104
- * @param options An array with configured options.
105
- */
106
- function _buildDefinition( options: Array<HighlightOption> ): HighlightConverterDefinition {
107
- const definition: HighlightConverterDefinition = {
108
- model: {
109
- key: 'highlight',
110
- values: []
111
- },
112
- view: {}
113
- };
114
-
115
- for ( const option of options ) {
116
- definition.model.values.push( option.model );
117
- definition.view[ option.model ] = {
118
- name: 'mark',
119
- classes: option.class
120
- };
121
- }
122
-
123
- return definition;
124
- }
125
-
126
- type HighlightConverterDefinition = {
127
- model: { key: string; values: Array<string> };
128
- view: Record<string, { name: string; classes: string }>;
129
- };
130
-
131
- declare module '@ckeditor/ckeditor5-core' {
132
- interface CommandsMap {
133
- highlight: HighlightCommand;
134
- }
135
-
136
- interface PluginsMap {
137
- [ HighlightEditing.pluginName ]: HighlightEditing;
138
- }
139
- }
@@ -1,282 +0,0 @@
1
- /**
2
- * @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
3
- * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
- */
5
-
6
- /**
7
- * @module highlight/highlightui
8
- */
9
-
10
- import { Plugin, icons } from 'ckeditor5/src/core';
11
- import {
12
- ButtonView,
13
- SplitButtonView,
14
- ToolbarSeparatorView,
15
- createDropdown,
16
- addToolbarToDropdown,
17
- type DropdownView
18
- } from 'ckeditor5/src/ui';
19
-
20
- import markerIcon from './../theme/icons/marker.svg';
21
- import penIcon from './../theme/icons/pen.svg';
22
- import type { HighlightOption } from './highlight';
23
-
24
- import './../theme/highlight.css';
25
-
26
- /**
27
- * The default highlight UI plugin. It introduces:
28
- *
29
- * * The `'highlight'` dropdown,
30
- * * The `'removeHighlight'` and `'highlight:*'` buttons.
31
- *
32
- * The default configuration includes the following buttons:
33
- *
34
- * * `'highlight:yellowMarker'`
35
- * * `'highlight:greenMarker'`
36
- * * `'highlight:pinkMarker'`
37
- * * `'highlight:blueMarker'`
38
- * * `'highlight:redPen'`
39
- * * `'highlight:greenPen'`
40
- *
41
- * See the {@link module:highlight/highlight~HighlightConfig#options configuration} to learn more
42
- * about the defaults.
43
- */
44
- export default class HighlightUI extends Plugin {
45
- /**
46
- * Returns the localized option titles provided by the plugin.
47
- *
48
- * The following localized titles corresponding with default
49
- * {@link module:highlight/highlight~HighlightConfig#options} are available:
50
- *
51
- * * `'Yellow marker'`,
52
- * * `'Green marker'`,
53
- * * `'Pink marker'`,
54
- * * `'Blue marker'`,
55
- * * `'Red pen'`,
56
- * * `'Green pen'`.
57
- */
58
- public get localizedOptionTitles(): Record<string, string> {
59
- const t = this.editor.t;
60
-
61
- return {
62
- 'Yellow marker': t( 'Yellow marker' ),
63
- 'Green marker': t( 'Green marker' ),
64
- 'Pink marker': t( 'Pink marker' ),
65
- 'Blue marker': t( 'Blue marker' ),
66
- 'Red pen': t( 'Red pen' ),
67
- 'Green pen': t( 'Green pen' )
68
- };
69
- }
70
-
71
- /**
72
- * @inheritDoc
73
- */
74
- public static get pluginName(): 'HighlightUI' {
75
- return 'HighlightUI';
76
- }
77
-
78
- /**
79
- * @inheritDoc
80
- */
81
- public init(): void {
82
- const options = this.editor.config.get( 'highlight.options' )!;
83
-
84
- for ( const option of options ) {
85
- this._addHighlighterButton( option );
86
- }
87
-
88
- this._addRemoveHighlightButton();
89
-
90
- this._addDropdown( options );
91
- }
92
-
93
- /**
94
- * Creates the "Remove highlight" button.
95
- */
96
- private _addRemoveHighlightButton(): void {
97
- const t = this.editor.t;
98
- const command = this.editor.commands.get( 'highlight' )!;
99
-
100
- this._addButton( 'removeHighlight', t( 'Remove highlight' ), icons.eraser, null, button => {
101
- button.bind( 'isEnabled' ).to( command, 'isEnabled' );
102
- } );
103
- }
104
-
105
- /**
106
- * Creates a toolbar button from the provided highlight option.
107
- */
108
- private _addHighlighterButton( option: HighlightOption ) {
109
- const command = this.editor.commands.get( 'highlight' )!;
110
-
111
- // TODO: change naming
112
- this._addButton( 'highlight:' + option.model, option.title, getIconForType( option.type ), option.model, decorateHighlightButton );
113
-
114
- function decorateHighlightButton( button: ButtonView ) {
115
- button.bind( 'isEnabled' ).to( command, 'isEnabled' );
116
- button.bind( 'isOn' ).to( command, 'value', value => value === option.model );
117
- button.iconView.fillColor = option.color;
118
- button.isToggleable = true;
119
- }
120
- }
121
-
122
- /**
123
- * Internal method for creating highlight buttons.
124
- *
125
- * @param name The name of the button.
126
- * @param label The label for the button.
127
- * @param icon The button icon.
128
- * @param value The `value` property passed to the executed command.
129
- * @param decorateButton A callback getting ButtonView instance so that it can be further customized.
130
- */
131
- private _addButton( name: string, label: string, icon: string, value: string | null, decorateButton: ( button: ButtonView ) => void ) {
132
- const editor = this.editor;
133
-
134
- editor.ui.componentFactory.add( name, locale => {
135
- const buttonView = new ButtonView( locale );
136
-
137
- const localized = this.localizedOptionTitles[ label ] ? this.localizedOptionTitles[ label ] : label;
138
-
139
- buttonView.set( {
140
- label: localized,
141
- icon,
142
- tooltip: true
143
- } );
144
-
145
- buttonView.on( 'execute', () => {
146
- editor.execute( 'highlight', { value } );
147
- editor.editing.view.focus();
148
- } );
149
-
150
- // Add additional behavior for buttonView.
151
- decorateButton( buttonView );
152
-
153
- return buttonView;
154
- } );
155
- }
156
-
157
- /**
158
- * Creates the split button dropdown UI from the provided highlight options.
159
- */
160
- private _addDropdown( options: Array<HighlightOption> ) {
161
- const editor = this.editor;
162
- const t = editor.t;
163
- const componentFactory = editor.ui.componentFactory;
164
-
165
- const startingHighlighter = options[ 0 ];
166
-
167
- const optionsMap = options.reduce( ( retVal, option ) => {
168
- retVal[ option.model ] = option;
169
-
170
- return retVal;
171
- }, {} as Record<string, HighlightOption> );
172
-
173
- componentFactory.add( 'highlight', locale => {
174
- const command = editor.commands.get( 'highlight' )!;
175
- const dropdownView = createDropdown( locale, SplitButtonView );
176
- const splitButtonView = dropdownView.buttonView as HighlightSplitButtonView;
177
-
178
- splitButtonView.set( {
179
- label: t( 'Highlight' ),
180
- tooltip: true,
181
- // Holds last executed highlighter.
182
- lastExecuted: startingHighlighter.model,
183
- // Holds current highlighter to execute (might be different then last used).
184
- commandValue: startingHighlighter.model,
185
- isToggleable: true
186
- } );
187
-
188
- // Dropdown button changes to selection (command.value):
189
- // - If selection is in highlight it get active highlight appearance (icon, color) and is activated.
190
- // - Otherwise it gets appearance (icon, color) of last executed highlight.
191
- splitButtonView.bind( 'icon' ).to( command, 'value', value => getIconForType( getActiveOption( value, 'type' ) ) );
192
- splitButtonView.bind( 'color' ).to( command, 'value', value => getActiveOption( value, 'color' ) );
193
- splitButtonView.bind( 'commandValue' ).to( command, 'value', value => getActiveOption( value, 'model' ) );
194
- splitButtonView.bind( 'isOn' ).to( command, 'value', value => !!value );
195
-
196
- splitButtonView.delegate( 'execute' ).to( dropdownView );
197
-
198
- // Create buttons array.
199
- const buttonsCreator = () => {
200
- const buttons = options.map( option => {
201
- // Get existing highlighter button.
202
- const buttonView = componentFactory.create( 'highlight:' + option.model );
203
-
204
- // Update lastExecutedHighlight on execute.
205
- this.listenTo( buttonView, 'execute', () => {
206
- ( dropdownView.buttonView as HighlightSplitButtonView ).set( { lastExecuted: option.model } );
207
- } );
208
-
209
- return buttonView;
210
- } );
211
-
212
- // Add separator and eraser buttons to dropdown.
213
- buttons.push( new ToolbarSeparatorView() );
214
- buttons.push( componentFactory.create( 'removeHighlight' ) );
215
-
216
- return buttons;
217
- };
218
-
219
- // Make toolbar button enabled when any button in dropdown is enabled before adding separator and eraser.
220
- dropdownView.bind( 'isEnabled' ).to( command, 'isEnabled' );
221
-
222
- addToolbarToDropdown( dropdownView, buttonsCreator, {
223
- enableActiveItemFocusOnDropdownOpen: true,
224
- ariaLabel: t( 'Text highlight toolbar' )
225
- } );
226
- bindToolbarIconStyleToActiveColor( dropdownView );
227
-
228
- // Execute current action from dropdown's split button action button.
229
- splitButtonView.on( 'execute', () => {
230
- editor.execute( 'highlight', { value: splitButtonView.commandValue } );
231
- } );
232
-
233
- // Focus the editable after executing the command.
234
- // It overrides a default behaviour where the focus is moved to the dropdown button (#12125).
235
- this.listenTo( dropdownView, 'execute', () => {
236
- editor.editing.view.focus();
237
- } );
238
-
239
- /**
240
- * Returns active highlighter option depending on current command value.
241
- * If current is not set or it is the same as last execute this method will return the option key (like icon or color)
242
- * of last executed highlighter. Otherwise it will return option key for current one.
243
- */
244
- function getActiveOption<Key extends keyof HighlightOption>( current: string | undefined, key: Key ): HighlightOption[ Key ] {
245
- const whichHighlighter = !current ||
246
- current === splitButtonView.lastExecuted ? splitButtonView.lastExecuted : current;
247
-
248
- return optionsMap[ whichHighlighter! ][ key ];
249
- }
250
-
251
- return dropdownView;
252
- } );
253
- }
254
- }
255
-
256
- /**
257
- * Extends split button icon style to reflect last used button style.
258
- */
259
- function bindToolbarIconStyleToActiveColor( dropdownView: DropdownView ): void {
260
- const actionView = ( dropdownView.buttonView as HighlightSplitButtonView ).actionView;
261
-
262
- actionView.iconView.bind( 'fillColor' ).to( ( dropdownView.buttonView! as HighlightSplitButtonView ), 'color' );
263
- }
264
-
265
- /**
266
- * Returns icon for given highlighter type.
267
- */
268
- function getIconForType( type: 'marker' | 'pen' ) {
269
- return type === 'marker' ? markerIcon : penIcon;
270
- }
271
-
272
- type HighlightSplitButtonView = SplitButtonView & {
273
- lastExecuted: string;
274
- commandValue: string;
275
- color: string;
276
- };
277
-
278
- declare module '@ckeditor/ckeditor5-core' {
279
- interface PluginsMap {
280
- [ HighlightUI.pluginName ]: HighlightUI;
281
- }
282
- }