From 1634f99a04fd2d8b2bbea90121b62807e40c35de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20Kalij=C3=A4rvi?= Date: Thu, 19 Dec 2024 08:09:27 +0200 Subject: [PATCH 1/6] UHF-11186: Changed the _getBalloonPosition() to getPositionOptions(). --- .../assets/js/ckeditor5_plugins/helfiLink/src/helfiLinkUi.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/helfi_ckeditor/assets/js/ckeditor5_plugins/helfiLink/src/helfiLinkUi.js b/modules/helfi_ckeditor/assets/js/ckeditor5_plugins/helfiLink/src/helfiLinkUi.js index a6a62a6ad..51b87f3f2 100644 --- a/modules/helfi_ckeditor/assets/js/ckeditor5_plugins/helfiLink/src/helfiLinkUi.js +++ b/modules/helfi_ckeditor/assets/js/ckeditor5_plugins/helfiLink/src/helfiLinkUi.js @@ -154,7 +154,7 @@ export default class HelfiLinkUi extends Plugin { contextualBalloonPlugin.remove(newValue); contextualBalloonPlugin.add({ view: linkFormView, - position: contextualBalloonPlugin._getBalloonPosition(), + position: contextualBalloonPlugin.getPositionOptions(), balloonClassName: 'helfi-contextual-balloon', withArrow: false, }); From 16635c628a7a2f45cf688d7d46425479cab93139 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20Kalij=C3=A4rvi?= Date: Thu, 19 Dec 2024 08:11:32 +0200 Subject: [PATCH 2/6] UHF-11186: Added minified js. --- modules/helfi_ckeditor/assets/js/build/helfiLink.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/helfi_ckeditor/assets/js/build/helfiLink.js b/modules/helfi_ckeditor/assets/js/build/helfiLink.js index cea87fbfe..00563666d 100644 --- a/modules/helfi_ckeditor/assets/js/build/helfiLink.js +++ b/modules/helfi_ckeditor/assets/js/build/helfiLink.js @@ -1 +1 @@ -!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.CKEditor5=t():(e.CKEditor5=e.CKEditor5||{},e.CKEditor5.helfiLink=t())}(self,(()=>(()=>{var e={"ckeditor5/src/core.js":(e,t,i)=>{e.exports=i("dll-reference CKEditor5.dll")("./src/core.js")},"ckeditor5/src/typing.js":(e,t,i)=>{e.exports=i("dll-reference CKEditor5.dll")("./src/typing.js")},"ckeditor5/src/ui.js":(e,t,i)=>{e.exports=i("dll-reference CKEditor5.dll")("./src/ui.js")},"ckeditor5/src/utils.js":(e,t,i)=>{e.exports=i("dll-reference CKEditor5.dll")("./src/utils.js")},"ckeditor5/src/widget.js":(e,t,i)=>{e.exports=i("dll-reference CKEditor5.dll")("./src/widget.js")},"dll-reference CKEditor5.dll":e=>{"use strict";e.exports=CKEditor5.dll}},t={};function i(n){var s=t[n];if(void 0!==s)return s.exports;var l=t[n]={exports:{}};return e[n](l,l.exports,i),l.exports}i.d=(e,t)=>{for(var n in t)i.o(t,n)&&!i.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},i.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t);var n={};return(()=>{"use strict";i.d(n,{default:()=>w});var e=i("ckeditor5/src/core.js"),t=i("ckeditor5/src/widget.js"),s=i("ckeditor5/src/typing.js");const l=(e,t)=>{let i;if("/"===e||""===e)return!1;try{i=new URL(e)}catch(t){if(i=new URL(`https://${e}`),!/https?:\/\/(?:www\.)?[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}/.test(i))return!1}const n=i.hostname;return!t.some((e=>e.startsWith("*.")&&n.endsWith(e.slice(2))||e===n))},o=e=>{try{const t=new URL(e);return("tel:"===t.protocol||"mailto:"===t.protocol)&&t.protocol.replace(":","")}catch(e){return!1}},r={linkIcon:{label:Drupal.t("Icon",{},{context:"CKEditor5 Helfi Link plugin"}),machineName:"icon",selectListOptions:{},type:"select",group:"advanced",isVisible:!1,viewAttribute:"data-hds-icon-start"},linkVariant:{label:Drupal.t("Design"),machineName:"variant",selectListOptions:{link:Drupal.t("Normal link",{},{context:"CKEditor5 Helfi Link plugin"}),primary:Drupal.t("Button primary"),secondary:Drupal.t("Button secondary"),supplementary:Drupal.t("Button supplementary")},type:"select",group:"advanced",isVisible:!0,viewAttribute:"data-hds-variant"},linkButton:{machineName:"data-hds-component",type:"static",viewAttribute:"data-hds-component"},linkProtocol:{label:Drupal.t("Protocol",{},{context:"CKEditor5 Helfi Link plugin"}),machineName:"protocol",selectListOptions:{https:"https://",tel:"tel:",mailto:"mailto:"},type:"select",group:"helper",viewAttribute:"data-protocol",isVisible:!0},linkNewWindowConfirm:{label:Drupal.t("The link meets the accessibility requirements",{},{context:"CKEditor5 Helfi Link plugin"}),description:Drupal.t('I have made sure that the description of this link clearly states that it will open in a new tab. See WCAG 3.2.5 accessibility requirement (the link opens in a new tab).',{"@wcag-techniques":"https://www.w3.org/WAI/WCAG21/Techniques/general/G200.html"},{context:"CKEditor5 Helfi Link plugin"}),machineName:"link-new-window-confirm",viewAttribute:{target:"_blank"},type:"checkbox",group:"advanced",isVisible:!1},linkNewWindow:{label:Drupal.t("Open in new window/tab",{},{context:"CKEditor5 Helfi Link plugin"}),machineName:"link-new-window",type:"checkbox",group:"advanced",isVisible:!0},linkIsExternal:{machineName:"data-is-external",type:"static",viewAttribute:"data-is-external"}};class a extends e.Plugin{static get requires(){return[t.Widget]}static get pluginName(){return"HelfiLinkEditing"}init(){Object.keys(r).forEach((e=>{r[e].machineName&&(this._convertAttribute(e,r[e].viewAttribute),this._removeAttributeOnUnlinkCommandExecute(e),this._refreshAttributeValue(e))})),this._defineHelfiButtonConverters(),this._trimHref(),this._addAttributeOnLinkCommandExecute(Object.keys(r))}_trimHref(){const{editor:e}=this;e.conversion.for("upcast").elementToAttribute({view:"a",model:{key:"linkHref",value:e=>{if(!e.hasAttribute("href"))return null;const t=e.getAttribute("href");return t?t.trim().replace(/^%20+/,"").replace(/%20+$/,"").trim():null}},converterPriority:"highest"})}_convertAttribute(e,t){const{editor:i}=this;if(t)if(i.model.schema.extend("$text",{allowAttributes:e}),i.conversion.for("downcast").attributeToElement({model:e,view:(e,{writer:i})=>{const n={};e&&"object"==typeof t?n[Object.keys(t)]=t[Object.keys(t)]:n[t]=e;const s=i.createAttributeElement("a",n,{priority:5});return i.setCustomProperty("link",!0,s),s}}),"object"==typeof t){const n=Object.keys(t)[0],s=t[Object.keys(t)];i.conversion.for("upcast").attributeToAttribute({view:{name:"a",key:n,value:s},model:{key:e,value:e=>!(!e.hasAttribute(n)||e.getAttribute(n)!==s)}})}else"linkIsExternal"===e||"linkProtocol"===e?i.conversion.for("upcast").elementToAttribute({view:"a",model:{key:e,value:t=>{if(!t.hasAttribute("href"))return null;const i=t.getAttribute("href"),{whiteListedDomains:n}=this.editor.config.get("link");if(!n||!i||i.startsWith("#"))return null;const s=l(i,n),r=o(i);return r&&"linkProtocol"===e?r:!(!s||"linkIsExternal"!==e)||null}},converterPriority:"high"}):i.conversion.for("upcast").elementToAttribute({view:{name:"a",attributes:{[t]:!0}},model:{key:e,value:e=>e.getAttribute(t)}})}_removeAttributeOnUnlinkCommandExecute(e){const{editor:t}=this,{model:i}=this.editor,{selection:n}=i.document,l=t.commands.get("unlink");let o=!1;l.on("execute",(l=>{o||(l.stop(),i.change((()=>{o=!0,t.execute("unlink"),o=!1,i.change((t=>{let l;l=n.isCollapsed?[(0,s.findAttributeRange)(n.getFirstPosition(),e,n.getAttribute(e),i)]:i.schema.getValidRanges(n.getRanges(),e),Array.isArray(l)&&l.forEach((i=>t.removeAttribute(e,i)))}))})))}),{priority:"high"})}_refreshAttributeValue(e){const{editor:t}=this,{model:i}=this.editor,{selection:n}=i.document,s=t.commands.get("link");s.set(e,null),i.document.on("change",(()=>{s[e]=n.getAttribute(e)}))}_defineHelfiButtonConverters(){const{editor:e}=this;e.model.schema.isRegistered("tableCell")&&e.model.schema.extend("tableCell",{allowContentOf:"$block"});const t=e=>{const t=e.split(" "),i=t.find((e=>e.startsWith("hds-button--"))),n=t.find((e=>e.endsWith("hds-button")));return i?i.replace("hds-button--",""):n?"primary":null};e.conversion.for("upcast").elementToElement({view:{name:"a"},model:e=>{const t=Array.from(e.getChildren()).find((e=>"span"===e.name&&e.hasClass("hds-button__label")));if(t){const i=Array.from(e.getChildren()),n=i.length;n>0&&e._removeChildren(0,n),i.forEach((t=>{if("span"===t.name&&t.hasClass("hel-icon")){const i=(e=>{let t=!1,i=e.next();for(;!i.done;){const n=i.value;if(n&&n.startsWith("hel-icon--")){t=n.replace("hel-icon--","");break}i=e.next()}return t})(t.getClassNames());i&&e._setAttribute("data-hds-icon-start",i)}})),Array.from(t.getChildren()).forEach((t=>{e._appendChild(t)}))}const i=Array.from(e.getChildren()).find((e=>!(!e.name||"span"!==e.name)&&(!e.getAttribute("dir")&&!e.getAttribute("lang")&&e)));return i&&(e._removeChildren(i.index,1),Array.from(i.getChildren()).forEach((t=>{e._appendChild(t)}))),e.hasAttribute("data-protocol")&&e.getAttribute("data-protocol").startsWith("http")&&e._removeAttribute("data-protocol"),e},converterPriority:"highest"}),e.conversion.for("upcast").attributeToAttribute({view:{name:"a",key:"data-design"},model:{key:"linkVariant",value:e=>{let i;return e.hasClass("hds-button")&&(i=t([...e._classes].join(" ")),i||(i=t(e.getAttribute("data-design")))),i&&"primary"===i&&(i=null),i}}}),e.conversion.for("upcast").attributeToAttribute({view:{name:"a",key:"data-design"},model:{key:"linkButton",value:e=>{let i;return e.hasClass("hds-button")&&(i=t([...e._classes].join(" ")),i||(i=t(e.getAttribute("data-design")))),!!i&&"button"}}}),e.conversion.for("upcast").attributeToAttribute({view:{name:"a",key:"class",value:"hds-button"},model:{key:"linkButton",value:"button"}}),e.conversion.for("upcast").attributeToAttribute({view:{name:"a",key:"data-protocol"},model:{key:"linkProtocol",value:e=>{return"https"!==(t=e.getAttribute("data-protocol"))&&"http"!==t&&t;var t}},converterPriority:"highest"}),e.conversion.for("upcast").attributeToAttribute({view:{name:"a",key:"data-selected-icon"},model:{key:"linkIcon"}})}_addAttributeOnLinkCommandExecute(e){const{editor:t}=this,i=t.commands.get("link");let n=!1;i.on("execute",((i,s)=>{if(s.length<3)return;if(n)return void(n=!1);i.stop(),n=!0;const l=s[s.length-1],{model:r}=t,{selection:a}=r.document,c=s[0];let d=c;if(c){d=c.trim().replace(/^%20+/,"").replace(/%20+$/,"").trim();const e=o(d);e&&"tel"===e&&(d=d.replace(/[\s()-]/g,"")),s[0]=d}try{r.change((i=>{t.execute("link",...s),e.forEach((e=>{if(a.isCollapsed){const t=e=>{const t=e.textNode||e.nodeBefore;if(!t){const t=i.createRange(e);return i.setSelection(t),t}return i.createRangeOn(t)};l[e]?i.setAttribute(e,l[e],t(a.getFirstPosition())):i.removeAttribute(e,t(a.getFirstPosition())),i.removeSelectionAttribute(e)}else{const t=r.schema.getValidRanges(a.getRanges(),e);let n=t.next();for(;!n.done;){const s=n.value;l[e]?i.setAttribute(e,l[e],s):i.removeAttribute(e,s),n=t.next()}}})),n=!1}))}catch(e){i.stop()}}),{priority:"high"})}}var c=i("ckeditor5/src/ui.js"),d=i("ckeditor5/src/utils.js");class h extends c.View{constructor(e){super(e);const t=this.bindTemplate;this.set("class"),this.set("isVisible",!0),this.set("isChecked",!1),this.set("label"),this.set("description"),this.set("id",null),this.set("tabindex",-1),this.children=this.createCollection(),this.labelView=this._createLabelView(),this.checkboxInputView=this._createCheckboxInputView(),this.checkboxSpanToggle=this._createCheckboxSpanToggleView(),this.bind("isVisible").to(this,"updateVisibility"),this.bind("isChecked").to(this,"updateChecked"),this.setTemplate({tag:"div",attributes:{class:["form-type--checkbox","helfi-link-checkbox",t.if("isVisible","is-hidden",(e=>!e)),t.to("class")]},on:{keydown:t.to((e=>{e.target===this.element&&e.keyCode===(0,d.getCode)("space")&&(this.isChecked=!this.isChecked)}))},children:this.children})}render(){super.render(),this.children.add(this.checkboxInputView),this.children.add(this.checkboxSpanToggle),this.children.add(this.labelView)}focus(){this.element.focus()}_createCheckboxInputView(){const e=new c.View,t=this.bindTemplate;return e.setTemplate({tag:"input",attributes:{type:"checkbox",id:t.to("id"),checked:t.if("isChecked")},on:{change:t.to((e=>{this.isChecked=e.target.checked}))}}),e}_createCheckboxSpanToggleView(){const e=new c.View,t=this.bindTemplate;return e.setTemplate({tag:"span",attributes:{class:["checkbox-toggle"],id:t.to("id")},children:[{tag:"span",attributes:{class:["checkbox-toggle__inner"]}}]}),e}_createLabelView(){const e=new c.View;return e.setTemplate({tag:"label",attributes:{for:this.bindTemplate.to("id")},children:[{text:this.bindTemplate.to("label")}]}),e}updateVisibility(e){e?this.element.classList.remove("is-hidden"):this.element.classList.add("is-hidden")}updateChecked(e){e!==this.isChecked&&this.checkboxInputView?.element?.click()}}class u extends c.View{constructor(e,t){super(e.locale),this.options=t,this.tomSelect=!1,this.linkCommandConfig=e.config.get("link"),this.loadedIcons=this.linkCommandConfig?.loadedIcons,this.set("isVisible",!1),this.bind("isVisible").to(this,"updateVisibility");const i=this.bindTemplate;this.set("isOpen",!1),this.set("label"),this.set("id",null),this.setTemplate({tag:"select",attributes:{id:i.to("id"),class:["ck-helfi-link-select-list"],"data-placeholder":this.options.label,autocomplete:"off"},on:{keydown:i.to((e=>{e.target===this.element&&e.keyCode===(0,d.getCode)("space")&&(this.isOpen=!this.isOpen)}))}})}updateVisibility(e){e?(this.tomSelect?.wrapper?.classList.remove("is-hidden"),this.element.classList.remove("is-hidden")):(this.tomSelect?.wrapper?.classList.add("is-hidden"),this.element.classList.add("is-hidden"))}render(){super.render()}focus(){this.element.focus()}selectListDefaultOptions(){return{valueField:"option",labelField:"name",searchField:"title",maxItems:1,placeholder:this.options.label,create:!1}}}class m extends u{renderTomSelect(e,t){if(!this.tomSelect&&e){const e=super.selectListDefaultOptions(),i=(e,t)=>`\n \n ${t(e.title)}\n \n `,n={...e,options:Object.keys(t).map((e=>({option:e,title:t[e]}))),render:{option:(e,t)=>i(e,t),item:(e,t)=>i(e,t)}};this.tomSelect=new TomSelect(this.element,n)}}}class p extends c.View{constructor(e,t){super(e),this.advancedChildren=t;const i=this.bindTemplate;this.set("isOpen",!1),this.set("label"),this.set("id",null),this.children=this.createCollection(),this.detailsSummary=this._createDetailsSummary(),this.setTemplate({tag:"details",attributes:{id:i.to("id"),class:["ck-helfi-link-details",i.if("isOpen","ck-is-open",(e=>e))],open:i.if("isOpen")},on:{keydown:i.to((e=>{e.target===this.element&&e.keyCode===(0,d.getCode)("space")&&(this.isOpen=!this.isOpen)}))},children:this.children})}render(){super.render(),this.children.add(this.detailsSummary),this.children.addMany(this.advancedChildren)}focus(){this.element.focus()}_createDetailsSummary(){const e=new c.View;return e.setTemplate({tag:"summary",attributes:{role:"button",class:["ck-helfi-link-details__summary"],tabindex:0},children:[{text:this.bindTemplate.to("label")}]}),e}}class b extends u{renderTomSelect(e,t){if(!this.tomSelect&&e){const e=super.selectListDefaultOptions(),i=(e,t)=>`\n \n ${t(e.title)}\n \n `,n={...e,plugins:{dropdown_input:{},remove_button:{title:"Remove this item"}},options:Object.keys(t).map((e=>({option:e,title:t[e]}))),render:{option:(e,t)=>i(e,t),item:(e,t)=>i(e,t)}};this.tomSelect=new TomSelect(this.element,n)}}}class k extends u{renderTomSelect(e){if(!this.tomSelect&&e){const e=super.selectListDefaultOptions(),t=(e,t)=>`\n \n \n ${t(e.name)}\n \n `,i={...e,plugins:{dropdown_input:{},remove_button:{title:"Remove this item"}},valueField:"icon",searchField:["name"],options:Object.keys(this.loadedIcons).map((e=>({icon:e,name:this.loadedIcons[e]}))),render:{option:(e,i)=>t(e,i),item:(e,i)=>t(e,i)}};this.tomSelect=new TomSelect(this.element,i)}}}class f extends e.Plugin{constructor(e){super(e),this.editor=e,this.advancedChildren=new d.Collection,this.formElements=r,this.helfiContextualBalloonInitialized=!1}init(){this.editor.plugins.get("LinkUI")._createViews&&this.editor.plugins.get("LinkUI")._createViews(),this._addContextualBalloonClass(),this.editor.plugins.get("ContextualBalloon").on("change:visibleView",((e,t,i,n)=>{const s=this.editor.plugins.get("LinkUI").formView;if(i===n||i!==s||!this.helfiContextualBalloonInitialized)return;const l=Object.keys(this.formElements).reverse();l.forEach((e=>{if(!this.formElements[e].machineName)return;const t=this._createFormField(e,s);this.formElements[e].group&&"advanced"===this.formElements[e].group&&void 0!==t&&this.advancedChildren.add(t)})),this._createAdvancedSettingsAccordion(s),l.forEach((e=>{this.formElements[e].machineName&&this._handleDataLoadingIntoFormField(e,s)})),s.urlInputView.infoText||(s.urlInputView.infoText=Drupal.t("Start typing to find content.",{},{context:"CKEditor5 Helfi Link plugin"})),this._handleCheckboxes(s),this._handleFormFieldSubmit(l)}))}_addContextualBalloonClass(){const{editor:e}=this;e.plugins.get("ContextualBalloon").on("set:visibleView",((t,i,n,s)=>{const l=e.plugins.get("LinkUI").formView;if(n===s||n!==l)return;const o=this.editor.plugins.get("ContextualBalloon");o.hasView(l)&&!o.view.element.classList.contains("helfi-contextual-balloon")&&(l.template.attributes.class.push("helfi-link-form"),l.template.attributes.class.push("ck-reset_all-excluded"),o.remove(n),o.add({view:l,position:o._getBalloonPosition(),balloonClassName:"helfi-contextual-balloon",withArrow:!1}),this.helfiContextualBalloonInitialized=!0)}))}_createSelectList(e,t,i){const{editor:n}=this;let s={};switch(e){case"linkProtocol":s=new m(n,t),i.urlInputView.on("change:isEmpty",((e,t,i)=>{s.updateVisibility(i)}));break;case"linkVariant":s=new b(n,t);break;case"linkIcon":s=new k(n,t),i.linkVariant.on("change:isEmpty",((e,t,i)=>{s.updateVisibility(i)}))}return s.set({isVisible:t.isVisible,id:t.machineName,label:t.label}),s}_createAdvancedSettingsAccordion(e){if(e.advancedSettings)return e.advancedSettings.element.open=!1,e.advancedSettings.detailsSummary.element.ariaExpanded=!1,e.advancedSettings.detailsSummary.element.ariaPressed=!1,e.advancedSettings;const{editor:t}=this,i=new p(t.locale,this.advancedChildren);return i.set({label:Drupal.t("Advanced settings",{},{context:"CKEditor5 Helfi Link plugin"}),id:"advanced-settings",isOpen:!1}),e.children.add(i,2),e.urlInputView.errorText&&(e.urlInputView.errorText=""),e.advancedSettings=i,e.advancedSettings}_createCheckbox(e){const t=new h(this.editor.locale),i=this.formElements[e];return t.set({isVisible:i.isVisible,tooltip:!0,class:"ck-find-checkboxes__box",id:i.machineName,label:i.label}),t}_createFormField(e,t){const{editor:i}=this,n=this.formElements[e],s=i.commands.get("link");if(!t[e]){let l={};switch(n.type){case"select":l=this._createSelectList(e,n,t);break;case"checkbox":l=this._createCheckbox(e);break;case"static":l=!1;break;default:l=new c.LabeledFieldView(i.locale,c.createLabeledInputText)}if(!l)return;return l.machineName=e,l.class=`helfi-link--${n.machineName}`,l.label=n.label,n.description&&(l.infoText=n.description),n.group&&"advanced"===n.group||t.children.add(l,"select"===n.type?0:1),t._focusables.add(l,1),t.focusTracker.add(l.element),t[e]=l,"checkbox"===n.type&&t[e].checkboxInputView.bind("isChecked").to(s,e),"input"===n.type&&t[e].fieldView.bind("value").to(s,e),"linkProtocol"!==e||t.urlInputView.isEmpty||t[e].updateVisibility(!1),t[e]}}_handleDataLoadingIntoFormField(e,t){const{editor:i}=this,n=i.commands.get("link"),s=this.formElements[e];if(void 0!==t[e])switch(s.type){case"static":return;case"checkbox":{const i=!!n.linkNewWindowConfirm;t[e].updateChecked(i),t.linkNewWindowConfirm&&t.linkNewWindowConfirm.updateVisibility(i);break}case"select":t[e].renderTomSelect(t[e].element,s?.selectListOptions),"linkIcon"===e&&t[e].tomSelect.on("initialize",(()=>{t[e].updateVisibility(!1)})),t[e].tomSelect.clear(),n[e]&&t[e].tomSelect.addItem(n[e],!0),"linkProtocol"===e&&t[e].tomSelect.on("item_add",(i=>{t.urlInputView.isEmpty&&(t.urlInputView.fieldView.value=s.selectListOptions[i],t.urlInputView.focus(),t[e].tomSelect.clear())})),"linkVariant"===e&&("button"!==n.linkButton||n[e]&&"primary"!==n[e]||t[e].tomSelect.addItem("primary",!0),n.linkVariant||"button"===n.linkButton||t?.linkIcon.updateVisibility(!1),t[e].tomSelect.on("item_remove",(()=>{t?.linkIcon.tomSelect.clear(),t?.linkIcon.updateVisibility(!1)})),t[e].tomSelect.on("item_add",(e=>{t?.linkIcon.updateVisibility("link"!==e),"link"===e&&t?.linkIcon.tomSelect.clear()})));break;default:t[e].fieldView.element.value=n[e]||""}}_handleCheckboxes(e){if(this.formElements.linkNewWindowConfirm&&this.formElements.linkNewWindow&&e&&e.linkNewWindow&&e.linkNewWindowConfirm&&e.linkNewWindowConfirm.element){if(!e.linkNewWindowConfirm.element.querySelector(".helfi-link-form__field_description")){const t=document.createElement("div");t.innerHTML=this.formElements.linkNewWindowConfirm.description,t.classList.add("helfi-link-form__field_description"),e.linkNewWindowConfirm.element.appendChild(t)}e.linkNewWindow.on("change:isChecked",((t,i,n)=>{e?.linkNewWindowConfirm.updateChecked(!1),e?.linkNewWindowConfirm.updateVisibility(n)}))}}_handleFormFieldSubmit(e){const{editor:t}=this,{selection:i}=t.model.document,n=t.plugins.get("LinkUI").formView,s=t.commands.get("link");this.stopListening(n,"submit"),this.listenTo(n,"submit",(t=>{n.urlInputView?.fieldView?.element?.value||(n.urlInputView.errorText=Drupal.t("The link URL field cannot be empty.",{},{context:"CKEditor5 Helfi Link plugin"}),t.stop());const{whiteListedDomains:r}=this.editor.config.get("link"),a=n.urlInputView?.fieldView?.element?.value,c=e.reduce(((e,t)=>{switch(t){case"linkVariant":{const i=n?.[t]?.tomSelect.getValue();if(!i||"link"===i)return e;if("primary"===i)return e.linkButton="button",e;e[t]=i,e.linkButton="button";break}case"linkIcon":e[t]=n?.[t]?.tomSelect.getValue();break;case"linkProtocol":if(!r||!a||a.startsWith("#"))break;o(a)&&(e[t]=o(a));break;case"linkIsExternal":if(!r||!a||a.startsWith("#"))break;if(!o(a)&&l(a,r)){e[t]=l(a,r);break}break;default:e[t]=n?.[t]?.fieldView?.element?.value??""}return"checkbox"===this.formElements[t].type&&(e[t]=n?.[t]?.checkboxInputView?.element?.checked),e}),{});i.isCollapsed&&!n.urlInputView?.fieldView?.element?.value&&c.linkId&&(n.urlInputView.errorText=Drupal.t("When there is no selection, the link URL must be provided. To add a link without a URL, first select text in the editor and then proceed with adding the link.",{},{context:"CKEditor5 Helfi Link plugin"}),t.stop()),c.linkNewWindowConfirm&&c.linkNewWindow||(c.linkNewWindowConfirm=!1,c.linkNewWindow=!1,n.linkNewWindowConfirm.checkboxInputView.element.checked&&n.linkNewWindowConfirm.checkboxInputView.element.click(),n.linkNewWindow.checkboxInputView.element.checked&&n.linkNewWindow.checkboxInputView.element.click()),s.once("execute",((e,t)=>{if(t.length<3)t.push(c);else{if(3!==t.length)throw Error("The link command has more than 3 arguments.");Object.assign(t[2],c)}}),{priority:"highest"})}),{priority:"high"})}}class g extends e.Plugin{static get requires(){return[a,f]}}const w={HelfiLink:g}})(),n=n.default})())); \ No newline at end of file +!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.CKEditor5=t():(e.CKEditor5=e.CKEditor5||{},e.CKEditor5.helfiLink=t())}(self,(()=>(()=>{var e={"ckeditor5/src/core.js":(e,t,i)=>{e.exports=i("dll-reference CKEditor5.dll")("./src/core.js")},"ckeditor5/src/typing.js":(e,t,i)=>{e.exports=i("dll-reference CKEditor5.dll")("./src/typing.js")},"ckeditor5/src/ui.js":(e,t,i)=>{e.exports=i("dll-reference CKEditor5.dll")("./src/ui.js")},"ckeditor5/src/utils.js":(e,t,i)=>{e.exports=i("dll-reference CKEditor5.dll")("./src/utils.js")},"ckeditor5/src/widget.js":(e,t,i)=>{e.exports=i("dll-reference CKEditor5.dll")("./src/widget.js")},"dll-reference CKEditor5.dll":e=>{"use strict";e.exports=CKEditor5.dll}},t={};function i(n){var s=t[n];if(void 0!==s)return s.exports;var l=t[n]={exports:{}};return e[n](l,l.exports,i),l.exports}i.d=(e,t)=>{for(var n in t)i.o(t,n)&&!i.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},i.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t);var n={};return(()=>{"use strict";i.d(n,{default:()=>w});var e=i("ckeditor5/src/core.js"),t=i("ckeditor5/src/widget.js"),s=i("ckeditor5/src/typing.js");const l=(e,t)=>{let i;if("/"===e||""===e)return!1;try{i=new URL(e)}catch(t){if(i=new URL(`https://${e}`),!/https?:\/\/(?:www\.)?[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}/.test(i))return!1}const n=i.hostname;return!t.some((e=>e.startsWith("*.")&&n.endsWith(e.slice(2))||e===n))},o=e=>{try{const t=new URL(e);return("tel:"===t.protocol||"mailto:"===t.protocol)&&t.protocol.replace(":","")}catch(e){return!1}},r={linkIcon:{label:Drupal.t("Icon",{},{context:"CKEditor5 Helfi Link plugin"}),machineName:"icon",selectListOptions:{},type:"select",group:"advanced",isVisible:!1,viewAttribute:"data-hds-icon-start"},linkVariant:{label:Drupal.t("Design"),machineName:"variant",selectListOptions:{link:Drupal.t("Normal link",{},{context:"CKEditor5 Helfi Link plugin"}),primary:Drupal.t("Button primary"),secondary:Drupal.t("Button secondary"),supplementary:Drupal.t("Button supplementary")},type:"select",group:"advanced",isVisible:!0,viewAttribute:"data-hds-variant"},linkButton:{machineName:"data-hds-component",type:"static",viewAttribute:"data-hds-component"},linkProtocol:{label:Drupal.t("Protocol",{},{context:"CKEditor5 Helfi Link plugin"}),machineName:"protocol",selectListOptions:{https:"https://",tel:"tel:",mailto:"mailto:"},type:"select",group:"helper",viewAttribute:"data-protocol",isVisible:!0},linkNewWindowConfirm:{label:Drupal.t("The link meets the accessibility requirements",{},{context:"CKEditor5 Helfi Link plugin"}),description:Drupal.t('I have made sure that the description of this link clearly states that it will open in a new tab. See WCAG 3.2.5 accessibility requirement (the link opens in a new tab).',{"@wcag-techniques":"https://www.w3.org/WAI/WCAG21/Techniques/general/G200.html"},{context:"CKEditor5 Helfi Link plugin"}),machineName:"link-new-window-confirm",viewAttribute:{target:"_blank"},type:"checkbox",group:"advanced",isVisible:!1},linkNewWindow:{label:Drupal.t("Open in new window/tab",{},{context:"CKEditor5 Helfi Link plugin"}),machineName:"link-new-window",type:"checkbox",group:"advanced",isVisible:!0},linkIsExternal:{machineName:"data-is-external",type:"static",viewAttribute:"data-is-external"}};class a extends e.Plugin{static get requires(){return[t.Widget]}static get pluginName(){return"HelfiLinkEditing"}init(){Object.keys(r).forEach((e=>{r[e].machineName&&(this._convertAttribute(e,r[e].viewAttribute),this._removeAttributeOnUnlinkCommandExecute(e),this._refreshAttributeValue(e))})),this._defineHelfiButtonConverters(),this._trimHref(),this._addAttributeOnLinkCommandExecute(Object.keys(r))}_trimHref(){const{editor:e}=this;e.conversion.for("upcast").elementToAttribute({view:"a",model:{key:"linkHref",value:e=>{if(!e.hasAttribute("href"))return null;const t=e.getAttribute("href");return t?t.trim().replace(/^%20+/,"").replace(/%20+$/,"").trim():null}},converterPriority:"highest"})}_convertAttribute(e,t){const{editor:i}=this;if(t)if(i.model.schema.extend("$text",{allowAttributes:e}),i.conversion.for("downcast").attributeToElement({model:e,view:(e,{writer:i})=>{const n={};e&&"object"==typeof t?n[Object.keys(t)]=t[Object.keys(t)]:n[t]=e;const s=i.createAttributeElement("a",n,{priority:5});return i.setCustomProperty("link",!0,s),s}}),"object"==typeof t){const n=Object.keys(t)[0],s=t[Object.keys(t)];i.conversion.for("upcast").attributeToAttribute({view:{name:"a",key:n,value:s},model:{key:e,value:e=>!(!e.hasAttribute(n)||e.getAttribute(n)!==s)}})}else"linkIsExternal"===e||"linkProtocol"===e?i.conversion.for("upcast").elementToAttribute({view:"a",model:{key:e,value:t=>{if(!t.hasAttribute("href"))return null;const i=t.getAttribute("href"),{whiteListedDomains:n}=this.editor.config.get("link");if(!n||!i||i.startsWith("#"))return null;const s=l(i,n),r=o(i);return r&&"linkProtocol"===e?r:!(!s||"linkIsExternal"!==e)||null}},converterPriority:"high"}):i.conversion.for("upcast").elementToAttribute({view:{name:"a",attributes:{[t]:!0}},model:{key:e,value:e=>e.getAttribute(t)}})}_removeAttributeOnUnlinkCommandExecute(e){const{editor:t}=this,{model:i}=this.editor,{selection:n}=i.document,l=t.commands.get("unlink");let o=!1;l.on("execute",(l=>{o||(l.stop(),i.change((()=>{o=!0,t.execute("unlink"),o=!1,i.change((t=>{let l;l=n.isCollapsed?[(0,s.findAttributeRange)(n.getFirstPosition(),e,n.getAttribute(e),i)]:i.schema.getValidRanges(n.getRanges(),e),Array.isArray(l)&&l.forEach((i=>t.removeAttribute(e,i)))}))})))}),{priority:"high"})}_refreshAttributeValue(e){const{editor:t}=this,{model:i}=this.editor,{selection:n}=i.document,s=t.commands.get("link");s.set(e,null),i.document.on("change",(()=>{s[e]=n.getAttribute(e)}))}_defineHelfiButtonConverters(){const{editor:e}=this;e.model.schema.isRegistered("tableCell")&&e.model.schema.extend("tableCell",{allowContentOf:"$block"});const t=e=>{const t=e.split(" "),i=t.find((e=>e.startsWith("hds-button--"))),n=t.find((e=>e.endsWith("hds-button")));return i?i.replace("hds-button--",""):n?"primary":null};e.conversion.for("upcast").elementToElement({view:{name:"a"},model:e=>{const t=Array.from(e.getChildren()).find((e=>"span"===e.name&&e.hasClass("hds-button__label")));if(t){const i=Array.from(e.getChildren()),n=i.length;n>0&&e._removeChildren(0,n),i.forEach((t=>{if("span"===t.name&&t.hasClass("hel-icon")){const i=(e=>{let t=!1,i=e.next();for(;!i.done;){const n=i.value;if(n&&n.startsWith("hel-icon--")){t=n.replace("hel-icon--","");break}i=e.next()}return t})(t.getClassNames());i&&e._setAttribute("data-hds-icon-start",i)}})),Array.from(t.getChildren()).forEach((t=>{e._appendChild(t)}))}const i=Array.from(e.getChildren()).find((e=>!(!e.name||"span"!==e.name)&&(!e.getAttribute("dir")&&!e.getAttribute("lang")&&e)));return i&&(e._removeChildren(i.index,1),Array.from(i.getChildren()).forEach((t=>{e._appendChild(t)}))),e.hasAttribute("data-protocol")&&e.getAttribute("data-protocol").startsWith("http")&&e._removeAttribute("data-protocol"),e},converterPriority:"highest"}),e.conversion.for("upcast").attributeToAttribute({view:{name:"a",key:"data-design"},model:{key:"linkVariant",value:e=>{let i;return e.hasClass("hds-button")&&(i=t([...e._classes].join(" ")),i||(i=t(e.getAttribute("data-design")))),i&&"primary"===i&&(i=null),i}}}),e.conversion.for("upcast").attributeToAttribute({view:{name:"a",key:"data-design"},model:{key:"linkButton",value:e=>{let i;return e.hasClass("hds-button")&&(i=t([...e._classes].join(" ")),i||(i=t(e.getAttribute("data-design")))),!!i&&"button"}}}),e.conversion.for("upcast").attributeToAttribute({view:{name:"a",key:"class",value:"hds-button"},model:{key:"linkButton",value:"button"}}),e.conversion.for("upcast").attributeToAttribute({view:{name:"a",key:"data-protocol"},model:{key:"linkProtocol",value:e=>{return"https"!==(t=e.getAttribute("data-protocol"))&&"http"!==t&&t;var t}},converterPriority:"highest"}),e.conversion.for("upcast").attributeToAttribute({view:{name:"a",key:"data-selected-icon"},model:{key:"linkIcon"}})}_addAttributeOnLinkCommandExecute(e){const{editor:t}=this,i=t.commands.get("link");let n=!1;i.on("execute",((i,s)=>{if(s.length<3)return;if(n)return void(n=!1);i.stop(),n=!0;const l=s[s.length-1],{model:r}=t,{selection:a}=r.document,c=s[0];let d=c;if(c){d=c.trim().replace(/^%20+/,"").replace(/%20+$/,"").trim();const e=o(d);e&&"tel"===e&&(d=d.replace(/[\s()-]/g,"")),s[0]=d}try{r.change((i=>{t.execute("link",...s),e.forEach((e=>{if(a.isCollapsed){const t=e=>{const t=e.textNode||e.nodeBefore;if(!t){const t=i.createRange(e);return i.setSelection(t),t}return i.createRangeOn(t)};l[e]?i.setAttribute(e,l[e],t(a.getFirstPosition())):i.removeAttribute(e,t(a.getFirstPosition())),i.removeSelectionAttribute(e)}else{const t=r.schema.getValidRanges(a.getRanges(),e);let n=t.next();for(;!n.done;){const s=n.value;l[e]?i.setAttribute(e,l[e],s):i.removeAttribute(e,s),n=t.next()}}})),n=!1}))}catch(e){i.stop()}}),{priority:"high"})}}var c=i("ckeditor5/src/ui.js"),d=i("ckeditor5/src/utils.js");class h extends c.View{constructor(e){super(e);const t=this.bindTemplate;this.set("class"),this.set("isVisible",!0),this.set("isChecked",!1),this.set("label"),this.set("description"),this.set("id",null),this.set("tabindex",-1),this.children=this.createCollection(),this.labelView=this._createLabelView(),this.checkboxInputView=this._createCheckboxInputView(),this.checkboxSpanToggle=this._createCheckboxSpanToggleView(),this.bind("isVisible").to(this,"updateVisibility"),this.bind("isChecked").to(this,"updateChecked"),this.setTemplate({tag:"div",attributes:{class:["form-type--checkbox","helfi-link-checkbox",t.if("isVisible","is-hidden",(e=>!e)),t.to("class")]},on:{keydown:t.to((e=>{e.target===this.element&&e.keyCode===(0,d.getCode)("space")&&(this.isChecked=!this.isChecked)}))},children:this.children})}render(){super.render(),this.children.add(this.checkboxInputView),this.children.add(this.checkboxSpanToggle),this.children.add(this.labelView)}focus(){this.element.focus()}_createCheckboxInputView(){const e=new c.View,t=this.bindTemplate;return e.setTemplate({tag:"input",attributes:{type:"checkbox",id:t.to("id"),checked:t.if("isChecked")},on:{change:t.to((e=>{this.isChecked=e.target.checked}))}}),e}_createCheckboxSpanToggleView(){const e=new c.View,t=this.bindTemplate;return e.setTemplate({tag:"span",attributes:{class:["checkbox-toggle"],id:t.to("id")},children:[{tag:"span",attributes:{class:["checkbox-toggle__inner"]}}]}),e}_createLabelView(){const e=new c.View;return e.setTemplate({tag:"label",attributes:{for:this.bindTemplate.to("id")},children:[{text:this.bindTemplate.to("label")}]}),e}updateVisibility(e){e?this.element.classList.remove("is-hidden"):this.element.classList.add("is-hidden")}updateChecked(e){e!==this.isChecked&&this.checkboxInputView?.element?.click()}}class u extends c.View{constructor(e,t){super(e.locale),this.options=t,this.tomSelect=!1,this.linkCommandConfig=e.config.get("link"),this.loadedIcons=this.linkCommandConfig?.loadedIcons,this.set("isVisible",!1),this.bind("isVisible").to(this,"updateVisibility");const i=this.bindTemplate;this.set("isOpen",!1),this.set("label"),this.set("id",null),this.setTemplate({tag:"select",attributes:{id:i.to("id"),class:["ck-helfi-link-select-list"],"data-placeholder":this.options.label,autocomplete:"off"},on:{keydown:i.to((e=>{e.target===this.element&&e.keyCode===(0,d.getCode)("space")&&(this.isOpen=!this.isOpen)}))}})}updateVisibility(e){e?(this.tomSelect?.wrapper?.classList.remove("is-hidden"),this.element.classList.remove("is-hidden")):(this.tomSelect?.wrapper?.classList.add("is-hidden"),this.element.classList.add("is-hidden"))}render(){super.render()}focus(){this.element.focus()}selectListDefaultOptions(){return{valueField:"option",labelField:"name",searchField:"title",maxItems:1,placeholder:this.options.label,create:!1}}}class m extends u{renderTomSelect(e,t){if(!this.tomSelect&&e){const e=super.selectListDefaultOptions(),i=(e,t)=>`\n \n ${t(e.title)}\n \n `,n={...e,options:Object.keys(t).map((e=>({option:e,title:t[e]}))),render:{option:(e,t)=>i(e,t),item:(e,t)=>i(e,t)}};this.tomSelect=new TomSelect(this.element,n)}}}class p extends c.View{constructor(e,t){super(e),this.advancedChildren=t;const i=this.bindTemplate;this.set("isOpen",!1),this.set("label"),this.set("id",null),this.children=this.createCollection(),this.detailsSummary=this._createDetailsSummary(),this.setTemplate({tag:"details",attributes:{id:i.to("id"),class:["ck-helfi-link-details",i.if("isOpen","ck-is-open",(e=>e))],open:i.if("isOpen")},on:{keydown:i.to((e=>{e.target===this.element&&e.keyCode===(0,d.getCode)("space")&&(this.isOpen=!this.isOpen)}))},children:this.children})}render(){super.render(),this.children.add(this.detailsSummary),this.children.addMany(this.advancedChildren)}focus(){this.element.focus()}_createDetailsSummary(){const e=new c.View;return e.setTemplate({tag:"summary",attributes:{role:"button",class:["ck-helfi-link-details__summary"],tabindex:0},children:[{text:this.bindTemplate.to("label")}]}),e}}class b extends u{renderTomSelect(e,t){if(!this.tomSelect&&e){const e=super.selectListDefaultOptions(),i=(e,t)=>`\n \n ${t(e.title)}\n \n `,n={...e,plugins:{dropdown_input:{},remove_button:{title:"Remove this item"}},options:Object.keys(t).map((e=>({option:e,title:t[e]}))),render:{option:(e,t)=>i(e,t),item:(e,t)=>i(e,t)}};this.tomSelect=new TomSelect(this.element,n)}}}class k extends u{renderTomSelect(e){if(!this.tomSelect&&e){const e=super.selectListDefaultOptions(),t=(e,t)=>`\n \n \n ${t(e.name)}\n \n `,i={...e,plugins:{dropdown_input:{},remove_button:{title:"Remove this item"}},valueField:"icon",searchField:["name"],options:Object.keys(this.loadedIcons).map((e=>({icon:e,name:this.loadedIcons[e]}))),render:{option:(e,i)=>t(e,i),item:(e,i)=>t(e,i)}};this.tomSelect=new TomSelect(this.element,i)}}}class f extends e.Plugin{constructor(e){super(e),this.editor=e,this.advancedChildren=new d.Collection,this.formElements=r,this.helfiContextualBalloonInitialized=!1}init(){this.editor.plugins.get("LinkUI")._createViews&&this.editor.plugins.get("LinkUI")._createViews(),this._addContextualBalloonClass(),this.editor.plugins.get("ContextualBalloon").on("change:visibleView",((e,t,i,n)=>{const s=this.editor.plugins.get("LinkUI").formView;if(i===n||i!==s||!this.helfiContextualBalloonInitialized)return;const l=Object.keys(this.formElements).reverse();l.forEach((e=>{if(!this.formElements[e].machineName)return;const t=this._createFormField(e,s);this.formElements[e].group&&"advanced"===this.formElements[e].group&&void 0!==t&&this.advancedChildren.add(t)})),this._createAdvancedSettingsAccordion(s),l.forEach((e=>{this.formElements[e].machineName&&this._handleDataLoadingIntoFormField(e,s)})),s.urlInputView.infoText||(s.urlInputView.infoText=Drupal.t("Start typing to find content.",{},{context:"CKEditor5 Helfi Link plugin"})),this._handleCheckboxes(s),this._handleFormFieldSubmit(l)}))}_addContextualBalloonClass(){const{editor:e}=this;e.plugins.get("ContextualBalloon").on("set:visibleView",((t,i,n,s)=>{const l=e.plugins.get("LinkUI").formView;if(n===s||n!==l)return;const o=this.editor.plugins.get("ContextualBalloon");o.hasView(l)&&!o.view.element.classList.contains("helfi-contextual-balloon")&&(l.template.attributes.class.push("helfi-link-form"),l.template.attributes.class.push("ck-reset_all-excluded"),o.remove(n),o.add({view:l,position:o.getPositionOptions(),balloonClassName:"helfi-contextual-balloon",withArrow:!1}),this.helfiContextualBalloonInitialized=!0)}))}_createSelectList(e,t,i){const{editor:n}=this;let s={};switch(e){case"linkProtocol":s=new m(n,t),i.urlInputView.on("change:isEmpty",((e,t,i)=>{s.updateVisibility(i)}));break;case"linkVariant":s=new b(n,t);break;case"linkIcon":s=new k(n,t),i.linkVariant.on("change:isEmpty",((e,t,i)=>{s.updateVisibility(i)}))}return s.set({isVisible:t.isVisible,id:t.machineName,label:t.label}),s}_createAdvancedSettingsAccordion(e){if(e.advancedSettings)return e.advancedSettings.element.open=!1,e.advancedSettings.detailsSummary.element.ariaExpanded=!1,e.advancedSettings.detailsSummary.element.ariaPressed=!1,e.advancedSettings;const{editor:t}=this,i=new p(t.locale,this.advancedChildren);return i.set({label:Drupal.t("Advanced settings",{},{context:"CKEditor5 Helfi Link plugin"}),id:"advanced-settings",isOpen:!1}),e.children.add(i,2),e.urlInputView.errorText&&(e.urlInputView.errorText=""),e.advancedSettings=i,e.advancedSettings}_createCheckbox(e){const t=new h(this.editor.locale),i=this.formElements[e];return t.set({isVisible:i.isVisible,tooltip:!0,class:"ck-find-checkboxes__box",id:i.machineName,label:i.label}),t}_createFormField(e,t){const{editor:i}=this,n=this.formElements[e],s=i.commands.get("link");if(!t[e]){let l={};switch(n.type){case"select":l=this._createSelectList(e,n,t);break;case"checkbox":l=this._createCheckbox(e);break;case"static":l=!1;break;default:l=new c.LabeledFieldView(i.locale,c.createLabeledInputText)}if(!l)return;return l.machineName=e,l.class=`helfi-link--${n.machineName}`,l.label=n.label,n.description&&(l.infoText=n.description),n.group&&"advanced"===n.group||t.children.add(l,"select"===n.type?0:1),t._focusables.add(l,1),t.focusTracker.add(l.element),t[e]=l,"checkbox"===n.type&&t[e].checkboxInputView.bind("isChecked").to(s,e),"input"===n.type&&t[e].fieldView.bind("value").to(s,e),"linkProtocol"!==e||t.urlInputView.isEmpty||t[e].updateVisibility(!1),t[e]}}_handleDataLoadingIntoFormField(e,t){const{editor:i}=this,n=i.commands.get("link"),s=this.formElements[e];if(void 0!==t[e])switch(s.type){case"static":return;case"checkbox":{const i=!!n.linkNewWindowConfirm;t[e].updateChecked(i),t.linkNewWindowConfirm&&t.linkNewWindowConfirm.updateVisibility(i);break}case"select":t[e].renderTomSelect(t[e].element,s?.selectListOptions),"linkIcon"===e&&t[e].tomSelect.on("initialize",(()=>{t[e].updateVisibility(!1)})),t[e].tomSelect.clear(),n[e]&&t[e].tomSelect.addItem(n[e],!0),"linkProtocol"===e&&t[e].tomSelect.on("item_add",(i=>{t.urlInputView.isEmpty&&(t.urlInputView.fieldView.value=s.selectListOptions[i],t.urlInputView.focus(),t[e].tomSelect.clear())})),"linkVariant"===e&&("button"!==n.linkButton||n[e]&&"primary"!==n[e]||t[e].tomSelect.addItem("primary",!0),n.linkVariant||"button"===n.linkButton||t?.linkIcon.updateVisibility(!1),t[e].tomSelect.on("item_remove",(()=>{t?.linkIcon.tomSelect.clear(),t?.linkIcon.updateVisibility(!1)})),t[e].tomSelect.on("item_add",(e=>{t?.linkIcon.updateVisibility("link"!==e),"link"===e&&t?.linkIcon.tomSelect.clear()})));break;default:t[e].fieldView.element.value=n[e]||""}}_handleCheckboxes(e){if(this.formElements.linkNewWindowConfirm&&this.formElements.linkNewWindow&&e&&e.linkNewWindow&&e.linkNewWindowConfirm&&e.linkNewWindowConfirm.element){if(!e.linkNewWindowConfirm.element.querySelector(".helfi-link-form__field_description")){const t=document.createElement("div");t.innerHTML=this.formElements.linkNewWindowConfirm.description,t.classList.add("helfi-link-form__field_description"),e.linkNewWindowConfirm.element.appendChild(t)}e.linkNewWindow.on("change:isChecked",((t,i,n)=>{e?.linkNewWindowConfirm.updateChecked(!1),e?.linkNewWindowConfirm.updateVisibility(n)}))}}_handleFormFieldSubmit(e){const{editor:t}=this,{selection:i}=t.model.document,n=t.plugins.get("LinkUI").formView,s=t.commands.get("link");this.stopListening(n,"submit"),this.listenTo(n,"submit",(t=>{n.urlInputView?.fieldView?.element?.value||(n.urlInputView.errorText=Drupal.t("The link URL field cannot be empty.",{},{context:"CKEditor5 Helfi Link plugin"}),t.stop());const{whiteListedDomains:r}=this.editor.config.get("link"),a=n.urlInputView?.fieldView?.element?.value,c=e.reduce(((e,t)=>{switch(t){case"linkVariant":{const i=n?.[t]?.tomSelect.getValue();if(!i||"link"===i)return e;if("primary"===i)return e.linkButton="button",e;e[t]=i,e.linkButton="button";break}case"linkIcon":e[t]=n?.[t]?.tomSelect.getValue();break;case"linkProtocol":if(!r||!a||a.startsWith("#"))break;o(a)&&(e[t]=o(a));break;case"linkIsExternal":if(!r||!a||a.startsWith("#"))break;if(!o(a)&&l(a,r)){e[t]=l(a,r);break}break;default:e[t]=n?.[t]?.fieldView?.element?.value??""}return"checkbox"===this.formElements[t].type&&(e[t]=n?.[t]?.checkboxInputView?.element?.checked),e}),{});i.isCollapsed&&!n.urlInputView?.fieldView?.element?.value&&c.linkId&&(n.urlInputView.errorText=Drupal.t("When there is no selection, the link URL must be provided. To add a link without a URL, first select text in the editor and then proceed with adding the link.",{},{context:"CKEditor5 Helfi Link plugin"}),t.stop()),c.linkNewWindowConfirm&&c.linkNewWindow||(c.linkNewWindowConfirm=!1,c.linkNewWindow=!1,n.linkNewWindowConfirm.checkboxInputView.element.checked&&n.linkNewWindowConfirm.checkboxInputView.element.click(),n.linkNewWindow.checkboxInputView.element.checked&&n.linkNewWindow.checkboxInputView.element.click()),s.once("execute",((e,t)=>{if(t.length<3)t.push(c);else{if(3!==t.length)throw Error("The link command has more than 3 arguments.");Object.assign(t[2],c)}}),{priority:"highest"})}),{priority:"high"})}}class g extends e.Plugin{static get requires(){return[a,f]}}const w={HelfiLink:g}})(),n=n.default})())); \ No newline at end of file From 9f2d667164974d1805c8300e960ec89131055650 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20Kalij=C3=A4rvi?= Date: Thu, 19 Dec 2024 08:11:49 +0200 Subject: [PATCH 3/6] UHF-11186: Fixed security issues. --- modules/helfi_ckeditor/package-lock.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/helfi_ckeditor/package-lock.json b/modules/helfi_ckeditor/package-lock.json index d2c2382db..5b6f0501f 100644 --- a/modules/helfi_ckeditor/package-lock.json +++ b/modules/helfi_ckeditor/package-lock.json @@ -7388,9 +7388,9 @@ "dev": true }, "node_modules/nanoid": { - "version": "3.3.7", - "resolved": "https://registry.npmjs.org/nanoid/-/nanoid-3.3.7.tgz", - "integrity": "sha512-eSRppjcPIatRIMC1U6UngP8XFcz8MQWGQdt1MTBQ7NaAmvXDfvNxbvWV3x2y6CdEUciCSsDHDQZbhYaB8QEo2g==", + "version": "3.3.8", + "resolved": "https://registry.npmjs.org/nanoid/-/nanoid-3.3.8.tgz", + "integrity": "sha512-WNLf5Sd8oZxOm+TzppcYk8gVOgP+l58xNy58D0nbUnOxOWRWvlcCV4kUF7ltmI6PsrLl/BgKEyS4mqsGChFN0w==", "dev": true, "funding": [ { From 0a83bdd7c1e202fd4d2847849dc475a763c19c08 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20Kalij=C3=A4rvi?= Date: Thu, 19 Dec 2024 08:29:12 +0200 Subject: [PATCH 4/6] UHF-11186: Reverted the conflict rule for Drupal core. --- composer.json | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/composer.json b/composer.json index 2bb8e388c..57af15198 100644 --- a/composer.json +++ b/composer.json @@ -73,9 +73,8 @@ "dg/bypass-finals": "^1.0" }, "conflict": { - "drupal/core": ">=10.4.0", - "drupal/core-composer-scaffold": ">=10.4.0", - "drupal/core-dev": ">=10.4.0", + "drupal/core": "<10.3.10", + "drupal/core-composer-scaffold": "<10.3", "drupal/stage_file_proxy": "<2.1.5", "drupal/ctools": "<3.11 || ^4.0.1", "drupal/gin_toolbar": ">1.0.0-rc6", From 43f9d63a03058733a3a88e5e3f4a54b2e95421e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20Kalij=C3=A4rvi?= Date: Thu, 19 Dec 2024 08:43:05 +0200 Subject: [PATCH 5/6] UHF-11186: Removed library asset ordering patch. --- composer.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 57af15198..dc05a20fa 100644 --- a/composer.json +++ b/composer.json @@ -96,8 +96,7 @@ "[#UHF-7008] Admin toolbar and contextual links should always be rendered in the admin language (https://www.drupal.org/project/drupal/issues/2313309)": "https://www.drupal.org/files/issues/2023-12-19/2313309-179.patch", "[#UHF-9388] Process configuration translation files for custom modules (https://www.drupal.org/i/2845437)": "https://raw.githubusercontent.com/City-of-Helsinki/drupal-helfi-platform-config/fd68277191b8f8ec290e53b5fbbae699b2260384/patches/drupal-2845437-process-custom-module-translation-config-10.3.x.patch", "[#UHF-9690] Allow updating lists when switching from allowed values to allowed values function (https://www.drupal.org/i/2873353)": "https://www.drupal.org/files/issues/2021-05-18/allow-allowed-values-function-update-D9-2873353_1.patch", - "[#UHF-9952, #UHF-9980] Duplicate
tags (https://www.drupal.org/i/3083786)": "https://www.drupal.org/files/issues/2024-08-08/3083786--mr-8066--10-3-backport.patch", - "[#UHF-10716] Ensure consistent ordering when calculating library asset order (https://www.drupal.org/i/3467860)": "https://raw.githubusercontent.com/City-of-Helsinki/drupal-helfi-platform-config/955e2fc9493c6574ab070187b8a5a8634da7daab/patches/drupal-3467860-optimized-js-assets-mismatch.patch" + "[#UHF-9952, #UHF-9980] Duplicate
tags (https://www.drupal.org/i/3083786)": "https://www.drupal.org/files/issues/2024-08-08/3083786--mr-8066--10-3-backport.patch" }, "drupal/default_content": { "https://www.drupal.org/project/default_content/issues/2640734#comment-14638943": "https://raw.githubusercontent.com/City-of-Helsinki/drupal-helfi-platform-config/main/patches/default_content_2.0.0-alpha2-2640734_manual_imports-e164a354.patch" From c39e1d9031397f709abe1419fcdd0a971eae3e68 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20Kalij=C3=A4rvi?= Date: Thu, 19 Dec 2024 08:47:14 +0200 Subject: [PATCH 6/6] UHF-11186: Require Drupal 10.4 --- composer.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index dc05a20fa..d59fc48f9 100644 --- a/composer.json +++ b/composer.json @@ -73,8 +73,8 @@ "dg/bypass-finals": "^1.0" }, "conflict": { - "drupal/core": "<10.3.10", - "drupal/core-composer-scaffold": "<10.3", + "drupal/core": "<10.4", + "drupal/core-composer-scaffold": "<10.4", "drupal/stage_file_proxy": "<2.1.5", "drupal/ctools": "<3.11 || ^4.0.1", "drupal/gin_toolbar": ">1.0.0-rc6",