Current Path : /var/www/www-root/data/www/monolith-realty.ru/bitrix/js/landing/node/text/dist/ |
Current File : /var/www/www-root/data/www/monolith-realty.ru/bitrix/js/landing/node/text/dist/text.bundle.min.js |
this.BX=this.BX||{};this.BX.Landing=this.BX.Landing||{};(function(e,t,n,i){"use strict";const s=BX.Landing.Utils.escapeText;const a=BX.Landing.Utils.Matchers;const l=BX.Landing.Utils.changeTagName;const o=BX.Landing.Utils.textToPlaceholders;class d extends n.Base{constructor(e){super(e);this.currentNode=null;this.type="text";this.tableBaseFontSize="22";this.onClick=this.onClick.bind(this);this.onPaste=this.onPaste.bind(this);this.onDrop=this.onDrop.bind(this);this.onInput=this.onInput.bind(this);this.onKeyDown=this.onKeyDown.bind(this);this.onMousedown=this.onMousedown.bind(this);this.onMouseup=this.onMouseup.bind(this);this.bindEvents(this.node);t.Event.bind(document,"mouseup",this.onMouseup)}bindEvents(e){t.Event.bind(e,"mousedown",this.onMousedown);t.Event.bind(e,"click",this.onClick);t.Event.bind(e,"paste",this.onPaste);t.Event.bind(e,"drop",this.onDrop);t.Event.bind(e,"input",this.onInput);t.Event.bind(e,"keydown",this.onKeyDown)}onAllowInlineEdit(){this.node.setAttribute("title",s(BX.Landing.Loc.getMessage("LANDING_TITLE_OF_TEXT_NODE")))}onChange(e,t){super.onChange.call(this,t);if(!e){BX.Landing.UI.Panel.EditorPanel.getInstance().adjustPosition(this.node)}if(!t){BX.Landing.History.getInstance().push()}}onKeyDown(e){if(e.code==="Backspace"){this.onBackspaceDown(e)}this.onInput(e)}onInput(e){clearTimeout(this.inputTimeout);const t=e.keyCode||e.which;if(!(t===90&&(/win/i.test(top.window.navigator.userAgent)?e.ctrlKey:e.metaKey))){this.inputTimeout=setTimeout((()=>{if(this.lastValue!==this.getValue()){this.onChange(true);this.lastValue=this.getValue()}}),400)}if(this.isTable(e)){const t=parseInt(window.getComputedStyle(e.srcElement).getPropertyValue("font-size"),10);if(e.srcElement.textContent===""&&BX.Dom.hasClass(e.srcElement,"landing-table-td")&&t<this.tableBaseFontSize){BX.Dom.addClass(e.srcElement,"landing-table-td-height")}else{BX.Dom.removeClass(e.srcElement,"landing-table-td-height")}}}onEscapePress(){if(this.isEditable()){if(this===this.currentNode){BX.Landing.UI.Panel.EditorPanel.getInstance().hide()}this.disableEdit()}}onDrop(e){e.preventDefault()}onPaste(e){e.preventDefault();if(e.clipboardData&&e.clipboardData.getData){const t=e.clipboardData.getData("text/plain");let n=BX.Text.encode(t);if(this.isLinkPasted(t)){n=this.prepareToLink(n)}const i=n.replaceAll("\n","<br>");document.execCommand("insertHTML",false,i)}else{const e=window.clipboardData.getData("text");document.execCommand("paste",true,BX.Text.encode(e))}this.onChange()}onDocumentClick(e){if(this.isEditable()&&!this.fromNode){BX.Landing.UI.Panel.EditorPanel.getInstance().hide();this.disableEdit()}this.fromNode=false}onMousedown(e){BX.Event.EventEmitter.emit("BX.Landing.Node.Text:onMousedown");if(!this.manifest.group){this.fromNode=true;if(this.manifest.allowInlineEdit!==false&&BX.Landing.Main.getInstance().isControlsEnabled()){e.stopPropagation();this.enableEdit();if(this.isTable(e)){this.disableEdit();this.currentNode.node.querySelectorAll(".landing-table-container").forEach((e=>{if(!e.hasAttribute("table-prepare")){this.prepareNewTable(e)}}));const t=parseInt(window.getComputedStyle(e.srcElement).getPropertyValue("font-size"),10);if(e.srcElement.textContent===""&&BX.Dom.hasClass(e.srcElement,"landing-table-td")&&t<this.tableBaseFontSize){BX.Dom.addClass(e.srcElement,"landing-table-td-height")}else{BX.Dom.removeClass(e.srcElement,"landing-table-td-height")}}else{if(!this.manifest.textOnly&&!BX.Landing.UI.Panel.StylePanel.getInstance().isShown()){BX.Landing.UI.Panel.EditorPanel.getInstance().show(this.node,null,this.buttons)}if(this.nodeTableContainerList){this.nodeTableContainerList.forEach((e=>{e.tableEditor.unselect(e.tableEditor)}))}}BX.Landing.UI.Tool.ColorPicker.hideAll()}requestAnimationFrame((()=>{if(e.target.nodeName==="A"||e.target.parentElement.nodeName==="A"){const t=document.createRange();t.selectNode(e.target);window.getSelection().removeAllRanges();window.getSelection().addRange(t)}}))}}onMouseup(){setTimeout((()=>{this.fromNode=false}),10)}onClick(e){if(this.isTable(e)){this.addTableButtons(e)}e.stopPropagation();e.preventDefault();this.fromNode=false;if(e.target.nodeName==="A"||e.target.parentElement.nodeName==="A"){const t=document.createRange();t.selectNode(e.target);window.getSelection().removeAllRanges();window.getSelection().addRange(t)}}isEditable(){return this.node.isContentEditable}enableEdit(){const e=this.currentNode;if(e){const e=this.currentNode.node;const t=e.querySelectorAll(".landing-table-container");if(t.length>0){t.forEach((e=>{if(!e.tableEditor){e.tableEditor=new i.TableEditor(e,this.currentNode)}}));this.nodeTableContainerList=t}}if(!this.isEditable()&&!BX.Landing.UI.Panel.StylePanel.getInstance().isShown()){if(this!==this.currentNode&&this.currentNode!==null){this.disableEdit()}this.currentNode=this;BX.Landing.Node.Text.currentNode=this.currentNode;this.buttons=[];this.buttons.push(this.getDesignButton());if(this.isHeader()){this.buttons.push(this.getChangeTagButton());this.getChangeTagButton().onChangeHandler=this.onChangeTag.bind(this)}this.lastValue=this.getValue();this.node.contentEditable=true;this.node.setAttribute("title","")}}getDesignButton(){if(!this.designButton){this.designButton=new BX.Landing.UI.Button.Design("design",{html:BX.Landing.Loc.getMessage("LANDING_TITLE_OF_EDITOR_ACTION_DESIGN"),attrs:{title:BX.Landing.Loc.getMessage("LANDING_TITLE_OF_EDITOR_ACTION_DESIGN")},onClick:function(){BX.Landing.UI.Panel.EditorPanel.getInstance().hide();this.disableEdit();this.onDesignShow(this.manifest.code)}.bind(this)})}this.designButton.insertBefore="ai_copilot";return this.designButton}disableEdit(){if(this.isEditable()){this.node.contentEditable=false;if(this.lastValue!==this.getValue()){this.onChange();this.lastValue=this.getValue()}if(this.isAllowInlineEdit()){this.node.setAttribute("title",s(BX.Landing.Loc.getMessage("LANDING_TITLE_OF_TEXT_NODE")))}}}getField(){if(this.field){this.field.setValue(this.node.innerHTML);this.field.content=this.node.innerHTML}else{this.field=new BX.Landing.UI.Field.Text({selector:this.selector,title:this.manifest.name,content:this.node.innerHTML,textOnly:this.manifest.textOnly,bind:this.node});if(this.isHeader()){this.field.changeTagButton=this.getChangeTagButton()}}return this.field}setValue(e,t,n){this.preventSave(t);this.lastValue=this.isSavePrevented()?this.getValue():this.lastValue;this.node.innerHTML=e;this.onChange(false,n)}getValue(){if(this.node.querySelector(".landing-table-container")!==null){const e=this.node.cloneNode(true);this.prepareTable(e);return o(e.innerHTML)}return o(this.node.innerHTML)}isHeader(){return a.headerTag.test(this.node.nodeName)}isTable(e){let t=false;if(this.currentNode&&e){this.currentNode.node.querySelectorAll(".landing-table-container").forEach((n=>{if(n.contains(e.srcElement)){t=true}}))}return t}prepareNewTable(e){e.querySelectorAll("br").forEach((e=>{e.remove()}));e.setAttribute("table-prepare","true");this.currentNode.onChange(true)}addTableButtons(e){const t=[];let n=[];let i=[];const s=this.getTableButtons();const a=[s[0],s[1],s[2],s[3]];const l=this.currentNode.node;let o=null;let d=false;let r=false;let h=false;let c=true;if(BX.Dom.hasClass(e.srcElement,"landing-table")||BX.Dom.hasClass(e.srcElement,"landing-table-col-dnd")){c=false}if(BX.Dom.hasClass(e.srcElement,"landing-table-row-add")){r=true}if(BX.Dom.hasClass(e.srcElement,"landing-table-col-add")){h=true}let g=[];const u=l.querySelectorAll(".landing-table");if(u.length>0){u.forEach((t=>{if(t.contains(e.srcElement)){o=t;return true}return false}))}let T;s.forEach((t=>{t.options.srcElement=e.srcElement;t.options.node=l;t.options.table=o}));if(BX.Dom.hasClass(e.srcElement,"landing-table-row-dnd")){i=e.srcElement.parentNode.children;i=[...i];n=this.getAmountTableRows(o)>1?[0,1,2,3,4,5,6]:[0,1,2,3,4,5];n.forEach((e=>{s[e].options.target="row";s[e].options.setTd=i;t.push(s[e])}))}if(BX.Dom.hasClass(e.srcElement.parentNode,"landing-table-col-dnd")){const a=e.srcElement.parentElement.parentElement.childNodes;const l=[...a];const d=[];l.forEach((e=>{if(e.nodeType===1){d.push(e)}}));const r=d.indexOf(e.srcElement.parentElement);const h=e.srcElement.parentElement.parentElement.parentElement.childNodes;h.forEach((e=>{if(e.nodeType===1){const t=[];e.childNodes.forEach((e=>{if(e.nodeType===1){t.push(e)}}));if(t[r]){i.push(t[r])}}}));n=this.getAmountTableCols(o)>1?[0,1,2,3,4,5,7]:[0,1,2,3,4,5];n.forEach((e=>{s[e].options.target="col";s[e].options.setTd=i;t.push(s[e])}))}if(BX.Dom.hasClass(e.srcElement,"landing-table-th-select-all")){if(BX.Dom.hasClass(e.srcElement,"landing-table-th-select-all-selected")){T=true;const a=e.srcElement.parentElement.parentElement.childNodes;a.forEach((e=>{e.childNodes.forEach((e=>{i.push(e)}))}));n=[0,1,2,3,4,5,8,9,10];n.forEach((e=>{s[e].options.target="table";s[e].options.setTd=i;t.push(s[e])}))}else{T=false;BX.Landing.UI.Panel.EditorPanel.getInstance().hide()}}if(BX.Dom.hasClass(e.srcElement,"landing-table-td")||e.srcElement.closest(".landing-table-td")!==null){i.push(e.srcElement);n=[3,2,1,0];n.forEach((e=>{s[e].options.target="cell";s[e].options.setTd=i;s[e].insertAfter="strikeThrough";t.push(s[e])}));d=true;g=["justifyLeft","justifyCenter","justifyRight","justifyFull","createTable","pasteTable"]}let E=null;const f=[];i.forEach((e=>{if(e.nodeType===1){E=undefined;if(BX.Dom.hasClass(e,"text-left")){E="alignLeft"}if(BX.Dom.hasClass(e,"text-center")){E="alignCenter"}if(BX.Dom.hasClass(e,"text-right")){E="alignRight"}if(BX.Dom.hasClass(e,"text-justify")){E="alignJustify"}f.push(E)}}));let L=0;let p=true;while(L<f.length&&p){if(L>0&&f[L]!==f[L-1]){p=false}L++}E=p?f[0]:undefined;if(E){a.forEach((e=>{if(e.id===E){BX.Dom.addClass(e.layout,"landing-ui-active")}}))}if(t[0]&&t[1]&&t[2]&&t[3]){t[0].options.alignButtons=a;t[1].options.alignButtons=a;t[2].options.alignButtons=a;t[3].options.alignButtons=a}if(!this.manifest.textOnly){if(c){if(!r&&!h&&o){if(d){BX.Landing.UI.Panel.EditorPanel.getInstance().show(o.parentNode,null,t,true,g)}else if(T===false){BX.Landing.UI.Panel.EditorPanel.getInstance().hide()}else{BX.Landing.UI.Panel.EditorPanel.getInstance().show(o.parentNode,null,t,true)}}}else{BX.Landing.UI.Panel.EditorPanel.getInstance().hide()}}}getChangeTagButton(){if(!this.changeTagButton){this.changeTagButton=new BX.Landing.UI.Button.ChangeTag("changeTag",{html:`<span class="landing-ui-icon-editor-${this.node.nodeName.toLowerCase()}"></span>`,attrs:{title:BX.Landing.Loc.getMessage("LANDING_TITLE_OF_EDITOR_ACTION_CHANGE_TAG")},onChange:this.onChangeTag.bind(this)})}this.changeTagButton.insertAfter="unlink";this.changeTagButton.activateItem(this.node.nodeName);return this.changeTagButton}getTableButtons(){this.buttons=[];this.buttons.push(new BX.Landing.UI.Button.AlignTable("alignLeft",{html:'<span class="landing-ui-icon-editor-left"></span>',attrs:{title:BX.Landing.Loc.getMessage("LANDING_TITLE_OF_EDITOR_ACTION_ALIGN_LEFT")}},this.currentNode),new BX.Landing.UI.Button.AlignTable("alignCenter",{html:'<span class="landing-ui-icon-editor-center"></span>',attrs:{title:BX.Landing.Loc.getMessage("LANDING_TITLE_OF_EDITOR_ACTION_ALIGN_CENTER")}},this.currentNode),new BX.Landing.UI.Button.AlignTable("alignRight",{html:'<span class="landing-ui-icon-editor-right"></span>',attrs:{title:BX.Landing.Loc.getMessage("LANDING_TITLE_OF_EDITOR_ACTION_ALIGN_RIGHT")}},this.currentNode),new BX.Landing.UI.Button.AlignTable("alignJustify",{html:'<span class="landing-ui-icon-editor-justify"></span>',attrs:{title:BX.Landing.Loc.getMessage("LANDING_TITLE_OF_EDITOR_ACTION_ALIGN_JUSTIFY")}},this.currentNode),new BX.Landing.UI.Button.TableColorAction("tableTextColor",{text:BX.Landing.Loc.getMessage("EDITOR_ACTION_SET_FORE_COLOR"),attrs:{title:BX.Landing.Loc.getMessage("LANDING_TITLE_OF_EDITOR_ACTION_COLOR")}},this.currentNode),new BX.Landing.UI.Button.TableColorAction("tableBgColor",{html:'<i class="landing-ui-icon-editor-fill-color"></i>',attrs:{title:BX.Landing.Loc.getMessage("LANDING_TITLE_OF_EDITOR_ACTION_TABLE_CELL_BG")}},this.currentNode),new BX.Landing.UI.Button.DeleteElementTable("deleteRow",{html:'<span class="landing-ui-icon-editor-delete"></span>',attrs:{title:BX.Landing.Loc.getMessage("LANDING_TITLE_OF_EDITOR_ACTION_DELETE_ROW_TABLE")}},this.currentNode),new BX.Landing.UI.Button.DeleteElementTable("deleteCol",{html:'<span class="landing-ui-icon-editor-delete"></span>',attrs:{title:BX.Landing.Loc.getMessage("LANDING_TITLE_OF_EDITOR_ACTION_DELETE_COL_TABLE")}},this.currentNode),new BX.Landing.UI.Button.StyleTable("styleTable",{html:`\n\t\t\t\t\t\t${BX.Landing.Loc.getMessage("LANDING_TITLE_OF_EDITOR_ACTION_TABLE_STYLE")}\n\t\t\t\t\t\t\t<i class="fas fa-chevron-down g-ml-8"></i>\n\t\t\t\t\t`,attrs:{title:BX.Landing.Loc.getMessage("LANDING_TITLE_OF_EDITOR_ACTION_TABLE_STYLE")}},this.currentNode),new BX.Landing.UI.Button.CopyTable("copyTable",{text:BX.Landing.Loc.getMessage("LANDING_TITLE_OF_EDITOR_ACTION_TABLE_COPY"),attrs:{title:BX.Landing.Loc.getMessage("LANDING_TITLE_OF_EDITOR_ACTION_TABLE_COPY")}},this.currentNode),new BX.Landing.UI.Button.DeleteTable("deleteTable",{html:'<span class="landing-ui-icon-editor-delete"></span>',attrs:{title:BX.Landing.Loc.getMessage("LANDING_TITLE_OF_EDITOR_ACTION_TABLE_DELETE")}},this.currentNode));return this.buttons}onChangeTag(e,t){this.node=l(this.node,e);this.bindEvents(this.node);if(!this.getField().isEditable()&&!t){this.disableEdit();this.enableEdit()}const n={};n[this.selector]=e;if(!t){this.changeOptionsHandler(n).then((()=>{BX.Landing.History.getInstance().push()})).catch((()=>{}))}}getAmountTableCols(e){return e.querySelectorAll(".landing-table-col-dnd").length}getAmountTableRows(e){return e.querySelectorAll(".landing-table-row-dnd").length}prepareTable(e){const t=["table-selected-all","landing-table-th-select-all-selected","landing-table-cell-selected","landing-table-row-selected","landing-table-th-selected","landing-table-th-selected-cell","landing-table-th-selected-top","landing-table-th-selected-x","landing-table-tr-selected-left","landing-table-tr-selected-y","landing-table-col-selected","landing-table-tr-selected","table-selected-all-right","table-selected-all-bottom"];t.forEach((t=>{e.querySelectorAll(`.${t}`).forEach((e=>{BX.Dom.removeClass(e,t)}))}));return e}onBackspaceDown(e){const t=window.getSelection();const n=t.getRangeAt(0).startOffset;if(n===0){let n=t.focusNode;if(!BX.Type.isNil(n)&&n.nodeType!==3){if(n.firstChild.nodeType===3&&n.firstChild.firstChild.nodeType===3){n=n.firstChild.firstChild}else if(n.firstChild.nodeType===3){n=null}else{n=n.firstChild}}if(n){const t=n.parentNode;const i=new Set(["BLOCKQUOTE","UL"]);if(t&&i.has(t.nodeName)){const e=document.createElement("div");e.append(n);t.append(e)}let s=n.parentNode.parentNode;while(s&&!i.has(s.nodeName)){s=s.parentNode}if(s&&s.childNodes.length===1){s.after(n.parentNode);s.remove();e.preventDefault()}}}}isLinkPasted(e){const t=/^https?:\/\/(?:www\.)?[\w#%+.:=@~-]{1,256}\.[\d()A-Za-z]{1,6}\b[\w#%&()+./:=?@~-]*$/;return Boolean(t.test(e))}prepareToLink(e){return`<a class='g-bg-transparent' href='${e}' target='_blank'> ${e} </a>`}}e.Text=d})(this.BX.Landing.Node=this.BX.Landing.Node||{},BX,BX.Landing.Node,BX.Landing.Node.TableEditor); //# sourceMappingURL=text.bundle.map.js