@storyblok/astro 6.2.0 → 7.0.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 +2 -49
- package/dist/index.d.ts +2 -2
- package/dist/lib/helpers.d.ts +2 -3
- package/dist/storyblok-astro.es.js +403 -796
- package/dist/storyblok-astro.umd.js +12 -35
- package/dist/types.d.ts +3 -4
- package/package.json +42 -59
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(function(
|
|
1
|
+
(function(w,$){typeof exports=="object"&&typeof module<"u"?$(exports):typeof define=="function"&&define.amd?define(["exports"],$):(w=typeof globalThis<"u"?globalThis:w||self,$(w.storyblokAstro={}))})(this,function(w){"use strict";const $=`<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,56 +7,33 @@
|
|
|
7
7
|
</g>
|
|
8
8
|
</g>
|
|
9
9
|
</g>
|
|
10
|
-
</svg>`,
|
|
10
|
+
</svg>`,W=/[\p{Lu}]/u,Y=/[\p{Ll}]/u,B=/^[\p{Lu}](?![\p{Lu}])/gu,N=/([\p{Alpha}\p{N}_]|$)/u,x=/[_.\- ]+/,V=new RegExp("^"+x.source),j=new RegExp(x.source+N.source,"gu"),P=new RegExp("\\d+"+N.source,"gu"),X=(e,t,s,n)=>{let l=!1,r=!1,b=!1,p=!1;for(let i=0;i<e.length;i++){const u=e[i];p=i>2?e[i-3]==="-":!0,l&&W.test(u)?(e=e.slice(0,i)+"-"+e.slice(i),l=!1,b=r,r=!0,i++):r&&b&&Y.test(u)&&(!p||n)?(e=e.slice(0,i-1)+"-"+e.slice(i-1),b=r,r=!1,l=!0):(l=t(u)===u&&s(u)!==u,b=r,r=s(u)===u&&t(u)!==u)}return e},Z=(e,t)=>(B.lastIndex=0,e.replaceAll(B,s=>t(s))),Q=(e,t)=>(j.lastIndex=0,P.lastIndex=0,e.replaceAll(P,(s,n,l)=>["_","-"].includes(e.charAt(l+s.length))?s:t(s)).replaceAll(j,(s,n)=>t(n)));function ee(e,t){if(!(typeof e=="string"||Array.isArray(e)))throw new TypeError("Expected the input to be `string | string[]`");if(t={pascalCase:!1,preserveConsecutiveUppercase:!1,...t},Array.isArray(e)?e=e.map(r=>r.trim()).filter(r=>r.length).join("-"):e=e.trim(),e.length===0)return"";const s=t.locale===!1?r=>r.toLowerCase():r=>r.toLocaleLowerCase(t.locale),n=t.locale===!1?r=>r.toUpperCase():r=>r.toLocaleUpperCase(t.locale);return e.length===1?x.test(e)?"":t.pascalCase?n(e):s(e):(e!==s(e)&&(e=X(e,s,n,t.preserveConsecutiveUppercase)),e=e.replace(V,""),e=t.preserveConsecutiveUppercase?Z(e,s):s(e),t.pascalCase&&(e=n(e.charAt(0))+e.slice(1)),Q(e,n))}function _(e){return ee(e)}function te(e,t={},s,n){const l="virtual:storyblok-components",r=`\0${l}`;return{name:"vite-plugin-storyblok-components",async resolveId(b){if(b===l)return r},async load(b){if(b===r){const p=[],i=[];for await(const[f,L]of Object.entries(t)){const S=await this.resolve(`/${e}/${L}.astro`);if(S)p.push(`import ${_(f)} from "${S.id}"`);else if(s)i.push(f);else throw new Error(`Component could not be found for blok "${f}"! Does "${`/${e}/${L}`}.astro" exist?`)}let u="";if(s)if(u=",FallbackComponent",n){const f=await this.resolve(`/${e}/${n}.astro`);if(!f)throw new Error(`Custom fallback component could not be found. Does "${`/${e}/${n}`}.astro" exist?`);p.push(`import FallbackComponent from "${f.id}"`)}else p.push("import FallbackComponent from '@storyblok/astro/FallbackComponent.astro'");if(Object.values(t).length)return`${p.join(";")};export default {${Object.keys(t).filter(f=>!i.includes(f)).map(f=>_(f)).join(",")}${u}}`;if(s)return`${p[0]}; export default {${u.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 oe(e,t,s){const n="virtual:storyblok-init",l=`\0${n}`;return{name:"vite-plugin-storyblok-init",async resolveId(r){if(r===n)return l},async load(r){if(r===l)return`
|
|
13
13
|
import { storyblokInit, apiPlugin } from "@storyblok/js";
|
|
14
14
|
const { storyblokApi } = storyblokInit({
|
|
15
|
-
accessToken: "${
|
|
16
|
-
use: ${
|
|
17
|
-
apiOptions: ${JSON.stringify(
|
|
15
|
+
accessToken: "${e}",
|
|
16
|
+
use: ${t?"[]":"[apiPlugin]"},
|
|
17
|
+
apiOptions: ${JSON.stringify(s)},
|
|
18
18
|
});
|
|
19
19
|
export const storyblokApiInstance = storyblokApi;
|
|
20
|
-
`}}}function
|
|
21
|
-
The "content" field must be an array of nodes as the type ISbRichtext.
|
|
22
|
-
ISbRichtext:
|
|
23
|
-
content?: ISbRichtext[]
|
|
24
|
-
marks?: ISbRichtext[]
|
|
25
|
-
attrs?: any
|
|
26
|
-
text?: string
|
|
27
|
-
type: string
|
|
28
|
-
|
|
29
|
-
Example:
|
|
30
|
-
{
|
|
31
|
-
content: [
|
|
32
|
-
{
|
|
33
|
-
content: [
|
|
34
|
-
{
|
|
35
|
-
text: 'Hello World',
|
|
36
|
-
type: 'text'
|
|
37
|
-
}
|
|
38
|
-
],
|
|
39
|
-
type: 'paragraph'
|
|
40
|
-
}
|
|
41
|
-
],
|
|
42
|
-
type: 'doc'
|
|
43
|
-
}`),""}optimizeImages(e,r){let o=0,n=0,s="",l="";typeof r!="boolean"&&(typeof r.width=="number"&&r.width>0&&(s+=`width="${r.width}" `,o=r.width),typeof r.height=="number"&&r.height>0&&(s+=`height="${r.height}" `,n=r.height),(r.loading==="lazy"||r.loading==="eager")&&(s+=`loading="${r.loading}" `),typeof r.class=="string"&&r.class.length>0&&(s+=`class="${r.class}" `),r.filters&&(typeof r.filters.blur=="number"&&r.filters.blur>=0&&r.filters.blur<=100&&(l+=`:blur(${r.filters.blur})`),typeof r.filters.brightness=="number"&&r.filters.brightness>=-100&&r.filters.brightness<=100&&(l+=`:brightness(${r.filters.brightness})`),r.filters.fill&&(r.filters.fill.match(/[0-9A-F]{6}/gi)||r.filters.fill==="transparent")&&(l+=`:fill(${r.filters.fill})`),r.filters.format&&["webp","png","jpeg"].includes(r.filters.format)&&(l+=`:format(${r.filters.format})`),typeof r.filters.grayscale=="boolean"&&r.filters.grayscale&&(l+=":grayscale()"),typeof r.filters.quality=="number"&&r.filters.quality>=0&&r.filters.quality<=100&&(l+=`:quality(${r.filters.quality})`),r.filters.rotate&&[90,180,270].includes(r.filters.rotate)&&(l+=`:rotate(${r.filters.rotate})`),l.length>0&&(l=`/filters${l}`))),s.length>0&&(e=e.replace(/<img/g,`<img ${s.trim()}`));const p=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/${p}`),typeof r!="boolean"&&(r.sizes||r.srcset)&&(e=e.replace(/<img.*?src=["|'](.*?)["|']/g,c=>{var u,h;const w=c.match(/a.storyblok.com\/f\/(\d+)\/([^.]+)\.(gif|jpg|jpeg|png|tif|bmp)/g);if(w&&w.length>0){const v={srcset:(u=r.srcset)==null?void 0:u.map(f=>{if(typeof f=="number")return`//${w}/m/${f}x0${l} ${f}w`;if(typeof f=="object"&&f.length===2){let I=0,j=0;return typeof f[0]=="number"&&(I=f[0]),typeof f[1]=="number"&&(j=f[1]),`//${w}/m/${I}x${j}${l} ${I}w`}return""}).join(", "),sizes:(h=r.sizes)==null?void 0:h.map(f=>f).join(", ")};let L="";return v.srcset&&(L+=`srcset="${v.srcset}" `),v.sizes&&(L+=`sizes="${v.sizes}" `),c.replace(/<img/g,`<img ${L.trim()}`)}return c})),e}renderNode(e){const r=[];e.marks&&e.marks.forEach(n=>{const s=this.getMatchingMark(n);s&&s.tag!==""&&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(Ne(e.text)):o&&o.singleTag?r.push(this.renderTag(o.singleTag," /")):o&&o.html?r.push(o.html):e.type==="emoji"&&r.push(this.renderEmoji(e)),o&&o.tag&&r.push(this.renderClosingTag(o.tag)),e.marks&&e.marks.slice(0).reverse().forEach(n=>{const s=this.getMatchingMark(n);s&&s.tag!==""&&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)if(Object.prototype.hasOwnProperty.call(o.attrs,s)){const l=o.attrs[s];l!==null&&(n+=` ${s}="${l}"`)}}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)}renderEmoji(e){if(e.attrs.emoji)return e.attrs.emoji;const r=[{tag:"img",attrs:{src:e.attrs.fallbackImage,draggable:"false",loading:"lazy",align:"absmiddle"}}];return this.renderTag(r," /")}}const Pe=t=>{if(typeof t!="object"||typeof t._editable>"u")return{};try{const e=JSON.parse(t._editable.replace(/^<!--#storyblok#/,"").replace(/-->$/,""));return e?{"data-blok-c":JSON.stringify(e),"data-blok-uid":`${e.id}-${e.uid}`}:{}}catch{return{}}};function Be(t,e){if(!e)return{src:t,attrs:{}};let r=0,o=0;const n={},s=[];function l(c,u,h,w,v){typeof c!="number"||c<=u||c>=h?console.warn(`[StoryblokRichText] - ${w.charAt(0).toUpperCase()+w.slice(1)} value must be a number between ${u} and ${h} (inclusive)`):v.push(`${w}(${c})`)}if(typeof e=="object"){if(typeof e.width=="number"&&e.width>0?(n.width=e.width,r=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:c}=e||{},{blur:u,brightness:h,fill:w,format:v,grayscale:L,quality:f,rotate:I}=c||{};u&&l(u,0,100,"blur",s),f&&l(f,0,100,"quality",s),h&&l(h,0,100,"brightness",s),w&&s.push(`fill(${w})`),L&&s.push("grayscale()"),I&&[0,90,180,270].includes(e.filters.rotate||0)&&s.push(`rotate(${I})`),v&&["webp","png","jpeg"].includes(v)&&s.push(`format(${v})`)}e.srcset&&(n.srcset=e.srcset.map(c=>{if(typeof c=="number")return`${t}/m/${c}x0/${s.length>0?`filters:${s.join(":")}`:""} ${c}w`;if(Array.isArray(c)&&c.length===2){const[u,h]=c;return`${t}/m/${u}x${h}/${s.length>0?`filters:${s.join(":")}`:""} ${u}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 p=`${t}/m/`;return r>0&&o>0&&(p=`${p}${r}x${o}/`),s.length>0&&(p=`${p}filters:${s.join(":")}`),{src:p,attrs:n}}var y=(t=>(t.DOCUMENT="doc",t.HEADING="heading",t.PARAGRAPH="paragraph",t.QUOTE="blockquote",t.OL_LIST="ordered_list",t.UL_LIST="bullet_list",t.LIST_ITEM="list_item",t.CODE_BLOCK="code_block",t.HR="horizontal_rule",t.BR="hard_break",t.IMAGE="image",t.EMOJI="emoji",t.COMPONENT="blok",t.TABLE="table",t.TABLE_ROW="tableRow",t.TABLE_CELL="tableCell",t.TABLE_HEADER="tableHeader",t))(y||{}),E=(t=>(t.BOLD="bold",t.STRONG="strong",t.STRIKE="strike",t.UNDERLINE="underline",t.ITALIC="italic",t.CODE="code",t.LINK="link",t.ANCHOR="anchor",t.STYLED="styled",t.SUPERSCRIPT="superscript",t.SUBSCRIPT="subscript",t.TEXT_STYLE="textStyle",t.HIGHLIGHT="highlight",t))(E||{}),N=(t=>(t.TEXT="text",t))(N||{}),R=(t=>(t.URL="url",t.STORY="story",t.ASSET="asset",t.EMAIL="email",t))(R||{});const De=["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"],Ue=(t={})=>Object.keys(t).map(e=>`${e}="${t[e]}"`).join(" "),ze=(t={})=>Object.keys(t).map(e=>`${e}: ${t[e]}`).join("; ");function He(t){return t.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}const x=t=>Object.fromEntries(Object.entries(t).filter(([e,r])=>r!==void 0));function W(t,e={},r){const o=Ue(e),n=o?`${t} ${o}`:t,s=Array.isArray(r)?r.join(""):r||"";if(t){if(De.includes(t))return`<${n}>`}else return s;return`<${n}>${s}</${t}>`}function Fe(t={}){const e=new Map,{renderFn:r=W,textFn:o=He,resolvers:n={},optimizeImages:s=!1,keyedResolvers:l=!1}=t,p=r!==W,c=()=>({render:(a,i={},d)=>{if(l&&a){const g=e.get(a)||0;e.set(a,g+1),i.key=`${a}-${g}`}return r(a,i,d)}}),u=a=>(i,d)=>{const g=i.attrs||{};return d.render(a,g,i.children||null)},h=(a,i)=>{const{src:d,alt:g,title:b,srcset:T,sizes:m}=a.attrs||{};let $=d,C={};if(s){const{src:dt,attrs:gt}=Be(d,s);$=dt,C=gt}const ut={src:$,alt:g,title:b,srcset:T,sizes:m,...C};return i.render("img",x(ut))},w=(a,i)=>{const{level:d,...g}=a.attrs||{};return i.render(`h${d}`,g,a.children)},v=(a,i)=>{var d,g,b,T;const m=i.render("img",{src:(d=a.attrs)==null?void 0:d.fallbackImage,alt:(g=a.attrs)==null?void 0:g.alt,style:"width: 1.25em; height: 1.25em; vertical-align: text-top",draggable:"false",loading:"lazy"});return i.render("span",{"data-type":"emoji","data-name":(b=a.attrs)==null?void 0:b.name,"data-emoji":(T=a.attrs)==null?void 0:T.emoji},m)},L=(a,i)=>i.render("pre",a.attrs||{},i.render("code",{},a.children||"")),f=(a,i=!1)=>({text:d,attrs:g},b)=>{const{class:T,id:m,...$}=g||{},C=i?{class:T,id:m,style:ze($)||void 0}:g||{};return b.render(a,x(C),d)},I=a=>P(a),j=a=>{const{marks:i,...d}=a;if("text"in a){if(i)return i.reduce((b,T)=>I({...T,text:b}),I({...d,children:d.children}));const g=a.attrs||{};if(l){const b=e.get("txt")||0;e.set("txt",b+1),g.key=`txt-${b}`}return o(d.text,g)}return""},Y=(a,i)=>{const{linktype:d,href:g,anchor:b,...T}=a.attrs||{};let m="";switch(d){case R.ASSET:case R.URL:m=g;break;case R.EMAIL:m=`mailto:${g}`;break;case R.STORY:m=g,b&&(m=`${m}#${b}`);break;default:m=g;break}const $={...T};return m&&($.href=m),i.render("a",$,a.text)},st=(a,i)=>{var d,g;return console.warn("[StoryblokRichtText] - BLOK resolver is not available for vanilla usage"),i.render("span",{blok:(d=a==null?void 0:a.attrs)==null?void 0:d.body[0],id:(g=a.attrs)==null?void 0:g.id,style:"display: none"})},nt=(a,i)=>{const d={},g=i.render("tbody",{},a.children);return i.render("table",d,g)},at=(a,i)=>{const d={};return i.render("tr",d,a.children)},lt=(a,i)=>{const{colspan:d,rowspan:g,colwidth:b,backgroundColor:T,...m}=a.attrs||{},$={...m};d>1&&($.colspan=d),g>1&&($.rowspan=g);const C=[];return b&&C.push(`width: ${b}px;`),T&&C.push(`background-color: ${T};`),C.length>0&&($.style=C.join(" ")),i.render("td",x($),a.children)},it=(a,i)=>{const{colspan:d,rowspan:g,colwidth:b,backgroundColor:T,...m}=a.attrs||{},$={...m};d>1&&($.colspan=d),g>1&&($.rowspan=g);const C=[];return b&&C.push(`width: ${b}px;`),T&&C.push(`background-color: ${T};`),C.length>0&&($.style=C.join(" ")),i.render("th",x($),a.children)},ct=new Map([[y.DOCUMENT,u("")],[y.HEADING,w],[y.PARAGRAPH,u("p")],[y.UL_LIST,u("ul")],[y.OL_LIST,u("ol")],[y.LIST_ITEM,u("li")],[y.IMAGE,h],[y.EMOJI,v],[y.CODE_BLOCK,L],[y.HR,u("hr")],[y.BR,u("br")],[y.QUOTE,u("blockquote")],[y.COMPONENT,st],[N.TEXT,j],[E.LINK,Y],[E.ANCHOR,Y],[E.STYLED,f("span",!0)],[E.BOLD,f("strong")],[E.TEXT_STYLE,f("span",!0)],[E.ITALIC,f("em")],[E.UNDERLINE,f("u")],[E.STRIKE,f("s")],[E.CODE,f("code")],[E.SUPERSCRIPT,f("sup")],[E.SUBSCRIPT,f("sub")],[E.HIGHLIGHT,f("mark")],[y.TABLE,nt],[y.TABLE_ROW,at],[y.TABLE_CELL,lt],[y.TABLE_HEADER,it],...Object.entries(n).map(([a,i])=>[a,i])]);function O(a){const i=ct.get(a.type);if(!i)return console.error("<Storyblok>",`No resolver found for node type ${a.type}`),"";const d=c();if(a.type==="text")return i(a,d);const g=a.content?a.content.map(P):void 0;return i({...a,children:g},d)}function P(a){return a.type==="doc"?p?a.content.map(O):a.content.map(O).join(""):Array.isArray(a)?a.map(O):O(a)}return{render:P}}let qe,Ge="https://app.storyblok.com/f/storyblok-v2-latest.js";const Ke=(t,e)=>{t.addNode("blok",r=>{let o="";return r.attrs.body.forEach(n=>{o+=e(n.component,n)}),{html:o}})},We=t=>{var e;return!t||!((e=t==null?void 0:t.content)!=null&&e.some(r=>r.content||r.type==="blok"||r.type==="horizontal_rule"))},Je=(t,e,r)=>{let o=r||qe;if(!o){console.error("Please initialize the Storyblok SDK before calling the renderRichText function");return}return We(t)?"":(e&&(o=new K(e.schema),e.resolver&&Ke(o,e.resolver)),o.render(t,{},!1))},Ye=()=>ae(Ge);function Ve(){if(!(globalThis!=null&&globalThis.storyblokApiInstance))throw new Error("storyblokApiInstance has not been initialized correctly");return globalThis.storyblokApiInstance}async function Xe(t){let e=null;return t&&t.locals._storyblok_preview_data&&(e=t.locals._storyblok_preview_data),e}function Ze(t,e){var o;const r=(o=globalThis==null?void 0:globalThis.storyblokApiInstance)==null?void 0:o.richTextResolver;if(!r)throw new Error("Please initialize the Storyblok SDK before calling the renderRichText function");return Je(t,e,r)}function Qe(t){return typeof t=="object"?`const storyblokInstance = new StoryblokBridge(${JSON.stringify(t)});`:"const storyblokInstance = new StoryblokBridge();"}function et(t){const e={useCustomApi:!1,bridge:!0,componentsDir:"src",enableFallbackComponent:!1,livePreview:!1,...t},r=Qe(e.bridge);return{name:"@storyblok/astro",hooks:{"astro:config:setup":({injectScript:o,updateConfig:n,addDevToolbarApp:s,addMiddleware:l,config:p})=>{if(n({vite:{plugins:[se(e.accessToken,e.useCustomApi,e.apiOptions),oe(e.componentsDir,e.components,e.enableFallbackComponent,e.customFallbackComponent),ne(e)]}}),e.livePreview&&(p==null?void 0:p.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",`
|
|
20
|
+
`}}}function re(e){const t="virtual:storyblok-options",s=`\0${t}`;return{name:"vite-plugin-storyblok-options",async resolveId(n){if(n===t)return s},async load(n){if(n===s)return`export default ${JSON.stringify(e)}`}}}function se(){if(!(globalThis!=null&&globalThis.storyblokApiInstance))throw new Error("storyblokApiInstance has not been initialized correctly");return globalThis.storyblokApiInstance}async function ne(e){let t=null;return e&&e.locals._storyblok_preview_data&&(t=e.locals._storyblok_preview_data),t}function le(e){return typeof e=="object"?`const storyblokInstance = new StoryblokBridge(${JSON.stringify(e)});`:"const storyblokInstance = new StoryblokBridge();"}function ae(e){const t={useCustomApi:!1,bridge:!0,componentsDir:"src",enableFallbackComponent:!1,livePreview:!1,...e},s=le(t.bridge);return{name:"@storyblok/astro",hooks:{"astro:config:setup":({injectScript:n,updateConfig:l,addDevToolbarApp:r,addMiddleware:b,config:p})=>{if(l({vite:{plugins:[oe(t.accessToken,t.useCustomApi,t.apiOptions),te(t.componentsDir,t.components,t.enableFallbackComponent,t.customFallbackComponent),re(t)]}}),t.livePreview&&(p==null?void 0:p.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.");n("page-ssr",`
|
|
44
21
|
import { storyblokApiInstance } from "virtual:storyblok-init";
|
|
45
22
|
globalThis.storyblokApiInstance = storyblokApiInstance;
|
|
46
|
-
`),
|
|
23
|
+
`),t.bridge&&!t.livePreview&&n("page",`import { loadStoryblokBridge } from "@storyblok/astro";
|
|
47
24
|
loadStoryblokBridge().then(() => {
|
|
48
25
|
const { StoryblokBridge, location } = window;
|
|
49
|
-
${
|
|
26
|
+
${s}
|
|
50
27
|
storyblokInstance.on(["published", "change"], (event) => {
|
|
51
28
|
if (!event.slugChanged) {
|
|
52
29
|
location.reload(true);
|
|
53
30
|
}
|
|
54
31
|
});
|
|
55
32
|
});
|
|
56
|
-
`),
|
|
33
|
+
`),t.livePreview&&(n("page",`import { loadStoryblokBridge, handleStoryblokMessage } from "@storyblok/astro";
|
|
57
34
|
loadStoryblokBridge().then(() => {
|
|
58
35
|
const { StoryblokBridge, location } = window;
|
|
59
|
-
${
|
|
36
|
+
${s}
|
|
60
37
|
storyblokInstance.on(["published", "change", "input"], handleStoryblokMessage);
|
|
61
38
|
});
|
|
62
|
-
`),
|
|
39
|
+
`),b({entrypoint:"@storyblok/astro/middleware.ts",order:"pre"})),r({id:"storyblok",name:"Storyblok",icon:$,entrypoint:"@storyblok/astro/toolbarApp.ts"})}}}}let D;async function ie(e){const{action:t,story:s}=e||{};if(t==="input"&&s){const n=async()=>{const r=await de(s),b=document.body;if(r.outerHTML===b.outerHTML)return;const p=document.querySelector('[data-blok-focused="true"]');ce(b,r,p),document.dispatchEvent(new Event("storyblok-live-preview-updated"))};clearTimeout(D),D=setTimeout(n,500)}["published","change"].includes(e==null?void 0:e.action)&&location.reload()}function ce(e,t,s){if(s){const n=s.getAttribute("data-blok-uid"),l=t.querySelector(`[data-blok-uid="${n}"]`);l&&(l.setAttribute("data-blok-focused","true"),s.replaceWith(l))}else e.replaceWith(t)}async function de(e){const s=await(await fetch(location.href,{method:"POST",body:JSON.stringify({...e,is_storyblok_preview:!0}),headers:{"Content-Type":"application/json"}})).text();return new DOMParser().parseFromString(s,"text/html").body}function ue(e,t){if(!t)return{src:e,attrs:{}};let s=0,n=0;const l={},r=[];function b(i,u,f,L,S){typeof i!="number"||i<=u||i>=f?console.warn(`[StoryblokRichText] - ${L.charAt(0).toUpperCase()+L.slice(1)} value must be a number between ${u} and ${f} (inclusive)`):S.push(`${L}(${i})`)}if(typeof t=="object"){if(typeof t.width=="number"&&t.width>0?(l.width=t.width,s=t.width):console.warn("[StoryblokRichText] - Width value must be a number greater than 0"),t.height&&typeof t.height=="number"&&t.height>0?(l.height=t.height,n=t.height):console.warn("[StoryblokRichText] - Height value must be a number greater than 0"),t.loading&&["lazy","eager"].includes(t.loading)&&(l.loading=t.loading),t.class&&(l.class=t.class),t.filters){const{filters:i}=t||{},{blur:u,brightness:f,fill:L,format:S,grayscale:E,quality:A,rotate:R}=i||{};u&&b(u,0,100,"blur",r),A&&b(A,0,100,"quality",r),f&&b(f,0,100,"brightness",r),L&&r.push(`fill(${L})`),E&&r.push("grayscale()"),R&&[0,90,180,270].includes(t.filters.rotate||0)&&r.push(`rotate(${R})`),S&&["webp","png","jpeg"].includes(S)&&r.push(`format(${S})`)}t.srcset&&(l.srcset=t.srcset.map(i=>{if(typeof i=="number")return`${e}/m/${i}x0/${r.length>0?`filters:${r.join(":")}`:""} ${i}w`;if(Array.isArray(i)&&i.length===2){const[u,f]=i;return`${e}/m/${u}x${f}/${r.length>0?`filters:${r.join(":")}`:""} ${u}w`}else{console.warn("[StoryblokRichText] - srcset entry must be a number or a tuple of two numbers");return}}).join(", ")),t.sizes&&(l.sizes=t.sizes.join(", "))}let p=`${e}/m/`;return s>0&&n>0&&(p=`${p}${s}x${n}/`),r.length>0&&(p=`${p}filters:${r.join(":")}`),{src:p,attrs:l}}var h=(e=>(e.DOCUMENT="doc",e.HEADING="heading",e.PARAGRAPH="paragraph",e.QUOTE="blockquote",e.OL_LIST="ordered_list",e.UL_LIST="bullet_list",e.LIST_ITEM="list_item",e.CODE_BLOCK="code_block",e.HR="horizontal_rule",e.BR="hard_break",e.IMAGE="image",e.EMOJI="emoji",e.COMPONENT="blok",e.TABLE="table",e.TABLE_ROW="tableRow",e.TABLE_CELL="tableCell",e.TABLE_HEADER="tableHeader",e))(h||{}),C=(e=>(e.BOLD="bold",e.STRONG="strong",e.STRIKE="strike",e.UNDERLINE="underline",e.ITALIC="italic",e.CODE="code",e.LINK="link",e.ANCHOR="anchor",e.STYLED="styled",e.SUPERSCRIPT="superscript",e.SUBSCRIPT="subscript",e.TEXT_STYLE="textStyle",e.HIGHLIGHT="highlight",e))(C||{}),U=(e=>(e.TEXT="text",e))(U||{}),T=(e=>(e.URL="url",e.STORY="story",e.ASSET="asset",e.EMAIL="email",e))(T||{});const pe=["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"],be=(e={})=>Object.keys(e).map(t=>`${t}="${e[t]}"`).join(" "),fe=(e={})=>Object.keys(e).map(t=>`${t}: ${e[t]}`).join("; ");function ye(e){return e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}const I=e=>Object.fromEntries(Object.entries(e).filter(([t,s])=>s!==void 0));function H(e,t={},s){const n=be(t),l=n?`${e} ${n}`:e,r=Array.isArray(s)?s.join(""):s||"";if(e){if(pe.includes(e))return`<${l}>`}else return r;return`<${l}>${r}</${e}>`}function F(e={}){const t=new Map,{renderFn:s=H,textFn:n=ye,resolvers:l={},optimizeImages:r=!1,keyedResolvers:b=!1}=e,p=s!==H,i=o=>(a,c)=>{const d=a.attrs||{};return c.render(o,d,a.children||null)},u=(o,a)=>{const{src:c,alt:d,title:y,srcset:k,sizes:g}=o.attrs||{};let m=c,v={};if(r){const{src:Ae,attrs:Ie}=ue(c,r);m=Ae,v=Ie}const Te={src:m,alt:d,title:y,srcset:k,sizes:g,...v};return a.render("img",I(Te))},f=(o,a)=>{const{level:c,...d}=o.attrs||{};return a.render(`h${c}`,d,o.children)},L=(o,a)=>{var c,d,y,k;const g=a.render("img",{src:(c=o.attrs)==null?void 0:c.fallbackImage,alt:(d=o.attrs)==null?void 0:d.alt,style:"width: 1.25em; height: 1.25em; vertical-align: text-top",draggable:"false",loading:"lazy"});return a.render("span",{"data-type":"emoji","data-name":(y=o.attrs)==null?void 0:y.name,"data-emoji":(k=o.attrs)==null?void 0:k.emoji},g)},S=(o,a)=>a.render("pre",o.attrs||{},a.render("code",{},o.children||"")),E=(o,a=!1)=>({text:c,attrs:d},y)=>{const{class:k,id:g,...m}=d||{},v=a?{class:k,id:g,style:fe(m)||void 0}:d||{};return y.render(o,I(v),c)},A=o=>M(o),R=o=>{const{marks:a,...c}=o;if("text"in o){if(a)return a.reduce((y,k)=>A({...k,text:y}),A({...c,children:c.children}));const d=o.attrs||{};if(b){const y=t.get("txt")||0;t.set("txt",y+1),d.key=`txt-${y}`}return n(c.text,d)}return""},K=(o,a)=>{const{linktype:c,href:d,anchor:y,...k}=o.attrs||{};let g="";switch(c){case T.ASSET:case T.URL:g=d;break;case T.EMAIL:g=`mailto:${d}`;break;case T.STORY:g=d,y&&(g=`${g}#${y}`);break;default:g=d;break}const m={...k};return g&&(m.href=g),a.render("a",m,o.text)},ve=(o,a)=>{var c,d;return console.warn("[StoryblokRichtText] - BLOK resolver is not available for vanilla usage"),a.render("span",{blok:(c=o==null?void 0:o.attrs)==null?void 0:c.body[0],id:(d=o.attrs)==null?void 0:d.id,style:"display: none"})},Ce=(o,a)=>{const c={},d=a.render("tbody",{},o.children);return a.render("table",c,d)},Ee=(o,a)=>{const c={};return a.render("tr",c,o.children)},Le=(o,a)=>{const{colspan:c,rowspan:d,colwidth:y,backgroundColor:k,...g}=o.attrs||{},m={...g};c>1&&(m.colspan=c),d>1&&(m.rowspan=d);const v=[];return y&&v.push(`width: ${y}px;`),k&&v.push(`background-color: ${k};`),v.length>0&&(m.style=v.join(" ")),a.render("td",I(m),o.children)},Se=(o,a)=>{const{colspan:c,rowspan:d,colwidth:y,backgroundColor:k,...g}=o.attrs||{},m={...g};c>1&&(m.colspan=c),d>1&&(m.rowspan=d);const v=[];return y&&v.push(`width: ${y}px;`),k&&v.push(`background-color: ${k};`),v.length>0&&(m.style=v.join(" ")),a.render("th",I(m),o.children)},J=new Map([[h.DOCUMENT,i("")],[h.HEADING,f],[h.PARAGRAPH,i("p")],[h.UL_LIST,i("ul")],[h.OL_LIST,i("ol")],[h.LIST_ITEM,i("li")],[h.IMAGE,u],[h.EMOJI,L],[h.CODE_BLOCK,S],[h.HR,i("hr")],[h.BR,i("br")],[h.QUOTE,i("blockquote")],[h.COMPONENT,ve],[U.TEXT,R],[C.LINK,K],[C.ANCHOR,K],[C.STYLED,E("span",!0)],[C.BOLD,E("strong")],[C.TEXT_STYLE,E("span",!0)],[C.ITALIC,E("em")],[C.UNDERLINE,E("u")],[C.STRIKE,E("s")],[C.CODE,E("code")],[C.SUPERSCRIPT,E("sup")],[C.SUBSCRIPT,E("sub")],[C.HIGHLIGHT,E("mark")],[h.TABLE,Ce],[h.TABLE_ROW,Ee],[h.TABLE_CELL,Le],[h.TABLE_HEADER,Se]]),q=new Map([...J,...Object.entries(l).map(([o,a])=>[o,a])]),$e=()=>({render:(o,a={},c)=>{if(b&&o){const d=t.get(o)||0;t.set(o,d+1),a.key=`${o}-${d}`}return s(o,a,c)},originalResolvers:J,mergedResolvers:q});function O(o){const a=q.get(o.type);if(!a)return console.error("<Storyblok>",`No resolver found for node type ${o.type}`),"";const c=$e();if(o.type==="text")return a(o,c);const d=o.content?o.content.map(M):void 0;return a({...o,children:d},c)}function M(o){return o.type==="doc"?p?o.content.map(O):o.content.map(O).join(""):Array.isArray(o)?o.map(O):O(o)}return{render:M}}let G=!1;const z=[],he=e=>new Promise((t,s)=>{if(typeof window>"u"){s(new Error("Cannot load Storyblok bridge: window is undefined (server-side environment)"));return}if(window.storyblokRegisterEvent=l=>{if(window.location===window.parent.location){console.warn("You are not in Draft Mode or in the Visual Editor.");return}G?l():z.push(l)},document.getElementById("storyblok-javascript-bridge")){t(void 0);return}const n=document.createElement("script");n.async=!0,n.src=e,n.id="storyblok-javascript-bridge",n.onerror=l=>s(l),n.onload=l=>{z.forEach(r=>r()),G=!0,t(l)},document.getElementsByTagName("head")[0].appendChild(n)}),ge=e=>{if(typeof e!="object"||typeof e._editable>"u")return{};try{const t=JSON.parse(e._editable.replace(/^<!--#storyblok#/,"").replace(/-->$/,""));return t?{"data-blok-c":JSON.stringify(t),"data-blok-uid":`${t.id}-${t.uid}`}:{}}catch{return{}}};let me="https://app.storyblok.com/f/storyblok-v2-latest.js";function ke(e,t){return F(t).render(e)}const we=()=>he(me);w.getLiveStory=ne,w.handleStoryblokMessage=ie,w.loadStoryblokBridge=we,w.renderRichText=ke,w.richTextResolver=F,w.storyblok=ae,w.storyblokEditable=ge,w.toCamelCase=_,w.useStoryblokApi=se,Object.defineProperty(w,Symbol.toStringTag,{value:"Module"})});
|
package/dist/types.d.ts
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
export type { ArrayFn, AsyncFn, ISbAlternateObject, // previously AlternateObject
|
|
1
|
+
export type { ArrayFn, AsyncFn, BlockTypes, ISbAlternateObject, // previously AlternateObject
|
|
2
2
|
ISbCache, // previously StoryblokCache
|
|
3
3
|
ISbConfig, // previously StoryblokConfig
|
|
4
4
|
ISbContentMangmntAPI, ISbDimensions, ISbError, ISbEventPayload, ISbManagmentApiResult, // previously StoryblokManagmentApiResult
|
|
5
|
-
|
|
6
|
-
ISbRichtext, // previously Richtext
|
|
5
|
+
ISbResponse, ISbResult, // previously StoryblokResult
|
|
7
6
|
ISbSchema, ISbStories, // previously Stories
|
|
8
7
|
ISbStoriesParams, // previously StoriesParams
|
|
9
8
|
ISbStory, // previously Story
|
|
10
9
|
ISbStoryData, // previously StoryData
|
|
11
10
|
ISbStoryParams, // previously StoryParams
|
|
12
|
-
|
|
11
|
+
MarkTypes, SbBlokData, SbBlokKeyDataTypes, SbPluginFactory, SbSDKOptions, StoryblokBridgeConfigV2, StoryblokBridgeV2, StoryblokClient, StoryblokComponentType, StoryblokRichTextDocumentNode, StoryblokRichTextImageOptimizationOptions, StoryblokRichTextNode, StoryblokRichTextNodeResolver, StoryblokRichTextNodeTypes, StoryblokRichTextOptions, StoryblokRichTextResolvers, TextTypes, } from '@storyblok/js';
|
package/package.json
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@storyblok/astro",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "
|
|
4
|
+
"version": "7.0.1",
|
|
5
5
|
"private": false,
|
|
6
|
-
"packageManager": "pnpm@9.13.2",
|
|
7
6
|
"description": "Official Astro integration for the Storyblok Headless CMS",
|
|
8
7
|
"author": "Storyblok",
|
|
9
8
|
"license": "MIT",
|
|
@@ -50,75 +49,33 @@
|
|
|
50
49
|
"*.d.ts",
|
|
51
50
|
"dist"
|
|
52
51
|
],
|
|
53
|
-
"scripts": {
|
|
54
|
-
"dev": "vite",
|
|
55
|
-
"build": "vite build && tsc --project tsconfig.json",
|
|
56
|
-
"playground": "pnpm run --filter ./playground/ssg dev",
|
|
57
|
-
"playground:ssr": "pnpm run --filter ./playground/ssr dev",
|
|
58
|
-
"playground:test": "pnpm run --filter ./playground/test dev",
|
|
59
|
-
"lint": "eslint .",
|
|
60
|
-
"lint:fix": "eslint . --fix",
|
|
61
|
-
"lint:playground": "pnpm -r --parallel --filter='./playground/*' run lint",
|
|
62
|
-
"lint:playground:fix": "pnpm -r --parallel --filter='./playground/*' run lint:fix",
|
|
63
|
-
"test": "pnpm run test:unit:ci && pnpm run test:e2e",
|
|
64
|
-
"test:unit": "vitest",
|
|
65
|
-
"test:unit:ci": "vitest run",
|
|
66
|
-
"test:e2e": "start-server-and-test playground:test http://localhost:4321/ cy:run",
|
|
67
|
-
"test:e2e-watch": "start-server-and-test playground:test http://localhost:4321/ cy:open",
|
|
68
|
-
"cy:run": "cypress run",
|
|
69
|
-
"cy:open": "cypress open",
|
|
70
|
-
"check-licenses": "node scripts/license-checker.mjs"
|
|
71
|
-
},
|
|
72
52
|
"peerDependencies": {
|
|
73
53
|
"astro": "^3.0.0 || ^4.0.0 || ^5.0.0"
|
|
74
54
|
},
|
|
75
55
|
"dependencies": {
|
|
76
|
-
"
|
|
77
|
-
"
|
|
56
|
+
"camelcase": "^8.0.0",
|
|
57
|
+
"@storyblok/js": "4.0.3"
|
|
78
58
|
},
|
|
79
59
|
"devDependencies": {
|
|
80
|
-
"@
|
|
81
|
-
"@commitlint/config-conventional": "^19.5.0",
|
|
82
|
-
"@cypress/vite-dev-server": "^5.2.0",
|
|
60
|
+
"@cypress/vite-dev-server": "^6.0.3",
|
|
83
61
|
"@rollup/plugin-dynamic-import-vars": "^2.1.5",
|
|
84
62
|
"@storyblok/eslint-config": "^0.3.0",
|
|
85
63
|
"@types/lodash.mergewith": "^4.6.9",
|
|
86
|
-
"@types/node": "22.
|
|
64
|
+
"@types/node": "^22.15.1",
|
|
87
65
|
"astro": "^5.0.9",
|
|
88
|
-
"cypress": "^
|
|
89
|
-
"eslint": "^9.
|
|
90
|
-
"eslint-config-prettier": "^
|
|
66
|
+
"cypress": "^14.3.3",
|
|
67
|
+
"eslint": "^9.26.0",
|
|
68
|
+
"eslint-config-prettier": "^10.0.1",
|
|
91
69
|
"eslint-plugin-astro": "^1.3.1",
|
|
92
|
-
"eslint-plugin-cypress": "^4.
|
|
93
|
-
"
|
|
94
|
-
"lint-staged": "^15.2.10",
|
|
95
|
-
"prettier": "^3.3.3",
|
|
70
|
+
"eslint-plugin-cypress": "^4.3.0",
|
|
71
|
+
"prettier": "^3.4.2",
|
|
96
72
|
"prettier-plugin-astro": "^0.13.0",
|
|
97
|
-
"
|
|
98
|
-
"
|
|
99
|
-
"
|
|
100
|
-
"vite": "^
|
|
101
|
-
"vite-plugin-dts": "^4.3.0",
|
|
73
|
+
"start-server-and-test": "^2.0.11",
|
|
74
|
+
"typescript": "5.8.3",
|
|
75
|
+
"vite": "^6.3.5",
|
|
76
|
+
"vite-plugin-dts": "^4.5.3",
|
|
102
77
|
"vite-plugin-static-copy": "^2.2.0",
|
|
103
|
-
"vitest": "^
|
|
104
|
-
},
|
|
105
|
-
"simple-git-hooks": {
|
|
106
|
-
"pre-commit": "pnpm lint",
|
|
107
|
-
"pre-push": "pnpm commitlint --last --verbose"
|
|
108
|
-
},
|
|
109
|
-
"lint-staged": {
|
|
110
|
-
"*.{astro,js,css}": [
|
|
111
|
-
"prettier --write",
|
|
112
|
-
"eslint"
|
|
113
|
-
],
|
|
114
|
-
"*.md": [
|
|
115
|
-
"prettier --write"
|
|
116
|
-
]
|
|
117
|
-
},
|
|
118
|
-
"commitlint": {
|
|
119
|
-
"extends": [
|
|
120
|
-
"@commitlint/config-conventional"
|
|
121
|
-
]
|
|
78
|
+
"vitest": "^3.1.3"
|
|
122
79
|
},
|
|
123
80
|
"eslintConfig": {
|
|
124
81
|
"env": {
|
|
@@ -163,5 +120,31 @@
|
|
|
163
120
|
},
|
|
164
121
|
"publishConfig": {
|
|
165
122
|
"access": "public"
|
|
123
|
+
},
|
|
124
|
+
"nx": {
|
|
125
|
+
"implicitDependencies": [
|
|
126
|
+
"!@storyblok/playground-*"
|
|
127
|
+
],
|
|
128
|
+
"tags": [
|
|
129
|
+
"type:lib"
|
|
130
|
+
]
|
|
131
|
+
},
|
|
132
|
+
"scripts": {
|
|
133
|
+
"dev": "vite",
|
|
134
|
+
"build": "vite build && tsc --project tsconfig.json",
|
|
135
|
+
"playground": "pnpm run --filter ./playground/ssg dev",
|
|
136
|
+
"playground:ssr": "pnpm run --filter ./playground/ssr dev",
|
|
137
|
+
"playground:test": "pnpm run --filter ./playground/test dev",
|
|
138
|
+
"lint": "eslint .",
|
|
139
|
+
"lint:fix": "eslint . --fix",
|
|
140
|
+
"lint:playground": "pnpm -r --parallel --filter='./playground/*' run lint",
|
|
141
|
+
"lint:playground:fix": "pnpm -r --parallel --filter='./playground/*' run lint:fix",
|
|
142
|
+
"test": "pnpm run test:unit:ci && pnpm run test:e2e",
|
|
143
|
+
"test:unit": "vitest",
|
|
144
|
+
"test:unit:ci": "vitest run",
|
|
145
|
+
"test:e2e": "start-server-and-test playground:test http://localhost:4321/ cy:run",
|
|
146
|
+
"test:e2e-watch": "start-server-and-test playground:test http://localhost:4321/ cy:open",
|
|
147
|
+
"cy:run": "cypress run",
|
|
148
|
+
"cy:open": "cypress open"
|
|
166
149
|
}
|
|
167
|
-
}
|
|
150
|
+
}
|