@storyblok/astro
Advanced tools
Comparing version 1.2.0 to 2.0.0
@@ -1,15 +0,15 @@ | ||
(function(i,c){typeof exports=="object"&&typeof module<"u"?c(exports,require("axios")):typeof define=="function"&&define.amd?define(["exports","axios"],c):(i=typeof globalThis<"u"?globalThis:i||self,c(i.storyblokAstro={}))})(this,function(i){"use strict";function c(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` | ||
(function(l,c){typeof exports=="object"&&typeof module<"u"?c(exports):typeof define=="function"&&define.amd?define(["exports"],c):(l=typeof globalThis<"u"?globalThis:l||self,c(l.storyblokAstro={}))})(this,function(l){"use strict";function c(t,e,r){const o="virtual:storyblok-init",s="\0"+o;return{name:"vite-plugin-storyblok-init",async resolveId(n){if(n===o)return s},async load(n){if(n===s)return` | ||
import { storyblokInit, apiPlugin } from "@storyblok/js"; | ||
const { storyblokApi } = storyblokInit({ | ||
accessToken: "${r}", | ||
accessToken: "${t}", | ||
use: ${e?"[]":"[apiPlugin]"}, | ||
apiOptions: ${JSON.stringify(t)}, | ||
apiOptions: ${JSON.stringify(r)}, | ||
}); | ||
export const storyblokApiInstance = storyblokApi; | ||
`}}}const T=/[\p{Lu}]/u,I=/[\p{Ll}]/u,d=/^[\p{Lu}](?![\p{Lu}])/gu,f=/([\p{Alpha}\p{N}_]|$)/u,u=/[_.\- ]+/,E=new RegExp("^"+u.source),h=new RegExp(u.source+f.source,"gu"),p=new RegExp("\\d+"+f.source,"gu"),A=(r,e,t)=>{let o=!1,n=!1,s=!1;for(let l=0;l<r.length;l++){const a=r[l];o&&T.test(a)?(r=r.slice(0,l)+"-"+r.slice(l),o=!1,s=n,n=!0,l++):n&&s&&I.test(a)?(r=r.slice(0,l-1)+"-"+r.slice(l-1),s=n,n=!1,o=!0):(o=e(a)===a&&t(a)!==a,s=n,n=t(a)===a&&e(a)!==a)}return r},S=(r,e)=>(d.lastIndex=0,r.replace(d,t=>e(t))),w=(r,e)=>(h.lastIndex=0,p.lastIndex=0,r.replace(h,(t,o)=>e(o)).replace(p,t=>e(t)));function g(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?u.test(r)?"":e.pascalCase?o(r):t(r):(r!==t(r)&&(r=A(r,t,o)),r=r.replace(E,""),r=e.preserveConsecutiveUppercase?S(r,t):t(r),e.pascalCase&&(r=o(r.charAt(0))+r.slice(1)),w(r,o))}function _(r){const e="virtual:storyblok-components",t="\0"+e;return{name:"vite-plugin-storyblok-components",async resolveId(o){if(o===e)return t},async load(o){if(o===t){const n=[];for await(const[s,l]of Object.entries(r)){const{id:a}=await this.resolve("/src/"+l+".astro");n.push(`import ${g(s)} from "${a}"`)}return`${n.join(";")};export default {${Object.keys(r).map(s=>g(s)).join(",")}}`}}}}var R=Object.defineProperty,y=Object.getOwnPropertySymbols,C=Object.prototype.hasOwnProperty,$=Object.prototype.propertyIsEnumerable,b=(r,e,t)=>e in r?R(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,x=(r,e)=>{for(var t in e||(e={}))C.call(e,t)&&b(r,t,e[t]);if(y)for(var t of y(e))$.call(e,t)&&b(r,t,e[t]);return r};let k=!1;const m=[],O=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}k?n():m.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=>{m.forEach(s=>s()),k=!0,e(n)},document.getElementsByTagName("head")[0].appendChild(o)}),P=function(r,e){if(!r)return null;let t={};for(let o in r){let n=r[o];e.indexOf(o)>-1&&n!==null&&(t[o]=n)}return t},N=r=>r==="email";var v={nodes:{horizontal_rule(){return{singleTag:"hr"}},blockquote(){return{tag:"blockquote"}},bullet_list(){return{tag:"ul"}},code_block(r){return{tag:["pre",{tag:"code",attrs:r.attrs}]}},hard_break(){return{singleTag:"br"}},heading(r){return{tag:`h${r.attrs.level}`}},image(r){return{singleTag:[{tag:"img",attrs:P(r.attrs,["src","alt","title"])}]}},list_item(){return{tag:"li"}},ordered_list(){return{tag:"ol"}},paragraph(){return{tag:"p"}}},marks:{bold(){return{tag:"b"}},strike(){return{tag:"strike"}},underline(){return{tag:"u"}},strong(){return{tag:"strong"}},code(){return{tag:"code"}},italic(){return{tag:"i"}},link(r){const e=x({},r.attrs),{linktype:t="url"}=r.attrs;return N(t)&&(e.href=`mailto:${e.href}`),e.anchor&&(e.href=`${e.href}#${e.anchor}`,delete e.anchor),{tag:[{tag:"a",attrs:e}]}},styled(r){return{tag:[{tag:"span",attrs:r.attrs}]}}}};const j=function(r){const e={"&":"&","<":"<",">":">",'"':""","'":"'"},t=/[&<>"']/g,o=RegExp(t.source);return r&&o.test(r)?r.replace(t,n=>e[n]):r};class L{constructor(e){e||(e=v),this.marks=e.marks||[],this.nodes=e.nodes||[]}addNode(e,t){this.nodes[e]=t}addMark(e,t){this.marks[e]=t}render(e={}){if(e.content&&Array.isArray(e.content)){let t="";return e.content.forEach(o=>{t+=this.renderNode(o)}),t}return console.warn("The render method must receive an object with a content field, which is an array"),""}renderNode(e){let t=[];e.marks&&e.marks.forEach(n=>{const s=this.getMatchingMark(n);s&&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(j(e.text)):o&&o.singleTag?t.push(this.renderTag(o.singleTag," /")):o&&o.html&&t.push(o.html),o&&o.tag&&t.push(this.renderClosingTag(o.tag)),e.marks&&e.marks.slice(0).reverse().forEach(n=>{const s=this.getMatchingMark(n);s&&t.push(this.renderClosingTag(s.tag))}),t.join("")}renderTag(e,t){return e.constructor===String?`<${e}${t}>`:e.map(n=>{if(n.constructor===String)return`<${n}${t}>`;{let s=`<${n.tag}`;if(n.attrs)for(let l in n.attrs){let a=n.attrs[l];a!==null&&(s+=` ${l}="${a}"`)}return`${s}${t}>`}}).join("")}renderOpeningTag(e){return this.renderTag(e,"")}renderClosingTag(e){return e.constructor===String?`</${e}>`:e.slice(0).reverse().map(o=>o.constructor===String?`</${o}>`:`</${o.tag}>`).join("")}getMatchingNode(e){if(typeof this.nodes[e.type]=="function")return this.nodes[e.type](e)}getMatchingMark(e){if(typeof this.marks[e.type]=="function")return this.marks[e.type](e)}}var M=r=>{if(typeof r!="object"||typeof r._editable>"u")return{};const e=JSON.parse(r._editable.replace(/^<!--#storyblok#/,"").replace(/-->$/,""));return{"data-blok-c":JSON.stringify(e),"data-blok-uid":e.id+"-"+e.uid}};let B;const U="https://app.storyblok.com/f/storyblok-v2-latest.js",D=(r,e)=>{r.addNode("blok",t=>{let o="";return t.attrs.body.forEach(n=>{o+=e(n.component,n)}),{html:o}})},z=(r,e,t)=>{let o=t||B;if(!o){console.error("Please initialize the Storyblok SDK before calling the renderRichText function");return}return r===""?"":r?(e&&(o=new L(e.schema),e.resolver&&D(o,e.resolver)),o.render(r)):(console.warn(`${r} is not a valid Richtext object. This might be because the value of the richtext field is empty. | ||
export const storyblokApiInstance = storyblokApi; | ||
`}}}const A=/[\p{Lu}]/u,E=/[\p{Ll}]/u,d=/^[\p{Lu}](?![\p{Lu}])/gu,g=/([\p{Alpha}\p{N}_]|$)/u,u=/[_.\- ]+/,w=new RegExp("^"+u.source),f=new RegExp(u.source+g.source,"gu"),h=new RegExp("\\d+"+g.source,"gu"),S=(t,e,r)=>{let o=!1,s=!1,n=!1;for(let a=0;a<t.length;a++){const i=t[a];o&&A.test(i)?(t=t.slice(0,a)+"-"+t.slice(a),o=!1,n=s,s=!0,a++):s&&n&&E.test(i)?(t=t.slice(0,a-1)+"-"+t.slice(a-1),n=s,s=!1,o=!0):(o=e(i)===i&&r(i)!==i,n=s,s=r(i)===i&&e(i)!==i)}return t},R=(t,e)=>(d.lastIndex=0,t.replace(d,r=>e(r))),_=(t,e)=>(f.lastIndex=0,h.lastIndex=0,t.replace(f,(r,o)=>e(o)).replace(h,r=>e(r)));function p(t,e){if(!(typeof t=="string"||Array.isArray(t)))throw new TypeError("Expected the input to be `string | string[]`");if(e={pascalCase:!1,preserveConsecutiveUppercase:!1,...e},Array.isArray(t)?t=t.map(n=>n.trim()).filter(n=>n.length).join("-"):t=t.trim(),t.length===0)return"";const r=e.locale===!1?n=>n.toLowerCase():n=>n.toLocaleLowerCase(e.locale),o=e.locale===!1?n=>n.toUpperCase():n=>n.toLocaleUpperCase(e.locale);return t.length===1?u.test(t)?"":e.pascalCase?o(t):r(t):(t!==r(t)&&(t=S(t,r,o)),t=t.replace(w,""),t=e.preserveConsecutiveUppercase?R(t,r):r(t),e.pascalCase&&(t=o(t.charAt(0))+t.slice(1)),_(t,o))}function C(t){const e="virtual:storyblok-components",r="\0"+e;return{name:"vite-plugin-storyblok-components",async resolveId(o){if(o===e)return r},async load(o){if(o===r){const s=[];for await(const[n,a]of Object.entries(t)){const{id:i}=await this.resolve("/src/"+a+".astro");s.push(`import ${p(n)} from "${i}"`)}return`${s.join(";")};export default {${Object.keys(t).map(n=>p(n)).join(",")}}`}}}}var $=Object.defineProperty,b=Object.getOwnPropertySymbols,O=Object.prototype.hasOwnProperty,x=Object.prototype.propertyIsEnumerable,y=(t,e,r)=>e in t?$(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,P=(t,e)=>{for(var r in e||(e={}))O.call(e,r)&&y(t,r,e[r]);if(b)for(var r of b(e))x.call(e,r)&&y(t,r,e[r]);return t};let m=!1;const k=[],j=t=>new Promise((e,r)=>{if(typeof window>"u"||(window.storyblokRegisterEvent=s=>{if(window.location===window.parent.location){console.warn("You are not in Draft Mode or in the Visual Editor.");return}m?s():k.push(s)},document.getElementById("storyblok-javascript-bridge")))return;const o=document.createElement("script");o.async=!0,o.src=t,o.id="storyblok-javascript-bridge",o.onerror=s=>r(s),o.onload=s=>{k.forEach(n=>n()),m=!0,e(s)},document.getElementsByTagName("head")[0].appendChild(o)});var N=Object.defineProperty,L=(t,e,r)=>e in t?N(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,v=(t,e,r)=>(L(t,typeof e!="symbol"?e+"":e,r),r);const M=function(t,e){const r={};for(const o in t){const s=t[o];e.indexOf(o)>-1&&s!==null&&(r[o]=s)}return r},U=t=>t==="email",B=()=>({singleTag:"hr"}),D=()=>({tag:"blockquote"}),z=()=>({tag:"ul"}),F=t=>({tag:["pre",{tag:"code",attrs:t.attrs}]}),V=()=>({singleTag:"br"}),q=t=>({tag:`h${t.attrs.level}`}),J=t=>({singleTag:[{tag:"img",attrs:M(t.attrs,["src","alt","title"])}]}),G=()=>({tag:"li"}),K=()=>({tag:"ol"}),H=()=>({tag:"p"}),W=()=>({tag:"b"}),Y=()=>({tag:"strike"}),Q=()=>({tag:"u"}),X=()=>({tag:"strong"}),Z=()=>({tag:"code"}),ee=()=>({tag:"i"}),te=t=>{const e=P({},t.attrs),{linktype:r="url"}=t.attrs;return U(r)&&(e.href=`mailto:${e.href}`),e.anchor&&(e.href=`${e.href}#${e.anchor}`,delete e.anchor),{tag:[{tag:"a",attrs:e}]}},re=t=>({tag:[{tag:"span",attrs:t.attrs}]}),T={nodes:{horizontal_rule:B,blockquote:D,bullet_list:z,code_block:F,hard_break:V,heading:q,image:J,list_item:G,ordered_list:K,paragraph:H},marks:{bold:W,strike:Y,underline:Q,strong:X,code:Z,italic:ee,link:te,styled:re}},oe=function(t){const e={"&":"&","<":"<",">":">",'"':""","'":"'"},r=/[&<>"']/g,o=RegExp(r.source);return t&&o.test(t)?t.replace(r,s=>e[s]):t};class I{constructor(e){v(this,"marks"),v(this,"nodes"),e||(e=T),this.marks=e.marks||[],this.nodes=e.nodes||[]}addNode(e,r){this.nodes[e]=r}addMark(e,r){this.marks[e]=r}render(e){if(e&&e.content&&Array.isArray(e.content)){let r="";return e.content.forEach(o=>{r+=this.renderNode(o)}),r}return console.warn("The render method must receive an object with a content field, which is an array"),""}renderNode(e){const r=[];e.marks&&e.marks.forEach(s=>{const n=this.getMatchingMark(s);n&&r.push(this.renderOpeningTag(n.tag))});const o=this.getMatchingNode(e);return o&&o.tag&&r.push(this.renderOpeningTag(o.tag)),e.content?e.content.forEach(s=>{r.push(this.renderNode(s))}):e.text?r.push(oe(e.text)):o&&o.singleTag?r.push(this.renderTag(o.singleTag," /")):o&&o.html&&r.push(o.html),o&&o.tag&&r.push(this.renderClosingTag(o.tag)),e.marks&&e.marks.slice(0).reverse().forEach(s=>{const n=this.getMatchingMark(s);n&&r.push(this.renderClosingTag(n.tag))}),r.join("")}renderTag(e,r){return e.constructor===String?`<${e}${r}>`:e.map(o=>{if(o.constructor===String)return`<${o}${r}>`;{let s=`<${o.tag}`;if(o.attrs)for(const n in o.attrs){const a=o.attrs[n];a!==null&&(s+=` ${n}="${a}"`)}return`${s}${r}>`}}).join("")}renderOpeningTag(e){return this.renderTag(e,"")}renderClosingTag(e){return e.constructor===String?`</${e}>`:e.slice(0).reverse().map(r=>r.constructor===String?`</${r}>`:`</${r.tag}>`).join("")}getMatchingNode(e){const r=this.nodes[e.type];if(typeof r=="function")return r(e)}getMatchingMark(e){const r=this.marks[e.type];if(typeof r=="function")return r(e)}}var se=t=>{if(typeof t!="object"||typeof t._editable>"u")return{};const e=JSON.parse(t._editable.replace(/^<!--#storyblok#/,"").replace(/-->$/,""));return{"data-blok-c":JSON.stringify(e),"data-blok-uid":e.id+"-"+e.uid}};let ne;const ae="https://app.storyblok.com/f/storyblok-v2-latest.js",le=(t,e)=>{t.addNode("blok",r=>{let o="";return r.attrs.body.forEach(s=>{o+=e(s.component,s)}),{html:o}})},ie=(t,e,r)=>{let o=r||ne;if(!o){console.error("Please initialize the Storyblok SDK before calling the renderRichText function");return}return t===""?"":t?(e&&(o=new I(e.schema),e.resolver&&le(o,e.resolver)),o.render(t)):(console.warn(`${t} is not a valid Richtext object. This might be because the value of the richtext field is empty. | ||
For more info about the richtext object check https://github.com/storyblok/storyblok-js#rendering-rich-text`),"")},H=()=>O(U);function q(){return globalThis.storyblokApiInstance||console.error("storyblokApiInstance has not been initialized correctly"),storyblokApiInstance}function F(r,e){const t=globalThis.storyblokApiInstance.richTextResolver;if(!t){console.error("Please initialize the Storyblok SDK before calling the renderRichText function");return}return z(r,e,t)}function V(r){return{name:"@storyblok/astro",hooks:{"astro:config:setup":({injectScript:e,updateConfig:t})=>{var n;t({vite:{plugins:[c(r.accessToken,r.useCustomApi,r.apiOptions),_(r.components)]}}),e("page-ssr",` | ||
For more info about the richtext object check https://github.com/storyblok/storyblok-js#rendering-rich-text`),"")},ce=()=>j(ae);function ue(){return globalThis.storyblokApiInstance||console.error("storyblokApiInstance has not been initialized correctly"),globalThis.storyblokApiInstance}function de(t,e){const r=globalThis.storyblokApiInstance.richTextResolver;if(!r){console.error("Please initialize the Storyblok SDK before calling the renderRichText function");return}return ie(t,e,r)}function ge(t={accessToken:"",useCustomApi:!1,apiOptions:{},bridge:!0,components:{}}){return{name:"@storyblok/astro",hooks:{"astro:config:setup":({injectScript:e,updateConfig:r})=>{r({vite:{plugins:[c(t.accessToken,t.useCustomApi,t.apiOptions),C(t.components)]}}),e("page-ssr",` | ||
import { storyblokApiInstance } from "virtual:storyblok-init"; | ||
globalThis.storyblokApiInstance = storyblokApiInstance; | ||
`),((n=r.bridge)!=null?n:!0)&&e("page",` | ||
`),t.bridge&&e("page",` | ||
import { loadStoryblokBridge } from "@storyblok/astro"; | ||
@@ -26,2 +26,2 @@ loadStoryblokBridge().then(() => { | ||
}); | ||
`)}}}}i.RichTextSchema=v,i.default=V,i.loadStoryblokBridge=H,i.renderRichText=F,i.storyblokEditable=M,i.useStoryblokApi=q,Object.defineProperties(i,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}); | ||
`)}}}}l.RichTextResolver=I,l.RichTextSchema=T,l.default=ge,l.loadStoryblokBridge=ce,l.renderRichText=de,l.storyblokEditable=se,l.useStoryblokApi=ue,Object.defineProperties(l,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}); |
{ | ||
"name": "@storyblok/astro", | ||
"version": "1.2.0", | ||
"version": "2.0.0", | ||
"description": "Official Astro integration for the Storyblok Headless CMS", | ||
@@ -18,5 +18,6 @@ "main": "./dist/storyblok-astro.js", | ||
}, | ||
"types": "./dist/index.d.ts", | ||
"scripts": { | ||
"dev": "vite build --watch", | ||
"build": "vite build", | ||
"build": "vite build && tsc", | ||
"test": "npm run test:e2e", | ||
@@ -31,13 +32,15 @@ "test:e2e": "start-server-and-test cy:playground http-get://localhost:3000/ cy:run", | ||
"dependencies": { | ||
"@storyblok/js": "^1.8.6", | ||
"@storyblok/js": "^2.0.4", | ||
"camelcase": "^7.0.0" | ||
}, | ||
"devDependencies": { | ||
"@cypress/vite-dev-server": "^2.0.7", | ||
"@rollup/plugin-dynamic-import-vars": "^1.4.4", | ||
"axios": "^0.27.2", | ||
"cypress": "^10.9.0", | ||
"@cypress/vite-dev-server": "^5.0.2", | ||
"@rollup/plugin-dynamic-import-vars": "^2.0.1", | ||
"cypress": "^12.1.0", | ||
"eslint-plugin-cypress": "^2.12.1", | ||
"start-server-and-test": "^1.14.0", | ||
"vite": "^3.2.4" | ||
"start-server-and-test": "^1.15.2", | ||
"vite": "^4.0.1", | ||
"typescript": "4.9.4", | ||
"@types/node": "18.11.10", | ||
"astro": "1.6.15" | ||
}, | ||
@@ -44,0 +47,0 @@ "repository": { |
@@ -62,2 +62,4 @@ <div align="center"> | ||
> ⚠️ This SDK uses the Fetch API under the hood. If your environment doesn't support it, you need to install a polyfill like [isomorphic-fetch](https://github.com/matthew-andrews/isomorphic-fetch). More info on [storyblok-js-client docs](https://github.com/storyblok/storyblok-js-client#fetch-use-polyfill-if-needed---version-5). | ||
### Options | ||
@@ -64,0 +66,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
34280
0
286
9
398
+ Added@storyblok/js@2.3.0(transitive)
+ Addedstoryblok-js-client@5.14.4(transitive)
- Removed@storyblok/js@1.8.6(transitive)
- Removedasynckit@0.4.0(transitive)
- Removedaxios@0.27.2(transitive)
- Removedcall-bind-apply-helpers@1.0.2(transitive)
- Removedcombined-stream@1.0.8(transitive)
- Removeddelayed-stream@1.0.0(transitive)
- Removeddunder-proto@1.0.1(transitive)
- Removedes-define-property@1.0.1(transitive)
- Removedes-errors@1.3.0(transitive)
- Removedes-object-atoms@1.1.1(transitive)
- Removedes-set-tostringtag@2.1.0(transitive)
- Removedfollow-redirects@1.15.9(transitive)
- Removedform-data@4.0.2(transitive)
- Removedfunction-bind@1.1.2(transitive)
- Removedget-intrinsic@1.2.7(transitive)
- Removedget-proto@1.0.1(transitive)
- Removedgopd@1.2.0(transitive)
- Removedhas-symbols@1.1.0(transitive)
- Removedhas-tostringtag@1.0.2(transitive)
- Removedhasown@2.0.2(transitive)
- Removedmath-intrinsics@1.1.0(transitive)
- Removedmime-db@1.52.0(transitive)
- Removedmime-types@2.1.35(transitive)
- Removedstoryblok-js-client@4.5.8(transitive)
Updated@storyblok/js@^2.0.4