@storyblok/astro 1.1.0 → 1.1.1
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/README.md +3 -3
- package/StoryblokComponent.astro +18 -1
- package/dist/storyblok-astro.js +4 -4
- package/dist/storyblok-astro.mjs +391 -366
- package/package.json +6 -5
package/README.md
CHANGED
|
@@ -143,7 +143,7 @@ For working examples, please refer to the [Live Demo on Stackblitz](https://stac
|
|
|
143
143
|
|
|
144
144
|
### 2. Getting Storyblok Stories and using the Storyblok Bridge
|
|
145
145
|
|
|
146
|
-
|
|
146
|
+
#### Fetching one Story
|
|
147
147
|
|
|
148
148
|
Use the `useStoryblokApi` function to have access to an instance of `storyblok-js-client`:
|
|
149
149
|
|
|
@@ -165,7 +165,7 @@ const story = data.story;
|
|
|
165
165
|
|
|
166
166
|
> Note: The available methods are described in the [storyblok-js-client] repository(https://github.com/storyblok/storyblok-js-client#method-storyblokget)
|
|
167
167
|
|
|
168
|
-
|
|
168
|
+
#### Dynamic Routing
|
|
169
169
|
|
|
170
170
|
In order to dynamically generate Astro pages based on the Stories in your Storyblok Space, you can use the [Storyblok Links API](https://www.storyblok.com/docs/api/content-delivery/v2#core-resources/links/links) and the Astro [`getStaticPaths()` function](https://docs.astro.build/en/reference/api-reference/#getstaticpaths) similar to this example:
|
|
171
171
|
|
|
@@ -210,7 +210,7 @@ The Storyblok Bridge is automatically activated by default. If you would like to
|
|
|
210
210
|
|
|
211
211
|
> Note: Since Astro is not a reactive JavaScript framework and renders everything as HTML, the Storyblok Bridge will not provide real-time editing as you may know it from other frameworks. However, it automatically refreshes the site for you whenever you save or publish a story.
|
|
212
212
|
|
|
213
|
-
|
|
213
|
+
### Rendering Rich Text
|
|
214
214
|
|
|
215
215
|
You can easily render rich text by using the `renderRichText` function that comes with `@storyblok/astro`. Then you can use the [`set:html` directive](https://docs.astro.build/en/reference/directives-reference/#sethtml):
|
|
216
216
|
|
package/StoryblokComponent.astro
CHANGED
|
@@ -1,8 +1,25 @@
|
|
|
1
1
|
---
|
|
2
2
|
import components from "virtual:storyblok-components";
|
|
3
|
+
import camelcase from "camelcase";
|
|
4
|
+
|
|
3
5
|
const { blok, ...props } = Astro.props;
|
|
4
6
|
|
|
5
|
-
|
|
7
|
+
/**
|
|
8
|
+
* convert blok components to camel case to match vite-plugin-storyblok
|
|
9
|
+
*/
|
|
10
|
+
const key = camelcase(blok.component);
|
|
11
|
+
|
|
12
|
+
if (!(key in components)) {
|
|
13
|
+
/**
|
|
14
|
+
* Component not found! Log an error with details on the blok name that could not be found
|
|
15
|
+
* TODO: Add support for a placeholder component as a fallback?
|
|
16
|
+
*/
|
|
17
|
+
throw new Error(
|
|
18
|
+
`Component could not be found for blok "${blok.component}"! Is it defined in astro.config.mjs?`
|
|
19
|
+
);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const Component = components[key];
|
|
6
23
|
---
|
|
7
24
|
|
|
8
25
|
<Component blok={blok} {...props} />
|
package/dist/storyblok-astro.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
(function(
|
|
1
|
+
(function(u,p){typeof exports=="object"&&typeof module<"u"?p(exports,require("axios")):typeof define=="function"&&define.amd?define(["exports","axios"],p):(u=typeof globalThis<"u"?globalThis:u||self,p(u.storyblokAstro={},u.axios))})(this,function(u,p){"use strict";const M=(s=>s&&typeof s=="object"&&"default"in s?s:{default:s})(p),U=/[\p{Lu}]/u,D=/[\p{Ll}]/u,T=/^[\p{Lu}](?![\p{Lu}])/gu,_=/([\p{Alpha}\p{N}_]|$)/u,m=/[_.\- ]+/,q=new RegExp("^"+m.source),R=new RegExp(m.source+_.source,"gu"),w=new RegExp("\\d+"+_.source,"gu"),B=(s,e,t)=>{let r=!1,o=!1,n=!1;for(let i=0;i<s.length;i++){const a=s[i];r&&U.test(a)?(s=s.slice(0,i)+"-"+s.slice(i),r=!1,n=o,o=!0,i++):o&&n&&D.test(a)?(s=s.slice(0,i-1)+"-"+s.slice(i-1),n=o,o=!1,r=!0):(r=e(a)===a&&t(a)!==a,n=o,o=t(a)===a&&e(a)!==a)}return s},z=(s,e)=>(T.lastIndex=0,s.replace(T,t=>e(t))),H=(s,e)=>(R.lastIndex=0,w.lastIndex=0,s.replace(R,(t,r)=>e(r)).replace(w,t=>e(t)));function E(s,e){if(!(typeof s=="string"||Array.isArray(s)))throw new TypeError("Expected the input to be `string | string[]`");if(e={pascalCase:!1,preserveConsecutiveUppercase:!1,...e},Array.isArray(s)?s=s.map(n=>n.trim()).filter(n=>n.length).join("-"):s=s.trim(),s.length===0)return"";const t=e.locale===!1?n=>n.toLowerCase():n=>n.toLocaleLowerCase(e.locale),r=e.locale===!1?n=>n.toUpperCase():n=>n.toLocaleUpperCase(e.locale);return s.length===1?m.test(s)?"":e.pascalCase?r(s):t(s):(s!==t(s)&&(s=B(s,t,r)),s=s.replace(q,""),s=e.preserveConsecutiveUppercase?z(s,t):t(s),e.pascalCase&&(s=r(s.charAt(0))+s.slice(1)),H(s,r))}function V(s){const e="virtual:storyblok-components",t="\0"+e;return{name:"vite-plugin-storyblok",async resolveId(r){if(r===e)return t},async load(r){if(r===t){const o=[];for await(const[n,i]of Object.entries(s)){const{id:a}=await this.resolve("/src/"+i+".astro");o.push(`import ${E(n)} from "${a}"`)}return`${o.join(";")};export default {${Object.keys(s).map(n=>E(n)).join(",")}}`}}}}var F=Object.defineProperty,J=Object.defineProperties,G=Object.getOwnPropertyDescriptors,A=Object.getOwnPropertySymbols,K=Object.prototype.hasOwnProperty,Y=Object.prototype.propertyIsEnumerable,$=(s,e,t)=>e in s?F(s,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):s[e]=t,d=(s,e)=>{for(var t in e||(e={}))K.call(e,t)&&$(s,t,e[t]);if(A)for(var t of A(e))Y.call(e,t)&&$(s,t,e[t]);return s},k=(s,e)=>J(s,G(e));let S=!1;const O=[],x=s=>new Promise((e,t)=>{if(typeof window>"u"||(window.storyblokRegisterEvent=o=>{if(window.location===window.parent.location){console.warn("You are not in Draft Mode or in the Visual Editor.");return}S?o():O.push(o)},document.getElementById("storyblok-javascript-bridge")))return;const r=document.createElement("script");r.async=!0,r.src=s,r.id="storyblok-javascript-bridge",r.onerror=o=>t(o),r.onload=o=>{O.forEach(n=>n()),S=!0,e(o)},document.getElementsByTagName("head")[0].appendChild(r)}),W=function(s,e){if(!s)return null;let t={};for(let r in s){let o=s[r];e.indexOf(r)>-1&&o!==null&&(t[r]=o)}return t},Q=s=>s==="email";var C={nodes:{horizontal_rule(){return{singleTag:"hr"}},blockquote(){return{tag:"blockquote"}},bullet_list(){return{tag:"ul"}},code_block(s){return{tag:["pre",{tag:"code",attrs:s.attrs}]}},hard_break(){return{singleTag:"br"}},heading(s){return{tag:`h${s.attrs.level}`}},image(s){return{singleTag:[{tag:"img",attrs:W(s.attrs,["src","alt","title"])}]}},list_item(){return{tag:"li"}},ordered_list(){return{tag:"ol"}},paragraph(){return{tag:"p"}}},marks:{bold(){return{tag:"b"}},strike(){return{tag:"strike"}},underline(){return{tag:"u"}},strong(){return{tag:"strong"}},code(){return{tag:"code"}},italic(){return{tag:"i"}},link(s){const e=d({},s.attrs),{linktype:t="url"}=s.attrs;return Q(t)&&(e.href=`mailto:${e.href}`),e.anchor&&(e.href=`${e.href}#${e.anchor}`,delete e.anchor),{tag:[{tag:"a",attrs:e}]}},styled(s){return{tag:[{tag:"span",attrs:s.attrs}]}}}};const X=function(s){const e={"&":"&","<":"<",">":">",'"':""","'":"'"},t=/[&<>"']/g,r=RegExp(t.source);return s&&r.test(s)?s.replace(t,o=>e[o]):s};class I{constructor(e){e||(e=C),this.marks=e.marks||[],this.nodes=e.nodes||[]}addNode(e,t){this.nodes[e]=t}addMark(e,t){this.marks[e]=t}render(e={}){if(e.content&&Array.isArray(e.content)){let t="";return e.content.forEach(r=>{t+=this.renderNode(r)}),t}return console.warn("The render method must receive an object with a content field, which is an array"),""}renderNode(e){let t=[];e.marks&&e.marks.forEach(o=>{const n=this.getMatchingMark(o);n&&t.push(this.renderOpeningTag(n.tag))});const r=this.getMatchingNode(e);return r&&r.tag&&t.push(this.renderOpeningTag(r.tag)),e.content?e.content.forEach(o=>{t.push(this.renderNode(o))}):e.text?t.push(X(e.text)):r&&r.singleTag?t.push(this.renderTag(r.singleTag," /")):r&&r.html&&t.push(r.html),r&&r.tag&&t.push(this.renderClosingTag(r.tag)),e.marks&&e.marks.slice(0).reverse().forEach(o=>{const n=this.getMatchingMark(o);n&&t.push(this.renderClosingTag(n.tag))}),t.join("")}renderTag(e,t){return e.constructor===String?`<${e}${t}>`:e.map(o=>{if(o.constructor===String)return`<${o}${t}>`;{let n=`<${o.tag}`;if(o.attrs)for(let i in o.attrs){let a=o.attrs[i];a!==null&&(n+=` ${i}="${a}"`)}return`${n}${t}>`}}).join("")}renderOpeningTag(e){return this.renderTag(e,"")}renderClosingTag(e){return e.constructor===String?`</${e}>`:e.slice(0).reverse().map(r=>r.constructor===String?`</${r}>`:`</${r.tag}>`).join("")}getMatchingNode(e){if(typeof this.nodes[e.type]=="function")return this.nodes[e.type](e)}getMatchingMark(e){if(typeof this.marks[e.type]=="function")return this.marks[e.type](e)}}/*!
|
|
2
2
|
* storyblok-js-client v4.5.2
|
|
3
3
|
* Universal JavaScript SDK for Storyblok's API
|
|
4
4
|
* (c) 2020-2022 Stobylok Team
|
|
5
|
-
*/function E(n){return typeof n=="number"&&n==n&&n!==1/0&&n!==-1/0}function S(n,e,t){if(!E(e))throw new TypeError("Expected `limit` to be a finite number");if(!E(t))throw new TypeError("Expected `interval` to be a finite number");var r=[],s=[],o=0,a=function(){o++;var c=setTimeout(function(){o--,r.length>0&&a(),s=s.filter(function(u){return u!==c})},t);s.indexOf(c)<0&&s.push(c);var l=r.shift();l.resolve(n.apply(l.self,l.args))},i=function(){var c=arguments,l=this;return new Promise(function(u,f){r.push({resolve:u,reject:f,args:c,self:l}),o<e&&a()})};return i.abort=function(){s.forEach(clearTimeout),s=[],r.forEach(function(c){c.reject(new throttle.AbortError)}),r.length=0},i}S.AbortError=function(){Error.call(this,"Throttled function aborted"),this.name="AbortError"};const D=function(n,e){if(!n)return null;let t={};for(let r in n){let s=n[r];e.indexOf(r)>-1&&s!==null&&(t[r]=s)}return t};var U={nodes:{horizontal_rule:()=>({singleTag:"hr"}),blockquote:()=>({tag:"blockquote"}),bullet_list:()=>({tag:"ul"}),code_block:n=>({tag:["pre",{tag:"code",attrs:n.attrs}]}),hard_break:()=>({singleTag:"br"}),heading:n=>({tag:`h${n.attrs.level}`}),image:n=>({singleTag:[{tag:"img",attrs:D(n.attrs,["src","alt","title"])}]}),list_item:()=>({tag:"li"}),ordered_list:()=>({tag:"ol"}),paragraph:()=>({tag:"p"})},marks:{bold:()=>({tag:"b"}),strike:()=>({tag:"strike"}),underline:()=>({tag:"u"}),strong:()=>({tag:"strong"}),code:()=>({tag:"code"}),italic:()=>({tag:"i"}),link(n){const e=d({},n.attrs),{linktype:t="url"}=n.attrs;return t==="email"&&(e.href=`mailto:${e.href}`),e.anchor&&(e.href=`${e.href}#${e.anchor}`,delete e.anchor),{tag:[{tag:"a",attrs:e}]}},styled:n=>({tag:[{tag:"span",attrs:n.attrs}]})}};class H{constructor(e){e||(e=U),this.marks=e.marks||[],this.nodes=e.nodes||[]}addNode(e,t){this.nodes[e]=t}addMark(e,t){this.marks[e]=t}render(e={}){if(e.content&&Array.isArray(e.content)){let t="";return e.content.forEach(r=>{t+=this.renderNode(r)}),t}return console.warn("The render method must receive an object with a content field, which is an array"),""}renderNode(e){let t=[];e.marks&&e.marks.forEach(s=>{const o=this.getMatchingMark(s);o&&t.push(this.renderOpeningTag(o.tag))});const r=this.getMatchingNode(e);return r&&r.tag&&t.push(this.renderOpeningTag(r.tag)),e.content?e.content.forEach(s=>{t.push(this.renderNode(s))}):e.text?t.push(function(s){const o={"&":"&","<":"<",">":">",'"':""","'":"'"},a=/[&<>"']/g,i=RegExp(a.source);return s&&i.test(s)?s.replace(a,c=>o[c]):s}(e.text)):r&&r.singleTag?t.push(this.renderTag(r.singleTag," /")):r&&r.html&&t.push(r.html),r&&r.tag&&t.push(this.renderClosingTag(r.tag)),e.marks&&e.marks.slice(0).reverse().forEach(s=>{const o=this.getMatchingMark(s);o&&t.push(this.renderClosingTag(o.tag))}),t.join("")}renderTag(e,t){return e.constructor===String?`<${e}${t}>`:e.map(r=>{if(r.constructor===String)return`<${r}${t}>`;{let s=`<${r.tag}`;if(r.attrs)for(let o in r.attrs){let a=r.attrs[o];a!==null&&(s+=` ${o}="${a}"`)}return`${s}${t}>`}}).join("")}renderOpeningTag(e){return this.renderTag(e,"")}renderClosingTag(e){return e.constructor===String?`</${e}>`:e.slice(0).reverse().map(t=>t.constructor===String?`</${t}>`:`</${t.tag}>`).join("")}getMatchingNode(e){if(typeof this.nodes[e.type]=="function")return this.nodes[e.type](e)}getMatchingMark(e){if(typeof this.marks[e.type]=="function")return this.marks[e.type](e)}}const V=(n=0,e=n)=>{const t=Math.abs(e-n)||0,r=n<e?1:-1;return((s=0,o)=>[...Array(s)].map(o))(t,(s,o)=>o*r+n)},m=(n,e,t)=>{const r=[];for(const s in n){if(!Object.prototype.hasOwnProperty.call(n,s))continue;const o=n[s],a=t?"":encodeURIComponent(s);let i;i=typeof o=="object"?m(o,e?e+encodeURIComponent("["+a+"]"):a,Array.isArray(o)):(e?e+encodeURIComponent("["+a+"]"):a)+"="+encodeURIComponent(o),r.push(i)}return r.join("&")};let y={},p={};class J{constructor(e,t){if(!t){let o=e.region?`-${e.region}`:"",a=e.https===!1?"http":"https";t=e.oauthToken===void 0?`${a}://api${o}.storyblok.com/v2`:`${a}://api${o}.storyblok.com/v1`}let r=Object.assign({},e.headers),s=5;e.oauthToken!==void 0&&(r.Authorization=e.oauthToken,s=3),e.rateLimit!==void 0&&(s=e.rateLimit),this.richTextResolver=new H(e.richTextSchema),typeof e.componentResolver=="function"&&this.setComponentResolver(e.componentResolver),this.maxRetries=e.maxRetries||5,this.throttle=S(this.throttledRequest,s,1e3),this.accessToken=e.accessToken,this.relations={},this.links={},this.cache=e.cache||{clear:"manual"},this.client=A.default.create({baseURL:t,timeout:e.timeout||0,headers:r,proxy:e.proxy||!1}),e.responseInterceptor&&this.client.interceptors.response.use(o=>e.responseInterceptor(o)),this.resolveNestedRelations=e.resolveNestedRelations||!0}setComponentResolver(e){this.richTextResolver.addNode("blok",t=>{let r="";return t.attrs.body.forEach(s=>{r+=e(s.component,s)}),{html:r}})}parseParams(e={}){return e.version||(e.version="published"),e.token||(e.token=this.getToken()),e.cv||(e.cv=p[e.token]),Array.isArray(e.resolve_relations)&&(e.resolve_relations=e.resolve_relations.join(",")),e}factoryParamOptions(e,t={}){return((r="")=>r.indexOf("/cdn/")>-1)(e)?this.parseParams(t):t}makeRequest(e,t,r,s){const o=this.factoryParamOptions(e,((a={},i=25,c=1)=>k(d({},a),{per_page:i,page:c}))(t,r,s));return this.cacheResponse(e,o)}get(e,t){let r=`/${e}`;const s=this.factoryParamOptions(r,t);return this.cacheResponse(r,s)}async getAll(e,t={},r){const s=t.per_page||25,o=`/${e}`,a=o.split("/");r=r||a[a.length-1];const i=await this.makeRequest(o,t,s,1),c=Math.ceil(i.total/s);return((l=[],u)=>l.map(u).reduce((f,te)=>[...f,...te],[]))([i,...await(async(l=[],u)=>Promise.all(l.map(u)))(V(1,c),async l=>this.makeRequest(o,t,s,l+1))],l=>Object.values(l.data[r]))}post(e,t){let r=`/${e}`;return this.throttle("post",r,t)}put(e,t){let r=`/${e}`;return this.throttle("put",r,t)}delete(e,t){let r=`/${e}`;return this.throttle("delete",r,t)}getStories(e){return this.get("cdn/stories",e)}getStory(e,t){return this.get(`cdn/stories/${e}`,t)}setToken(e){this.accessToken=e}getToken(){return this.accessToken}_cleanCopy(e){return JSON.parse(JSON.stringify(e))}_insertLinks(e,t){const r=e[t];r&&r.fieldtype=="multilink"&&r.linktype=="story"&&typeof r.id=="string"&&this.links[r.id]?r.story=this._cleanCopy(this.links[r.id]):r&&r.linktype==="story"&&typeof r.uuid=="string"&&this.links[r.uuid]&&(r.story=this._cleanCopy(this.links[r.uuid]))}_insertRelations(e,t,r){if(r.indexOf(e.component+"."+t)>-1){if(typeof e[t]=="string")this.relations[e[t]]&&(e[t]=this._cleanCopy(this.relations[e[t]]));else if(e[t].constructor===Array){let s=[];e[t].forEach(o=>{this.relations[o]&&s.push(this._cleanCopy(this.relations[o]))}),e[t]=s}}}_insertAssetsRelations(e,t){t.forEach(r=>{e.id===r.id&&(e.original=r,e.original.filename=e.filename,e.original.filename=e.original.filename.includes("https://s3.amazonaws.com/")?e.original.filename:e.original.filename.replace("https://","https://s3.amazonaws.com/"),delete e.original.s3_filename)})}iterateTree(e,t){let r=s=>{if(s!=null){if(s.constructor===Array)for(let o=0;o<s.length;o++)r(s[o]);else if(s.constructor===Object){if(s._stopResolving)return;for(let o in s)s.component&&s._uid||s.type==="link"?(this._insertRelations(s,o,t),this._insertLinks(s,o)):"id"in s&&s.fieldtype==="asset"&&this._insertAssetsRelations(s,t),r(s[o])}}};r(e.content)}async resolveLinks(e,t){let r=[];if(e.link_uuids){const s=e.link_uuids.length;let o=[];const a=50;for(let i=0;i<s;i+=a){const c=Math.min(s,i+a);o.push(e.link_uuids.slice(i,c))}for(let i=0;i<o.length;i++)(await this.getStories({per_page:a,language:t.language,version:t.version,by_uuids:o[i].join(",")})).data.stories.forEach(c=>{r.push(c)})}else r=e.links;r.forEach(s=>{this.links[s.uuid]=k(d({},s),{_stopResolving:!0})})}async resolveRelations(e,t){let r=[];if(e.rel_uuids){const s=e.rel_uuids.length;let o=[];const a=50;for(let i=0;i<s;i+=a){const c=Math.min(s,i+a);o.push(e.rel_uuids.slice(i,c))}for(let i=0;i<o.length;i++)(await this.getStories({per_page:a,language:t.language,version:t.version,by_uuids:o[i].join(",")})).data.stories.forEach(c=>{r.push(c)})}else r=e.rels;r.forEach(s=>{this.relations[s.uuid]=k(d({},s),{_stopResolving:!0})})}async resolveStories(e,t){let r=[];if(t.resolve_relations!==void 0&&t.resolve_relations.length>0&&(e.rels||e.rel_uuids)&&(r=t.resolve_relations.split(","),await this.resolveRelations(e,t)),["1","story","url"].indexOf(t.resolve_links)>-1&&(e.links||e.link_uuids)&&await this.resolveLinks(e,t),this.resolveNestedRelations)for(const s in this.relations)this.iterateTree(this.relations[s],r);e.story?this.iterateTree(e.story,r):e.stories.forEach(s=>{this.iterateTree(s,r)})}resolveAssetsRelations(e){const{assets:t,stories:r,story:s}=e;if(r)for(const o of r)this.iterateTree(o,t);else{if(!s)return e;this.iterateTree(s,t)}}cacheResponse(e,t,r){return r===void 0&&(r=0),new Promise(async(s,o)=>{let a=m({url:e,params:t}),i=this.cacheProvider();if(this.cache.clear==="auto"&&t.version==="draft"&&await this.flushCache(),t.version==="published"&&e!="/cdn/spaces/me"){const l=await i.get(a);if(l)return s(l)}try{let l=await this.throttle("get",e,{params:t,paramsSerializer:f=>m(f)}),u={data:l.data,headers:l.headers};if(u.data.assets&&u.data.assets.length&&this.resolveAssetsRelations(u.data),l.headers["per-page"]&&(u=Object.assign({},u,{perPage:parseInt(l.headers["per-page"]),total:parseInt(l.headers.total)})),l.status!=200)return o(l);(u.data.story||u.data.stories)&&await this.resolveStories(u.data,t),t.version==="published"&&e!="/cdn/spaces/me"&&i.set(a,u),u.data.cv&&(t.version=="draft"&&p[t.token]!=u.data.cv&&this.flushCache(),p[t.token]=u.data.cv),s(u)}catch(l){if(l.response&&l.response.status===429&&(r+=1)<this.maxRetries)return console.log(`Hit rate limit. Retrying in ${r} seconds.`),await(c=1e3*r,new Promise(u=>setTimeout(u,c))),this.cacheResponse(e,t,r).then(s).catch(o);o(l)}var c})}throttledRequest(e,t,r){return this.client[e](t,r)}cacheVersions(){return p}cacheVersion(){return p[this.accessToken]}setCacheVersion(e){this.accessToken&&(p[this.accessToken]=e)}cacheProvider(){return this.cache.type==="memory"?{get:e=>y[e],getAll:()=>y,set(e,t){y[e]=t},flush(){y={}}}:{get(){},getAll(){},set(){},flush(){}}}async flushCache(){return await this.cacheProvider().flush(),this}}const F=(n={})=>{const{apiOptions:e}=n;if(!e.accessToken){console.error("You need to provide an access token to interact with Storyblok API. Read https://www.storyblok.com/docs/api/content-delivery#topics/authentication");return}return{storyblokApi:new J(e)}};var K=n=>{if(typeof n!="object"||typeof n._editable>"u")return{};const e=JSON.parse(n._editable.replace(/^<!--#storyblok#/,"").replace(/-->$/,""));return{"data-blok-c":JSON.stringify(e),"data-blok-uid":e.id+"-"+e.uid}};let b;const j="https://app.storyblok.com/f/storyblok-v2-latest.js",Y=(n={})=>{const{bridge:e,accessToken:t,use:r=[],apiOptions:s={},richText:o={}}=n;s.accessToken=s.accessToken||t;const a={bridge:e,apiOptions:s};let i={};return r.forEach(c=>{i=d(d({},i),c(a))}),e!==!1&&R(j),b=new O(o.schema),o.resolver&&x(b,o.resolver),i},x=(n,e)=>{n.addNode("blok",t=>{let r="";return t.attrs.body.forEach(s=>{r+=e(s.component,s)}),{html:r}})},G=(n,e,t)=>{let r=t||b;if(!r){console.error("Please initialize the Storyblok SDK before calling the renderRichText function");return}return n===""?"":n?(e&&(r=new O(e.schema),e.resolver&&x(r,e.resolver)),r.render(n)):(console.warn(`${n} is not a valid Richtext object. This might be because the value of the richtext field is empty.
|
|
5
|
+
*/function j(s){return typeof s=="number"&&s==s&&s!==1/0&&s!==-1/0}function P(s,e,t){if(!j(e))throw new TypeError("Expected `limit` to be a finite number");if(!j(t))throw new TypeError("Expected `interval` to be a finite number");var r=[],o=[],n=0,i=function(){n++;var c=setTimeout(function(){n--,r.length>0&&i(),o=o.filter(function(h){return h!==c})},t);o.indexOf(c)<0&&o.push(c);var l=r.shift();l.resolve(s.apply(l.self,l.args))},a=function(){var c=arguments,l=this;return new Promise(function(h,g){r.push({resolve:h,reject:g,args:c,self:l}),n<e&&i()})};return a.abort=function(){o.forEach(clearTimeout),o=[],r.forEach(function(c){c.reject(new throttle.AbortError)}),r.length=0},a}P.AbortError=function(){Error.call(this,"Throttled function aborted"),this.name="AbortError"};const Z=function(s,e){if(!s)return null;let t={};for(let r in s){let o=s[r];e.indexOf(r)>-1&&o!==null&&(t[r]=o)}return t};var ee={nodes:{horizontal_rule:()=>({singleTag:"hr"}),blockquote:()=>({tag:"blockquote"}),bullet_list:()=>({tag:"ul"}),code_block:s=>({tag:["pre",{tag:"code",attrs:s.attrs}]}),hard_break:()=>({singleTag:"br"}),heading:s=>({tag:`h${s.attrs.level}`}),image:s=>({singleTag:[{tag:"img",attrs:Z(s.attrs,["src","alt","title"])}]}),list_item:()=>({tag:"li"}),ordered_list:()=>({tag:"ol"}),paragraph:()=>({tag:"p"})},marks:{bold:()=>({tag:"b"}),strike:()=>({tag:"strike"}),underline:()=>({tag:"u"}),strong:()=>({tag:"strong"}),code:()=>({tag:"code"}),italic:()=>({tag:"i"}),link(s){const e=d({},s.attrs),{linktype:t="url"}=s.attrs;return t==="email"&&(e.href=`mailto:${e.href}`),e.anchor&&(e.href=`${e.href}#${e.anchor}`,delete e.anchor),{tag:[{tag:"a",attrs:e}]}},styled:s=>({tag:[{tag:"span",attrs:s.attrs}]})}};class te{constructor(e){e||(e=ee),this.marks=e.marks||[],this.nodes=e.nodes||[]}addNode(e,t){this.nodes[e]=t}addMark(e,t){this.marks[e]=t}render(e={}){if(e.content&&Array.isArray(e.content)){let t="";return e.content.forEach(r=>{t+=this.renderNode(r)}),t}return console.warn("The render method must receive an object with a content field, which is an array"),""}renderNode(e){let t=[];e.marks&&e.marks.forEach(o=>{const n=this.getMatchingMark(o);n&&t.push(this.renderOpeningTag(n.tag))});const r=this.getMatchingNode(e);return r&&r.tag&&t.push(this.renderOpeningTag(r.tag)),e.content?e.content.forEach(o=>{t.push(this.renderNode(o))}):e.text?t.push(function(o){const n={"&":"&","<":"<",">":">",'"':""","'":"'"},i=/[&<>"']/g,a=RegExp(i.source);return o&&a.test(o)?o.replace(i,c=>n[c]):o}(e.text)):r&&r.singleTag?t.push(this.renderTag(r.singleTag," /")):r&&r.html&&t.push(r.html),r&&r.tag&&t.push(this.renderClosingTag(r.tag)),e.marks&&e.marks.slice(0).reverse().forEach(o=>{const n=this.getMatchingMark(o);n&&t.push(this.renderClosingTag(n.tag))}),t.join("")}renderTag(e,t){return e.constructor===String?`<${e}${t}>`:e.map(r=>{if(r.constructor===String)return`<${r}${t}>`;{let o=`<${r.tag}`;if(r.attrs)for(let n in r.attrs){let i=r.attrs[n];i!==null&&(o+=` ${n}="${i}"`)}return`${o}${t}>`}}).join("")}renderOpeningTag(e){return this.renderTag(e,"")}renderClosingTag(e){return e.constructor===String?`</${e}>`:e.slice(0).reverse().map(t=>t.constructor===String?`</${t}>`:`</${t.tag}>`).join("")}getMatchingNode(e){if(typeof this.nodes[e.type]=="function")return this.nodes[e.type](e)}getMatchingMark(e){if(typeof this.marks[e.type]=="function")return this.marks[e.type](e)}}const re=(s=0,e=s)=>{const t=Math.abs(e-s)||0,r=s<e?1:-1;return((o=0,n)=>[...Array(o)].map(n))(t,(o,n)=>n*r+s)},b=(s,e,t)=>{const r=[];for(const o in s){if(!Object.prototype.hasOwnProperty.call(s,o))continue;const n=s[o],i=t?"":encodeURIComponent(o);let a;a=typeof n=="object"?b(n,e?e+encodeURIComponent("["+i+"]"):i,Array.isArray(n)):(e?e+encodeURIComponent("["+i+"]"):i)+"="+encodeURIComponent(n),r.push(a)}return r.join("&")};let y={},f={};class se{constructor(e,t){if(!t){let n=e.region?`-${e.region}`:"",i=e.https===!1?"http":"https";t=e.oauthToken===void 0?`${i}://api${n}.storyblok.com/v2`:`${i}://api${n}.storyblok.com/v1`}let r=Object.assign({},e.headers),o=5;e.oauthToken!==void 0&&(r.Authorization=e.oauthToken,o=3),e.rateLimit!==void 0&&(o=e.rateLimit),this.richTextResolver=new te(e.richTextSchema),typeof e.componentResolver=="function"&&this.setComponentResolver(e.componentResolver),this.maxRetries=e.maxRetries||5,this.throttle=P(this.throttledRequest,o,1e3),this.accessToken=e.accessToken,this.relations={},this.links={},this.cache=e.cache||{clear:"manual"},this.client=M.default.create({baseURL:t,timeout:e.timeout||0,headers:r,proxy:e.proxy||!1}),e.responseInterceptor&&this.client.interceptors.response.use(n=>e.responseInterceptor(n)),this.resolveNestedRelations=e.resolveNestedRelations||!0}setComponentResolver(e){this.richTextResolver.addNode("blok",t=>{let r="";return t.attrs.body.forEach(o=>{r+=e(o.component,o)}),{html:r}})}parseParams(e={}){return e.version||(e.version="published"),e.token||(e.token=this.getToken()),e.cv||(e.cv=f[e.token]),Array.isArray(e.resolve_relations)&&(e.resolve_relations=e.resolve_relations.join(",")),e}factoryParamOptions(e,t={}){return((r="")=>r.indexOf("/cdn/")>-1)(e)?this.parseParams(t):t}makeRequest(e,t,r,o){const n=this.factoryParamOptions(e,((i={},a=25,c=1)=>k(d({},i),{per_page:a,page:c}))(t,r,o));return this.cacheResponse(e,n)}get(e,t){let r=`/${e}`;const o=this.factoryParamOptions(r,t);return this.cacheResponse(r,o)}async getAll(e,t={},r){const o=t.per_page||25,n=`/${e}`,i=n.split("/");r=r||i[i.length-1];const a=await this.makeRequest(n,t,o,1),c=Math.ceil(a.total/o);return((l=[],h)=>l.map(h).reduce((g,fe)=>[...g,...fe],[]))([a,...await(async(l=[],h)=>Promise.all(l.map(h)))(re(1,c),async l=>this.makeRequest(n,t,o,l+1))],l=>Object.values(l.data[r]))}post(e,t){let r=`/${e}`;return this.throttle("post",r,t)}put(e,t){let r=`/${e}`;return this.throttle("put",r,t)}delete(e,t){let r=`/${e}`;return this.throttle("delete",r,t)}getStories(e){return this.get("cdn/stories",e)}getStory(e,t){return this.get(`cdn/stories/${e}`,t)}setToken(e){this.accessToken=e}getToken(){return this.accessToken}_cleanCopy(e){return JSON.parse(JSON.stringify(e))}_insertLinks(e,t){const r=e[t];r&&r.fieldtype=="multilink"&&r.linktype=="story"&&typeof r.id=="string"&&this.links[r.id]?r.story=this._cleanCopy(this.links[r.id]):r&&r.linktype==="story"&&typeof r.uuid=="string"&&this.links[r.uuid]&&(r.story=this._cleanCopy(this.links[r.uuid]))}_insertRelations(e,t,r){if(r.indexOf(e.component+"."+t)>-1){if(typeof e[t]=="string")this.relations[e[t]]&&(e[t]=this._cleanCopy(this.relations[e[t]]));else if(e[t].constructor===Array){let o=[];e[t].forEach(n=>{this.relations[n]&&o.push(this._cleanCopy(this.relations[n]))}),e[t]=o}}}_insertAssetsRelations(e,t){t.forEach(r=>{e.id===r.id&&(e.original=r,e.original.filename=e.filename,e.original.filename=e.original.filename.includes("https://s3.amazonaws.com/")?e.original.filename:e.original.filename.replace("https://","https://s3.amazonaws.com/"),delete e.original.s3_filename)})}iterateTree(e,t){let r=o=>{if(o!=null){if(o.constructor===Array)for(let n=0;n<o.length;n++)r(o[n]);else if(o.constructor===Object){if(o._stopResolving)return;for(let n in o)o.component&&o._uid||o.type==="link"?(this._insertRelations(o,n,t),this._insertLinks(o,n)):"id"in o&&o.fieldtype==="asset"&&this._insertAssetsRelations(o,t),r(o[n])}}};r(e.content)}async resolveLinks(e,t){let r=[];if(e.link_uuids){const o=e.link_uuids.length;let n=[];const i=50;for(let a=0;a<o;a+=i){const c=Math.min(o,a+i);n.push(e.link_uuids.slice(a,c))}for(let a=0;a<n.length;a++)(await this.getStories({per_page:i,language:t.language,version:t.version,by_uuids:n[a].join(",")})).data.stories.forEach(c=>{r.push(c)})}else r=e.links;r.forEach(o=>{this.links[o.uuid]=k(d({},o),{_stopResolving:!0})})}async resolveRelations(e,t){let r=[];if(e.rel_uuids){const o=e.rel_uuids.length;let n=[];const i=50;for(let a=0;a<o;a+=i){const c=Math.min(o,a+i);n.push(e.rel_uuids.slice(a,c))}for(let a=0;a<n.length;a++)(await this.getStories({per_page:i,language:t.language,version:t.version,by_uuids:n[a].join(",")})).data.stories.forEach(c=>{r.push(c)})}else r=e.rels;r.forEach(o=>{this.relations[o.uuid]=k(d({},o),{_stopResolving:!0})})}async resolveStories(e,t){let r=[];if(t.resolve_relations!==void 0&&t.resolve_relations.length>0&&(e.rels||e.rel_uuids)&&(r=t.resolve_relations.split(","),await this.resolveRelations(e,t)),["1","story","url"].indexOf(t.resolve_links)>-1&&(e.links||e.link_uuids)&&await this.resolveLinks(e,t),this.resolveNestedRelations)for(const o in this.relations)this.iterateTree(this.relations[o],r);e.story?this.iterateTree(e.story,r):e.stories.forEach(o=>{this.iterateTree(o,r)})}resolveAssetsRelations(e){const{assets:t,stories:r,story:o}=e;if(r)for(const n of r)this.iterateTree(n,t);else{if(!o)return e;this.iterateTree(o,t)}}cacheResponse(e,t,r){return r===void 0&&(r=0),new Promise(async(o,n)=>{let i=b({url:e,params:t}),a=this.cacheProvider();if(this.cache.clear==="auto"&&t.version==="draft"&&await this.flushCache(),t.version==="published"&&e!="/cdn/spaces/me"){const l=await a.get(i);if(l)return o(l)}try{let l=await this.throttle("get",e,{params:t,paramsSerializer:g=>b(g)}),h={data:l.data,headers:l.headers};if(h.data.assets&&h.data.assets.length&&this.resolveAssetsRelations(h.data),l.headers["per-page"]&&(h=Object.assign({},h,{perPage:parseInt(l.headers["per-page"]),total:parseInt(l.headers.total)})),l.status!=200)return n(l);(h.data.story||h.data.stories)&&await this.resolveStories(h.data,t),t.version==="published"&&e!="/cdn/spaces/me"&&a.set(i,h),h.data.cv&&(t.version=="draft"&&f[t.token]!=h.data.cv&&this.flushCache(),f[t.token]=h.data.cv),o(h)}catch(l){if(l.response&&l.response.status===429&&(r+=1)<this.maxRetries)return console.log(`Hit rate limit. Retrying in ${r} seconds.`),await(c=1e3*r,new Promise(h=>setTimeout(h,c))),this.cacheResponse(e,t,r).then(o).catch(n);n(l)}var c})}throttledRequest(e,t,r){return this.client[e](t,r)}cacheVersions(){return f}cacheVersion(){return f[this.accessToken]}setCacheVersion(e){this.accessToken&&(f[this.accessToken]=e)}cacheProvider(){return this.cache.type==="memory"?{get:e=>y[e],getAll:()=>y,set(e,t){y[e]=t},flush(){y={}}}:{get(){},getAll(){},set(){},flush(){}}}async flushCache(){return await this.cacheProvider().flush(),this}}const oe=(s={})=>{const{apiOptions:e}=s;if(!e.accessToken){console.error("You need to provide an access token to interact with Storyblok API. Read https://www.storyblok.com/docs/api/content-delivery#topics/authentication");return}return{storyblokApi:new se(e)}};var ne=s=>{if(typeof s!="object"||typeof s._editable>"u")return{};const e=JSON.parse(s._editable.replace(/^<!--#storyblok#/,"").replace(/-->$/,""));return{"data-blok-c":JSON.stringify(e),"data-blok-uid":e.id+"-"+e.uid}};let v;const N="https://app.storyblok.com/f/storyblok-v2-latest.js",ae=(s={})=>{const{bridge:e,accessToken:t,use:r=[],apiOptions:o={},richText:n={}}=s;o.accessToken=o.accessToken||t;const i={bridge:e,apiOptions:o};let a={};return r.forEach(c=>{a=d(d({},a),c(i))}),e!==!1&&x(N),v=new I(n.schema),n.resolver&&L(v,n.resolver),a},L=(s,e)=>{s.addNode("blok",t=>{let r="";return t.attrs.body.forEach(o=>{r+=e(o.component,o)}),{html:r}})},ie=(s,e,t)=>{let r=t||v;if(!r){console.error("Please initialize the Storyblok SDK before calling the renderRichText function");return}return s===""?"":s?(e&&(r=new I(e.schema),e.resolver&&L(r,e.resolver)),r.render(s)):(console.warn(`${s} is not a valid Richtext object. This might be because the value of the richtext field is empty.
|
|
6
6
|
|
|
7
|
-
For more info about the richtext object check https://github.com/storyblok/storyblok-js#rendering-rich-text`),"")},
|
|
7
|
+
For more info about the richtext object check https://github.com/storyblok/storyblok-js#rendering-rich-text`),"")},le=()=>x(N);function ce(s,e,t){const{storyblokApi:r}=ae({accessToken:s,use:e||[oe],apiOptions:{...t}});globalThis.storyblokApiInstance=r}function he(){return globalThis.storyblokApiInstance||console.error("storyblokApiInstance has not been initialized correctly"),globalThis.storyblokApiInstance}function ue(s,e){const t=globalThis.storyblokApiInstance.richTextResolver;if(!t){console.error("Please initialize the Storyblok SDK before calling the renderRichText function");return}return ie(s,e,t)}function de(s){return{name:"@storyblok/astro",hooks:{"astro:config:setup":({injectScript:e,updateConfig:t})=>{var o;t({vite:{plugins:[V(s.components)]}}),ce(s.accessToken,s.use,s.apiOptions),((o=s.bridge)!=null?o:!0)&&e("page",`
|
|
8
8
|
import { loadStoryblokBridge } from "@storyblok/astro";
|
|
9
9
|
loadStoryblokBridge().then(() => {
|
|
10
10
|
const { StoryblokBridge, location } = window;
|
|
@@ -16,4 +16,4 @@
|
|
|
16
16
|
}
|
|
17
17
|
});
|
|
18
18
|
});
|
|
19
|
-
`)}}}}
|
|
19
|
+
`)}}}}u.RichTextSchema=C,u.default=de,u.loadStoryblokBridge=le,u.renderRichText=ue,u.storyblokEditable=ne,u.useStoryblokApi=he,Object.defineProperties(u,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|
package/dist/storyblok-astro.mjs
CHANGED
|
@@ -1,57 +1,77 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import N from "axios";
|
|
2
|
+
const L = /[\p{Lu}]/u, M = /[\p{Ll}]/u, v = /^[\p{Lu}](?![\p{Lu}])/gu, O = /([\p{Alpha}\p{N}_]|$)/u, k = /[_.\- ]+/, U = new RegExp("^" + k.source), b = new RegExp(k.source + O.source, "gu"), T = new RegExp("\\d+" + O.source, "gu"), D = (s, e, t) => {
|
|
3
|
+
let r = !1, o = !1, n = !1;
|
|
4
|
+
for (let i = 0; i < s.length; i++) {
|
|
5
|
+
const a = s[i];
|
|
6
|
+
r && L.test(a) ? (s = s.slice(0, i) + "-" + s.slice(i), r = !1, n = o, o = !0, i++) : o && n && M.test(a) ? (s = s.slice(0, i - 1) + "-" + s.slice(i - 1), n = o, o = !1, r = !0) : (r = e(a) === a && t(a) !== a, n = o, o = t(a) === a && e(a) !== a);
|
|
7
|
+
}
|
|
8
|
+
return s;
|
|
9
|
+
}, q = (s, e) => (v.lastIndex = 0, s.replace(v, (t) => e(t))), B = (s, e) => (b.lastIndex = 0, T.lastIndex = 0, s.replace(b, (t, r) => e(r)).replace(T, (t) => e(t)));
|
|
10
|
+
function _(s, e) {
|
|
11
|
+
if (!(typeof s == "string" || Array.isArray(s)))
|
|
12
|
+
throw new TypeError("Expected the input to be `string | string[]`");
|
|
13
|
+
if (e = {
|
|
14
|
+
pascalCase: !1,
|
|
15
|
+
preserveConsecutiveUppercase: !1,
|
|
16
|
+
...e
|
|
17
|
+
}, Array.isArray(s) ? s = s.map((n) => n.trim()).filter((n) => n.length).join("-") : s = s.trim(), s.length === 0)
|
|
18
|
+
return "";
|
|
19
|
+
const t = e.locale === !1 ? (n) => n.toLowerCase() : (n) => n.toLocaleLowerCase(e.locale), r = e.locale === !1 ? (n) => n.toUpperCase() : (n) => n.toLocaleUpperCase(e.locale);
|
|
20
|
+
return s.length === 1 ? k.test(s) ? "" : e.pascalCase ? r(s) : t(s) : (s !== t(s) && (s = D(s, t, r)), s = s.replace(U, ""), s = e.preserveConsecutiveUppercase ? q(s, t) : t(s), e.pascalCase && (s = r(s.charAt(0)) + s.slice(1)), B(s, r));
|
|
21
|
+
}
|
|
22
|
+
function z(s) {
|
|
23
|
+
const e = "virtual:storyblok-components", t = "\0" + e;
|
|
4
24
|
return {
|
|
5
25
|
name: "vite-plugin-storyblok",
|
|
6
26
|
async resolveId(r) {
|
|
7
|
-
if (r ===
|
|
8
|
-
return
|
|
27
|
+
if (r === e)
|
|
28
|
+
return t;
|
|
9
29
|
},
|
|
10
30
|
async load(r) {
|
|
11
|
-
if (r ===
|
|
12
|
-
const
|
|
13
|
-
for await (const [
|
|
14
|
-
const { id:
|
|
15
|
-
|
|
31
|
+
if (r === t) {
|
|
32
|
+
const o = [];
|
|
33
|
+
for await (const [n, i] of Object.entries(s)) {
|
|
34
|
+
const { id: a } = await this.resolve("/src/" + i + ".astro");
|
|
35
|
+
o.push(`import ${_(n)} from "${a}"`);
|
|
16
36
|
}
|
|
17
|
-
return `${
|
|
37
|
+
return `${o.join(";")};export default {${Object.keys(s).map((n) => _(n)).join(",")}}`;
|
|
18
38
|
}
|
|
19
39
|
}
|
|
20
40
|
};
|
|
21
41
|
}
|
|
22
|
-
var
|
|
23
|
-
for (var
|
|
24
|
-
|
|
25
|
-
if (
|
|
26
|
-
for (var
|
|
27
|
-
|
|
28
|
-
return
|
|
29
|
-
},
|
|
30
|
-
let
|
|
31
|
-
const
|
|
32
|
-
if (typeof window > "u" || (window.storyblokRegisterEvent = (
|
|
42
|
+
var H = Object.defineProperty, V = Object.defineProperties, F = Object.getOwnPropertyDescriptors, R = Object.getOwnPropertySymbols, J = Object.prototype.hasOwnProperty, G = Object.prototype.propertyIsEnumerable, w = (s, e, t) => e in s ? H(s, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : s[e] = t, u = (s, e) => {
|
|
43
|
+
for (var t in e || (e = {}))
|
|
44
|
+
J.call(e, t) && w(s, t, e[t]);
|
|
45
|
+
if (R)
|
|
46
|
+
for (var t of R(e))
|
|
47
|
+
G.call(e, t) && w(s, t, e[t]);
|
|
48
|
+
return s;
|
|
49
|
+
}, g = (s, e) => V(s, F(e));
|
|
50
|
+
let E = !1;
|
|
51
|
+
const A = [], S = (s) => new Promise((e, t) => {
|
|
52
|
+
if (typeof window > "u" || (window.storyblokRegisterEvent = (o) => {
|
|
33
53
|
if (window.location === window.parent.location) {
|
|
34
54
|
console.warn("You are not in Draft Mode or in the Visual Editor.");
|
|
35
55
|
return;
|
|
36
56
|
}
|
|
37
|
-
|
|
57
|
+
E ? o() : A.push(o);
|
|
38
58
|
}, document.getElementById("storyblok-javascript-bridge")))
|
|
39
59
|
return;
|
|
40
60
|
const r = document.createElement("script");
|
|
41
|
-
r.async = !0, r.src =
|
|
42
|
-
|
|
61
|
+
r.async = !0, r.src = s, r.id = "storyblok-javascript-bridge", r.onerror = (o) => t(o), r.onload = (o) => {
|
|
62
|
+
A.forEach((n) => n()), E = !0, e(o);
|
|
43
63
|
}, document.getElementsByTagName("head")[0].appendChild(r);
|
|
44
|
-
}),
|
|
45
|
-
if (!
|
|
64
|
+
}), K = function(s, e) {
|
|
65
|
+
if (!s)
|
|
46
66
|
return null;
|
|
47
|
-
let
|
|
48
|
-
for (let r in
|
|
49
|
-
let
|
|
50
|
-
|
|
51
|
-
}
|
|
52
|
-
return
|
|
53
|
-
},
|
|
54
|
-
var
|
|
67
|
+
let t = {};
|
|
68
|
+
for (let r in s) {
|
|
69
|
+
let o = s[r];
|
|
70
|
+
e.indexOf(r) > -1 && o !== null && (t[r] = o);
|
|
71
|
+
}
|
|
72
|
+
return t;
|
|
73
|
+
}, Y = (s) => s === "email";
|
|
74
|
+
var W = {
|
|
55
75
|
nodes: {
|
|
56
76
|
horizontal_rule() {
|
|
57
77
|
return {
|
|
@@ -68,13 +88,13 @@ var z = {
|
|
|
68
88
|
tag: "ul"
|
|
69
89
|
};
|
|
70
90
|
},
|
|
71
|
-
code_block(
|
|
91
|
+
code_block(s) {
|
|
72
92
|
return {
|
|
73
93
|
tag: [
|
|
74
94
|
"pre",
|
|
75
95
|
{
|
|
76
96
|
tag: "code",
|
|
77
|
-
attrs:
|
|
97
|
+
attrs: s.attrs
|
|
78
98
|
}
|
|
79
99
|
]
|
|
80
100
|
};
|
|
@@ -84,17 +104,17 @@ var z = {
|
|
|
84
104
|
singleTag: "br"
|
|
85
105
|
};
|
|
86
106
|
},
|
|
87
|
-
heading(
|
|
107
|
+
heading(s) {
|
|
88
108
|
return {
|
|
89
|
-
tag: `h${
|
|
109
|
+
tag: `h${s.attrs.level}`
|
|
90
110
|
};
|
|
91
111
|
},
|
|
92
|
-
image(
|
|
112
|
+
image(s) {
|
|
93
113
|
return {
|
|
94
114
|
singleTag: [
|
|
95
115
|
{
|
|
96
116
|
tag: "img",
|
|
97
|
-
attrs:
|
|
117
|
+
attrs: K(s.attrs, ["src", "alt", "title"])
|
|
98
118
|
}
|
|
99
119
|
]
|
|
100
120
|
};
|
|
@@ -146,100 +166,100 @@ var z = {
|
|
|
146
166
|
tag: "i"
|
|
147
167
|
};
|
|
148
168
|
},
|
|
149
|
-
link(
|
|
150
|
-
const
|
|
151
|
-
return
|
|
169
|
+
link(s) {
|
|
170
|
+
const e = u({}, s.attrs), { linktype: t = "url" } = s.attrs;
|
|
171
|
+
return Y(t) && (e.href = `mailto:${e.href}`), e.anchor && (e.href = `${e.href}#${e.anchor}`, delete e.anchor), {
|
|
152
172
|
tag: [
|
|
153
173
|
{
|
|
154
174
|
tag: "a",
|
|
155
|
-
attrs:
|
|
175
|
+
attrs: e
|
|
156
176
|
}
|
|
157
177
|
]
|
|
158
178
|
};
|
|
159
179
|
},
|
|
160
|
-
styled(
|
|
180
|
+
styled(s) {
|
|
161
181
|
return {
|
|
162
182
|
tag: [
|
|
163
183
|
{
|
|
164
184
|
tag: "span",
|
|
165
|
-
attrs:
|
|
185
|
+
attrs: s.attrs
|
|
166
186
|
}
|
|
167
187
|
]
|
|
168
188
|
};
|
|
169
189
|
}
|
|
170
190
|
}
|
|
171
191
|
};
|
|
172
|
-
const
|
|
173
|
-
const
|
|
192
|
+
const Q = function(s) {
|
|
193
|
+
const e = {
|
|
174
194
|
"&": "&",
|
|
175
195
|
"<": "<",
|
|
176
196
|
">": ">",
|
|
177
197
|
'"': """,
|
|
178
198
|
"'": "'"
|
|
179
|
-
},
|
|
180
|
-
return
|
|
199
|
+
}, t = /[&<>"']/g, r = RegExp(t.source);
|
|
200
|
+
return s && r.test(s) ? s.replace(t, (o) => e[o]) : s;
|
|
181
201
|
};
|
|
182
|
-
class
|
|
183
|
-
constructor(
|
|
184
|
-
|
|
185
|
-
}
|
|
186
|
-
addNode(
|
|
187
|
-
this.nodes[
|
|
188
|
-
}
|
|
189
|
-
addMark(
|
|
190
|
-
this.marks[
|
|
191
|
-
}
|
|
192
|
-
render(
|
|
193
|
-
if (
|
|
194
|
-
let
|
|
195
|
-
return
|
|
196
|
-
|
|
197
|
-
}),
|
|
202
|
+
class x {
|
|
203
|
+
constructor(e) {
|
|
204
|
+
e || (e = W), this.marks = e.marks || [], this.nodes = e.nodes || [];
|
|
205
|
+
}
|
|
206
|
+
addNode(e, t) {
|
|
207
|
+
this.nodes[e] = t;
|
|
208
|
+
}
|
|
209
|
+
addMark(e, t) {
|
|
210
|
+
this.marks[e] = t;
|
|
211
|
+
}
|
|
212
|
+
render(e = {}) {
|
|
213
|
+
if (e.content && Array.isArray(e.content)) {
|
|
214
|
+
let t = "";
|
|
215
|
+
return e.content.forEach((r) => {
|
|
216
|
+
t += this.renderNode(r);
|
|
217
|
+
}), t;
|
|
198
218
|
}
|
|
199
219
|
return console.warn("The render method must receive an object with a content field, which is an array"), "";
|
|
200
220
|
}
|
|
201
|
-
renderNode(
|
|
202
|
-
let
|
|
203
|
-
|
|
204
|
-
const
|
|
205
|
-
|
|
221
|
+
renderNode(e) {
|
|
222
|
+
let t = [];
|
|
223
|
+
e.marks && e.marks.forEach((o) => {
|
|
224
|
+
const n = this.getMatchingMark(o);
|
|
225
|
+
n && t.push(this.renderOpeningTag(n.tag));
|
|
206
226
|
});
|
|
207
|
-
const r = this.getMatchingNode(
|
|
208
|
-
return r && r.tag &&
|
|
209
|
-
|
|
210
|
-
}) :
|
|
211
|
-
const
|
|
212
|
-
|
|
213
|
-
}),
|
|
214
|
-
}
|
|
215
|
-
renderTag(
|
|
216
|
-
return
|
|
217
|
-
if (
|
|
218
|
-
return `<${
|
|
227
|
+
const r = this.getMatchingNode(e);
|
|
228
|
+
return r && r.tag && t.push(this.renderOpeningTag(r.tag)), e.content ? e.content.forEach((o) => {
|
|
229
|
+
t.push(this.renderNode(o));
|
|
230
|
+
}) : e.text ? t.push(Q(e.text)) : r && r.singleTag ? t.push(this.renderTag(r.singleTag, " /")) : r && r.html && t.push(r.html), r && r.tag && t.push(this.renderClosingTag(r.tag)), e.marks && e.marks.slice(0).reverse().forEach((o) => {
|
|
231
|
+
const n = this.getMatchingMark(o);
|
|
232
|
+
n && t.push(this.renderClosingTag(n.tag));
|
|
233
|
+
}), t.join("");
|
|
234
|
+
}
|
|
235
|
+
renderTag(e, t) {
|
|
236
|
+
return e.constructor === String ? `<${e}${t}>` : e.map((o) => {
|
|
237
|
+
if (o.constructor === String)
|
|
238
|
+
return `<${o}${t}>`;
|
|
219
239
|
{
|
|
220
|
-
let
|
|
221
|
-
if (
|
|
222
|
-
for (let
|
|
223
|
-
let
|
|
224
|
-
|
|
240
|
+
let n = `<${o.tag}`;
|
|
241
|
+
if (o.attrs)
|
|
242
|
+
for (let i in o.attrs) {
|
|
243
|
+
let a = o.attrs[i];
|
|
244
|
+
a !== null && (n += ` ${i}="${a}"`);
|
|
225
245
|
}
|
|
226
|
-
return `${
|
|
246
|
+
return `${n}${t}>`;
|
|
227
247
|
}
|
|
228
248
|
}).join("");
|
|
229
249
|
}
|
|
230
|
-
renderOpeningTag(
|
|
231
|
-
return this.renderTag(
|
|
250
|
+
renderOpeningTag(e) {
|
|
251
|
+
return this.renderTag(e, "");
|
|
232
252
|
}
|
|
233
|
-
renderClosingTag(
|
|
234
|
-
return
|
|
253
|
+
renderClosingTag(e) {
|
|
254
|
+
return e.constructor === String ? `</${e}>` : e.slice(0).reverse().map((r) => r.constructor === String ? `</${r}>` : `</${r.tag}>`).join("");
|
|
235
255
|
}
|
|
236
|
-
getMatchingNode(
|
|
237
|
-
if (typeof this.nodes[
|
|
238
|
-
return this.nodes[
|
|
256
|
+
getMatchingNode(e) {
|
|
257
|
+
if (typeof this.nodes[e.type] == "function")
|
|
258
|
+
return this.nodes[e.type](e);
|
|
239
259
|
}
|
|
240
|
-
getMatchingMark(
|
|
241
|
-
if (typeof this.marks[
|
|
242
|
-
return this.marks[
|
|
260
|
+
getMatchingMark(e) {
|
|
261
|
+
if (typeof this.marks[e.type] == "function")
|
|
262
|
+
return this.marks[e.type](e);
|
|
243
263
|
}
|
|
244
264
|
}
|
|
245
265
|
/*!
|
|
@@ -247,319 +267,319 @@ class R {
|
|
|
247
267
|
* Universal JavaScript SDK for Storyblok's API
|
|
248
268
|
* (c) 2020-2022 Stobylok Team
|
|
249
269
|
*/
|
|
250
|
-
function
|
|
251
|
-
return typeof
|
|
270
|
+
function $(s) {
|
|
271
|
+
return typeof s == "number" && s == s && s !== 1 / 0 && s !== -1 / 0;
|
|
252
272
|
}
|
|
253
|
-
function
|
|
254
|
-
if (
|
|
273
|
+
function C(s, e, t) {
|
|
274
|
+
if (!$(e))
|
|
255
275
|
throw new TypeError("Expected `limit` to be a finite number");
|
|
256
|
-
if (
|
|
276
|
+
if (!$(t))
|
|
257
277
|
throw new TypeError("Expected `interval` to be a finite number");
|
|
258
|
-
var r = [],
|
|
259
|
-
|
|
278
|
+
var r = [], o = [], n = 0, i = function() {
|
|
279
|
+
n++;
|
|
260
280
|
var c = setTimeout(function() {
|
|
261
|
-
|
|
281
|
+
n--, r.length > 0 && i(), o = o.filter(function(h) {
|
|
262
282
|
return h !== c;
|
|
263
283
|
});
|
|
264
|
-
},
|
|
265
|
-
|
|
284
|
+
}, t);
|
|
285
|
+
o.indexOf(c) < 0 && o.push(c);
|
|
266
286
|
var l = r.shift();
|
|
267
|
-
l.resolve(
|
|
268
|
-
},
|
|
287
|
+
l.resolve(s.apply(l.self, l.args));
|
|
288
|
+
}, a = function() {
|
|
269
289
|
var c = arguments, l = this;
|
|
270
290
|
return new Promise(function(h, p) {
|
|
271
|
-
r.push({ resolve: h, reject: p, args: c, self: l }),
|
|
291
|
+
r.push({ resolve: h, reject: p, args: c, self: l }), n < e && i();
|
|
272
292
|
});
|
|
273
293
|
};
|
|
274
|
-
return
|
|
275
|
-
|
|
294
|
+
return a.abort = function() {
|
|
295
|
+
o.forEach(clearTimeout), o = [], r.forEach(function(c) {
|
|
276
296
|
c.reject(new throttle.AbortError());
|
|
277
297
|
}), r.length = 0;
|
|
278
|
-
},
|
|
298
|
+
}, a;
|
|
279
299
|
}
|
|
280
|
-
|
|
300
|
+
C.AbortError = function() {
|
|
281
301
|
Error.call(this, "Throttled function aborted"), this.name = "AbortError";
|
|
282
302
|
};
|
|
283
|
-
const
|
|
284
|
-
if (!
|
|
303
|
+
const X = function(s, e) {
|
|
304
|
+
if (!s)
|
|
285
305
|
return null;
|
|
286
|
-
let
|
|
287
|
-
for (let r in
|
|
288
|
-
let
|
|
289
|
-
|
|
306
|
+
let t = {};
|
|
307
|
+
for (let r in s) {
|
|
308
|
+
let o = s[r];
|
|
309
|
+
e.indexOf(r) > -1 && o !== null && (t[r] = o);
|
|
290
310
|
}
|
|
291
|
-
return
|
|
311
|
+
return t;
|
|
292
312
|
};
|
|
293
|
-
var
|
|
294
|
-
const
|
|
295
|
-
return
|
|
296
|
-
}, styled: (
|
|
297
|
-
class
|
|
298
|
-
constructor(
|
|
299
|
-
|
|
300
|
-
}
|
|
301
|
-
addNode(
|
|
302
|
-
this.nodes[
|
|
303
|
-
}
|
|
304
|
-
addMark(
|
|
305
|
-
this.marks[
|
|
306
|
-
}
|
|
307
|
-
render(
|
|
308
|
-
if (
|
|
309
|
-
let
|
|
310
|
-
return
|
|
311
|
-
|
|
312
|
-
}),
|
|
313
|
+
var Z = { nodes: { horizontal_rule: () => ({ singleTag: "hr" }), blockquote: () => ({ tag: "blockquote" }), bullet_list: () => ({ tag: "ul" }), code_block: (s) => ({ tag: ["pre", { tag: "code", attrs: s.attrs }] }), hard_break: () => ({ singleTag: "br" }), heading: (s) => ({ tag: `h${s.attrs.level}` }), image: (s) => ({ singleTag: [{ tag: "img", attrs: X(s.attrs, ["src", "alt", "title"]) }] }), list_item: () => ({ tag: "li" }), ordered_list: () => ({ tag: "ol" }), paragraph: () => ({ tag: "p" }) }, marks: { bold: () => ({ tag: "b" }), strike: () => ({ tag: "strike" }), underline: () => ({ tag: "u" }), strong: () => ({ tag: "strong" }), code: () => ({ tag: "code" }), italic: () => ({ tag: "i" }), link(s) {
|
|
314
|
+
const e = u({}, s.attrs), { linktype: t = "url" } = s.attrs;
|
|
315
|
+
return t === "email" && (e.href = `mailto:${e.href}`), e.anchor && (e.href = `${e.href}#${e.anchor}`, delete e.anchor), { tag: [{ tag: "a", attrs: e }] };
|
|
316
|
+
}, styled: (s) => ({ tag: [{ tag: "span", attrs: s.attrs }] }) } };
|
|
317
|
+
class ee {
|
|
318
|
+
constructor(e) {
|
|
319
|
+
e || (e = Z), this.marks = e.marks || [], this.nodes = e.nodes || [];
|
|
320
|
+
}
|
|
321
|
+
addNode(e, t) {
|
|
322
|
+
this.nodes[e] = t;
|
|
323
|
+
}
|
|
324
|
+
addMark(e, t) {
|
|
325
|
+
this.marks[e] = t;
|
|
326
|
+
}
|
|
327
|
+
render(e = {}) {
|
|
328
|
+
if (e.content && Array.isArray(e.content)) {
|
|
329
|
+
let t = "";
|
|
330
|
+
return e.content.forEach((r) => {
|
|
331
|
+
t += this.renderNode(r);
|
|
332
|
+
}), t;
|
|
313
333
|
}
|
|
314
334
|
return console.warn("The render method must receive an object with a content field, which is an array"), "";
|
|
315
335
|
}
|
|
316
|
-
renderNode(
|
|
317
|
-
let
|
|
318
|
-
|
|
319
|
-
const
|
|
320
|
-
|
|
336
|
+
renderNode(e) {
|
|
337
|
+
let t = [];
|
|
338
|
+
e.marks && e.marks.forEach((o) => {
|
|
339
|
+
const n = this.getMatchingMark(o);
|
|
340
|
+
n && t.push(this.renderOpeningTag(n.tag));
|
|
321
341
|
});
|
|
322
|
-
const r = this.getMatchingNode(
|
|
323
|
-
return r && r.tag &&
|
|
324
|
-
|
|
325
|
-
}) :
|
|
326
|
-
const
|
|
327
|
-
return
|
|
328
|
-
}(
|
|
329
|
-
const
|
|
330
|
-
|
|
331
|
-
}),
|
|
332
|
-
}
|
|
333
|
-
renderTag(
|
|
334
|
-
return
|
|
342
|
+
const r = this.getMatchingNode(e);
|
|
343
|
+
return r && r.tag && t.push(this.renderOpeningTag(r.tag)), e.content ? e.content.forEach((o) => {
|
|
344
|
+
t.push(this.renderNode(o));
|
|
345
|
+
}) : e.text ? t.push(function(o) {
|
|
346
|
+
const n = { "&": "&", "<": "<", ">": ">", '"': """, "'": "'" }, i = /[&<>"']/g, a = RegExp(i.source);
|
|
347
|
+
return o && a.test(o) ? o.replace(i, (c) => n[c]) : o;
|
|
348
|
+
}(e.text)) : r && r.singleTag ? t.push(this.renderTag(r.singleTag, " /")) : r && r.html && t.push(r.html), r && r.tag && t.push(this.renderClosingTag(r.tag)), e.marks && e.marks.slice(0).reverse().forEach((o) => {
|
|
349
|
+
const n = this.getMatchingMark(o);
|
|
350
|
+
n && t.push(this.renderClosingTag(n.tag));
|
|
351
|
+
}), t.join("");
|
|
352
|
+
}
|
|
353
|
+
renderTag(e, t) {
|
|
354
|
+
return e.constructor === String ? `<${e}${t}>` : e.map((r) => {
|
|
335
355
|
if (r.constructor === String)
|
|
336
|
-
return `<${r}${
|
|
356
|
+
return `<${r}${t}>`;
|
|
337
357
|
{
|
|
338
|
-
let
|
|
358
|
+
let o = `<${r.tag}`;
|
|
339
359
|
if (r.attrs)
|
|
340
|
-
for (let
|
|
341
|
-
let
|
|
342
|
-
|
|
360
|
+
for (let n in r.attrs) {
|
|
361
|
+
let i = r.attrs[n];
|
|
362
|
+
i !== null && (o += ` ${n}="${i}"`);
|
|
343
363
|
}
|
|
344
|
-
return `${
|
|
364
|
+
return `${o}${t}>`;
|
|
345
365
|
}
|
|
346
366
|
}).join("");
|
|
347
367
|
}
|
|
348
|
-
renderOpeningTag(
|
|
349
|
-
return this.renderTag(
|
|
368
|
+
renderOpeningTag(e) {
|
|
369
|
+
return this.renderTag(e, "");
|
|
350
370
|
}
|
|
351
|
-
renderClosingTag(
|
|
352
|
-
return
|
|
371
|
+
renderClosingTag(e) {
|
|
372
|
+
return e.constructor === String ? `</${e}>` : e.slice(0).reverse().map((t) => t.constructor === String ? `</${t}>` : `</${t.tag}>`).join("");
|
|
353
373
|
}
|
|
354
|
-
getMatchingNode(
|
|
355
|
-
if (typeof this.nodes[
|
|
356
|
-
return this.nodes[
|
|
374
|
+
getMatchingNode(e) {
|
|
375
|
+
if (typeof this.nodes[e.type] == "function")
|
|
376
|
+
return this.nodes[e.type](e);
|
|
357
377
|
}
|
|
358
|
-
getMatchingMark(
|
|
359
|
-
if (typeof this.marks[
|
|
360
|
-
return this.marks[
|
|
378
|
+
getMatchingMark(e) {
|
|
379
|
+
if (typeof this.marks[e.type] == "function")
|
|
380
|
+
return this.marks[e.type](e);
|
|
361
381
|
}
|
|
362
382
|
}
|
|
363
|
-
const
|
|
364
|
-
const
|
|
365
|
-
return ((
|
|
366
|
-
}, y = (
|
|
383
|
+
const te = (s = 0, e = s) => {
|
|
384
|
+
const t = Math.abs(e - s) || 0, r = s < e ? 1 : -1;
|
|
385
|
+
return ((o = 0, n) => [...Array(o)].map(n))(t, (o, n) => n * r + s);
|
|
386
|
+
}, y = (s, e, t) => {
|
|
367
387
|
const r = [];
|
|
368
|
-
for (const
|
|
369
|
-
if (!Object.prototype.hasOwnProperty.call(
|
|
388
|
+
for (const o in s) {
|
|
389
|
+
if (!Object.prototype.hasOwnProperty.call(s, o))
|
|
370
390
|
continue;
|
|
371
|
-
const
|
|
372
|
-
let
|
|
373
|
-
|
|
391
|
+
const n = s[o], i = t ? "" : encodeURIComponent(o);
|
|
392
|
+
let a;
|
|
393
|
+
a = typeof n == "object" ? y(n, e ? e + encodeURIComponent("[" + i + "]") : i, Array.isArray(n)) : (e ? e + encodeURIComponent("[" + i + "]") : i) + "=" + encodeURIComponent(n), r.push(a);
|
|
374
394
|
}
|
|
375
395
|
return r.join("&");
|
|
376
396
|
};
|
|
377
|
-
let
|
|
378
|
-
class
|
|
379
|
-
constructor(
|
|
380
|
-
if (!
|
|
381
|
-
let
|
|
382
|
-
|
|
397
|
+
let f = {}, d = {};
|
|
398
|
+
class re {
|
|
399
|
+
constructor(e, t) {
|
|
400
|
+
if (!t) {
|
|
401
|
+
let n = e.region ? `-${e.region}` : "", i = e.https === !1 ? "http" : "https";
|
|
402
|
+
t = e.oauthToken === void 0 ? `${i}://api${n}.storyblok.com/v2` : `${i}://api${n}.storyblok.com/v1`;
|
|
383
403
|
}
|
|
384
|
-
let r = Object.assign({},
|
|
385
|
-
|
|
404
|
+
let r = Object.assign({}, e.headers), o = 5;
|
|
405
|
+
e.oauthToken !== void 0 && (r.Authorization = e.oauthToken, o = 3), e.rateLimit !== void 0 && (o = e.rateLimit), this.richTextResolver = new ee(e.richTextSchema), typeof e.componentResolver == "function" && this.setComponentResolver(e.componentResolver), this.maxRetries = e.maxRetries || 5, this.throttle = C(this.throttledRequest, o, 1e3), this.accessToken = e.accessToken, this.relations = {}, this.links = {}, this.cache = e.cache || { clear: "manual" }, this.client = N.create({ baseURL: t, timeout: e.timeout || 0, headers: r, proxy: e.proxy || !1 }), e.responseInterceptor && this.client.interceptors.response.use((n) => e.responseInterceptor(n)), this.resolveNestedRelations = e.resolveNestedRelations || !0;
|
|
386
406
|
}
|
|
387
|
-
setComponentResolver(
|
|
388
|
-
this.richTextResolver.addNode("blok", (
|
|
407
|
+
setComponentResolver(e) {
|
|
408
|
+
this.richTextResolver.addNode("blok", (t) => {
|
|
389
409
|
let r = "";
|
|
390
|
-
return
|
|
391
|
-
r +=
|
|
410
|
+
return t.attrs.body.forEach((o) => {
|
|
411
|
+
r += e(o.component, o);
|
|
392
412
|
}), { html: r };
|
|
393
413
|
});
|
|
394
414
|
}
|
|
395
|
-
parseParams(
|
|
396
|
-
return
|
|
415
|
+
parseParams(e = {}) {
|
|
416
|
+
return e.version || (e.version = "published"), e.token || (e.token = this.getToken()), e.cv || (e.cv = d[e.token]), Array.isArray(e.resolve_relations) && (e.resolve_relations = e.resolve_relations.join(",")), e;
|
|
397
417
|
}
|
|
398
|
-
factoryParamOptions(
|
|
399
|
-
return ((r = "") => r.indexOf("/cdn/") > -1)(
|
|
418
|
+
factoryParamOptions(e, t = {}) {
|
|
419
|
+
return ((r = "") => r.indexOf("/cdn/") > -1)(e) ? this.parseParams(t) : t;
|
|
400
420
|
}
|
|
401
|
-
makeRequest(
|
|
402
|
-
const
|
|
403
|
-
return this.cacheResponse(
|
|
421
|
+
makeRequest(e, t, r, o) {
|
|
422
|
+
const n = this.factoryParamOptions(e, ((i = {}, a = 25, c = 1) => g(u({}, i), { per_page: a, page: c }))(t, r, o));
|
|
423
|
+
return this.cacheResponse(e, n);
|
|
404
424
|
}
|
|
405
|
-
get(
|
|
406
|
-
let r = `/${
|
|
407
|
-
const
|
|
408
|
-
return this.cacheResponse(r,
|
|
425
|
+
get(e, t) {
|
|
426
|
+
let r = `/${e}`;
|
|
427
|
+
const o = this.factoryParamOptions(r, t);
|
|
428
|
+
return this.cacheResponse(r, o);
|
|
409
429
|
}
|
|
410
|
-
async getAll(
|
|
411
|
-
const
|
|
412
|
-
r = r ||
|
|
413
|
-
const
|
|
414
|
-
return ((l = [], h) => l.map(h).reduce((p,
|
|
430
|
+
async getAll(e, t = {}, r) {
|
|
431
|
+
const o = t.per_page || 25, n = `/${e}`, i = n.split("/");
|
|
432
|
+
r = r || i[i.length - 1];
|
|
433
|
+
const a = await this.makeRequest(n, t, o, 1), c = Math.ceil(a.total / o);
|
|
434
|
+
return ((l = [], h) => l.map(h).reduce((p, j) => [...p, ...j], []))([a, ...await (async (l = [], h) => Promise.all(l.map(h)))(te(1, c), async (l) => this.makeRequest(n, t, o, l + 1))], (l) => Object.values(l.data[r]));
|
|
415
435
|
}
|
|
416
|
-
post(
|
|
417
|
-
let r = `/${
|
|
418
|
-
return this.throttle("post", r,
|
|
436
|
+
post(e, t) {
|
|
437
|
+
let r = `/${e}`;
|
|
438
|
+
return this.throttle("post", r, t);
|
|
419
439
|
}
|
|
420
|
-
put(
|
|
421
|
-
let r = `/${
|
|
422
|
-
return this.throttle("put", r,
|
|
440
|
+
put(e, t) {
|
|
441
|
+
let r = `/${e}`;
|
|
442
|
+
return this.throttle("put", r, t);
|
|
423
443
|
}
|
|
424
|
-
delete(
|
|
425
|
-
let r = `/${
|
|
426
|
-
return this.throttle("delete", r,
|
|
444
|
+
delete(e, t) {
|
|
445
|
+
let r = `/${e}`;
|
|
446
|
+
return this.throttle("delete", r, t);
|
|
427
447
|
}
|
|
428
|
-
getStories(
|
|
429
|
-
return this.get("cdn/stories",
|
|
448
|
+
getStories(e) {
|
|
449
|
+
return this.get("cdn/stories", e);
|
|
430
450
|
}
|
|
431
|
-
getStory(
|
|
432
|
-
return this.get(`cdn/stories/${
|
|
451
|
+
getStory(e, t) {
|
|
452
|
+
return this.get(`cdn/stories/${e}`, t);
|
|
433
453
|
}
|
|
434
|
-
setToken(
|
|
435
|
-
this.accessToken =
|
|
454
|
+
setToken(e) {
|
|
455
|
+
this.accessToken = e;
|
|
436
456
|
}
|
|
437
457
|
getToken() {
|
|
438
458
|
return this.accessToken;
|
|
439
459
|
}
|
|
440
|
-
_cleanCopy(
|
|
441
|
-
return JSON.parse(JSON.stringify(
|
|
460
|
+
_cleanCopy(e) {
|
|
461
|
+
return JSON.parse(JSON.stringify(e));
|
|
442
462
|
}
|
|
443
|
-
_insertLinks(
|
|
444
|
-
const r = t
|
|
463
|
+
_insertLinks(e, t) {
|
|
464
|
+
const r = e[t];
|
|
445
465
|
r && r.fieldtype == "multilink" && r.linktype == "story" && typeof r.id == "string" && this.links[r.id] ? r.story = this._cleanCopy(this.links[r.id]) : r && r.linktype === "story" && typeof r.uuid == "string" && this.links[r.uuid] && (r.story = this._cleanCopy(this.links[r.uuid]));
|
|
446
466
|
}
|
|
447
|
-
_insertRelations(
|
|
448
|
-
if (r.indexOf(
|
|
449
|
-
if (typeof t
|
|
450
|
-
this.relations[t
|
|
451
|
-
else if (t
|
|
452
|
-
let
|
|
453
|
-
t
|
|
454
|
-
this.relations[
|
|
455
|
-
}), t
|
|
467
|
+
_insertRelations(e, t, r) {
|
|
468
|
+
if (r.indexOf(e.component + "." + t) > -1) {
|
|
469
|
+
if (typeof e[t] == "string")
|
|
470
|
+
this.relations[e[t]] && (e[t] = this._cleanCopy(this.relations[e[t]]));
|
|
471
|
+
else if (e[t].constructor === Array) {
|
|
472
|
+
let o = [];
|
|
473
|
+
e[t].forEach((n) => {
|
|
474
|
+
this.relations[n] && o.push(this._cleanCopy(this.relations[n]));
|
|
475
|
+
}), e[t] = o;
|
|
456
476
|
}
|
|
457
477
|
}
|
|
458
478
|
}
|
|
459
|
-
_insertAssetsRelations(
|
|
460
|
-
|
|
461
|
-
|
|
479
|
+
_insertAssetsRelations(e, t) {
|
|
480
|
+
t.forEach((r) => {
|
|
481
|
+
e.id === r.id && (e.original = r, e.original.filename = e.filename, e.original.filename = e.original.filename.includes("https://s3.amazonaws.com/") ? e.original.filename : e.original.filename.replace("https://", "https://s3.amazonaws.com/"), delete e.original.s3_filename);
|
|
462
482
|
});
|
|
463
483
|
}
|
|
464
|
-
iterateTree(
|
|
465
|
-
let r = (
|
|
466
|
-
if (
|
|
467
|
-
if (
|
|
468
|
-
for (let
|
|
469
|
-
r(
|
|
470
|
-
else if (
|
|
471
|
-
if (
|
|
484
|
+
iterateTree(e, t) {
|
|
485
|
+
let r = (o) => {
|
|
486
|
+
if (o != null) {
|
|
487
|
+
if (o.constructor === Array)
|
|
488
|
+
for (let n = 0; n < o.length; n++)
|
|
489
|
+
r(o[n]);
|
|
490
|
+
else if (o.constructor === Object) {
|
|
491
|
+
if (o._stopResolving)
|
|
472
492
|
return;
|
|
473
|
-
for (let
|
|
474
|
-
|
|
493
|
+
for (let n in o)
|
|
494
|
+
o.component && o._uid || o.type === "link" ? (this._insertRelations(o, n, t), this._insertLinks(o, n)) : "id" in o && o.fieldtype === "asset" && this._insertAssetsRelations(o, t), r(o[n]);
|
|
475
495
|
}
|
|
476
496
|
}
|
|
477
497
|
};
|
|
478
|
-
r(
|
|
498
|
+
r(e.content);
|
|
479
499
|
}
|
|
480
|
-
async resolveLinks(
|
|
500
|
+
async resolveLinks(e, t) {
|
|
481
501
|
let r = [];
|
|
482
|
-
if (
|
|
483
|
-
const
|
|
484
|
-
let
|
|
485
|
-
const
|
|
486
|
-
for (let
|
|
487
|
-
const c = Math.min(
|
|
488
|
-
|
|
502
|
+
if (e.link_uuids) {
|
|
503
|
+
const o = e.link_uuids.length;
|
|
504
|
+
let n = [];
|
|
505
|
+
const i = 50;
|
|
506
|
+
for (let a = 0; a < o; a += i) {
|
|
507
|
+
const c = Math.min(o, a + i);
|
|
508
|
+
n.push(e.link_uuids.slice(a, c));
|
|
489
509
|
}
|
|
490
|
-
for (let
|
|
491
|
-
(await this.getStories({ per_page:
|
|
510
|
+
for (let a = 0; a < n.length; a++)
|
|
511
|
+
(await this.getStories({ per_page: i, language: t.language, version: t.version, by_uuids: n[a].join(",") })).data.stories.forEach((c) => {
|
|
492
512
|
r.push(c);
|
|
493
513
|
});
|
|
494
514
|
} else
|
|
495
|
-
r =
|
|
496
|
-
r.forEach((
|
|
497
|
-
this.links[
|
|
515
|
+
r = e.links;
|
|
516
|
+
r.forEach((o) => {
|
|
517
|
+
this.links[o.uuid] = g(u({}, o), { _stopResolving: !0 });
|
|
498
518
|
});
|
|
499
519
|
}
|
|
500
|
-
async resolveRelations(
|
|
520
|
+
async resolveRelations(e, t) {
|
|
501
521
|
let r = [];
|
|
502
|
-
if (
|
|
503
|
-
const
|
|
504
|
-
let
|
|
505
|
-
const
|
|
506
|
-
for (let
|
|
507
|
-
const c = Math.min(
|
|
508
|
-
|
|
522
|
+
if (e.rel_uuids) {
|
|
523
|
+
const o = e.rel_uuids.length;
|
|
524
|
+
let n = [];
|
|
525
|
+
const i = 50;
|
|
526
|
+
for (let a = 0; a < o; a += i) {
|
|
527
|
+
const c = Math.min(o, a + i);
|
|
528
|
+
n.push(e.rel_uuids.slice(a, c));
|
|
509
529
|
}
|
|
510
|
-
for (let
|
|
511
|
-
(await this.getStories({ per_page:
|
|
530
|
+
for (let a = 0; a < n.length; a++)
|
|
531
|
+
(await this.getStories({ per_page: i, language: t.language, version: t.version, by_uuids: n[a].join(",") })).data.stories.forEach((c) => {
|
|
512
532
|
r.push(c);
|
|
513
533
|
});
|
|
514
534
|
} else
|
|
515
|
-
r =
|
|
516
|
-
r.forEach((
|
|
517
|
-
this.relations[
|
|
535
|
+
r = e.rels;
|
|
536
|
+
r.forEach((o) => {
|
|
537
|
+
this.relations[o.uuid] = g(u({}, o), { _stopResolving: !0 });
|
|
518
538
|
});
|
|
519
539
|
}
|
|
520
|
-
async resolveStories(
|
|
540
|
+
async resolveStories(e, t) {
|
|
521
541
|
let r = [];
|
|
522
|
-
if (
|
|
523
|
-
for (const
|
|
524
|
-
this.iterateTree(this.relations[
|
|
525
|
-
|
|
526
|
-
this.iterateTree(
|
|
542
|
+
if (t.resolve_relations !== void 0 && t.resolve_relations.length > 0 && (e.rels || e.rel_uuids) && (r = t.resolve_relations.split(","), await this.resolveRelations(e, t)), ["1", "story", "url"].indexOf(t.resolve_links) > -1 && (e.links || e.link_uuids) && await this.resolveLinks(e, t), this.resolveNestedRelations)
|
|
543
|
+
for (const o in this.relations)
|
|
544
|
+
this.iterateTree(this.relations[o], r);
|
|
545
|
+
e.story ? this.iterateTree(e.story, r) : e.stories.forEach((o) => {
|
|
546
|
+
this.iterateTree(o, r);
|
|
527
547
|
});
|
|
528
548
|
}
|
|
529
|
-
resolveAssetsRelations(
|
|
530
|
-
const { assets:
|
|
549
|
+
resolveAssetsRelations(e) {
|
|
550
|
+
const { assets: t, stories: r, story: o } = e;
|
|
531
551
|
if (r)
|
|
532
|
-
for (const
|
|
533
|
-
this.iterateTree(
|
|
552
|
+
for (const n of r)
|
|
553
|
+
this.iterateTree(n, t);
|
|
534
554
|
else {
|
|
535
|
-
if (!
|
|
536
|
-
return
|
|
537
|
-
this.iterateTree(
|
|
555
|
+
if (!o)
|
|
556
|
+
return e;
|
|
557
|
+
this.iterateTree(o, t);
|
|
538
558
|
}
|
|
539
559
|
}
|
|
540
|
-
cacheResponse(
|
|
541
|
-
return r === void 0 && (r = 0), new Promise(async (
|
|
542
|
-
let
|
|
543
|
-
if (this.cache.clear === "auto" &&
|
|
544
|
-
const l = await
|
|
560
|
+
cacheResponse(e, t, r) {
|
|
561
|
+
return r === void 0 && (r = 0), new Promise(async (o, n) => {
|
|
562
|
+
let i = y({ url: e, params: t }), a = this.cacheProvider();
|
|
563
|
+
if (this.cache.clear === "auto" && t.version === "draft" && await this.flushCache(), t.version === "published" && e != "/cdn/spaces/me") {
|
|
564
|
+
const l = await a.get(i);
|
|
545
565
|
if (l)
|
|
546
|
-
return
|
|
566
|
+
return o(l);
|
|
547
567
|
}
|
|
548
568
|
try {
|
|
549
|
-
let l = await this.throttle("get",
|
|
569
|
+
let l = await this.throttle("get", e, { params: t, paramsSerializer: (p) => y(p) }), h = { data: l.data, headers: l.headers };
|
|
550
570
|
if (h.data.assets && h.data.assets.length && this.resolveAssetsRelations(h.data), l.headers["per-page"] && (h = Object.assign({}, h, { perPage: parseInt(l.headers["per-page"]), total: parseInt(l.headers.total) })), l.status != 200)
|
|
551
|
-
return
|
|
552
|
-
(h.data.story || h.data.stories) && await this.resolveStories(h.data,
|
|
571
|
+
return n(l);
|
|
572
|
+
(h.data.story || h.data.stories) && await this.resolveStories(h.data, t), t.version === "published" && e != "/cdn/spaces/me" && a.set(i, h), h.data.cv && (t.version == "draft" && d[t.token] != h.data.cv && this.flushCache(), d[t.token] = h.data.cv), o(h);
|
|
553
573
|
} catch (l) {
|
|
554
574
|
if (l.response && l.response.status === 429 && (r += 1) < this.maxRetries)
|
|
555
|
-
return console.log(`Hit rate limit. Retrying in ${r} seconds.`), await (c = 1e3 * r, new Promise((h) => setTimeout(h, c))), this.cacheResponse(
|
|
556
|
-
|
|
575
|
+
return console.log(`Hit rate limit. Retrying in ${r} seconds.`), await (c = 1e3 * r, new Promise((h) => setTimeout(h, c))), this.cacheResponse(e, t, r).then(o).catch(n);
|
|
576
|
+
n(l);
|
|
557
577
|
}
|
|
558
578
|
var c;
|
|
559
579
|
});
|
|
560
580
|
}
|
|
561
|
-
throttledRequest(
|
|
562
|
-
return this.client[
|
|
581
|
+
throttledRequest(e, t, r) {
|
|
582
|
+
return this.client[e](t, r);
|
|
563
583
|
}
|
|
564
584
|
cacheVersions() {
|
|
565
585
|
return d;
|
|
@@ -567,14 +587,14 @@ class D {
|
|
|
567
587
|
cacheVersion() {
|
|
568
588
|
return d[this.accessToken];
|
|
569
589
|
}
|
|
570
|
-
setCacheVersion(
|
|
571
|
-
this.accessToken && (d[this.accessToken] =
|
|
590
|
+
setCacheVersion(e) {
|
|
591
|
+
this.accessToken && (d[this.accessToken] = e);
|
|
572
592
|
}
|
|
573
593
|
cacheProvider() {
|
|
574
|
-
return this.cache.type === "memory" ? { get: (
|
|
575
|
-
|
|
594
|
+
return this.cache.type === "memory" ? { get: (e) => f[e], getAll: () => f, set(e, t) {
|
|
595
|
+
f[e] = t;
|
|
576
596
|
}, flush() {
|
|
577
|
-
|
|
597
|
+
f = {};
|
|
578
598
|
} } : { get() {
|
|
579
599
|
}, getAll() {
|
|
580
600
|
}, set() {
|
|
@@ -585,87 +605,91 @@ class D {
|
|
|
585
605
|
return await this.cacheProvider().flush(), this;
|
|
586
606
|
}
|
|
587
607
|
}
|
|
588
|
-
const
|
|
589
|
-
const { apiOptions:
|
|
590
|
-
if (!
|
|
608
|
+
const se = (s = {}) => {
|
|
609
|
+
const { apiOptions: e } = s;
|
|
610
|
+
if (!e.accessToken) {
|
|
591
611
|
console.error("You need to provide an access token to interact with Storyblok API. Read https://www.storyblok.com/docs/api/content-delivery#topics/authentication");
|
|
592
612
|
return;
|
|
593
613
|
}
|
|
594
|
-
return { storyblokApi: new
|
|
614
|
+
return { storyblokApi: new re(e) };
|
|
595
615
|
};
|
|
596
|
-
var
|
|
597
|
-
if (typeof
|
|
616
|
+
var le = (s) => {
|
|
617
|
+
if (typeof s != "object" || typeof s._editable > "u")
|
|
598
618
|
return {};
|
|
599
|
-
const
|
|
619
|
+
const e = JSON.parse(s._editable.replace(/^<!--#storyblok#/, "").replace(/-->$/, ""));
|
|
600
620
|
return {
|
|
601
|
-
"data-blok-c": JSON.stringify(
|
|
602
|
-
"data-blok-uid":
|
|
621
|
+
"data-blok-c": JSON.stringify(e),
|
|
622
|
+
"data-blok-uid": e.id + "-" + e.uid
|
|
603
623
|
};
|
|
604
624
|
};
|
|
605
625
|
let m;
|
|
606
|
-
const
|
|
626
|
+
const I = "https://app.storyblok.com/f/storyblok-v2-latest.js", oe = (s = {}) => {
|
|
607
627
|
const {
|
|
608
|
-
bridge:
|
|
609
|
-
accessToken:
|
|
628
|
+
bridge: e,
|
|
629
|
+
accessToken: t,
|
|
610
630
|
use: r = [],
|
|
611
|
-
apiOptions:
|
|
612
|
-
richText:
|
|
613
|
-
} =
|
|
614
|
-
|
|
615
|
-
const
|
|
616
|
-
let
|
|
631
|
+
apiOptions: o = {},
|
|
632
|
+
richText: n = {}
|
|
633
|
+
} = s;
|
|
634
|
+
o.accessToken = o.accessToken || t;
|
|
635
|
+
const i = { bridge: e, apiOptions: o };
|
|
636
|
+
let a = {};
|
|
617
637
|
return r.forEach((c) => {
|
|
618
|
-
|
|
619
|
-
}),
|
|
620
|
-
},
|
|
621
|
-
|
|
638
|
+
a = u(u({}, a), c(i));
|
|
639
|
+
}), e !== !1 && S(I), m = new x(n.schema), n.resolver && P(m, n.resolver), a;
|
|
640
|
+
}, P = (s, e) => {
|
|
641
|
+
s.addNode("blok", (t) => {
|
|
622
642
|
let r = "";
|
|
623
|
-
return
|
|
624
|
-
r +=
|
|
643
|
+
return t.attrs.body.forEach((o) => {
|
|
644
|
+
r += e(o.component, o);
|
|
625
645
|
}), {
|
|
626
646
|
html: r
|
|
627
647
|
};
|
|
628
648
|
});
|
|
629
|
-
},
|
|
630
|
-
let r =
|
|
649
|
+
}, ne = (s, e, t) => {
|
|
650
|
+
let r = t || m;
|
|
631
651
|
if (!r) {
|
|
632
652
|
console.error("Please initialize the Storyblok SDK before calling the renderRichText function");
|
|
633
653
|
return;
|
|
634
654
|
}
|
|
635
|
-
return
|
|
655
|
+
return s === "" ? "" : s ? (e && (r = new x(e.schema), e.resolver && P(r, e.resolver)), r.render(s)) : (console.warn(`${s} is not a valid Richtext object. This might be because the value of the richtext field is empty.
|
|
636
656
|
|
|
637
657
|
For more info about the richtext object check https://github.com/storyblok/storyblok-js#rendering-rich-text`), "");
|
|
638
|
-
},
|
|
639
|
-
function
|
|
640
|
-
const { storyblokApi: r } =
|
|
641
|
-
accessToken:
|
|
642
|
-
use:
|
|
643
|
-
apiOptions: { ...
|
|
658
|
+
}, ce = () => S(I);
|
|
659
|
+
function ae(s, e, t) {
|
|
660
|
+
const { storyblokApi: r } = oe({
|
|
661
|
+
accessToken: s,
|
|
662
|
+
use: e || [se],
|
|
663
|
+
apiOptions: { ...t }
|
|
644
664
|
});
|
|
645
665
|
globalThis.storyblokApiInstance = r;
|
|
646
666
|
}
|
|
647
|
-
function
|
|
667
|
+
function he() {
|
|
648
668
|
return globalThis.storyblokApiInstance || console.error("storyblokApiInstance has not been initialized correctly"), globalThis.storyblokApiInstance;
|
|
649
669
|
}
|
|
650
|
-
function
|
|
651
|
-
const
|
|
652
|
-
if (!
|
|
653
|
-
console.error(
|
|
670
|
+
function ue(s, e) {
|
|
671
|
+
const t = globalThis.storyblokApiInstance.richTextResolver;
|
|
672
|
+
if (!t) {
|
|
673
|
+
console.error(
|
|
674
|
+
"Please initialize the Storyblok SDK before calling the renderRichText function"
|
|
675
|
+
);
|
|
654
676
|
return;
|
|
655
677
|
}
|
|
656
|
-
return
|
|
678
|
+
return ne(s, e, t);
|
|
657
679
|
}
|
|
658
|
-
function
|
|
680
|
+
function de(s) {
|
|
659
681
|
return {
|
|
660
682
|
name: "@storyblok/astro",
|
|
661
683
|
hooks: {
|
|
662
|
-
"astro:config:setup": ({ injectScript:
|
|
663
|
-
var
|
|
664
|
-
|
|
684
|
+
"astro:config:setup": ({ injectScript: e, updateConfig: t }) => {
|
|
685
|
+
var o;
|
|
686
|
+
t({
|
|
665
687
|
vite: {
|
|
666
|
-
plugins: [
|
|
688
|
+
plugins: [z(s.components)]
|
|
667
689
|
}
|
|
668
|
-
}),
|
|
690
|
+
}), ae(s.accessToken, s.use, s.apiOptions), ((o = s.bridge) != null ? o : !0) && e(
|
|
691
|
+
"page",
|
|
692
|
+
`
|
|
669
693
|
import { loadStoryblokBridge } from "@storyblok/astro";
|
|
670
694
|
loadStoryblokBridge().then(() => {
|
|
671
695
|
const { StoryblokBridge, location } = window;
|
|
@@ -677,16 +701,17 @@ function tt(n) {
|
|
|
677
701
|
}
|
|
678
702
|
});
|
|
679
703
|
});
|
|
680
|
-
`
|
|
704
|
+
`
|
|
705
|
+
);
|
|
681
706
|
}
|
|
682
707
|
}
|
|
683
708
|
};
|
|
684
709
|
}
|
|
685
710
|
export {
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
711
|
+
W as RichTextSchema,
|
|
712
|
+
de as default,
|
|
713
|
+
ce as loadStoryblokBridge,
|
|
714
|
+
ue as renderRichText,
|
|
715
|
+
le as storyblokEditable,
|
|
716
|
+
he as useStoryblokApi
|
|
692
717
|
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@storyblok/astro",
|
|
3
|
-
"version": "1.1.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "1.1.1",
|
|
4
|
+
"description": "SDK to integrate Storyblok into your project using Astro.",
|
|
5
5
|
"main": "./dist/storyblok-astro.js",
|
|
6
6
|
"module": "./dist/storyblok-astro.mjs",
|
|
7
7
|
"files": [
|
|
@@ -27,16 +27,17 @@
|
|
|
27
27
|
"prepublishOnly": "npm run build && cp ../README.md ./"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@storyblok/js": "^1.8.5"
|
|
30
|
+
"@storyblok/js": "^1.8.5",
|
|
31
|
+
"camelcase": "^7.0.0"
|
|
31
32
|
},
|
|
32
33
|
"devDependencies": {
|
|
33
34
|
"@cypress/vite-dev-server": "^2.0.7",
|
|
34
35
|
"@rollup/plugin-dynamic-import-vars": "^1.4.4",
|
|
35
36
|
"axios": "^0.27.2",
|
|
36
|
-
"cypress": "^10.
|
|
37
|
+
"cypress": "^10.9.0",
|
|
37
38
|
"eslint-plugin-cypress": "^2.12.1",
|
|
38
39
|
"start-server-and-test": "^1.14.0",
|
|
39
|
-
"vite": "^3.
|
|
40
|
+
"vite": "^3.1.3"
|
|
40
41
|
},
|
|
41
42
|
"repository": {
|
|
42
43
|
"type": "git",
|