diff --git a/assets/js/admin/editor.js b/assets/js/admin/editor.js index a919256..b260783 100644 --- a/assets/js/admin/editor.js +++ b/assets/js/admin/editor.js @@ -135,18 +135,18 @@ wp.hooks.addFilter('editor.BlockEdit', 'easytts/toolbar-button', withToolbarButt }); - $('.easytts-classic-editor-btn').on('click', function (e) { - let tinyMceActive = isTinyMCEActive(); + $(document).on('click', '.easytts-classic-editor-btn', function (e) { + const editorID = $(this).data('editor-id') || 'content'; + let tinyMceActive = isTinyMCEActive(editorID); let voiceContent = ''; if (tinyMceActive) { - voiceContent = getTinymceContent(); + voiceContent = getTinymceContent(editorID); } else { - const selectedText = getSelectedText($('#content')); - voiceContent = selectedText ? selectedText.trim() : $('#content').val(); + const selectedText = getSelectedText($('#' + editorID)); + voiceContent = selectedText ? selectedText.trim() : $('#' + editorID).val(); voiceContent = getTrimmedText(voiceContent); } - const editorID = $(this).data('editor-id'); $('#easytts-editor-id').val(editorID); $('#easytts-content').text(voiceContent); diff --git a/dist/js/editor.asset.php b/dist/js/editor.asset.php index 9d7c873..398e7f3 100644 --- a/dist/js/editor.asset.php +++ b/dist/js/editor.asset.php @@ -1 +1 @@ - array('jquery', 'wp-element'), 'version' => '1e64b004503b66f3c05f'); + array('jquery', 'wp-element'), 'version' => '5f46ee7d3300e71b3ad6'); diff --git a/dist/js/editor.js b/dist/js/editor.js index 4017eb9..0c4c14a 100644 --- a/dist/js/editor.js +++ b/dist/js/editor.js @@ -1 +1 @@ -!function(){var e={579:function(){function e(t){return e="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},e(t)}!function(){"use strict";"object"!==e(window.SUI)&&(window.SUI={});var t=t||{};t.KeyCode={BACKSPACE:8,TAB:9,RETURN:13,ESC:27,SPACE:32,PAGE_UP:33,PAGE_DOWN:34,END:35,HOME:36,LEFT:37,UP:38,RIGHT:39,DOWN:40,DELETE:46},t.Utils=t.Utils||{},t.Utils.remove=function(e){return e.remove&&"function"===typeof e.remove?e.remove():!(!e.parentNode||!e.parentNode.removeChild||"function"!==typeof e.parentNode.removeChild)&&e.parentNode.removeChild(e)},t.Utils.isFocusable=function(e){if(04&&void 0!==arguments[4])||arguments[4],n=!(arguments.length>5&&void 0!==arguments[5])||arguments[5];if(this.dialogNode=document.getElementById(o),null===this.dialogNode)throw new Error('No element found with id="'+o+'".');var l=["dialog","alertdialog"];if(!(this.dialogNode.getAttribute("role")||"").trim().split(/\s+/g).some((function(e){return l.some((function(t){return e===t}))})))throw new Error("Dialog() requires a DOM element with ARIA role of dialog or alertdialog.");this.isCloseOnEsc=d;var r=new Event("open");this.dialogNode.dispatchEvent(r);var c="sui-modal";if(this.dialogNode.parentNode.classList.contains(c)?this.backdropNode=this.dialogNode.parentNode:(this.backdropNode=document.createElement("div"),this.backdropNode.className=c,this.backdropNode.setAttribute("data-markup","new"),this.dialogNode.parentNode.insertBefore(this.backdropNode,this.dialogNodev),this.backdropNode.appendChild(this.dialogNode)),this.backdropNode.classList.add("sui-active"),document.body.parentNode.classList.add(t.Utils.dialogOpenClass),"string"===typeof a)this.focusAfterClosed=document.getElementById(a);else{if("object"!==e(a))throw new Error("the focusAfterClosed parameter is required for the aria.Dialog constructor.");this.focusAfterClosed=a}"string"===typeof i?this.focusFirst=document.getElementById(i):"object"===e(i)?this.focusFirst=i:this.focusFirst=null;var u=document.createElement("div");this.preNode=this.dialogNode.parentNode.insertBefore(u,this.dialogNode),this.preNode.tabIndex=0,"boolean"===typeof s&&!0===s&&(this.preNode.classList.add("sui-modal-overlay"),this.preNode.onclick=function(){t.getCurrentDialog().close()});var m=document.createElement("div");this.postNode=this.dialogNode.parentNode.insertBefore(m,this.dialogNode.nextSibling),this.postNode.tabIndex=0,00&&void 0!==arguments[0])||arguments[0],o=this,a=new Event("close");this.dialogNode.dispatchEvent(a),t.OpenDialogList.pop(),this.removeListeners(),this.preNode.parentNode.removeChild(this.preNode),this.postNode.parentNode.removeChild(this.postNode),e?(this.dialogNode.classList.add("sui-content-fade-out"),this.dialogNode.classList.remove("sui-content-fade-in")):(this.dialogNode.classList.remove("sui-content-fade-in"),this.dialogNode.classList.remove("sui-content-fade-out")),this.focusAfterClosed.focus(),setTimeout((function(){o.backdropNode.classList.remove("sui-active")}),300),setTimeout((function(){var e=o.dialogNode.querySelectorAll(".sui-modal-slide");if(04&&void 0!==arguments[4])||arguments[4],d=!(arguments.length>5&&void 0!==arguments[5])||arguments[5],n=this;t.OpenDialogList.pop(),this.removeListeners(),t.Utils.remove(this.preNode),t.Utils.remove(this.postNode),d?(this.dialogNode.classList.add("sui-content-fade-in"),this.dialogNode.classList.remove("sui-content-fade-out")):(this.dialogNode.classList.remove("sui-content-fade-in"),this.dialogNode.classList.remove("sui-content-fade-out")),this.backdropNode.classList.remove("sui-active"),setTimeout((function(){var e=n.dialogNode.querySelectorAll(".sui-modal-slide");if(04&&void 0!==arguments[4])||arguments[4],d=arguments.length>5?arguments[5]:void 0;new t.Dialog(e,o,a,i,s,d)},SUI.closeModal=function(e){t.getCurrentDialog().close(e)},SUI.replaceModal=function(e,o,a,i){var s=!(arguments.length>4&&void 0!==arguments[4])||arguments[4],d=arguments.length>5?arguments[5]:void 0;t.getCurrentDialog().replace(e,o,a,i,s,d)},SUI.slideModal=function(e,o,a){t.getCurrentDialog().slide(e,o,a)}}(),function(t){"use strict";"object"!==e(window.SUI)&&(window.SUI={}),SUI.modalDialog=function(){return function(){var o,a,i,s,d,n,l,r,c,u,m,g;a=t("[data-modal-open]"),i=t("[data-modal-close]"),s=t("[data-modal-replace]"),d=t("[data-modal-slide]"),n=t(".sui-modal-overlay"),a.on("click",(function(a){o=t(this),l=o.attr("data-modal-open"),c=o.attr("data-modal-close-focus"),u=o.attr("data-modal-open-focus"),n=o.attr("data-modal-mask"),g=o.attr("data-modal-animated");var i="false"!==o.attr("data-esc-close");"undefined"!==e(c)&&!1!==c&&""!==c||(c=this),"undefined"!==e(u)&&!1!==u&&""!==u||(u=void 0),n="undefined"!==e(n)&&!1!==n&&"true"===n,g="undefined"===e(g)||!1===g||"false"!==g,"undefined"!==e(l)&&!1!==l&&""!==l&&SUI.openModal(l,c,u,n,i,g),a.preventDefault()})),s.on("click",(function(a){o=t(this),l=o.attr("data-modal-replace"),c=o.attr("data-modal-close-focus"),u=o.attr("data-modal-open-focus"),n=o.attr("data-modal-replace-mask");var i="false"!==o.attr("data-esc-close");"undefined"!==e(c)&&!1!==c&&""!==c||(c=void 0),"undefined"!==e(u)&&!1!==u&&""!==u||(u=void 0),n="undefined"!==e(n)&&!1!==n&&"true"===n,"undefined"!==e(l)&&!1!==l&&""!==l&&SUI.replaceModal(l,c,u,n,i,g),a.preventDefault()})),d.on("click",(function(a){o=t(this),r=o.attr("data-modal-slide"),u=o.attr("data-modal-slide-focus"),m=o.attr("data-modal-slide-intro"),"undefined"!==e(u)&&!1!==u&&""!==u||(u=void 0),"undefined"!==e(m)&&!1!==m&&""!==m||(m=""),"undefined"!==e(r)&&!1!==r&&""!==r&&SUI.slideModal(r,u,m),a.preventDefault()})),i.on("click",(function(e){SUI.closeModal(g),e.preventDefault()}))}(),this},SUI.modalDialog()}(jQuery)}},t={};function o(a){var i=t[a];if(void 0!==i)return i.exports;var s=t[a]={exports:{}};return e[a](s,s.exports,o),s.exports}o.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return o.d(t,{a:t}),t},o.d=function(e,t){for(var a in t)o.o(t,a)&&!o.o(e,a)&&Object.defineProperty(e,a,{enumerable:!0,get:t[a]})},o.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},function(){"use strict";var e=window.wp.element,t=window.jQuery,a=o.n(t);o(579);const i=e=>e.replace(/<[^>]*>?/gm,"").replace(/[ ]+/g," "),s=(e,t="error")=>`
\n\t\t\t\t\t\t\t
\n\t\t\t\t\t\t\t\t
\n\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\t

${e}

\n\t\t\t\t\t\t\t\t
\n\t\t\t\t\t\t\t
\n\t\t\t\t\t\t
`,d=e=>{const t=e.prop("selectionStart"),o=e.prop("selectionEnd");return e.val().substring(t,o)},n=()=>!!EasyTTSEditor.isBlockEditor&&EasyTTSEditor.isBlockEditor,{__:l}=wp.i18n,r=["core/paragraph","core/heading"],{createHigherOrderComponent:c}=wp.compose,{Fragment:u,useState:m}=wp.element,{BlockControls:g}=wp.blockEditor,{ToolbarGroup:p,ToolbarButton:f,Icon:v}=wp.components,h=c((t=>o=>{if(!r.includes(o.name))return(0,e.createElement)(t,o);const{setAttributes:i}=o;return(0,e.createElement)(u,null,(0,e.createElement)(g,{group:"block"},(0,e.createElement)(p,null,(0,e.createElement)(f,{icon:(0,e.createElement)(v,{icon:"controls-volumeon"}),label:l("Text-to-Speech","easy-text-to-speech"),showTooltip:"true",onClick:()=>{let e=(()=>{let e=window.getSelection().toString();if(!e){e=a()(".wp-block-post-content").text();let t=wp.data.select("core/block-editor").getBlocks(),o="";t.length>0&&(t.forEach((function(e){r.includes(e.name)&&(o+=e.attributes.content+"\n\n")})),e=o)}return e})(),t=a()("#easytts-content");a()("#generate_voice_result_msg").html(""),t.val(""),e=t.html(e).text(),e=e.replace(/(<([^>]+)>)/gi,""),t.val(e),window.SUI.openModal("easytts-modal","wpbody-content",void 0,!0)}}))),(0,e.createElement)(t,o))}),"withToolbarButton");var b;wp.hooks.addFilter("editor.BlockEdit","easytts/toolbar-button",h,99),(b=a())(".aws_polly_engine_for_content").on("change",(function(e){e.preventDefault();const t=b("#generate_voice_result_msg");b.post(ajaxurl,{beforeSend(){a()("#aws_polly_voice").attr("disabled","disabled"),t.html("")},action:"easytts_voice_list",nonce:b("#content_nonce").val(),engine:b(this).val()},(function(e){if(e.success)b("#aws_polly_voice").html(e.data.html);else{b("#aws_polly_voice").html("");const o=s(e.data.message,"error");t.html(o)}})).done((function(){a()("#aws_polly_voice").attr("disabled",!1)}))})),b(".easytts-classic-editor-btn").on("click",(function(e){let t="";if(a()("#wp-content-wrap").hasClass("tmce-active"))t=((e,t)=>{if("undefined"==typeof e&&(e=wpActiveEditor),"undefined"==typeof t&&(t=e),a()("#wp-"+e+"-wrap").hasClass("tmce-active")&&tinyMCE.get(e)){const t=tinyMCE.get(e).selection.getContent({format:"text"});return t?t.trim():tinyMCE.get(e).getContent({format:"text"})}{const e=d(a()("#"+t));return i(e||a()("#"+t).val())}})();else{const e=d(b("#content"));t=e?e.trim():b("#content").val(),t=i(t)}const o=b(this).data("editor-id");b("#easytts-editor-id").val(o),b("#easytts-content").text(t),SUI.openModal("easytts-modal",this,void 0,!0,!0,!1)})),b(document).on("click","#easytts-modal-close",(function(e){e.preventDefault(),a()(".wp-toolbar").removeClass("sui-has-modal"),a()(".sui-modal").removeClass("sui-active"),window.SUI.closeModal()})),b(document).on("easytts-audio-generated",(function(e){a()(".wp-toolbar").removeClass("sui-has-modal"),a()(".sui-modal").removeClass("sui-active"),window.SUI.closeModal()})),b(document).on("submit","#easytts-voice-generator-form",(function(e){e.preventDefault();const t=b("#generate_voice_result_msg"),o=b("#easytts-generate-voice"),i=b("#easytts-editor-id").val();b.post(ajaxurl,{beforeSend(){t.html(""),o.addClass("sui-button-onload-text")},action:"easytts_generate_voice",nonce:b("#content_nonce").val(),data:b("#easytts-voice-generator-form").serialize(),title:n()?wp.data.select("core/editor").getEditedPostAttribute("title"):a()("#titlewrap").find("input").val()},(function(e){if(e.success){if(b(document).trigger("easytts-audio-generated"),n()){let t="core/audio",o=wp.blocks.createBlock(t,{id:e.data.attachment_id,src:e.data.attachment_url,caption:b("#easytts_tts_disclosure").val()});return void wp.data.dispatch("core/block-editor").insertBlocks(o)}if(wp&&wp.media&&wp.media.editor){wpActiveEditor&&tinyMCE&&tinyMCE.get(wpActiveEditor).selection.collapse(),wp.media.editor.activeEditor=i;let t=wp.media.editor.get(i);(!t||t.options&&t.state!==t.options.state)&&(t=wp.media.editor.add(i,{})),wp.media.frame=t,wp.media.frame.content.mode("browse"),wp.media.frame.on("open",(function(){null!==wp.media.frame.content.get()&&(wp.media.frame.content.get().collection._requery(!0),wp.media.frame.content.get().options.selection.reset());let t=wp.media.frame.state().get("selection"),o=wp.media.attachment(e.data.attachment_id);o.set("type","audio"),o.set("filename","easytts.mp3"),o.set("meta",{bitrate:48e3,bitrate_mode:"cbr"}),t.multiple=!1,t.add(o)}),this),wp.media.frame.open()}}else{const o=s(e.data.message,"error");t.html(o)}})).done((function(){o.removeClass("sui-button-onload-text")}))}))}()}(); \ No newline at end of file +!function(){var e={579:function(){function e(t){return e="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},e(t)}!function(){"use strict";"object"!==e(window.SUI)&&(window.SUI={});var t=t||{};t.KeyCode={BACKSPACE:8,TAB:9,RETURN:13,ESC:27,SPACE:32,PAGE_UP:33,PAGE_DOWN:34,END:35,HOME:36,LEFT:37,UP:38,RIGHT:39,DOWN:40,DELETE:46},t.Utils=t.Utils||{},t.Utils.remove=function(e){return e.remove&&"function"===typeof e.remove?e.remove():!(!e.parentNode||!e.parentNode.removeChild||"function"!==typeof e.parentNode.removeChild)&&e.parentNode.removeChild(e)},t.Utils.isFocusable=function(e){if(04&&void 0!==arguments[4])||arguments[4],n=!(arguments.length>5&&void 0!==arguments[5])||arguments[5];if(this.dialogNode=document.getElementById(o),null===this.dialogNode)throw new Error('No element found with id="'+o+'".');var l=["dialog","alertdialog"];if(!(this.dialogNode.getAttribute("role")||"").trim().split(/\s+/g).some((function(e){return l.some((function(t){return e===t}))})))throw new Error("Dialog() requires a DOM element with ARIA role of dialog or alertdialog.");this.isCloseOnEsc=d;var r=new Event("open");this.dialogNode.dispatchEvent(r);var c="sui-modal";if(this.dialogNode.parentNode.classList.contains(c)?this.backdropNode=this.dialogNode.parentNode:(this.backdropNode=document.createElement("div"),this.backdropNode.className=c,this.backdropNode.setAttribute("data-markup","new"),this.dialogNode.parentNode.insertBefore(this.backdropNode,this.dialogNodev),this.backdropNode.appendChild(this.dialogNode)),this.backdropNode.classList.add("sui-active"),document.body.parentNode.classList.add(t.Utils.dialogOpenClass),"string"===typeof a)this.focusAfterClosed=document.getElementById(a);else{if("object"!==e(a))throw new Error("the focusAfterClosed parameter is required for the aria.Dialog constructor.");this.focusAfterClosed=a}"string"===typeof i?this.focusFirst=document.getElementById(i):"object"===e(i)?this.focusFirst=i:this.focusFirst=null;var u=document.createElement("div");this.preNode=this.dialogNode.parentNode.insertBefore(u,this.dialogNode),this.preNode.tabIndex=0,"boolean"===typeof s&&!0===s&&(this.preNode.classList.add("sui-modal-overlay"),this.preNode.onclick=function(){t.getCurrentDialog().close()});var m=document.createElement("div");this.postNode=this.dialogNode.parentNode.insertBefore(m,this.dialogNode.nextSibling),this.postNode.tabIndex=0,00&&void 0!==arguments[0])||arguments[0],o=this,a=new Event("close");this.dialogNode.dispatchEvent(a),t.OpenDialogList.pop(),this.removeListeners(),this.preNode.parentNode.removeChild(this.preNode),this.postNode.parentNode.removeChild(this.postNode),e?(this.dialogNode.classList.add("sui-content-fade-out"),this.dialogNode.classList.remove("sui-content-fade-in")):(this.dialogNode.classList.remove("sui-content-fade-in"),this.dialogNode.classList.remove("sui-content-fade-out")),this.focusAfterClosed.focus(),setTimeout((function(){o.backdropNode.classList.remove("sui-active")}),300),setTimeout((function(){var e=o.dialogNode.querySelectorAll(".sui-modal-slide");if(04&&void 0!==arguments[4])||arguments[4],d=!(arguments.length>5&&void 0!==arguments[5])||arguments[5],n=this;t.OpenDialogList.pop(),this.removeListeners(),t.Utils.remove(this.preNode),t.Utils.remove(this.postNode),d?(this.dialogNode.classList.add("sui-content-fade-in"),this.dialogNode.classList.remove("sui-content-fade-out")):(this.dialogNode.classList.remove("sui-content-fade-in"),this.dialogNode.classList.remove("sui-content-fade-out")),this.backdropNode.classList.remove("sui-active"),setTimeout((function(){var e=n.dialogNode.querySelectorAll(".sui-modal-slide");if(04&&void 0!==arguments[4])||arguments[4],d=arguments.length>5?arguments[5]:void 0;new t.Dialog(e,o,a,i,s,d)},SUI.closeModal=function(e){t.getCurrentDialog().close(e)},SUI.replaceModal=function(e,o,a,i){var s=!(arguments.length>4&&void 0!==arguments[4])||arguments[4],d=arguments.length>5?arguments[5]:void 0;t.getCurrentDialog().replace(e,o,a,i,s,d)},SUI.slideModal=function(e,o,a){t.getCurrentDialog().slide(e,o,a)}}(),function(t){"use strict";"object"!==e(window.SUI)&&(window.SUI={}),SUI.modalDialog=function(){return function(){var o,a,i,s,d,n,l,r,c,u,m,g;a=t("[data-modal-open]"),i=t("[data-modal-close]"),s=t("[data-modal-replace]"),d=t("[data-modal-slide]"),n=t(".sui-modal-overlay"),a.on("click",(function(a){o=t(this),l=o.attr("data-modal-open"),c=o.attr("data-modal-close-focus"),u=o.attr("data-modal-open-focus"),n=o.attr("data-modal-mask"),g=o.attr("data-modal-animated");var i="false"!==o.attr("data-esc-close");"undefined"!==e(c)&&!1!==c&&""!==c||(c=this),"undefined"!==e(u)&&!1!==u&&""!==u||(u=void 0),n="undefined"!==e(n)&&!1!==n&&"true"===n,g="undefined"===e(g)||!1===g||"false"!==g,"undefined"!==e(l)&&!1!==l&&""!==l&&SUI.openModal(l,c,u,n,i,g),a.preventDefault()})),s.on("click",(function(a){o=t(this),l=o.attr("data-modal-replace"),c=o.attr("data-modal-close-focus"),u=o.attr("data-modal-open-focus"),n=o.attr("data-modal-replace-mask");var i="false"!==o.attr("data-esc-close");"undefined"!==e(c)&&!1!==c&&""!==c||(c=void 0),"undefined"!==e(u)&&!1!==u&&""!==u||(u=void 0),n="undefined"!==e(n)&&!1!==n&&"true"===n,"undefined"!==e(l)&&!1!==l&&""!==l&&SUI.replaceModal(l,c,u,n,i,g),a.preventDefault()})),d.on("click",(function(a){o=t(this),r=o.attr("data-modal-slide"),u=o.attr("data-modal-slide-focus"),m=o.attr("data-modal-slide-intro"),"undefined"!==e(u)&&!1!==u&&""!==u||(u=void 0),"undefined"!==e(m)&&!1!==m&&""!==m||(m=""),"undefined"!==e(r)&&!1!==r&&""!==r&&SUI.slideModal(r,u,m),a.preventDefault()})),i.on("click",(function(e){SUI.closeModal(g),e.preventDefault()}))}(),this},SUI.modalDialog()}(jQuery)}},t={};function o(a){var i=t[a];if(void 0!==i)return i.exports;var s=t[a]={exports:{}};return e[a](s,s.exports,o),s.exports}o.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return o.d(t,{a:t}),t},o.d=function(e,t){for(var a in t)o.o(t,a)&&!o.o(e,a)&&Object.defineProperty(e,a,{enumerable:!0,get:t[a]})},o.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},function(){"use strict";var e=window.wp.element,t=window.jQuery,a=o.n(t);o(579);const i=e=>e.replace(/<[^>]*>?/gm,"").replace(/[ ]+/g," "),s=(e,t="error")=>`
\n\t\t\t\t\t\t\t
\n\t\t\t\t\t\t\t\t
\n\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\t

${e}

\n\t\t\t\t\t\t\t\t
\n\t\t\t\t\t\t\t
\n\t\t\t\t\t\t
`,d=e=>{const t=e.prop("selectionStart"),o=e.prop("selectionEnd"),a=e.val();return a&&void 0!==t&&void 0!==o?a.substring(t,o):""},n=()=>!!EasyTTSEditor.isBlockEditor&&EasyTTSEditor.isBlockEditor,{__:l}=wp.i18n,r=["core/paragraph","core/heading"],{createHigherOrderComponent:c}=wp.compose,{Fragment:u,useState:m}=wp.element,{BlockControls:g}=wp.blockEditor,{ToolbarGroup:p,ToolbarButton:f,Icon:v}=wp.components,h=c((t=>o=>{if(!r.includes(o.name))return(0,e.createElement)(t,o);const{setAttributes:i}=o;return(0,e.createElement)(u,null,(0,e.createElement)(g,{group:"block"},(0,e.createElement)(p,null,(0,e.createElement)(f,{icon:(0,e.createElement)(v,{icon:"controls-volumeon"}),label:l("Text-to-Speech","easy-text-to-speech"),showTooltip:"true",onClick:()=>{let e=(()=>{let e=window.getSelection().toString();if(!e){e=a()(".wp-block-post-content").text();let t=wp.data.select("core/block-editor").getBlocks(),o="";t.length>0&&(t.forEach((function(e){r.includes(e.name)&&(o+=e.attributes.content+"\n\n")})),e=o)}return e})(),t=a()("#easytts-content");a()("#generate_voice_result_msg").html(""),t.val(""),e=t.html(e).text(),e=e.replace(/(<([^>]+)>)/gi,""),t.val(e),window.SUI.openModal("easytts-modal","wpbody-content",void 0,!0)}}))),(0,e.createElement)(t,o))}),"withToolbarButton");var b;wp.hooks.addFilter("editor.BlockEdit","easytts/toolbar-button",h,99),(b=a())(".aws_polly_engine_for_content").on("change",(function(e){e.preventDefault();const t=b("#generate_voice_result_msg");b.post(ajaxurl,{beforeSend(){a()("#aws_polly_voice").attr("disabled","disabled"),t.html("")},action:"easytts_voice_list",nonce:b("#content_nonce").val(),engine:b(this).val()},(function(e){if(e.success)b("#aws_polly_voice").html(e.data.html);else{b("#aws_polly_voice").html("");const o=s(e.data.message,"error");t.html(o)}})).done((function(){a()("#aws_polly_voice").attr("disabled",!1)}))})),b(document).on("click",".easytts-classic-editor-btn",(function(e){const t=b(this).data("editor-id")||"content";var o;let s="";if(o=t,a()("#wp-"+o+"-wrap").hasClass("tmce-active"))s=((e,t)=>{if("undefined"==typeof e&&(e=wpActiveEditor),"undefined"==typeof t&&(t=e),a()("#wp-"+e+"-wrap").hasClass("tmce-active")&&tinyMCE.get(e)){const t=tinyMCE.get(e).selection.getContent({format:"text"});return t?t.trim():tinyMCE.get(e).getContent({format:"text"})}{const e=d(a()("#"+t));return i(e||a()("#"+t).val())}})(t);else{const e=d(b("#"+t));s=e?e.trim():b("#"+t).val(),s=i(s)}b("#easytts-editor-id").val(t),b("#easytts-content").text(s),SUI.openModal("easytts-modal",this,void 0,!0,!0,!1)})),b(document).on("click","#easytts-modal-close",(function(e){e.preventDefault(),a()(".wp-toolbar").removeClass("sui-has-modal"),a()(".sui-modal").removeClass("sui-active"),window.SUI.closeModal()})),b(document).on("easytts-audio-generated",(function(e){a()(".wp-toolbar").removeClass("sui-has-modal"),a()(".sui-modal").removeClass("sui-active"),window.SUI.closeModal()})),b(document).on("submit","#easytts-voice-generator-form",(function(e){e.preventDefault();const t=b("#generate_voice_result_msg"),o=b("#easytts-generate-voice"),i=b("#easytts-editor-id").val();b.post(ajaxurl,{beforeSend(){t.html(""),o.addClass("sui-button-onload-text")},action:"easytts_generate_voice",nonce:b("#content_nonce").val(),data:b("#easytts-voice-generator-form").serialize(),title:n()?wp.data.select("core/editor").getEditedPostAttribute("title"):a()("#titlewrap").find("input").val()},(function(e){if(e.success){if(b(document).trigger("easytts-audio-generated"),n()){let t="core/audio",o=wp.blocks.createBlock(t,{id:e.data.attachment_id,src:e.data.attachment_url,caption:b("#easytts_tts_disclosure").val()});return void wp.data.dispatch("core/block-editor").insertBlocks(o)}if(wp&&wp.media&&wp.media.editor){wpActiveEditor&&tinyMCE&&tinyMCE.get(wpActiveEditor).selection.collapse(),wp.media.editor.activeEditor=i;let t=wp.media.editor.get(i);(!t||t.options&&t.state!==t.options.state)&&(t=wp.media.editor.add(i,{})),wp.media.frame=t,wp.media.frame.content.mode("browse"),wp.media.frame.on("open",(function(){null!==wp.media.frame.content.get()&&(wp.media.frame.content.get().collection._requery(!0),wp.media.frame.content.get().options.selection.reset());let t=wp.media.frame.state().get("selection"),o=wp.media.attachment(e.data.attachment_id);o.set("type","audio"),o.set("filename","easytts.mp3"),o.set("meta",{bitrate:48e3,bitrate_mode:"cbr"}),t.multiple=!1,t.add(o)}),this),wp.media.frame.open()}}else{const o=s(e.data.message,"error");t.html(o)}})).done((function(){o.removeClass("sui-button-onload-text")}))}))}()}(); \ No newline at end of file