@@ -559,6 +559,59 @@ function RemoteFunctions(config) {
559559 return true ;
560560 }
561561
562+ /**
563+ * this function is to check if an element should show the edit text option
564+ * it is needed because edit text option doesn't make sense with many elements like images, videos, hr tag etc
565+ * @param {Element } element - DOM element to check
566+ * @returns {boolean } - true if we should show the edit text option otherwise false
567+ */
568+ function _shouldShowEditTextOption ( element ) {
569+ if ( ! element || ! element . tagName ) {
570+ return false ;
571+ }
572+
573+ const tagName = element . tagName . toLowerCase ( ) ;
574+
575+ // these are self-closing tags and don't allow any text content
576+ const voidElements = [
577+ "img" ,
578+ "br" ,
579+ "hr" ,
580+ "input" ,
581+ "meta" ,
582+ "link" ,
583+ "area" ,
584+ "base" ,
585+ "col" ,
586+ "embed" ,
587+ "source" ,
588+ "track" ,
589+ "wbr"
590+ ] ;
591+
592+ // these elements are non-editable as they have their own mechanisms
593+ const nonEditableElements = [
594+ "script" ,
595+ "style" ,
596+ "noscript" ,
597+ "canvas" ,
598+ "svg" ,
599+ "video" ,
600+ "audio" ,
601+ "iframe" ,
602+ "object" ,
603+ "button" ,
604+ "select" ,
605+ "textarea"
606+ ] ;
607+
608+ if ( voidElements . includes ( tagName ) || nonEditableElements . includes ( tagName ) ) {
609+ return false ;
610+ }
611+
612+ return true ;
613+ }
614+
562615 /**
563616 * This is for the advanced DOM options that appears when a DOM element is clicked
564617 * advanced options like: 'select parent', 'duplicate', 'delete'
@@ -601,8 +654,11 @@ function RemoteFunctions(config) {
601654 // the element that was clicked
602655 let elemBounds = this . element . getBoundingClientRect ( ) ;
603656
657+ // check if edit text option should be shown to determine box width
658+ const showEditTextOption = _shouldShowEditTextOption ( this . element ) ;
659+
604660 // the box width and the positions where it should be placed
605- const boxWidth = 106 ;
661+ const boxWidth = showEditTextOption ? 106 : 82 ;
606662 const scrollLeft = window . pageXOffset || document . documentElement . scrollLeft ;
607663 const scrollTop = window . pageYOffset || document . documentElement . scrollTop ;
608664
@@ -666,11 +722,15 @@ function RemoteFunctions(config) {
666722 let content = `<div class="node-options">
667723 <span data-action="select-parent" title="Select Parent">
668724 ${ ICONS . arrowUp }
669- </span>
670- <span data-action="edit-text" title="Edit Text">
725+ </span>` ;
726+
727+ if ( showEditTextOption ) { // to check if the element is editable
728+ content += `<span data-action="edit-text" title="Edit Text">
671729 ${ ICONS . edit }
672- </span>
673- <span data-action="duplicate" title="Duplicate">
730+ </span>` ;
731+ }
732+
733+ content += `<span data-action="duplicate" title="Duplicate">
674734 ${ ICONS . copy }
675735 </span>
676736 <span data-action="delete" title="Delete">
0 commit comments