@storyblok/astro 2.0.2 → 2.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -4,7 +4,7 @@ import type { ISbConfig, ISbRichtext, SbRichTextOptions } from "./types";
4
4
  export { storyblokEditable, loadStoryblokBridge, RichTextResolver, RichTextSchema, } from "@storyblok/js";
5
5
  export declare function useStoryblokApi(): StoryblokClient;
6
6
  export declare function renderRichText(data: ISbRichtext, options?: SbRichTextOptions): string;
7
- export interface IntegrationOptions {
7
+ export declare type IntegrationOptions = {
8
8
  /**
9
9
  * The access token from your space.
10
10
  */
@@ -12,7 +12,7 @@ export interface IntegrationOptions {
12
12
  /**
13
13
  * 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.
14
14
  */
15
- useCustomApi?: false;
15
+ useCustomApi?: boolean;
16
16
  /**
17
17
  * Set custom API options here (cache, region, and more). All options are documented [here](https://github.com/storyblok/storyblok-js-client#class-storyblok).
18
18
  */
@@ -34,6 +34,6 @@ export interface IntegrationOptions {
34
34
  * ```
35
35
  */
36
36
  components?: object;
37
- }
38
- export default function storyblokIntegration(options?: IntegrationOptions): AstroIntegration;
37
+ };
38
+ export default function storyblokIntegration(options: IntegrationOptions): AstroIntegration;
39
39
  export * from "./types";
@@ -2647,7 +2647,7 @@ export declare interface WatchOptions {
2647
2647
 
2648
2648
  /**
2649
2649
  * Whether to use the `fsevents` watching interface if available. When set to `true` explicitly
2650
- * and `fsevents` is available this supercedes the `usePolling` setting. When set to `false` on
2650
+ * and `fsevents` is available this supersedes the `usePolling` setting. When set to `false` on
2651
2651
  * OS X, `usePolling: true` becomes the default.
2652
2652
  */
2653
2653
  useFsEvents?: boolean
@@ -1,4 +1,4 @@
1
- (function(l,c){typeof exports=="object"&&typeof module<"u"?c(exports):typeof define=="function"&&define.amd?define(["exports"],c):(l=typeof globalThis<"u"?globalThis:l||self,c(l.storyblokAstro={}))})(this,function(l){"use strict";function c(t,e,r){const o="virtual:storyblok-init",s="\0"+o;return{name:"vite-plugin-storyblok-init",async resolveId(n){if(n===o)return s},async load(n){if(n===s)return`
1
+ (function(a,d){typeof exports=="object"&&typeof module<"u"?d(exports):typeof define=="function"&&define.amd?define(["exports"],d):(a=typeof globalThis<"u"?globalThis:a||self,d(a.storyblokAstro={}))})(this,function(a){"use strict";function d(t,e,r){const o="virtual:storyblok-init",n="\0"+o;return{name:"vite-plugin-storyblok-init",async resolveId(s){if(s===o)return n},async load(s){if(s===n)return`
2
2
  import { storyblokInit, apiPlugin } from "@storyblok/js";
3
3
  const { storyblokApi } = storyblokInit({
4
4
  accessToken: "${t}",
@@ -6,12 +6,12 @@
6
6
  apiOptions: ${JSON.stringify(r)},
7
7
  });
8
8
  export const storyblokApiInstance = storyblokApi;
9
- `}}}const A=/[\p{Lu}]/u,E=/[\p{Ll}]/u,d=/^[\p{Lu}](?![\p{Lu}])/gu,g=/([\p{Alpha}\p{N}_]|$)/u,u=/[_.\- ]+/,w=new RegExp("^"+u.source),f=new RegExp(u.source+g.source,"gu"),h=new RegExp("\\d+"+g.source,"gu"),S=(t,e,r)=>{let o=!1,s=!1,n=!1;for(let a=0;a<t.length;a++){const i=t[a];o&&A.test(i)?(t=t.slice(0,a)+"-"+t.slice(a),o=!1,n=s,s=!0,a++):s&&n&&E.test(i)?(t=t.slice(0,a-1)+"-"+t.slice(a-1),n=s,s=!1,o=!0):(o=e(i)===i&&r(i)!==i,n=s,s=r(i)===i&&e(i)!==i)}return t},R=(t,e)=>(d.lastIndex=0,t.replace(d,r=>e(r))),_=(t,e)=>(f.lastIndex=0,h.lastIndex=0,t.replace(f,(r,o)=>e(o)).replace(h,r=>e(r)));function p(t,e){if(!(typeof t=="string"||Array.isArray(t)))throw new TypeError("Expected the input to be `string | string[]`");if(e={pascalCase:!1,preserveConsecutiveUppercase:!1,...e},Array.isArray(t)?t=t.map(n=>n.trim()).filter(n=>n.length).join("-"):t=t.trim(),t.length===0)return"";const r=e.locale===!1?n=>n.toLowerCase():n=>n.toLocaleLowerCase(e.locale),o=e.locale===!1?n=>n.toUpperCase():n=>n.toLocaleUpperCase(e.locale);return t.length===1?u.test(t)?"":e.pascalCase?o(t):r(t):(t!==r(t)&&(t=S(t,r,o)),t=t.replace(w,""),t=e.preserveConsecutiveUppercase?R(t,r):r(t),e.pascalCase&&(t=o(t.charAt(0))+t.slice(1)),_(t,o))}function C(t){const e="virtual:storyblok-components",r="\0"+e;return{name:"vite-plugin-storyblok-components",async resolveId(o){if(o===e)return r},async load(o){if(o===r){const s=[];for await(const[n,a]of Object.entries(t)){const{id:i}=await this.resolve("/src/"+a+".astro");s.push(`import ${p(n)} from "${i}"`)}return`${s.join(";")};export default {${Object.keys(t).map(n=>p(n)).join(",")}}`}}}}var $=Object.defineProperty,b=Object.getOwnPropertySymbols,O=Object.prototype.hasOwnProperty,x=Object.prototype.propertyIsEnumerable,y=(t,e,r)=>e in t?$(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,P=(t,e)=>{for(var r in e||(e={}))O.call(e,r)&&y(t,r,e[r]);if(b)for(var r of b(e))x.call(e,r)&&y(t,r,e[r]);return t};let m=!1;const k=[],j=t=>new Promise((e,r)=>{if(typeof window>"u"||(window.storyblokRegisterEvent=s=>{if(window.location===window.parent.location){console.warn("You are not in Draft Mode or in the Visual Editor.");return}m?s():k.push(s)},document.getElementById("storyblok-javascript-bridge")))return;const o=document.createElement("script");o.async=!0,o.src=t,o.id="storyblok-javascript-bridge",o.onerror=s=>r(s),o.onload=s=>{k.forEach(n=>n()),m=!0,e(s)},document.getElementsByTagName("head")[0].appendChild(o)});var N=Object.defineProperty,L=(t,e,r)=>e in t?N(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,v=(t,e,r)=>(L(t,typeof e!="symbol"?e+"":e,r),r);const M=function(t,e){const r={};for(const o in t){const s=t[o];e.indexOf(o)>-1&&s!==null&&(r[o]=s)}return r},U=t=>t==="email",B=()=>({singleTag:"hr"}),D=()=>({tag:"blockquote"}),z=()=>({tag:"ul"}),F=t=>({tag:["pre",{tag:"code",attrs:t.attrs}]}),V=()=>({singleTag:"br"}),q=t=>({tag:`h${t.attrs.level}`}),J=t=>({singleTag:[{tag:"img",attrs:M(t.attrs,["src","alt","title"])}]}),G=()=>({tag:"li"}),K=()=>({tag:"ol"}),H=()=>({tag:"p"}),W=()=>({tag:"b"}),Y=()=>({tag:"strike"}),Q=()=>({tag:"u"}),X=()=>({tag:"strong"}),Z=()=>({tag:"code"}),ee=()=>({tag:"i"}),te=t=>{const e=P({},t.attrs),{linktype:r="url"}=t.attrs;return U(r)&&(e.href=`mailto:${e.href}`),e.anchor&&(e.href=`${e.href}#${e.anchor}`,delete e.anchor),{tag:[{tag:"a",attrs:e}]}},re=t=>({tag:[{tag:"span",attrs:t.attrs}]}),T={nodes:{horizontal_rule:B,blockquote:D,bullet_list:z,code_block:F,hard_break:V,heading:q,image:J,list_item:G,ordered_list:K,paragraph:H},marks:{bold:W,strike:Y,underline:Q,strong:X,code:Z,italic:ee,link:te,styled:re}},oe=function(t){const e={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"},r=/[&<>"']/g,o=RegExp(r.source);return t&&o.test(t)?t.replace(r,s=>e[s]):t};class I{constructor(e){v(this,"marks"),v(this,"nodes"),e||(e=T),this.marks=e.marks||[],this.nodes=e.nodes||[]}addNode(e,r){this.nodes[e]=r}addMark(e,r){this.marks[e]=r}render(e){if(e&&e.content&&Array.isArray(e.content)){let r="";return e.content.forEach(o=>{r+=this.renderNode(o)}),r}return console.warn("The render method must receive an object with a content field, which is an array"),""}renderNode(e){const r=[];e.marks&&e.marks.forEach(s=>{const n=this.getMatchingMark(s);n&&r.push(this.renderOpeningTag(n.tag))});const o=this.getMatchingNode(e);return o&&o.tag&&r.push(this.renderOpeningTag(o.tag)),e.content?e.content.forEach(s=>{r.push(this.renderNode(s))}):e.text?r.push(oe(e.text)):o&&o.singleTag?r.push(this.renderTag(o.singleTag," /")):o&&o.html&&r.push(o.html),o&&o.tag&&r.push(this.renderClosingTag(o.tag)),e.marks&&e.marks.slice(0).reverse().forEach(s=>{const n=this.getMatchingMark(s);n&&r.push(this.renderClosingTag(n.tag))}),r.join("")}renderTag(e,r){return e.constructor===String?`<${e}${r}>`:e.map(o=>{if(o.constructor===String)return`<${o}${r}>`;{let s=`<${o.tag}`;if(o.attrs)for(const n in o.attrs){const a=o.attrs[n];a!==null&&(s+=` ${n}="${a}"`)}return`${s}${r}>`}}).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){const r=this.nodes[e.type];if(typeof r=="function")return r(e)}getMatchingMark(e){const r=this.marks[e.type];if(typeof r=="function")return r(e)}}var se=t=>{if(typeof t!="object"||typeof t._editable>"u")return{};const e=JSON.parse(t._editable.replace(/^<!--#storyblok#/,"").replace(/-->$/,""));return{"data-blok-c":JSON.stringify(e),"data-blok-uid":e.id+"-"+e.uid}};let ne;const ae="https://app.storyblok.com/f/storyblok-v2-latest.js",le=(t,e)=>{t.addNode("blok",r=>{let o="";return r.attrs.body.forEach(s=>{o+=e(s.component,s)}),{html:o}})},ie=(t,e,r)=>{let o=r||ne;if(!o){console.error("Please initialize the Storyblok SDK before calling the renderRichText function");return}return t===""?"":t?(e&&(o=new I(e.schema),e.resolver&&le(o,e.resolver)),o.render(t)):(console.warn(`${t} is not a valid Richtext object. This might be because the value of the richtext field is empty.
9
+ `}}}const I=/[\p{Lu}]/u,E=/[\p{Ll}]/u,h=/^[\p{Lu}](?![\p{Lu}])/gu,f=/([\p{Alpha}\p{N}_]|$)/u,g=/[_.\- ]+/,S=new RegExp("^"+g.source),p=new RegExp(g.source+f.source,"gu"),b=new RegExp("\\d+"+f.source,"gu"),C=(t,e,r,o)=>{let n=!1,s=!1,c=!1,u=!1;for(let i=0;i<t.length;i++){const l=t[i];u=i>2?t[i-3]==="-":!0,n&&I.test(l)?(t=t.slice(0,i)+"-"+t.slice(i),n=!1,c=s,s=!0,i++):s&&c&&E.test(l)&&(!u||o)?(t=t.slice(0,i-1)+"-"+t.slice(i-1),c=s,s=!1,n=!0):(n=e(l)===l&&r(l)!==l,c=s,s=r(l)===l&&e(l)!==l)}return t},w=(t,e)=>(h.lastIndex=0,t.replace(h,r=>e(r))),R=(t,e)=>(p.lastIndex=0,b.lastIndex=0,t.replace(p,(r,o)=>e(o)).replace(b,r=>e(r)));function y(t,e){if(!(typeof t=="string"||Array.isArray(t)))throw new TypeError("Expected the input to be `string | string[]`");if(e={pascalCase:!1,preserveConsecutiveUppercase:!1,...e},Array.isArray(t)?t=t.map(s=>s.trim()).filter(s=>s.length).join("-"):t=t.trim(),t.length===0)return"";const r=e.locale===!1?s=>s.toLowerCase():s=>s.toLocaleLowerCase(e.locale),o=e.locale===!1?s=>s.toUpperCase():s=>s.toLocaleUpperCase(e.locale);return t.length===1?g.test(t)?"":e.pascalCase?o(t):r(t):(t!==r(t)&&(t=C(t,r,o,e.preserveConsecutiveUppercase)),t=t.replace(S,""),t=e.preserveConsecutiveUppercase?w(t,r):r(t),e.pascalCase&&(t=o(t.charAt(0))+t.slice(1)),R(t,o))}function $(t){const e="virtual:storyblok-components",r="\0"+e;return{name:"vite-plugin-storyblok-components",async resolveId(o){if(o===e)return r},async load(o){if(o===r){const n=[];for await(const[s,c]of Object.entries(t)){const{id:u}=await this.resolve("/src/"+c+".astro");n.push(`import ${y(s)} from "${u}"`)}return`${n.join(";")};export default {${Object.keys(t).map(s=>y(s)).join(",")}}`}}}}let k=!1;const m=[],x=t=>new Promise((e,r)=>{if(typeof window>"u"||(window.storyblokRegisterEvent=n=>{if(window.location===window.parent.location){console.warn("You are not in Draft Mode or in the Visual Editor.");return}k?n():m.push(n)},document.getElementById("storyblok-javascript-bridge")))return;const o=document.createElement("script");o.async=!0,o.src=t,o.id="storyblok-javascript-bridge",o.onerror=n=>r(n),o.onload=n=>{m.forEach(s=>s()),k=!0,e(n)},document.getElementsByTagName("head")[0].appendChild(o)});var N=Object.defineProperty,j=(t,e,r)=>e in t?N(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,v=(t,e,r)=>(j(t,typeof e!="symbol"?e+"":e,r),r);const L=function(t,e){const r={};for(const o in t){const n=t[o];e.indexOf(o)>-1&&n!==null&&(r[o]=n)}return r},_=t=>t==="email",O=()=>({singleTag:"hr"}),M=()=>({tag:"blockquote"}),P=()=>({tag:"ul"}),U=t=>({tag:["pre",{tag:"code",attrs:t.attrs}]}),D=()=>({singleTag:"br"}),B=t=>({tag:`h${t.attrs.level}`}),z=t=>({singleTag:[{tag:"img",attrs:L(t.attrs,["src","alt","title"])}]}),F=()=>({tag:"li"}),q=()=>({tag:"ol"}),J=()=>({tag:"p"}),V=()=>({tag:"b"}),K=()=>({tag:"strike"}),G=()=>({tag:"u"}),Y=()=>({tag:"strong"}),H=()=>({tag:"code"}),Q=()=>({tag:"i"}),W=t=>{const e={...t.attrs},{linktype:r="url"}=t.attrs;return _(r)&&(e.href=`mailto:${e.href}`),e.anchor&&(e.href=`${e.href}#${e.anchor}`,delete e.anchor),{tag:[{tag:"a",attrs:e}]}},Z=t=>({tag:[{tag:"span",attrs:t.attrs}]}),T={nodes:{horizontal_rule:O,blockquote:M,bullet_list:P,code_block:U,hard_break:D,heading:B,image:z,list_item:F,ordered_list:q,paragraph:J},marks:{bold:V,strike:K,underline:G,strong:Y,code:H,italic:Q,link:W,styled:Z}},X=function(t){const e={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"},r=/[&<>"']/g,o=RegExp(r.source);return t&&o.test(t)?t.replace(r,n=>e[n]):t};class A{constructor(e){v(this,"marks"),v(this,"nodes"),e||(e=T),this.marks=e.marks||[],this.nodes=e.nodes||[]}addNode(e,r){this.nodes[e]=r}addMark(e,r){this.marks[e]=r}render(e){if(e&&e.content&&Array.isArray(e.content)){let r="";return e.content.forEach(o=>{r+=this.renderNode(o)}),r}return console.warn("The render method must receive an object with a content field, which is an array"),""}renderNode(e){const r=[];e.marks&&e.marks.forEach(n=>{const s=this.getMatchingMark(n);s&&r.push(this.renderOpeningTag(s.tag))});const o=this.getMatchingNode(e);return o&&o.tag&&r.push(this.renderOpeningTag(o.tag)),e.content?e.content.forEach(n=>{r.push(this.renderNode(n))}):e.text?r.push(X(e.text)):o&&o.singleTag?r.push(this.renderTag(o.singleTag," /")):o&&o.html&&r.push(o.html),o&&o.tag&&r.push(this.renderClosingTag(o.tag)),e.marks&&e.marks.slice(0).reverse().forEach(n=>{const s=this.getMatchingMark(n);s&&r.push(this.renderClosingTag(s.tag))}),r.join("")}renderTag(e,r){return e.constructor===String?`<${e}${r}>`:e.map(o=>{if(o.constructor===String)return`<${o}${r}>`;{let n=`<${o.tag}`;if(o.attrs)for(const s in o.attrs){const c=o.attrs[s];c!==null&&(n+=` ${s}="${c}"`)}return`${n}${r}>`}}).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){const r=this.nodes[e.type];if(typeof r=="function")return r(e)}getMatchingMark(e){const r=this.marks[e.type];if(typeof r=="function")return r(e)}}const ee=t=>{if(typeof t!="object"||typeof t._editable>"u")return{};const e=JSON.parse(t._editable.replace(/^<!--#storyblok#/,"").replace(/-->$/,""));return{"data-blok-c":JSON.stringify(e),"data-blok-uid":e.id+"-"+e.uid}};let te;const re="https://app.storyblok.com/f/storyblok-v2-latest.js",oe=(t,e)=>{t.addNode("blok",r=>{let o="";return r.attrs.body.forEach(n=>{o+=e(n.component,n)}),{html:o}})},se=(t,e,r)=>{let o=r||te;if(!o){console.error("Please initialize the Storyblok SDK before calling the renderRichText function");return}return t===""?"":t?(e&&(o=new A(e.schema),e.resolver&&oe(o,e.resolver)),o.render(t)):(console.warn(`${t} is not a valid Richtext object. This might be because the value of the richtext field is empty.
10
10
 
11
- For more info about the richtext object check https://github.com/storyblok/storyblok-js#rendering-rich-text`),"")},ce=()=>j(ae);function ue(){return globalThis.storyblokApiInstance||console.error("storyblokApiInstance has not been initialized correctly"),globalThis.storyblokApiInstance}function de(t,e){const r=globalThis.storyblokApiInstance.richTextResolver;if(!r){console.error("Please initialize the Storyblok SDK before calling the renderRichText function");return}return ie(t,e,r)}function ge(t={accessToken:"",useCustomApi:!1,apiOptions:{},bridge:!0,components:{}}){return{name:"@storyblok/astro",hooks:{"astro:config:setup":({injectScript:e,updateConfig:r})=>{r({vite:{plugins:[c(t.accessToken,t.useCustomApi,t.apiOptions),C(t.components)]}}),e("page-ssr",`
11
+ For more info about the richtext object check https://github.com/storyblok/storyblok-js#rendering-rich-text`),"")},ne=()=>x(re);function ae(){return globalThis.storyblokApiInstance||console.error("storyblokApiInstance has not been initialized correctly"),globalThis.storyblokApiInstance}function ie(t,e){const r=globalThis.storyblokApiInstance.richTextResolver;if(!r){console.error("Please initialize the Storyblok SDK before calling the renderRichText function");return}return se(t,e,r)}function le(t){const e={useCustomApi:!1,bridge:!0,...t};return{name:"@storyblok/astro",hooks:{"astro:config:setup":({injectScript:r,updateConfig:o})=>{o({vite:{plugins:[d(e.accessToken,e.useCustomApi,e.apiOptions),$(e.components)]}}),r("page-ssr",`
12
12
  import { storyblokApiInstance } from "virtual:storyblok-init";
13
13
  globalThis.storyblokApiInstance = storyblokApiInstance;
14
- `),t.bridge&&e("page",`
14
+ `),e.bridge&&r("page",`
15
15
  import { loadStoryblokBridge } from "@storyblok/astro";
16
16
  loadStoryblokBridge().then(() => {
17
17
  const { StoryblokBridge, location } = window;
@@ -23,4 +23,4 @@
23
23
  }
24
24
  });
25
25
  });
26
- `)}}}}l.RichTextResolver=I,l.RichTextSchema=T,l.default=ge,l.loadStoryblokBridge=ce,l.renderRichText=de,l.storyblokEditable=se,l.useStoryblokApi=ue,Object.defineProperties(l,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
26
+ `)}}}}a.RichTextResolver=A,a.RichTextSchema=T,a.default=le,a.loadStoryblokBridge=ne,a.renderRichText=ie,a.storyblokEditable=ee,a.useStoryblokApi=ae,Object.defineProperties(a,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
@@ -1,13 +1,13 @@
1
- function k(t, e, r) {
2
- const o = "virtual:storyblok-init", s = "\0" + o;
1
+ function m(t, e, r) {
2
+ const o = "virtual:storyblok-init", a = "\0" + o;
3
3
  return {
4
4
  name: "vite-plugin-storyblok-init",
5
- async resolveId(n) {
6
- if (n === o)
7
- return s;
5
+ async resolveId(s) {
6
+ if (s === o)
7
+ return a;
8
8
  },
9
- async load(n) {
10
- if (n === s)
9
+ async load(s) {
10
+ if (s === a)
11
11
  return `
12
12
  import { storyblokInit, apiPlugin } from "@storyblok/js";
13
13
  const { storyblokApi } = storyblokInit({
@@ -20,27 +20,27 @@ function k(t, e, r) {
20
20
  }
21
21
  };
22
22
  }
23
- const v = /[\p{Lu}]/u, I = /[\p{Ll}]/u, c = /^[\p{Lu}](?![\p{Lu}])/gu, m = /([\p{Alpha}\p{N}_]|$)/u, i = /[_.\- ]+/, T = new RegExp("^" + i.source), u = new RegExp(i.source + m.source, "gu"), d = new RegExp("\\d+" + m.source, "gu"), E = (t, e, r) => {
24
- let o = !1, s = !1, n = !1;
25
- for (let a = 0; a < t.length; a++) {
26
- const l = t[a];
27
- o && v.test(l) ? (t = t.slice(0, a) + "-" + t.slice(a), o = !1, n = s, s = !0, a++) : s && n && I.test(l) ? (t = t.slice(0, a - 1) + "-" + t.slice(a - 1), n = s, s = !1, o = !0) : (o = e(l) === l && r(l) !== l, n = s, s = r(l) === l && e(l) !== l);
23
+ const v = /[\p{Lu}]/u, I = /[\p{Ll}]/u, u = /^[\p{Lu}](?![\p{Lu}])/gu, k = /([\p{Alpha}\p{N}_]|$)/u, d = /[_.\- ]+/, T = new RegExp("^" + d.source), g = new RegExp(d.source + k.source, "gu"), h = new RegExp("\\d+" + k.source, "gu"), A = (t, e, r, o) => {
24
+ let a = !1, s = !1, i = !1, c = !1;
25
+ for (let n = 0; n < t.length; n++) {
26
+ const l = t[n];
27
+ c = n > 2 ? t[n - 3] === "-" : !0, a && v.test(l) ? (t = t.slice(0, n) + "-" + t.slice(n), a = !1, i = s, s = !0, n++) : s && i && I.test(l) && (!c || o) ? (t = t.slice(0, n - 1) + "-" + t.slice(n - 1), i = s, s = !1, a = !0) : (a = e(l) === l && r(l) !== l, i = s, s = r(l) === l && e(l) !== l);
28
28
  }
29
29
  return t;
30
- }, A = (t, e) => (c.lastIndex = 0, t.replace(c, (r) => e(r))), w = (t, e) => (u.lastIndex = 0, d.lastIndex = 0, t.replace(u, (r, o) => e(o)).replace(d, (r) => e(r)));
31
- function g(t, e) {
30
+ }, E = (t, e) => (u.lastIndex = 0, t.replace(u, (r) => e(r))), C = (t, e) => (g.lastIndex = 0, h.lastIndex = 0, t.replace(g, (r, o) => e(o)).replace(h, (r) => e(r)));
31
+ function p(t, e) {
32
32
  if (!(typeof t == "string" || Array.isArray(t)))
33
33
  throw new TypeError("Expected the input to be `string | string[]`");
34
34
  if (e = {
35
35
  pascalCase: !1,
36
36
  preserveConsecutiveUppercase: !1,
37
37
  ...e
38
- }, Array.isArray(t) ? t = t.map((n) => n.trim()).filter((n) => n.length).join("-") : t = t.trim(), t.length === 0)
38
+ }, Array.isArray(t) ? t = t.map((s) => s.trim()).filter((s) => s.length).join("-") : t = t.trim(), t.length === 0)
39
39
  return "";
40
- const r = e.locale === !1 ? (n) => n.toLowerCase() : (n) => n.toLocaleLowerCase(e.locale), o = e.locale === !1 ? (n) => n.toUpperCase() : (n) => n.toLocaleUpperCase(e.locale);
41
- return t.length === 1 ? i.test(t) ? "" : e.pascalCase ? o(t) : r(t) : (t !== r(t) && (t = E(t, r, o)), t = t.replace(T, ""), t = e.preserveConsecutiveUppercase ? A(t, r) : r(t), e.pascalCase && (t = o(t.charAt(0)) + t.slice(1)), w(t, o));
40
+ const r = 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 t.length === 1 ? d.test(t) ? "" : e.pascalCase ? o(t) : r(t) : (t !== r(t) && (t = A(t, r, o, e.preserveConsecutiveUppercase)), t = t.replace(T, ""), t = e.preserveConsecutiveUppercase ? E(t, r) : r(t), e.pascalCase && (t = o(t.charAt(0)) + t.slice(1)), C(t, o));
42
42
  }
43
- function S(t) {
43
+ function w(t) {
44
44
  const e = "virtual:storyblok-components", r = "\0" + e;
45
45
  return {
46
46
  name: "vite-plugin-storyblok-components",
@@ -50,54 +50,46 @@ function S(t) {
50
50
  },
51
51
  async load(o) {
52
52
  if (o === r) {
53
- const s = [];
54
- for await (const [n, a] of Object.entries(t)) {
55
- const { id: l } = await this.resolve("/src/" + a + ".astro");
56
- s.push(`import ${g(n)} from "${l}"`);
53
+ const a = [];
54
+ for await (const [s, i] of Object.entries(t)) {
55
+ const { id: c } = await this.resolve("/src/" + i + ".astro");
56
+ a.push(`import ${p(s)} from "${c}"`);
57
57
  }
58
- return `${s.join(";")};export default {${Object.keys(t).map((n) => g(n)).join(",")}}`;
58
+ return `${a.join(";")};export default {${Object.keys(t).map((s) => p(s)).join(",")}}`;
59
59
  }
60
60
  }
61
61
  };
62
62
  }
63
- var C = Object.defineProperty, h = Object.getOwnPropertySymbols, R = Object.prototype.hasOwnProperty, _ = Object.prototype.propertyIsEnumerable, f = (t, e, r) => e in t ? C(t, e, { enumerable: !0, configurable: !0, writable: !0, value: r }) : t[e] = r, x = (t, e) => {
64
- for (var r in e || (e = {}))
65
- R.call(e, r) && f(t, r, e[r]);
66
- if (h)
67
- for (var r of h(e))
68
- _.call(e, r) && f(t, r, e[r]);
69
- return t;
70
- };
71
- let p = !1;
72
- const b = [], $ = (t) => new Promise((e, r) => {
73
- if (typeof window > "u" || (window.storyblokRegisterEvent = (s) => {
63
+ let f = !1;
64
+ const b = [], S = (t) => new Promise((e, r) => {
65
+ if (typeof window > "u" || (window.storyblokRegisterEvent = (a) => {
74
66
  if (window.location === window.parent.location) {
75
67
  console.warn("You are not in Draft Mode or in the Visual Editor.");
76
68
  return;
77
69
  }
78
- p ? s() : b.push(s);
70
+ f ? a() : b.push(a);
79
71
  }, document.getElementById("storyblok-javascript-bridge")))
80
72
  return;
81
73
  const o = document.createElement("script");
82
- o.async = !0, o.src = t, o.id = "storyblok-javascript-bridge", o.onerror = (s) => r(s), o.onload = (s) => {
83
- b.forEach((n) => n()), p = !0, e(s);
74
+ o.async = !0, o.src = t, o.id = "storyblok-javascript-bridge", o.onerror = (a) => r(a), o.onload = (a) => {
75
+ b.forEach((s) => s()), f = !0, e(a);
84
76
  }, document.getElementsByTagName("head")[0].appendChild(o);
85
77
  });
86
- var O = Object.defineProperty, P = (t, e, r) => e in t ? O(t, e, { enumerable: !0, configurable: !0, writable: !0, value: r }) : t[e] = r, y = (t, e, r) => (P(t, typeof e != "symbol" ? e + "" : e, r), r);
87
- const N = function(t, e) {
78
+ var $ = Object.defineProperty, R = (t, e, r) => e in t ? $(t, e, { enumerable: !0, configurable: !0, writable: !0, value: r }) : t[e] = r, y = (t, e, r) => (R(t, typeof e != "symbol" ? e + "" : e, r), r);
79
+ const x = function(t, e) {
88
80
  const r = {};
89
81
  for (const o in t) {
90
- const s = t[o];
91
- e.indexOf(o) > -1 && s !== null && (r[o] = s);
82
+ const a = t[o];
83
+ e.indexOf(o) > -1 && a !== null && (r[o] = a);
92
84
  }
93
85
  return r;
94
- }, j = (t) => t === "email", L = () => ({
86
+ }, N = (t) => t === "email", L = () => ({
95
87
  singleTag: "hr"
96
- }), M = () => ({
88
+ }), j = () => ({
97
89
  tag: "blockquote"
98
- }), U = () => ({
90
+ }), O = () => ({
99
91
  tag: "ul"
100
- }), D = (t) => ({
92
+ }), _ = (t) => ({
101
93
  tag: [
102
94
  "pre",
103
95
  {
@@ -105,38 +97,38 @@ const N = function(t, e) {
105
97
  attrs: t.attrs
106
98
  }
107
99
  ]
108
- }), B = () => ({
100
+ }), P = () => ({
109
101
  singleTag: "br"
110
- }), z = (t) => ({
102
+ }), M = (t) => ({
111
103
  tag: `h${t.attrs.level}`
112
- }), F = (t) => ({
104
+ }), U = (t) => ({
113
105
  singleTag: [
114
106
  {
115
107
  tag: "img",
116
- attrs: N(t.attrs, ["src", "alt", "title"])
108
+ attrs: x(t.attrs, ["src", "alt", "title"])
117
109
  }
118
110
  ]
119
- }), V = () => ({
111
+ }), D = () => ({
120
112
  tag: "li"
121
- }), q = () => ({
113
+ }), B = () => ({
122
114
  tag: "ol"
123
- }), J = () => ({
115
+ }), z = () => ({
124
116
  tag: "p"
125
- }), G = () => ({
117
+ }), F = () => ({
126
118
  tag: "b"
127
- }), K = () => ({
119
+ }), q = () => ({
128
120
  tag: "strike"
129
- }), H = () => ({
121
+ }), J = () => ({
130
122
  tag: "u"
131
- }), W = () => ({
123
+ }), V = () => ({
132
124
  tag: "strong"
133
- }), Y = () => ({
125
+ }), K = () => ({
134
126
  tag: "code"
135
- }), Q = () => ({
127
+ }), G = () => ({
136
128
  tag: "i"
137
- }), X = (t) => {
138
- const e = x({}, t.attrs), { linktype: r = "url" } = t.attrs;
139
- return j(r) && (e.href = `mailto:${e.href}`), e.anchor && (e.href = `${e.href}#${e.anchor}`, delete e.anchor), {
129
+ }), Y = (t) => {
130
+ const e = { ...t.attrs }, { linktype: r = "url" } = t.attrs;
131
+ return N(r) && (e.href = `mailto:${e.href}`), e.anchor && (e.href = `${e.href}#${e.anchor}`, delete e.anchor), {
140
132
  tag: [
141
133
  {
142
134
  tag: "a",
@@ -144,37 +136,37 @@ const N = function(t, e) {
144
136
  }
145
137
  ]
146
138
  };
147
- }, Z = (t) => ({
139
+ }, H = (t) => ({
148
140
  tag: [
149
141
  {
150
142
  tag: "span",
151
143
  attrs: t.attrs
152
144
  }
153
145
  ]
154
- }), ee = {
146
+ }), Q = {
155
147
  nodes: {
156
148
  horizontal_rule: L,
157
- blockquote: M,
158
- bullet_list: U,
159
- code_block: D,
160
- hard_break: B,
161
- heading: z,
162
- image: F,
163
- list_item: V,
164
- ordered_list: q,
165
- paragraph: J
149
+ blockquote: j,
150
+ bullet_list: O,
151
+ code_block: _,
152
+ hard_break: P,
153
+ heading: M,
154
+ image: U,
155
+ list_item: D,
156
+ ordered_list: B,
157
+ paragraph: z
166
158
  },
167
159
  marks: {
168
- bold: G,
169
- strike: K,
170
- underline: H,
171
- strong: W,
172
- code: Y,
173
- italic: Q,
174
- link: X,
175
- styled: Z
160
+ bold: F,
161
+ strike: q,
162
+ underline: J,
163
+ strong: V,
164
+ code: K,
165
+ italic: G,
166
+ link: Y,
167
+ styled: H
176
168
  }
177
- }, te = function(t) {
169
+ }, W = function(t) {
178
170
  const e = {
179
171
  "&": "&amp;",
180
172
  "<": "&lt;",
@@ -182,11 +174,11 @@ const N = function(t, e) {
182
174
  '"': "&quot;",
183
175
  "'": "&#39;"
184
176
  }, r = /[&<>"']/g, o = RegExp(r.source);
185
- return t && o.test(t) ? t.replace(r, (s) => e[s]) : t;
177
+ return t && o.test(t) ? t.replace(r, (a) => e[a]) : t;
186
178
  };
187
- class re {
179
+ class Z {
188
180
  constructor(e) {
189
- y(this, "marks"), y(this, "nodes"), e || (e = ee), this.marks = e.marks || [], this.nodes = e.nodes || [];
181
+ y(this, "marks"), y(this, "nodes"), e || (e = Q), this.marks = e.marks || [], this.nodes = e.nodes || [];
190
182
  }
191
183
  addNode(e, r) {
192
184
  this.nodes[e] = r;
@@ -201,20 +193,22 @@ class re {
201
193
  r += this.renderNode(o);
202
194
  }), r;
203
195
  }
204
- return console.warn("The render method must receive an object with a content field, which is an array"), "";
196
+ return console.warn(
197
+ "The render method must receive an object with a content field, which is an array"
198
+ ), "";
205
199
  }
206
200
  renderNode(e) {
207
201
  const r = [];
208
- e.marks && e.marks.forEach((s) => {
209
- const n = this.getMatchingMark(s);
210
- n && r.push(this.renderOpeningTag(n.tag));
202
+ e.marks && e.marks.forEach((a) => {
203
+ const s = this.getMatchingMark(a);
204
+ s && r.push(this.renderOpeningTag(s.tag));
211
205
  });
212
206
  const o = this.getMatchingNode(e);
213
- return o && o.tag && r.push(this.renderOpeningTag(o.tag)), e.content ? e.content.forEach((s) => {
214
- r.push(this.renderNode(s));
215
- }) : e.text ? r.push(te(e.text)) : o && o.singleTag ? r.push(this.renderTag(o.singleTag, " /")) : o && o.html && r.push(o.html), o && o.tag && r.push(this.renderClosingTag(o.tag)), e.marks && e.marks.slice(0).reverse().forEach((s) => {
216
- const n = this.getMatchingMark(s);
217
- n && r.push(this.renderClosingTag(n.tag));
207
+ return o && o.tag && r.push(this.renderOpeningTag(o.tag)), e.content ? e.content.forEach((a) => {
208
+ r.push(this.renderNode(a));
209
+ }) : e.text ? r.push(W(e.text)) : o && o.singleTag ? r.push(this.renderTag(o.singleTag, " /")) : o && o.html && r.push(o.html), o && o.tag && r.push(this.renderClosingTag(o.tag)), e.marks && e.marks.slice(0).reverse().forEach((a) => {
210
+ const s = this.getMatchingMark(a);
211
+ s && r.push(this.renderClosingTag(s.tag));
218
212
  }), r.join("");
219
213
  }
220
214
  renderTag(e, r) {
@@ -222,13 +216,13 @@ class re {
222
216
  if (o.constructor === String)
223
217
  return `<${o}${r}>`;
224
218
  {
225
- let s = `<${o.tag}`;
219
+ let a = `<${o.tag}`;
226
220
  if (o.attrs)
227
- for (const n in o.attrs) {
228
- const a = o.attrs[n];
229
- a !== null && (s += ` ${n}="${a}"`);
221
+ for (const s in o.attrs) {
222
+ const i = o.attrs[s];
223
+ i !== null && (a += ` ${s}="${i}"`);
230
224
  }
231
- return `${s}${r}>`;
225
+ return `${a}${r}>`;
232
226
  }
233
227
  }).join("");
234
228
  }
@@ -249,39 +243,43 @@ class re {
249
243
  return r(e);
250
244
  }
251
245
  }
252
- var le = (t) => {
246
+ const oe = (t) => {
253
247
  if (typeof t != "object" || typeof t._editable > "u")
254
248
  return {};
255
- const e = JSON.parse(t._editable.replace(/^<!--#storyblok#/, "").replace(/-->$/, ""));
249
+ const e = JSON.parse(
250
+ t._editable.replace(/^<!--#storyblok#/, "").replace(/-->$/, "")
251
+ );
256
252
  return {
257
253
  "data-blok-c": JSON.stringify(e),
258
254
  "data-blok-uid": e.id + "-" + e.uid
259
255
  };
260
256
  };
261
- let oe;
262
- const se = "https://app.storyblok.com/f/storyblok-v2-latest.js", ne = (t, e) => {
257
+ let X;
258
+ const ee = "https://app.storyblok.com/f/storyblok-v2-latest.js", te = (t, e) => {
263
259
  t.addNode("blok", (r) => {
264
260
  let o = "";
265
- return r.attrs.body.forEach((s) => {
266
- o += e(s.component, s);
261
+ return r.attrs.body.forEach((a) => {
262
+ o += e(a.component, a);
267
263
  }), {
268
264
  html: o
269
265
  };
270
266
  });
271
- }, ae = (t, e, r) => {
272
- let o = r || oe;
267
+ }, re = (t, e, r) => {
268
+ let o = r || X;
273
269
  if (!o) {
274
- console.error("Please initialize the Storyblok SDK before calling the renderRichText function");
270
+ console.error(
271
+ "Please initialize the Storyblok SDK before calling the renderRichText function"
272
+ );
275
273
  return;
276
274
  }
277
- return t === "" ? "" : t ? (e && (o = new re(e.schema), e.resolver && ne(o, e.resolver)), o.render(t)) : (console.warn(`${t} is not a valid Richtext object. This might be because the value of the richtext field is empty.
275
+ return t === "" ? "" : t ? (e && (o = new Z(e.schema), e.resolver && te(o, e.resolver)), o.render(t)) : (console.warn(`${t} is not a valid Richtext object. This might be because the value of the richtext field is empty.
278
276
 
279
277
  For more info about the richtext object check https://github.com/storyblok/storyblok-js#rendering-rich-text`), "");
280
- }, ie = () => $(se);
281
- function ce() {
278
+ }, se = () => S(ee);
279
+ function ae() {
282
280
  return globalThis.storyblokApiInstance || console.error("storyblokApiInstance has not been initialized correctly"), globalThis.storyblokApiInstance;
283
281
  }
284
- function ue(t, e) {
282
+ function ne(t, e) {
285
283
  const r = globalThis.storyblokApiInstance.richTextResolver;
286
284
  if (!r) {
287
285
  console.error(
@@ -289,37 +287,36 @@ function ue(t, e) {
289
287
  );
290
288
  return;
291
289
  }
292
- return ae(t, e, r);
290
+ return re(t, e, r);
293
291
  }
294
- function de(t = {
295
- accessToken: "",
296
- useCustomApi: !1,
297
- apiOptions: {},
298
- bridge: !0,
299
- components: {}
300
- }) {
292
+ function le(t) {
293
+ const e = {
294
+ useCustomApi: !1,
295
+ bridge: !0,
296
+ ...t
297
+ };
301
298
  return {
302
299
  name: "@storyblok/astro",
303
300
  hooks: {
304
- "astro:config:setup": ({ injectScript: e, updateConfig: r }) => {
305
- r({
301
+ "astro:config:setup": ({ injectScript: r, updateConfig: o }) => {
302
+ o({
306
303
  vite: {
307
304
  plugins: [
308
- k(
309
- t.accessToken,
310
- t.useCustomApi,
311
- t.apiOptions
305
+ m(
306
+ e.accessToken,
307
+ e.useCustomApi,
308
+ e.apiOptions
312
309
  ),
313
- S(t.components)
310
+ w(e.components)
314
311
  ]
315
312
  }
316
- }), e(
313
+ }), r(
317
314
  "page-ssr",
318
315
  `
319
316
  import { storyblokApiInstance } from "virtual:storyblok-init";
320
317
  globalThis.storyblokApiInstance = storyblokApiInstance;
321
318
  `
322
- ), t.bridge && e(
319
+ ), e.bridge && r(
323
320
  "page",
324
321
  `
325
322
  import { loadStoryblokBridge } from "@storyblok/astro";
@@ -340,11 +337,11 @@ function de(t = {
340
337
  };
341
338
  }
342
339
  export {
343
- re as RichTextResolver,
344
- ee as RichTextSchema,
345
- de as default,
346
- ie as loadStoryblokBridge,
347
- ue as renderRichText,
348
- le as storyblokEditable,
349
- ce as useStoryblokApi
340
+ Z as RichTextResolver,
341
+ Q as RichTextSchema,
342
+ le as default,
343
+ se as loadStoryblokBridge,
344
+ ne as renderRichText,
345
+ oe as storyblokEditable,
346
+ ae as useStoryblokApi
350
347
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@storyblok/astro",
3
- "version": "2.0.2",
3
+ "version": "2.0.4",
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",
@@ -28,19 +28,19 @@
28
28
  "prepublishOnly": "npm run build && cp ../README.md ./"
29
29
  },
30
30
  "dependencies": {
31
- "@storyblok/js": "^2.0.5",
32
- "camelcase": "^7.0.0"
31
+ "@storyblok/js": "^2.0.9",
32
+ "camelcase": "^7.0.1"
33
33
  },
34
34
  "devDependencies": {
35
35
  "@cypress/vite-dev-server": "^5.0.2",
36
- "@rollup/plugin-dynamic-import-vars": "^2.0.1",
37
- "@types/node": "18.11.10",
38
- "astro": "1.6.15",
39
- "cypress": "^12.1.0",
36
+ "@rollup/plugin-dynamic-import-vars": "^2.0.2",
37
+ "@types/node": "18.11.18",
38
+ "astro": "1.9.2",
39
+ "cypress": "^12.3.0",
40
40
  "eslint-plugin-cypress": "^2.12.1",
41
41
  "start-server-and-test": "^1.15.2",
42
42
  "typescript": "4.9.4",
43
- "vite": "^4.0.1",
43
+ "vite": "^4.0.4",
44
44
  "vite-plugin-dts": "^1.7.1"
45
45
  },
46
46
  "repository": {