From 7f88dbab9051fa9845f5b07b6fd74ac1f40d00eb Mon Sep 17 00:00:00 2001 From: Alan Date: Fri, 17 Feb 2023 15:36:54 +0800 Subject: [PATCH] sync values before triggering delete --- Roo/bootstrap/form/HtmlEditorToolbar/Standard.js | 5 +++++ roojs-bootstrap-debug.js | 5 +++++ roojs-bootstrap.js | 14 +++++++------- 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/Roo/bootstrap/form/HtmlEditorToolbar/Standard.js b/Roo/bootstrap/form/HtmlEditorToolbar/Standard.js index 72ccc6800b..1ae985461b 100644 --- a/Roo/bootstrap/form/HtmlEditorToolbar/Standard.js +++ b/Roo/bootstrap/form/HtmlEditorToolbar/Standard.js @@ -231,6 +231,7 @@ Roo.extend(Roo.bootstrap.form.HtmlEditorToolbar.Standard, Roo.bootstrap.nav.Simp if (!far.length) { if (fire_add) { + this.editor.syncValue(); editor.owner.fireEvent('editorevent', editor.owner, false); editor.owner.fireEvent('imageadd', editor.owner, false); } @@ -255,6 +256,7 @@ Roo.extend(Roo.bootstrap.form.HtmlEditorToolbar.Standard, Roo.bootstrap.nav.Simp bl.image_src = reader.result; //bl.caption = f.name; bl.updateElement(sn); + this.editor.syncValue(); editor.owner.fireEvent('editorevent', editor.owner, false); editor.owner.fireEvent('imageupdate', editor.owner, sn); // we only do the first file!! and replace. @@ -273,6 +275,7 @@ Roo.extend(Roo.bootstrap.form.HtmlEditorToolbar.Standard, Roo.bootstrap.nav.Simp // just a standard img.. if (sn && sn.tagName.toUpperCase() == 'IMG') { sn.src = reader.result; + this.editor.syncValue(); editor.owner.fireEvent('editorevent', editor.owner, false); editor.owner.fireEvent('imageupdate', editor.owner, sn); return; @@ -445,6 +448,7 @@ Roo.extend(Roo.bootstrap.form.HtmlEditorToolbar.Standard, Roo.bootstrap.nav.Simp selection.addRange(range); this.updateToolbar(null, null, null); if (sn.tagName.toUpperCase() == 'FIGURE') { + this.editor.syncValue(); this.editor.fireEvent('imagedelete', this.editor, sn); } @@ -469,6 +473,7 @@ Roo.extend(Roo.bootstrap.form.HtmlEditorToolbar.Standard, Roo.bootstrap.nav.Simp selection.removeAllRanges(); selection.addRange(range); if (sn.tagName.toUpperCase() == 'IMG"') { + this.editor.syncValue(); this.editor.fireEvent('imagedelete', this.editor, sn); } diff --git a/roojs-bootstrap-debug.js b/roojs-bootstrap-debug.js index c03f007e07..e47a90ad09 100644 --- a/roojs-bootstrap-debug.js +++ b/roojs-bootstrap-debug.js @@ -33134,6 +33134,7 @@ Roo.extend(Roo.bootstrap.form.HtmlEditorToolbar.Standard, Roo.bootstrap.nav.Simp if (!far.length) { if (fire_add) { + this.editor.syncValue(); editor.owner.fireEvent('editorevent', editor.owner, false); editor.owner.fireEvent('imageadd', editor.owner, false); } @@ -33158,6 +33159,7 @@ Roo.extend(Roo.bootstrap.form.HtmlEditorToolbar.Standard, Roo.bootstrap.nav.Simp bl.image_src = reader.result; //bl.caption = f.name; bl.updateElement(sn); + this.editor.syncValue(); editor.owner.fireEvent('editorevent', editor.owner, false); editor.owner.fireEvent('imageupdate', editor.owner, sn); // we only do the first file!! and replace. @@ -33176,6 +33178,7 @@ Roo.extend(Roo.bootstrap.form.HtmlEditorToolbar.Standard, Roo.bootstrap.nav.Simp // just a standard img.. if (sn && sn.tagName.toUpperCase() == 'IMG') { sn.src = reader.result; + this.editor.syncValue(); editor.owner.fireEvent('editorevent', editor.owner, false); editor.owner.fireEvent('imageupdate', editor.owner, sn); return; @@ -33348,6 +33351,7 @@ Roo.extend(Roo.bootstrap.form.HtmlEditorToolbar.Standard, Roo.bootstrap.nav.Simp selection.addRange(range); this.updateToolbar(null, null, null); if (sn.tagName.toUpperCase() == 'FIGURE') { + this.editor.syncValue(); this.editor.fireEvent('imagedelete', this.editor, sn); } @@ -33372,6 +33376,7 @@ Roo.extend(Roo.bootstrap.form.HtmlEditorToolbar.Standard, Roo.bootstrap.nav.Simp selection.removeAllRanges(); selection.addRange(range); if (sn.tagName.toUpperCase() == 'IMG"') { + this.editor.syncValue(); this.editor.fireEvent('imagedelete', this.editor, sn); } diff --git a/roojs-bootstrap.js b/roojs-bootstrap.js index bb37c5dacc..29c75def07 100644 --- a/roojs-bootstrap.js +++ b/roojs-bootstrap.js @@ -1423,9 +1423,9 @@ F('list-ol','insertorderedlist',true);F('pencil',false,true,function(G){Roo.log( i'); +if(!A.length){if(B){this.editor.syncValue();C.owner.fireEvent('editorevent',C.owner,false);C.owner.fireEvent('imageadd',C.owner,false);}return;}var f=A.pop();if(!f.type.match(/^image/)){this.addFiles(A,B);return;}var sn=this.selectedNode;var bl=sn&&this.editorcore.enableBlocks?Roo.htmleditor.Block.factory(sn):false; +var D=new FileReader();D.addEventListener('load',(function(){if(bl){bl.image_src=D.result;bl.updateElement(sn);this.editor.syncValue();C.owner.fireEvent('editorevent',C.owner,false);C.owner.fireEvent('imageupdate',C.owner,sn);return;}if(this.editorcore.enableBlocks){var E=new Roo.htmleditor.BlockFigure({image_src:D.result,caption:'',caption_display:'none'} +);C.insertAtCursor(E.toHTML());this.addFiles(A,true);return;}if(sn&&sn.tagName.toUpperCase()=='IMG'){sn.src=D.result;this.editor.syncValue();C.owner.fireEvent('editorevent',C.owner,false);C.owner.fireEvent('imageupdate',C.owner,sn);return;}C.insertAtCursor(''); this.addFiles(A,true);}).createDelegate(this));D.readAsDataURL(f);},onBtnClick:function(id){this.editorcore.relayCmd(id);this.editorcore.focus();},onLinkClick:function(A){var B=this.selectedNode&&this.selectedNode.tagName.toUpperCase()=='A'?this.selectedNode.getAttribute('href'):''; Roo.bootstrap.MessageBox.show({title:"Add / Edit Link URL",msg:"Enter the URL for the link",buttons:Roo.bootstrap.MessageBox.OKCANCEL,minWidth:250,scope:this,prompt:true,multiline:false,modal:true,value:B,fn:function(C,D){if(C!='ok'){this.editorcore.focus(); return;}if(B!=''){this.selectedNode.setAttribute('href',D);return;}if(D&&D.match(/http(s):\/\/.+/)){this.editorcore.relayCmd('createlink',D);}this.editorcore.focus();}});},updateToolbar:function(A,ev,B){if(!this.editorcore.activated){this.editor.onFirstFocus(); @@ -1435,10 +1435,10 @@ return;}var C=this.buttons;var D=this.editorcore.doc;var E=false;C.each(function });var H=false;if(db&&this.editorcore.enableBlocks){H=Roo.htmleditor.Block.factory(db);if(H){db.className=(db.classList.length>0?db.className+' ':'')+' roo-ed-selection';B=this.selectedNode=db;}}var tn=B&&B.tagName.toUpperCase()||'';if(!H&&B&&tn!='A'){var I=B.closest('A'); if(I){B=I;}}C.get('link').setActive(tn=='A'&&this.selectedNode.hasAttribute('href'));C.get('image').setActive(tn=='IMG'||this.editorcore.enableBlocks&&tn=='FIGURE');C.get('underline').setActive(tn=='U'||B.closest('u')?true:false);Roo.bootstrap.menu.Manager.hideAll(); if(E||(tn.length&&tn=='BODY')){this.deleteBtn.hide();return;}this.deleteBtn.show();},onFirstFocus:function(){this.buttons.each(function(A){A.enable();});},onDelete:function(){var A=this.editorcore.createRange();var B=this.editorcore.getSelection();var sn=this.selectedNode; -A.setStart(sn,0);A.setEnd(sn,0);if(sn.hasAttribute('data-block')){var C=Roo.htmleditor.Block.factory(this.selectedNode);if(C){sn=C.removeNode();sn.parentNode.removeChild(sn);B.removeAllRanges();B.addRange(A);this.updateToolbar(null,null,null);if(sn.tagName.toUpperCase()=='FIGURE'){this.editor.fireEvent('imagedelete',this.editor,sn); -}this.selectedNode=false;this.editorcore.fireEditorEvent(false);return;}}if(!sn){return;}if(sn&&sn.tagName=='BODY'){return;}var D=sn.childNodes[0]||sn.nextSibling||sn.previousSibling||sn.parentNode;a=new Roo.htmleditor.FilterKeepChildren({tag:false});a.replaceTag(sn); -B.removeAllRanges();B.addRange(A);if(sn.tagName.toUpperCase()=='IMG"'){this.editor.fireEvent('imagedelete',this.editor,sn);}this.selectedNode=false;this.editorcore.fireEditorEvent(false);},toggleSourceEdit:function(A){if(A){Roo.log("disabling buttons");this.buttons.each(function(B){if(B.cmd!='pencil'){B.disable(); -}});}else{Roo.log("enabling buttons");if(this.editorcore.initialized){this.buttons.each(function(B){B.enable();});}}Roo.log("calling toggole on editor");this.editor.toggleSourceEdit(A);}}); +A.setStart(sn,0);A.setEnd(sn,0);if(sn.hasAttribute('data-block')){var C=Roo.htmleditor.Block.factory(this.selectedNode);if(C){sn=C.removeNode();sn.parentNode.removeChild(sn);B.removeAllRanges();B.addRange(A);this.updateToolbar(null,null,null);if(sn.tagName.toUpperCase()=='FIGURE'){this.editor.syncValue(); +this.editor.fireEvent('imagedelete',this.editor,sn);}this.selectedNode=false;this.editorcore.fireEditorEvent(false);return;}}if(!sn){return;}if(sn&&sn.tagName=='BODY'){return;}var D=sn.childNodes[0]||sn.nextSibling||sn.previousSibling||sn.parentNode;a=new Roo.htmleditor.FilterKeepChildren({tag:false} +);a.replaceTag(sn);B.removeAllRanges();B.addRange(A);if(sn.tagName.toUpperCase()=='IMG"'){this.editor.syncValue();this.editor.fireEvent('imagedelete',this.editor,sn);}this.selectedNode=false;this.editorcore.fireEditorEvent(false);},toggleSourceEdit:function(A){if(A){Roo.log("disabling buttons"); +this.buttons.each(function(B){if(B.cmd!='pencil'){B.disable();}});}else{Roo.log("enabling buttons");if(this.editorcore.initialized){this.buttons.each(function(B){B.enable();});}}Roo.log("calling toggole on editor");this.editor.toggleSourceEdit(A);}}); // Roo/bootstrap/form/Markdown.js Roo.bootstrap.form.Markdown=function(A){Roo.bootstrap.form.Markdown.superclass.constructor.call(this,A);};Roo.extend(Roo.bootstrap.form.Markdown,Roo.bootstrap.form.TextArea,{editing:false,initEvents:function(){Roo.bootstrap.form.TextArea.prototype.initEvents.call(this); this.markdownEl=this.el.createChild({cls:'roo-markdown-area'});this.inputEl().addClass('d-none');if(this.getValue()==''){this.markdownEl.dom.innerHTML=String.format('{0}',this.placeholder||'');}else{this.markdownEl.dom.innerHTML=Roo.Markdown.toHtml(Roo.util.Format.htmlEncode(this.getValue())); -- 2.39.2