@sveltia/cms 0.5.6 → 0.5.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/sveltia-cms.js +1 -1
- package/package.json +1 -1
package/dist/sveltia-cms.js
CHANGED
|
@@ -403,7 +403,7 @@ ${c}
|
|
|
403
403
|
${u}`;if(s==="json-frontmatter")return`${a}
|
|
404
404
|
${o()}
|
|
405
405
|
${c}
|
|
406
|
-
${u}`}catch{}}return""},Bu=(t,e,n)=>{const{path:s,identifier_field:i="title"}=ms(t);if(!s)return e;if(s.includes("{{slug}}")){const[,r]=e.match(new RegExp(`^${ln(s).replace("\\{\\{slug\\}\\}","(.+)")}$`))||[];if(r)return r}return Ik(n[i]||n.title||n.name||n.label||"")},Rk=t=>{const e=[];return t.forEach(n=>{const s=OO(n);if(!Li(s))return;const{path:i,sha:r,meta:l={},config:{folder:o,collectionName:a,fileName:c}}=n,u=ms(a),f=Dk(u),{structure:d,hasLocales:p,locales:m,defaultLocale:_}=u._i18n,[,b]=c?[]:i.match(new RegExp(`^${ln(wi(o))}\\/(.+)\\.${f}$`))||[];if(!c&&!b)return;const v={sha:r,collectionName:a,fileName:c,...l};if(p||(v.slug=Bu(a,b,s),v.locales={default:{content:s,path:i,sha:r}}),p&&(d==="single_file"||c)&&(v.slug=c||Bu(a,b,s[_]),v.locales=Object.fromEntries(m.filter(k=>k in s).map(k=>[k,{content:s[k],path:i,sha:r}]))),p&&(d==="multiple_folders"||d==="multiple_files")){let k,$;if(d==="multiple_folders"?[,$,k]=b.match(new RegExp(`^(${m.join("|")})\\/(.+)$`))||[]:[,k,$]=b.match(new RegExp(`^(.+)\\.(${m.join("|")})$`))||[],k&&$){const I=Bu(a,k,s),O=e.findIndex(A=>A.slug===I);if(O>-1){e[O].locales[$]={content:s,path:i,sha:r};return}v.slug=I,v.locales={[$]:{content:s,path:i,sha:r}}}}v.id=`${a}/${
|
|
406
|
+
${u}`}catch{}}return""},Bu=(t,e,n)=>{const{path:s,identifier_field:i="title"}=ms(t);if(!s)return e;if(s.includes("{{slug}}")){const[,r]=e.match(new RegExp(`^${ln(s).replace("\\{\\{slug\\}\\}","(.+)")}$`))||[];if(r)return r}return Ik(n[i]||n.title||n.name||n.label||"")},Rk=t=>{const e=[];return t.forEach(n=>{const s=OO(n);if(!Li(s))return;const{path:i,sha:r,meta:l={},config:{folder:o,collectionName:a,fileName:c}}=n,u=ms(a),f=Dk(u),{structure:d,hasLocales:p,locales:m,defaultLocale:_}=u._i18n,[,b]=c?[]:i.match(new RegExp(`^${ln(wi(o))}\\/(.+)\\.${f}$`))||[];if(!c&&!b)return;const v={sha:r,collectionName:a,fileName:c,...l};if(p||(v.slug=c||Bu(a,b,s),v.locales={default:{content:s,path:i,sha:r}}),p&&(d==="single_file"||c)&&(v.slug=c||Bu(a,b,s[_]),v.locales=Object.fromEntries(m.filter(k=>k in s).map(k=>[k,{content:s[k],path:i,sha:r}]))),p&&(d==="multiple_folders"||d==="multiple_files")){let k,$;if(d==="multiple_folders"?[,$,k]=b.match(new RegExp(`^(${m.join("|")})\\/(.+)$`))||[]:[,k,$]=b.match(new RegExp(`^(.+)\\.(${m.join("|")})$`))||[],k&&$){const I=c||Bu(a,k,s),O=e.findIndex(A=>A.slug===I);if(O>-1){e[O].locales[$]={content:s,path:i,sha:r};return}v.slug=I,v.locales={[$]:{content:s,path:i,sha:r}}}}v.id=`${a}/${v.slug}`,e.push(v)}),e},jk=t=>t.map(e=>{const{file:n,url:s,fetchURL:i,repoFileURL:r,path:l,name:o,sha:a,size:c,text:u=null,meta:f={},config:{collectionName:d,internalPath:p}}=e;return{file:n,url:s,fetchURL:i,repoFileURL:r,path:l,name:o,sha:a,size:c,kind:tp(o),text:u,collectionName:d,folder:p,...f}});class Qt{static async set(e,n){window.localStorage.setItem(e,JSON.stringify(n))}static async get(e){return JSON.parse(window.localStorage.getItem(e))}static async delete(e){window.localStorage.removeItem(e)}static async clear(){window.localStorage.clear()}static async keys(){return Object.keys(window.localStorage)}static async values(){return Object.values(window.localStorage).map(e=>JSON.parse(e))}static async entries(){return Object.entries(window.localStorage).map(([e,n])=>[e,JSON.parse(n)])}}const LO="GitHub",NO="https://github.com/{repo}",Rc=async(t,{method:e="GET",headers:n={},body:s=null,token:i=te(En).token,responseType:r="json"}={})=>{const{api_root:l="https://api.github.com"}=te(mt).backend,o=await fetch(`${l}${t}`,{method:e,headers:{Authorization:`token ${i}`,...n},body:s});if(!o.ok)throw new Error("Invalid request");return r==="raw"?o:r==="blob"?o.blob():r==="text"?o.text():o.json()},Qd=async(t,e={})=>{const{data:n}=await Rc("/graphql",{method:"POST",body:JSON.stringify({query:t,variables:e})});return n},PO=async t=>{const e=t||await lL("github");if(!e)throw new Error("Authentication failed");try{return{...await Rc("/user",{token:e}),backendName:"github",token:e}}catch{En.set(null);try{await Qt.delete("sveltia-cms.user")}catch{}throw new Error("Token is not valid")}},IO=async()=>{},CO=async()=>{const{backend:{repo:t="",branch:e="master"}={}}=te(mt)||{};if(!t.trim())throw new Error("Backend is not defined");const[n,s]=t.split("/"),{tree:i}=await Rc(`/repos/${n}/${s}/git/trees/${e}?recursive=1`),{entryFiles:r,assetFiles:l}=Ck(i.filter(({type:u})=>u==="blob")),o=[...r,...l];if(!o.length)return;const{repository:a}=await Qd(`query {
|
|
407
407
|
repository(owner: "${n}", name: "${s}") {
|
|
408
408
|
${o.map(({type:u,path:f},d)=>`
|
|
409
409
|
${u==="entry"?`
|