wpmind/build/editor.js

7 lines
37 KiB
JavaScript
Raw Normal View History

2025-03-16 10:25:51 +03:00
(()=>{"use strict";var e,t={43:(e,t,n)=>{var r={};n.r(r),n.d(r,{getSettingsPageURL:()=>p,isConnected:()=>u});var o={};n.r(o),n.d(o,{getHighlightBlocks:()=>h});var s={};n.r(s),n.d(s,{removeHighlightBlocks:()=>f,setHighlightBlocks:()=>g});var i={};n.r(i),n.d(i,{close:()=>N,open:()=>B,requestAI:()=>F,reset:()=>D,setContext:()=>x,setError:()=>A,setInput:()=>j,setInsertionPlace:()=>M,setLoading:()=>R,setResponse:()=>L,setScreen:()=>T,toggle:()=>P});var a={};n.r(a),n.d(a,{getContext:()=>U,getError:()=>W,getInput:()=>G,getInsertionPlace:()=>q,getLoading:()=>K,getProgress:()=>Z,getResponse:()=>V,getScreen:()=>$,isOpen:()=>H});const{connected:c,settingsPageURL:l}=window.mindData;function u(){return"1"===c}function p(){return l}const d=window.wp.data,m=(0,d.createReduxStore)("mind",{selectors:r,reducer:e=>e});(0,d.register)(m);function h(e){return e?.highlightBlocks||[]}function g(e){return{type:"SET_HIGHLIGHT_BLOCKS",highlightBlocks:e}}function f(e){return{type:"REMOVE_HIGHLIGHT_BLOCKS",removeBlocks:e}}const E=(0,d.createReduxStore)("mind/blocks",{reducer:function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{highlightBlocks:[]},t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};switch(t.type){case"SET_HIGHLIGHT_BLOCKS":if(t.highlightBlocks&&t.highlightBlocks.length)return{...e,highlightBlocks:[...e.highlightBlocks,...t.highlightBlocks]};break;case"REMOVE_HIGHLIGHT_BLOCKS":if(e.highlightBlocks&&e.highlightBlocks.length&&t.removeBlocks&&t.removeBlocks.length)return{...e,highlightBlocks:e.highlightBlocks.filter((e=>!t.removeBlocks.includes(e)))}}return e},selectors:o,actions:s});(0,d.register)(E);const _={isOpen:!1,input:"",context:["selected-blocks","page"],insertionPlace:"",screen:"",loading:!1,response:"",error:null,progress:{charsProcessed:0,queueSize:0,isComplete:!1}},b=window.wp.i18n,k=window.wp.apiFetch;var v=n.n(k);function w(e){return" \r\n\t".indexOf(e)>=0}const y=window.wp.blocks;class O{constructor(e){this.dispatch=e,this.contentBuffer="",this.decoder=new TextDecoder,this.isJsonStarted=!1,this.jsonBuffer="",this.throttledDispatch=this.throttle(this.performDispatch.bind(this),200)}throttle(e,t){let n;return function(...r){n||(e.apply(this,r),n=!0,setTimeout((()=>n=!1),t))}}async processStream(e){try{for(;;){const{value:t,done:n}=await e.read();if(n)break;await this.processChunk(t)}}catch(e){this.handleError(e)}}async processChunk(e){const t=this.decoder.decode(e,{stream:!0}).split("\n");for(const e of t)if(e.startsWith("data: "))try{const t=e.slice(6),n=JSON.parse(t);if(n.error){this.handleError(n);break}if(!0===n.done)return void(this.jsonBuffer&&await this.parseAndDispatchBlocks(this.jsonBuffer,!0));if(!n.content)continue;await this.processContent(n.content)}catch(e){}}async processContent(e){if(this.contentBuffer+=e,this.isJsonStarted)if(e.includes("```")){const t=e.indexOf("```");this.jsonBuffer+=e.substring(0,t),await this.parseAndDispatchBlocks(this.jsonBuffer,!0),this.isJsonStarted=!1,this.jsonBuffer=""}else this.jsonBuffer+=e,await this.tryParseIncomplete(this.jsonBuffer);else if(this.contentBuffer.includes("```json")){this.isJsonStarted=!0;const[,e]=this.contentBuffer.split("```json");this.jsonBuffer=e||""}}async tryParseIncomplete(e){try{if(!e||!e.trim().startsWith("["))return;const t=function(e){for(var t,n,r,o=["topLevel"],s=0,i=function(e){return o.push(e)},a=function(e){return o[o.length-1]=e},c=function(e){null==t&&(t=s,n=o.length,r=e)},l=function(e){e===r&&(t=void 0,n=void 0,r=void 0)},u=function(){return o.pop()},p=function(){return s--},d=function(e){if("0"<=e&&e<="9")i("number");else switch(e){case'"':return void i("string");case"-":return void i("numberNeedsDigit");case"t":return void i("true");case"f":return void i("false");case"n":return void i("null");case"[":return void i("arrayNeedsValue");case"{":return void i("objectNeedsKey")}},m=e.length;s<m;s++){var h=e[s];switch(o[o.length-1]){case"topLevel":d(h);break;case"string":switch(h){case'"':u();break;case"\\":c("stringEscape"),i("stringEscaped")}break;case"stringEscaped":"u"===h?i("stringUnicode"):(l("stringEscape"),u())
2024-11-27 21:04:43 +03:00
// translators: %s - tone.
2023-10-26 21:22:56 +03:00
// translators: %s - tone.
2024-12-28 15:50:14 +03:00
(0,b.__)("Change tone to %s","mind"),e[0]))}},(0,Q.createElement)(z.RawHTML,null,nt(e[1]))))))))),(0,Q.createElement)(X.DropdownMenu,{icon:(0,Q.createElement)(tt,null),iconPosition:"left",toggleProps:{children:(0,Q.createElement)(Q.Fragment,null,(0,b.__)("Translate","mind"),(0,Q.createElement)(Ie,null))},popoverProps:{placement:"right-end",className:"mind-toolbar-dropdown"},className:"mind-toolbar-dropdown-toggle"},(()=>(0,Q.createElement)(Q.Fragment,null,(0,Q.createElement)(X.MenuGroup,{label:(0,b.__)("Select Language","@@text_domain")},ot.map((e=>(0,Q.createElement)(X.MenuItem,{key:e[0],onClick:()=>{o((0,b.sprintf)(
2023-10-26 21:22:56 +03:00
// translators: %s - tone.
2024-11-27 21:04:43 +03:00
// translators: %s - tone.
2024-12-28 15:50:14 +03:00
(0,b.__)("Translate to %s","mind"),e[0]))}},(0,Q.createElement)(z.RawHTML,null,nt(e[1])))))))))))))}const it=(0,ye.createHigherOrderComponent)((e=>function(t){return(0,Q.createElement)(Q.Fragment,null,(0,Q.createElement)(e,{...t}),(0,Q.createElement)(ue.BlockControls,{group:"other"},(0,Q.createElement)(st,null)))}),"withToolbarControl");function at(e){const{styles:t}=e,n=(0,z.useMemo)((()=>{const e=(0,ue.transformStyles)([{css:t}],".editor-styles-wrapper");let n="";return(0,le.map)((0,le.compact)(e),(e=>{n+=e})),n}),[t]);return(0,Q.createElement)("style",{dangerouslySetInnerHTML:{__html:n}})}(0,we.addFilter)("editor.BlockEdit","mind/block-toolbar-toggle",it);const ct=(0,ye.createHigherOrderComponent)((e=>function(t){const{clientId:n}=t,[r,o]=(0,z.useState)(!1),{removeHighlightBlocks:s}=(0,d.useDispatch)("mind/blocks"),{highlightBlocks:i}=(0,d.useSelect)((e=>{const{getHighlightBlocks:t}=e("mind/blocks");return{highlightBlocks:t()}})),a=i&&i.length&&i.includes(n);return(0,z.useEffect)((()=>{a&&setTimeout((()=>{o(!0),setTimeout((()=>{o(!1),s([n])}),1200)}),200)}),[a,n,s]),a?(0,Q.createElement)(Q.Fragment,null,(0,Q.createElement)(e,{...t}),(0,Q.createElement)(at,{styles:`\n\t\t\t\t\t\t\t[data-block="${n}"] {\n\t\t\t\t\t\t\t\tfilter: blur(15px);\n\t\t\t\t\t\t\t\t${r?"transition: 0.5s filter;":""}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t${r?`\n\t\t\t\t\t\t\t\t\t\t[data-block="${n}"] {\n\t\t\t\t\t\t\t\t\t\t\tfilter: blur(0px);\n\t\t\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`})):(0,Q.createElement)(e,{...t})}),"withMindAIEditorStyles");(0,we.addFilter)("editor.BlockEdit","mind/editor-styles",ct);const lt=(0,b.getLocaleData)(),ut="Type / to choose a block",pt=lt&&void 0!==lt[ut]?lt[ut]:ut;(0,b.setLocaleData)({[ut]:[`${pt}... Press \`space\` for AI`]},"default");const dt=(0,ye.createHigherOrderComponent)((e=>function(t){const{name:n,attributes:r}=t,{content:o}=r,s=(0,ye.usePrevious)(o),{open:i,setInsertionPlace:a}=(0,d.useDispatch)("mind/popup");return(0,z.useEffect)((()=>{"core/paragraph"!==n||`${s||""}`||" "!=`${o||""}`||(i(),a("selected-blocks"))}),[n,s,o,i,a]),(0,Q.createElement)(e,{...t})}),"withMindAI");(0,we.addFilter)("editor.BlockEdit","mind/open-popup",dt);const mt="mind-post-toolbar-toggle";function ht(){const{open:e,setInsertionPlace:t}=(0,d.useDispatch)("mind/popup"),{getSelectedBlockClientIds:n}=(0,d.useSelect)((e=>({getSelectedBlockClientIds:e("core/block-editor").getSelectedBlockClientIds})));return(0,Q.createElement)("button",{type:"button",className:"components-button components-icon-button",onClick:r=>{r.preventDefault(),e();const o=n();o&&o.length&&t("selected-blocks")}},(0,Q.createElement)(se,null),(0,b.__)("Open Mind","@@text_domain"))}ee()((()=>{(0,d.subscribe)((0,le.throttle)((()=>{if(document.querySelector(`.${mt}`))return;const e=document.querySelector(".editor-header__toolbar, .edit-post-header__toolbar");e&&(e=>{const t=document.createElement("div");t.classList.add(mt),e.appendChild(t),(0,z.createRoot)(t).render((0,Q.createElement)(ht,null))})(e)}),200,{trailing:!0}))}))}},n={};function r(e){var o=n[e];if(void 0!==o)return o.exports;var s=n[e]={exports:{}};return t[e](s,s.exports,r),s.exports}r.m=t,e=[],r.O=(t,n,o,s)=>{if(!n){var i=1/0;for(u=0;u<e.length;u++){n=e[u][0],o=e[u][1],s=e[u][2];for(var a=!0,c=0;c<n.length;c++)(!1&s||i>=s)&&Object.keys(r.O).every((e=>r.O[e](n[c])))?n.splice(c--,1):(a=!1,s<i&&(i=s));if(a){e.splice(u--,1);var l=o();void 0!==l&&(t=l)}}return t}s=s||0;for(var u=e.length;u>0&&e[u-1][2]>s;u--)e[u]=e[u-1];e[u]=[n,o,s]},r.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return r.d(t,{a:t}),t},r.d=(e,t)=>{for(var n in t)r.o(t,n)&&!r.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},r.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},(()=>{var e={8:0,117:0};r.O.j=t=>0===e[t];var t=(t,n)=>{var o,s,i=n[0],a=n[1],c=n[2],l=0;if(i.some((t=>0!==e[t]))){for(o in a)r.o(a,o)&&(r.m[o]=a[o]);if(c)var u=c(r)}for(t&&t