@storyblok/astro 6.1.0 → 6.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 +27 -1
- package/dist/index.d.ts +1 -1
- package/dist/storyblok-astro.es.js +547 -315
- package/dist/storyblok-astro.umd.js +12 -12
- package/package.json +4 -2
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(function(
|
|
1
|
+
(function(m,L){typeof exports=="object"&&typeof module<"u"?L(exports):typeof define=="function"&&define.amd?define(["exports"],L):(m=typeof globalThis<"u"?globalThis:m||self,L(m.storyblokAstro={}))})(this,function(m){"use strict";const L=`<svg width="45px" height="53px" viewBox="0 0 45 53" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
|
|
2
2
|
<g id="storyblok-logo-kit" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
|
|
3
3
|
<g id="storyblok-partner-logo" transform="translate(-59.000000, -169.000000)" fill-rule="nonzero">
|
|
4
4
|
<g id="storyblok-symbol" transform="translate(59.000000, 169.000000)">
|
|
@@ -7,17 +7,17 @@
|
|
|
7
7
|
</g>
|
|
8
8
|
</g>
|
|
9
9
|
</g>
|
|
10
|
-
</svg>`,
|
|
10
|
+
</svg>`,W=/[\p{Lu}]/u,Y=/[\p{Ll}]/u,P=/^[\p{Lu}](?![\p{Lu}])/gu,B=/([\p{Alpha}\p{N}_]|$)/u,x=/[_.\- ]+/,V=new RegExp("^"+x.source),D=new RegExp(x.source+B.source,"gu"),U=new RegExp("\\d+"+B.source,"gu"),X=(r,e,t,o)=>{let n=!1,s=!1,l=!1,d=!1;for(let i=0;i<r.length;i++){const p=r[i];d=i>2?r[i-3]==="-":!0,n&&W.test(p)?(r=r.slice(0,i)+"-"+r.slice(i),n=!1,l=s,s=!0,i++):s&&l&&Y.test(p)&&(!d||o)?(r=r.slice(0,i-1)+"-"+r.slice(i-1),l=s,s=!1,n=!0):(n=e(p)===p&&t(p)!==p,l=s,s=t(p)===p&&e(p)!==p)}return r},Z=(r,e)=>(P.lastIndex=0,r.replaceAll(P,t=>e(t))),Q=(r,e)=>(D.lastIndex=0,U.lastIndex=0,r.replaceAll(U,(t,o,n)=>["_","-"].includes(r.charAt(n+t.length))?t:e(t)).replaceAll(D,(t,o)=>e(o)));function ee(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?x.test(r)?"":e.pascalCase?o(r):t(r):(r!==t(r)&&(r=X(r,t,o,e.preserveConsecutiveUppercase)),r=r.replace(V,""),r=e.preserveConsecutiveUppercase?Z(r,t):t(r),e.pascalCase&&(r=o(r.charAt(0))+r.slice(1)),Q(r,o))}function _(r){return ee(r)}function te(r,e={},t,o){const n="virtual:storyblok-components",s=`\0${n}`;return{name:"vite-plugin-storyblok-components",async resolveId(l){if(l===n)return s},async load(l){if(l===s){const d=[],i=[];for await(const[g,w]of Object.entries(e)){const C=await this.resolve(`/${r}/${w}.astro`);if(C)d.push(`import ${_(g)} from "${C.id}"`);else if(t)i.push(g);else throw new Error(`Component could not be found for blok "${g}"! Does "${`/${r}/${w}`}.astro" exist?`)}let p="";if(t)if(p=",FallbackComponent",o){const g=await this.resolve(`/${r}/${o}.astro`);if(!g)throw new Error(`Custom fallback component could not be found. Does "${`/${r}/${o}`}.astro" exist?`);d.push(`import FallbackComponent from "${g.id}"`)}else d.push("import FallbackComponent from '@storyblok/astro/FallbackComponent.astro'");if(Object.values(e).length)return`${d.join(";")};export default {${Object.keys(e).filter(g=>!i.includes(g)).map(g=>_(g)).join(",")}${p}}`;if(t)return`${d[0]}; export default {${p.replace(",","")}}`;throw new Error(`Currently, no Storyblok components are registered in astro.config.mjs.
|
|
11
11
|
Please register your components or enable the fallback component.
|
|
12
|
-
Detailed information can be found here: https://github.com/storyblok/storyblok-astro`)}}}}function
|
|
12
|
+
Detailed information can be found here: https://github.com/storyblok/storyblok-astro`)}}}}function re(r,e,t){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`
|
|
13
13
|
import { storyblokInit, apiPlugin } from "@storyblok/js";
|
|
14
14
|
const { storyblokApi } = storyblokInit({
|
|
15
15
|
accessToken: "${r}",
|
|
16
|
-
use: ${
|
|
17
|
-
apiOptions: ${JSON.stringify(
|
|
16
|
+
use: ${e?"[]":"[apiPlugin]"},
|
|
17
|
+
apiOptions: ${JSON.stringify(t)},
|
|
18
18
|
});
|
|
19
19
|
export const storyblokApiInstance = storyblokApi;
|
|
20
|
-
`}}}function
|
|
20
|
+
`}}}function oe(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 z=!1;const H=[],se=r=>new Promise((e,t)=>{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}z?n():H.push(n)},document.getElementById("storyblok-javascript-bridge")))return;const o=document.createElement("script");o.async=!0,o.src=r,o.id="storyblok-javascript-bridge",o.onerror=n=>t(n),o.onload=n=>{H.forEach(s=>s()),z=!0,e(n)},document.getElementsByTagName("head")[0].appendChild(o)});var ne=Object.defineProperty,ae=(r,e,t)=>e in r?ne(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,S=(r,e,t)=>ae(r,typeof e!="symbol"?e+"":e,t);class le{constructor(){S(this,"isCDNUrl",(e="")=>e.includes("/cdn/")),S(this,"getOptionsPage",(e,t=25,o=1)=>({...e,per_page:t,page:o})),S(this,"delay",e=>new Promise(t=>setTimeout(t,e))),S(this,"arrayFrom",(e=0,t)=>Array.from({length:e},t)),S(this,"range",(e=0,t=e)=>{const o=Math.abs(t-e)||0,n=e<t?1:-1;return this.arrayFrom(o,(s,l)=>l*n+e)}),S(this,"asyncMap",async(e,t)=>Promise.all(e.map(t))),S(this,"flatMap",(e=[],t)=>e.map(t).reduce((o,n)=>[...o,...n],[])),S(this,"escapeHTML",function(e){const t={"&":"&","<":"<",">":">",'"':""","'":"'"},o=/[&<>"']/g,n=new RegExp(o.source);return e&&n.test(e)?e.replace(o,s=>t[s]):e})}stringify(e,t,o){const n=[];for(const s in e){if(!Object.prototype.hasOwnProperty.call(e,s))continue;const l=e[s],d=o?"":encodeURIComponent(s);let i;typeof l=="object"?i=this.stringify(l,t?t+encodeURIComponent(`[${d}]`):d,Array.isArray(l)):i=`${t?t+encodeURIComponent(`[${d}]`):d}=${encodeURIComponent(l)}`,n.push(i)}return n.join("&")}getRegionURL(e){const t="api.storyblok.com",o="api-us.storyblok.com",n="app.storyblokchina.cn",s="api-ap.storyblok.com",l="api-ca.storyblok.com";switch(e){case"us":return o;case"cn":return n;case"ap":return s;case"ca":return l;default:return t}}}const ie=function(r,e){const t={};for(const o in r){const n=r[o];e.includes(o)&&n!==null&&(t[o]=n)}return t},ce=r=>r==="email",ue=()=>({singleTag:"hr"}),de=()=>({tag:"blockquote"}),pe=()=>({tag:"ul"}),ge=r=>({tag:["pre",{tag:"code",attrs:r.attrs}]}),he=()=>({singleTag:"br"}),fe=r=>({tag:`h${r.attrs.level}`}),be=r=>({singleTag:[{tag:"img",attrs:ie(r.attrs,["src","alt","title"])}]}),ye=()=>({tag:"li"}),me=()=>({tag:"ol"}),ke=()=>({tag:"p"}),$e=r=>({tag:[{tag:"span",attrs:{"data-type":"emoji","data-name":r.attrs.name,emoji:r.attrs.emoji}}]}),we=()=>({tag:"b"}),Te=()=>({tag:"s"}),Ee=()=>({tag:"u"}),Ce=()=>({tag:"strong"}),ve=()=>({tag:"code"}),Se=()=>({tag:"i"}),Ie=r=>{if(!r.attrs)return{tag:""};const e=new le().escapeHTML,t={...r.attrs},{linktype:o="url"}=r.attrs;if(delete t.linktype,t.href&&(t.href=e(r.attrs.href||"")),ce(o)&&(t.href=`mailto:${t.href}`),t.anchor&&(t.href=`${t.href}#${t.anchor}`,delete t.anchor),t.custom){for(const n in t.custom)t[n]=t.custom[n];delete t.custom}return{tag:[{tag:"a",attrs:t}]}},Le=r=>({tag:[{tag:"span",attrs:r.attrs}]}),Ae=()=>({tag:"sub"}),Re=()=>({tag:"sup"}),je=r=>({tag:[{tag:"span",attrs:r.attrs}]}),Oe=r=>{var e;return(e=r.attrs)!=null&&e.color?{tag:[{tag:"span",attrs:{style:`background-color:${r.attrs.color};`}}]}:{tag:""}},xe=r=>{var e;return(e=r.attrs)!=null&&e.color?{tag:[{tag:"span",attrs:{style:`color:${r.attrs.color}`}}]}:{tag:""}},F={nodes:{horizontal_rule:ue,blockquote:de,bullet_list:pe,code_block:ge,hard_break:he,heading:fe,image:be,list_item:ye,ordered_list:me,paragraph:ke,emoji:$e},marks:{bold:we,strike:Te,underline:Ee,strong:Ce,code:ve,italic:Se,link:Ie,styled:Le,subscript:Ae,superscript:Re,anchor:je,highlight:Oe,textStyle:xe}},_e=function(r){const e={"&":"&","<":"<",">":">",'"':""","'":"'"},t=/[&<>"']/g,o=new RegExp(t.source);return r&&o.test(r)?r.replace(t,n=>e[n]):r};let q=!1;class G{constructor(e){S(this,"marks"),S(this,"nodes"),e||(e=F),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},o=!0){if(!q&&o&&(console.warn("Warning ⚠️: The RichTextResolver class is deprecated and will be removed in the next major release. Please use the `@storyblok/richtext` package instead. https://github.com/storyblok/richtext/"),q=!0),e&&e.content&&Array.isArray(e.content)){let n="";return e.content.forEach(s=>{n+=this.renderNode(s)}),t.optimizeImages?this.optimizeImages(n,t.optimizeImages):n}return console.warn(`The render method must receive an Object with a "content" field.
|
|
21
21
|
The "content" field must be an array of nodes as the type ISbRichtext.
|
|
22
22
|
ISbRichtext:
|
|
23
23
|
content?: ISbRichtext[]
|
|
@@ -40,23 +40,23 @@ Detailed information can be found here: https://github.com/storyblok/storyblok-a
|
|
|
40
40
|
}
|
|
41
41
|
],
|
|
42
42
|
type: 'doc'
|
|
43
|
-
}`),""}optimizeImages(t,e){let o=0,s=0,n="",a="";typeof e!="boolean"&&(typeof e.width=="number"&&e.width>0&&(n+=`width="${e.width}" `,o=e.width),typeof e.height=="number"&&e.height>0&&(n+=`height="${e.height}" `,s=e.height),(e.loading==="lazy"||e.loading==="eager")&&(n+=`loading="${e.loading}" `),typeof e.class=="string"&&e.class.length>0&&(n+=`class="${e.class}" `),e.filters&&(typeof e.filters.blur=="number"&&e.filters.blur>=0&&e.filters.blur<=100&&(a+=`:blur(${e.filters.blur})`),typeof e.filters.brightness=="number"&&e.filters.brightness>=-100&&e.filters.brightness<=100&&(a+=`:brightness(${e.filters.brightness})`),e.filters.fill&&(e.filters.fill.match(/[0-9A-F]{6}/gi)||e.filters.fill==="transparent")&&(a+=`:fill(${e.filters.fill})`),e.filters.format&&["webp","png","jpeg"].includes(e.filters.format)&&(a+=`:format(${e.filters.format})`),typeof e.filters.grayscale=="boolean"&&e.filters.grayscale&&(a+=":grayscale()"),typeof e.filters.quality=="number"&&e.filters.quality>=0&&e.filters.quality<=100&&(a+=`:quality(${e.filters.quality})`),e.filters.rotate&&[90,180,270].includes(e.filters.rotate)&&(a+=`:rotate(${e.filters.rotate})`),a.length>0&&(a=`/filters${a}`))),n.length>0&&(t=t.replace(/<img/g,`<img ${n.trim()}`));const l=o>0||s>0||a.length>0?`${o}x${s}${a}`:"";return t=t.replace(/a.storyblok.com\/f\/(\d+)\/([^.]+)\.(gif|jpg|jpeg|png|tif|bmp)/g,`a.storyblok.com/f/$1/$2.$3/m/${l}`),typeof e!="boolean"&&(e.sizes||e.srcset)&&(t=t.replace(/<img.*?src=["|'](.*?)["|']/g,i=>{var c,d;const f=i.match(/a.storyblok.com\/f\/(\d+)\/([^.]+)\.(gif|jpg|jpeg|png|tif|bmp)/g);if(f&&f.length>0){const h={srcset:(c=e.srcset)==null?void 0:c.map(g=>{if(typeof g=="number")return`//${f}/m/${g}x0${a} ${g}w`;if(typeof g=="object"&&g.length===2){let w=0,j=0;return typeof g[0]=="number"&&(w=g[0]),typeof g[1]=="number"&&(j=g[1]),`//${f}/m/${w}x${j}${a} ${w}w`}return""}).join(", "),sizes:(d=e.sizes)==null?void 0:d.map(g=>g).join(", ")};let k="";return h.srcset&&(k+=`srcset="${h.srcset}" `),h.sizes&&(k+=`sizes="${h.sizes}" `),i.replace(/<img/g,`<img ${k.trim()}`)}return i})),t}renderNode(t){const e=[];t.marks&&t.marks.forEach(s=>{const n=this.getMatchingMark(s);n&&n.tag!==""&&e.push(this.renderOpeningTag(n.tag))});const o=this.getMatchingNode(t);return o&&o.tag&&e.push(this.renderOpeningTag(o.tag)),t.content?t.content.forEach(s=>{e.push(this.renderNode(s))}):t.text?e.push(me(t.text)):o&&o.singleTag?e.push(this.renderTag(o.singleTag," /")):o&&o.html?e.push(o.html):t.type==="emoji"&&e.push(this.renderEmoji(t)),o&&o.tag&&e.push(this.renderClosingTag(o.tag)),t.marks&&t.marks.slice(0).reverse().forEach(s=>{const n=this.getMatchingMark(s);n&&n.tag!==""&&e.push(this.renderClosingTag(n.tag))}),e.join("")}renderTag(t,e){return t.constructor===String?`<${t}${e}>`:t.map(o=>{if(o.constructor===String)return`<${o}${e}>`;{let s=`<${o.tag}`;if(o.attrs){for(const n in o.attrs)if(Object.prototype.hasOwnProperty.call(o.attrs,n)){const a=o.attrs[n];a!==null&&(s+=` ${n}="${a}"`)}}return`${s}${e}>`}}).join("")}renderOpeningTag(t){return this.renderTag(t,"")}renderClosingTag(t){return t.constructor===String?`</${t}>`:t.slice(0).reverse().map(e=>e.constructor===String?`</${e}>`:`</${e.tag}>`).join("")}getMatchingNode(t){const e=this.nodes[t.type];if(typeof e=="function")return e(t)}getMatchingMark(t){const e=this.marks[t.type];if(typeof e=="function")return e(t)}renderEmoji(t){if(t.attrs.emoji)return t.attrs.emoji;const e=[{tag:"img",attrs:{src:t.attrs.fallbackImage,draggable:"false",loading:"lazy",align:"absmiddle"}}];return this.renderTag(e," /")}}const ke=r=>{if(typeof r!="object"||typeof r._editable>"u")return{};try{const t=JSON.parse(r._editable.replace(/^<!--#storyblok#/,"").replace(/-->$/,""));return t?{"data-blok-c":JSON.stringify(t),"data-blok-uid":`${t.id}-${t.uid}`}:{}}catch{return{}}};let we,$e="https://app.storyblok.com/f/storyblok-v2-latest.js";const ve=(r,t)=>{r.addNode("blok",e=>{let o="";return e.attrs.body.forEach(s=>{o+=t(s.component,s)}),{html:o}})},Ce=r=>{var t;return!r||!((t=r==null?void 0:r.content)!=null&&t.some(e=>e.content||e.type==="blok"||e.type==="horizontal_rule"))},Se=(r,t,e)=>{let o=e||we;if(!o){console.error("Please initialize the Storyblok SDK before calling the renderRichText function");return}return Ce(r)?"":(t&&(o=new L(t.schema),t.resolver&&ve(o,t.resolver)),o.render(r,{},!1))},Ie=()=>U($e);function Ae(){if(!(globalThis!=null&&globalThis.storyblokApiInstance))throw new Error("storyblokApiInstance has not been initialized correctly");return globalThis.storyblokApiInstance}async function Te(r){let t=null;return r&&r.locals._storyblok_preview_data&&(t=r.locals._storyblok_preview_data),t}function Ee(r,t){var o;const e=(o=globalThis==null?void 0:globalThis.storyblokApiInstance)==null?void 0:o.richTextResolver;if(!e)throw new Error("Please initialize the Storyblok SDK before calling the renderRichText function");return Se(r,t,e)}function Le(r){return typeof r=="object"?`const storyblokInstance = new StoryblokBridge(${JSON.stringify(r)});`:"const storyblokInstance = new StoryblokBridge();"}function xe(r){const t={useCustomApi:!1,bridge:!0,componentsDir:"src",enableFallbackComponent:!1,livePreview:!1,...r},e=Le(t.bridge);return{name:"@storyblok/astro",hooks:{"astro:config:setup":({injectScript:o,updateConfig:s,addDevToolbarApp:n,addMiddleware:a,config:l})=>{if(s({vite:{plugins:[D(t.accessToken,t.useCustomApi,t.apiOptions),B(t.componentsDir,t.components,t.enableFallbackComponent,t.customFallbackComponent),F(t)]}}),t.livePreview&&(l==null?void 0:l.output)!=="server")throw new Error("To utilize the Astro Storyblok Live feature, Astro must be configured to run in SSR mode. Please disable this feature or switch Astro to SSR mode.");o("page-ssr",`
|
|
43
|
+
}`),""}optimizeImages(e,t){let o=0,n=0,s="",l="";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}" `,n=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&&(l+=`:blur(${t.filters.blur})`),typeof t.filters.brightness=="number"&&t.filters.brightness>=-100&&t.filters.brightness<=100&&(l+=`:brightness(${t.filters.brightness})`),t.filters.fill&&(t.filters.fill.match(/[0-9A-F]{6}/gi)||t.filters.fill==="transparent")&&(l+=`:fill(${t.filters.fill})`),t.filters.format&&["webp","png","jpeg"].includes(t.filters.format)&&(l+=`:format(${t.filters.format})`),typeof t.filters.grayscale=="boolean"&&t.filters.grayscale&&(l+=":grayscale()"),typeof t.filters.quality=="number"&&t.filters.quality>=0&&t.filters.quality<=100&&(l+=`:quality(${t.filters.quality})`),t.filters.rotate&&[90,180,270].includes(t.filters.rotate)&&(l+=`:rotate(${t.filters.rotate})`),l.length>0&&(l=`/filters${l}`))),s.length>0&&(e=e.replace(/<img/g,`<img ${s.trim()}`));const d=o>0||n>0||l.length>0?`${o}x${n}${l}`:"";return e=e.replace(/a.storyblok.com\/f\/(\d+)\/([^.]+)\.(gif|jpg|jpeg|png|tif|bmp)/g,`a.storyblok.com/f/$1/$2.$3/m/${d}`),typeof t!="boolean"&&(t.sizes||t.srcset)&&(e=e.replace(/<img.*?src=["|'](.*?)["|']/g,i=>{var p,g;const w=i.match(/a.storyblok.com\/f\/(\d+)\/([^.]+)\.(gif|jpg|jpeg|png|tif|bmp)/g);if(w&&w.length>0){const C={srcset:(p=t.srcset)==null?void 0:p.map(k=>{if(typeof k=="number")return`//${w}/m/${k}x0${l} ${k}w`;if(typeof k=="object"&&k.length===2){let I=0,R=0;return typeof k[0]=="number"&&(I=k[0]),typeof k[1]=="number"&&(R=k[1]),`//${w}/m/${I}x${R}${l} ${I}w`}return""}).join(", "),sizes:(g=t.sizes)==null?void 0:g.map(k=>k).join(", ")};let T="";return C.srcset&&(T+=`srcset="${C.srcset}" `),C.sizes&&(T+=`sizes="${C.sizes}" `),i.replace(/<img/g,`<img ${T.trim()}`)}return i})),e}renderNode(e){const t=[];e.marks&&e.marks.forEach(n=>{const s=this.getMatchingMark(n);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(n=>{t.push(this.renderNode(n))}):e.text?t.push(_e(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(n=>{const s=this.getMatchingMark(n);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 n=`<${o.tag}`;if(o.attrs){for(const s in o.attrs)if(Object.prototype.hasOwnProperty.call(o.attrs,s)){const l=o.attrs[s];l!==null&&(n+=` ${s}="${l}"`)}}return`${n}${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 Me=r=>{if(typeof r!="object"||typeof r._editable>"u")return{};try{const e=JSON.parse(r._editable.replace(/^<!--#storyblok#/,"").replace(/-->$/,""));return e?{"data-blok-c":JSON.stringify(e),"data-blok-uid":`${e.id}-${e.uid}`}:{}}catch{return{}}};function Ne(r,e){if(!e)return{src:r,attrs:{}};let t=0,o=0;const n={},s=[];function l(i,p,g,w,C){typeof i!="number"||i<=p||i>=g?console.warn(`[StoryblokRichText] - ${w.charAt(0).toUpperCase()+w.slice(1)} value must be a number between ${p} and ${g} (inclusive)`):C.push(`${w}(${i})`)}if(typeof e=="object"){if(typeof e.width=="number"&&e.width>0?(n.width=e.width,t=e.width):console.warn("[StoryblokRichText] - Width value must be a number greater than 0"),e.height&&typeof e.height=="number"&&e.height>0?(n.height=e.height,o=e.height):console.warn("[StoryblokRichText] - Height value must be a number greater than 0"),e.loading&&["lazy","eager"].includes(e.loading)&&(n.loading=e.loading),e.class&&(n.class=e.class),e.filters){const{filters:i}=e||{},{blur:p,brightness:g,fill:w,format:C,grayscale:T,quality:k,rotate:I}=i||{};p&&l(p,0,100,"blur",s),k&&l(k,0,100,"quality",s),g&&l(g,0,100,"brightness",s),w&&s.push(`fill(${w})`),T&&s.push("grayscale()"),I&&[0,90,180,270].includes(e.filters.rotate||0)&&s.push(`rotate(${I})`),C&&["webp","png","jpeg"].includes(C)&&s.push(`format(${C})`)}e.srcset&&(n.srcset=e.srcset.map(i=>{if(typeof i=="number")return`${r}/m/${i}x0/${s.length>0?`filters:${s.join(":")}`:""} ${i}w`;if(Array.isArray(i)&&i.length===2){const[p,g]=i;return`${r}/m/${p}x${g}/${s.length>0?`filters:${s.join(":")}`:""} ${p}w`}else{console.warn("[StoryblokRichText] - srcset entry must be a number or a tuple of two numbers");return}}).join(", ")),e.sizes&&(n.sizes=e.sizes.join(", "))}let d=`${r}/m/`;return t>0&&o>0&&(d=`${d}${t}x${o}/`),s.length>0&&(d=`${d}filters:${s.join(":")}`),{src:d,attrs:n}}var b=(r=>(r.DOCUMENT="doc",r.HEADING="heading",r.PARAGRAPH="paragraph",r.QUOTE="blockquote",r.OL_LIST="ordered_list",r.UL_LIST="bullet_list",r.LIST_ITEM="list_item",r.CODE_BLOCK="code_block",r.HR="horizontal_rule",r.BR="hard_break",r.IMAGE="image",r.EMOJI="emoji",r.COMPONENT="blok",r.TABLE="table",r.TABLE_ROW="tableRow",r.TABLE_CELL="tableCell",r.TABLE_HEADER="tableHeader",r))(b||{}),v=(r=>(r.BOLD="bold",r.STRONG="strong",r.STRIKE="strike",r.UNDERLINE="underline",r.ITALIC="italic",r.CODE="code",r.LINK="link",r.ANCHOR="anchor",r.STYLED="styled",r.SUPERSCRIPT="superscript",r.SUBSCRIPT="subscript",r.TEXT_STYLE="textStyle",r.HIGHLIGHT="highlight",r))(v||{}),M=(r=>(r.TEXT="text",r))(M||{}),A=(r=>(r.URL="url",r.STORY="story",r.ASSET="asset",r.EMAIL="email",r))(A||{});const Pe=["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"],Be=(r={})=>Object.keys(r).map(e=>`${e}="${r[e]}"`).join(" "),De=(r={})=>Object.keys(r).map(e=>`${e}: ${r[e]}`).join("; ");function Ue(r){return r.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}const j=r=>Object.fromEntries(Object.entries(r).filter(([e,t])=>t!==void 0));function K(r,e={},t){const o=Be(e),n=o?`${r} ${o}`:r,s=Array.isArray(t)?t.join(""):t||"";if(r){if(Pe.includes(r))return`<${n}>`}else return s;return`<${n}>${s}</${r}>`}function ze(r={}){let e=0;const{renderFn:t=K,textFn:o=Ue,resolvers:n={},optimizeImages:s=!1,keyedResolvers:l=!1}=r,d=t!==K,i=a=>c=>{const u=c.attrs||{};return l&&(u.key=`${a}-${e}`),t(a,u,c.children||null)},p=a=>{const{src:c,alt:u,title:f,srcset:E,sizes:y}=a.attrs||{};let h=c,$={};if(s){const{src:ct,attrs:ut}=Ne(c,s);h=ct,$=ut}l&&($={...$,key:`img-${e}`});const it={src:h,alt:u,title:f,srcset:E,sizes:y,...$};return t("img",j(it))},g=a=>{const{level:c,...u}=a.attrs||{},f={...u};return l&&(f.key=`h${c}-${e}`),t(`h${c}`,f,a.children)},w=a=>{var c,u,f,E;const y=t("img",{src:(c=a.attrs)==null?void 0:c.fallbackImage,alt:(u=a.attrs)==null?void 0:u.alt,style:"width: 1.25em; height: 1.25em; vertical-align: text-top",draggable:"false",loading:"lazy"}),h={"data-type":"emoji","data-name":(f=a.attrs)==null?void 0:f.name,"data-emoji":(E=a.attrs)==null?void 0:E.emoji};return l&&(h.key=`emoji-${e}`),t("span",h,y)},C=a=>t("pre",{...a.attrs,key:`code-${e}`},t("code",{key:`code-${e}`},a.children||"")),T=(a,c=!1)=>({text:u,attrs:f})=>{const{class:E,id:y,...h}=f||{},$=c?{class:E,id:y,style:De(h)||void 0}:f||{};return l&&($.key=`${a}-${e}`),t(a,j($),u)},k=a=>N(a),I=a=>{const{marks:c,...u}=a;return"text"in a?c?c.reduce((f,E)=>k({...E,text:f}),k({...u,children:u.children})):o(u.text):""},R=a=>{const{linktype:c,href:u,anchor:f,...E}=a.attrs||{};let y="";switch(c){case A.ASSET:case A.URL:y=u;break;case A.EMAIL:y=`mailto:${u}`;break;case A.STORY:y=u,f&&(y=`${y}#${f}`);break;default:y=u;break}const h={...E};return y&&(h.href=y),l&&(h.key=`a-${e}`),t("a",h,a.text)},rt=a=>{var c,u;return console.warn("[StoryblokRichtText] - BLOK resolver is not available for vanilla usage"),t("span",{blok:(c=a==null?void 0:a.attrs)==null?void 0:c.body[0],id:(u=a.attrs)==null?void 0:u.id,key:`component-${e}`,style:"display: none"})},ot=a=>{const c={};return l&&(c.key=`table-${e}`),t("table",c,a.children)},st=a=>{const c={};return l&&(c.key=`tr-${e}`),t("tr",c,a.children)},nt=a=>{const{colspan:c,rowspan:u,colwidth:f,backgroundColor:E,...y}=a.attrs||{},h={...y};c>1&&(h.colspan=c),u>1&&(h.rowspan=u);const $=[];return f&&$.push(`width: ${f}px;`),E&&$.push(`background-color: ${E};`),$.length>0&&(h.style=$.join(" ")),l&&(h.key=`td-${e}`),t("td",j(h),a.children)},at=a=>{const{colspan:c,rowspan:u,colwidth:f,backgroundColor:E,...y}=a.attrs||{},h={...y};c>1&&(h.colspan=c),u>1&&(h.rowspan=u);const $=[];return f&&$.push(`width: ${f}px;`),E&&$.push(`background-color: ${E};`),$.length>0&&(h.style=$.join(" ")),l&&(h.key=`th-${e}`),t("th",j(h),a.children)},lt=new Map([[b.DOCUMENT,i("")],[b.HEADING,g],[b.PARAGRAPH,i("p")],[b.UL_LIST,i("ul")],[b.OL_LIST,i("ol")],[b.LIST_ITEM,i("li")],[b.IMAGE,p],[b.EMOJI,w],[b.CODE_BLOCK,C],[b.HR,i("hr")],[b.BR,i("br")],[b.QUOTE,i("blockquote")],[b.COMPONENT,rt],[M.TEXT,I],[v.LINK,R],[v.ANCHOR,R],[v.STYLED,T("span",!0)],[v.BOLD,T("strong")],[v.TEXT_STYLE,T("span",!0)],[v.ITALIC,T("em")],[v.UNDERLINE,T("u")],[v.STRIKE,T("s")],[v.CODE,T("code")],[v.SUPERSCRIPT,T("sup")],[v.SUBSCRIPT,T("sub")],[v.HIGHLIGHT,T("mark")],[b.TABLE,ot],[b.TABLE_ROW,st],[b.TABLE_CELL,nt],[b.TABLE_HEADER,at],...Object.entries(n).map(([a,c])=>[a,c])]);function O(a){e+=1;const c=lt.get(a.type);if(!c)return console.error("<Storyblok>",`No resolver found for node type ${a.type}`),"";if(a.type==="text")return c(a);const u=a.content?a.content.map(N):void 0;return c({...a,children:u})}function N(a){return a.type==="doc"?d?a.content.map(O):a.content.map(O).join(""):Array.isArray(a)?a.map(O):O(a)}return{render:N}}let He,Fe="https://app.storyblok.com/f/storyblok-v2-latest.js";const qe=(r,e)=>{r.addNode("blok",t=>{let o="";return t.attrs.body.forEach(n=>{o+=e(n.component,n)}),{html:o}})},Ge=r=>{var e;return!r||!((e=r==null?void 0:r.content)!=null&&e.some(t=>t.content||t.type==="blok"||t.type==="horizontal_rule"))},Ke=(r,e,t)=>{let o=t||He;if(!o){console.error("Please initialize the Storyblok SDK before calling the renderRichText function");return}return Ge(r)?"":(e&&(o=new G(e.schema),e.resolver&&qe(o,e.resolver)),o.render(r,{},!1))},Je=()=>se(Fe);function We(){if(!(globalThis!=null&&globalThis.storyblokApiInstance))throw new Error("storyblokApiInstance has not been initialized correctly");return globalThis.storyblokApiInstance}async function Ye(r){let e=null;return r&&r.locals._storyblok_preview_data&&(e=r.locals._storyblok_preview_data),e}function Ve(r,e){var o;const t=(o=globalThis==null?void 0:globalThis.storyblokApiInstance)==null?void 0:o.richTextResolver;if(!t)throw new Error("Please initialize the Storyblok SDK before calling the renderRichText function");return Ke(r,e,t)}function Xe(r){return typeof r=="object"?`const storyblokInstance = new StoryblokBridge(${JSON.stringify(r)});`:"const storyblokInstance = new StoryblokBridge();"}function Ze(r){const e={useCustomApi:!1,bridge:!0,componentsDir:"src",enableFallbackComponent:!1,livePreview:!1,...r},t=Xe(e.bridge);return{name:"@storyblok/astro",hooks:{"astro:config:setup":({injectScript:o,updateConfig:n,addDevToolbarApp:s,addMiddleware:l,config:d})=>{if(n({vite:{plugins:[re(e.accessToken,e.useCustomApi,e.apiOptions),te(e.componentsDir,e.components,e.enableFallbackComponent,e.customFallbackComponent),oe(e)]}}),e.livePreview&&(d==null?void 0:d.output)!=="server")throw new Error("To utilize the Astro Storyblok Live feature, Astro must be configured to run in SSR mode. Please disable this feature or switch Astro to SSR mode.");o("page-ssr",`
|
|
44
44
|
import { storyblokApiInstance } from "virtual:storyblok-init";
|
|
45
45
|
globalThis.storyblokApiInstance = storyblokApiInstance;
|
|
46
|
-
`),
|
|
46
|
+
`),e.bridge&&!e.livePreview&&o("page",`import { loadStoryblokBridge } from "@storyblok/astro";
|
|
47
47
|
loadStoryblokBridge().then(() => {
|
|
48
48
|
const { StoryblokBridge, location } = window;
|
|
49
|
-
${
|
|
49
|
+
${t}
|
|
50
50
|
storyblokInstance.on(["published", "change"], (event) => {
|
|
51
51
|
if (!event.slugChanged) {
|
|
52
52
|
location.reload(true);
|
|
53
53
|
}
|
|
54
54
|
});
|
|
55
55
|
});
|
|
56
|
-
`),
|
|
56
|
+
`),e.livePreview&&(o("page",`import { loadStoryblokBridge, handleStoryblokMessage } from "@storyblok/astro";
|
|
57
57
|
loadStoryblokBridge().then(() => {
|
|
58
58
|
const { StoryblokBridge, location } = window;
|
|
59
|
-
${
|
|
59
|
+
${t}
|
|
60
60
|
storyblokInstance.on(["published", "change", "input"], handleStoryblokMessage);
|
|
61
61
|
});
|
|
62
|
-
`),
|
|
62
|
+
`),l({entrypoint:"@storyblok/astro/middleware.ts",order:"pre"})),s({id:"storyblok",name:"Storyblok",icon:L,entrypoint:"@storyblok/astro/toolbarApp.ts"})}}}}let J;async function Qe(r){const{action:e,story:t}=r||{};if(e==="input"&&t){const o=async()=>{const s=await tt(t),l=document.body;if(s.outerHTML===l.outerHTML)return;const d=document.querySelector('[data-blok-focused="true"]');et(l,s,d),document.dispatchEvent(new Event("storyblok-live-preview-updated"))};clearTimeout(J),J=setTimeout(o,500)}["published","change"].includes(r==null?void 0:r.action)&&location.reload()}function et(r,e,t){if(t){const o=t.getAttribute("data-blok-uid"),n=e.querySelector(`[data-blok-uid="${o}"]`);n&&(n.setAttribute("data-blok-focused","true"),t.replaceWith(n))}else r.replaceWith(e)}async function tt(r){const t=await(await fetch(location.href,{method:"POST",body:JSON.stringify({...r,is_storyblok_preview:!0}),headers:{"Content-Type":"application/json"}})).text();return new DOMParser().parseFromString(t,"text/html").body}m.RichTextResolver=G,m.RichTextSchema=F,m.TextTypes=M,m.getLiveStory=Ye,m.handleStoryblokMessage=Qe,m.loadStoryblokBridge=Je,m.renderRichText=Ve,m.richTextResolver=ze,m.storyblok=Ze,m.storyblokEditable=Me,m.toCamelCase=_,m.useStoryblokApi=We,Object.defineProperty(m,Symbol.toStringTag,{value:"Module"})});
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@storyblok/astro",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "6.1.
|
|
4
|
+
"version": "6.1.1",
|
|
5
5
|
"private": false,
|
|
6
6
|
"packageManager": "pnpm@9.13.2",
|
|
7
7
|
"description": "Official Astro integration for the Storyblok Headless CMS",
|
|
@@ -66,7 +66,8 @@
|
|
|
66
66
|
"test:e2e": "start-server-and-test playground:test http://localhost:4321/ cy:run",
|
|
67
67
|
"test:e2e-watch": "start-server-and-test playground:test http://localhost:4321/ cy:open",
|
|
68
68
|
"cy:run": "cypress run",
|
|
69
|
-
"cy:open": "cypress open"
|
|
69
|
+
"cy:open": "cypress open",
|
|
70
|
+
"check-licenses": "node scripts/license-checker.mjs"
|
|
70
71
|
},
|
|
71
72
|
"peerDependencies": {
|
|
72
73
|
"astro": "^3.0.0 || ^4.0.0 || ^5.0.0"
|
|
@@ -89,6 +90,7 @@
|
|
|
89
90
|
"eslint-config-prettier": "^9.1.0",
|
|
90
91
|
"eslint-plugin-astro": "^1.3.1",
|
|
91
92
|
"eslint-plugin-cypress": "^4.1.0",
|
|
93
|
+
"license-checker": "^25.0.1",
|
|
92
94
|
"lint-staged": "^15.2.10",
|
|
93
95
|
"prettier": "^3.3.3",
|
|
94
96
|
"prettier-plugin-astro": "^0.13.0",
|