@sveltia/cms 0.5.5 → 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 +2 -2
- package/package.json +6 -6
package/dist/sveltia-cms.js
CHANGED
|
@@ -389,7 +389,7 @@ ${n.comment}`:n.comment}this.doc.range[2]=n.offset;break}default:this.errors.pus
|
|
|
389
389
|
`)?t.split(`
|
|
390
390
|
`):t,e[0])}else{let n=e.length;if(n){const{raw:s}=t;for(t=s[n];n;)e[--n]+=s[n];t=e.join("")+t}else t=t.raw[0]}return Ut(t.includes(`
|
|
391
391
|
`)?t.split(`
|
|
392
|
-
`):t,es(null))},yO=new tA("utf-8",es({fatal:!0,ignoreBOM:!1})),Yo=t=>{if(Q4(t)?t.length!==t.byteLength:!eA(t))throw ze("only Uint8Array or ArrayBuffer is acceptable");try{return yO.decode(t)}catch{throw Jt("A TOML doc must be a (ful-scalar) valid UTF-8 file, without any unknown code point.")}},Go=t=>"byteLength"in t,{test:wO}=at(/[\uD800-\uDFFF]/u),zu=t=>{if(Tv(wO(t)))throw Jt("A TOML doc must be a (ful-scalar) valid UTF-8 file, without any uncoupled UCS-4 character code.")};let Uu=!1;const js=(t,e,n,s,i,r)=>{let l="";if(typeof t=="object"&&t){if(Ki(t))throw ze(gO(t)?"TOML.parse(array from TOML.stringify(,{newline?}))":"TOML.parse(array)");if(Go(t))t=Yo(t);else{if(l=t.path,typeof l!="string")throw ze("TOML.parse(source.path)");const{data:f,require:d=typeof require=="function"?require:mn}=t;if(d){const{resolve:p}=d;if(p!=null){const{paths:m}=p;if(m!=null){const _=Md(m,p,[""]);if(_!=null){const b=_[0];if(b!=null){const v=b.replace(/node_modules$/,"");if(v&&(l=d("path").resolve(v,l),typeof l!="string"))throw ze("TOML.parse(source.require('path').resolve)")}}}}if(f===mn){const m=d("fs").readFileSync(l);if(typeof m=="object"&&m&&Go(m))t=Yo(m);else throw ze("TOML.parse(source.require('fs').readFileSync)")}else if(typeof f=="string")zu(t=f);else if(typeof f=="object"&&f&&Go(f))t=Yo(f);else throw ze("TOML.parse(source.data)")}else{if(f===mn)throw ze("TOML.parse(source.data|source.require)");if(typeof f=="string")zu(t=f);else if(typeof f=="object"&&f&&Go(f))t=Yo(f);else throw ze("TOML.parse(source.data)")}}}else if(typeof t=="string")zu(t);else throw ze("TOML.parse(source)");let o,a;if(typeof n=="object"&&n){if(s!==mn||i!==mn)throw ze("options mode ? args mode");o=n.joiner,s=n.bigint,a=n.keys,i=n.x,r=""}else o=n;let c,u;if(Uu)throw Jt("parsing during parsing.");Uu=!0;try{J4(e,o,s,a,i,r),w4(t,l),t&&t[0]==="\uFEFF"&&pe(ze("TOML content (string) should not start with BOM (U+FEFF)"+he(" at "))),c=VA(),u=Z4()}finally{T4(),X4(),Uu=!1,Tv()}return u&&u(),c},$O=ki((t,e,n,s,i)=>typeof e=="number"?js(t,e,n,s,i,",,"):js(t,1,e,n,s,","),{"1.0":(t,e,n,s)=>js(t,.1,e,n,s,","),1:(t,e,n,s)=>js(t,1,e,n,s,","),.5:(t,e,n,s)=>js(t,.5,e,n,s,","),.4:(t,e,n,s)=>js(t,.4,e,n,s,","),.3:(t,e,n,s)=>js(t,.3,e,n,s,","),.2:(t,e,n,s)=>js(t,.2,e,n,s,","),.1:(t,e,n,s)=>js(t,.1,e,n,s,",")}),xf=KE({version:GE,parse:$O,stringify:_O,Section:g4,inline:p4,multiline:bO,basic:vO,literal:kO,commentFor:Ua,commentForThis:zl,OffsetDateTime:Gd,LocalDateTime:Wd,LocalDate:Kd,LocalTime:Zd,isInline:Ud,isSection:Pl,Keys:Jv}),Lk=({date:t=new Date,timeZone:e=void 0}={})=>{const n={year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",second:"2-digit",timeZoneName:"longOffset"};return Object.fromEntries(new Intl.DateTimeFormat("en-US",{...n,timeZone:e}).formatToParts(t).filter(({type:s})=>s in n).map(({type:s,value:i})=>[s,i]))},ln=t=>t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),wi=t=>t.replace(/^\//,"").replace(/\/$/,""),Gi=()=>window.crypto.randomUUID(),SO=async({items:t},{accept:e}={})=>{const n=e?e.trim().split(/,\s*/g):[],s=i=>new Promise(r=>{i.name.startsWith(".")?r(null):i.isFile?i.file(l=>{const o=!n.length||n.some(a=>{const[c,u]=a.split("/");return u==="*"?l.type.split("/")[0]===c:l.type===a});r(o?l:null)},()=>{r(null)}):i.createReader().readEntries(l=>{r(Promise.all(l.map(s)))})});return(await Promise.all([...t].map(i=>s(i.webkitGetAsEntry())))).flat(1e5).filter(Boolean).sort((i,r)=>i.name.localeCompare(r.name))},TO=async t=>{const e=new FileReader;return new Promise(n=>{e.onload=()=>{n(e.result)},e.readAsText(t)})},EO=async t=>{const e=new FileReader;return new Promise(n=>{e.onload=()=>{n(e.result)},e.readAsArrayBuffer(t)})},xa=async t=>{const e=await window.crypto.subtle.digest("SHA-1",await EO(t));return Array.from(new Uint8Array(e)).map(n=>n.toString(16).padStart(2,"0")).join("")},Nk=async t=>{const e=typeof t=="string"?new Blob([t],{type:"text/plain"}):t,n=new FileReader;return new Promise(s=>{n.onload=()=>{s(n.result)},n.readAsDataURL(e)})},AO=async t=>(await Nk(t)).split(",")[1],rl=t=>{const e=new Intl.NumberFormat(te(On)),n=1e3,s=n*1e3,i=s*1e3,r=i*1e3;return t<n?`${e.format(t)} bytes`:t<s?`${e.format(Number((t/n).toFixed(1)))} KB`:t<i?`${e.format(Number((t/s).toFixed(1)))} MB`:t<r?`${e.format(Number((t/i).toFixed(1)))} GB`:`${e.format(Number((t/r).toFixed(1)))} TB`},Pk=(t,e)=>{if(!e.length)return t;const[,n,s]=t.match(/(.+)(?:\.([a-zA-Z0-9]+?))?$/),i=new RegExp(`^${ln(n)}(?:-(\\d+?))?${s?`\\.${s}`:""}$`),r=e.sort().findLast(l=>l.match(i));return r?`${n}-${Number(r.match(i)[1]||0)+1}${s?`.${s}`:""}`:t},Hf=t=>{const e=t.split("/");return e.forEach((n,s)=>{if(n===".."){const i=e.findLastIndex((r,l)=>!!r&&l<s);i>-1&&(e[i]=null)}(n===".."||n===".")&&(e[s]=null)}),e.filter(Boolean).join("/")},Ik=t=>{const{slug:{encoding:e="unicode",clean_accents:n=!1,sanitize_replacement:s="-"}={}}=te(mt);let i=t;return n&&(i=i.normalize("NFD").replace(/\p{Diacritic}/gu,"")),e==="ascii"?i=i.replaceAll(/[^\w-~]/g," "):i=i.replaceAll(/[^\p{L}\p{N}]/gu," "),i.toLocaleLowerCase().trim().replaceAll(/\s+/g,s)},to=(t,{collection:e,content:n,currentSlug:s="",isMediaFolder:i=!1,entryFilePath:r=""})=>{const{name:l,identifier_field:o="title",folder:a}=e,c=Lk(),u=t.replaceAll(/{{(.+?)}}/g,(f,d)=>{if(["year","month","day","hour","minute","second"].includes(d))return c[d];if(d==="slug"&&s)return s;if(d==="uuid")return Gi();if(d==="uuid_short")return Gi().split("-").pop();if(d==="uuid_shorter")return Gi().split("-").shift();if(i){if(!r)return"";if(d==="dirname")return r.replace(a,"").split("/").slice(0,-1).join("/");if(d==="filename")return r.split("/").pop().split(".").shift();if(d==="extension")return r.split("/").pop().split(".").pop()}let p;return d.startsWith("fields.")?p=n[d.replace(/^fields\./,"")]:d==="slug"?p=n[o]||n.title||n.name||n.label:p=n[d],p=Ik(p),!p&&d==="slug"?Gi().split("-").pop():p});return s?u:Pk(u,Ac(l).map(f=>f.slug))},Ck=t=>{const e=[],n=[];return t.forEach(s=>{const{path:i}=s,r=i.split("/").pop(),l=te(Pd).find(({folder:a,file:c})=>i.startsWith(a)||i===c),o=te(us).findLast(({internalPath:a})=>i.startsWith(a));l&&r.match(/\.(?:json|markdown|md|toml|ya?ml)$/i)&&e.push({...s,type:"entry",config:l}),o&&!r.startsWith("+")&&!e.find(a=>a.path===i)&&n.push({...s,type:"asset",config:o})}),{entryFiles:e,assetFiles:n}},Dk=({format:t,extension:e})=>e||(t==="yml"||t==="yaml"?"yml":t==="toml"?"toml":t==="json"?"json":"md"),Mk=(t,e)=>typeof e=="string"&&e.trim()?[e,e]:Array.isArray(e)&&e.length===2?e:t==="json-frontmatter"?["{","}"]:t==="toml-frontmatter"?["+++","+++"]:["---","---"],OO=({text:t,path:e,config:{file:n,extension:s,format:i,frontmatterDelimiter:r}})=>{if(i||(i=s==="md"||e.endsWith(".md")?"yaml-frontmatter":s||(n==null?void 0:n.match(/\.([^.]+)$/)[1])),!i)return null;try{if(i.match(/^ya?ml$/)&&e.match(/\.ya?ml$/))return tl.parse(t);if(i==="toml"&&e.match(/\.toml$/))return xf.parse(t);if(i==="json"&&e.match(/\.json$/))return JSON.parse(t)}catch{return null}if(i.match(/^(?:(?:yaml|toml|json)-)?frontmatter$/)&&e.match(/\.(?:md|markdown)$/)){const[l,o]=Mk(i,r),[,a,c=""]=t.match(new RegExp(`^${ln(l)}\\n(.+?)\\n${ln(o)}(?:\\n(.+))?`,"ms"))||[];if(a&&(i==="frontmatter"||i==="yaml-frontmatter"))try{return{...tl.parse(a),body:c}}catch{}if(a&&(i==="frontmatter"||i==="toml-frontmatter"))try{return{...xf.parse(a),body:c}}catch{}if(a&&(i==="frontmatter"||i==="json-frontmatter"))try{return{...JSON.parse(a),body:c}}catch{}}return null},Vm=({content:t,path:e,config:{extension:n,format:s,frontmatterDelimiter:i}})=>{t=JSON.parse(JSON.stringify(t)),s||(s=n==="md"||e.endsWith(".md")?"yaml-frontmatter":n||e.match(/\.([^.]+)$/)[1]);const r=()=>tl.stringify(t,null,{lineWidth:0}).trim(),l=()=>xf.stringify(t,{newline:`
|
|
392
|
+
`):t,es(null))},yO=new tA("utf-8",es({fatal:!0,ignoreBOM:!1})),Yo=t=>{if(Q4(t)?t.length!==t.byteLength:!eA(t))throw ze("only Uint8Array or ArrayBuffer is acceptable");try{return yO.decode(t)}catch{throw Jt("A TOML doc must be a (ful-scalar) valid UTF-8 file, without any unknown code point.")}},Go=t=>"byteLength"in t,{test:wO}=at(/[\uD800-\uDFFF]/u),zu=t=>{if(Tv(wO(t)))throw Jt("A TOML doc must be a (ful-scalar) valid UTF-8 file, without any uncoupled UCS-4 character code.")};let Uu=!1;const js=(t,e,n,s,i,r)=>{let l="";if(typeof t=="object"&&t){if(Ki(t))throw ze(gO(t)?"TOML.parse(array from TOML.stringify(,{newline?}))":"TOML.parse(array)");if(Go(t))t=Yo(t);else{if(l=t.path,typeof l!="string")throw ze("TOML.parse(source.path)");const{data:f,require:d=typeof require=="function"?require:mn}=t;if(d){const{resolve:p}=d;if(p!=null){const{paths:m}=p;if(m!=null){const _=Md(m,p,[""]);if(_!=null){const b=_[0];if(b!=null){const v=b.replace(/node_modules$/,"");if(v&&(l=d("path").resolve(v,l),typeof l!="string"))throw ze("TOML.parse(source.require('path').resolve)")}}}}if(f===mn){const m=d("fs").readFileSync(l);if(typeof m=="object"&&m&&Go(m))t=Yo(m);else throw ze("TOML.parse(source.require('fs').readFileSync)")}else if(typeof f=="string")zu(t=f);else if(typeof f=="object"&&f&&Go(f))t=Yo(f);else throw ze("TOML.parse(source.data)")}else{if(f===mn)throw ze("TOML.parse(source.data|source.require)");if(typeof f=="string")zu(t=f);else if(typeof f=="object"&&f&&Go(f))t=Yo(f);else throw ze("TOML.parse(source.data)")}}}else if(typeof t=="string")zu(t);else throw ze("TOML.parse(source)");let o,a;if(typeof n=="object"&&n){if(s!==mn||i!==mn)throw ze("options mode ? args mode");o=n.joiner,s=n.bigint,a=n.keys,i=n.x,r=""}else o=n;let c,u;if(Uu)throw Jt("parsing during parsing.");Uu=!0;try{J4(e,o,s,a,i,r),w4(t,l),t&&t[0]==="\uFEFF"&&pe(ze("TOML content (string) should not start with BOM (U+FEFF)"+he(" at "))),c=VA(),u=Z4()}finally{T4(),X4(),Uu=!1,Tv()}return u&&u(),c},$O=ki((t,e,n,s,i)=>typeof e=="number"?js(t,e,n,s,i,",,"):js(t,1,e,n,s,","),{"1.0":(t,e,n,s)=>js(t,.1,e,n,s,","),1:(t,e,n,s)=>js(t,1,e,n,s,","),.5:(t,e,n,s)=>js(t,.5,e,n,s,","),.4:(t,e,n,s)=>js(t,.4,e,n,s,","),.3:(t,e,n,s)=>js(t,.3,e,n,s,","),.2:(t,e,n,s)=>js(t,.2,e,n,s,","),.1:(t,e,n,s)=>js(t,.1,e,n,s,",")}),xf=KE({version:GE,parse:$O,stringify:_O,Section:g4,inline:p4,multiline:bO,basic:vO,literal:kO,commentFor:Ua,commentForThis:zl,OffsetDateTime:Gd,LocalDateTime:Wd,LocalDate:Kd,LocalTime:Zd,isInline:Ud,isSection:Pl,Keys:Jv}),Lk=({date:t=new Date,timeZone:e=void 0}={})=>{const n={year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",second:"2-digit",timeZoneName:"longOffset"};return Object.fromEntries(new Intl.DateTimeFormat("en-US",{...n,hour12:!1,timeZone:e}).formatToParts(t).filter(({type:s})=>s in n).map(({type:s,value:i})=>[s,i]))},ln=t=>t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),wi=t=>t.replace(/^\//,"").replace(/\/$/,""),Gi=()=>window.crypto.randomUUID(),SO=async({items:t},{accept:e}={})=>{const n=e?e.trim().split(/,\s*/g):[],s=i=>new Promise(r=>{i.name.startsWith(".")?r(null):i.isFile?i.file(l=>{const o=!n.length||n.some(a=>{const[c,u]=a.split("/");return u==="*"?l.type.split("/")[0]===c:l.type===a});r(o?l:null)},()=>{r(null)}):i.createReader().readEntries(l=>{r(Promise.all(l.map(s)))})});return(await Promise.all([...t].map(i=>s(i.webkitGetAsEntry())))).flat(1e5).filter(Boolean).sort((i,r)=>i.name.localeCompare(r.name))},TO=async t=>{const e=new FileReader;return new Promise(n=>{e.onload=()=>{n(e.result)},e.readAsText(t)})},EO=async t=>{const e=new FileReader;return new Promise(n=>{e.onload=()=>{n(e.result)},e.readAsArrayBuffer(t)})},xa=async t=>{const e=await window.crypto.subtle.digest("SHA-1",await EO(t));return Array.from(new Uint8Array(e)).map(n=>n.toString(16).padStart(2,"0")).join("")},Nk=async t=>{const e=typeof t=="string"?new Blob([t],{type:"text/plain"}):t,n=new FileReader;return new Promise(s=>{n.onload=()=>{s(n.result)},n.readAsDataURL(e)})},AO=async t=>(await Nk(t)).split(",")[1],rl=t=>{const e=new Intl.NumberFormat(te(On)),n=1e3,s=n*1e3,i=s*1e3,r=i*1e3;return t<n?`${e.format(t)} bytes`:t<s?`${e.format(Number((t/n).toFixed(1)))} KB`:t<i?`${e.format(Number((t/s).toFixed(1)))} MB`:t<r?`${e.format(Number((t/i).toFixed(1)))} GB`:`${e.format(Number((t/r).toFixed(1)))} TB`},Pk=(t,e)=>{if(!e.length)return t;const[,n,s]=t.match(/(.+)(?:\.([a-zA-Z0-9]+?))?$/),i=new RegExp(`^${ln(n)}(?:-(\\d+?))?${s?`\\.${s}`:""}$`),r=e.sort().findLast(l=>l.match(i));return r?`${n}-${Number(r.match(i)[1]||0)+1}${s?`.${s}`:""}`:t},Hf=t=>{const e=t.split("/");return e.forEach((n,s)=>{if(n===".."){const i=e.findLastIndex((r,l)=>!!r&&l<s);i>-1&&(e[i]=null)}(n===".."||n===".")&&(e[s]=null)}),e.filter(Boolean).join("/")},Ik=t=>{const{slug:{encoding:e="unicode",clean_accents:n=!1,sanitize_replacement:s="-"}={}}=te(mt);let i=t;return n&&(i=i.normalize("NFD").replace(/\p{Diacritic}/gu,"")),e==="ascii"?i=i.replaceAll(/[^\w-~]/g," "):i=i.replaceAll(/[^\p{L}\p{N}]/gu," "),i.toLocaleLowerCase().trim().replaceAll(/\s+/g,s)},to=(t,{collection:e,content:n,currentSlug:s="",isMediaFolder:i=!1,entryFilePath:r=""})=>{const{name:l,identifier_field:o="title",folder:a}=e,c=Lk(),u=t.replaceAll(/{{(.+?)}}/g,(f,d)=>{if(["year","month","day","hour","minute","second"].includes(d))return c[d];if(d==="slug"&&s)return s;if(d==="uuid")return Gi();if(d==="uuid_short")return Gi().split("-").pop();if(d==="uuid_shorter")return Gi().split("-").shift();if(i){if(!r)return"";if(d==="dirname")return r.replace(a,"").split("/").slice(0,-1).join("/");if(d==="filename")return r.split("/").pop().split(".").shift();if(d==="extension")return r.split("/").pop().split(".").pop()}let p;return d.startsWith("fields.")?p=n[d.replace(/^fields\./,"")]:d==="slug"?p=n[o]||n.title||n.name||n.label:p=n[d],p=Ik(p),!p&&d==="slug"?Gi().split("-").pop():p});return s?u:Pk(u,Ac(l).map(f=>f.slug))},Ck=t=>{const e=[],n=[];return t.forEach(s=>{const{path:i}=s,r=i.split("/").pop(),l=te(Pd).find(({folder:a,file:c})=>i.startsWith(a)||i===c),o=te(us).findLast(({internalPath:a})=>i.startsWith(a));l&&r.match(/\.(?:json|markdown|md|toml|ya?ml)$/i)&&e.push({...s,type:"entry",config:l}),o&&!r.startsWith("+")&&!e.find(a=>a.path===i)&&n.push({...s,type:"asset",config:o})}),{entryFiles:e,assetFiles:n}},Dk=({format:t,extension:e})=>e||(t==="yml"||t==="yaml"?"yml":t==="toml"?"toml":t==="json"?"json":"md"),Mk=(t,e)=>typeof e=="string"&&e.trim()?[e,e]:Array.isArray(e)&&e.length===2?e:t==="json-frontmatter"?["{","}"]:t==="toml-frontmatter"?["+++","+++"]:["---","---"],OO=({text:t,path:e,config:{file:n,extension:s,format:i,frontmatterDelimiter:r}})=>{if(i||(i=s==="md"||e.endsWith(".md")?"yaml-frontmatter":s||(n==null?void 0:n.match(/\.([^.]+)$/)[1])),!i)return null;try{if(i.match(/^ya?ml$/)&&e.match(/\.ya?ml$/))return tl.parse(t);if(i==="toml"&&e.match(/\.toml$/))return xf.parse(t);if(i==="json"&&e.match(/\.json$/))return JSON.parse(t)}catch{return null}if(i.match(/^(?:(?:yaml|toml|json)-)?frontmatter$/)&&e.match(/\.(?:md|markdown)$/)){const[l,o]=Mk(i,r),[,a,c=""]=t.match(new RegExp(`^${ln(l)}\\n(.+?)\\n${ln(o)}(?:\\n(.+))?`,"ms"))||[];if(a&&(i==="frontmatter"||i==="yaml-frontmatter"))try{return{...tl.parse(a),body:c}}catch{}if(a&&(i==="frontmatter"||i==="toml-frontmatter"))try{return{...xf.parse(a),body:c}}catch{}if(a&&(i==="frontmatter"||i==="json-frontmatter"))try{return{...JSON.parse(a),body:c}}catch{}}return null},Vm=({content:t,path:e,config:{extension:n,format:s,frontmatterDelimiter:i}})=>{t=JSON.parse(JSON.stringify(t)),s||(s=n==="md"||e.endsWith(".md")?"yaml-frontmatter":n||e.match(/\.([^.]+)$/)[1]);const r=()=>tl.stringify(t,null,{lineWidth:0}).trim(),l=()=>xf.stringify(t,{newline:`
|
|
393
393
|
`}).trim(),o=()=>JSON.stringify(t,null,2).trim();try{if(s.match(/^ya?ml$/))return`${r()}
|
|
394
394
|
`;if(s==="toml")return`${l()}
|
|
395
395
|
`;if(s==="json")return`${o()}
|
|
@@ -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"?`
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sveltia/cms",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.7",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"publishConfig": {
|
|
@@ -26,13 +26,13 @@
|
|
|
26
26
|
"@types/flat": "^5.0.2",
|
|
27
27
|
"@types/marked": "^5.0.1",
|
|
28
28
|
"@types/mime": "^3.0.1",
|
|
29
|
-
"cspell": "^7.0.
|
|
30
|
-
"eslint": "^8.
|
|
29
|
+
"cspell": "^7.0.1",
|
|
30
|
+
"eslint": "^8.48.0",
|
|
31
31
|
"eslint-config-airbnb-base": "^15.0.0",
|
|
32
32
|
"eslint-config-prettier": "^9.0.0",
|
|
33
33
|
"eslint-plugin-import": "^2.28.1",
|
|
34
34
|
"eslint-plugin-jsdoc": "^46.5.0",
|
|
35
|
-
"eslint-plugin-svelte": "^2.
|
|
35
|
+
"eslint-plugin-svelte": "^2.33.0",
|
|
36
36
|
"npm-run-all": "^4.1.5",
|
|
37
37
|
"postcss": "^8.4.28",
|
|
38
38
|
"postcss-html": "^1.5.0",
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
"svelte-i18n": "^3.7.0",
|
|
48
48
|
"svelte-preprocess": "^5.0.4",
|
|
49
49
|
"vite": "^4.4.9",
|
|
50
|
-
"vitest": "^0.34.
|
|
50
|
+
"vitest": "^0.34.3"
|
|
51
51
|
},
|
|
52
52
|
"dependencies": {
|
|
53
53
|
"@ltd/j-toml": "^1.38.0",
|
|
@@ -55,7 +55,7 @@
|
|
|
55
55
|
"fast-deep-equal": "^3.1.3",
|
|
56
56
|
"flat": "^5.0.2",
|
|
57
57
|
"isomorphic-dompurify": "^1.8.0",
|
|
58
|
-
"marked": "^7.0.
|
|
58
|
+
"marked": "^7.0.5",
|
|
59
59
|
"mime": "^3.0.0",
|
|
60
60
|
"moment": "^2.29.4",
|
|
61
61
|
"yaml": "^2.3.1"
|