UNPKG

@northernco/ckeditor5-anchor-drupal

Version:

Drupal CKEditor 5 integration

61 lines 31.8 kB
!function(t){const e=t.en=t.en||{};e.dictionary=Object.assign(e.dictionary||{},{Anchor:"Anchor","Anchor name":"Anchor name","Edit anchor":"Edit anchor",Unanchor:"Unanchor"})}(window.CKEDITOR_TRANSLATIONS||(window.CKEDITOR_TRANSLATIONS={})),(()=>{var t={945:(t,e,n)=>{t.exports=n(79)("./src/clipboard.js")},704:(t,e,n)=>{t.exports=n(79)("./src/core.js")},492:(t,e,n)=>{t.exports=n(79)("./src/engine.js")},181:(t,e,n)=>{t.exports=n(79)("./src/typing.js")},273:(t,e,n)=>{t.exports=n(79)("./src/ui.js")},209:(t,e,n)=>{t.exports=n(79)("./src/utils.js")},79:t=>{"use strict";t.exports=CKEditor5.dll}},e={};function n(o){var i=e[o];if(void 0!==i)return i.exports;var r=e[o]={exports:{}};return t[o](r,r.exports,n),r.exports}n.d=(t,e)=>{for(var o in e)n.o(e,o)&&!n.o(t,o)&&Object.defineProperty(t,o,{enumerable:!0,get:e[o]})},n.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),n.r=t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})};var o={};(()=>{"use strict";n.r(o),n.d(o,{default:()=>At});var t=n(704),e=n(492),i=n(181),r=n(945),s=n(209); /** * @license Copyright (c) 2003-2020, CKSource - Frederico Knabben. All rights reserved. * For licensing, see LICENSE.md. */ class a{constructor(){this._definitions=new Set}get length(){return this._definitions.size}add(t){Array.isArray(t)?t.forEach(t=>this._definitions.add(t)):this._definitions.add(t)}getDispatcher(){return t=>{t.on("attribute:anchorId",(t,e,n)=>{if(!n.consumable.test(e.item,"attribute:anchorId"))return;const o=n.writer,i=o.document.selection;for(const t of this._definitions){const r=o.createAttributeElement("a",t.attributes,{priority:5});o.setCustomProperty("anchor",!0,r),t.callback(e.attributeNewValue)?e.item.is("selection")?o.wrap(i.getFirstRange(),r):o.wrap(n.mapper.toViewRange(e.range),r):o.unwrap(n.mapper.toViewRange(e.range),r)}},{priority:"high"})}}getDispatcherForAnchoredImage(){return t=>{t.on("attribute:anchorId:image",(t,e,n)=>{const o=n.mapper.toViewElement(e.item),i=Array.from(o.getChildren()).find(t=>"a"===t.name);for(const t of this._definitions){const o=(0,s.toMap)(t.attributes);if(t.callback(e.attributeNewValue))for(const[t,e]of o)"class"===t?n.writer.addClass(e,i):n.writer.setAttribute(t,e,i);else for(const[t,e]of o)"class"===t?n.writer.removeClass(e,i):n.writer.removeAttribute(t,i)}})}}}const c=function(t,e,n){var o=-1,i=t.length;e<0&&(e=-e>i?0:i+e),(n=n>i?i:n)<0&&(n+=i),i=e>n?0:n-e>>>0,e>>>=0;for(var r=Array(i);++o<i;)r[o]=t[o+e];return r};const l=function(t,e,n){var o=t.length;return n=void 0===n?o:n,!e&&n>=o?t:c(t,e,n)};var h=RegExp("[\\u200d\\ud800-\\udfff\\u0300-\\u036f\\ufe20-\\ufe2f\\u20d0-\\u20ff\\ufe0e\\ufe0f]");const u=function(t){return h.test(t)};const d=function(t){return t.split("")};var f="[\\ud800-\\udfff]",m="[\\u0300-\\u036f\\ufe20-\\ufe2f\\u20d0-\\u20ff]",g="\\ud83c[\\udffb-\\udfff]",b="[^\\ud800-\\udfff]",w="(?:\\ud83c[\\udde6-\\uddff]){2}",p="[\\ud800-\\udbff][\\udc00-\\udfff]",v="(?:"+m+"|"+g+")"+"?",_="[\\ufe0e\\ufe0f]?"+v+("(?:\\u200d(?:"+[b,w,p].join("|")+")[\\ufe0e\\ufe0f]?"+v+")*"),A="(?:"+[b+m+"?",m,w,p,f].join("|")+")",k=RegExp(g+"(?="+g+")|"+A+_,"g");const V=function(t){return t.match(k)||[]};const y=function(t){return u(t)?V(t):d(t)};const I="object"==typeof global&&global&&global.Object===Object&&global;var T="object"==typeof self&&self&&self.Object===Object&&self;const S=(I||T||Function("return this")()).Symbol;const x=function(t,e){for(var n=-1,o=null==t?0:t.length,i=Array(o);++n<o;)i[n]=e(t[n],n,t);return i};const E=Array.isArray;var C=Object.prototype,B=C.hasOwnProperty,D=C.toString,F=S?S.toStringTag:void 0;const P=function(t){var e=B.call(t,F),n=t[F];try{t[F]=void 0;var o=!0}catch(t){}var i=D.call(t);return o&&(e?t[F]=n:delete t[F]),i};var O=Object.prototype.toString;const R=function(t){return O.call(t)};var U=S?S.toStringTag:void 0;const j=function(t){return null==t?void 0===t?"[object Undefined]":"[object Null]":U&&U in Object(t)?P(t):R(t)};const M=function(t){return null!=t&&"object"==typeof t};const N=function(t){return"symbol"==typeof t||M(t)&&"[object Symbol]"==j(t)};var z=S?S.prototype:void 0,L=z?z.toString:void 0;const H=function t(e){if("string"==typeof e)return e;if(E(e))return x(e,t)+"";if(N(e))return L?L.call(e):"";var n=e+"";return"0"==n&&1/e==-1/0?"-0":n};const q=function(t){return null==t?"":H(t)};const K=function(t){return function(e){e=q(e);var n=u(e)?y(e):void 0,o=n?n[0]:e.charAt(0),i=n?l(n,1).join(""):e.slice(1);return o[t]()+i}}("toUpperCase"),$=/[\u0000-\u0020\u00A0\u1680\u180E\u2000-\u2029\u205f\u3000]/g,W=/^(?:(?:https?|ftps?|mailto):|[^a-z]|[a-z+.-]+(?:[^a-z+.:-]|$))/i,G=/^[\S]+@((?![-_])(?:[-\w\u00a1-\uffff]{0,63}[^-_]\.))+(?:[a-z\u00a1-\uffff]{2,})$/i,Y=/^((\w+:(\/{2,})?)|(\W))/i;function J(t,{writer:e}){const n=e.createAttributeElement("a",{id:t,name:t},{priority:5});return e.addClass("ck-anchor",n),e.setCustomProperty("anchor",!0,n),n}function Q(t){return function(t){return t.replace($,"").match(W)}(t=String(t))?t:"#"}function X(t,e){return!!t&&(t.is("element","image")&&e.checkAttribute("image","anchorId"))}function Z(t,e){const n=(o=t,G.test(o)?"mailto:":e);var o;const i=!!n&&!Y.test(t);return t&&i?n+t:t} /** * @license Copyright (c) 2003-2020, CKSource - Frederico Knabben. All rights reserved. * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license */ class tt extends t.Command{constructor(t){super(t),this.manualDecorators=new s.Collection,this.automaticDecorators=new a}restoreManualDecoratorStates(){for(const t of this.manualDecorators)t.value=this._getDecoratorStateFromModel(t.id)}refresh(){const t=this.editor.model,e=t.document,n=(0,s.first)(e.selection.getSelectedBlocks());X(n,t.schema)?(this.value=n.getAttribute("anchorId"),this.isEnabled=t.schema.checkAttribute(n,"anchorId")):(this.value=e.selection.getAttribute("anchorId"),this.isEnabled=t.schema.checkAttributeInSelection(e.selection,"anchorId"));for(const t of this.manualDecorators)t.value=this._getDecoratorStateFromModel(t.id)}execute(t,e={}){const n=this.editor.model,o=n.document.selection,r=[],a=[];for(const t in e)e[t]?r.push(t):a.push(t);n.change(e=>{if(o.isCollapsed){const c=o.getFirstPosition();if(o.hasAttribute("anchorId")){const s=(0,i.findAttributeRange)(c,"anchorId",o.getAttribute("anchorId"),n);e.setAttribute("anchorId",t,s),r.forEach(t=>{e.setAttribute(t,!0,s)}),a.forEach(t=>{e.removeAttribute(t,s)}),e.setSelection(e.createPositionAfter(s.end.nodeBefore))}else if(""!==t){const i=(0,s.toMap)(o.getAttributes());i.set("anchorId",t),r.forEach(t=>{i.set(t,!0)});const{end:a}=n.insertContent(e.createText(t,i),c);e.setSelection(a)}["anchorId",...r,...a].forEach(t=>{e.removeSelectionAttribute(t)})}else{const i=n.schema.getValidRanges(o.getRanges(),"anchorId"),s=[];for(const t of o.getSelectedBlocks())n.schema.checkAttribute(t,"anchorId")&&s.push(e.createRangeOn(t));const c=s.slice();for(const t of i)this._isRangeToUpdate(t,s)&&c.push(t);for(const n of c)e.setAttribute("anchorId",t,n),r.forEach(t=>{e.setAttribute(t,!0,n)}),a.forEach(t=>{e.removeAttribute(t,n)})}})}_getDecoratorStateFromModel(t){const e=this.editor.model,n=e.document,o=(0,s.first)(n.selection.getSelectedBlocks());return X(o,e.schema)?o.getAttribute(t):n.selection.getAttribute(t)}_isRangeToUpdate(t,e){for(const n of e)if(n.containsRange(t))return!1;return!0}} /** * @license Copyright (c) 2003-2020, CKSource - Frederico Knabben. All rights reserved. * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license */ class et extends t.Command{refresh(){const t=this.editor.model,e=t.document,n=(0,s.first)(e.selection.getSelectedBlocks());X(n,t.schema)?this.isEnabled=t.schema.checkAttribute(n,"anchorId"):this.isEnabled=t.schema.checkAttributeInSelection(e.selection,"anchorId")}execute(){const t=this.editor,e=this.editor.model,n=e.document.selection,o=t.commands.get("anchor");e.change(t=>{const r=n.isCollapsed?[(0,i.findAttributeRange)(n.getFirstPosition(),"anchorId",n.getAttribute("anchorId"),e)]:e.schema.getValidRanges(n.getRanges(),"anchorId");for(const e of r)if(t.removeAttribute("anchorId",e),o)for(const n of o.manualDecorators)t.removeAttribute(n.id,e)})}} /** * @license Copyright (c) 2003-2020, CKSource - Frederico Knabben. All rights reserved. * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license */ class nt{constructor({id:t,label:e,attributes:n,defaultValue:o}){this.id=t,this.set("value"),this.defaultValue=o,this.label=e,this.attributes=n}} /** * @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved. * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license */ function ot(t,e,n,o){return o.createRange(it(t,e,n,!0,o),it(t,e,n,!1,o))}function it(t,e,n,o,i){let r=t.textNode||(o?t.nodeBefore:t.nodeAfter),s=null;for(;r&&r.getAttribute(e)==n;)s=r,r=o?r.previousSibling:r.nextSibling;return s?i.createPositionAt(s,o?"before":"after"):t}(0,s.mix)(nt,s.ObservableMixin);Error;const rt= /** * @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved. * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license */ function(){try{return navigator.userAgent.toLowerCase()}catch(t){return""}}();st(rt),function(t){t.indexOf("windows")}(rt),function(t){t.match(/gecko\/\d+/)}(rt),function(t){t.indexOf(" applewebkit/")>-1&&t.indexOf("chrome")}(rt),function(t){!!t.match(/iphone|ipad/i)||st(t)&&navigator.maxTouchPoints}(rt),function(t){t.indexOf("android")}(rt),function(t){t.indexOf("chrome/")>-1&&t.indexOf("edge/")}(rt),function(){let t=!1;try{t=0==="ć".search(new RegExp("[\\p{L}]","u"))}catch(t){}}();function st(t){return t.indexOf("macintosh")>-1} /** * @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved. * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license */ const at=function(){const t={arrowleft:37,arrowup:38,arrowright:39,arrowdown:40,backspace:8,delete:46,enter:13,space:32,esc:27,tab:9,ctrl:1114112,shift:2228224,alt:4456448,cmd:8912896};for(let e=65;e<=90;e++){const n=String.fromCharCode(e);t[n.toLowerCase()]=e}for(let e=48;e<=57;e++)t[e-48]=e;for(let e=112;e<=123;e++)t["f"+(e-111)]=e;for(const e of"`-=[];',./\\")t[e]=e.charCodeAt(0);return t}();Object.fromEntries(Object.entries(at).map(([t,e])=>[e,t.charAt(0).toUpperCase()+t.slice(1)])); /** * @license Copyright (c) 2003-2020, CKSource - Frederico Knabben. All rights reserved. * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license */ const ct=/^(https?:)?\/\//;class lt extends t.Plugin{static get pluginName(){return"AnchorEditing"}static get requires(){return[i.TwoStepCaretMovement,i.Input,r.Clipboard]}constructor(t){super(t),t.config.define("anchor",{addTargetToExternalAnchors:!1})}init(){const t=this.editor;t.model.schema.extend("$text",{allowAttributes:"anchorId"}),t.conversion.for("dataDowncast").attributeToElement({model:"anchorId",view:J}),t.conversion.for("editingDowncast").attributeToElement({model:"anchorId",view:(t,e)=>J(Q(t),e)}),t.conversion.for("upcast").elementToAttribute({view:{name:"a",attributes:{id:!0}},model:{key:"anchorId",value:t=>t.getAttribute("id")}}),t.commands.add("anchor",new tt(t)),t.commands.add("unanchor",new et(t));const e=function(t,e){const n={};return e.forEach(t=>(t.label&&n[t.label]&&(t.label=n[t.label]),t)),e}(t.t,function(t){const e=[];if(t)for(const[n,o]of Object.entries(t)){const t=Object.assign({},o,{id:"anchor"+K(n)});e.push(t)}return e}(t.config.get("anchor.decorators")));this._enableAutomaticDecorators(e.filter(t=>"automatic"===t.mode)),this._enableManualDecorators(e.filter(t=>"manual"===t.mode));t.plugins.get(i.TwoStepCaretMovement).registerAttribute("anchorId"),(0,i.inlineHighlight)(t,"anchorId","a","ck-anchor_selected"),this._enableInsertContentSelectionAttributesFixer(),this._enableClickingAfterAnchor(),this._enableTypingOverAnchor(),this._handleDeleteContentAfterAnchor()}_enableAutomaticDecorators(t){const e=this.editor,n=e.commands.get("anchor").automaticDecorators;e.config.get("anchor.addTargetToExternalAnchors")&&n.add({id:"anchorIsExternal",mode:"automatic",callback:t=>ct.test(t),attributes:{target:"_blank",rel:"noopener noreferrer"}}),n.add(t),n.length&&e.conversion.for("downcast").add(n.getDispatcher())}_enableManualDecorators(t){if(!t.length)return;const e=this.editor,n=e.commands.get("anchor").manualDecorators;t.forEach(t=>{e.model.schema.extend("$text",{allowAttributes:t.id}),n.add(new nt(t)),e.conversion.for("downcast").attributeToElement({model:t.id,view:(e,{writer:o})=>{if(e){const e=n.get(t.id).attributes,i=o.createAttributeElement("a",e,{priority:5});return o.setCustomProperty("anchor",!0,i),i}}}),e.conversion.for("upcast").elementToAttribute({view:{name:"a",attributes:n.get(t.id).attributes},model:{key:t.id}})})}_enableInsertContentSelectionAttributesFixer(){const t=this.editor,e=t.model,n=e.document.selection,o=t.commands.get("anchor");this.listenTo(e,"insertContent",()=>{const t=n.anchor.nodeBefore,i=n.anchor.nodeAfter;n.hasAttribute("anchorId")&&t&&t.hasAttribute("anchorId")&&(i&&i.hasAttribute("anchorId")||e.change(t=>{ht(t,o.manualDecorators)}))},{priority:"low"})}_enableClickingAfterAnchor(){const t=this.editor,n=t.commands.get("anchor");t.editing.view.addObserver(e.MouseObserver);let o=!1;this.listenTo(t.editing.view.document,"mousedown",()=>{o=!0}),this.listenTo(t.editing.view.document,"selectionChange",()=>{if(!o)return;o=!1;const e=t.model.document.selection;if(!e.isCollapsed)return;if(!e.hasAttribute("anchorId"))return;const i=e.getFirstPosition(),r=ot(i,"anchorId",e.getAttribute("anchorId"),t.model);(i.isTouching(r.start)||i.isTouching(r.end))&&t.model.change(t=>{ht(t,n.manualDecorators)})})}_enableTypingOverAnchor(){const t=this.editor,e=t.editing.view;let n,o;this.listenTo(e.document,"delete",()=>{o=!0},{priority:"high"}),this.listenTo(t.model,"deleteContent",()=>{const e=t.model.document.selection;e.isCollapsed||(o?o=!1:ut(t)&&function(t){const e=t.document.selection,n=e.getFirstPosition(),o=e.getLastPosition(),i=n.nodeAfter;if(!i)return!1;if(!i.is("$text"))return!1;if(!i.hasAttribute("anchorId"))return!1;const r=o.textNode||o.nodeBefore;if(i===r)return!0;return ot(n,"anchorId",i.getAttribute("anchorId"),t).containsRange(t.createRange(n,o),!0)}(t.model)&&(n=e.getAttributes()))},{priority:"high"}),this.listenTo(t.model,"insertContent",(e,[i])=>{o=!1,ut(t)&&n&&(t.model.change(t=>{for(const[e,o]of n)t.setAttribute(e,o,i)}),n=null)},{priority:"high"})}_handleDeleteContentAfterAnchor(){const t=this.editor,e=t.model,n=e.document.selection,o=t.editing.view,i=t.commands.get("anchor");let r=!1,s=!1;this.listenTo(o.document,"delete",(t,e)=>{s=e.domEvent.keyCode===at.backspace},{priority:"high"}),this.listenTo(e,"deleteContent",()=>{r=!1;const t=n.getFirstPosition(),o=n.getAttribute("anchorId");if(!o)return;const i=ot(t,"anchorId",o,e);r=i.containsPosition(t)||i.end.isEqual(t)},{priority:"high"}),this.listenTo(e,"deleteContent",()=>{s&&(s=!1,r||t.model.enqueueChange(t=>{ht(t,i.manualDecorators)}))},{priority:"low"})}}function ht(t,e){t.removeSelectionAttribute("anchorId");for(const n of e)t.removeSelectionAttribute(n.id)}function ut(t){return t.model.change(t=>t.batch).isTyping}var dt=n(273); /** * @license Copyright (c) 2003-2020, CKSource - Frederico Knabben. All rights reserved. * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license */ class ft extends dt.View{constructor(t,e){super(t);const n=t.t;this.focusTracker=new s.FocusTracker,this.keystrokes=new s.KeystrokeHandler,this.urlInputView=this._createUrlInput(),this.saveButtonView=this._createButton(n("Save"),'<svg viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg"><path d="M6.972 16.615a.997.997 0 0 1-.744-.292l-4.596-4.596a1 1 0 1 1 1.414-1.414l3.926 3.926 9.937-9.937a1 1 0 0 1 1.414 1.415L7.717 16.323a.997.997 0 0 1-.745.292z"/></svg>',"ck-button-save"),this.saveButtonView.type="submit",this.cancelButtonView=this._createButton(n("Cancel"),'<svg viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg"><path d="m11.591 10.177 4.243 4.242a1 1 0 0 1-1.415 1.415l-4.242-4.243-4.243 4.243a1 1 0 0 1-1.414-1.415l4.243-4.242L4.52 5.934A1 1 0 0 1 5.934 4.52l4.243 4.243 4.242-4.243a1 1 0 1 1 1.415 1.414l-4.243 4.243z"/></svg>',"ck-button-cancel","cancel"),this._manualDecoratorSwitches=this._createManualDecoratorSwitches(e),this.children=this._createFormChildren(e.manualDecorators),this._focusables=new dt.ViewCollection,this._focusCycler=new dt.FocusCycler({focusables:this._focusables,focusTracker:this.focusTracker,keystrokeHandler:this.keystrokes,actions:{focusPrevious:"shift + tab",focusNext:"tab"}});const o=["ck","ck-anchor-form","ck-responsive-form"];e.manualDecorators.length&&o.push("ck-anchor-form_layout-vertical","ck-vertical-form"),this.setTemplate({tag:"form",attributes:{class:o,tabindex:"-1"},children:this.children}),(0,dt.injectCssTransitionDisabler)(this)}getDecoratorSwitchesState(){return Array.from(this._manualDecoratorSwitches).reduce((t,e)=>(t[e.name]=e.isOn,t),{})}render(){super.render(),(0,dt.submitHandler)({view:this});[this.urlInputView,...this._manualDecoratorSwitches,this.saveButtonView,this.cancelButtonView].forEach(t=>{this._focusables.add(t),this.focusTracker.add(t.element)}),this.keystrokes.listenTo(this.element)}focus(){this._focusCycler.focusFirst()}_createUrlInput(){const t=this.locale.t,e=new dt.LabeledFieldView(this.locale,dt.createLabeledInputText);return e.label=t("Anchor name"),e}_createButton(t,e,n,o){const i=new dt.ButtonView(this.locale);return i.set({label:t,icon:e,tooltip:!0}),i.extendTemplate({attributes:{class:n}}),o&&i.delegate("execute").to(this,o),i}_createManualDecoratorSwitches(t){const e=this.createCollection();for(const n of t.manualDecorators){const o=new dt.SwitchButtonView(this.locale);o.set({name:n.id,label:n.label,withText:!0}),o.bind("isOn").toMany([n,t],"value",(t,e)=>void 0===e&&void 0===t?n.defaultValue:t),o.on("execute",()=>{n.set("value",!o.isOn)}),e.add(o)}return e}_createFormChildren(t){const e=this.createCollection();if(e.add(this.urlInputView),t.length){const t=new dt.View;t.setTemplate({tag:"ul",children:this._manualDecoratorSwitches.map(t=>({tag:"li",children:[t],attributes:{class:["ck","ck-list__item"]}})),attributes:{class:["ck","ck-reset","ck-list"]}}),e.add(t)}return e.add(this.saveButtonView),e.add(this.cancelButtonView),e}} /** * @license Copyright (c) 2003-2020, CKSource - Frederico Knabben. All rights reserved. * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license */ class mt extends dt.View{constructor(e){super(e);const n=e.t;this.focusTracker=new s.FocusTracker,this.keystrokes=new s.KeystrokeHandler,this.unanchorButtonView=this._createButton(n("Unanchor"),'<?xml version="1.0" standalone="no"?>\n<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 20010904//EN"\n "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">\n<svg version="1.0"\n xmlns="http://www.w3.org/2000/svg" width="512.000000pt" height="512.000000pt" viewBox="0 0 512.000000 512.000000" preserveAspectRatio="xMidYMid meet">\n <metadata>\nCreated by potrace 1.16, written by Peter Selinger 2001-2019\n </metadata>\n <g transform="translate(0.000000,512.000000) scale(0.100000,-0.100000)" fill="#000000" stroke="none">\n <path d="M4255 5006 c-204 -208 -399 -316 -686 -380 -261 -58 -568 -60 -1104\n-7 -170 17 -404 36 -519 43 -593 32 -1000 -83 -1307 -370 l-72 -68 21 -64 c12\n-36 175 -616 363 -1290 188 -674 343 -1227 344 -1228 2 -2 44 31 94 75 201\n175 418 276 711 330 79 15 149 18 410 17 267 0 354 -4 575 -27 143 -15 318\n-32 390 -37 192 -16 529 -14 666 4 349 47 616 174 843 400 95 95 124 139 132\n198 11 83 7 88 -133 163 -250 133 -497 302 -731 501 -62 53 -115 106 -118 119\n-3 12 17 114 45 226 97 396 173 780 227 1157 19 134 34 268 32 296 -3 51 -3\n51 -38 53 -32 1 -44 -7 -145 -111z"/>\n <path d="M152 4245 c-97 -30 -151 -104 -152 -204 0 -42 126 -506 541 -1990\n297 -1065 548 -1951 556 -1969 26 -54 77 -82 149 -82 159 0 274 80 274 191 0\n35 -1083 3917 -1105 3959 -21 41 -81 87 -131 99 -54 14 -78 13 -132 -4z"/>\n <path d="M3845 1352 c-16 -11 -47 -38 -67 -60 -33 -36 -38 -49 -38 -89 l0 -47\n212 -213 212 -213 -212 -213 -212 -213 0 -47 c0 -42 5 -53 42 -93 51 -55 85\n-74 134 -74 36 0 50 12 251 212 l213 212 213 -212 c201 -200 215 -212 251\n-212 49 0 83 19 134 74 37 40 42 51 42 93 l0 47 -212 213 -212 213 212 213\n212 213 0 47 c0 42 -5 53 -42 93 -51 55 -85 74 -134 74 -36 0 -50 -12 -251\n-212 l-213 -212 -213 212 c-205 204 -214 212 -253 212 -21 0 -52 -8 -69 -18z"/>\n </g>\n</svg>',"unanchor"),this.editButtonView=this._createButton(n("Edit anchor"),t.icons.pencil,"edit"),this._focusables=new dt.ViewCollection,this._focusCycler=new dt.FocusCycler({focusables:this._focusables,focusTracker:this.focusTracker,keystrokeHandler:this.keystrokes,actions:{focusPrevious:"shift + tab",focusNext:"tab"}}),this.setTemplate({tag:"div",attributes:{class:["ck","ck-anchor-actions","ck-responsive-form"],tabindex:"-1"},children:[this.editButtonView,this.unanchorButtonView]})}render(){super.render();[this.editButtonView,this.unanchorButtonView].forEach(t=>{this._focusables.add(t),this.focusTracker.add(t.element)}),this.keystrokes.listenTo(this.element)}focus(){this._focusCycler.focusFirst()}_createButton(t,e,n){const o=new dt.ButtonView(this.locale);return o.set({label:t,icon:e,tooltip:!0}),o.delegate("execute").to(this,n),o}}class gt extends t.Plugin{static get requires(){return[dt.ContextualBalloon]}static get pluginName(){return"AnchorUI"}init(){const t=this.editor;t.editing.view.addObserver(e.ClickObserver),this.actionsView=this._createActionsView(),this.formView=this._createFormView(),this._balloon=t.plugins.get(dt.ContextualBalloon),this._createToolbarAnchorButton(),this._enableUserBalloonInteractions(),t.conversion.for("editingDowncast").markerToHighlight({model:"anchor-ui",view:{classes:["ck-fake-anchor-selection"]}}),t.conversion.for("editingDowncast").markerToElement({model:"anchor-ui",view:{name:"span",classes:["ck-fake-anchor-selection","ck-fake-anchor-selection_collapsed"]}})}destroy(){super.destroy(),this.formView.destroy()}_createActionsView(){const t=this.editor,e=new mt(t.locale),n=t.commands.get("anchor"),o=t.commands.get("unanchor");return e.bind("id").to(n,"value"),e.editButtonView.bind("isEnabled").to(n),e.unanchorButtonView.bind("isEnabled").to(o),this.listenTo(e,"edit",()=>{this._addFormView()}),this.listenTo(e,"unanchor",()=>{t.execute("unanchor"),this._hideUI()}),e.keystrokes.set("Esc",(t,e)=>{this._hideUI(),e()}),e.keystrokes.set("Ctrl+M",(t,e)=>{this._addFormView(),e()}),e}_createFormView(){const t=this.editor,e=t.commands.get("anchor"),n=t.config.get("anchor.defaultProtocol"),o=new ft(t.locale,e);return o.urlInputView.fieldView.bind("value").to(e,"value"),o.urlInputView.bind("isReadOnly").to(e,"isEnabled",t=>!t),o.saveButtonView.bind("isEnabled").to(e),this.listenTo(o,"submit",()=>{const{value:e}=o.urlInputView.fieldView.element,i=Z(e,n);t.execute("anchor",i,o.getDecoratorSwitchesState()),this._closeFormView()}),this.listenTo(o,"cancel",()=>{this._closeFormView()}),o.keystrokes.set("Esc",(t,e)=>{this._closeFormView(),e()}),o}_createToolbarAnchorButton(){const t=this.editor,e=t.commands.get("anchor"),n=t.t;t.keystrokes.set("Ctrl+M",(t,n)=>{n(),e.isEnabled&&this._showUI(!0)}),t.ui.componentFactory.add("anchor",t=>{const o=new dt.ButtonView(t);return o.isEnabled=!0,o.label=n("Anchor"),o.icon='<svg height="512" viewBox="0 0 58 58" width="512"\n xmlns="http://www.w3.org/2000/svg">\n <g id="Page-1" fill="none" fill-rule="evenodd">\n <g id="037---Waypoint-Flag" fill="rgb(0,0,0)" fill-rule="nonzero" transform="translate(0 -1)">\n <path id="Shape" d="m14.678 58.9507 1.0678-.2984c1.0270794-.287091 1.6269982-1.3523947 1.34-2.3795l-12.2083-43.6888c-.17227193-.6165569-.58242107-1.139423-1.14021438-1.4535673-.5577933-.3141444-1.21753647-.3938324-1.83408562-.2215327l-.1379.0385c-1.28397381.3587434-2.0340279 1.6904218-1.6753 2.9744l12.2086 43.6888c.2870014 1.0271063 1.3522895 1.6270863 2.3794 1.3401z"/>\n <path id="Shape" d="m57.67 28.42c-3.8715209-1.930437-7.4530885-4.3944478-10.64-7.32-.2678864-.245221-.3726619-.6216366-.27-.97 1.579074-5.9738125 2.7517572-12.04771023 3.51-18.18.12-1.02-.43-1.32-1.01-.62-11.38 13.61-31.07-2.49-42.79 9.88.14070884.2634479.25140182.5418575.33.83l7.92 28.36c11.74-12.22 31.36 3.78 42.72-9.8.58-.7.69-1.98.23-2.18z"/>\n </g>\n </g>\n</svg>',o.keystroke="Ctrl+M",o.tooltip=!0,o.isToggleable=!0,o.bind("isEnabled").to(e,"isEnabled"),o.bind("isOn").to(e,"value",t=>!!t),this.listenTo(o,"execute",()=>this._showUI(!0)),o})}_enableUserBalloonInteractions(){const t=this.editor.editing.view.document;this.listenTo(t,"click",()=>{this._getSelectedAnchorElement()&&this._showUI()}),this.editor.keystrokes.set("Tab",(t,e)=>{this._areActionsVisible&&!this.actionsView.focusTracker.isFocused&&(this.actionsView.focus(),e())},{priority:"high"}),this.editor.keystrokes.set("Esc",(t,e)=>{this._isUIVisible&&(this._hideUI(),e())}),(0,dt.clickOutsideHandler)({emitter:this.formView,activator:()=>this._isUIInPanel,contextElements:[this._balloon.view.element],callback:()=>this._hideUI()})}_addActionsView(){this._areActionsInPanel||this._balloon.add({view:this.actionsView,position:this._getBalloonPositionData()})}_addFormView(){if(this._isFormInPanel)return;const t=this.editor.commands.get("anchor");this.formView.disableCssTransitions(),this._balloon.add({view:this.formView,position:this._getBalloonPositionData()}),this._balloon.visibleView===this.formView&&this.formView.urlInputView.fieldView.select(),this.formView.enableCssTransitions(),this.formView.urlInputView.fieldView.element.value=t.value||""}_closeFormView(){const t=this.editor.commands.get("anchor");t.restoreManualDecoratorStates(),void 0!==t.value?this._removeFormView():this._hideUI()}_removeFormView(){this._isFormInPanel&&(this.formView.saveButtonView.focus(),this._balloon.remove(this.formView),this.editor.editing.view.focus(),this._hideFakeVisualSelection())}_showUI(t=!1){this._getSelectedAnchorElement()?(this._areActionsVisible?this._addFormView():this._addActionsView(),t&&this._balloon.showStack("main")):(this._showFakeVisualSelection(),this._addActionsView(),t&&this._balloon.showStack("main"),this._addFormView()),this._startUpdatingUI()}_hideUI(){if(!this._isUIInPanel)return;const t=this.editor;this.stopListening(t.ui,"update"),this.stopListening(this._balloon,"change:visibleView"),t.editing.view.focus(),this._removeFormView(),this._balloon.remove(this.actionsView),this._hideFakeVisualSelection()}_startUpdatingUI(){const t=this.editor,e=t.editing.view.document;let n=this._getSelectedAnchorElement(),o=r();const i=()=>{const t=this._getSelectedAnchorElement(),e=r();n&&!t||!n&&e!==o?this._hideUI():this._isUIVisible&&this._balloon.updatePosition(this._getBalloonPositionData()),n=t,o=e};function r(){return e.selection.focus.getAncestors().reverse().find(t=>t.is("element"))}this.listenTo(t.ui,"update",i),this.listenTo(this._balloon,"change:visibleView",i)}get _isFormInPanel(){return this._balloon.hasView(this.formView)}get _areActionsInPanel(){return this._balloon.hasView(this.actionsView)}get _areActionsVisible(){return this._balloon.visibleView===this.actionsView}get _isUIInPanel(){return this._isFormInPanel||this._areActionsInPanel}get _isUIVisible(){return this._balloon.visibleView==this.formView||this._areActionsVisible}_getBalloonPositionData(){const t=this.editor.editing.view,e=this.editor.model,n=t.document;let o=null;if(e.markers.has("anchor-ui")){const e=Array.from(this.editor.editing.mapper.markerNameToElements("anchor-ui")),n=t.createRange(t.createPositionBefore(e[0]),t.createPositionAfter(e[e.length-1]));o=t.domConverter.viewRangeToDom(n)}else{const e=this._getSelectedAnchorElement(),i=n.selection.getFirstRange();o=e?t.domConverter.mapViewToDom(e):t.domConverter.viewRangeToDom(i)}return{target:o}}_getSelectedAnchorElement(){const t=this.editor.editing.view,e=t.document.selection;if(e.isCollapsed)return bt(e.getFirstPosition());{const n=e.getFirstRange().getTrimmed(),o=bt(n.start),i=bt(n.end);return o&&o==i&&t.createRangeIn(o).getTrimmed().isEqual(n)?o:null}}_showFakeVisualSelection(){const t=this.editor.model;t.change(e=>{const n=t.document.selection.getFirstRange();if(t.markers.has("anchor-ui"))e.updateMarker("anchor-ui",{range:n});else if(n.start.isAtEnd){const o=function t(e,n,o){const i=[e.start.path[0]+1,0],r=o.createPositionFromPath(e.start.root,i,"toNext"),s=o.createRange(r,e.end);if(s.start.path[0]>e.end.path[0])return o.createRange(n);if(r.isAtStart&&r.isAtEnd)return t(s,n,o);return s}(n,t.document.selection.focus,e);e.addMarker("anchor-ui",{usingOperation:!1,affectsData:!1,range:o})}else e.addMarker("anchor-ui",{usingOperation:!1,affectsData:!1,range:n})})}_hideFakeVisualSelection(){const t=this.editor.model;t.markers.has("anchor-ui")&&t.change(t=>{t.removeMarker("anchor-ui")})}}function bt(t){return t.getAncestors().find(t=>{return(e=t).is("attributeElement")&&!!e.getCustomProperty("anchor");var e})} /** * @license Copyright (c) 2003-2020, CKSource - Frederico Knabben. All rights reserved. * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license */ const wt=new RegExp("(^|\\s)(((?:(?:(?:https?|ftp):)?\\/\\/)(?:\\S+(?::\\S*)?@)?(?:(?![-_])(?:[-\\w\\u00a1-\\uffff]{0,63}[^-_]\\.)+(?:[a-z\\u00a1-\\uffff]{2,}))(?::\\d{2,5})?(?:[/?#]\\S*)?)|((www.|(\\S+@))((?![-_])(?:[-\\w\\u00a1-\\uffff]{0,63}[^-_]\\.))+(?:[a-z\\u00a1-\\uffff]{2,})))$","i");class pt extends t.Plugin{static get pluginName(){return"AutoAnchor"}init(){const t=this.editor.model.document.selection;t.on("change:range",()=>{this.isEnabled=!t.anchor.parent.is("element","codeBlock")}),this._enableTypingHandling()}afterInit(){this._enableEnterHandling(),this._enableShiftEnterHandling()}_enableTypingHandling(){const t=this.editor,e=new i.TextWatcher(t.model,t=>{if(!function(t){return t.length>4&&" "===t[t.length-1]&&" "!==t[t.length-2]}(t))return;const e=vt(t.substr(0,t.length-1));return e?{url:e}:void 0});e.on("matched:data",(e,n)=>{const{batch:o,range:i,url:r}=n;if(!o.isTyping)return;const s=i.end.getShiftedBy(-1),a=s.getShiftedBy(-r.length),c=t.model.createRange(a,s);this._applyAutoAnchor(r,c)}),e.bind("isEnabled").to(this)}_enableEnterHandling(){const t=this.editor,e=t.model,n=t.commands.get("enter");n&&n.on("execute",()=>{const t=e.document.selection.getFirstPosition();if(!t.parent.previousSibling)return;const n=e.createRangeIn(t.parent.previousSibling);this._checkAndApplyAutoAnchorOnRange(n)})}_enableShiftEnterHandling(){const t=this.editor,e=t.model,n=t.commands.get("shiftEnter");n&&n.on("execute",()=>{const t=e.document.selection.getFirstPosition(),n=e.createRange(e.createPositionAt(t.parent,0),t.getShiftedBy(-1));this._checkAndApplyAutoAnchorOnRange(n)})}_checkAndApplyAutoAnchorOnRange(t){const e=this.editor.model,{text:n,range:o}=(0,i.getLastTextLine)(t,e),r=vt(n);if(r){const t=e.createRange(o.end.getShiftedBy(-r.length),o.end);this._applyAutoAnchor(r,t)}}_applyAutoAnchor(t,e){const n=this.editor.model;this.isEnabled&&function(t,e){return e.schema.checkAttributeInSelection(e.createSelection(t),"anchorId")}(e,n)&&n.enqueueChange(n=>{const o=this.editor.config.get("anchor.defaultProtocol"),i=Z(t,o);n.setAttribute("anchorId",i,e)})}}function vt(t){const e=wt.exec(t);return e?e[2]:null} /** * @license Copyright (c) 2003-2020, CKSource - Frederico Knabben. All rights reserved. * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license */ class _t extends t.Plugin{static get requires(){return[lt,gt,pt]}static get pluginName(){return"Anchor"}}const At={Anchor:_t}})(),(window.CKEditor5=window.CKEditor5||{}).anchor=o})();