wpmind/build/editor.js

5 lines
67 KiB
JavaScript
Raw Normal View History

2023-11-14 18:15:02 +03:00
(()=>{"use strict";var e,t={181:(e,t,n)=>{var r={};n.r(r),n.d(r,{getSettingsPageURL:()=>p,isConnected:()=>u});var s={};n.r(s),n.d(s,{getHighlightBlocks:()=>d});var i={};n.r(i),n.d(i,{removeHighlightBlocks:()=>f,setHighlightBlocks:()=>m});var l={};n.r(l),n.d(l,{close:()=>K,open:()=>V,requestAI:()=>ie,reset:()=>le,setContext:()=>Y,setError:()=>se,setInput:()=>J,setInsertionPlace:()=>ee,setLoading:()=>ne,setResponse:()=>re,setScreen:()=>te,toggle:()=>X});var o={};n.r(o),n.d(o,{getContext:()=>ce,getError:()=>de,getInput:()=>ae,getInsertionPlace:()=>ue,getLoading:()=>he,getResponse:()=>ge,getScreen:()=>pe,isOpen:()=>oe});const{connected:a,settingsPageURL:c}=window.mindData;function u(){return"1"===a}function p(){return c}const h=window.wp.data,g=(0,h.createReduxStore)("mind",{selectors:r,reducer:e=>e});(0,h.register)(g);function d(e){return e?.highlightBlocks||[]}function m(e){return{type:"SET_HIGHLIGHT_BLOCKS",highlightBlocks:e}}function f(e){return{type:"REMOVE_HIGHLIGHT_BLOCKS",removeBlocks:e}}const k=(0,h.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:s,actions:i});(0,h.register)(k);let b={async:!1,breaks:!1,extensions:null,gfm:!0,hooks:null,pedantic:!1,renderer:null,silent:!1,tokenizer:null,walkTokens:null};function w(e){b=e}const x=/[&<>"']/,_=new RegExp(x.source,"g"),E=/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/,y=new RegExp(E.source,"g"),v={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"},S=e=>v[e];function O(e,t){if(t){if(x.test(e))return e.replace(_,S)}else if(E.test(e))return e.replace(y,S);return e}const $=/&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/gi,C=/(^|[^\[])\^/g;function I(e,t){e="string"==typeof e?e:e.source,t=t||"";const n={replace:(t,r)=>(r=(r="object"==typeof r&&"source"in r?r.source:r).replace(C,"$1"),e=e.replace(t,r),n),getRegex:()=>new RegExp(e,t)};return n}function T(e){try{e=encodeURI(e).replace(/%25/g,"%")}catch(e){return null}return e}const R={exec:()=>null};function M(e,t){const n=e.replace(/\|/g,((e,t,n)=>{let r=!1,s=t;for(;--s>=0&&"\\"===n[s];)r=!r;return r?"|":" |"})).split(/ \|/);let r=0;if(n[0].trim()||n.shift(),n.length>0&&!n[n.length-1].trim()&&n.pop(),t)if(n.length>t)n.splice(t);else for(;n.length<t;)n.push("");for(;r<n.length;r++)n[r]=n[r].trim().replace(/\\\|/g,"|");return n}function P(e,t,n){const r=e.length;if(0===r)return"";let s=0;for(;s<r;){const i=e.charAt(r-s-1);if(i!==t||n){if(i===t||!n)break;s++}else s++}return e.slice(0,r-s)}function z(e,t,n,r){const s=t.href,i=t.title?O(t.title):null,l=e[1].replace(/\\([\[\]])/g,"$1");if("!"!==e[0].charAt(0)){r.state.inLink=!0;const e={type:"link",raw:n,href:s,title:i,text:l,tokens:r.inlineTokens(l)};return r.state.inLink=!1,e}return{type:"image",raw:n,href:s,title:i,text:O(l)}}class A{options;rules;lexer;constructor(e){this.options=e||b}space(e){const t=this.rules.block.newline.exec(e);if(t&&t[0].length>0)return{type:"space",raw:t[0]}}code(e){const t=this.rules.block.code.exec(e);if(t){const e=t[0].replace(/^ {1,4}/gm,"");return{type:"code",raw:t[0],codeBlockStyle:"indented",text:this.options.pedantic?e:P(e,"\n")}}}fences(e){const t=this.rules.block.fences.exec(e);if(t){const e=t[0],n=function(e,t){const n=e.match(/^(\s+)(?:```)/);if(null===n)return t;const r=n[1];return t.split("\n").map((e=>{const t=e.match(/^\s+/);if(null===t)return e;const[n]=t;return n.length>=r.length?e.slice(r.length):e})).join("\n")}(e,t[3]||"");return{type:"code",raw:e,lang:t[2]?t[2].trim().replace(this.rules.inline._escapes,"$1"):t[2],text:n}}}heading(e){const t=this.rules.block.heading.exec(e);if(t){let e=t[2].trim()
2023-10-26 21:22:56 +03:00
// translators: %s - tone.
2023-11-14 18:15:02 +03:00
(0,U.__)("Change tone to %s","mind"),e[0]))}},(0,fe.createElement)(fe.RawHTML,null,zt(e[1]))))))))),(0,fe.createElement)(ke.DropdownMenu,{icon:(0,fe.createElement)(Pt,null),iconPosition:"left",toggleProps:{children:(0,fe.createElement)(fe.Fragment,null,(0,U.__)("Translate","mind"),(0,fe.createElement)(ct,null))},popoverProps:{placement:"right-end",className:"mind-toolbar-dropdown"},className:"mind-toolbar-dropdown-toggle"},(()=>(0,fe.createElement)(fe.Fragment,null,(0,fe.createElement)(ke.MenuGroup,{label:(0,U.__)("Select Language","@@text_domain")},Lt.map((e=>(0,fe.createElement)(ke.MenuItem,{key:e[0],onClick:()=>{i((0,U.sprintf)(
2023-10-26 21:22:56 +03:00
// translators: %s - tone.
2023-11-14 18:15:02 +03:00
(0,U.__)("Translate to %s","mind"),e[0]))}},(0,fe.createElement)(fe.RawHTML,null,zt(e[1]))))))))))))))}const qt=(0,it.createHigherOrderComponent)((e=>function(t){var n;return n=t,At.includes(n.name)?(0,fe.createElement)(fe.Fragment,null,(0,fe.createElement)(e,t),(0,fe.createElement)(st.BlockControls,{group:"other"},(0,fe.createElement)(Bt,null))):(0,fe.createElement)(e,t)}),"withToolbarControl");(0,rt.addFilter)("editor.BlockEdit","mind/block-toolbar-toggle",qt);const Nt=window.lodash,{elementContext:Ht,__unstableElementContext:Zt}=st.BlockList,Dt=Ht||Zt;function Ft(e){const{styles:t}=e,n=(0,fe.useMemo)((()=>{const e=(0,st.transformStyles)([{css:t}],".editor-styles-wrapper");let n="";return(0,Nt.map)((0,Nt.compact)(e),(e=>{n+=e})),n}),[t]),r=(0,fe.useContext)(Dt);return n&&r&&(0,fe.createPortal)((0,fe.createElement)("style",{dangerouslySetInnerHTML:{__html:n}}),r)}const Gt=["core/paragraph","core/list","core/code","core/preformatted","core/quote","core/blockquote"],Ut=(0,it.createHigherOrderComponent)((e=>function(t){const{name:n,clientId:r}=t,[s,i]=(0,fe.useState)(!1),{removeHighlightBlocks:l}=(0,h.useDispatch)("mind/blocks"),{highlightBlocks:o}=(0,h.useSelect)((e=>{const{getHighlightBlocks:t}=e("mind/blocks");return{highlightBlocks:t()}})),a=Gt.includes(n)&&o&&o.length&&o.includes(r);return(0,fe.useEffect)((()=>{a&&setTimeout((()=>{i(!0),setTimeout((()=>{i(!1),l([r])}),3e3)}),3e3)}),[a,r,l]),a?(0,fe.createElement)(fe.Fragment,null,(0,fe.createElement)(e,t),(0,fe.createElement)(Ft,{styles:`\n\t\t\t\t\t\t\t[data-block="${r}"] {\n\t\t\t\t\t\t\t\tbackground-color: rgba(228, 85, 223, 0.1);\n\t\t\t\t\t\t\t\tbox-shadow: 0 0 0 0.75rem rgba(228, 85, 223, 0.1);\n\t\t\t\t\t\t\t\t${s?"transition: 3s background-color, 3s box-shadow;":""}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t${s?`\n\t\t\t\t\t\t\t\t\t\t[data-block="${r}"] {\n\t\t\t\t\t\t\t\t\t\t\tbackground-color: rgba(228, 85, 223, 0);\n\t\t\t\t\t\t\t\t\t\t\tbox-shadow: 0 0 0 0.75rem rgba(228, 85, 223, 0);\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,fe.createElement)(e,t)}),"withMindAIEditorStyles");(0,rt.addFilter)("editor.BlockEdit","mind/editor-styles",Ut);const Qt=(0,U.getLocaleData)(),Wt="Type / to choose a block",Vt=Qt&&void 0!==Qt[Wt]?Qt[Wt]:Wt;(0,U.setLocaleData)({[Wt]:[`${Vt}... Press \`space\` for AI`]},"default");const Kt=(0,it.createHigherOrderComponent)((e=>function(t){const{name:n,attributes:r}=t,{content:s}=r,i=(0,it.usePrevious)(s),{open:l,setInsertionPlace:o}=(0,h.useDispatch)("mind/popup");return(0,fe.useEffect)((()=>{"core/paragraph"!==n||i||" "!==s||(l(),o("selected-blocks"))}),[n,i,s,l,o]),(0,fe.createElement)(e,t)}),"withMindAI");(0,rt.addFilter)("editor.BlockEdit","mind/open-popup",Kt);const Xt="mind-post-toolbar-toggle";function Jt(){const{toggle:e}=(0,h.useDispatch)("mind/popup");return(0,fe.createElement)("button",{type:"button",className:"components-button components-icon-button",onClick:t=>{t.preventDefault(),e()}},(0,fe.createElement)(Le,null),(0,U.__)("Open Mind","@@text_domain"))}xe()((()=>{(0,h.subscribe)((0,Nt.throttle)((()=>{if(document.querySelector(`.${Xt}`))return;const e=document.querySelector(".edit-post-header__toolbar");e&&(e=>{const t=document.createElement("div");t.classList.add(Xt),e.appendChild(t),(0,fe.createRoot)(t).render((0,fe.createElement)(Jt,null))})(e)}),200,{trailing:!0}))}))}},n={};function r(e){var s=n[e];if(void 0!==s)return s.exports;var i=n[e]={exports:{}};return t[e](i,i.exports,r),i.exports}r.m=t,e=[],r.O=(t,n,s,i)=>{if(!n){var l=1/0;for(u=0;u<e.length;u++){for(var[n,s,i]=e[u],o=!0,a=0;a<n.length;a++)(!1&i||l>=i)&&Object.keys(r.O).every((e=>r.O[e](n[a])))?n.splice(a--,1):(o=!1,i<l&&(l=i));if(o){e.splice(u--,1);var c=s();void 0!==c&&(t=c)}}return t}i=i||0;for(var u=e.length;u>0&&e[u-1][2]>i;u--)e[u]=e[u-1];e[u]=[n,s,i]},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&&Objec