@storyblok/astro 6.1.1 → 7.0.0
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 +1 -2
- package/dist/storyblok-astro.es.js +397 -793
- package/dist/storyblok-astro.umd.js +12 -35
- package/dist/types.d.ts +3 -4
- package/package.json +2 -2
|
@@ -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>`,J=/[\p{Lu}]/u,q=/[\p{Ll}]/u,M=/^[\p{Lu}](?![\p{Lu}])/gu,N=/([\p{Alpha}\p{N}_]|$)/u,O=/[_.\- ]+/,W=new RegExp("^"+O.source),j=new RegExp(O.source+N.source,"gu"),P=new RegExp("\\d+"+N.source,"gu"),Y=(e,t,n,s)=>{let l=!1,r=!1,b=!1,p=!1;for(let u=0;u<e.length;u++){const d=e[u];p=u>2?e[u-3]==="-":!0,l&&J.test(d)?(e=e.slice(0,u)+"-"+e.slice(u),l=!1,b=r,r=!0,u++):r&&b&&q.test(d)&&(!p||s)?(e=e.slice(0,u-1)+"-"+e.slice(u-1),b=r,r=!1,l=!0):(l=t(d)===d&&n(d)!==d,b=r,r=n(d)===d&&t(d)!==d)}return e},V=(e,t)=>(M.lastIndex=0,e.replaceAll(M,n=>t(n))),X=(e,t)=>(j.lastIndex=0,P.lastIndex=0,e.replaceAll(P,(n,s,l)=>["_","-"].includes(e.charAt(l+n.length))?n:t(n)).replaceAll(j,(n,s)=>t(s)));function Z(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 n=t.locale===!1?r=>r.toLowerCase():r=>r.toLocaleLowerCase(t.locale),s=t.locale===!1?r=>r.toUpperCase():r=>r.toLocaleUpperCase(t.locale);return e.length===1?O.test(e)?"":t.pascalCase?s(e):n(e):(e!==n(e)&&(e=Y(e,n,s,t.preserveConsecutiveUppercase)),e=e.replace(W,""),e=t.preserveConsecutiveUppercase?V(e,n):n(e),t.pascalCase&&(e=s(e.charAt(0))+e.slice(1)),X(e,s))}function x(e){return Z(e)}function Q(e,t={},n,s){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=[],u=[];for await(const[f,S]of Object.entries(t)){const T=await this.resolve(`/${e}/${S}.astro`);if(T)p.push(`import ${x(f)} from "${T.id}"`);else if(n)u.push(f);else throw new Error(`Component could not be found for blok "${f}"! Does "${`/${e}/${S}`}.astro" exist?`)}let d="";if(n)if(d=",FallbackComponent",s){const f=await this.resolve(`/${e}/${s}.astro`);if(!f)throw new Error(`Custom fallback component could not be found. Does "${`/${e}/${s}`}.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=>!u.includes(f)).map(f=>x(f)).join(",")}${d}}`;if(n)return`${p[0]}; export default {${d.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 ee(e,t,n){const s="virtual:storyblok-init",l=`\0${s}`;return{name:"vite-plugin-storyblok-init",async resolveId(r){if(r===s)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(n)},
|
|
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,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",`
|
|
20
|
+
`}}}function te(e){const t="virtual:storyblok-options",n=`\0${t}`;return{name:"vite-plugin-storyblok-options",async resolveId(s){if(s===t)return n},async load(s){if(s===n)return`export default ${JSON.stringify(e)}`}}}function oe(){if(!(globalThis!=null&&globalThis.storyblokApiInstance))throw new Error("storyblokApiInstance has not been initialized correctly");return globalThis.storyblokApiInstance}async function re(e){let t=null;return e&&e.locals._storyblok_preview_data&&(t=e.locals._storyblok_preview_data),t}function ne(e){return typeof e=="object"?`const storyblokInstance = new StoryblokBridge(${JSON.stringify(e)});`:"const storyblokInstance = new StoryblokBridge();"}function se(e){const t={useCustomApi:!1,bridge:!0,componentsDir:"src",enableFallbackComponent:!1,livePreview:!1,...e},n=ne(t.bridge);return{name:"@storyblok/astro",hooks:{"astro:config:setup":({injectScript:s,updateConfig:l,addDevToolbarApp:r,addMiddleware:b,config:p})=>{if(l({vite:{plugins:[ee(t.accessToken,t.useCustomApi,t.apiOptions),Q(t.componentsDir,t.components,t.enableFallbackComponent,t.customFallbackComponent),te(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.");s("page-ssr",`
|
|
44
21
|
import { storyblokApiInstance } from "virtual:storyblok-init";
|
|
45
22
|
globalThis.storyblokApiInstance = storyblokApiInstance;
|
|
46
|
-
`),
|
|
23
|
+
`),t.bridge&&!t.livePreview&&s("page",`import { loadStoryblokBridge } from "@storyblok/astro";
|
|
47
24
|
loadStoryblokBridge().then(() => {
|
|
48
25
|
const { StoryblokBridge, location } = window;
|
|
49
|
-
${
|
|
26
|
+
${n}
|
|
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&&(s("page",`import { loadStoryblokBridge, handleStoryblokMessage } from "@storyblok/astro";
|
|
57
34
|
loadStoryblokBridge().then(() => {
|
|
58
35
|
const { StoryblokBridge, location } = window;
|
|
59
|
-
${
|
|
36
|
+
${n}
|
|
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 le(e){const{action:t,story:n}=e||{};if(t==="input"&&n){const s=async()=>{const r=await ie(n),b=document.body;if(r.outerHTML===b.outerHTML)return;const p=document.querySelector('[data-blok-focused="true"]');ae(b,r,p),document.dispatchEvent(new Event("storyblok-live-preview-updated"))};clearTimeout(D),D=setTimeout(s,500)}["published","change"].includes(e==null?void 0:e.action)&&location.reload()}function ae(e,t,n){if(n){const s=n.getAttribute("data-blok-uid"),l=t.querySelector(`[data-blok-uid="${s}"]`);l&&(l.setAttribute("data-blok-focused","true"),n.replaceWith(l))}else e.replaceWith(t)}async function ie(e){const n=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(n,"text/html").body}function ce(e,t){if(!t)return{src:e,attrs:{}};let n=0,s=0;const l={},r=[];function b(u,d,f,S,T){typeof u!="number"||u<=d||u>=f?console.warn(`[StoryblokRichText] - ${S.charAt(0).toUpperCase()+S.slice(1)} value must be a number between ${d} and ${f} (inclusive)`):T.push(`${S}(${u})`)}if(typeof t=="object"){if(typeof t.width=="number"&&t.width>0?(l.width=t.width,n=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,s=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:u}=t||{},{blur:d,brightness:f,fill:S,format:T,grayscale:_,quality:L,rotate:A}=u||{};d&&b(d,0,100,"blur",r),L&&b(L,0,100,"quality",r),f&&b(f,0,100,"brightness",r),S&&r.push(`fill(${S})`),_&&r.push("grayscale()"),A&&[0,90,180,270].includes(t.filters.rotate||0)&&r.push(`rotate(${A})`),T&&["webp","png","jpeg"].includes(T)&&r.push(`format(${T})`)}t.srcset&&(l.srcset=t.srcset.map(u=>{if(typeof u=="number")return`${e}/m/${u}x0/${r.length>0?`filters:${r.join(":")}`:""} ${u}w`;if(Array.isArray(u)&&u.length===2){const[d,f]=u;return`${e}/m/${d}x${f}/${r.length>0?`filters:${r.join(":")}`:""} ${d}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 n>0&&s>0&&(p=`${p}${n}x${s}/`),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||{}),E=(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))(E||{}),U=(e=>(e.TEXT="text",e))(U||{}),v=(e=>(e.URL="url",e.STORY="story",e.ASSET="asset",e.EMAIL="email",e))(v||{});const de=["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"],ue=(e={})=>Object.keys(e).map(t=>`${t}="${e[t]}"`).join(" "),pe=(e={})=>Object.keys(e).map(t=>`${t}: ${e[t]}`).join("; ");function be(e){return e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}const I=e=>Object.fromEntries(Object.entries(e).filter(([t,n])=>n!==void 0));function H(e,t={},n){const s=ue(t),l=s?`${e} ${s}`:e,r=Array.isArray(n)?n.join(""):n||"";if(e){if(de.includes(e))return`<${l}>`}else return r;return`<${l}>${r}</${e}>`}function F(e={}){const t=new Map,{renderFn:n=H,textFn:s=be,resolvers:l={},optimizeImages:r=!1,keyedResolvers:b=!1}=e,p=n!==H,u=()=>({render:(o,a={},i)=>{if(b&&o){const c=t.get(o)||0;t.set(o,c+1),a.key=`${o}-${c}`}return n(o,a,i)}}),d=o=>(a,i)=>{const c=a.attrs||{};return i.render(o,c,a.children||null)},f=(o,a)=>{const{src:i,alt:c,title:y,srcset:m,sizes:g}=o.attrs||{};let k=i,C={};if(r){const{src:ve,attrs:Ae}=ce(i,r);k=ve,C=Ae}const $e={src:k,alt:c,title:y,srcset:m,sizes:g,...C};return a.render("img",I($e))},S=(o,a)=>{const{level:i,...c}=o.attrs||{};return a.render(`h${i}`,c,o.children)},T=(o,a)=>{var i,c,y,m;const g=a.render("img",{src:(i=o.attrs)==null?void 0:i.fallbackImage,alt:(c=o.attrs)==null?void 0:c.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":(m=o.attrs)==null?void 0:m.emoji},g)},_=(o,a)=>a.render("pre",o.attrs||{},a.render("code",{},o.children||"")),L=(o,a=!1)=>({text:i,attrs:c},y)=>{const{class:m,id:g,...k}=c||{},C=a?{class:m,id:g,style:pe(k)||void 0}:c||{};return y.render(o,I(C),i)},A=o=>B(o),me=o=>{const{marks:a,...i}=o;if("text"in o){if(a)return a.reduce((y,m)=>A({...m,text:y}),A({...i,children:i.children}));const c=o.attrs||{};if(b){const y=t.get("txt")||0;t.set("txt",y+1),c.key=`txt-${y}`}return s(i.text,c)}return""},K=(o,a)=>{const{linktype:i,href:c,anchor:y,...m}=o.attrs||{};let g="";switch(i){case v.ASSET:case v.URL:g=c;break;case v.EMAIL:g=`mailto:${c}`;break;case v.STORY:g=c,y&&(g=`${g}#${y}`);break;default:g=c;break}const k={...m};return g&&(k.href=g),a.render("a",k,o.text)},we=(o,a)=>{var i,c;return console.warn("[StoryblokRichtText] - BLOK resolver is not available for vanilla usage"),a.render("span",{blok:(i=o==null?void 0:o.attrs)==null?void 0:i.body[0],id:(c=o.attrs)==null?void 0:c.id,style:"display: none"})},Ce=(o,a)=>{const i={},c=a.render("tbody",{},o.children);return a.render("table",i,c)},Ee=(o,a)=>{const i={};return a.render("tr",i,o.children)},Le=(o,a)=>{const{colspan:i,rowspan:c,colwidth:y,backgroundColor:m,...g}=o.attrs||{},k={...g};i>1&&(k.colspan=i),c>1&&(k.rowspan=c);const C=[];return y&&C.push(`width: ${y}px;`),m&&C.push(`background-color: ${m};`),C.length>0&&(k.style=C.join(" ")),a.render("td",I(k),o.children)},Se=(o,a)=>{const{colspan:i,rowspan:c,colwidth:y,backgroundColor:m,...g}=o.attrs||{},k={...g};i>1&&(k.colspan=i),c>1&&(k.rowspan=c);const C=[];return y&&C.push(`width: ${y}px;`),m&&C.push(`background-color: ${m};`),C.length>0&&(k.style=C.join(" ")),a.render("th",I(k),o.children)},Te=new Map([[h.DOCUMENT,d("")],[h.HEADING,S],[h.PARAGRAPH,d("p")],[h.UL_LIST,d("ul")],[h.OL_LIST,d("ol")],[h.LIST_ITEM,d("li")],[h.IMAGE,f],[h.EMOJI,T],[h.CODE_BLOCK,_],[h.HR,d("hr")],[h.BR,d("br")],[h.QUOTE,d("blockquote")],[h.COMPONENT,we],[U.TEXT,me],[E.LINK,K],[E.ANCHOR,K],[E.STYLED,L("span",!0)],[E.BOLD,L("strong")],[E.TEXT_STYLE,L("span",!0)],[E.ITALIC,L("em")],[E.UNDERLINE,L("u")],[E.STRIKE,L("s")],[E.CODE,L("code")],[E.SUPERSCRIPT,L("sup")],[E.SUBSCRIPT,L("sub")],[E.HIGHLIGHT,L("mark")],[h.TABLE,Ce],[h.TABLE_ROW,Ee],[h.TABLE_CELL,Le],[h.TABLE_HEADER,Se],...Object.entries(l).map(([o,a])=>[o,a])]);function R(o){const a=Te.get(o.type);if(!a)return console.error("<Storyblok>",`No resolver found for node type ${o.type}`),"";const i=u();if(o.type==="text")return a(o,i);const c=o.content?o.content.map(B):void 0;return a({...o,children:c},i)}function B(o){return o.type==="doc"?p?o.content.map(R):o.content.map(R).join(""):Array.isArray(o)?o.map(R):R(o)}return{render:B}}let G=!1;const z=[],fe=e=>new Promise((t,n)=>{if(typeof window>"u"||(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")))return;const s=document.createElement("script");s.async=!0,s.src=e,s.id="storyblok-javascript-bridge",s.onerror=l=>n(l),s.onload=l=>{z.forEach(r=>r()),G=!0,t(l)},document.getElementsByTagName("head")[0].appendChild(s)}),ye=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 he="https://app.storyblok.com/f/storyblok-v2-latest.js";function ge(e,t){return F(t).render(e)}const ke=()=>fe(he);w.getLiveStory=re,w.handleStoryblokMessage=le,w.loadStoryblokBridge=ke,w.renderRichText=ge,w.richTextResolver=F,w.storyblok=se,w.storyblokEditable=ye,w.toCamelCase=x,w.useStoryblokApi=oe,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,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@storyblok/astro",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "
|
|
4
|
+
"version": "7.0.0",
|
|
5
5
|
"private": false,
|
|
6
6
|
"packageManager": "pnpm@9.13.2",
|
|
7
7
|
"description": "Official Astro integration for the Storyblok Headless CMS",
|
|
@@ -73,7 +73,7 @@
|
|
|
73
73
|
"astro": "^3.0.0 || ^4.0.0 || ^5.0.0"
|
|
74
74
|
},
|
|
75
75
|
"dependencies": {
|
|
76
|
-
"@storyblok/js": "
|
|
76
|
+
"@storyblok/js": "4.0.0",
|
|
77
77
|
"camelcase": "^8.0.0"
|
|
78
78
|
},
|
|
79
79
|
"devDependencies": {
|