Skip to content

Conversation

@dcalhoun
Copy link
Member

@dcalhoun dcalhoun commented Oct 29, 2024

Related

Description

Enable attaching media selected from the Media Library.

Testing Instructions

1 - Inserting media

  1. Add a media-related blocks—Image, Gallery, etc.
  2. Attach media from the Media Library.
  3. Verify the media displays as expected.

2 - Modifying media

  1. Open a post with an existing Gallery block.
  2. Select an image within the gallery.
  3. Tap Replace and select a different image from the Media Library.
  4. Verify the image is replaced as expected.

3 - Add media

  1. Open a post with an existing Gallery block.
  2. Select an image within the gallery.
  3. Select the parent Gallery block by tapping the three vertical dots at the end of the keyboard toolbar.
  4. Tap Add.
  5. Add additional images from the Media Library.
  6. Verify the images are added as expected.

4 - Cancel additions/modifications

  1. Open a post with an existing Gallery block.
  2. Select an image within the gallery.
  3. Select the parent Gallery block by tapping the three vertical dots at the end of the keyboard toolbar.
  4. Tap Add.
  5. Tap Cancel.
  6. Verify gallery remains unchanged.

A single Media Library callback resulted in erroneously mutating
unselected blocks.
Unable to recreate the original erroneously replacement of media
attachments for unselected blocks. This now feels unnecessary.
Avoid unexpected collisions or memory leaks.
@@ -0,0 +1 @@
(function(){const t=document.createElement("link").relList;if(t&&t.supports&&t.supports("modulepreload"))return;for(const i of document.querySelectorAll('link[rel="modulepreload"]'))n(i);new MutationObserver(i=>{for(const s of i)if(s.type==="childList")for(const a of s.addedNodes)a.tagName==="LINK"&&a.rel==="modulepreload"&&n(a)}).observe(document,{childList:!0,subtree:!0});function r(i){const s={};return i.integrity&&(s.integrity=i.integrity),i.referrerPolicy&&(s.referrerPolicy=i.referrerPolicy),i.crossOrigin==="use-credentials"?s.credentials="include":i.crossOrigin==="anonymous"?s.credentials="omit":s.credentials="same-origin",s}function n(i){if(i.ep)return;i.ep=!0;const s=r(i);fetch(i.href,s)}})();const ue="modulepreload",de=function(e,t){return new URL(e,t).href},$={},fe=function(t,r,n){let i=Promise.resolve();if(r&&r.length>0){const a=document.getElementsByTagName("link"),c=document.querySelector("meta[property=csp-nonce]"),d=c?.nonce||c?.getAttribute("nonce");i=Promise.allSettled(r.map(l=>{if(l=de(l,n),l in $)return;$[l]=!0;const h=l.endsWith(".css"),o=h?'[rel="stylesheet"]':"";if(!!n)for(let m=a.length-1;m>=0;m--){const f=a[m];if(f.href===l&&(!h||f.rel==="stylesheet"))return}else if(document.querySelector(`link[href="${l}"]${o}`))return;const w=document.createElement("link");if(w.rel=h?"stylesheet":ue,h||(w.as="script"),w.crossOrigin="",w.href=l,d&&w.setAttribute("nonce",d),document.head.appendChild(w),h)return new Promise((m,f)=>{w.addEventListener("load",m),w.addEventListener("error",()=>f(new Error(`Unable to preload CSS for ${l}`)))})}))}function s(a){const c=new Event("vite:preloadError",{cancelable:!0});if(c.payload=a,window.dispatchEvent(c),!c.defaultPrevented)throw a}return i.then(a=>{for(const c of a||[])c.status==="rejected"&&s(c.reason);return t().catch(s)})};var pe={};(function(e){(function(){var t={not_string:/[^s]/,not_bool:/[^t]/,not_type:/[^T]/,not_primitive:/[^v]/,number:/[diefg]/,numeric_arg:/[bcdiefguxX]/,json:/[j]/,not_json:/[^j]/,text:/^[^\x25]+/,modulo:/^\x25{2}/,placeholder:/^\x25(?:([1-9]\d*)\$|\(([^)]+)\))?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-gijostTuvxX])/,key:/^([a-z_][a-z_\d]*)/i,key_access:/^\.([a-z_][a-z_\d]*)/i,index_access:/^\[(\d+)\]/,sign:/^[+-]/};function r(c){return i(a(c),arguments)}function n(c,d){return r.apply(null,[c].concat(d||[]))}function i(c,d){var l=1,h=c.length,o,y="",w,m,f,x,P,S,O,u;for(w=0;w<h;w++)if(typeof c[w]=="string")y+=c[w];else if(typeof c[w]=="object"){if(f=c[w],f.keys)for(o=d[l],m=0;m<f.keys.length;m++){if(o==null)throw new Error(r('[sprintf] Cannot access property "%s" of undefined value "%s"',f.keys[m],f.keys[m-1]));o=o[f.keys[m]]}else f.param_no?o=d[f.param_no]:o=d[l++];if(t.not_type.test(f.type)&&t.not_primitive.test(f.type)&&o instanceof Function&&(o=o()),t.numeric_arg.test(f.type)&&typeof o!="number"&&isNaN(o))throw new TypeError(r("[sprintf] expecting number but found %T",o));switch(t.number.test(f.type)&&(O=o>=0),f.type){case"b":o=parseInt(o,10).toString(2);break;case"c":o=String.fromCharCode(parseInt(o,10));break;case"d":case"i":o=parseInt(o,10);break;case"j":o=JSON.stringify(o,null,f.width?parseInt(f.width):0);break;case"e":o=f.precision?parseFloat(o).toExponential(f.precision):parseFloat(o).toExponential();break;case"f":o=f.precision?parseFloat(o).toFixed(f.precision):parseFloat(o);break;case"g":o=f.precision?String(Number(o.toPrecision(f.precision))):parseFloat(o);break;case"o":o=(parseInt(o,10)>>>0).toString(8);break;case"s":o=String(o),o=f.precision?o.substring(0,f.precision):o;break;case"t":o=String(!!o),o=f.precision?o.substring(0,f.precision):o;break;case"T":o=Object.prototype.toString.call(o).slice(8,-1).toLowerCase(),o=f.precision?o.substring(0,f.precision):o;break;case"u":o=parseInt(o,10)>>>0;break;case"v":o=o.valueOf(),o=f.precision?o.substring(0,f.precision):o;break;case"x":o=(parseInt(o,10)>>>0).toString(16);break;case"X":o=(parseInt(o,10)>>>0).toString(16).toUpperCase();break}t.json.test(f.type)?y+=o:(t.number.test(f.type)&&(!O||f.sign)?(u=O?"+":"-",o=o.toString().replace(t.sign,"")):u="",P=f.pad_char?f.pad_char==="0"?"0":f.pad_char.charAt(1):" ",S=f.width-(u+o).length,x=f.width&&S>0?P.repeat(S):"",y+=f.align?u+o+x:P==="0"?u+x+o:x+u+o)}return y}var s=Object.create(null);function a(c){if(s[c])return s[c];for(var d=c,l,h=[],o=0;d;){if((l=t.text.exec(d))!==null)h.push(l[0]);else if((l=t.modulo.exec(d))!==null)h.push("%");else if((l=t.placeholder.exec(d))!==null){if(l[2]){o|=1;var y=[],w=l[2],m=[];if((m=t.key.exec(w))!==null)for(y.push(m[1]);(w=w.substring(m[0].length))!=="";)if((m=t.key_access.exec(w))!==null)y.push(m[1]);else if((m=t.index_access.exec(w))!==null)y.push(m[1]);else throw new SyntaxError("[sprintf] failed to parse named argument key");else throw new SyntaxError("[sprintf] failed to parse named argument key");l[2]=y}else o|=2;if(o===3)throw new Error("[sprintf] mixing positional and named placeholders is not (yet) supported");h.push({placeholder:l[0],param_no:l[1],keys:l[2],sign:l[3],pad_char:l[4],align:l[5],width:l[6],precision:l[7],type:l[8]})}else throw new SyntaxError("[sprintf] unexpected placeholder");d=d.substring(l[0].length)}return s[c]=h}e.sprintf=r,e.vsprintf=n,typeof window<"u"&&(window.sprintf=r,window.vsprintf=n)})()})(pe);var D,ee,R,te;D={"(":9,"!":8,"*":7,"/":7,"%":7,"+":6,"-":6,"<":5,"<=":5,">":5,">=":5,"==":4,"!=":4,"&&":3,"||":2,"?":1,"?:":1};ee=["(","?"];R={")":["("],":":["?","?:"]};te=/<=|>=|==|!=|&&|\|\||\?:|\(|!|\*|\/|%|\+|-|<|>|\?|\)|:/;function he(e){for(var t=[],r=[],n,i,s,a;n=e.match(te);){for(i=n[0],s=e.substr(0,n.index).trim(),s&&t.push(s);a=r.pop();){if(R[i]){if(R[i][0]===a){i=R[i][1]||i;break}}else if(ee.indexOf(a)>=0||D[a]<D[i]){r.push(a);break}t.push(a)}R[i]||r.push(i),e=e.substr(n.index+i.length)}return e=e.trim(),e&&t.push(e),t.concat(r.reverse())}var we={"!":function(e){return!e},"*":function(e,t){return e*t},"/":function(e,t){return e/t},"%":function(e,t){return e%t},"+":function(e,t){return e+t},"-":function(e,t){return e-t},"<":function(e,t){return e<t},"<=":function(e,t){return e<=t},">":function(e,t){return e>t},">=":function(e,t){return e>=t},"==":function(e,t){return e===t},"!=":function(e,t){return e!==t},"&&":function(e,t){return e&&t},"||":function(e,t){return e||t},"?:":function(e,t,r){if(e)throw t;return r}};function me(e,t){var r=[],n,i,s,a,c,d;for(n=0;n<e.length;n++){if(c=e[n],a=we[c],a){for(i=a.length,s=Array(i);i--;)s[i]=r.pop();try{d=a.apply(null,s)}catch(l){return l}}else t.hasOwnProperty(c)?d=t[c]:d=+c;r.push(d)}return r[0]}function ye(e){var t=he(e);return function(r){return me(t,r)}}function ge(e){var t=ye(e);return function(r){return+t({n:r})}}var N={contextDelimiter:"",onMissingKey:null};function _e(e){var t,r,n;for(t=e.split(";"),r=0;r<t.length;r++)if(n=t[r].trim(),n.indexOf("plural=")===0)return n.substr(7)}function H(e,t){var r;this.data=e,this.pluralForms={},this.options={};for(r in N)this.options[r]=t!==void 0&&r in t?t[r]:N[r]}H.prototype.getPluralForm=function(e,t){var r=this.pluralForms[e],n,i,s;return r||(n=this.data[e][""],s=n["Plural-Forms"]||n["plural-forms"]||n.plural_forms,typeof s!="function"&&(i=_e(n["Plural-Forms"]||n["plural-forms"]||n.plural_forms),s=ge(i)),r=this.pluralForms[e]=s),r(t)};H.prototype.dcnpgettext=function(e,t,r,n,i){var s,a,c;return i===void 0?s=0:s=this.getPluralForm(e,i),a=r,t&&(a=t+this.options.contextDelimiter+r),c=this.data[e][a],c&&c[s]?c[s]:(this.options.onMissingKey&&this.options.onMissingKey(r,e),s===0?r:n)};const z={"":{plural_forms(e){return e===1?0:1}}},be=/^i18n\.(n?gettext|has_translation)(_|$)/,ve=(e,t,r)=>{const n=new H({}),i=new Set,s=()=>{i.forEach(u=>u())},a=u=>(i.add(u),()=>i.delete(u)),c=(u="default")=>n.data[u],d=(u,p="default")=>{n.data[p]={...n.data[p],...u},n.data[p][""]={...z[""],...n.data[p]?.[""]},delete n.pluralForms[p]},l=(u,p)=>{d(u,p),s()},h=(u,p="default")=>{n.data[p]={...n.data[p],...u,"":{...z[""],...n.data[p]?.[""],...u?.[""]}},delete n.pluralForms[p],s()},o=(u,p)=>{n.data={},n.pluralForms={},l(u,p)},y=(u="default",p,g,v,E)=>(n.data[u]||d(void 0,u),n.dcnpgettext(u,p,g,v,E)),w=(u="default")=>u,m=(u,p)=>{let g=y(p,void 0,u);return r?(g=r.applyFilters("i18n.gettext",g,u,p),r.applyFilters("i18n.gettext_"+w(p),g,u,p)):g},f=(u,p,g)=>{let v=y(g,p,u);return r?(v=r.applyFilters("i18n.gettext_with_context",v,u,p,g),r.applyFilters("i18n.gettext_with_context_"+w(g),v,u,p,g)):v},x=(u,p,g,v)=>{let E=y(v,void 0,u,p,g);return r?(E=r.applyFilters("i18n.ngettext",E,u,p,g,v),r.applyFilters("i18n.ngettext_"+w(v),E,u,p,g,v)):E},P=(u,p,g,v,E)=>{let F=y(E,v,u,p,g);return r?(F=r.applyFilters("i18n.ngettext_with_context",F,u,p,g,v,E),r.applyFilters("i18n.ngettext_with_context_"+w(E),F,u,p,g,v,E)):F},S=()=>f("ltr","text direction")==="rtl",O=(u,p,g)=>{const v=p?p+""+u:u;let E=!!n.data?.[g??"default"]?.[v];return r&&(E=r.applyFilters("i18n.has_translation",E,u,p,g),E=r.applyFilters("i18n.has_translation_"+w(g),E,u,p,g)),E};if(r){const u=p=>{be.test(p)&&s()};r.addAction("hookAdded","core/i18n",u),r.addAction("hookRemoved","core/i18n",u)}return{getLocaleData:c,setLocaleData:l,addLocaleData:h,resetLocaleData:o,subscribe:a,__:m,_x:f,_n:x,_nx:P,isRTL:S,hasTranslation:O}};function re(e){return typeof e!="string"||e===""?(console.error("The namespace must be a non-empty string."),!1):/^[a-zA-Z][a-zA-Z0-9_.\-\/]*$/.test(e)?!0:(console.error("The namespace can only contain numbers, letters, dashes, periods, underscores and slashes."),!1)}function C(e){return typeof e!="string"||e===""?(console.error("The hook name must be a non-empty string."),!1):/^__/.test(e)?(console.error("The hook name cannot begin with `__`."),!1):/^[a-zA-Z][a-zA-Z0-9_.-]*$/.test(e)?!0:(console.error("The hook name can only contain numbers, letters, dashes, periods and underscores."),!1)}function K(e,t){return function(n,i,s,a=10){const c=e[t];if(!C(n)||!re(i))return;if(typeof s!="function"){console.error("The hook callback must be a function.");return}if(typeof a!="number"){console.error("If specified, the hook priority must be a number.");return}const d={callback:s,priority:a,namespace:i};if(c[n]){const l=c[n].handlers;let h;for(h=l.length;h>0&&!(a>=l[h-1].priority);h--);h===l.length?l[h]=d:l.splice(h,0,d),c.__current.forEach(o=>{o.name===n&&o.currentIndex>=h&&o.currentIndex++})}else c[n]={handlers:[d],runs:0};n!=="hookAdded"&&e.doAction("hookAdded",n,i,s,a)}}function k(e,t,r=!1){return function(i,s){const a=e[t];if(!C(i)||!r&&!re(s))return;if(!a[i])return 0;let c=0;if(r)c=a[i].handlers.length,a[i]={runs:a[i].runs,handlers:[]};else{const d=a[i].handlers;for(let l=d.length-1;l>=0;l--)d[l].namespace===s&&(d.splice(l,1),c++,a.__current.forEach(h=>{h.name===i&&h.currentIndex>=l&&h.currentIndex--}))}return i!=="hookRemoved"&&e.doAction("hookRemoved",i,s),c}}function q(e,t){return function(n,i){const s=e[t];return typeof i<"u"?n in s&&s[n].handlers.some(a=>a.namespace===i):n in s}}function M(e,t,r,n){return function(s,...a){const c=e[t];c[s]||(c[s]={handlers:[],runs:0}),c[s].runs++;const d=c[s].handlers;if(!d||!d.length)return r?a[0]:void 0;const l={name:s,currentIndex:0};async function h(){try{c.__current.add(l);let y=r?a[0]:void 0;for(;l.currentIndex<d.length;)y=await d[l.currentIndex].callback.apply(null,a),r&&(a[0]=y),l.currentIndex++;return r?y:void 0}finally{c.__current.delete(l)}}function o(){try{c.__current.add(l);let y=r?a[0]:void 0;for(;l.currentIndex<d.length;)y=d[l.currentIndex].callback.apply(null,a),r&&(a[0]=y),l.currentIndex++;return r?y:void 0}finally{c.__current.delete(l)}}return(n?h:o)()}}function B(e,t){return function(){var n;const i=e[t];return(n=Array.from(i.__current).at(-1)?.name)!==null&&n!==void 0?n:null}}function G(e,t){return function(n){const i=e[t];return typeof n>"u"?i.__current.size>0:Array.from(i.__current).some(s=>s.name===n)}}function Q(e,t){return function(n){const i=e[t];if(C(n))return i[n]&&i[n].runs?i[n].runs:0}}class Ee{constructor(){this.actions=Object.create(null),this.actions.__current=new Set,this.filters=Object.create(null),this.filters.__current=new Set,this.addAction=K(this,"actions"),this.addFilter=K(this,"filters"),this.removeAction=k(this,"actions"),this.removeFilter=k(this,"filters"),this.hasAction=q(this,"actions"),this.hasFilter=q(this,"filters"),this.removeAllActions=k(this,"actions",!0),this.removeAllFilters=k(this,"filters",!0),this.doAction=M(this,"actions",!1,!1),this.doActionAsync=M(this,"actions",!1,!0),this.applyFilters=M(this,"filters",!0,!1),this.applyFiltersAsync=M(this,"filters",!0,!0),this.currentAction=B(this,"actions"),this.currentFilter=B(this,"filters"),this.doingAction=G(this,"actions"),this.doingFilter=G(this,"filters"),this.didAction=Q(this,"actions"),this.didFilter=Q(this,"filters")}}function Ae(){return new Ee}const xe=Ae(),b=ve(void 0,void 0,xe);b.getLocaleData.bind(b);b.setLocaleData.bind(b);b.resetLocaleData.bind(b);b.subscribe.bind(b);const L=b.__.bind(b);b._x.bind(b);b._n.bind(b);b._nx.bind(b);b.isRTL.bind(b);b.hasTranslation.bind(b);function Pe(e){const t=(r,n)=>{const{headers:i={}}=r;for(const s in i)if(s.toLowerCase()==="x-wp-nonce"&&i[s]===t.nonce)return n(r);return n({...r,headers:{...i,"X-WP-Nonce":t.nonce}})};return t.nonce=e,t}const ne=(e,t)=>{let r=e.path,n,i;return typeof e.namespace=="string"&&typeof e.endpoint=="string"&&(n=e.namespace.replace(/^\/|\/$/g,""),i=e.endpoint.replace(/^\//,""),i?r=n+"/"+i:r=n),delete e.namespace,delete e.endpoint,t({...e,path:r})},Se=e=>(t,r)=>ne(t,n=>{let i=n.url,s=n.path,a;return typeof s=="string"&&(a=e,e.indexOf("?")!==-1&&(s=s.replace("?","&")),s=s.replace(/^\//,""),typeof a=="string"&&a.indexOf("?")!==-1&&(s=s.replace("?","&")),i=a+s),r({...n,url:i})});function Oe(e){let t;try{t=new URL(e,"http://example.com").search.substring(1)}catch{}if(t)return t}function ie(e){let t="";const r=Object.entries(e);let n;for(;n=r.shift();){let[i,s]=n;if(Array.isArray(s)||s&&s.constructor===Object){const c=Object.entries(s).reverse();for(const[d,l]of c)r.unshift([`${i}[${d}]`,l])}else s!==void 0&&(s===null&&(s=""),t+="&"+[i,s].map(encodeURIComponent).join("="))}return t.substr(1)}function Re(e){try{return decodeURIComponent(e)}catch{return e}}function Te(e,t,r){const n=t.length,i=n-1;for(let s=0;s<n;s++){let a=t[s];!a&&Array.isArray(e)&&(a=e.length.toString()),a=["__proto__","constructor","prototype"].includes(a)?a.toUpperCase():a;const c=!isNaN(Number(t[s+1]));e[a]=s===i?r:e[a]||(c?[]:{}),Array.isArray(e[a])&&!c&&(e[a]={...e[a]}),e=e[a]}}function I(e){return(Oe(e)||"").replace(/\+/g,"%20").split("&").reduce((t,r)=>{const[n,i=""]=r.split("=").filter(Boolean).map(Re);if(n){const s=n.replace(/\]/g,"").split("[");Te(t,s,i)}return t},Object.create(null))}function A(e="",t){if(!t||!Object.keys(t).length)return e;let r=e;const n=e.indexOf("?");return n!==-1&&(t=Object.assign(I(e),t),r=r.substr(0,n)),r+"?"+ie(t)}function j(e,t){return I(e)[t]}function J(e,t){return j(e,t)!==void 0}function X(e,...t){const r=e.indexOf("?");if(r===-1)return e;const n=I(e),i=e.substr(0,r);t.forEach(a=>delete n[a]);const s=ie(n);return s?i+"?"+s:i}function V(e){const t=e.split("?"),r=t[1],n=t[0];return r?n+"?"+r.split("&").map(i=>i.split("=")).map(i=>i.map(decodeURIComponent)).sort((i,s)=>i[0].localeCompare(s[0])).map(i=>i.map(encodeURIComponent)).map(i=>i.join("=")).join("&"):n}function Fe(e){const t=Object.fromEntries(Object.entries(e).map(([r,n])=>[V(r),n]));return(r,n)=>{const{parse:i=!0}=r;let s=r.path;if(!s&&r.url){const{rest_route:d,...l}=I(r.url);typeof d=="string"&&(s=A(d,l))}if(typeof s!="string")return n(r);const a=r.method||"GET",c=V(s);if(a==="GET"&&t[c]){const d=t[c];return delete t[c],Z(d,!!i)}else if(a==="OPTIONS"&&t[a]&&t[a][c]){const d=t[a][c];return delete t[a][c],Z(d,!!i)}return n(r)}}function Z(e,t){return Promise.resolve(t?e.body:new window.Response(JSON.stringify(e.body),{status:200,statusText:"OK",headers:e.headers}))}const ke=({path:e,url:t,...r},n)=>({...r,url:t&&A(t,n),path:e&&A(e,n)}),W=e=>e.json?e.json():Promise.reject(e),Me=e=>{if(!e)return{};const t=e.match(/<([^>]+)>; rel="next"/);return t?{next:t[1]}:{}},Y=e=>{const{next:t}=Me(e.headers.get("link"));return t},Le=e=>{const t=!!e.path&&e.path.indexOf("per_page=-1")!==-1,r=!!e.url&&e.url.indexOf("per_page=-1")!==-1;return t||r},se=async(e,t)=>{if(e.parse===!1||!Le(e))return t(e);const r=await _({...ke(e,{per_page:100}),parse:!1}),n=await W(r);if(!Array.isArray(n))return n;let i=Y(r);if(!i)return n;let s=[].concat(n);for(;i;){const a=await _({...e,path:void 0,url:i,parse:!1}),c=await W(a);s=s.concat(c),i=Y(a)}return s},Ie=new Set(["PATCH","PUT","DELETE"]),De="GET",je=(e,t)=>{const{method:r=De}=e;return Ie.has(r.toUpperCase())&&(e={...e,headers:{...e.headers,"X-HTTP-Method-Override":r,"Content-Type":"application/json"},method:"POST"}),t(e)},He=(e,t)=>(typeof e.url=="string"&&!J(e.url,"_locale")&&(e.url=A(e.url,{_locale:"user"})),typeof e.path=="string"&&!J(e.path,"_locale")&&(e.path=A(e.path,{_locale:"user"})),t(e)),Ce=(e,t=!0)=>t?e.status===204?null:e.json?e.json():Promise.reject(e):e,Ue=e=>{const t={code:"invalid_json",message:L("The response is not a valid JSON response.")};if(!e||!e.json)throw t;return e.json().catch(()=>{throw t})},ae=(e,t=!0)=>Promise.resolve(Ce(e,t)).catch(r=>U(r,t));function U(e,t=!0){if(!t)throw e;return Ue(e).then(r=>{const n={code:"unknown_error",message:L("An unknown error occurred.")};throw r||n})}function $e(e){const t=!!e.method&&e.method==="POST";return(!!e.path&&e.path.indexOf("/wp/v2/media")!==-1||!!e.url&&e.url.indexOf("/wp/v2/media")!==-1)&&t}const Ne=(e,t)=>{if(!$e(e))return t(e);let r=0;const n=5,i=s=>(r++,t({path:`/wp/v2/media/${s}/post-process`,method:"POST",data:{action:"create-image-subsizes"},parse:!1}).catch(()=>r<n?i(s):(t({path:`/wp/v2/media/${s}?force=true`,method:"DELETE"}),Promise.reject())));return t({...e,parse:!1}).catch(s=>{if(!s.headers)return Promise.reject(s);const a=s.headers.get("x-wp-upload-attachment-id");return s.status>=500&&s.status<600&&a?i(a).catch(()=>e.parse!==!1?Promise.reject({code:"post_process",message:L("Media upload failed. If this is a photo or a large image, please scale it down and try again.")}):Promise.reject(s)):U(s,e.parse)}).then(s=>ae(s,e.parse))},ze=e=>(t,r)=>{if(typeof t.url=="string"){const n=j(t.url,"wp_theme_preview");n===void 0?t.url=A(t.url,{wp_theme_preview:e}):n===""&&(t.url=X(t.url,"wp_theme_preview"))}if(typeof t.path=="string"){const n=j(t.path,"wp_theme_preview");n===void 0?t.path=A(t.path,{wp_theme_preview:e}):n===""&&(t.path=X(t.path,"wp_theme_preview"))}return r(t)},Ke={Accept:"application/json, */*;q=0.1"},qe={credentials:"include"},oe=[He,ne,je,se];function Be(e){oe.unshift(e)}const ce=e=>{if(e.status>=200&&e.status<300)return e;throw e},Ge=e=>{const{url:t,path:r,data:n,parse:i=!0,...s}=e;let{body:a,headers:c}=e;return c={...Ke,...c},n&&(a=JSON.stringify(n),c["Content-Type"]="application/json"),window.fetch(t||r||window.location.href,{...qe,...s,body:a,headers:c}).then(l=>Promise.resolve(l).then(ce).catch(h=>U(h,i)).then(h=>ae(h,i)),l=>{throw l&&l.name==="AbortError"?l:{code:"fetch_error",message:L("You are probably offline.")}})};let le=Ge;function Qe(e){le=e}function _(e){return oe.reduceRight((r,n)=>i=>n(i,r),le)(e).catch(r=>r.code!=="rest_cookie_invalid_nonce"?Promise.reject(r):window.fetch(_.nonceEndpoint).then(ce).then(n=>n.text()).then(n=>(_.nonceMiddleware.nonce=n,_(e))))}_.use=Be;_.setFetchHandler=Qe;_.createNonceMiddleware=Pe;_.createPreloadingMiddleware=Fe;_.createRootURLMiddleware=Se;_.fetchAllMiddleware=se;_.mediaUploadMiddleware=Ne;_.createThemePreviewMiddleware=ze;function T(){if(window.GBKit)return window.GBKit;if(window.editorDelegate)try{return JSON.parse(window.editorDelegate.getEditorConfiguration())}catch(e){return console.error("Failed parsing GBKit from editorDelegate:",e),{}}try{return JSON.parse(localStorage.getItem("GBKit"))||{}}catch(e){return console.error("Failed parsing GBKit from localStorage:",e),{}}}function Je(){const{post:e}=T();return e?{id:e.id,title:{raw:decodeURIComponent(e.title)},content:{raw:decodeURIComponent(e.content)},type:e.type||"post"}:{type:"post",status:"draft",id:-1}}function Xe(){const{siteApiRoot:e,authHeader:t}=T();_.use(_.createRootURLMiddleware(e)),_.use(Ve),_.use(Ze),_.use(We(t)),_.use(Ye),_.use(et),_.use(_.createPreloadingMiddleware({"/wp/v2/types?context=view":{body:{post:{description:"",hierarchical:!1,has_archive:!1,name:"Posts",slug:"post",taxonomies:["category","post_tag"],rest_base:"posts",rest_namespace:"wp/v2",template:[],template_lock:!1,_links:{}},page:{description:"",hierarchical:!0,has_archive:!1,name:"Pages",slug:"page",taxonomies:[],rest_base:"pages",rest_namespace:"wp/v2",template:[],template_lock:!1,_links:{}}}},"/wp/v2/types/post?context=edit":{body:{name:"Posts",slug:"post",supports:{title:!0,editor:!0,author:!0,thumbnail:!0,excerpt:!0,trackbacks:!0,"custom-fields":!0,comments:!0,revisions:!0,"post-formats":!0,autosave:!0},taxonomies:["category","post_tag"],rest_base:"posts",rest_namespace:"wp/v2",template:[],template_lock:!1}}}))}function Ve(e,t){return e.mode="cors",delete e.headers["x-wp-api-fetch-from-editor"],t(e)}function Ze(e,t){const{siteApiNamespace:r}=T();return e.path&&r&&!e.path.includes(r)&&(e.path=e.path.replace(/^(?<apiPath>\/?(?:[\w.-]+\/){2})/,`$<apiPath>${r}/`)),t(e)}function We(e){return(t,r)=>(t.headers=t.headers||{},e&&(t.headers.Authorization=e),r(t))}function Ye(e,t){return[/^\/wp\/v2\/posts\/-?\d+/,/^\/wp\/v2\/pages\/-?\d+/].some(i=>i.test(e.path))?Promise.resolve([]):t(e)}function et(e,t){return e.path&&e.path.startsWith("/wp/v2/media")&&e.method==="POST"&&e.body instanceof FormData&&e.body.get("post")==="-1"&&e.body.delete("post"),t(e)}window.GBKit=T();window.wp=window.wp||{};window.wp.apiFetch=_;Xe();tt();async function tt(){try{const{themeStyles:e,siteURL:t,siteApiRoot:r}=T(),{styles:n,scripts:i}=await _({url:`${t}/wp-json/__experimental/wp-block-editor/v1/editor-assets`});await rt([...n,...i].join(""));const{dispatch:s}=window.wp.data,{store:a}=window.wp.editor,{store:c}=window.wp.preferences;r?.length&&_({path:"/wp-block-editor/v1/settings"}).then(m=>{s(a).updateEditorSettings(m)}).catch(m=>{console.error("Error fetching editor settings:",m)}),s(c).setDefaults("core/edit-post",{themeStyles:e});const l={post:Je()},{default:h}=await fe(async()=>{const{default:m}=await import("./App-8sifGnV4.js");return{default:m}},[],import.meta.url),{createRoot:o,createElement:y,StrictMode:w}=window.wp.element;o(document.getElementById("root")).render(y(w,null,y(h,l)))}catch{window.location.href="index.html?error=remote_editor_load_error"}}async function rt(e){const t=new window.DOMParser().parseFromString(e,"text/html"),r=Array.from(t.querySelectorAll('link[rel="stylesheet"],script')).filter(n=>n.id&&!it.test(n.src));for(const n of r)await st(n)}const nt=["api-fetch"],it=new RegExp(nt.flatMap(e=>[`wp-content/plugins/gutenberg/build/${e.replace(/\//g,"\\/")}\\b`,`wp-includes/js/dist/${e.replace(/\//g,"\\/")}\\b`]).join("|"));function st(e){return new Promise(t=>{const r=document.createElement(e.nodeName);["id","rel","src","href","type"].forEach(n=>{e[n]&&(r[n]=e[n])}),e.innerHTML&&r.appendChild(document.createTextNode(e.innerHTML)),r.onload=()=>t(!0),r.onerror=n=>{console.error("Error loading asset",n),t(!1)},document.body.appendChild(r),(r.nodeName.toLowerCase()==="link"||r.nodeName.toLowerCase()==="script"&&!r.src)&&t()})}

Check failure

Code scanning / CodeQL

Incomplete string escaping or encoding High

This does not escape backslash characters in the input.

Copilot Autofix

AI about 1 year ago

Copilot could not generate an autofix suggestion

Copilot could not generate an autofix suggestion for this alert. Try pushing a new commit or if the problem persists contact support.

@@ -0,0 +1 @@
(function(){const t=document.createElement("link").relList;if(t&&t.supports&&t.supports("modulepreload"))return;for(const i of document.querySelectorAll('link[rel="modulepreload"]'))n(i);new MutationObserver(i=>{for(const s of i)if(s.type==="childList")for(const a of s.addedNodes)a.tagName==="LINK"&&a.rel==="modulepreload"&&n(a)}).observe(document,{childList:!0,subtree:!0});function r(i){const s={};return i.integrity&&(s.integrity=i.integrity),i.referrerPolicy&&(s.referrerPolicy=i.referrerPolicy),i.crossOrigin==="use-credentials"?s.credentials="include":i.crossOrigin==="anonymous"?s.credentials="omit":s.credentials="same-origin",s}function n(i){if(i.ep)return;i.ep=!0;const s=r(i);fetch(i.href,s)}})();const ue="modulepreload",de=function(e,t){return new URL(e,t).href},$={},fe=function(t,r,n){let i=Promise.resolve();if(r&&r.length>0){const a=document.getElementsByTagName("link"),c=document.querySelector("meta[property=csp-nonce]"),d=c?.nonce||c?.getAttribute("nonce");i=Promise.allSettled(r.map(l=>{if(l=de(l,n),l in $)return;$[l]=!0;const h=l.endsWith(".css"),o=h?'[rel="stylesheet"]':"";if(!!n)for(let m=a.length-1;m>=0;m--){const f=a[m];if(f.href===l&&(!h||f.rel==="stylesheet"))return}else if(document.querySelector(`link[href="${l}"]${o}`))return;const w=document.createElement("link");if(w.rel=h?"stylesheet":ue,h||(w.as="script"),w.crossOrigin="",w.href=l,d&&w.setAttribute("nonce",d),document.head.appendChild(w),h)return new Promise((m,f)=>{w.addEventListener("load",m),w.addEventListener("error",()=>f(new Error(`Unable to preload CSS for ${l}`)))})}))}function s(a){const c=new Event("vite:preloadError",{cancelable:!0});if(c.payload=a,window.dispatchEvent(c),!c.defaultPrevented)throw a}return i.then(a=>{for(const c of a||[])c.status==="rejected"&&s(c.reason);return t().catch(s)})};var pe={};(function(e){(function(){var t={not_string:/[^s]/,not_bool:/[^t]/,not_type:/[^T]/,not_primitive:/[^v]/,number:/[diefg]/,numeric_arg:/[bcdiefguxX]/,json:/[j]/,not_json:/[^j]/,text:/^[^\x25]+/,modulo:/^\x25{2}/,placeholder:/^\x25(?:([1-9]\d*)\$|\(([^)]+)\))?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-gijostTuvxX])/,key:/^([a-z_][a-z_\d]*)/i,key_access:/^\.([a-z_][a-z_\d]*)/i,index_access:/^\[(\d+)\]/,sign:/^[+-]/};function r(c){return i(a(c),arguments)}function n(c,d){return r.apply(null,[c].concat(d||[]))}function i(c,d){var l=1,h=c.length,o,y="",w,m,f,x,P,S,O,u;for(w=0;w<h;w++)if(typeof c[w]=="string")y+=c[w];else if(typeof c[w]=="object"){if(f=c[w],f.keys)for(o=d[l],m=0;m<f.keys.length;m++){if(o==null)throw new Error(r('[sprintf] Cannot access property "%s" of undefined value "%s"',f.keys[m],f.keys[m-1]));o=o[f.keys[m]]}else f.param_no?o=d[f.param_no]:o=d[l++];if(t.not_type.test(f.type)&&t.not_primitive.test(f.type)&&o instanceof Function&&(o=o()),t.numeric_arg.test(f.type)&&typeof o!="number"&&isNaN(o))throw new TypeError(r("[sprintf] expecting number but found %T",o));switch(t.number.test(f.type)&&(O=o>=0),f.type){case"b":o=parseInt(o,10).toString(2);break;case"c":o=String.fromCharCode(parseInt(o,10));break;case"d":case"i":o=parseInt(o,10);break;case"j":o=JSON.stringify(o,null,f.width?parseInt(f.width):0);break;case"e":o=f.precision?parseFloat(o).toExponential(f.precision):parseFloat(o).toExponential();break;case"f":o=f.precision?parseFloat(o).toFixed(f.precision):parseFloat(o);break;case"g":o=f.precision?String(Number(o.toPrecision(f.precision))):parseFloat(o);break;case"o":o=(parseInt(o,10)>>>0).toString(8);break;case"s":o=String(o),o=f.precision?o.substring(0,f.precision):o;break;case"t":o=String(!!o),o=f.precision?o.substring(0,f.precision):o;break;case"T":o=Object.prototype.toString.call(o).slice(8,-1).toLowerCase(),o=f.precision?o.substring(0,f.precision):o;break;case"u":o=parseInt(o,10)>>>0;break;case"v":o=o.valueOf(),o=f.precision?o.substring(0,f.precision):o;break;case"x":o=(parseInt(o,10)>>>0).toString(16);break;case"X":o=(parseInt(o,10)>>>0).toString(16).toUpperCase();break}t.json.test(f.type)?y+=o:(t.number.test(f.type)&&(!O||f.sign)?(u=O?"+":"-",o=o.toString().replace(t.sign,"")):u="",P=f.pad_char?f.pad_char==="0"?"0":f.pad_char.charAt(1):" ",S=f.width-(u+o).length,x=f.width&&S>0?P.repeat(S):"",y+=f.align?u+o+x:P==="0"?u+x+o:x+u+o)}return y}var s=Object.create(null);function a(c){if(s[c])return s[c];for(var d=c,l,h=[],o=0;d;){if((l=t.text.exec(d))!==null)h.push(l[0]);else if((l=t.modulo.exec(d))!==null)h.push("%");else if((l=t.placeholder.exec(d))!==null){if(l[2]){o|=1;var y=[],w=l[2],m=[];if((m=t.key.exec(w))!==null)for(y.push(m[1]);(w=w.substring(m[0].length))!=="";)if((m=t.key_access.exec(w))!==null)y.push(m[1]);else if((m=t.index_access.exec(w))!==null)y.push(m[1]);else throw new SyntaxError("[sprintf] failed to parse named argument key");else throw new SyntaxError("[sprintf] failed to parse named argument key");l[2]=y}else o|=2;if(o===3)throw new Error("[sprintf] mixing positional and named placeholders is not (yet) supported");h.push({placeholder:l[0],param_no:l[1],keys:l[2],sign:l[3],pad_char:l[4],align:l[5],width:l[6],precision:l[7],type:l[8]})}else throw new SyntaxError("[sprintf] unexpected placeholder");d=d.substring(l[0].length)}return s[c]=h}e.sprintf=r,e.vsprintf=n,typeof window<"u"&&(window.sprintf=r,window.vsprintf=n)})()})(pe);var D,ee,R,te;D={"(":9,"!":8,"*":7,"/":7,"%":7,"+":6,"-":6,"<":5,"<=":5,">":5,">=":5,"==":4,"!=":4,"&&":3,"||":2,"?":1,"?:":1};ee=["(","?"];R={")":["("],":":["?","?:"]};te=/<=|>=|==|!=|&&|\|\||\?:|\(|!|\*|\/|%|\+|-|<|>|\?|\)|:/;function he(e){for(var t=[],r=[],n,i,s,a;n=e.match(te);){for(i=n[0],s=e.substr(0,n.index).trim(),s&&t.push(s);a=r.pop();){if(R[i]){if(R[i][0]===a){i=R[i][1]||i;break}}else if(ee.indexOf(a)>=0||D[a]<D[i]){r.push(a);break}t.push(a)}R[i]||r.push(i),e=e.substr(n.index+i.length)}return e=e.trim(),e&&t.push(e),t.concat(r.reverse())}var we={"!":function(e){return!e},"*":function(e,t){return e*t},"/":function(e,t){return e/t},"%":function(e,t){return e%t},"+":function(e,t){return e+t},"-":function(e,t){return e-t},"<":function(e,t){return e<t},"<=":function(e,t){return e<=t},">":function(e,t){return e>t},">=":function(e,t){return e>=t},"==":function(e,t){return e===t},"!=":function(e,t){return e!==t},"&&":function(e,t){return e&&t},"||":function(e,t){return e||t},"?:":function(e,t,r){if(e)throw t;return r}};function me(e,t){var r=[],n,i,s,a,c,d;for(n=0;n<e.length;n++){if(c=e[n],a=we[c],a){for(i=a.length,s=Array(i);i--;)s[i]=r.pop();try{d=a.apply(null,s)}catch(l){return l}}else t.hasOwnProperty(c)?d=t[c]:d=+c;r.push(d)}return r[0]}function ye(e){var t=he(e);return function(r){return me(t,r)}}function ge(e){var t=ye(e);return function(r){return+t({n:r})}}var N={contextDelimiter:"",onMissingKey:null};function _e(e){var t,r,n;for(t=e.split(";"),r=0;r<t.length;r++)if(n=t[r].trim(),n.indexOf("plural=")===0)return n.substr(7)}function H(e,t){var r;this.data=e,this.pluralForms={},this.options={};for(r in N)this.options[r]=t!==void 0&&r in t?t[r]:N[r]}H.prototype.getPluralForm=function(e,t){var r=this.pluralForms[e],n,i,s;return r||(n=this.data[e][""],s=n["Plural-Forms"]||n["plural-forms"]||n.plural_forms,typeof s!="function"&&(i=_e(n["Plural-Forms"]||n["plural-forms"]||n.plural_forms),s=ge(i)),r=this.pluralForms[e]=s),r(t)};H.prototype.dcnpgettext=function(e,t,r,n,i){var s,a,c;return i===void 0?s=0:s=this.getPluralForm(e,i),a=r,t&&(a=t+this.options.contextDelimiter+r),c=this.data[e][a],c&&c[s]?c[s]:(this.options.onMissingKey&&this.options.onMissingKey(r,e),s===0?r:n)};const z={"":{plural_forms(e){return e===1?0:1}}},be=/^i18n\.(n?gettext|has_translation)(_|$)/,ve=(e,t,r)=>{const n=new H({}),i=new Set,s=()=>{i.forEach(u=>u())},a=u=>(i.add(u),()=>i.delete(u)),c=(u="default")=>n.data[u],d=(u,p="default")=>{n.data[p]={...n.data[p],...u},n.data[p][""]={...z[""],...n.data[p]?.[""]},delete n.pluralForms[p]},l=(u,p)=>{d(u,p),s()},h=(u,p="default")=>{n.data[p]={...n.data[p],...u,"":{...z[""],...n.data[p]?.[""],...u?.[""]}},delete n.pluralForms[p],s()},o=(u,p)=>{n.data={},n.pluralForms={},l(u,p)},y=(u="default",p,g,v,E)=>(n.data[u]||d(void 0,u),n.dcnpgettext(u,p,g,v,E)),w=(u="default")=>u,m=(u,p)=>{let g=y(p,void 0,u);return r?(g=r.applyFilters("i18n.gettext",g,u,p),r.applyFilters("i18n.gettext_"+w(p),g,u,p)):g},f=(u,p,g)=>{let v=y(g,p,u);return r?(v=r.applyFilters("i18n.gettext_with_context",v,u,p,g),r.applyFilters("i18n.gettext_with_context_"+w(g),v,u,p,g)):v},x=(u,p,g,v)=>{let E=y(v,void 0,u,p,g);return r?(E=r.applyFilters("i18n.ngettext",E,u,p,g,v),r.applyFilters("i18n.ngettext_"+w(v),E,u,p,g,v)):E},P=(u,p,g,v,E)=>{let F=y(E,v,u,p,g);return r?(F=r.applyFilters("i18n.ngettext_with_context",F,u,p,g,v,E),r.applyFilters("i18n.ngettext_with_context_"+w(E),F,u,p,g,v,E)):F},S=()=>f("ltr","text direction")==="rtl",O=(u,p,g)=>{const v=p?p+""+u:u;let E=!!n.data?.[g??"default"]?.[v];return r&&(E=r.applyFilters("i18n.has_translation",E,u,p,g),E=r.applyFilters("i18n.has_translation_"+w(g),E,u,p,g)),E};if(r){const u=p=>{be.test(p)&&s()};r.addAction("hookAdded","core/i18n",u),r.addAction("hookRemoved","core/i18n",u)}return{getLocaleData:c,setLocaleData:l,addLocaleData:h,resetLocaleData:o,subscribe:a,__:m,_x:f,_n:x,_nx:P,isRTL:S,hasTranslation:O}};function re(e){return typeof e!="string"||e===""?(console.error("The namespace must be a non-empty string."),!1):/^[a-zA-Z][a-zA-Z0-9_.\-\/]*$/.test(e)?!0:(console.error("The namespace can only contain numbers, letters, dashes, periods, underscores and slashes."),!1)}function C(e){return typeof e!="string"||e===""?(console.error("The hook name must be a non-empty string."),!1):/^__/.test(e)?(console.error("The hook name cannot begin with `__`."),!1):/^[a-zA-Z][a-zA-Z0-9_.-]*$/.test(e)?!0:(console.error("The hook name can only contain numbers, letters, dashes, periods and underscores."),!1)}function K(e,t){return function(n,i,s,a=10){const c=e[t];if(!C(n)||!re(i))return;if(typeof s!="function"){console.error("The hook callback must be a function.");return}if(typeof a!="number"){console.error("If specified, the hook priority must be a number.");return}const d={callback:s,priority:a,namespace:i};if(c[n]){const l=c[n].handlers;let h;for(h=l.length;h>0&&!(a>=l[h-1].priority);h--);h===l.length?l[h]=d:l.splice(h,0,d),c.__current.forEach(o=>{o.name===n&&o.currentIndex>=h&&o.currentIndex++})}else c[n]={handlers:[d],runs:0};n!=="hookAdded"&&e.doAction("hookAdded",n,i,s,a)}}function k(e,t,r=!1){return function(i,s){const a=e[t];if(!C(i)||!r&&!re(s))return;if(!a[i])return 0;let c=0;if(r)c=a[i].handlers.length,a[i]={runs:a[i].runs,handlers:[]};else{const d=a[i].handlers;for(let l=d.length-1;l>=0;l--)d[l].namespace===s&&(d.splice(l,1),c++,a.__current.forEach(h=>{h.name===i&&h.currentIndex>=l&&h.currentIndex--}))}return i!=="hookRemoved"&&e.doAction("hookRemoved",i,s),c}}function q(e,t){return function(n,i){const s=e[t];return typeof i<"u"?n in s&&s[n].handlers.some(a=>a.namespace===i):n in s}}function M(e,t,r,n){return function(s,...a){const c=e[t];c[s]||(c[s]={handlers:[],runs:0}),c[s].runs++;const d=c[s].handlers;if(!d||!d.length)return r?a[0]:void 0;const l={name:s,currentIndex:0};async function h(){try{c.__current.add(l);let y=r?a[0]:void 0;for(;l.currentIndex<d.length;)y=await d[l.currentIndex].callback.apply(null,a),r&&(a[0]=y),l.currentIndex++;return r?y:void 0}finally{c.__current.delete(l)}}function o(){try{c.__current.add(l);let y=r?a[0]:void 0;for(;l.currentIndex<d.length;)y=d[l.currentIndex].callback.apply(null,a),r&&(a[0]=y),l.currentIndex++;return r?y:void 0}finally{c.__current.delete(l)}}return(n?h:o)()}}function B(e,t){return function(){var n;const i=e[t];return(n=Array.from(i.__current).at(-1)?.name)!==null&&n!==void 0?n:null}}function G(e,t){return function(n){const i=e[t];return typeof n>"u"?i.__current.size>0:Array.from(i.__current).some(s=>s.name===n)}}function Q(e,t){return function(n){const i=e[t];if(C(n))return i[n]&&i[n].runs?i[n].runs:0}}class Ee{constructor(){this.actions=Object.create(null),this.actions.__current=new Set,this.filters=Object.create(null),this.filters.__current=new Set,this.addAction=K(this,"actions"),this.addFilter=K(this,"filters"),this.removeAction=k(this,"actions"),this.removeFilter=k(this,"filters"),this.hasAction=q(this,"actions"),this.hasFilter=q(this,"filters"),this.removeAllActions=k(this,"actions",!0),this.removeAllFilters=k(this,"filters",!0),this.doAction=M(this,"actions",!1,!1),this.doActionAsync=M(this,"actions",!1,!0),this.applyFilters=M(this,"filters",!0,!1),this.applyFiltersAsync=M(this,"filters",!0,!0),this.currentAction=B(this,"actions"),this.currentFilter=B(this,"filters"),this.doingAction=G(this,"actions"),this.doingFilter=G(this,"filters"),this.didAction=Q(this,"actions"),this.didFilter=Q(this,"filters")}}function Ae(){return new Ee}const xe=Ae(),b=ve(void 0,void 0,xe);b.getLocaleData.bind(b);b.setLocaleData.bind(b);b.resetLocaleData.bind(b);b.subscribe.bind(b);const L=b.__.bind(b);b._x.bind(b);b._n.bind(b);b._nx.bind(b);b.isRTL.bind(b);b.hasTranslation.bind(b);function Pe(e){const t=(r,n)=>{const{headers:i={}}=r;for(const s in i)if(s.toLowerCase()==="x-wp-nonce"&&i[s]===t.nonce)return n(r);return n({...r,headers:{...i,"X-WP-Nonce":t.nonce}})};return t.nonce=e,t}const ne=(e,t)=>{let r=e.path,n,i;return typeof e.namespace=="string"&&typeof e.endpoint=="string"&&(n=e.namespace.replace(/^\/|\/$/g,""),i=e.endpoint.replace(/^\//,""),i?r=n+"/"+i:r=n),delete e.namespace,delete e.endpoint,t({...e,path:r})},Se=e=>(t,r)=>ne(t,n=>{let i=n.url,s=n.path,a;return typeof s=="string"&&(a=e,e.indexOf("?")!==-1&&(s=s.replace("?","&")),s=s.replace(/^\//,""),typeof a=="string"&&a.indexOf("?")!==-1&&(s=s.replace("?","&")),i=a+s),r({...n,url:i})});function Oe(e){let t;try{t=new URL(e,"http://example.com").search.substring(1)}catch{}if(t)return t}function ie(e){let t="";const r=Object.entries(e);let n;for(;n=r.shift();){let[i,s]=n;if(Array.isArray(s)||s&&s.constructor===Object){const c=Object.entries(s).reverse();for(const[d,l]of c)r.unshift([`${i}[${d}]`,l])}else s!==void 0&&(s===null&&(s=""),t+="&"+[i,s].map(encodeURIComponent).join("="))}return t.substr(1)}function Re(e){try{return decodeURIComponent(e)}catch{return e}}function Te(e,t,r){const n=t.length,i=n-1;for(let s=0;s<n;s++){let a=t[s];!a&&Array.isArray(e)&&(a=e.length.toString()),a=["__proto__","constructor","prototype"].includes(a)?a.toUpperCase():a;const c=!isNaN(Number(t[s+1]));e[a]=s===i?r:e[a]||(c?[]:{}),Array.isArray(e[a])&&!c&&(e[a]={...e[a]}),e=e[a]}}function I(e){return(Oe(e)||"").replace(/\+/g,"%20").split("&").reduce((t,r)=>{const[n,i=""]=r.split("=").filter(Boolean).map(Re);if(n){const s=n.replace(/\]/g,"").split("[");Te(t,s,i)}return t},Object.create(null))}function A(e="",t){if(!t||!Object.keys(t).length)return e;let r=e;const n=e.indexOf("?");return n!==-1&&(t=Object.assign(I(e),t),r=r.substr(0,n)),r+"?"+ie(t)}function j(e,t){return I(e)[t]}function J(e,t){return j(e,t)!==void 0}function X(e,...t){const r=e.indexOf("?");if(r===-1)return e;const n=I(e),i=e.substr(0,r);t.forEach(a=>delete n[a]);const s=ie(n);return s?i+"?"+s:i}function V(e){const t=e.split("?"),r=t[1],n=t[0];return r?n+"?"+r.split("&").map(i=>i.split("=")).map(i=>i.map(decodeURIComponent)).sort((i,s)=>i[0].localeCompare(s[0])).map(i=>i.map(encodeURIComponent)).map(i=>i.join("=")).join("&"):n}function Fe(e){const t=Object.fromEntries(Object.entries(e).map(([r,n])=>[V(r),n]));return(r,n)=>{const{parse:i=!0}=r;let s=r.path;if(!s&&r.url){const{rest_route:d,...l}=I(r.url);typeof d=="string"&&(s=A(d,l))}if(typeof s!="string")return n(r);const a=r.method||"GET",c=V(s);if(a==="GET"&&t[c]){const d=t[c];return delete t[c],Z(d,!!i)}else if(a==="OPTIONS"&&t[a]&&t[a][c]){const d=t[a][c];return delete t[a][c],Z(d,!!i)}return n(r)}}function Z(e,t){return Promise.resolve(t?e.body:new window.Response(JSON.stringify(e.body),{status:200,statusText:"OK",headers:e.headers}))}const ke=({path:e,url:t,...r},n)=>({...r,url:t&&A(t,n),path:e&&A(e,n)}),W=e=>e.json?e.json():Promise.reject(e),Me=e=>{if(!e)return{};const t=e.match(/<([^>]+)>; rel="next"/);return t?{next:t[1]}:{}},Y=e=>{const{next:t}=Me(e.headers.get("link"));return t},Le=e=>{const t=!!e.path&&e.path.indexOf("per_page=-1")!==-1,r=!!e.url&&e.url.indexOf("per_page=-1")!==-1;return t||r},se=async(e,t)=>{if(e.parse===!1||!Le(e))return t(e);const r=await _({...ke(e,{per_page:100}),parse:!1}),n=await W(r);if(!Array.isArray(n))return n;let i=Y(r);if(!i)return n;let s=[].concat(n);for(;i;){const a=await _({...e,path:void 0,url:i,parse:!1}),c=await W(a);s=s.concat(c),i=Y(a)}return s},Ie=new Set(["PATCH","PUT","DELETE"]),De="GET",je=(e,t)=>{const{method:r=De}=e;return Ie.has(r.toUpperCase())&&(e={...e,headers:{...e.headers,"X-HTTP-Method-Override":r,"Content-Type":"application/json"},method:"POST"}),t(e)},He=(e,t)=>(typeof e.url=="string"&&!J(e.url,"_locale")&&(e.url=A(e.url,{_locale:"user"})),typeof e.path=="string"&&!J(e.path,"_locale")&&(e.path=A(e.path,{_locale:"user"})),t(e)),Ce=(e,t=!0)=>t?e.status===204?null:e.json?e.json():Promise.reject(e):e,Ue=e=>{const t={code:"invalid_json",message:L("The response is not a valid JSON response.")};if(!e||!e.json)throw t;return e.json().catch(()=>{throw t})},ae=(e,t=!0)=>Promise.resolve(Ce(e,t)).catch(r=>U(r,t));function U(e,t=!0){if(!t)throw e;return Ue(e).then(r=>{const n={code:"unknown_error",message:L("An unknown error occurred.")};throw r||n})}function $e(e){const t=!!e.method&&e.method==="POST";return(!!e.path&&e.path.indexOf("/wp/v2/media")!==-1||!!e.url&&e.url.indexOf("/wp/v2/media")!==-1)&&t}const Ne=(e,t)=>{if(!$e(e))return t(e);let r=0;const n=5,i=s=>(r++,t({path:`/wp/v2/media/${s}/post-process`,method:"POST",data:{action:"create-image-subsizes"},parse:!1}).catch(()=>r<n?i(s):(t({path:`/wp/v2/media/${s}?force=true`,method:"DELETE"}),Promise.reject())));return t({...e,parse:!1}).catch(s=>{if(!s.headers)return Promise.reject(s);const a=s.headers.get("x-wp-upload-attachment-id");return s.status>=500&&s.status<600&&a?i(a).catch(()=>e.parse!==!1?Promise.reject({code:"post_process",message:L("Media upload failed. If this is a photo or a large image, please scale it down and try again.")}):Promise.reject(s)):U(s,e.parse)}).then(s=>ae(s,e.parse))},ze=e=>(t,r)=>{if(typeof t.url=="string"){const n=j(t.url,"wp_theme_preview");n===void 0?t.url=A(t.url,{wp_theme_preview:e}):n===""&&(t.url=X(t.url,"wp_theme_preview"))}if(typeof t.path=="string"){const n=j(t.path,"wp_theme_preview");n===void 0?t.path=A(t.path,{wp_theme_preview:e}):n===""&&(t.path=X(t.path,"wp_theme_preview"))}return r(t)},Ke={Accept:"application/json, */*;q=0.1"},qe={credentials:"include"},oe=[He,ne,je,se];function Be(e){oe.unshift(e)}const ce=e=>{if(e.status>=200&&e.status<300)return e;throw e},Ge=e=>{const{url:t,path:r,data:n,parse:i=!0,...s}=e;let{body:a,headers:c}=e;return c={...Ke,...c},n&&(a=JSON.stringify(n),c["Content-Type"]="application/json"),window.fetch(t||r||window.location.href,{...qe,...s,body:a,headers:c}).then(l=>Promise.resolve(l).then(ce).catch(h=>U(h,i)).then(h=>ae(h,i)),l=>{throw l&&l.name==="AbortError"?l:{code:"fetch_error",message:L("You are probably offline.")}})};let le=Ge;function Qe(e){le=e}function _(e){return oe.reduceRight((r,n)=>i=>n(i,r),le)(e).catch(r=>r.code!=="rest_cookie_invalid_nonce"?Promise.reject(r):window.fetch(_.nonceEndpoint).then(ce).then(n=>n.text()).then(n=>(_.nonceMiddleware.nonce=n,_(e))))}_.use=Be;_.setFetchHandler=Qe;_.createNonceMiddleware=Pe;_.createPreloadingMiddleware=Fe;_.createRootURLMiddleware=Se;_.fetchAllMiddleware=se;_.mediaUploadMiddleware=Ne;_.createThemePreviewMiddleware=ze;function T(){if(window.GBKit)return window.GBKit;if(window.editorDelegate)try{return JSON.parse(window.editorDelegate.getEditorConfiguration())}catch(e){return console.error("Failed parsing GBKit from editorDelegate:",e),{}}try{return JSON.parse(localStorage.getItem("GBKit"))||{}}catch(e){return console.error("Failed parsing GBKit from localStorage:",e),{}}}function Je(){const{post:e}=T();return e?{id:e.id,title:{raw:decodeURIComponent(e.title)},content:{raw:decodeURIComponent(e.content)},type:e.type||"post"}:{type:"post",status:"draft",id:-1}}function Xe(){const{siteApiRoot:e,authHeader:t}=T();_.use(_.createRootURLMiddleware(e)),_.use(Ve),_.use(Ze),_.use(We(t)),_.use(Ye),_.use(et),_.use(_.createPreloadingMiddleware({"/wp/v2/types?context=view":{body:{post:{description:"",hierarchical:!1,has_archive:!1,name:"Posts",slug:"post",taxonomies:["category","post_tag"],rest_base:"posts",rest_namespace:"wp/v2",template:[],template_lock:!1,_links:{}},page:{description:"",hierarchical:!0,has_archive:!1,name:"Pages",slug:"page",taxonomies:[],rest_base:"pages",rest_namespace:"wp/v2",template:[],template_lock:!1,_links:{}}}},"/wp/v2/types/post?context=edit":{body:{name:"Posts",slug:"post",supports:{title:!0,editor:!0,author:!0,thumbnail:!0,excerpt:!0,trackbacks:!0,"custom-fields":!0,comments:!0,revisions:!0,"post-formats":!0,autosave:!0},taxonomies:["category","post_tag"],rest_base:"posts",rest_namespace:"wp/v2",template:[],template_lock:!1}}}))}function Ve(e,t){return e.mode="cors",delete e.headers["x-wp-api-fetch-from-editor"],t(e)}function Ze(e,t){const{siteApiNamespace:r}=T();return e.path&&r&&!e.path.includes(r)&&(e.path=e.path.replace(/^(?<apiPath>\/?(?:[\w.-]+\/){2})/,`$<apiPath>${r}/`)),t(e)}function We(e){return(t,r)=>(t.headers=t.headers||{},e&&(t.headers.Authorization=e),r(t))}function Ye(e,t){return[/^\/wp\/v2\/posts\/-?\d+/,/^\/wp\/v2\/pages\/-?\d+/].some(i=>i.test(e.path))?Promise.resolve([]):t(e)}function et(e,t){return e.path&&e.path.startsWith("/wp/v2/media")&&e.method==="POST"&&e.body instanceof FormData&&e.body.get("post")==="-1"&&e.body.delete("post"),t(e)}window.GBKit=T();window.wp=window.wp||{};window.wp.apiFetch=_;Xe();tt();async function tt(){try{const{themeStyles:e,siteURL:t,siteApiRoot:r}=T(),{styles:n,scripts:i}=await _({url:`${t}/wp-json/__experimental/wp-block-editor/v1/editor-assets`});await rt([...n,...i].join(""));const{dispatch:s}=window.wp.data,{store:a}=window.wp.editor,{store:c}=window.wp.preferences;r?.length&&_({path:"/wp-block-editor/v1/settings"}).then(m=>{s(a).updateEditorSettings(m)}).catch(m=>{console.error("Error fetching editor settings:",m)}),s(c).setDefaults("core/edit-post",{themeStyles:e});const l={post:Je()},{default:h}=await fe(async()=>{const{default:m}=await import("./App-8sifGnV4.js");return{default:m}},[],import.meta.url),{createRoot:o,createElement:y,StrictMode:w}=window.wp.element;o(document.getElementById("root")).render(y(w,null,y(h,l)))}catch{window.location.href="index.html?error=remote_editor_load_error"}}async function rt(e){const t=new window.DOMParser().parseFromString(e,"text/html"),r=Array.from(t.querySelectorAll('link[rel="stylesheet"],script')).filter(n=>n.id&&!it.test(n.src));for(const n of r)await st(n)}const nt=["api-fetch"],it=new RegExp(nt.flatMap(e=>[`wp-content/plugins/gutenberg/build/${e.replace(/\//g,"\\/")}\\b`,`wp-includes/js/dist/${e.replace(/\//g,"\\/")}\\b`]).join("|"));function st(e){return new Promise(t=>{const r=document.createElement(e.nodeName);["id","rel","src","href","type"].forEach(n=>{e[n]&&(r[n]=e[n])}),e.innerHTML&&r.appendChild(document.createTextNode(e.innerHTML)),r.onload=()=>t(!0),r.onerror=n=>{console.error("Error loading asset",n),t(!1)},document.body.appendChild(r),(r.nodeName.toLowerCase()==="link"||r.nodeName.toLowerCase()==="script"&&!r.src)&&t()})}

Check failure

Code scanning / CodeQL

Incomplete string escaping or encoding High

This does not escape backslash characters in the input.

Copilot Autofix

AI about 1 year ago

Copilot could not generate an autofix suggestion

Copilot could not generate an autofix suggestion for this alert. Try pushing a new commit or if the problem persists contact support.

}
}

public struct MediaInfo: Encodable {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The MediaInfo concept was copied and adapted from Gutenberg Mobile's bridge.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What creates the MedaInfo JSON?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I interpret this inquiring as to where MediaInfo is utilized. If so, WP-iOS creates instances when passing the values to GutenbergKit, which is a part of the sibling PR: wordpress-mobile/WordPress-iOS#23721.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is similar to how Gutenberg Mobile expects WP-iOS to create MediaInfo entities.

@dcalhoun dcalhoun marked this pull request as ready for review October 30, 2024 13:36
@dcalhoun dcalhoun requested a review from jkmassel October 30, 2024 13:36
}
}

