Liferay.Loader.define("@liferay/layout-content-page-editor-web@3.0.145/page_editor/app/processors/getAlloyEditorProcessor",["module","exports","require","frontend-js-web","../config/index","../utils/isNullOrUndefined"],(function(e,t,n){window;{Object.defineProperty(t,"__esModule",{value:!0}),t.default=function getAlloyEditorProcessor(t,n=defaultGetEditorWrapper,o=defaultRender){let r,c,l,d={};return{createEditor:(o,u,f,b)=>{if(d.changeCallback=u,d.destroyCallback=f,r)return;const{editorConfig:g}=i.config.defaultEditorConfigurations[t];l=o;const p="".concat(i.config.portletNamespace,"FragmentEntryLinkEditable_").concat(o.id),y=n(o);y.setAttribute("id",p),y.setAttribute("name",p),o.addEventListener("keyup",keyupHandler),r=AlloyEditor.editable(y,_objectSpread(_objectSpread({},g),{},{documentBrowseLinkCallback:(e,t,n)=>{(0,a.openSelectionModal)({onSelect:n,selectEventName:p+"selectItem",title:Liferay.Language.get("select-item"),url:t})},documentBrowseLinkUrl:g.documentBrowseLinkUrl.replace("_EDITOR_NAME_",p),filebrowserImageBrowseLinkUrl:g.filebrowserImageBrowseLinkUrl.replace("_EDITOR_NAME_",p),filebrowserImageBrowseUrl:g.filebrowserImageBrowseUrl.replace("_EDITOR_NAME_",p),title:""}));const m=r.get("nativeEditor"),onClickOutside=e=>{e.target.closest('[name="'.concat(p,'"]'))||!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()))};c=[{removeListener:()=>document.removeEventListener("click",onClickOutside)},m.on("key",(t=>{t.data.keyCode!==e&&t.data.keyCode!==s||!l||"text"!==l.getAttribute("type")&&"text"!==l.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,a.debounce)((()=>{d.changeCallback&&d.changeCallback(m.getData())}),100))]},destroyEditor:(e,t)=>{if(r){const e=r.get("nativeEditor").getData();r.destroy(),c.forEach((e=>{e.removeListener()})),o(l,e,t),r=null,c=null,l=null,d={}}e&&e.removeEventListener("keyup",keyupHandler)},render:(e,t,n)=>{e!==l&&o(e,t,n)}}};var o,r,a=n("frontend-js-web"),i=n("../config/index"),c=function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}(n("../utils/isNullOrUndefined"));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,l=32,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,c.default)(t)||(e.innerHTML=t)},keyupHandler=e=>{e.keyCode===l&&e.preventDefault()};function isTextNode(e){return e.nodeType===Node.TEXT_NODE}}}));
//# sourceMappingURL=getAlloyEditorProcessor.js.map