smart-webcomponents-angular
Version:
[](https://jqwidgets.com/license/)
6 lines (4 loc) • 187 kB
JavaScript
/* Smart UI v20.0.2 (2024-09-06)
Copyright (c) 2011-2024 jQWidgets.
License: https://htmlelements.com/license/ */ //
Smart("smart-editor",class extends Smart.ContentElement{static get properties(){return{autoLoad:{value:!1,type:"boolean"},autoSave:{value:!1,type:"boolean"},autoSaveInterval:{value:1e3,type:"number"},autoExpand:{value:!1,type:"boolean"},charCountFormatFunction:{value:null,type:"function?"},contentFiltering:{value:{attributes:{value:[],type:"array"},attributeFilterMode:{allowedValues:["blackList","whiteList"],value:"blackList",type:"string"},tags:{value:[],type:"array"},tagFilterMode:{allowedValues:["blackList","whiteList"],value:"blackList",type:"string"},styleAttributes:{value:[],type:"array"},styleAttributeFilterMode:{allowedValues:["blackList","whiteList"],value:"blackList",type:"string"}},type:"object"},contextMenu:{allowedValues:["default","browser","none"],value:"default",type:"string"},contextMenuDataSource:{value:null,type:"any",reflectToAttribute:!1},dataExport:{value:{style:{value:null,type:"object"},fileName:{value:"smartEditor",type:"string?"},pageOrientation:{value:"portrait",type:"string"}},type:"object"},disableEditing:{value:!1,type:"boolean"},disableSearchBar:{value:!1,type:"boolean"},editMode:{allowedValues:["html","markdown"],value:"html",type:"string"},enableHtmlEncode:{value:!1,type:"boolean"},enableTabKey:{value:!1,type:"boolean"},findAndReplaceTimeout:{value:50,type:"number"},hideToolbar:{value:!1,type:"boolean"},hideInlineToolbar:{value:!1,type:"boolean"},imageFormat:{allowedValues:["blob","base64"],value:"base64",type:"string"},imageName:{value:"userfile[]",type:"string"},innerHTML:{type:"string",validator:"_sanitize",reflectToAttribute:!1},inlineToolbarOffset:{value:[0,-5],type:"array"},iframeSettings:{value:{attributes:{value:null,type:"object?"},enabled:{value:!1,type:"boolean"},resources:{value:null,type:"object?"}},type:"object"},maxCharCount:{value:null,type:"number?"},messages:{extend:!0,value:{en:{invalidValue:"{{elementType}}: Invalid {{property}} value. {{property}} should be of type {{typeOne}} or {{typeTwo}}.",incorrectArgument:"{{elementType}}: Incorrect argument {{argumentName}} in method {{methodName}}.",permissionsRequired:"{{elementType}}: Permissions are required for the following action {{actionName}}.",timeout:"{{elementType}}: The import request has timed out.",importError:"{{elementType}}: The import request errored with the following status: {{status}}.",exportError:"{{elementType}}: The Export request errored with the following status: {{status}}.",ok:"Ok",cancel:"Cancel",alignLeft:"Align Left",alignCenter:"Align Center",alignRight:"Align Right",alignJustify:"Align Justify",segoeUi:"Segoe UI",arial:"Arial",georgia:"Georgia",impact:"Impact",tahoma:"Tahoma",timesNewRoman:"Times New Roman",verdana:"Verdana",p:"Paragraph",pre:"Code",code:"Code",blockquote:"Quotation",h1:"Heading 1",h2:"Heading 2",h3:"Heading 3",h4:"Heading 4",h5:"Heading 5",h6:"Heading 6",bold:"Bold",italic:"Italic",underline:"Underline",strikethrough:"Strikethrough",orderedlist:"Ordered List",unorderedlist:"Unordered List",checklist:"Check List",subscript:"Subscript",superscript:"Superscript",alignment:"Alignments",fontname:"Font Name",fontsize:"Font Size",formats:"Formats",backgroundcolor:"Background Color",fontcolor:"Font Color",redo:"Redo",undo:"Undo",indent:"Indent",outdent:"Outdent",createlink:"Hyperlink",hyperlink:"Hyperlink",editlink:"Hyperlink",removelink:"Remove link",openlink:"Open link",image:"Image",video:"Video",table:"Table",lowercase:"Lower Case",uppercase:"Upper Case",print:" Print",cut:" Cut",copy:" Copy",paste:" Paste",clearformat:"Clear Format",fullscreen:"Full Screen",restore:"Restore Screen",sourcecode:"Source Code",preview:"Preview",splitmode:"Split Editor",address:"Web Address",text:"Display Text",addressPlaceholder:"http://example.com",textPlaceholder:"Enter Text",targetPlaceholder:"Select Target",titlePlaceholder:"Enter a Title",urlPlaceholder:"http://example.com/image.png",srcPlaceholder:"https://www.youtube.com/embed/video_link",thumbnail:"Or provide a URL as a video thumbnail",thumbnailPlaceholder:"https://www.link-to-thumbnail.jpg",videoUrl:"Video URL",videoUrlPlaceholder:"https://www.youtube.com/video_link",captionPlaceholder:"Caption",altPlaceholder:"Alternative Text",widthPlaceholder:"auto",heightPlaceholder:"auto",target:"Open Link in",linkBlankDescr:"New Window",linkSelfDescr:"Same Window",linkParentDescr:"Parent Frame",linkTopDescr:"Full Body of the Window",linkCustomDescr:"Custom Frame Name",title:"Title",url:"Or provide the URL to an image",src:"Or provide the URL to an embed video",width:"Width",height:"Height",alt:"Alternative Text",caption:"Caption",display:"Display",displayPlaceholder:"Display",displayBlock:"Block",displayInline:"Inline",draggable:"Enable Dragging",resizable:"Enable Resizing",browse:"Browse",connectionError:"{{elementType}}: File Upload requires connection to the server.",wrongItemIndex:"{{elementType}}: There is no file with such an index in the list of uploaded files.",tooLongFileName:"{{elementType}}: File name is too long.",totalFiles:"Total files: ",cancelFile:"Cancel File",dashedborders:"Dashed Borders",altrows:"Alternate Rows",insertRowBefore:"Insert Row Before",insertRowAfter:"Insert Row After",deleteRow:"Delete Row",insertColumnLeft:"Insert Column Left",insertColumnRight:"Insert Column Right",deleteColumn:"Delete Column",alignTop:"Align Top",alignMiddle:"Align Middle",alignBottom:"Align Bottom",delete:"Delete",tablerows:"Table Rows",tablecolumns:"Table Columns",tablevalign:"Table Cell Vertical Align",tablestyle:"Table Style",tableheader:"Table Header",buttonLabel:"Custom Table",pasteLabel:"Choose the paste format action:",cols:"Columns",rows:"Rows",alphabet:"abcdefghijklmnopqrstuvwxyz",header:"Header",column:"Column",plainText:"Plain Text",keepFormat:"Keep Format",cleanFormat:"Clean Format",roleDescription:"Text Editor",iframeTitle:"Editor Content is Encloused in it's own DOM inside an iFrame",toolbarButtonAriaLabel:"Toolbar Toggle Button",primaryToolbarAriaLabel:"Primary Toolbar",secondaryToolbarAriaLabel:"Secondary Toolbar",inputAriaLabel:"Enter Text",homeTab:"Home",viewTab:"View",insertTab:"Insert",layoutTab:"Layout",undoGroup:"Undo",clipboardGroup:"Clipboard",fontGroup:"Font",paragraphGroup:"Paragraph",editingGroup:"Editing",tableGroup:"Tables",imageGroup:"Images",videoGroup:"Videos",linkGroup:"Links",viewsGroup:"Views",deleteGroup:"Delete",findandreplace:"Find and Replace",requiredMessage:"The content of the Editor cannot be empty",tableProperties:"Table Properties",imageProperties:"Image Properties",videoProperties:"Video Properties",linkProperties:"Link Properties",selectAll:"Select All",deleteTable:"Delete Table",deleteImage:"Delete Image",deleteVideo:"Delete Video",createLink:"Create Link",deleteLink:"Delete Link",copyImage:"Copy",cutImage:"Cut",copyVideo:"Copy",cutVideo:"Cut",find:"Find",findPlaceholder:"",replace:"Replace",replaceWith:"Replace With",replaceAll:"Replace All",replacePlaceholder:"",results:"Results",resultsPlaceholder:"No match",matchCase:"Match Case",searchPlaceholder:"Search..."}}},name:{value:null,type:"string?"},pasteFormat:{allowedValues:["prompt","plainText","keepFormat","cleanFormat"],value:"keepFormat",type:"string"},postData:{value:null,type:"object"},placeholder:{value:"",type:"string"},removeStylesOnClearFormat:{value:!1,type:"boolean"},required:{value:!1,type:"boolean"},sanitized:{value:!1,type:"boolean"},showCharCount:{value:!1,type:"boolean"},splitModeRefreshTimeout:{value:100,type:"number"},toolbarItems:{value:["bold","italic","underline","|","formats","alignment","orderedList","unorderedList","|","hyperlink","image","video","|","sourceCode","undo","redo"],reflectToAttribute:!1,type:"array"},toolbarMode:{allowedValues:["menu","singleLineRibbon"],value:"menu",type:"string"},toolbarRibbonConfig:{value:[{name:"homeTab",groups:[{name:"undoGroup",items:["undo","redo"]},{name:"clipboardGroup",items:["cut","copy","paste"]},{name:"fontGroup",items:["fontName","fontSize","backgroundColor","fontColor","clearFormat","formats","bold","italic","underline","strikethrough","superscript","subscript"]},{name:"paragraphGroup",items:["orderedList","unorderedList","indent","outdent","alignment"]},{name:"editingGroup",items:["findAndReplace"]}]},{name:"insertTab",groups:[{name:"tableGroup",items:["table"]},{name:"imageGroup",items:["image"]},{name:"videoGroup",items:["video"]},{name:"linkGroup",items:["createLink","removeLink"]}]},{name:"viewTab",groups:[{name:"viewsGroup",items:["fullScreen","sourceCode","splitMode"]}]},{name:"layoutTab",hidden:!0,groups:[{name:"deleteGroup",items:["delete"]},{name:"tableGroup",items:["table","tableHeader","tableRows","tableColumns","tableVAlign","tableStyle",""]},{name:"imageGroup",items:["image","caption"]},{name:"videoGroup",items:["video","caption"]}]}],type:"array"},toolbarViewMode:{allowedValues:["toggle","multiRow","scroll"],value:"toggle",type:"string"},toolbarSticky:{value:!1,type:"boolean"},spellCheck:{value:!0,type:"boolean"},value:{value:"",type:"string",validator:"_sanitize",reflectToAttribute:!1},validateFile:{value:null,type:"function?",reflectToAttribute:!1},uploadUrl:{value:"",type:"string",reflectToAttribute:!1},removeUrl:{value:"",type:"string",reflectToAttribute:!1},onImageRemove:{value:null,type:"function?"},autoUpload:{value:!0,type:"boolean"},windowCustomizationFunction:{value:null,reflectToAttribute:!1,type:"function?"}}}static get listeners(){return{"document.down":"_documentDownHandler","document.move":"_documentMoveHandler","document.up":"_documentUpHandler","document.dragstart":"_dragStartHandler","document.selectstart":"_selectStartHandler","document.selectionchange":"_selectionChangeHandler","container.dragend":"_dragEndHandler","container.drop":"_dropHandler","container.change":"_changeHandler","container.beforeinput":"_beforeInputHandler","container.input":"_afterInputHandler","contentContainer.contextmenu":"_contextMenuHandler","contentContainer.keydown":"_editableElementKeyDownHandler","contentContainer.keyup":"_updateOnInputChange","contentContainer.paste":"_updateOnInputChange","input.focus":"_editableElementFocusHandler","input.blur":"_editableElementBlurHandler","input.change":"_inputChangeEvent","editableElement.focus":"_editableElementFocusHandler","editableElement.blur":"_editableElementBlurHandler","editableElement.wheel":"_editableElementWheelHandler","editableElement.move":"_editableElementMoveHandler",touchmove:"_touchmoveHandler",resize:"_resizeHandler"}}static get requires(){return{"Smart.Button":"smart.button.js","Smart.Window":"smart.window.js","Smart.Tooltip":"smart.tooltip.js"}}static get styleUrls(){return["smart.editor.css"]}template(){return'<div id="container" role="presentation">\n <div id="toolbar" class="smart-editor-toolbar" role="presentation">\n <div id="toolbarItemsPrimary" class="smart-editor-toolbar-items-primary" role="toolbar"></div>\n <div id="toolbarToggleButton" class="smart-editor-toolbar-toggle-button" role="button"></div>\n <div id="toolbarItemsSecondary" class="smart-editor-toolbar-items-secondary" role="toolbar"></div>\n </div>\n <div id="contentContainer" class="smart-editor-content-container" role="presentation">\n <div class="smart-editor-editable" contenteditable="true" id="editableElement" aria-placeholder="[[placeholder]]"\n inner-h-t-m-l="[[innerHTML]]" spellcheck="[[spellCheck]]" role="textbox" aria-multiline="true"><content></content></div>\n <textarea name="[[name]]" id="input" class="smart-hidden" placeholder="[[placeholder]]" aria-placeholder="[[placeholder]]"\n spellcheck="[[spellCheck]]" autocapitalize="none" autocomplete="off"></textarea>\n </div>\n </div>'}propertyChangedHandler(e,t,o){const n=this;switch(e){case"contentFiltering":case"contentFiltering_attributes":case"contentFiltering_attributeFilterMode":case"contentFiltering_tags":case"contentFiltering_tagFilterMode":case"contentFiltering_styleAttributes":case"contentFiltering_styleAttributeFilterMode":n._handleContentFiltering();break;case"disabled":case"disableEditing":n.$.input.readonly=o,n.$.editableElement.setAttribute("contenteditable",!o),"disabled"===e&&n._setFocusable();break;case"disableSearchBar":n._closeSearchToolbar();break;case"enableHtmlEncode":{const e=n.$.input;e.classList.contains("smart-hidden")||(e.value=n._getInputValue());break}case"hideToolbar":o&&n._updateToolbarItems(void 0,n.$.toolbar);break;case"innerHTML":case"value":n._handleInputContent(e,o),n.$.fireEvent("change",{oldValue:n._value||t,value:n._value=n._getCurrentValue()});break;case"editMode":n._handleEditMode(o);break;case"hideInlineToolbar":{const e=n.$.inlineToolbar;e&&e.visible&&e.classList.contains("smart-editor-inline-toolbar")&&e.close();break}case"toolbarViewMode":n._toggleToolbar("toggle"===o);break;case"toolbarMode":case"toolbarRibbonConfig":n._handleToolbarMode();break;case"locale":delete n._toolbarItemsObj,delete n._inlineToolbarItemsObj,n._refreshToolbarItems(n._getToolbarItems()),n._closeToolbar(),n._closeWindow();break;case"iframeSettings":n._handleInputElement();break;case"maxCharCount":n._handleMaxCharCount(),n._setCharCount();break;case"name":o&&"markdown"!==n.editMode&&(n.$.input.value=n._getInputValue(n.$.editableElement.innerHTML.trim()));break;case"placeholder":n._handlePlaceholder();break;case"pasteFormat":n._closeWindow();break;case"readonly":n.$.input.readonly=o,n.$.editableElement.setAttribute("contenteditable","markdown"!==n.editMode&&!o),n._closePopups(),n._setResizeFrame(),n._closeWindow();break;case"showCharCount":n._setCharCount();break;case"rightToLeft":case"animation":case"theme":n._updateIframeBody();break;case"toolbarItems":n._handleToolbarItems();break;default:super.propertyChangedHandler(e,t,o)}}addToolbarItem(e){const t=this;t.toolbarItems||(t.toolbarItems=[]),t.toolbarItems.push(e),t._handleToolbarItems()}insertToolbarItem(e,t){const o=this;o.toolbarItems||(o.toolbarItems=[]),o.toolbarItems.splice(t,0,e),o._handleToolbarItems()}removeToolbarItem(e){const t=this;t.toolbarItems||(t.toolbarItems=[]),t.toolbarItems.splice(e,1),t._handleToolbarItems()}_handleToolbarItems(){const e=this,t=e.$.toolbarItemsPrimary,o=e.$.toolbarItemsSecondary;if(t&&o&&(t.innerHTML=o.innerHTML="",delete e._toolbarItemsObj,delete e._inlineToolbarItemsObj,e._refreshToolbarItems(e._getToolbarItems()),"toggle"===e.toolbarViewMode)){const n=e.$.toolbarToggleButton;t.scrollHeight!==t.offsetHeight||o.children.length?n.classList.remove("smart-visibility-hidden"):n.classList.add("smart-visibility-hidden")}}render(){const e=this,t=()=>0===e.offsetWidth||0===e.offsetHeight,o=()=>{e._isMobile=Smart.Utilities.Core.isMobile,e._isFireFox=Smart.Utilities.Core.Browser.Firefox,e._isSafari=Smart.Utilities.Core.Browser.Safari,e._isMacOS=(window.navigator.platform||"").indexOf("Mac")>-1,e._handleMaxCharCount(),e._handleInputContent(),e._setToolbarVisibility(),e._handleToolbarMode(),e._handleInputElement(),e._handleEditMode(),e._predefPropertyGetter(),e._setCharCount(),e._setFocusable(),e._setAriaSettings(),e.autoExpand&&e.expandToolbar(),e.isInitialized=!0,e.checkLicense(),e.$.input&&(e.$.input.value=e._getInputValue(e.$.editableElement.innerHTML.trim()))};if(t())return requestAnimationFrame((()=>{e.isInitialized||t()?e._createInterval=setInterval((()=>{e.isInitialized||t()||(o(),clearInterval(e._createInterval))}),100):o()})),void super.render();o(),super.render()}detached(){const e=this;super.detached(),delete e._dragDetails,delete e._resizeFrameObj,delete e._toolbarItemClick,e._endInlineToolbarClick(),e._closeWindow(),e._closeToolbarItemDropDown(e.$.inputPopup),e._closeToolbarItemDropDown(e.$.colorInputPopup),e._closeContextMenu(),e._closeToolbar(),e._handleTableSelection()}focus(){const e=this,t="markdown"===e.editMode?e.$.input:e.$.editableElement;t&&t.focus()}blur(){const e=this,t="markdown"===e.editMode?e.$.input:e.$.editableElement;t&&t.blur()}clearState(){const e=this;e.id?window.localStorage.removeItem("smartEditor"+e.id):e.warn(e.localize("noId"))}collapseToolbar(){this._toggleToolbar(!0)}disableToolbarItem(e){this._setToolbarItemAttr(e,"disabled",!0)}enableToolbarItem(e){this._setToolbarItemAttr(e,"disabled",!1)}expandToolbar(){this._toggleToolbar()}executeCommand(e,t){const o=this,n=o._getCurrentValue();o.$.editableElement.focus();const a=o.$.editableElement.getRootNode().execCommand(e,!1,t),i=o._getCurrentValue();return o.$.fireEvent("change",{value:i,oldValue:n}),a}exportData(e,t){this._handleDataExport(e,t)}importData(e,t){"string"==typeof e&&(e={url:e}),t||(t={}),this._ajax(e,t)}fullScreenMode(e){const t=this;t.$.fireEvent("actionStart",{name:"fullScreenMode"}).defaultPrevented||(t._handleFullScreenMode(t._toggleItem("fullscreen",e)),t.$.fireEvent("actionEnd",{name:"fullScreenMode"}))}getCharCount(){const e=this;if("html"===e.editMode){const t=e.$.editableElement,o=t.textContent.length,n=t.innerText.length;return n&&o?n:0}return e.$.input.value.length}getSelection(){const e=this.$.iframe;let t,o;return e?(t=e.contentDocument,o=e.contentWindow):(t=document,o=window),new function(e){var t={initialize:function(e){this.document=e},getSelection:function(){return this.document.getSelection?this.document.getSelection():this.document.selection},getRange:function(){var e=this.getSelection();if(!e)return null;try{return e.rangeCount>0?e.getRangeAt(0):this.document.createRange?this.document.createRange():this.document.selection.createRange()}catch(e){return this.document.body.createTextRange()}},selectRange:function(e){if(e.select)e.select();else{var t=this.getSelection();t.addRange&&(t.removeAllRanges(),t.addRange(e))}},selectNode:function(e,t){var o=this.getRange(),n=this.getSelection();if(o.moveToElementText)o.moveToElementText(e),o.select();else if(n.addRange)try{t?o.selectNodeContents(e):o.selectNode(e),n.removeAllRanges(),n.addRange(o)}catch(e){}else n.setBaseAndExtent(e,0,e,1);return e},isCollapsed:function(){var e=this.getRange();return!e.item&&(0==e.boundingWidth||this.getSelection().isCollapsed)},collapse:function(e){var t=this.getRange(),o=this.getSelection();t.select?(t.collapse(e),t.select()):e?o.collapseToStart():o.collapseToEnd()},getContent:function(){var t=this.getRange(),o=e.createElement("div");return this.isCollapsed()?"":t.cloneContents?(o.appendChild(t.cloneContents()),o.innerHTML):null!=t.item||null!=t.htmlText?t.item?t.item(0).outerHTML:t.htmlText:t.toString()},getText:function(){var e=this.getRange(),t=this.getSelection();return this.isCollapsed()?"":e.text||(t.toString?t.toString():"")},getNode:function(){var t=this.getRange();if(!$.smart.browser.msie||$.smart.browser.version>=9){var o=null;if(t)for(o=t.commonAncestorContainer,t.collapsed||t.startContainer==t.endContainer&&t.startOffset-t.endOffset<2&&t.startContainer.hasChildNodes()&&(o=t.startContainer.childNodes[t.startOffset]);"element"!=typeof o;)o=o.parentNode;return e.id(o)}return e.id(t.item?t.item(0):t.parentElement())},insertContent:function(e){var t=this.getRange();if(t.pasteHTML)t.pasteHTML(e),t.collapse(!1),t.select();else if(t.insertNode)if(t.deleteContents(),t.createContextualFragment)t.insertNode(t.createContextualFragment(e));else{var o=this.document,n=o.createDocumentFragment(),a=o.createElement("div");n.appendChild(a),a.outerHTML=e,t.insertNode(n)}}};return t.initialize(e),t}(t)}getSelectionRange(){return this._selectionRange}clearContent(){const e=this;e._setResizeFrame(),e.$.editableElement.innerHTML=e.$.input.value=""}getHTML(){const e=this;if("markdown"===e.editMode){const t=e.$.input;return window.marked?window.marked(t.value):t.value}return e.$.editableElement.innerHTML}getText(){const e=this;return"markdown"===e.editMode?e.$.input.value:e.$.editableElement.textContent}loadState(e){const t=this;t.id?(e||(e=window.localStorage.getItem("smartEditor"+t.id)),"string"==typeof e&&(t.set("value",e),t.$.editableElement.innerHTML=t.$.input.value=e)):t.warn(t.localize("noId"))}showMessage(e,t){const o=this;if(!e||!o.isRendered)return;if(!Smart.Toast)return void o.error(o.localize("missingReference",{elementType:o.nodeName.toLowerCase(),methodName:"showMessage",files:"smart.toast.js"}));o._setToast();const n=o.$.toast;if(n){let a;if("object"==typeof t)for(let e in t)"iconType"===e?a=t[e]:n[e]=t[e];if(!o.$.container.contains(n)){const e=o.$toast;o._toastVisibilityHandler||(o._toastVisibilityHandler=e=>{const t=e.type;"close"===e.type&&e.detail.instance===o._requiredMessage&&delete o._requiredMessage,e.stopPropagation(),o.$.fireEvent("message"+t.slice(0,1).toUpperCase()+t.slice(1),e.detail)},e.listen("open",o._toastVisibilityHandler),e.listen("close",o._toastVisibilityHandler)),o.$.container.appendChild(n)}return n.open(e+"",a)}}hideMessage(e){const t=this.$.toast;t&&(void 0===e?t.closeAll():t.closeItem(e))}hideLastMessage(){const e=this.$.toast;e&&e.closeLast()}selectAll(){this._selectAll()}selectRange(e,t){const o=this,n=o.$.editableElement.getRootNode();if(!n)return;e=parseInt(e),t=parseInt(t),e=Math.min(e,t),t=Math.max(e,t);const a=o.$.input,i=o.$.editableElement,r="markdown"===o.editMode||o.$.editableElement.classList.contains("smart-hidden")?a:i,l=o.$.iframe,[s,d]=l?[l.contentWindow,l.contentDocument]:[window,document],c=s.getSelection();let m=n.activeElement;if((!m||m!==a&&m!==i||m.classList.contains("smart-hidden"))&&(r.focus(),m=r),c.removeAllRanges(),delete o._selectionRange,!isNaN(e)&&!isNaN(t)&&e!==t){if(m===a)a.setSelectionRange(e,t),o._selectionRange={selectionStart:e,selectionEnd:t};else{const n=o._getNodes(i,e,t).nodes;for(let e=0,t=n.length;e<t;e+=1){const{node:t,index:a,startIndex:i}=n[e],r=d.createRange();t.nodeType===Node.TEXT_NODE?(r.setStart(t,Math.max(0,i)),r.setEnd(t,Math.min(a,t.nodeValue.length))):r.selectNodeContents(t),c.addRange(r),o._selectionRange=r}}o._updateToolbarItems()}}saveState(){const e=this;e.id?window.localStorage.setItem("smartEditor"+e.id,e.$.editableElement.innerHTML):e.warn(e.localize("noId"))}splitMode(e){const t=this;t.$.fireEvent("actionStart",{name:"splitMode"}).defaultPrevented||(t._handleSplitMode(t._toggleItem("splitmode",e)),t.$.fireEvent("actionEnd",{name:"splitMode"}))}previewMode(e){const t=this;t.$.contentContainer.hasAttribute("split-mode")||t.$.fireEvent("actionStart",{name:"sourcecode"}).defaultPrevented||(t._handleSourceCodeMode(t._toggleItem("sourcecode",e)),t.$.fireEvent("actionEnd",{name:"sourcecode"}))}print(){this._handlePrint()}updateToolbarItem(e,t){const o=this,n=o.toolbarItems;let a;if("string"==typeof e?a=n.find((t=>t.name===e)):"number"==typeof e&&(a=n[e]),a){o._closePopups(),o._closeWindow(),delete o._toolbarItemsObj[a.name],delete o._inlineToolbarItemsObj[a.name];for(let e in t)a[e]=t[e];return o._refreshToolbarItems(o._getToolbarItems()),!0}}_toggleItem(e,t){const o=this._toolbarItemsObj;if(!o)return;const n=o[e],a=this.$.toolbar.querySelector(`.smart-editor-toolbar-item[item-name="${e}"]`);return n&&a?((t=n.value=void 0===t?!n.value:!!t)?(a.setAttribute("checked",""),a.setAttribute("aria-pressed",!0)):(a.removeAttribute("checked"),a.setAttribute("aria-pressed",!1)),a):void 0}_ajax(e,t={}){const o=this;let n="GET",a=e.url,i=null,r=!0;if(e.type&&(n=e.type),e.data)if("GET"===n){a+="?";for(let t in e.data)Object.prototype.hasOwnProperty.call(e.data,t)&&(a+=encodeURI(t+"="+e.data[t]+"&"));"&"===a.charAt(a.length-1)&&(a=a.slice(0,a.length-1))}else"POST"===n&&(i=JSON.stringify(e.data));t&&!1===t.async&&(r=!1),void 0!==window.fetch&&r?o._ajaxFetch(e,t,n,a,i):o._ajaxXMLHttpRequest(e,t,n,a,i,r)}_ajaxFetch(e,t,o,n,a){const i=this,r={method:o};let l,s,d;t&&t.contentType&&(r.headers=new Headers({"Content-Type":t.contentType})),null!==a&&(r.body=a),e.timeout&&(s=setTimeout((function(){d=!0}),e.timeout)),t.beforeSend&&!1===t.beforeSend(r,t)||fetch(n,r).then((function(e){if(d)throw l=408,i.error(i.localize("timeout",{elementType:i.nodeName.toLowerCase()}));if(s&&clearTimeout(s),l=e.status,!e.ok)throw i.error(i.localize("importError",{elementType:i.nodeName.toLowerCase(),status:e.statusText}));return e.text()})).then((e=>i._ajaxComplete(t,e,l))).catch((function(e){t&&t.loadError&&t.loadError(l,e)}))}_ajaxXMLHttpRequest(e,t,o,n,a,i){const r=new XMLHttpRequest,l=this;r.open(o,n,i),r.ontimeout=function(){t&&t.loadError&&t.loadError(408,"timeout")},r.onload=function(){if(4===r.readyState){const o=r.status;let n=r.response;o>=200&&o<=299?("json"===e.dataType&&(n=JSON.parse(n)),l._ajaxComplete(t,n,o)):t&&t.loadError&&t.loadError(o,n)}},r.onerror=function(){t&&t.loadError&&t.loadError(r.status,r.response)},t&&t.contentType&&r.setRequestHeader("Content-Type",t.contentType),i&&e.timeout&&(r.timeout=e.timeout),t.beforeSend&&!1===t.beforeSend(r,t)||r.send(a)}_ajaxComplete(e,t){if(e){if(e.beforeLoadComplete){const o=e.beforeLoadComplete(t);o&&(t=o)}this._handleInputContent("value",t)}}_afterInputHandler(e){const t=this,o=t._beforeInputObj,n=t.$.editableElement,a=!n.innerHTML;let i,r;if(o&&o.type&&(i=o.type,r=o.rangeDetails),delete t._beforeInputObj,a&&(t._setResizeFrame(),t._closeToolbar()),"insertParagraph"===i||a){let e=t._getSelectionRange().startContainer;if(e.nodeType===Node.TEXT_NODE&&(e=e.parentElement),e&&e.classList&&(e.closest(".smart-editor-image-caption")||e.closest(".smart-editor-editable table")))return;const o=t.$.iframe,[i,r]=o?[o.contentWindow,o.contentDocument]:[window,document];("div"===i.getSelection().anchorNode.nodeName.toLowerCase()||e===n&&a)&&r.execCommand("insertHTML",!1,"<p><br></p>")}else if(i&&r&&i.indexOf("delete")>-1){const e=t._resizeFrameObj;e&&e.target&&!n.contains(e.target)&&t._setResizeFrame()}n.textContent.length&&n.innerText.length?n.removeAttribute("show-placeholder"):n.setAttribute("show-placeholder",""),t.name&&e.target===t.$.editableElement&&"markdown"!==t.editMode&&(t.$.input.value=t._getInputValue(t.$.editableElement.innerHTML.trim())),t._setCharCount()}_beforeInputHandler(e){const t=this,o=t.$.iframe,n=t.$.contentContainer,a=t.$.editableElement,i=(o?o.contentWindow:window).getSelection(),r=i.rangeCount>0?i.getRangeAt(0):null;if(!r)return;const l=e.inputType,s=r.startContainer;let d;if(l&&(d=l.indexOf("delete")>-1,t._beforeInputObj={type:l,rangeDetails:{startOffset:r.startOffset,endOffset:r.endOffset,startContainer:r.startContainer,endContainer:r.endContainer}}),d&&a.contains(s))if(s===r.endContainer&&r.startOffset===r.endOffset){const e=t._resizeFrameObj;let o=s;if(e&&e.target&&e.target.contains(s))return;if(o.nodeType!==Node.TEXT_NODE&&o.innerHTML.length){if(o===a)return}else{let e=o.parentElement,t=o.previousElementSibling;for(;!t&&e;)t=e.previousElementSibling,e=e.parentElement;a!==t&&a.contains(t)&&!t.innerHTML.length&&t.nodeName}}else r.deleteContents(),e.preventDefault();if(!n.classList.contains("char-count-maxed")||d){if("insertParagraph"===l){const o=t._getSelectionRange().startContainer;if(o.nodeType===Node.TEXT_NODE&&o.parentElement===a){if(-1!==t.$.editableElement.innerHTML.indexOf("<")){const o=document.createElement("p");o.innerHTML="​";const n=document.createElement("span");n.id="INSERTION_MARKER",n.innerHTML=" ";let i=t._getSelectionRange(),r=i.endContainer;r.parentElement.insertBefore(o,i.endContainer.nextSibling),r.parentElement.insertBefore(n,o.nextSibling),t.selectRange(i);const l=a.getRootNode().querySelector("#INSERTION_MARKER");return t._setSelectionRange(l.previousElementSibling),i=t._getSelectionRange(),i.collapse(),l.remove(),e.preventDefault&&e.preventDefault(),!1}a.getRootNode().execCommand("formatBlock",!1,"p")}}}else e.preventDefault()}_changeHandler(e){const t=this,o=e.target,n=e.detail,a=o.closest(".smart-editor-toolbar-item");if(e.stopPropagation(),t._toolbarItemsObj||t._inlineToolbarItemsObj)return a&&o===t.$.inputPopup||o===t.$.colorInputPopup?(t._ignoreSelectionChange=!0,t._updateToolbarItem(a,n),void delete t._ignoreSelectionChange):void 0}_contextMenuHandler(e){const t=this,o=t.contextMenu;"browser"!==o?(e.preventDefault(),"none"!==o?t._openContextMenu(e):t._closeContextMenu()):t._closeContextMenu()}_closeContextMenu(){const e=this.$.inlineToolbar,t=this.$.fireEvent("dropDownToolbarClosing",{target:e}).defaultPrevented;e&&e.visible&&e.classList.contains("smart-editor-context-menu")&&!t&&e.close()}_openContextMenu(e){const t=this,o=e.target;let n=t.$.inlineToolbar;if(n||(n=t._createToolbar()),t.$.fireEvent("contextMenuOpening",{target:n}).defaultPrevented)return;t._setupToolbar(o,"context"),n.parentElement||t.getShadowRootOrBody().appendChild(n),n.clear(),t._setContextMenuContent(o);const a=t.getBoundingClientRect();n.style.left=Math.min(e.pageX+1,a.right+window.pageXOffset-n.offsetWidth)+"px",n.style.top=Math.min(e.pageY+1,a.bottom+window.pageYOffset-n.offsetHeight)+"px",n.open()}_setContextMenuContent(e){const t=this;if(!e)return;let o=t._contextList,n=t._getContextMenuTargetType(e),a=t._getContextMenuDataSource(e,n);o||(t._contextList=o=document.createElement("div"),o.classList.add("smart-editor-context-menu-item-container"));const i=document.createDocumentFragment(),r=a.length;let l=o.children;for(;l.length>r;)l[0].remove();l=Array.from(l);for(let o=0;o<r;o++){const r=a[o];let s,d,c=l[o];if("object"==typeof r?(s=r.label,d=r.value):s=d=r+"",c||(c=document.createElement("div"),c.classList.add("smart-editor-context-menu-item"),c.setAttribute("role","option")),c.removeAttribute("disabled"),"deleteLink"!==r||"image"!==n||e.closest(".smart-editor-editable a")){if("cut"===r||"copy"===r){const e=t._getSelectionRange();(void 0!==e.selectionStart?e.selectionStart:e.startOffset)===(void 0!==e.selectionEnd?e.selectionEnd:e.endOffset)&&c.setAttribute("disabled","")}}else c.setAttribute("disabled","");c.parentElement||i.appendChild(c),c.innerHTML=t.localize(s)||s,c.setAttribute("value",d)}o.appendChild(i),t.$.inlineToolbar.appendChild(o)}_getContextMenuTargetType(e){let t;return t=e.closest(".smart-editor-editable table")?"table":e.closest(".smart-editor-editable img")?"image":e.closest(".smart-editor-video-container")?"video":e.closest(".smart-editor-editable a")?"link":"text",t}_getContextMenuDataSource(e,t){if(!t)return[];const o=this.contextMenuDataSource;let n;switch(t){case"table":n=["tableProperties","insertRowAfter","insertRowBefore","insertColumnLeft","insertColumnRight","deleteRow","deleteColumn","deleteTable","selectAll"];break;case"image":n=["imageProperties","copyImage","cutImage","createLink","deleteLink","deleteImage","caption"];break;case"video":n=["videoProperties","copyVideo","cutVideo","deleteVideo","caption"];break;case"link":n=["linkProperties","deleteLink","selectAll"];break;default:n=["copy","cut","paste","selectAll"]}return o&&(n="function"==typeof o?o(e,t,n):Array.isArray(o)?o:[]),n}_updateToolbarItem(e,t){const o=this,n=o.editMode,a=e.getAttribute("item-name"),i=o.$.toolbarItemsPrimary,r=o.$.toolbarItemsSecondary,l=o.$.inlineToolbar,s="markdown"===n?o.$.input:o.$.editableElement,d=(e,n,a)=>{n&&(n.label=t["alignment"===n.name?"value":"label"],n.value=t.value,e&&o._setItemValue(e,n),a&&o._updateToolbarTarget(n))};if(l&&l.contains(e)?(d(e,o._inlineToolbarItemsObj[a],!0),o._toolbarItemsObj&&o._toolbarItemsObj[a]&&d(o.$.toolbar.querySelector(`.smart-editor-toolbar-item[item-name=${a}]`),o._toolbarItemsObj[a])):(i.contains(e)||r.contains(e))&&o._toolbarItemsObj&&(d(e,o._toolbarItemsObj[a],!0),l&&l.visible&&o._inlineToolbarItemsObj&&d(l.querySelector(`.smart-editor-toolbar-item[item-name=${a}]`),o._inlineToolbarItemsObj[a])),s.getRootNode().activeElement!==s){const e=o._selectionRange,t=s.scrollTop;e&&("markdown"===n?o._setSelectionRange(s,e.selectionStart,e.selectionEnd):o._setSelectionRange(e.startContainer,e.startOffset,e.endOffset)),s.focus({preventScroll:!0}),o._isSafari&&t&&(s.scrollTop=t)}}_updateToolbarTarget(e){const t=this,o=t._resizeFrameObj;if(!e)return;const n=t.$.inlineToolbar;let a;o&&o.target?a=o.target:n&&n.visible&&(a=n.selector,a=a.closest?a.closest(".smart-editor-editable img")||a.closest(".smart-editor-editable table"):void 0);const i=a?a.nodeName.toLowerCase():"";if(a&&"img"===i)return"alignment"===e.name&&(a.closest(".smart-editor-image-container")||a).setAttribute("alignment",e.value),t._setResizeFrame(a),void(n&&n.visible&&n.reposition());if(a&&"table"===i)return void t._handleTableToolbarAction(e,a);const r=t._getSelectionRange();if(r&&(r.startContainer||void 0!==r.selectionStart)){const o=e.name;if(t.$.fireEvent("actionStart",{name:o}).defaultPrevented)return;switch(o){case"backgroundcolor":t._handleBackgroundColor(e);break;case"fontcolor":t._handleFontColor(e);break;case"alignment":t._handleTextAlignment(e);break;case"fontsize":t._handleFontSize(e);break;case"fontname":t._handleFontName(e);break;case"formats":t._handleFormats(e);break;case"paste":t._handlePaste(e);break;default:{const t=r.startContainer.closest?r.startContainer:r.startContainer.parentElement;return void(t&&t.closest&&t.setAttribute(e.name,e.value))}}o&&t.$.fireEvent("actionEnd",{name:o})}}_setSelectionRange(e,t,o){const n=this,a=n.$.iframe,i=n.editMode;let r;if(n.disabled)return;if("markdown"===i||n.$.editableElement.classList.contains("smart-hidden")){r=n.$.input,n._selectionRange={selectionStart:void 0!==t?t:r.selectionStart,selectionEnd:void 0!==o?o:r.selectionEnd};const e=n._selectionRange;return void(n._selectionChangeFired||r.setSelectionRange(e.selectionStart,e.selectionEnd))}const l=(a?a.contentWindow:window).getSelection();let s;if(r=n.$.editableElement,e){if(s=document.createRange(),"number"==typeof t&&"number"==typeof o)try{s.setStart(e,parseInt(t)),s.setEnd(e,parseInt(o))}catch(t){s.selectNodeContents(e)}else"img"===e.nodeName.toLowerCase()||e.classList.contains("smart-editor-video-container")?(s.setStartBefore(e),s.setEndAfter(e),s.selectNode(e)):s.selectNodeContents(e);l.removeAllRanges(),l.addRange(s)}else l.rangeCount&&(s=l.getRangeAt(0));try{s&&s.startContainer&&r.contains(s.startContainer)&&(n._selectionRange=s)}catch(e){}n._selectionRange||(s=document.createRange(),s.selectNodeContents(r),s.collapse(!0),n._selectionRange=s)}_getSelectionRange(){const e=this,t=e.editMode;let o=e._selectionRange;return o&&("markdown"===t&&void 0===o.selectionStart||"html"===t&&void 0===o.startContainer)&&(delete e._selectionRange,o=void 0),o||e._setSelectionRange(),e._selectionRange}_setCharCount(){const e=this,t=e.$.contentContainer;if(!e.showCharCount)return void t.removeAttribute("char-count");const o=e.maxCharCount;let n,a;if("html"===e.editMode){const t=e.$.editableElement,o=t.textContent.length,n=t.innerText.length;a=n&&o?n:0}else a=e.$.input.value.length;if(n=e.charCountFormatFunction?e.charCountFormatFunction(a,o)+"":o?`${a} / ${o}`:a+"",t.setAttribute("char-count",n),null===o)return void t.classList.remove("char-count-low","char-count-medium");const i=parseFloat((a/o).toFixed(2));t.classList[i>=.7&&i<=.9?"add":"remove"]("char-count-warning"),t.classList[i>=.9?"add":"remove"]("char-count-error"),t.classList[a>=o?"add":"remove"]("char-count-maxed")}_documentDownHandler(e){const t=this,o=t.$.iframe,n=t.$.inlineToolbar,a=t.$.window,i=e.originalEvent||e,r=t.shadowRoot||t.isInShadowDOM?i.composedPath()[0]:i.target;if(t.contains(document.activeElement)){const e=t.getSelectionRange();t._editorSelectionRange=e}if(n&&n.contains(r)){const e=r.closest(".smart-editor-toolbar-item");return t._handleToolbarItemDown(e,r),void i.preventDefault()}if(t.$.container.contains(r)||o&&o.contentDocument.body.contains(r))return void t._handleDownInside(i,r);const l=r.closest(".smart-input-drop-down-menu");let s;if(l&&(s=l.ownerElement),a&&a.opened&&!a.contains(s||r)&&a.close(),t._handleTableSelection(),s&&(t.$.toolbarItemsPrimary.contains(s)||t.$.toolbarItemsSecondary.contains(s)||n&&n.contains(s)))return t._toolbarItemClick={},void i.preventDefault();t._setResizeFrame(),t._closePopups()}_handleDownInside(e,t){const o=this,n=e.originalEvent||e,a=t.closest(".smart-editor-toolbar-item"),i=o.$.inlineToolbar,r=t.classList.contains("smart-editor-video-container")?t:null,l=o.$.window;let s=o._editorVideoItemClick;if(s&&(r&&s.dragElement&&s.dragElement.remove(),delete o._editorVideoItemClick,s=void 0),t===o.$.toolbarToggleButton)o._toolbarItemClick={},e.preventDefault();else{if(a)return o._handleToolbarItemDown(a,t),void e.preventDefault();if(t.closest(".smart-editor-toolbar-tab"))e.preventDefault();else if(r)s||(s=o._editorVideoItemClick={target:t,originalSelectionRange:o._selectionRange}),e.preventDefault(),!1!==r.getAttribute("draggable")&&r.querySelector("video")?(s.dragElement=o._createWhiteSpaceChar(t,r),o._setSelectionRange(t)):s.dragElement&&(s.dragElement.remove(),delete s.dragElement);else if(t.closest(".smart-editor-search-bar"))o._searchBarDown={target:t},t.closest(".smart-search-input")||e.preventDefault();else{const e={x:n.pageX+window.pageXOffset,y:n.pageY+window.pageYOffset};l&&l.opened&&l.close();const a=o._getInlineToolbarTarget(t,e);if(a){const t=o.$.contentContainer;t.contains(t.getRootNode().activeElement)||o._focusEditableElement(),o._handleInlineToolbarItemDown(a,e)}else!i||i.contains(t)&&i.classList.contains("smart-editor-drop-down-toolbar")||(o._closeToolbar(),o._handleTableSelection())}}o._closeToolbarItemDropDown(o.$.inputPopup),o._closeToolbarItemDropDown(o.$.colorInputPopup)}_handleToolbarItemDown(e,t){const o=this,n=o.$.inlineToolbar,a=o.$.window;if(!e)return;const i=e.getAttribute("item-type"),r=e.getAttribute("item-name");switch(!a||!a.opened||a._target&&a._target.item.name===r||a.close(),o._toolbarItemClick={toolbarItem:e},o._resizeFrameObj&&o._resizeFrameObj.target?o._toolbarItemClick.target=o._resizeFrameObj.target:o._setResizeFrame(),o._setSelectionRange(),i){case"button":["hyperlink","createlink","image","video"].includes(r)?o._toolbarItemClick.callback=o._toggleWindow:"table"===r&&(o._toolbarItemClick.callback=n&&n.contains(e)?o._toggleWindow:o._toggleDropDownToolbar);break;case"toggle":e.toggleAttribute("checked"),e.hasAttribute("checked")?e.setAttribute("aria-pressed",!0):e.setAttribute("aria-pressed",!1),o._closeToolbarItemDropDown(o.$.inputPopup),o._closeToolbarItemDropDown(o.$.colorInputPopup);break;case"drop-down":o._toolbarItemClick.callback=o._toggleItemDropDown;break;case"color-input":t.closest(".smart-editor-item-drop-down-button")&&(o._toolbarItemClick.callback=o._toggleItemDropDown)}}_handleInlineToolbarItemDown(e,t){const o=this,n=e.closest(".smart-editor-editable table"),a=o.$.editableElement;if(o._inlineToolbarClickObj&&o._inlineToolbarClickObj.target&&(o._inlineToolbarClickObj.target.removeAttribute("drag-id"),o._inlineToolbarClickObj.dragElement&&o._inlineToolbarClickObj.dragElement.removeAttribute("drag-id")),o._inlineToolbarClickObj={},e)if("img"===e.nodeName.toLowerCase())e.setAttribute("drag-id",Math.random().toString(36).substr(2,5));else if(e.classList.contains("smart-editor-video-container")){const t=e.querySelector("video, iframe");t&&(t.setAttribute("drag-id",Math.random().toString(36).substr(2,5)),o._inlineToolbarClickObj.dragElement=t)}if(n&&a.hasAttribute("table-cell-resize")){const i=a.getAttribute("table-cell-resize");o._inlineToolbarClickObj.resizeDetails={x:t.x,y:t.y,position:i,target:"vertical"===i?e.closest("tr"):e,table:n},e=void 0}o._handleTableSelection(e),o._inlineToolbarClickObj.target=e,o._inlineToolbarClickObj.dragTarget=e}_getInlineToolbarTarget(e,t){const o=this;let n,a=e.closest(".smart-editor-editable img")||e.closest(".smart-editor-editable a")||e.closest(".smart-editor-video-container");return a||(n=e.closest(".smart-editor-editable table"),n&&(a=e.closest(".smart-editor-editable td")||e.closest(".smart-editor-editable th"))),e.closest(".smart-editor-resize-frame")&&o._resizeFrameObj?(o._resizeFrameObj.resizeDetails={x:t.x,y:t.y,position:e.getAttribute("position")},a=o._resizeFrameObj.target):a&&(a&&"img"===a.nodeName.toLowerCase()||n||a.classList.contains("smart-editor-video-container"))||o._setResizeFrame(),a}_documentMoveHandler(e){const t=this,o=t._resizeFrameObj,n=t._inlineToolbarClickObj,a=e.originalEvent||e;o&&o.resizeDetails?t._handleFrameResize(a):n&&n.resizeDetails&&t._handleTableCellResize(a)}_touchmoveHandler(e){const t=this,o=t._resizeFrameObj;t._isMobile&&o&&o.target&&(o.resizeDetails?(e.preventDefault(),e.stopPropagation()):(t._closeToolbar(),t._setResizeFrame()))}_dragStartHandler(e){const t=this,o=t._resizeFrameObj,n=t._inlineToolbarClickObj;if(o&&o.resizeDetails||n&&n.resizeDetails)return e.preventDefault(),void delete t._dragDetails;if(!t.$.contentContainer.contains(e.target))return;if(!n||!n.target)return void e.preventDefault();const a=t._inlineToolbarClickObj.target;if(a&&(["img","table"].indexOf(a.nodeName.toLowerCase())>-1||a.classList.contains("smart-editor-video-container"))){if("false"===a.getAttribute("draggable"))return void e.preventDefault();const o=e.target,n=o.parentElement,i=o.closest(".smart-editor-image-container");t._closeToolbar(),t._setResizeFrame(),t._dragDetails={target:o,scrollTop:t.$.editableElement.scrollTop,container:i,anchor:n&&"a"===n.nodeName.toLowerCase()?n:void 0,caption:i?i.querySelector(".smart-editor-image-caption"):void 0}}}_dropHandler(){const e=this;e._isFireFox&&e._dragEndHandler()}_dragEndHandler(){const e=this,t=e.$.inlineToolbar,o=e._dragDetails;if(o){const n=o.target,a=o.container,i=e.$.editableElement,r=i.querySelector(`[drag-id="${n.getAttribute("drag-id")}"]`);if(r){const n=o.anchor;if(r.removeAttribute("drag-id"),a&&!a.contains(r)&&r.parentElement){const e=o.caption;let t=r.parentElement;if(t.classList.contains("smart-editor-video-container")){const e=t;t=t.parentElement,e.remove(),t.appendChild(r)}a.remove(),a.innerHTML="",t.insertBefore(a,r),a.appendChild(r),e&&a.appendChild(e)}n&&r.parentElement!==n&&(n.innerHTML="",r.parentElement.insertBefore(n,r),n.appendChild(r)),void 0!==o.scrollTop&&(i.scrollTop=o.scrollTop),requestAnimationFrame((()=>e._setResizeFrame(r)));const l=e._resizeFrameObj;if(e._editorVideoItemClick){const t=i.querySelectorAll('.smart-editor-video-white-space, div[pseudo="-webkit-media-controls"]');for(let e=0,o=t.length;e<o;e+=1)t[e].remove();delete e._editorVideoItemClick}(!t||t&&!t.visible)&&l&&l.target&&e._openInlineToolbar(l.target)}return void delete e._dragDetails}e._setSelectionRange();const n=e._getSelectionRange();n&&n.startOffset!==n.endOffset&&(e._handleInlineToolbar(n.startContainer),e._focusEditableElement())}_documentUpHandler(e){const t=this,o=t._resizeFrameObj,n=t.$.inlineToolbar,a=e.originalEvent||e,i=t.shadowRoot||t.isInShadowDOM?a.composedPath()[0]:a.target;if(o&&(o.resizeDetails&&o.target&&(o.target.removeAttribute("dragged"),t.$.fireEvent("resizeEnd",{target:o.target})),delete o.resizeDetails),t._dragDetails)return t._endInlineToolbarClick(),void delete t._toolbarItemClick;const r=t.$.iframe;if(t.$.container.contains(i)||n&&n.contains(i)||r&&r.contentDocument.body.contains(i)){const e=i.closest(".smart-editor-toolbar-item");e?t._handleToolbarUp(e):t._handleContentUp(a,i)}t._endInlineToolbarClick(),delete t._searchBarDown,delete t._dragDetails,delete t._toolbarItemClick}_handleToolbarUp(e){const t=this,o=t._toolbarItemClick,n=e.getAttribute("item-type");if(o&&o.toolbarItem===e){const e=o.toolbarItem;"custom"!==n&&(t._handleToolbarItemClick(event,e),t._focusEditableElement())}}_handleContentUp(e,t){const o=this,n=o._inlineToolbarClickObj,a=o.$.toolbarToggleButton,i=o._editorVideoItemClick,r=void 0!==e.button&&2===e.button;if(r||t!==a&&!a.contains(t))if(t.classList.contains("smart-editor-toolbar-tab"))o.$.toolbar.hasAttribute("expanded")?t.hasAttribute("checked")||o._selectToolbarTab(t):(o._selectToolbarTab(t),o._toggleSecondaryToolbar(t.hasAttribute("checked")));else if(i&&t.classList.contains("smart-editor-video-container")&&t===i.target)o._setResizeFrame(t),o._focusEditableElement();else if(n){const e=n.target;e&&(e===t||e.contains(t))&&(r?o._setResizeFrame(e):o._handleInlineToolbar(e),o._focusEditableElement())}else if(t&&"LI"===t.nodeName&&t.closest("UL[checklist]")){const e=o._getSelectionRange();e&&0===e.startOffset&&(t.hasAttribute("checked")?t.removeAttribute("checked"):t.setAttribute("checked",""))}else if(!r&&(o.$.editableElement.contains(t)||"markdown"===o.editMode&&t===o.$.input)){const e=o.$.iframe,t=e?e.contentWindow:window;requestAnimationFrame((()=>{e&&o._setSelectionRange();const n=o._getSelectionRange();if(n instanceof t.Range){let e=n.startContainer;n.startOffset!==n.endOffset&&(o._handleInlineToolbar(e),o._focusEditableElement())}}))}else!r&&t.closest(".smart-editor-search-bar")&&o._handleSearchButtonClick(t.closest(".smart-search-button"));else o._toggleToolbar(o.$.toolbar.hasAttribute("expanded"))}_toggleSecondaryToolbar(e){const t=this,o=t.$.toolbar,n=t.$.toolbarItemsPrimary,a=t.$.toolbarItemsSecondary,i=()=>{o.hasAttribute("expanded")?(a.classList.remove("smart-drop-down"),o.contains(a)||o.appendChild(a),a.style.top=""):(a.classList.add("smart-drop-down"),o.contains(a)&&o.parentElement.insertBefore(a,o.nextElementSibling),a.style.top=n.offsetTop+n.offsetHeight+"px")};if(!e&&(a.classList.add("smart-visibility-hidden"),t.hasAnimation))return a.addEventListener("transitionend",i,{once:!0}),void a.addEventListener("transitioncancel",i,{once:!0});i(),e&&(t._setToolbarGroupHeight(),a.classList.remove("smart-visibility-hidden"))}_setToolbarGroupHeight(){const e=this.$.toolbarItemsSecondary,t=e.children;if(e.style.height="","menu"===this.toolbarMode)return;let o;for(let e=0,n=t.length;e<n;e+=1){const n=t[e].offsetHeight;(void 0===o||o<n)&&(o=n)}void 0!==o&&(e.style.height=o+"px")}_endInlineToolbarClick(){const e=this,t=e._inlineToolbarClickObj;if(t){const o=t.resizeDetails;if(!e._dragDetails&&t.target&&(t.target.removeAttribute("drag-id"),t.dragElement&&t.dragElement.removeAttribute("drag-id")),o&&o.target){if("horizontal"===o.position){const e=o.cells,t=o.table.offsetWidth;e&&e.forEach((e=>{e.style.width&&(e.style.width=100*parseFloat((e.offsetWidth/t).toFixed(2))+"%")}))}e.$.editableElement.removeAttribute("table-cell-resize"),o.target.removeAttribute("resizing"),o.isInlineToolbarOpened&&e._handleInlineToolbar(o.target)}delete e._inlineToolbarClickObj}}_updateToolbarItems(e,t){const o=this;if(o._dragDetails||o.readonly||o.disabled)return;if("markdown"===o.editMode)return void o._updateToolbarItemsMarkdown(e);const n=o._getSelectionRange(),a=o.$.inlineToolbar;let i,r;if(!n)return;if(t||(t=o.$.toolbar),a&&t!==a&&!o.hideInlineToolbar&&a.visible&&(o._updateToolbarItems(e,a),i=!0),t!==o.$.toolbar||o.hideToolbar?i||o.hideInlineToolbar||(r=o._inlineToolbarItemsObj):r=o._toolbarItemsObj,!r)return;const l=o.$.editableElement;let s,d=n.startOffset>n.endOffset?n.endContainer:n.startContainer;if(d&&(d.closest||(d=d.parentElement),d&&d.closest)){e||(e=["alignment","bold","italic","strikethrough","underline","fontsize","fontname","formats","fontcolor","backgroundcolor","orderedlist","unorderedlist","checklist","subscript","superscript"]);for(let n=0,a=e.length;n<a;n+=1){const a=e[n],i=r[a];if(i){let e;if("alignment"===a)e=d.style.textAlign;else if("bold"===a)e=!!o._getNodeFromList(d,["b","strong","h1","h2","h3","h4","h5","h6"]);else if("italic"===a)e=!!o._getNodeFromList(d,["i"]);else if("underline"===a)e=!!o._getNodeFromList(d,["u"]);else if("strikethrough"===a)e=!!o._getNodeFromList(d,["strike"]);else if("fontsize"===a){const t=d.closest(".smart-editor-editable font");t&&(e=t.style.fontSize),e||(s||(s=window.getComputedStyle(d)),e=s.fontSize),e=parseInt(e),isNaN(e)&&(e="")}else if("fontname"===a){const t=d.closest(".smart-editor-editable font");t&&t.hasAttribute("face")?e=t.getAttribute("face"):(s||(s=window.getComputedStyle(d)),e=s.fontFamily.split(",")[0])}else if("formats"===a&&d!==l){const t=i.dataSource;if(e="",t){const n=t.map((e=>e.value));e=o._getNodeFromList(d,n)||""}}else if("fontcolor"===a){const t=d.closest(".smart-editor-editable font");t?e=t.color:(s||(s=window.getComputedStyle(d)),e=s.color)}else if("backgroundcolor"===a)e=o._getNodeBackgroundColor(d),e||(s||(s=window.getComputedStyle(d)),e=s.backgroundColor);else if("orderedlist"===a||"unorderedlist"===a){e=!!d.closest(`.smart-editor-editable ${"orderedlist"===a?"ol":"ul"} li`);const t=d.closest(`.smart-editor-editable ${"orderedlist"===a?"ol":"ul"} li`);t&&t.parentElement&&t.parentElement.hasAttribute("checklist")&&(e=!1)}else if("checklist"===a){e=!!d.closest(`.smart-editor-editable ${"orderedlist"===a?"ol":"ul"} li`);const t=d.closest(`.smart-editor-editable ${"orderedlist"===a?"ol":"ul"} li`);t&&t.hasAttribute("checklist")&&(e=!0)}else"subscript"===a?e=!!d.closest(".smart-editor-editable sub"):"superscript"===a&&(e=!!d.closest(".smart-editor-editable sup"));if(!e&&i.dataSource){const t=i.dataSource[0];t&&(e=t.value||t)}null!==e&&(i.value=e,o._setItemValue(t.querySelector(`.smart-editor-toolbar-item[item-name=${a}]`),i))}}}}_updateToolbarItemsMarkdown(e){const t=this,o=t._getSelectionRange();if(!o||void 0===o.selectionStart)return;const n=o.selectionStart;e||(e=["bold","italic","strikethrough","underline","formats","orderedlist","unorderedlist","subscript","superscript"]);for(let o=0,a=e.length;o<a;o+=1){const a=e[o],i=t._toolbarItemsObj[a];if(i){let e;if("bold"===a)e=!!t._getMarkdownItem(n,"**"),e||(e=!!t._getMarkdownItem(n,"__"));else if("italic"===a)e=!!t._getMarkdownItem(n,"*"),e||(e=!!t._getMarkdownItem(n,"_"));else if("strikethrough"===a)e=!!t._getMarkdownItem(n,"~~");else if("underline"===a)e=!!t._getMarkdownItem(n,"<ins>","</ins>");else if("formats"===a){const o=i.dataSource;if(e="",o){const a=o.map((e=>e.value));e:for(let o=0,i=a.length;o<i;o+=1)if(e=t._getMarkdownFormat(n,a[o]),e&&void 0!==e.formatName){e=e.formatName;break e}}}else"orderedlist"===a||"unorderedlist"===a?e=!!t._getMarkdownFormat(n,a):"subscript"===a?e=!!t._getMarkdownItem(n,"<sub>","</sub>"):"superscript"===a&&(e=!!t._getMarkdownItem(n,"<sup>","</sup>"));if(!e&&i.dataSource){const t=i.dataSource[0];t&&(e=t.value||t)}null!==e&&(i.value=e,t._setItemValue(t.$.toolbar.queryS