@storyblok/astro
Advanced tools
Comparing version 2.0.3 to 2.0.4
@@ -1,2 +0,2 @@ | ||
(function(a,u){typeof exports=="object"&&typeof module<"u"?u(exports):typeof define=="function"&&define.amd?define(["exports"],u):(a=typeof globalThis<"u"?globalThis:a||self,u(a.storyblokAstro={}))})(this,function(a){"use strict";function u(t,e,r){const o="virtual:storyblok-init",n="\0"+o;return{name:"vite-plugin-storyblok-init",async resolveId(s){if(s===o)return n},async load(s){if(s===n)return` | ||
(function(a,d){typeof exports=="object"&&typeof module<"u"?d(exports):typeof define=="function"&&define.amd?define(["exports"],d):(a=typeof globalThis<"u"?globalThis:a||self,d(a.storyblokAstro={}))})(this,function(a){"use strict";function d(t,e,r){const o="virtual:storyblok-init",n="\0"+o;return{name:"vite-plugin-storyblok-init",async resolveId(s){if(s===o)return n},async load(s){if(s===n)return` | ||
import { storyblokInit, apiPlugin } from "@storyblok/js"; | ||
@@ -9,5 +9,5 @@ const { storyblokApi } = storyblokInit({ | ||
export const storyblokApiInstance = storyblokApi; | ||
`}}}const w=/[\p{Lu}]/u,S=/[\p{Ll}]/u,f=/^[\p{Lu}](?![\p{Lu}])/gu,h=/([\p{Alpha}\p{N}_]|$)/u,g=/[_.\- ]+/,C=new RegExp("^"+g.source),p=new RegExp(g.source+h.source,"gu"),b=new RegExp("\\d+"+h.source,"gu"),R=(t,e,r,o)=>{let n=!1,s=!1,c=!1,d=!1;for(let i=0;i<t.length;i++){const l=t[i];d=i>2?t[i-3]==="-":!0,n&&w.test(l)?(t=t.slice(0,i)+"-"+t.slice(i),n=!1,c=s,s=!0,i++):s&&c&&S.test(l)&&(!d||o)?(t=t.slice(0,i-1)+"-"+t.slice(i-1),c=s,s=!1,n=!0):(n=e(l)===l&&r(l)!==l,c=s,s=r(l)===l&&e(l)!==l)}return t},_=(t,e)=>(f.lastIndex=0,t.replace(f,r=>e(r))),$=(t,e)=>(p.lastIndex=0,b.lastIndex=0,t.replace(p,(r,o)=>e(o)).replace(b,r=>e(r)));function y(t,e){if(!(typeof t=="string"||Array.isArray(t)))throw new TypeError("Expected the input to be `string | string[]`");if(e={pascalCase:!1,preserveConsecutiveUppercase:!1,...e},Array.isArray(t)?t=t.map(s=>s.trim()).filter(s=>s.length).join("-"):t=t.trim(),t.length===0)return"";const r=e.locale===!1?s=>s.toLowerCase():s=>s.toLocaleLowerCase(e.locale),o=e.locale===!1?s=>s.toUpperCase():s=>s.toLocaleUpperCase(e.locale);return t.length===1?g.test(t)?"":e.pascalCase?o(t):r(t):(t!==r(t)&&(t=R(t,r,o,e.preserveConsecutiveUppercase)),t=t.replace(C,""),t=e.preserveConsecutiveUppercase?_(t,r):r(t),e.pascalCase&&(t=o(t.charAt(0))+t.slice(1)),$(t,o))}function O(t){const e="virtual:storyblok-components",r="\0"+e;return{name:"vite-plugin-storyblok-components",async resolveId(o){if(o===e)return r},async load(o){if(o===r){const n=[];for await(const[s,c]of Object.entries(t)){const{id:d}=await this.resolve("/src/"+c+".astro");n.push(`import ${y(s)} from "${d}"`)}return`${n.join(";")};export default {${Object.keys(t).map(s=>y(s)).join(",")}}`}}}}var P=Object.defineProperty,m=Object.getOwnPropertySymbols,x=Object.prototype.hasOwnProperty,j=Object.prototype.propertyIsEnumerable,k=(t,e,r)=>e in t?P(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,N=(t,e)=>{for(var r in e||(e={}))x.call(e,r)&&k(t,r,e[r]);if(m)for(var r of m(e))j.call(e,r)&&k(t,r,e[r]);return t};let v=!1;const T=[],L=t=>new Promise((e,r)=>{if(typeof window>"u"||(window.storyblokRegisterEvent=n=>{if(window.location===window.parent.location){console.warn("You are not in Draft Mode or in the Visual Editor.");return}v?n():T.push(n)},document.getElementById("storyblok-javascript-bridge")))return;const o=document.createElement("script");o.async=!0,o.src=t,o.id="storyblok-javascript-bridge",o.onerror=n=>r(n),o.onload=n=>{T.forEach(s=>s()),v=!0,e(n)},document.getElementsByTagName("head")[0].appendChild(o)});var M=Object.defineProperty,U=(t,e,r)=>e in t?M(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,I=(t,e,r)=>(U(t,typeof e!="symbol"?e+"":e,r),r);const B=function(t,e){const r={};for(const o in t){const n=t[o];e.indexOf(o)>-1&&n!==null&&(r[o]=n)}return r},D=t=>t==="email",z=()=>({singleTag:"hr"}),F=()=>({tag:"blockquote"}),V=()=>({tag:"ul"}),q=t=>({tag:["pre",{tag:"code",attrs:t.attrs}]}),J=()=>({singleTag:"br"}),G=t=>({tag:`h${t.attrs.level}`}),K=t=>({singleTag:[{tag:"img",attrs:B(t.attrs,["src","alt","title"])}]}),H=()=>({tag:"li"}),W=()=>({tag:"ol"}),Y=()=>({tag:"p"}),Q=()=>({tag:"b"}),X=()=>({tag:"strike"}),Z=()=>({tag:"u"}),ee=()=>({tag:"strong"}),te=()=>({tag:"code"}),re=()=>({tag:"i"}),oe=t=>{const e=N({},t.attrs),{linktype:r="url"}=t.attrs;return D(r)&&(e.href=`mailto:${e.href}`),e.anchor&&(e.href=`${e.href}#${e.anchor}`,delete e.anchor),{tag:[{tag:"a",attrs:e}]}},se=t=>({tag:[{tag:"span",attrs:t.attrs}]}),A={nodes:{horizontal_rule:z,blockquote:F,bullet_list:V,code_block:q,hard_break:J,heading:G,image:K,list_item:H,ordered_list:W,paragraph:Y},marks:{bold:Q,strike:X,underline:Z,strong:ee,code:te,italic:re,link:oe,styled:se}},ne=function(t){const e={"&":"&","<":"<",">":">",'"':""","'":"'"},r=/[&<>"']/g,o=RegExp(r.source);return t&&o.test(t)?t.replace(r,n=>e[n]):t};class E{constructor(e){I(this,"marks"),I(this,"nodes"),e||(e=A),this.marks=e.marks||[],this.nodes=e.nodes||[]}addNode(e,r){this.nodes[e]=r}addMark(e,r){this.marks[e]=r}render(e){if(e&&e.content&&Array.isArray(e.content)){let r="";return e.content.forEach(o=>{r+=this.renderNode(o)}),r}return console.warn("The render method must receive an object with a content field, which is an array"),""}renderNode(e){const r=[];e.marks&&e.marks.forEach(n=>{const s=this.getMatchingMark(n);s&&r.push(this.renderOpeningTag(s.tag))});const o=this.getMatchingNode(e);return o&&o.tag&&r.push(this.renderOpeningTag(o.tag)),e.content?e.content.forEach(n=>{r.push(this.renderNode(n))}):e.text?r.push(ne(e.text)):o&&o.singleTag?r.push(this.renderTag(o.singleTag," /")):o&&o.html&&r.push(o.html),o&&o.tag&&r.push(this.renderClosingTag(o.tag)),e.marks&&e.marks.slice(0).reverse().forEach(n=>{const s=this.getMatchingMark(n);s&&r.push(this.renderClosingTag(s.tag))}),r.join("")}renderTag(e,r){return e.constructor===String?`<${e}${r}>`:e.map(o=>{if(o.constructor===String)return`<${o}${r}>`;{let n=`<${o.tag}`;if(o.attrs)for(const s in o.attrs){const c=o.attrs[s];c!==null&&(n+=` ${s}="${c}"`)}return`${n}${r}>`}}).join("")}renderOpeningTag(e){return this.renderTag(e,"")}renderClosingTag(e){return e.constructor===String?`</${e}>`:e.slice(0).reverse().map(r=>r.constructor===String?`</${r}>`:`</${r.tag}>`).join("")}getMatchingNode(e){const r=this.nodes[e.type];if(typeof r=="function")return r(e)}getMatchingMark(e){const r=this.marks[e.type];if(typeof r=="function")return r(e)}}var ae=t=>{if(typeof t!="object"||typeof t._editable>"u")return{};const e=JSON.parse(t._editable.replace(/^<!--#storyblok#/,"").replace(/-->$/,""));return{"data-blok-c":JSON.stringify(e),"data-blok-uid":e.id+"-"+e.uid}};let ie;const le="https://app.storyblok.com/f/storyblok-v2-latest.js",ce=(t,e)=>{t.addNode("blok",r=>{let o="";return r.attrs.body.forEach(n=>{o+=e(n.component,n)}),{html:o}})},ue=(t,e,r)=>{let o=r||ie;if(!o){console.error("Please initialize the Storyblok SDK before calling the renderRichText function");return}return t===""?"":t?(e&&(o=new E(e.schema),e.resolver&&ce(o,e.resolver)),o.render(t)):(console.warn(`${t} is not a valid Richtext object. This might be because the value of the richtext field is empty. | ||
`}}}const I=/[\p{Lu}]/u,E=/[\p{Ll}]/u,h=/^[\p{Lu}](?![\p{Lu}])/gu,f=/([\p{Alpha}\p{N}_]|$)/u,g=/[_.\- ]+/,S=new RegExp("^"+g.source),p=new RegExp(g.source+f.source,"gu"),b=new RegExp("\\d+"+f.source,"gu"),C=(t,e,r,o)=>{let n=!1,s=!1,c=!1,u=!1;for(let i=0;i<t.length;i++){const l=t[i];u=i>2?t[i-3]==="-":!0,n&&I.test(l)?(t=t.slice(0,i)+"-"+t.slice(i),n=!1,c=s,s=!0,i++):s&&c&&E.test(l)&&(!u||o)?(t=t.slice(0,i-1)+"-"+t.slice(i-1),c=s,s=!1,n=!0):(n=e(l)===l&&r(l)!==l,c=s,s=r(l)===l&&e(l)!==l)}return t},w=(t,e)=>(h.lastIndex=0,t.replace(h,r=>e(r))),R=(t,e)=>(p.lastIndex=0,b.lastIndex=0,t.replace(p,(r,o)=>e(o)).replace(b,r=>e(r)));function y(t,e){if(!(typeof t=="string"||Array.isArray(t)))throw new TypeError("Expected the input to be `string | string[]`");if(e={pascalCase:!1,preserveConsecutiveUppercase:!1,...e},Array.isArray(t)?t=t.map(s=>s.trim()).filter(s=>s.length).join("-"):t=t.trim(),t.length===0)return"";const r=e.locale===!1?s=>s.toLowerCase():s=>s.toLocaleLowerCase(e.locale),o=e.locale===!1?s=>s.toUpperCase():s=>s.toLocaleUpperCase(e.locale);return t.length===1?g.test(t)?"":e.pascalCase?o(t):r(t):(t!==r(t)&&(t=C(t,r,o,e.preserveConsecutiveUppercase)),t=t.replace(S,""),t=e.preserveConsecutiveUppercase?w(t,r):r(t),e.pascalCase&&(t=o(t.charAt(0))+t.slice(1)),R(t,o))}function $(t){const e="virtual:storyblok-components",r="\0"+e;return{name:"vite-plugin-storyblok-components",async resolveId(o){if(o===e)return r},async load(o){if(o===r){const n=[];for await(const[s,c]of Object.entries(t)){const{id:u}=await this.resolve("/src/"+c+".astro");n.push(`import ${y(s)} from "${u}"`)}return`${n.join(";")};export default {${Object.keys(t).map(s=>y(s)).join(",")}}`}}}}let k=!1;const m=[],x=t=>new Promise((e,r)=>{if(typeof window>"u"||(window.storyblokRegisterEvent=n=>{if(window.location===window.parent.location){console.warn("You are not in Draft Mode or in the Visual Editor.");return}k?n():m.push(n)},document.getElementById("storyblok-javascript-bridge")))return;const o=document.createElement("script");o.async=!0,o.src=t,o.id="storyblok-javascript-bridge",o.onerror=n=>r(n),o.onload=n=>{m.forEach(s=>s()),k=!0,e(n)},document.getElementsByTagName("head")[0].appendChild(o)});var N=Object.defineProperty,j=(t,e,r)=>e in t?N(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,v=(t,e,r)=>(j(t,typeof e!="symbol"?e+"":e,r),r);const L=function(t,e){const r={};for(const o in t){const n=t[o];e.indexOf(o)>-1&&n!==null&&(r[o]=n)}return r},_=t=>t==="email",O=()=>({singleTag:"hr"}),M=()=>({tag:"blockquote"}),P=()=>({tag:"ul"}),U=t=>({tag:["pre",{tag:"code",attrs:t.attrs}]}),D=()=>({singleTag:"br"}),B=t=>({tag:`h${t.attrs.level}`}),z=t=>({singleTag:[{tag:"img",attrs:L(t.attrs,["src","alt","title"])}]}),F=()=>({tag:"li"}),q=()=>({tag:"ol"}),J=()=>({tag:"p"}),V=()=>({tag:"b"}),K=()=>({tag:"strike"}),G=()=>({tag:"u"}),Y=()=>({tag:"strong"}),H=()=>({tag:"code"}),Q=()=>({tag:"i"}),W=t=>{const e={...t.attrs},{linktype:r="url"}=t.attrs;return _(r)&&(e.href=`mailto:${e.href}`),e.anchor&&(e.href=`${e.href}#${e.anchor}`,delete e.anchor),{tag:[{tag:"a",attrs:e}]}},Z=t=>({tag:[{tag:"span",attrs:t.attrs}]}),T={nodes:{horizontal_rule:O,blockquote:M,bullet_list:P,code_block:U,hard_break:D,heading:B,image:z,list_item:F,ordered_list:q,paragraph:J},marks:{bold:V,strike:K,underline:G,strong:Y,code:H,italic:Q,link:W,styled:Z}},X=function(t){const e={"&":"&","<":"<",">":">",'"':""","'":"'"},r=/[&<>"']/g,o=RegExp(r.source);return t&&o.test(t)?t.replace(r,n=>e[n]):t};class A{constructor(e){v(this,"marks"),v(this,"nodes"),e||(e=T),this.marks=e.marks||[],this.nodes=e.nodes||[]}addNode(e,r){this.nodes[e]=r}addMark(e,r){this.marks[e]=r}render(e){if(e&&e.content&&Array.isArray(e.content)){let r="";return e.content.forEach(o=>{r+=this.renderNode(o)}),r}return console.warn("The render method must receive an object with a content field, which is an array"),""}renderNode(e){const r=[];e.marks&&e.marks.forEach(n=>{const s=this.getMatchingMark(n);s&&r.push(this.renderOpeningTag(s.tag))});const o=this.getMatchingNode(e);return o&&o.tag&&r.push(this.renderOpeningTag(o.tag)),e.content?e.content.forEach(n=>{r.push(this.renderNode(n))}):e.text?r.push(X(e.text)):o&&o.singleTag?r.push(this.renderTag(o.singleTag," /")):o&&o.html&&r.push(o.html),o&&o.tag&&r.push(this.renderClosingTag(o.tag)),e.marks&&e.marks.slice(0).reverse().forEach(n=>{const s=this.getMatchingMark(n);s&&r.push(this.renderClosingTag(s.tag))}),r.join("")}renderTag(e,r){return e.constructor===String?`<${e}${r}>`:e.map(o=>{if(o.constructor===String)return`<${o}${r}>`;{let n=`<${o.tag}`;if(o.attrs)for(const s in o.attrs){const c=o.attrs[s];c!==null&&(n+=` ${s}="${c}"`)}return`${n}${r}>`}}).join("")}renderOpeningTag(e){return this.renderTag(e,"")}renderClosingTag(e){return e.constructor===String?`</${e}>`:e.slice(0).reverse().map(r=>r.constructor===String?`</${r}>`:`</${r.tag}>`).join("")}getMatchingNode(e){const r=this.nodes[e.type];if(typeof r=="function")return r(e)}getMatchingMark(e){const r=this.marks[e.type];if(typeof r=="function")return r(e)}}const ee=t=>{if(typeof t!="object"||typeof t._editable>"u")return{};const e=JSON.parse(t._editable.replace(/^<!--#storyblok#/,"").replace(/-->$/,""));return{"data-blok-c":JSON.stringify(e),"data-blok-uid":e.id+"-"+e.uid}};let te;const re="https://app.storyblok.com/f/storyblok-v2-latest.js",oe=(t,e)=>{t.addNode("blok",r=>{let o="";return r.attrs.body.forEach(n=>{o+=e(n.component,n)}),{html:o}})},se=(t,e,r)=>{let o=r||te;if(!o){console.error("Please initialize the Storyblok SDK before calling the renderRichText function");return}return t===""?"":t?(e&&(o=new A(e.schema),e.resolver&&oe(o,e.resolver)),o.render(t)):(console.warn(`${t} is not a valid Richtext object. This might be because the value of the richtext field is empty. | ||
For more info about the richtext object check https://github.com/storyblok/storyblok-js#rendering-rich-text`),"")},de=()=>L(le);function ge(){return globalThis.storyblokApiInstance||console.error("storyblokApiInstance has not been initialized correctly"),globalThis.storyblokApiInstance}function fe(t,e){const r=globalThis.storyblokApiInstance.richTextResolver;if(!r){console.error("Please initialize the Storyblok SDK before calling the renderRichText function");return}return ue(t,e,r)}function he(t){const e={useCustomApi:!1,bridge:!0,...t};return{name:"@storyblok/astro",hooks:{"astro:config:setup":({injectScript:r,updateConfig:o})=>{o({vite:{plugins:[u(e.accessToken,e.useCustomApi,e.apiOptions),O(e.components)]}}),r("page-ssr",` | ||
For more info about the richtext object check https://github.com/storyblok/storyblok-js#rendering-rich-text`),"")},ne=()=>x(re);function ae(){return globalThis.storyblokApiInstance||console.error("storyblokApiInstance has not been initialized correctly"),globalThis.storyblokApiInstance}function ie(t,e){const r=globalThis.storyblokApiInstance.richTextResolver;if(!r){console.error("Please initialize the Storyblok SDK before calling the renderRichText function");return}return se(t,e,r)}function le(t){const e={useCustomApi:!1,bridge:!0,...t};return{name:"@storyblok/astro",hooks:{"astro:config:setup":({injectScript:r,updateConfig:o})=>{o({vite:{plugins:[d(e.accessToken,e.useCustomApi,e.apiOptions),$(e.components)]}}),r("page-ssr",` | ||
import { storyblokApiInstance } from "virtual:storyblok-init"; | ||
@@ -27,2 +27,2 @@ globalThis.storyblokApiInstance = storyblokApiInstance; | ||
}); | ||
`)}}}}a.RichTextResolver=E,a.RichTextSchema=A,a.default=he,a.loadStoryblokBridge=de,a.renderRichText=fe,a.storyblokEditable=ae,a.useStoryblokApi=ge,Object.defineProperties(a,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}); | ||
`)}}}}a.RichTextResolver=A,a.RichTextSchema=T,a.default=le,a.loadStoryblokBridge=ne,a.renderRichText=ie,a.storyblokEditable=ee,a.useStoryblokApi=ae,Object.defineProperties(a,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}); |
{ | ||
"name": "@storyblok/astro", | ||
"version": "2.0.3", | ||
"version": "2.0.4", | ||
"description": "Official Astro integration for the Storyblok Headless CMS", | ||
@@ -31,3 +31,3 @@ "main": "./dist/storyblok-astro.js", | ||
"dependencies": { | ||
"@storyblok/js": "^2.0.6", | ||
"@storyblok/js": "^2.0.9", | ||
"camelcase": "^7.0.1" | ||
@@ -34,0 +34,0 @@ }, |
Sorry, the diff of this file is not supported yet
209582
5387
Updated@storyblok/js@^2.0.9