import{u as B}from"./js/index.317ad629.js";import{f as g}from"./js/helpers.633a054c.js";import{d as m}from"./js/debounce.652fa24c.js";import"./js/runtime-core.esm-bundler.ce5add0b.js";import"./js/default-i18n.65d58dd6.js";import"./js/translations.e71e2202.js";import"./js/toNumber.ad9dffac.js";var h;if(((h=window.aioseo.currentPost)==null?void 0:h.context)==="post"){let u=[];window.wp.data.subscribe(()=>{I()});const I=m(()=>{const s=window.wp.data.select("core/block-editor").getBlocks();(s.length<u.length||s.length===1)&&c(),u=s},200);window.aioseoBus.$on("schemaBlockUpdated",()=>{c()});const c=m(()=>{var f;let s=window.wp.data.select("core/block-editor").getBlocks();s=g(s),s=s.filter(t=>{var o;return(o=t==null?void 0:t.attributes)==null?void 0:o.schemaBlockId}),s=s.map(t=>(t.attributes.type=t.name,t));const d=B(),a=((f=d.currentPost.schema)==null?void 0:f.blockGraphs)||[];a.forEach((t,o)=>{const n=s.findIndex(e=>{var p;return((p=e==null?void 0:e.attributes)==null?void 0:p.schemaBlockId)===(t==null?void 0:t.schemaBlockId)});if(n===-1){a.splice(o,1);return}const r={...s[n].attributes};["backgroundColor","textColor","fontSize","style"].forEach(e=>{delete r[e]}),Object.keys(r).forEach(e=>{typeof r[e]=="string"&&r[e].match(/^({.*}|\[.*\])$/)&&(r[e]=JSON.parse(r[e]))}),a[o]=r}),s.forEach(t=>{a.findIndex(n=>{var r;return(n==null?void 0:n.schemaBlockId)===((r=t==null?void 0:t.attributes)==null?void 0:r.schemaBlockId)})===-1&&(t!=null&&t.attributes)&&(Object.keys(t==null?void 0:t.attributes).forEach(n=>{typeof t.attributes[n]=="string"&&t.attributes[n].match(/^({.*}|\[.*\])$/)&&(t.attributes[n]=JSON.parse(t.attributes[n]))}),a.push(t.attributes))}),a.sort((t,o)=>{const n=s.findIndex(i=>{var e;return((e=i==null?void 0:i.attributes)==null?void 0:e.schemaBlockId)===(t==null?void 0:t.schemaBlockId)}),r=s.findIndex(i=>{var e;return((e=i==null?void 0:i.attributes)==null?void 0:e.schemaBlockId)===(o==null?void 0:o.schemaBlockId)});return n-r}),d.currentPost.schema.blockGraphs=a},200)}
