| 1 |
(()=>{"use strict";var t={1455:t=>{t.exports=window.wp.apiFetch},1857:(t,n,e)=>{e.d(n,{GQ:()=>u,aJ:()=>l,kF:()=>c,td:()=>r,vB:()=>o});const r={"rank-math/faq-block":"thinkrank/faq","rank-math/howto-block":"thinkrank/howto"};function o(t){if("string"!=typeof t)return{};const n=t.match(/^\s*<!--\s+wp:[a-z][a-z0-9-]*\/[a-z][a-z0-9-]*\s+(\{[\s\S]*?\})\s+\/?-->/);if(!n)return{};try{const t=JSON.parse(n[1]);return t&&"object"==typeof t?t:{}}catch(t){return{}}}function a(t){return!(t&&Object.prototype.hasOwnProperty.call(t,"visible")&&!1===t.visible)}function i(t,n){const e=parseInt(t,10);return!e||e<1||!n[e]?{imageId:0,imageUrl:"",imageAlt:""}:{imageId:e,imageUrl:n[e].url||"",imageAlt:n[e].alt||""}}function s(t){return Math.max(0,parseInt(t,10)||0)}function l(t,n,e={}){const o=r[t];if(!o)return null;const l="thinkrank/faq"===o?function(t,n={}){const e=(Array.isArray(t?.questions)?t.questions:[]).filter(t=>t&&a(t)&&"string"==typeof t.title&&""!==t.title&&"string"==typeof t.content&&""!==t.content).map(t=>({question:t.title,answer:t.content,...i(t.imageID,n)}));return e.length?{faqs:e}:null}(n,e):function(t,n={}){const e=(Array.isArray(t?.steps)?t.steps:[]).filter(t=>t&&a(t)).map(t=>({title:"string"==typeof t.title?t.title:"",text:"string"==typeof t.content?t.content:"",...i(t.imageID,n)})).filter(t=>""!==t.title||""!==t.text||0!==t.imageId);if(!e.length)return null;const r={};return"string"==typeof t.description&&""!==t.description&&(r.description=t.description),r.steps=e,t.hasDuration&&(r.totalDays=s(t.days),r.totalHours=s(t.hours),r.totalMinutes=s(t.minutes)),r}(n,e);return l?{name:o,attributes:l}:null}function c(t,n){const e="rank-math/faq-block"===t?n?.questions:n?.steps,r=(Array.isArray(e)?e:[]).filter(t=>t&&a(t)).map(t=>parseInt(t.imageID,10)).filter(t=>t>0),o=parseInt(n?.imageID,10);return"rank-math/howto-block"===t&&o>0&&r.push(o),[...new Set(r)]}function u(t,n,e={}){if("rank-math/howto-block"!==t)return null;const r=parseInt(n?.imageID,10);return!r||r<1||!e[r]?null:{id:r,url:e[r].url||"",alt:e[r].alt||"",sizeSlug:"full",linkDestination:"none"}}},27723:t=>{t.exports=window.wp.i18n},29491:t=>{t.exports=window.wp.compose},47143:t=>{t.exports=window.wp.data},51609:t=>{t.exports=window.React},52619:t=>{t.exports=window.wp.hooks},56427:t=>{t.exports=window.wp.components},74997:t=>{t.exports=window.wp.blocks},86087:t=>{t.exports=window.wp.element},94715:t=>{t.exports=window.wp.blockEditor}},n={};function e(r){var o=n[r];if(void 0!==o)return o.exports;var a=n[r]={exports:{}};return t[r](a,a.exports,e),a.exports}e.n=t=>{var n=t&&t.__esModule?()=>t.default:()=>t;return e.d(n,{a:n}),n},e.d=(t,n)=>{for(var r in n)e.o(n,r)&&!e.o(t,r)&&Object.defineProperty(t,r,{enumerable:!0,get:n[r]})},e.o=(t,n)=>Object.prototype.hasOwnProperty.call(t,n);var r=e(51609),o=e(52619),a=e(74997),i=e(94715),s=e(56427),l=e(47143),c=e(29491),u=e(86087),p=e(1455),k=e.n(p),m=e(27723),f=e(1857);async function h(t){const n=t?.attributes?.originalName;if(!f.td[n])return null;const e=(0,f.vB)(t.attributes.originalContent),r=await async function(t){const n={};return await Promise.all(t.map(async t=>{try{const e=await k()({path:`/wp/v2/media/${t}`});e&&e.source_url&&(n[t]={url:e.source_url,alt:e.alt_text||""})}catch(t){}})),n}((0,f.kF)(n,e)),o=(0,f.aJ)(n,e,r);if(!o)return[];const i=[],s=(0,f.GQ)(n,e,r);return s&&i.push((0,a.createBlock)("core/image",s)),i.push((0,a.createBlock)(o.name,o.attributes)),i}function w(t){return"core/missing"===t?.name&&!!f.td[t?.attributes?.originalName]}function d(t,n=[]){return(t||[]).forEach(t=>{w(t)&&n.push(t),t?.innerBlocks?.length&&d(t.innerBlocks,n)}),n}const g=(0,c.createHigherOrderComponent)(t=>n=>{const{replaceBlocks:e}=(0,l.useDispatch)(i.store),o=(0,l.useSelect)(t=>t(i.store).getBlocks,[]),a=(0,u.useCallback)(async()=>{const t=await h(n);t&&e(n.clientId,t)},[n,e]),c=(0,u.useCallback)(async()=>{const t=d(o());for(const n of t){const t=await h(n);t&&e(n.clientId,t)}},[o,e]);if(!w(n))return(0,r.createElement)(t,{...n});const p="rank-math/faq-block"===n.attributes.originalName,k=d(o()).length;return(0,r.createElement)(r.Fragment,null,(0,r.createElement)(t,{...n}),(0,r.createElement)(i.BlockControls,null,(0,r.createElement)(s.ToolbarGroup,null,(0,r.createElement)(s.ToolbarButton,{onClick:a},p?(0,m.__)("Convert to ThinkRank FAQ","thinkrank"):(0,m.__)("Convert to ThinkRank HowTo","thinkrank")),k>1&&(0,r.createElement)(s.ToolbarButton,{onClick:c},(0,m.__)("Convert all Rank Math blocks on this page","thinkrank")))))},"withRankMathConversion");(0,o.addFilter)("editor.BlockEdit","thinkrank/rank-math-block-converter",g),(0,o.addFilter)("blocks.registerBlockType","thinkrank/rank-math-block-transforms",(t,n)=>{if(!f.td[n])return t;const e=f.td[n],r={type:"block",blocks:[e],transform:t=>{const r=(0,f.aJ)(n,t,{});return r?(0,a.createBlock)(r.name,r.attributes):(0,a.createBlock)(e)}};return{...t,transforms:{...t.transforms||{},to:[...t.transforms?.to||[],r]}}})})(); |