public enum MediaType: String, Decodable {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Meant to note that the MediaType concept was copied and adapted from Gutenberg Mobile as well.

self.metadata = metadata
}

public func encode(to encoder: Encoder) throws {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need a custom encoder for this?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It appears we do not. Removed in 5e88318.

}
}

public struct MediaInfo: Encodable {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What creates the MedaInfo JSON?

}
}

public struct MediaInfo: Encodable {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All of the objects should probably just conform to Codable instead of just Encodable

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense, merely an example of my lack of familiarity with the types. I updated the objects to use Codable in e37c6e2 and 258c6e9.

case allowedTypes, multiple, value
}

public init(from decoder: Decoder) throws {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of a custom decoder, could value be an enum with arms for the different potential values?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My perception is that Value is currently an enum with arms for the different values and that the custom decoder is necessary to translate the JavaScript value to Swift types. Am I overlooking something? Are you able to provide an alternative example?

public var isEmpty = true
}

public struct OpenMediaLibrary: Decodable {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This name is a little bit unclear – could we call it OpenMediaLibraryAction or something?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, thanks for the suggestion. Addressed in 0230a7d.

Copy link
Contributor

@jkmassel jkmassel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving to unblock this pending suggestions

@dcalhoun dcalhoun merged commit 6cc307e into trunk Nov 11, 2024
7 of 8 checks passed
@dcalhoun dcalhoun deleted the feat/media-library-ios branch November 11, 2024 20:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Type] Enhancement A suggestion for improvement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants