@storyblok/astro 2.5.3 → 2.5.5

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 CHANGED
@@ -59,7 +59,8 @@ export default defineConfig({
59
59
  });
60
60
  ```
61
61
 
62
- > ⚠️ This SDK uses the Fetch API under the hood. If your environment doesn't support it, you need to install a polyfill like [isomorphic-fetch](https://github.com/matthew-andrews/isomorphic-fetch). More info on [storyblok-js-client docs](https://github.com/storyblok/storyblok-js-client#fetch-use-polyfill-if-needed---version-5).
62
+ > **Warning**
63
+ > This SDK uses the Fetch API under the hood. If your environment doesn't support it, you need to install a polyfill like [isomorphic-fetch](https://github.com/matthew-andrews/isomorphic-fetch). More info on [storyblok-js-client docs](https://github.com/storyblok/storyblok-js-client#fetch-use-polyfill-if-needed---version-5).
63
64
 
64
65
  ### Options
65
66
 
@@ -79,7 +80,8 @@ storyblok({
79
80
  });
80
81
  ```
81
82
 
82
- > Note: By default, the apiPlugin from `@storyblok/js` is loaded. If you want to use your own method to fetch data from Storyblok, you can disable this behavior by setting `useCustomApi` to `true`, resulting in an optimized final bundle.
83
+ > **Note**
84
+ > By default, the `apiPlugin` from `@storyblok/js` is loaded. If you want to use your own method to fetch data from Storyblok, you can disable this behavior by setting `useCustomApi` to `true`, resulting in an optimized final bundle.
83
85
 
84
86
  #### Region parameter
85
87
 
@@ -100,7 +102,8 @@ storyblok({
100
102
  });
101
103
  ```
102
104
 
103
- > Note: For spaces created in the United States or China, the `region` parameter **must** be specified.
105
+ > **Warning**
106
+ > For spaces created in the United States or China, the `region` parameter **must** be specified.
104
107
 
105
108
  ## Getting started
106
109
 
@@ -119,7 +122,8 @@ components: {
119
122
  },
120
123
  ```
121
124
 
122
- > Note: The `src` folder is automatically added to the beginning of the path, so in this example your Astro components should be located here:
125
+ > **Note**
126
+ > The `src` folder is automatically added to the beginning of the path, so in this example your Astro components should be located here:
123
127
  >
124
128
  > - `src/storyblok/Page.astro`
125
129
  > - `src/storyblok/Feature.astro`
@@ -167,7 +171,8 @@ const { blok } = Astro.props
167
171
  </main>
168
172
  ```
169
173
 
170
- > Note: The `blok` is the actual blok data coming from [Storblok's Content Delivery API](https://www.storyblok.com/docs/api/content-delivery/v2?utm_source=github.com&utm_medium=readme&utm_campaign=storyblok-astro).
174
+ > **Note**
175
+ > The `blok` is the actual blok data coming from [Storblok's Content Delivery API](https://www.storyblok.com/docs/api/content-delivery/v2?utm_source=github.com&utm_medium=readme&utm_campaign=storyblok-astro).
171
176
 
172
177
  #### Using fallback components
173
178
 
@@ -205,7 +210,8 @@ const story = data.story;
205
210
  <StoryblokComponent blok="{story.content}" />
206
211
  ```
207
212
 
208
- > Note: The available methods are described in the [storyblok-js-client] repository(https://github.com/storyblok/storyblok-js-client#method-storyblokget)
213
+ > **Note**
214
+ > The available methods are described in the [storyblok-js-client] repository(https://github.com/storyblok/storyblok-js-client#method-storyblokget)
209
215
 
210
216
  #### Dynamic Routing
211
217
 
@@ -250,7 +256,8 @@ const story = data.story;
250
256
 
251
257
  The Storyblok Bridge is enabled by default. If you would like to disable it or enable it conditionally (e.g. depending on the environment) you can set the `bridge` parameter to `true` or `false` in `astro.config.mjs`:
252
258
 
253
- > 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.
259
+ > **Note**
260
+ > 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.
254
261
 
255
262
  You can also provide a `StoryblokBridgeConfigV2` configuration object to the `bridge` parameter.
256
263
 
@@ -258,16 +265,20 @@ You can also provide a `StoryblokBridgeConfigV2` configuration object to the `br
258
265
  bridge: {
259
266
  customParent?: string,
260
267
  preventClicks?: boolean, // Defaults to false.
261
- resolveRelations?: strings[]
268
+ resolveRelations?: strings[],
269
+ resolveLinks?: string
262
270
  }
263
271
  ```
264
272
 
265
273
  - `customParent` is used to provide a custom URL for the Storyblok editor iframe.
266
274
  - `preventClicks` prevents the default behaviour of clicks when inside the Storyblok editor.
267
- - `resolveRelations` may be needed to tell the Storyblok Bridge to resolve the same relations that are already resolved in the API requests via the `resolve_relations` parameter. _Note: this paramenter won't have any effect in Astro, since the Storyblok Bridge will reload the page and thus all the requests needed will be performed after the reload_
275
+ - `resolveRelations` may be needed to resolve the same relations that are already resolved in the API requests via the `resolve_relations` parameter.
276
+ - `resolveLinks` may be needed to resolve link fields.
268
277
 
269
- The provided options will be used to initialize the Storyblok Bridge.
270
- You can find more information about the Storyblok Bridge and its configuration options on the [In Depth Storyblok Bridge guide](https://www.storyblok.com/docs/guide/in-depth/storyblok-latest-js-v2).
278
+ > **Note**
279
+ > `resolveRelations` and `resolveLinks` will not have any effect in Astro, since the Storyblok Bridge is configured to reload the page. Thus, all the requests needed will be performed after the reload.
280
+
281
+ The provided options will be used when initializing the Storyblok Bridge. You can find more information about the Storyblok Bridge and its configuration options on the [In Depth Storyblok Bridge guide](https://www.storyblok.com/docs/guide/in-depth/storyblok-latest-js-v2?utm_source=github.com&utm_medium=readme&utm_campaign=storyblok-astro).
271
282
 
272
283
  If you want to deploy a dedicated preview environment with the Bridge enabled, allowing users of the Storyblok CMS to see their changes being reflected on the frontend directly without having to rebuild the static site, you can enable Server Side Rendering for that particular use case. More information can be found in the [Astro Docs](https://docs.astro.build/en/guides/server-side-rendering/).
273
284
 
@@ -1,4 +1,4 @@
1
- (function(g,h){typeof exports=="object"&&typeof module<"u"?h(exports):typeof define=="function"&&define.amd?define(["exports"],h):(g=typeof globalThis<"u"?globalThis:g||self,h(g.storyblokAstro={}))})(this,function(g){"use strict";function h(r,e,t){const o="virtual:storyblok-init",a="\0"+o;return{name:"vite-plugin-storyblok-init",async resolveId(s){if(s===o)return a},async load(s){if(s===a)return`
1
+ (function(u,h){typeof exports=="object"&&typeof module<"u"?h(exports):typeof define=="function"&&define.amd?define(["exports"],h):(u=typeof globalThis<"u"?globalThis:u||self,h(u.storyblokAstro={}))})(this,function(u){"use strict";function h(r,e,t){const o="virtual:storyblok-init",a="\0"+o;return{name:"vite-plugin-storyblok-init",async resolveId(s){if(s===o)return a},async load(s){if(s===a)return`
2
2
  import { storyblokInit, apiPlugin } from "@storyblok/js";
3
3
  const { storyblokApi } = storyblokInit({
4
4
  accessToken: "${r}",
@@ -8,7 +8,7 @@
8
8
  export const storyblokApiInstance = storyblokApi;
9
9
  `}}}const x=/[\p{Lu}]/u,R=/[\p{Ll}]/u,k=/^[\p{Lu}](?![\p{Lu}])/gu,$=/([\p{Alpha}\p{N}_]|$)/u,b=/[_.\- ]+/,O=new RegExp("^"+b.source),v=new RegExp(b.source+$.source,"gu"),I=new RegExp("\\d+"+$.source,"gu"),N=(r,e,t,o)=>{let a=!1,s=!1,n=!1,f=!1;for(let l=0;l<r.length;l++){const i=r[l];f=l>2?r[l-3]==="-":!0,a&&x.test(i)?(r=r.slice(0,l)+"-"+r.slice(l),a=!1,n=s,s=!0,l++):s&&n&&R.test(i)&&(!f||o)?(r=r.slice(0,l-1)+"-"+r.slice(l-1),n=s,s=!1,a=!0):(a=e(i)===i&&t(i)!==i,n=s,s=t(i)===i&&e(i)!==i)}return r},L=(r,e)=>(k.lastIndex=0,r.replace(k,t=>e(t))),M=(r,e)=>(v.lastIndex=0,I.lastIndex=0,r.replace(v,(t,o)=>e(o)).replace(I,t=>e(t)));function w(r,e){if(!(typeof r=="string"||Array.isArray(r)))throw new TypeError("Expected the input to be `string | string[]`");if(e={pascalCase:!1,preserveConsecutiveUppercase:!1,...e},Array.isArray(r)?r=r.map(s=>s.trim()).filter(s=>s.length).join("-"):r=r.trim(),r.length===0)return"";const t=e.locale===!1?s=>s.toLowerCase():s=>s.toLocaleLowerCase(e.locale),o=e.locale===!1?s=>s.toUpperCase():s=>s.toLocaleUpperCase(e.locale);return r.length===1?b.test(r)?"":e.pascalCase?o(r):t(r):(r!==t(r)&&(r=N(r,t,o,e.preserveConsecutiveUppercase)),r=r.replace(O,""),r=e.preserveConsecutiveUppercase?L(r,t):t(r),e.pascalCase&&(r=o(r.charAt(0))+r.slice(1)),M(r,o))}function P(r,e,t,o){const a="virtual:storyblok-components",s="\0"+a;return{name:"vite-plugin-storyblok-components",async resolveId(n){if(n===a)return s},async load(n){if(n===s){const f=[],l=[];for await(const[c,d]of Object.entries(e)){const p=await this.resolve("/"+r+"/"+d+".astro");if(p)f.push(`import ${w(c)} from "${p.id}"`);else if(t)l.push(c);else throw new Error(`Component could not be found for blok "${c}"! Does "${"/"+r+"/"+d}.astro" exist?`)}let i="";if(t)if(i=",FallbackComponent",o){const c=await this.resolve("/"+r+"/"+o+".astro");if(!c)throw new Error(`Custom fallback component could not be found. Does "${"/"+r+"/"+o}.astro" exist?`);f.push(`import FallbackComponent from "${c.id}"`)}else f.push("import FallbackComponent from '@storyblok/astro/FallbackComponent.astro'");if(Object.values(e).length)return`${f.join(";")};export default {${Object.keys(e).filter(c=>!l.includes(c)).map(c=>w(c)).join(",")}${i}}`;if(t)return`${f[0]}; export default {${i.replace(",","")}}`;throw new Error(`Currently, no Storyblok components are registered in astro.config.mjs.
10
10
  Please register your components or enable the fallback component.
11
- Detailed information can be found here: https://github.com/storyblok/storyblok-astro`)}}}}function _(r){const e="virtual:storyblok-options",t="\0"+e;return{name:"vite-plugin-storyblok-options",async resolveId(o){if(o===e)return t},async load(o){if(o===t)return`export default ${JSON.stringify(r)}`}}}let T=!1;const E=[],z=r=>new Promise((e,t)=>{if(typeof window>"u"||(window.storyblokRegisterEvent=a=>{if(window.location===window.parent.location){console.warn("You are not in Draft Mode or in the Visual Editor.");return}T?a():E.push(a)},document.getElementById("storyblok-javascript-bridge")))return;const o=document.createElement("script");o.async=!0,o.src=r,o.id="storyblok-javascript-bridge",o.onerror=a=>t(a),o.onload=a=>{E.forEach(s=>s()),T=!0,e(a)},document.getElementsByTagName("head")[0].appendChild(o)});var D=Object.defineProperty,U=(r,e,t)=>e in r?D(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,C=(r,e,t)=>(U(r,typeof e!="symbol"?e+"":e,t),t);const q=function(r,e){const t={};for(const o in r){const a=r[o];e.indexOf(o)>-1&&a!==null&&(t[o]=a)}return t},B=r=>r==="email",F=()=>({singleTag:"hr"}),J=()=>({tag:"blockquote"}),K=()=>({tag:"ul"}),V=r=>({tag:["pre",{tag:"code",attrs:r.attrs}]}),G=()=>({singleTag:"br"}),W=r=>({tag:`h${r.attrs.level}`}),H=r=>({singleTag:[{tag:"img",attrs:q(r.attrs,["src","alt","title"])}]}),Y=()=>({tag:"li"}),Q=()=>({tag:"ol"}),X=()=>({tag:"p"}),Z=r=>({tag:[{tag:"span",attrs:{["data-type"]:"emoji",["data-name"]:r.attrs.name,emoji:r.attrs.emoji}}]}),ee=()=>({tag:"b"}),te=()=>({tag:"strike"}),re=()=>({tag:"u"}),oe=()=>({tag:"strong"}),se=()=>({tag:"code"}),ae=()=>({tag:"i"}),ne=r=>{const e={...r.attrs},{linktype:t="url"}=r.attrs;if(B(t)&&(e.href=`mailto:${e.href}`),e.anchor&&(e.href=`${e.href}#${e.anchor}`,delete e.anchor),e.custom){for(const o in e.custom)e[o]=e.custom[o];delete e.custom}return{tag:[{tag:"a",attrs:e}]}},le=r=>({tag:[{tag:"span",attrs:r.attrs}]}),ie=()=>({tag:"sub"}),ce=()=>({tag:"sup"}),ge=r=>({tag:[{tag:"span",attrs:r.attrs}]}),ue=r=>{var e;return(e=r.attrs)!=null&&e.color?{tag:[{tag:"span",attrs:{style:`background-color:${r.attrs.color};`}}]}:{tag:""}},fe=r=>{var e;return(e=r.attrs)!=null&&e.color?{tag:[{tag:"span",attrs:{style:`color:${r.attrs.color}`}}]}:{tag:""}},S={nodes:{horizontal_rule:F,blockquote:J,bullet_list:K,code_block:V,hard_break:G,heading:W,image:H,list_item:Y,ordered_list:Q,paragraph:X,emoji:Z},marks:{bold:ee,strike:te,underline:re,strong:oe,code:se,italic:ae,link:ne,styled:le,subscript:ie,superscript:ce,anchor:ge,highlight:ue,textStyle:fe}},de=function(r){const e={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"},t=/[&<>"']/g,o=RegExp(t.source);return r&&o.test(r)?r.replace(t,a=>e[a]):r};class A{constructor(e){C(this,"marks"),C(this,"nodes"),e||(e=S),this.marks=e.marks||[],this.nodes=e.nodes||[]}addNode(e,t){this.nodes[e]=t}addMark(e,t){this.marks[e]=t}render(e,t={optimizeImages:!1}){if(e&&e.content&&Array.isArray(e.content)){let o="";return e.content.forEach(a=>{o+=this.renderNode(a)}),t.optimizeImages?this.optimizeImages(o,t.optimizeImages):o}return console.warn(`The render method must receive an Object with a "content" field.
11
+ Detailed information can be found here: https://github.com/storyblok/storyblok-astro`)}}}}function _(r){const e="virtual:storyblok-options",t="\0"+e;return{name:"vite-plugin-storyblok-options",async resolveId(o){if(o===e)return t},async load(o){if(o===t)return`export default ${JSON.stringify(r)}`}}}let T=!1;const E=[],z=r=>new Promise((e,t)=>{if(typeof window>"u"||(window.storyblokRegisterEvent=a=>{if(window.location===window.parent.location){console.warn("You are not in Draft Mode or in the Visual Editor.");return}T?a():E.push(a)},document.getElementById("storyblok-javascript-bridge")))return;const o=document.createElement("script");o.async=!0,o.src=r,o.id="storyblok-javascript-bridge",o.onerror=a=>t(a),o.onload=a=>{E.forEach(s=>s()),T=!0,e(a)},document.getElementsByTagName("head")[0].appendChild(o)});var D=Object.defineProperty,U=(r,e,t)=>e in r?D(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,S=(r,e,t)=>(U(r,typeof e!="symbol"?e+"":e,t),t);const q=function(r,e){const t={};for(const o in r){const a=r[o];e.indexOf(o)>-1&&a!==null&&(t[o]=a)}return t},B=r=>r==="email",F=()=>({singleTag:"hr"}),J=()=>({tag:"blockquote"}),K=()=>({tag:"ul"}),V=r=>({tag:["pre",{tag:"code",attrs:r.attrs}]}),G=()=>({singleTag:"br"}),W=r=>({tag:`h${r.attrs.level}`}),Y=r=>({singleTag:[{tag:"img",attrs:q(r.attrs,["src","alt","title"])}]}),H=()=>({tag:"li"}),Q=()=>({tag:"ol"}),X=()=>({tag:"p"}),Z=r=>({tag:[{tag:"span",attrs:{"data-type":"emoji","data-name":r.attrs.name,emoji:r.attrs.emoji}}]}),ee=()=>({tag:"b"}),te=()=>({tag:"strike"}),re=()=>({tag:"u"}),oe=()=>({tag:"strong"}),se=()=>({tag:"code"}),ae=()=>({tag:"i"}),ne=r=>{const e={...r.attrs},{linktype:t="url"}=r.attrs;if(B(t)&&(e.href=`mailto:${e.href}`),e.anchor&&(e.href=`${e.href}#${e.anchor}`,delete e.anchor),e.custom){for(const o in e.custom)e[o]=e.custom[o];delete e.custom}return{tag:[{tag:"a",attrs:e}]}},le=r=>({tag:[{tag:"span",attrs:r.attrs}]}),ie=()=>({tag:"sub"}),ce=()=>({tag:"sup"}),ue=r=>({tag:[{tag:"span",attrs:r.attrs}]}),ge=r=>{var e;return(e=r.attrs)!=null&&e.color?{tag:[{tag:"span",attrs:{style:`background-color:${r.attrs.color};`}}]}:{tag:""}},fe=r=>{var e;return(e=r.attrs)!=null&&e.color?{tag:[{tag:"span",attrs:{style:`color:${r.attrs.color}`}}]}:{tag:""}},C={nodes:{horizontal_rule:F,blockquote:J,bullet_list:K,code_block:V,hard_break:G,heading:W,image:Y,list_item:H,ordered_list:Q,paragraph:X,emoji:Z},marks:{bold:ee,strike:te,underline:re,strong:oe,code:se,italic:ae,link:ne,styled:le,subscript:ie,superscript:ce,anchor:ue,highlight:ge,textStyle:fe}},de=function(r){const e={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"},t=/[&<>"']/g,o=RegExp(t.source);return r&&o.test(r)?r.replace(t,a=>e[a]):r};class A{constructor(e){S(this,"marks"),S(this,"nodes"),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,t={optimizeImages:!1}){if(e&&e.content&&Array.isArray(e.content)){let o="";return e.content.forEach(a=>{o+=this.renderNode(a)}),t.optimizeImages?this.optimizeImages(o,t.optimizeImages):o}return console.warn(`The render method must receive an Object with a "content" field.
12
12
  The "content" field must be an array of nodes as the type ISbRichtext.
13
13
  ISbRichtext:
14
14
  content?: ISbRichtext[]
@@ -31,7 +31,7 @@ Detailed information can be found here: https://github.com/storyblok/storyblok-a
31
31
  }
32
32
  ],
33
33
  type: 'doc'
34
- }`),""}optimizeImages(e,t){let o=0,a=0,s="",n="";typeof t!="boolean"&&(typeof t.width=="number"&&t.width>0&&(s+=`width="${t.width}" `,o=t.width),typeof t.height=="number"&&t.height>0&&(s+=`height="${t.height}" `,a=t.height),(t.loading==="lazy"||t.loading==="eager")&&(s+=`loading="${t.loading}" `),typeof t.class=="string"&&t.class.length>0&&(s+=`class="${t.class}" `),t.filters&&(typeof t.filters.blur=="number"&&t.filters.blur>=0&&t.filters.blur<=100&&(n+=`:blur(${t.filters.blur})`),typeof t.filters.brightness=="number"&&t.filters.brightness>=-100&&t.filters.brightness<=100&&(n+=`:brightness(${t.filters.brightness})`),t.filters.fill&&(t.filters.fill.match(/[0-9A-Fa-f]{6}/g)||t.filters.fill==="transparent")&&(n+=`:fill(${t.filters.fill})`),t.filters.format&&["webp","png","jpeg"].includes(t.filters.format)&&(n+=`:format(${t.filters.format})`),typeof t.filters.grayscale=="boolean"&&t.filters.grayscale&&(n+=":grayscale()"),typeof t.filters.quality=="number"&&t.filters.quality>=0&&t.filters.quality<=100&&(n+=`:quality(${t.filters.quality})`),t.filters.rotate&&[90,180,270].includes(t.filters.rotate)&&(n+=`:rotate(${t.filters.rotate})`),n.length>0&&(n="/filters"+n))),s.length>0&&(e=e.replace(/<img/g,`<img ${s.trim()}`));const f=o>0||a>0||n.length>0?`${o}x${a}${n}`:"";return e=e.replace(/a.storyblok.com\/f\/(\d+)\/([^.]+)\.(gif|jpg|jpeg|png|tif|tiff|bmp)/g,`a.storyblok.com/f/$1/$2.$3/m/${f}`),typeof t!="boolean"&&(t.sizes||t.srcset)&&(e=e.replace(/<img.*?src=["|'](.*?)["|']/g,l=>{var i,c;const d=l.match(/a.storyblok.com\/f\/(\d+)\/([^.]+)\.(gif|jpg|jpeg|png|tif|tiff|bmp)/g);if(d&&d.length>0){const p={srcset:(i=t.srcset)==null?void 0:i.map(u=>{if(typeof u=="number")return`//${d}/m/${u}x0${n} ${u}w`;if(typeof u=="object"&&u.length===2){let y=0,j=0;return typeof u[0]=="number"&&(y=u[0]),typeof u[1]=="number"&&(j=u[1]),`//${d}/m/${y}x${j}${n} ${y}w`}}).join(", "),sizes:(c=t.sizes)==null?void 0:c.map(u=>u).join(", ")};let m="";return p.srcset&&(m+=`srcset="${p.srcset}" `),p.sizes&&(m+=`sizes="${p.sizes}" `),l.replace(/<img/g,`<img ${m.trim()}`)}return l})),e}renderNode(e){const t=[];e.marks&&e.marks.forEach(a=>{const s=this.getMatchingMark(a);s&&s.tag!==""&&t.push(this.renderOpeningTag(s.tag))});const o=this.getMatchingNode(e);return o&&o.tag&&t.push(this.renderOpeningTag(o.tag)),e.content?e.content.forEach(a=>{t.push(this.renderNode(a))}):e.text?t.push(de(e.text)):o&&o.singleTag?t.push(this.renderTag(o.singleTag," /")):o&&o.html?t.push(o.html):e.type==="emoji"&&t.push(this.renderEmoji(e)),o&&o.tag&&t.push(this.renderClosingTag(o.tag)),e.marks&&e.marks.slice(0).reverse().forEach(a=>{const s=this.getMatchingMark(a);s&&s.tag!==""&&t.push(this.renderClosingTag(s.tag))}),t.join("")}renderTag(e,t){return e.constructor===String?`<${e}${t}>`:e.map(o=>{if(o.constructor===String)return`<${o}${t}>`;{let a=`<${o.tag}`;if(o.attrs)for(const s in o.attrs){const n=o.attrs[s];n!==null&&(a+=` ${s}="${n}"`)}return`${a}${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){const t=this.nodes[e.type];if(typeof t=="function")return t(e)}getMatchingMark(e){const t=this.marks[e.type];if(typeof t=="function")return t(e)}renderEmoji(e){if(e.attrs.emoji)return e.attrs.emoji;const t=[{tag:"img",attrs:{src:e.attrs.fallbackImage,draggable:"false",loading:"lazy",align:"absmiddle"}}];return this.renderTag(t," /")}}const pe=r=>{if(typeof r!="object"||typeof r._editable>"u")return{};const e=JSON.parse(r._editable.replace(/^<!--#storyblok#/,"").replace(/-->$/,""));return{"data-blok-c":JSON.stringify(e),"data-blok-uid":e.id+"-"+e.uid}};let he;const be="https://app.storyblok.com/f/storyblok-v2-latest.js",me=(r,e)=>{r.addNode("blok",t=>{let o="";return t.attrs.body.forEach(a=>{o+=e(a.component,a)}),{html:o}})},ye=r=>{var e,t;return!r||((e=r==null?void 0:r.content)==null?void 0:e[0].type)!=="blok"&&!((t=r==null?void 0:r.content)!=null&&t[0].content)},ke=(r,e,t)=>{let o=t||he;if(!o){console.error("Please initialize the Storyblok SDK before calling the renderRichText function");return}return ye(r)?"":(e&&(o=new A(e.schema),e.resolver&&me(o,e.resolver)),o.render(r))},$e=()=>z(be);function ve(){return globalThis.storyblokApiInstance||console.error("storyblokApiInstance has not been initialized correctly"),globalThis.storyblokApiInstance}function Ie(r,e){const t=globalThis.storyblokApiInstance.richTextResolver;if(!t){console.error("Please initialize the Storyblok SDK before calling the renderRichText function");return}return ke(r,e,t)}function we(r){const e={useCustomApi:!1,bridge:!0,componentsDir:"src",enableFallbackComponent:!1,...r};return{name:"@storyblok/astro",hooks:{"astro:config:setup":({injectScript:t,updateConfig:o})=>{if(o({vite:{plugins:[h(e.accessToken,e.useCustomApi,e.apiOptions),P(e.componentsDir,e.components,e.enableFallbackComponent,e.customFallbackComponent),_(e)]}}),t("page-ssr",`
34
+ }`),""}optimizeImages(e,t){let o=0,a=0,s="",n="";typeof t!="boolean"&&(typeof t.width=="number"&&t.width>0&&(s+=`width="${t.width}" `,o=t.width),typeof t.height=="number"&&t.height>0&&(s+=`height="${t.height}" `,a=t.height),(t.loading==="lazy"||t.loading==="eager")&&(s+=`loading="${t.loading}" `),typeof t.class=="string"&&t.class.length>0&&(s+=`class="${t.class}" `),t.filters&&(typeof t.filters.blur=="number"&&t.filters.blur>=0&&t.filters.blur<=100&&(n+=`:blur(${t.filters.blur})`),typeof t.filters.brightness=="number"&&t.filters.brightness>=-100&&t.filters.brightness<=100&&(n+=`:brightness(${t.filters.brightness})`),t.filters.fill&&(t.filters.fill.match(/[0-9A-Fa-f]{6}/g)||t.filters.fill==="transparent")&&(n+=`:fill(${t.filters.fill})`),t.filters.format&&["webp","png","jpeg"].includes(t.filters.format)&&(n+=`:format(${t.filters.format})`),typeof t.filters.grayscale=="boolean"&&t.filters.grayscale&&(n+=":grayscale()"),typeof t.filters.quality=="number"&&t.filters.quality>=0&&t.filters.quality<=100&&(n+=`:quality(${t.filters.quality})`),t.filters.rotate&&[90,180,270].includes(t.filters.rotate)&&(n+=`:rotate(${t.filters.rotate})`),n.length>0&&(n="/filters"+n))),s.length>0&&(e=e.replace(/<img/g,`<img ${s.trim()}`));const f=o>0||a>0||n.length>0?`${o}x${a}${n}`:"";return e=e.replace(/a.storyblok.com\/f\/(\d+)\/([^.]+)\.(gif|jpg|jpeg|png|tif|tiff|bmp)/g,`a.storyblok.com/f/$1/$2.$3/m/${f}`),typeof t!="boolean"&&(t.sizes||t.srcset)&&(e=e.replace(/<img.*?src=["|'](.*?)["|']/g,l=>{var i,c;const d=l.match(/a.storyblok.com\/f\/(\d+)\/([^.]+)\.(gif|jpg|jpeg|png|tif|tiff|bmp)/g);if(d&&d.length>0){const p={srcset:(i=t.srcset)==null?void 0:i.map(g=>{if(typeof g=="number")return`//${d}/m/${g}x0${n} ${g}w`;if(typeof g=="object"&&g.length===2){let y=0,j=0;return typeof g[0]=="number"&&(y=g[0]),typeof g[1]=="number"&&(j=g[1]),`//${d}/m/${y}x${j}${n} ${y}w`}}).join(", "),sizes:(c=t.sizes)==null?void 0:c.map(g=>g).join(", ")};let m="";return p.srcset&&(m+=`srcset="${p.srcset}" `),p.sizes&&(m+=`sizes="${p.sizes}" `),l.replace(/<img/g,`<img ${m.trim()}`)}return l})),e}renderNode(e){const t=[];e.marks&&e.marks.forEach(a=>{const s=this.getMatchingMark(a);s&&s.tag!==""&&t.push(this.renderOpeningTag(s.tag))});const o=this.getMatchingNode(e);return o&&o.tag&&t.push(this.renderOpeningTag(o.tag)),e.content?e.content.forEach(a=>{t.push(this.renderNode(a))}):e.text?t.push(de(e.text)):o&&o.singleTag?t.push(this.renderTag(o.singleTag," /")):o&&o.html?t.push(o.html):e.type==="emoji"&&t.push(this.renderEmoji(e)),o&&o.tag&&t.push(this.renderClosingTag(o.tag)),e.marks&&e.marks.slice(0).reverse().forEach(a=>{const s=this.getMatchingMark(a);s&&s.tag!==""&&t.push(this.renderClosingTag(s.tag))}),t.join("")}renderTag(e,t){return e.constructor===String?`<${e}${t}>`:e.map(o=>{if(o.constructor===String)return`<${o}${t}>`;{let a=`<${o.tag}`;if(o.attrs)for(const s in o.attrs){const n=o.attrs[s];n!==null&&(a+=` ${s}="${n}"`)}return`${a}${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){const t=this.nodes[e.type];if(typeof t=="function")return t(e)}getMatchingMark(e){const t=this.marks[e.type];if(typeof t=="function")return t(e)}renderEmoji(e){if(e.attrs.emoji)return e.attrs.emoji;const t=[{tag:"img",attrs:{src:e.attrs.fallbackImage,draggable:"false",loading:"lazy",align:"absmiddle"}}];return this.renderTag(t," /")}}const pe=r=>{if(typeof r!="object"||typeof r._editable>"u")return{};const e=JSON.parse(r._editable.replace(/^<!--#storyblok#/,"").replace(/-->$/,""));return{"data-blok-c":JSON.stringify(e),"data-blok-uid":e.id+"-"+e.uid}};let he;const be="https://app.storyblok.com/f/storyblok-v2-latest.js",me=(r,e)=>{r.addNode("blok",t=>{let o="";return t.attrs.body.forEach(a=>{o+=e(a.component,a)}),{html:o}})},ye=r=>{var e,t;return!r||((e=r==null?void 0:r.content)==null?void 0:e[0].type)!=="blok"&&!((t=r==null?void 0:r.content)!=null&&t[0].content)},ke=(r,e,t)=>{let o=t||he;if(!o){console.error("Please initialize the Storyblok SDK before calling the renderRichText function");return}return ye(r)?"":(e&&(o=new A(e.schema),e.resolver&&me(o,e.resolver)),o.render(r))},$e=()=>z(be);function ve(){return globalThis.storyblokApiInstance||console.error("storyblokApiInstance has not been initialized correctly"),globalThis.storyblokApiInstance}function Ie(r,e){const t=globalThis.storyblokApiInstance.richTextResolver;if(!t){console.error("Please initialize the Storyblok SDK before calling the renderRichText function");return}return ke(r,e,t)}function we(r){const e={useCustomApi:!1,bridge:!0,componentsDir:"src",enableFallbackComponent:!1,...r};return{name:"@storyblok/astro",hooks:{"astro:config:setup":({injectScript:t,updateConfig:o})=>{if(o({vite:{plugins:[h(e.accessToken,e.useCustomApi,e.apiOptions),P(e.componentsDir,e.components,e.enableFallbackComponent,e.customFallbackComponent),_(e)]}}),t("page-ssr",`
35
35
  import { storyblokApiInstance } from "virtual:storyblok-init";
36
36
  globalThis.storyblokApiInstance = storyblokApiInstance;
37
37
  `),e.bridge){const a={...e.bridge};t("page",`
@@ -46,4 +46,4 @@ Detailed information can be found here: https://github.com/storyblok/storyblok-a
46
46
  }
47
47
  });
48
48
  });
49
- `)}}}}}g.RichTextResolver=A,g.RichTextSchema=S,g.default=we,g.loadStoryblokBridge=$e,g.renderRichText=Ie,g.storyblokEditable=pe,g.useStoryblokApi=ve,Object.defineProperties(g,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
49
+ `)}}}}}u.RichTextResolver=A,u.RichTextSchema=C,u.default=we,u.loadStoryblokBridge=$e,u.renderRichText=Ie,u.storyblokEditable=pe,u.useStoryblokApi=ve,Object.defineProperties(u,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
@@ -20,11 +20,11 @@ function x(r, e, t) {
20
20
  }
21
21
  };
22
22
  }
23
- const T = /[\p{Lu}]/u, A = /[\p{Ll}]/u, y = /^[\p{Lu}](?![\p{Lu}])/gu, C = /([\p{Alpha}\p{N}_]|$)/u, b = /[_.\- ]+/, S = new RegExp("^" + b.source), k = new RegExp(b.source + C.source, "gu"), $ = new RegExp("\\d+" + C.source, "gu"), j = (r, e, t, o) => {
23
+ const T = /[\p{Lu}]/u, S = /[\p{Ll}]/u, y = /^[\p{Lu}](?![\p{Lu}])/gu, C = /([\p{Alpha}\p{N}_]|$)/u, b = /[_.\- ]+/, A = new RegExp("^" + b.source), k = new RegExp(b.source + C.source, "gu"), $ = new RegExp("\\d+" + C.source, "gu"), j = (r, e, t, o) => {
24
24
  let a = !1, s = !1, n = !1, u = !1;
25
25
  for (let l = 0; l < r.length; l++) {
26
26
  const i = r[l];
27
- u = l > 2 ? r[l - 3] === "-" : !0, a && T.test(i) ? (r = r.slice(0, l) + "-" + r.slice(l), a = !1, n = s, s = !0, l++) : s && n && A.test(i) && (!u || o) ? (r = r.slice(0, l - 1) + "-" + r.slice(l - 1), n = s, s = !1, a = !0) : (a = e(i) === i && t(i) !== i, n = s, s = t(i) === i && e(i) !== i);
27
+ u = l > 2 ? r[l - 3] === "-" : !0, a && T.test(i) ? (r = r.slice(0, l) + "-" + r.slice(l), a = !1, n = s, s = !0, l++) : s && n && S.test(i) && (!u || o) ? (r = r.slice(0, l - 1) + "-" + r.slice(l - 1), n = s, s = !1, a = !0) : (a = e(i) === i && t(i) !== i, n = s, s = t(i) === i && e(i) !== i);
28
28
  }
29
29
  return r;
30
30
  }, R = (r, e) => (y.lastIndex = 0, r.replace(y, (t) => e(t))), O = (r, e) => (k.lastIndex = 0, $.lastIndex = 0, r.replace(k, (t, o) => e(o)).replace($, (t) => e(t)));
@@ -38,7 +38,7 @@ function v(r, e) {
38
38
  }, Array.isArray(r) ? r = r.map((s) => s.trim()).filter((s) => s.length).join("-") : r = r.trim(), r.length === 0)
