Liferay.Loader.define("@liferay/layout-content-page-editor-web@3.0.179/page_editor/app/processors/getAlloyEditorProcessor",["module","exports","require","@liferay/layout-js-components-web","frontend-js-web","../config/constants/keyboardCodes","../config/index"],(function(e,t,n){window;{Object.defineProperty(t,"__esModule",{value:!0}),t.default=function getAlloyEditorProcessor(t,n=defaultGetEditorWrapper,o=defaultRender){let r,a,c,d={};return{createEditor:(o,u,f,b)=>{if(d.changeCallback=u,d.destroyCallback=f,r)return;const{editorConfig:g}=l.config.defaultEditorConfigurations[t];c=o;const y="".concat(l.config.portletNamespace,"FragmentEntryLinkEditable_").concat(o.id),p=n(o);p.setAttribute("id",y),p.setAttribute("name",y),o.addEventListener("keyup",keyupHandler),r=AlloyEditor.editable(p,_objectSpread(_objectSpread({},g),{},{documentBrowseLinkCallback:(e,t,n)=>{(0,i.openSelectionModal)({onSelect:n,selectEventName:y+"selectItem",title:Liferay.Language.get("select-item"),url:t})},documentBrowseLinkUrl:g.documentBrowseLinkUrl.replace("_EDITOR_NAME_",y),filebrowserImageBrowseLinkUrl:g.filebrowserImageBrowseLinkUrl.replace("_EDITOR_NAME_",y),filebrowserImageBrowseUrl:g.filebrowserImageBrowseUrl.replace("_EDITOR_NAME_",y),title:""}));const m=r.get("nativeEditor"),onClickOutside=e=>{e.target.closest('[name="'.concat(y,'"]'))||!e.target.closest(".page-editor__toolbar")&&!e.target.closest(".page-editor__wrapper")||onBlurEditor()},onBlurEditor=()=>{d.changeCallback?d.changeCallback(m.getData()).then((()=>{d.destroyCallback&&d.destroyCallback()})).catch((()=>{d.destroyCallback&&d.destroyCallback()})):d.destroyCallback&&requestAnimationFrame((()=>d.destroyCallback()))};a=[{removeListener:()=>document.removeEventListener("click",onClickOutside)},m.on("key",(t=>{t.data.keyCode!==e&&t.data.keyCode!==s||!c||"text"!==c.getAttribute("type")&&"text"!==c.dataset.lfrEditableType||t.cancel()})),m.on("blur",(()=>{r._mainUI.state.hidden?onBlurEditor():document.addEventListener("click",onClickOutside)})),m.on("instanceReady",(()=>{m.focus(),b?function _selectRange(e,t){const n=t.getSelection().getRanges()[0];if(document.caretPositionFromPoint){const t=document.caretPositionFromPoint(e.clientX,e.clientY),o=t.offsetNode;isTextNode(o)&&(n.setStart(CKEDITOR.dom.node(o),t.offset),n.setEnd(CKEDITOR.dom.node(o),t.offset))}else if(document.caretRangeFromPoint){const t=document.caretRangeFromPoint(e.clientX,e.clientY),o=t.startOffset||0;isTextNode(t.startContainer)&&isTextNode(t.endContainer)&&(n.setStart(CKEDITOR.dom.node(t.startContainer),o),n.setEnd(CKEDITOR.dom.node(t.endContainer),o))}t.getSelection().selectRanges([n])}(b,m):m.execCommand("selectAll")})),m.on("saveSnapshot",(0,i.debounce)((()=>{d.changeCallback&&d.changeCallback(m.getData())}),100))]},destroyEditor:(e,t)=>{if(r){const e=r.get("nativeEditor").getData();r.destroy(),a.forEach((e=>{e.removeListener()})),o(c,e,t),r=null,a=null,c=null,d={}}e&&e.removeEventListener("keyup",keyupHandler)},render:(e,t,n)=>{e!==c&&o(e,t,n)}}};var o,r,a=n("@liferay/layout-js-components-web"),i=n("frontend-js-web"),c=n("../config/constants/keyboardCodes"),l=n("../config/index");function ownKeys(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);t&&(o=o.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,o)}return n}function _objectSpread(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?ownKeys(Object(n),!0).forEach((function(t){_defineProperty(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):ownKeys(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function _defineProperty(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}const e=13,s=(null!==(o=null===(r=window.CKEDITOR)||void 0===r?void 0:r.SHIFT)&&void 0!==o?o:0)+e,defaultGetEditorWrapper=e=>{const t=document.createElement("div");return t.innerHTML=e.innerHTML,e.innerHTML="",e.appendChild(t),t},defaultRender=(e,t)=>{(0,a.isNullOrUndefined)(t)||(e.innerHTML=t)},keyupHandler=e=>{e.code===c.SPACE_KEY_CODE&&e.preventDefault()};function isTextNode(e){return e.nodeType===Node.TEXT_NODE}}}));
//# sourceMappingURL=getAlloyEditorProcessor.js.map