39
39
  return "";
40
40
  const t = e.locale === !1 ? (s) => s.toLowerCase() : (s) => s.toLocaleLowerCase(e.locale), o = e.locale === !1 ? (s) => s.toUpperCase() : (s) => s.toLocaleUpperCase(e.locale);
41
- return r.length === 1 ? b.test(r) ? "" : e.pascalCase ? o(r) : t(r) : (r !== t(r) && (r = j(r, t, o, e.preserveConsecutiveUppercase)), r = r.replace(S, ""), r = e.preserveConsecutiveUppercase ? R(r, t) : t(r), e.pascalCase && (r = o(r.charAt(0)) + r.slice(1)), O(r, o));
41
+ return r.length === 1 ? b.test(r) ? "" : e.pascalCase ? o(r) : t(r) : (r !== t(r) && (r = j(r, t, o, e.preserveConsecutiveUppercase)), r = r.replace(A, ""), r = e.preserveConsecutiveUppercase ? R(r, t) : t(r), e.pascalCase && (r = o(r.charAt(0)) + r.slice(1)), O(r, o));
42
42
  }
43
43
  function N(r, e, t, o) {
44
44
  const a = "virtual:storyblok-components", s = "\0" + a;
@@ -52,11 +52,11 @@ function N(r, e, t, o) {
52
52
  if (n === s) {
53
53
  const u = [], l = [];
54
54
  for await (const [c, f] of Object.entries(e)) {
55
- const p = await this.resolve(
55
+ const d = await this.resolve(
56
56
  "/" + r + "/" + f + ".astro"
57
57
  );
58
- if (p)
59
- u.push(`import ${v(c)} from "${p.id}"`);
58
+ if (d)
59
+ u.push(`import ${v(c)} from "${d.id}"`);
60
60
  else if (t)
61
61
  l.push(c);
62
62
  else
@@ -160,15 +160,15 @@ const _ = function(r, e) {
160
160
  tag: "li"
161
161
  }), W = () => ({
162
162
  tag: "ol"
163
- }), H = () => ({
163
+ }), Y = () => ({
164
164
  tag: "p"
165
- }), Y = (r) => ({
165
+ }), H = (r) => ({
166
166
  tag: [
167
167
  {
168
168
  tag: "span",
169
169
  attrs: {
170
- ["data-type"]: "emoji",
171
- ["data-name"]: r.attrs.name,
170
+ "data-type": "emoji",
171
+ "data-name": r.attrs.name,
172
172
  emoji: r.attrs.emoji
173
173
  }
174
174
  }
@@ -257,8 +257,8 @@ const _ = function(r, e) {
257
257
  image: V,
258
258
  list_item: G,
259
259
  ordered_list: W,
260
- paragraph: H,
261
- emoji: Y
260
+ paragraph: Y,
261
+ emoji: H
262
262
  },
263
263
  marks: {
264
264
  bold: Q,
@@ -342,7 +342,7 @@ class fe {
342
342
  /a.storyblok.com\/f\/(\d+)\/([^.]+)\.(gif|jpg|jpeg|png|tif|tiff|bmp)/g
343
343
  );
344
344
  if (f && f.length > 0) {
345
- const p = {
345
+ const d = {
346
346
  srcset: (i = t.srcset) == null ? void 0 : i.map((g) => {
347
347
  if (typeof g == "number")
348
348
  return `//${f}/m/${g}x0${n} ${g}w`;
@@ -353,8 +353,8 @@ class fe {
353
353
  }).join(", "),
354
354
  sizes: (c = t.sizes) == null ? void 0 : c.map((g) => g).join(", ")
355
355
  };
356
- let d = "";
357
- return p.srcset && (d += `srcset="${p.srcset}" `), p.sizes && (d += `sizes="${p.sizes}" `), l.replace(/<img/g, `<img ${d.trim()}`);
356
+ let p = "";
357
+ return d.srcset && (p += `srcset="${d.srcset}" `), d.sizes && (p += `sizes="${d.sizes}" `), l.replace(/<img/g, `<img ${p.trim()}`);
358
358
  }
359
359
  return l;
360
360
  })), e;
@@ -432,8 +432,8 @@ const ye = (r) => {
432
432
  "data-blok-uid": e.id + "-" + e.uid
433
433
  };
434
434
  };
435
- let pe;
436
- const de = "https://app.storyblok.com/f/storyblok-v2-latest.js", he = (r, e) => {
435
+ let de;
436
+ const pe = "https://app.storyblok.com/f/storyblok-v2-latest.js", he = (r, e) => {
437
437
  r.addNode("blok", (t) => {
438
438
  let o = "";
439
439
  return t.attrs.body.forEach((a) => {
@@ -446,7 +446,7 @@ const de = "https://app.storyblok.com/f/storyblok-v2-latest.js", he = (r, e) =>
446
446
  var e, t;
447
447
  return !r || ((e = r == null ? void 0 : r.content) == null ? void 0 : e[0].type) !== "blok" && !((t = r == null ? void 0 : r.content) != null && t[0].content);
448
448
  }, me = (r, e, t) => {
449
- let o = t || pe;
449
+ let o = t || de;
450
450
  if (!o) {
451
451
  console.error(
452
452
  "Please initialize the Storyblok SDK before calling the renderRichText function"
@@ -454,7 +454,7 @@ const de = "https://app.storyblok.com/f/storyblok-v2-latest.js", he = (r, e) =>
454
454
  return;
455
455
  }
456
456
  return be(r) ? "" : (e && (o = new fe(e.schema), e.resolver && he(o, e.resolver)), o.render(r));
457
- }, ke = () => P(de);
457
+ }, ke = () => P(pe);
458
458
  function $e() {
459
459
  return globalThis.storyblokApiInstance || console.error("storyblokApiInstance has not been initialized correctly"), globalThis.storyblokApiInstance;
460
460
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@storyblok/astro",
3
- "version": "2.5.3",
3
+ "version": "2.5.5",
4
4
  "description": "Official Astro integration for the Storyblok Headless CMS",
5
5
  "main": "./dist/storyblok-astro.js",
6
6
  "module": "./dist/storyblok-astro.mjs",
@@ -33,20 +33,20 @@
33
33
  "prepublishOnly": "npm run build && cp ../README.md ./"
34
34
  },
35
35
  "dependencies": {
36
- "@storyblok/js": "^2.2.2",
36
+ "@storyblok/js": "^2.2.4",
37
37
  "camelcase": "^7.0.1"
38
38
  },
39
39
  "devDependencies": {
40
40
  "@cypress/vite-dev-server": "^5.0.5",
41
- "@rollup/plugin-dynamic-import-vars": "^2.0.3",
42
- "@types/node": "20.3.3",
43
- "astro": "2.7.3",
44
- "cypress": "^12.16.0",
41
+ "@rollup/plugin-dynamic-import-vars": "^2.0.4",
42
+ "@types/node": "20.4.2",
43
+ "astro": "2.9.7",
44
+ "cypress": "^12.17.3",
45
45
  "eslint-plugin-cypress": "^2.13.3",
46
46
  "start-server-and-test": "^2.0.0",
47
47
  "typescript": "5.1.6",
48
- "vite": "^4.3.9",
49
- "vite-plugin-dts": "^3.0.3"
48
+ "vite": "^4.4.4",
49
+ "vite-plugin-dts": "^3.3.1"
50
50
  },
51
51
  "repository": {
52
52
  "type": "git",
@@ -1,2 +0,0 @@
1
- declare const _default: import("vite").UserConfigExport;
2
- export default _default;
File without changes
File without changes