@storyblok/astro 2.5.6 → 2.5.8
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/dist/storyblok-astro.js +9 -9
- package/dist/storyblok-astro.mjs +280 -224
- package/package.json +7 -7
package/dist/storyblok-astro.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
(function(
|
|
1
|
+
(function(g,m){typeof exports=="object"&&typeof module<"u"?m(exports):typeof define=="function"&&define.amd?define(["exports"],m):(g=typeof globalThis<"u"?globalThis:g||self,m(g.storyblokAstro={}))})(this,function(g){"use strict";function m(r,t,e){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`
|
|
2
2
|
import { storyblokInit, apiPlugin } from "@storyblok/js";
|
|
3
3
|
const { storyblokApi } = storyblokInit({
|
|
4
4
|
accessToken: "${r}",
|
|
5
|
-
use: ${
|
|
6
|
-
apiOptions: ${JSON.stringify(
|
|
5
|
+
use: ${t?"[]":"[apiPlugin]"},
|
|
6
|
+
apiOptions: ${JSON.stringify(e)},
|
|
7
7
|
});
|
|
8
8
|
export const storyblokApiInstance = storyblokApi;
|
|
9
|
-
`}}}const
|
|
9
|
+
`}}}const R=/[\p{Lu}]/u,x=/[\p{Ll}]/u,$=/^[\p{Lu}](?![\p{Lu}])/gu,v=/([\p{Alpha}\p{N}_]|$)/u,b=/[_.\- ]+/,O=new RegExp("^"+b.source),I=new RegExp(b.source+v.source,"gu"),w=new RegExp("\\d+"+v.source,"gu"),M=(r,t,e,o)=>{let s=!1,n=!1,a=!1,c=!1;for(let l=0;l<r.length;l++){const i=r[l];c=l>2?r[l-3]==="-":!0,s&&R.test(i)?(r=r.slice(0,l)+"-"+r.slice(l),s=!1,a=n,n=!0,l++):n&&a&&x.test(i)&&(!c||o)?(r=r.slice(0,l-1)+"-"+r.slice(l-1),a=n,n=!1,s=!0):(s=t(i)===i&&e(i)!==i,a=n,n=e(i)===i&&t(i)!==i)}return r},N=(r,t)=>($.lastIndex=0,r.replace($,e=>t(e))),P=(r,t)=>(I.lastIndex=0,w.lastIndex=0,r.replace(I,(e,o)=>t(o)).replace(w,e=>t(e)));function T(r,t){if(!(typeof r=="string"||Array.isArray(r)))throw new TypeError("Expected the input to be `string | string[]`");if(t={pascalCase:!1,preserveConsecutiveUppercase:!1,...t},Array.isArray(r)?r=r.map(n=>n.trim()).filter(n=>n.length).join("-"):r=r.trim(),r.length===0)return"";const e=t.locale===!1?n=>n.toLowerCase():n=>n.toLocaleLowerCase(t.locale),o=t.locale===!1?n=>n.toUpperCase():n=>n.toLocaleUpperCase(t.locale);return r.length===1?b.test(r)?"":t.pascalCase?o(r):e(r):(r!==e(r)&&(r=M(r,e,o,t.preserveConsecutiveUppercase)),r=r.replace(O,""),r=t.preserveConsecutiveUppercase?N(r,e):e(r),t.pascalCase&&(r=o(r.charAt(0))+r.slice(1)),P(r,o))}function L(r,t,e,o){const s="virtual:storyblok-components",n="\0"+s;return{name:"vite-plugin-storyblok-components",async resolveId(a){if(a===s)return n},async load(a){if(a===n){const c=[],l=[];for await(const[u,d]of Object.entries(t)){const h=await this.resolve("/"+r+"/"+d+".astro");if(h)c.push(`import ${T(u)} from "${h.id}"`);else if(e)l.push(u);else throw new Error(`Component could not be found for blok "${u}"! Does "${"/"+r+"/"+d}.astro" exist?`)}let i="";if(e)if(i=",FallbackComponent",o){const u=await this.resolve("/"+r+"/"+o+".astro");if(!u)throw new Error(`Custom fallback component could not be found. Does "${"/"+r+"/"+o}.astro" exist?`);c.push(`import FallbackComponent from "${u.id}"`)}else c.push("import FallbackComponent from '@storyblok/astro/FallbackComponent.astro'");if(Object.values(t).length)return`${c.join(";")};export default {${Object.keys(t).filter(u=>!l.includes(u)).map(u=>T(u)).join(",")}${i}}`;if(e)return`${c[0]}; export default {${i.replace(",","")}}`;throw new Error(`Currently, no Storyblok components are registered in astro.config.mjs.
|
|
10
10
|
Please register your components or enable the fallback component.
|
|
11
|
-
Detailed information can be found here: https://github.com/storyblok/storyblok-astro`)}}}}function _(r){const
|
|
11
|
+
Detailed information can be found here: https://github.com/storyblok/storyblok-astro`)}}}}function _(r){const t="virtual:storyblok-options",e="\0"+t;return{name:"vite-plugin-storyblok-options",async resolveId(o){if(o===t)return e},async load(o){if(o===e)return`export default ${JSON.stringify(r)}`}}}let C=!1;const E=[],z=r=>new Promise((t,e)=>{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}C?s():E.push(s)},document.getElementById("storyblok-javascript-bridge")))return;const o=document.createElement("script");o.async=!0,o.src=r,o.id="storyblok-javascript-bridge",o.onerror=s=>e(s),o.onload=s=>{E.forEach(n=>n()),C=!0,t(s)},document.getElementsByTagName("head")[0].appendChild(o)});var U=Object.defineProperty,D=(r,t,e)=>t in r?U(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,p=(r,t,e)=>(D(r,typeof t!="symbol"?t+"":t,e),e);class q{constructor(){p(this,"isCDNUrl",(t="")=>t.indexOf("/cdn/")>-1),p(this,"getOptionsPage",(t,e=25,o=1)=>({...t,per_page:e,page:o})),p(this,"delay",t=>new Promise(e=>setTimeout(e,t))),p(this,"arrayFrom",(t=0,e)=>[...Array(t)].map(e)),p(this,"range",(t=0,e=t)=>{const o=Math.abs(e-t)||0,s=t<e?1:-1;return this.arrayFrom(o,(n,a)=>a*s+t)}),p(this,"asyncMap",async(t,e)=>Promise.all(t.map(e))),p(this,"flatMap",(t=[],e)=>t.map(e).reduce((o,s)=>[...o,...s],[])),p(this,"escapeHTML",function(t){const e={"&":"&","<":"<",">":">",'"':""","'":"'"},o=/[&<>"']/g,s=RegExp(o.source);return t&&s.test(t)?t.replace(o,n=>e[n]):t})}stringify(t,e,o){const s=[];for(const n in t){if(!Object.prototype.hasOwnProperty.call(t,n))continue;const a=t[n],c=o?"":encodeURIComponent(n);let l;typeof a=="object"?l=this.stringify(a,e?e+encodeURIComponent("["+c+"]"):c,Array.isArray(a)):l=(e?e+encodeURIComponent("["+c+"]"):c)+"="+encodeURIComponent(a),s.push(l)}return s.join("&")}getRegionURL(t){const e="api.storyblok.com",o="api-us.storyblok.com",s="app.storyblokchina.cn";switch(t){case"us":return o;case"cn":return s;default:return e}}}const F=function(r,t){const e={};for(const o in r){const s=r[o];t.indexOf(o)>-1&&s!==null&&(e[o]=s)}return e},B=r=>r==="email",J=()=>({singleTag:"hr"}),K=()=>({tag:"blockquote"}),V=()=>({tag:"ul"}),H=r=>({tag:["pre",{tag:"code",attrs:r.attrs}]}),G=()=>({singleTag:"br"}),W=r=>({tag:`h${r.attrs.level}`}),Y=r=>({singleTag:[{tag:"img",attrs:F(r.attrs,["src","alt","title"])}]}),Q=()=>({tag:"li"}),X=()=>({tag:"ol"}),Z=()=>({tag:"p"}),ee=r=>({tag:[{tag:"span",attrs:{"data-type":"emoji","data-name":r.attrs.name,emoji:r.attrs.emoji}}]}),te=()=>({tag:"b"}),re=()=>({tag:"strike"}),oe=()=>({tag:"u"}),se=()=>({tag:"strong"}),ne=()=>({tag:"code"}),ae=()=>({tag:"i"}),le=r=>{const t=new q().escapeHTML,e={...r.attrs},{linktype:o="url"}=r.attrs;if(e.href&&(e.href=t(r.attrs.href||"")),B(o)&&(e.href=`mailto:${e.href}`),e.anchor&&(e.href=`${e.href}#${e.anchor}`,delete e.anchor),e.custom){for(const s in e.custom)e[s]=e.custom[s];delete e.custom}return{tag:[{tag:"a",attrs:e}]}},ie=r=>({tag:[{tag:"span",attrs:r.attrs}]}),ce=()=>({tag:"sub"}),ue=()=>({tag:"sup"}),ge=r=>({tag:[{tag:"span",attrs:r.attrs}]}),fe=r=>{var t;return(t=r.attrs)!=null&&t.color?{tag:[{tag:"span",attrs:{style:`background-color:${r.attrs.color};`}}]}:{tag:""}},pe=r=>{var t;return(t=r.attrs)!=null&&t.color?{tag:[{tag:"span",attrs:{style:`color:${r.attrs.color}`}}]}:{tag:""}},A={nodes:{horizontal_rule:J,blockquote:K,bullet_list:V,code_block:H,hard_break:G,heading:W,image:Y,list_item:Q,ordered_list:X,paragraph:Z,emoji:ee},marks:{bold:te,strike:re,underline:oe,strong:se,code:ne,italic:ae,link:le,styled:ie,subscript:ce,superscript:ue,anchor:ge,highlight:fe,textStyle:pe}},de=function(r){const t={"&":"&","<":"<",">":">",'"':""","'":"'"},e=/[&<>"']/g,o=RegExp(e.source);return r&&o.test(r)?r.replace(e,s=>t[s]):r};class S{constructor(t){p(this,"marks"),p(this,"nodes"),t||(t=A),this.marks=t.marks||[],this.nodes=t.nodes||[]}addNode(t,e){this.nodes[t]=e}addMark(t,e){this.marks[t]=e}render(t,e={optimizeImages:!1}){if(t&&t.content&&Array.isArray(t.content)){let o="";return t.content.forEach(s=>{o+=this.renderNode(s)}),e.optimizeImages?this.optimizeImages(o,e.optimizeImages):o}return console.warn(`The render method must receive an Object with a "content" field.
|
|
12
12
|
The "content" field must be an array of nodes as the type ISbRichtext.
|
|
13
13
|
ISbRichtext:
|
|
14
14
|
content?: ISbRichtext[]
|
|
@@ -31,14 +31,14 @@ Detailed information can be found here: https://github.com/storyblok/storyblok-a
|
|
|
31
31
|
}
|
|
32
32
|
],
|
|
33
33
|
type: 'doc'
|
|
34
|
-
}`),""}optimizeImages(e
|
|
34
|
+
}`),""}optimizeImages(t,e){let o=0,s=0,n="",a="";typeof e!="boolean"&&(typeof e.width=="number"&&e.width>0&&(n+=`width="${e.width}" `,o=e.width),typeof e.height=="number"&&e.height>0&&(n+=`height="${e.height}" `,s=e.height),(e.loading==="lazy"||e.loading==="eager")&&(n+=`loading="${e.loading}" `),typeof e.class=="string"&&e.class.length>0&&(n+=`class="${e.class}" `),e.filters&&(typeof e.filters.blur=="number"&&e.filters.blur>=0&&e.filters.blur<=100&&(a+=`:blur(${e.filters.blur})`),typeof e.filters.brightness=="number"&&e.filters.brightness>=-100&&e.filters.brightness<=100&&(a+=`:brightness(${e.filters.brightness})`),e.filters.fill&&(e.filters.fill.match(/[0-9A-Fa-f]{6}/g)||e.filters.fill==="transparent")&&(a+=`:fill(${e.filters.fill})`),e.filters.format&&["webp","png","jpeg"].includes(e.filters.format)&&(a+=`:format(${e.filters.format})`),typeof e.filters.grayscale=="boolean"&&e.filters.grayscale&&(a+=":grayscale()"),typeof e.filters.quality=="number"&&e.filters.quality>=0&&e.filters.quality<=100&&(a+=`:quality(${e.filters.quality})`),e.filters.rotate&&[90,180,270].includes(e.filters.rotate)&&(a+=`:rotate(${e.filters.rotate})`),a.length>0&&(a="/filters"+a))),n.length>0&&(t=t.replace(/<img/g,`<img ${n.trim()}`));const c=o>0||s>0||a.length>0?`${o}x${s}${a}`:"";return t=t.replace(/a.storyblok.com\/f\/(\d+)\/([^.]+)\.(gif|jpg|jpeg|png|tif|tiff|bmp)/g,`a.storyblok.com/f/$1/$2.$3/m/${c}`),typeof e!="boolean"&&(e.sizes||e.srcset)&&(t=t.replace(/<img.*?src=["|'](.*?)["|']/g,l=>{var i,u;const d=l.match(/a.storyblok.com\/f\/(\d+)\/([^.]+)\.(gif|jpg|jpeg|png|tif|tiff|bmp)/g);if(d&&d.length>0){const h={srcset:(i=e.srcset)==null?void 0:i.map(f=>{if(typeof f=="number")return`//${d}/m/${f}x0${a} ${f}w`;if(typeof f=="object"&&f.length===2){let k=0,j=0;return typeof f[0]=="number"&&(k=f[0]),typeof f[1]=="number"&&(j=f[1]),`//${d}/m/${k}x${j}${a} ${k}w`}}).join(", "),sizes:(u=e.sizes)==null?void 0:u.map(f=>f).join(", ")};let y="";return h.srcset&&(y+=`srcset="${h.srcset}" `),h.sizes&&(y+=`sizes="${h.sizes}" `),l.replace(/<img/g,`<img ${y.trim()}`)}return l})),t}renderNode(t){const e=[];t.marks&&t.marks.forEach(s=>{const n=this.getMatchingMark(s);n&&n.tag!==""&&e.push(this.renderOpeningTag(n.tag))});const o=this.getMatchingNode(t);return o&&o.tag&&e.push(this.renderOpeningTag(o.tag)),t.content?t.content.forEach(s=>{e.push(this.renderNode(s))}):t.text?e.push(de(t.text)):o&&o.singleTag?e.push(this.renderTag(o.singleTag," /")):o&&o.html?e.push(o.html):t.type==="emoji"&&e.push(this.renderEmoji(t)),o&&o.tag&&e.push(this.renderClosingTag(o.tag)),t.marks&&t.marks.slice(0).reverse().forEach(s=>{const n=this.getMatchingMark(s);n&&n.tag!==""&&e.push(this.renderClosingTag(n.tag))}),e.join("")}renderTag(t,e){return t.constructor===String?`<${t}${e}>`:t.map(o=>{if(o.constructor===String)return`<${o}${e}>`;{let s=`<${o.tag}`;if(o.attrs)for(const n in o.attrs){const a=o.attrs[n];a!==null&&(s+=` ${n}="${a}"`)}return`${s}${e}>`}}).join("")}renderOpeningTag(t){return this.renderTag(t,"")}renderClosingTag(t){return t.constructor===String?`</${t}>`:t.slice(0).reverse().map(e=>e.constructor===String?`</${e}>`:`</${e.tag}>`).join("")}getMatchingNode(t){const e=this.nodes[t.type];if(typeof e=="function")return e(t)}getMatchingMark(t){const e=this.marks[t.type];if(typeof e=="function")return e(t)}renderEmoji(t){if(t.attrs.emoji)return t.attrs.emoji;const e=[{tag:"img",attrs:{src:t.attrs.fallbackImage,draggable:"false",loading:"lazy",align:"absmiddle"}}];return this.renderTag(e," /")}}const he=r=>{if(typeof r!="object"||typeof r._editable>"u")return{};const t=JSON.parse(r._editable.replace(/^<!--#storyblok#/,"").replace(/-->$/,""));return{"data-blok-c":JSON.stringify(t),"data-blok-uid":t.id+"-"+t.uid}};let me;const be="https://app.storyblok.com/f/storyblok-v2-latest.js",ye=(r,t)=>{r.addNode("blok",e=>{let o="";return e.attrs.body.forEach(s=>{o+=t(s.component,s)}),{html:o}})},ke=r=>!r||!(r!=null&&r.content.some(t=>t.content||t.type==="blok"||t.type==="horizontal_rule")),$e=(r,t,e)=>{let o=e||me;if(!o){console.error("Please initialize the Storyblok SDK before calling the renderRichText function");return}return ke(r)?"":(t&&(o=new S(t.schema),t.resolver&&ye(o,t.resolver)),o.render(r))},ve=()=>z(be);function Ie(){return globalThis.storyblokApiInstance||console.error("storyblokApiInstance has not been initialized correctly"),globalThis.storyblokApiInstance}function we(r,t){const e=globalThis.storyblokApiInstance.richTextResolver;if(!e){console.error("Please initialize the Storyblok SDK before calling the renderRichText function");return}return $e(r,t,e)}function Te(r){const t={useCustomApi:!1,bridge:!0,componentsDir:"src",enableFallbackComponent:!1,...r};return{name:"@storyblok/astro",hooks:{"astro:config:setup":({injectScript:e,updateConfig:o})=>{if(o({vite:{plugins:[m(t.accessToken,t.useCustomApi,t.apiOptions),L(t.componentsDir,t.components,t.enableFallbackComponent,t.customFallbackComponent),_(t)]}}),e("page-ssr",`
|
|
35
35
|
import { storyblokApiInstance } from "virtual:storyblok-init";
|
|
36
36
|
globalThis.storyblokApiInstance = storyblokApiInstance;
|
|
37
|
-
`),
|
|
37
|
+
`),t.bridge){const s={...t.bridge};e("page",`
|
|
38
38
|
import { loadStoryblokBridge } from "@storyblok/astro";
|
|
39
39
|
loadStoryblokBridge().then(() => {
|
|
40
40
|
const { StoryblokBridge, location } = window;
|
|
41
|
-
const storyblokInstance = new StoryblokBridge(${JSON.stringify(
|
|
41
|
+
const storyblokInstance = new StoryblokBridge(${JSON.stringify(s)});
|
|
42
42
|
|
|
43
43
|
storyblokInstance.on(["published", "change"], (event) => {
|
|
44
44
|
if (!event.slugChanged) {
|
|
@@ -46,4 +46,4 @@ Detailed information can be found here: https://github.com/storyblok/storyblok-a
|
|
|
46
46
|
}
|
|
47
47
|
});
|
|
48
48
|
});
|
|
49
|
-
`)}}}}}
|
|
49
|
+
`)}}}}}g.RichTextResolver=S,g.RichTextSchema=A,g.default=Te,g.loadStoryblokBridge=ve,g.renderRichText=we,g.storyblokEditable=he,g.useStoryblokApi=Ie,Object.defineProperties(g,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|
package/dist/storyblok-astro.mjs
CHANGED
|
@@ -1,90 +1,90 @@
|
|
|
1
|
-
function
|
|
2
|
-
const o = "virtual:storyblok-init",
|
|
1
|
+
function T(r, t, e) {
|
|
2
|
+
const o = "virtual:storyblok-init", s = "\0" + o;
|
|
3
3
|
return {
|
|
4
4
|
name: "vite-plugin-storyblok-init",
|
|
5
|
-
async resolveId(
|
|
6
|
-
if (
|
|
7
|
-
return
|
|
5
|
+
async resolveId(a) {
|
|
6
|
+
if (a === o)
|
|
7
|
+
return s;
|
|
8
8
|
},
|
|
9
|
-
async load(
|
|
10
|
-
if (
|
|
9
|
+
async load(a) {
|
|
10
|
+
if (a === s)
|
|
11
11
|
return `
|
|
12
12
|
import { storyblokInit, apiPlugin } from "@storyblok/js";
|
|
13
13
|
const { storyblokApi } = storyblokInit({
|
|
14
14
|
accessToken: "${r}",
|
|
15
|
-
use: ${
|
|
16
|
-
apiOptions: ${JSON.stringify(
|
|
15
|
+
use: ${t ? "[]" : "[apiPlugin]"},
|
|
16
|
+
apiOptions: ${JSON.stringify(e)},
|
|
17
17
|
});
|
|
18
18
|
export const storyblokApiInstance = storyblokApi;
|
|
19
19
|
`;
|
|
20
20
|
}
|
|
21
21
|
};
|
|
22
22
|
}
|
|
23
|
-
const
|
|
24
|
-
let
|
|
23
|
+
const x = /[\p{Lu}]/u, A = /[\p{Ll}]/u, k = /^[\p{Lu}](?![\p{Lu}])/gu, E = /([\p{Alpha}\p{N}_]|$)/u, b = /[_.\- ]+/, S = new RegExp("^" + b.source), $ = new RegExp(b.source + E.source, "gu"), v = new RegExp("\\d+" + E.source, "gu"), R = (r, t, e, o) => {
|
|
24
|
+
let s = !1, a = !1, n = !1, c = !1;
|
|
25
25
|
for (let l = 0; l < r.length; l++) {
|
|
26
26
|
const i = r[l];
|
|
27
|
-
|
|
27
|
+
c = l > 2 ? r[l - 3] === "-" : !0, s && x.test(i) ? (r = r.slice(0, l) + "-" + r.slice(l), s = !1, n = a, a = !0, l++) : a && n && A.test(i) && (!c || o) ? (r = r.slice(0, l - 1) + "-" + r.slice(l - 1), n = a, a = !1, s = !0) : (s = t(i) === i && e(i) !== i, n = a, a = e(i) === i && t(i) !== i);
|
|
28
28
|
}
|
|
29
29
|
return r;
|
|
30
|
-
},
|
|
31
|
-
function
|
|
30
|
+
}, j = (r, t) => (k.lastIndex = 0, r.replace(k, (e) => t(e))), O = (r, t) => ($.lastIndex = 0, v.lastIndex = 0, r.replace($, (e, o) => t(o)).replace(v, (e) => t(e)));
|
|
31
|
+
function I(r, t) {
|
|
32
32
|
if (!(typeof r == "string" || Array.isArray(r)))
|
|
33
33
|
throw new TypeError("Expected the input to be `string | string[]`");
|
|
34
|
-
if (
|
|
34
|
+
if (t = {
|
|
35
35
|
pascalCase: !1,
|
|
36
36
|
preserveConsecutiveUppercase: !1,
|
|
37
|
-
...
|
|
38
|
-
}, Array.isArray(r) ? r = r.map((
|
|
37
|
+
...t
|
|
38
|
+
}, Array.isArray(r) ? r = r.map((a) => a.trim()).filter((a) => a.length).join("-") : r = r.trim(), r.length === 0)
|
|
39
39
|
return "";
|
|
40
|
-
const
|
|
41
|
-
return r.length === 1 ? b.test(r) ? "" :
|
|
40
|
+
const e = t.locale === !1 ? (a) => a.toLowerCase() : (a) => a.toLocaleLowerCase(t.locale), o = t.locale === !1 ? (a) => a.toUpperCase() : (a) => a.toLocaleUpperCase(t.locale);
|
|
41
|
+
return r.length === 1 ? b.test(r) ? "" : t.pascalCase ? o(r) : e(r) : (r !== e(r) && (r = R(r, e, o, t.preserveConsecutiveUppercase)), r = r.replace(S, ""), r = t.preserveConsecutiveUppercase ? j(r, e) : e(r), t.pascalCase && (r = o(r.charAt(0)) + r.slice(1)), O(r, o));
|
|
42
42
|
}
|
|
43
|
-
function N(r,
|
|
44
|
-
const
|
|
43
|
+
function N(r, t, e, o) {
|
|
44
|
+
const s = "virtual:storyblok-components", a = "\0" + s;
|
|
45
45
|
return {
|
|
46
46
|
name: "vite-plugin-storyblok-components",
|
|
47
47
|
async resolveId(n) {
|
|
48
|
-
if (n ===
|
|
49
|
-
return
|
|
48
|
+
if (n === s)
|
|
49
|
+
return a;
|
|
50
50
|
},
|
|
51
51
|
async load(n) {
|
|
52
|
-
if (n ===
|
|
53
|
-
const
|
|
54
|
-
for await (const [
|
|
55
|
-
const
|
|
52
|
+
if (n === a) {
|
|
53
|
+
const c = [], l = [];
|
|
54
|
+
for await (const [g, f] of Object.entries(t)) {
|
|
55
|
+
const h = await this.resolve(
|
|
56
56
|
"/" + r + "/" + f + ".astro"
|
|
57
57
|
);
|
|
58
|
-
if (
|
|
59
|
-
|
|
60
|
-
else if (
|
|
61
|
-
l.push(
|
|
58
|
+
if (h)
|
|
59
|
+
c.push(`import ${I(g)} from "${h.id}"`);
|
|
60
|
+
else if (e)
|
|
61
|
+
l.push(g);
|
|
62
62
|
else
|
|
63
63
|
throw new Error(
|
|
64
|
-
`Component could not be found for blok "${
|
|
64
|
+
`Component could not be found for blok "${g}"! Does "${"/" + r + "/" + f}.astro" exist?`
|
|
65
65
|
);
|
|
66
66
|
}
|
|
67
67
|
let i = "";
|
|
68
|
-
if (
|
|
68
|
+
if (e)
|
|
69
69
|
if (i = ",FallbackComponent", o) {
|
|
70
|
-
const
|
|
70
|
+
const g = await this.resolve(
|
|
71
71
|
"/" + r + "/" + o + ".astro"
|
|
72
72
|
);
|
|
73
|
-
if (!
|
|
73
|
+
if (!g)
|
|
74
74
|
throw new Error(
|
|
75
75
|
`Custom fallback component could not be found. Does "${"/" + r + "/" + o}.astro" exist?`
|
|
76
76
|
);
|
|
77
|
-
|
|
78
|
-
`import FallbackComponent from "${
|
|
77
|
+
c.push(
|
|
78
|
+
`import FallbackComponent from "${g.id}"`
|
|
79
79
|
);
|
|
80
80
|
} else
|
|
81
|
-
|
|
81
|
+
c.push(
|
|
82
82
|
"import FallbackComponent from '@storyblok/astro/FallbackComponent.astro'"
|
|
83
83
|
);
|
|
84
|
-
if (Object.values(
|
|
85
|
-
return `${
|
|
86
|
-
if (
|
|
87
|
-
return `${
|
|
84
|
+
if (Object.values(t).length)
|
|
85
|
+
return `${c.join(";")};export default {${Object.keys(t).filter((g) => !l.includes(g)).map((g) => I(g)).join(",")}${i}}`;
|
|
86
|
+
if (e)
|
|
87
|
+
return `${c[0]}; export default {${i.replace(",", "")}}`;
|
|
88
88
|
throw new Error(
|
|
89
89
|
`Currently, no Storyblok components are registered in astro.config.mjs.
|
|
90
90
|
Please register your components or enable the fallback component.
|
|
@@ -95,49 +95,108 @@ Detailed information can be found here: https://github.com/storyblok/storyblok-a
|
|
|
95
95
|
};
|
|
96
96
|
}
|
|
97
97
|
function L(r) {
|
|
98
|
-
const
|
|
98
|
+
const t = "virtual:storyblok-options", e = "\0" + t;
|
|
99
99
|
return {
|
|
100
100
|
name: "vite-plugin-storyblok-options",
|
|
101
101
|
async resolveId(o) {
|
|
102
|
-
if (o ===
|
|
103
|
-
return
|
|
102
|
+
if (o === t)
|
|
103
|
+
return e;
|
|
104
104
|
},
|
|
105
105
|
async load(o) {
|
|
106
|
-
if (o ===
|
|
106
|
+
if (o === e)
|
|
107
107
|
return `export default ${JSON.stringify(r)}`;
|
|
108
108
|
}
|
|
109
109
|
};
|
|
110
110
|
}
|
|
111
|
-
let
|
|
112
|
-
const
|
|
113
|
-
if (typeof window > "u" || (window.storyblokRegisterEvent = (
|
|
111
|
+
let w = !1;
|
|
112
|
+
const C = [], M = (r) => new Promise((t, e) => {
|
|
113
|
+
if (typeof window > "u" || (window.storyblokRegisterEvent = (s) => {
|
|
114
114
|
if (window.location === window.parent.location) {
|
|
115
115
|
console.warn("You are not in Draft Mode or in the Visual Editor.");
|
|
116
116
|
return;
|
|
117
117
|
}
|
|
118
|
-
|
|
118
|
+
w ? s() : C.push(s);
|
|
119
119
|
}, document.getElementById("storyblok-javascript-bridge")))
|
|
120
120
|
return;
|
|
121
121
|
const o = document.createElement("script");
|
|
122
|
-
o.async = !0, o.src = r, o.id = "storyblok-javascript-bridge", o.onerror = (
|
|
123
|
-
|
|
122
|
+
o.async = !0, o.src = r, o.id = "storyblok-javascript-bridge", o.onerror = (s) => e(s), o.onload = (s) => {
|
|
123
|
+
C.forEach((a) => a()), w = !0, t(s);
|
|
124
124
|
}, document.getElementsByTagName("head")[0].appendChild(o);
|
|
125
125
|
});
|
|
126
|
-
var
|
|
127
|
-
|
|
128
|
-
|
|
126
|
+
var P = Object.defineProperty, _ = (r, t, e) => t in r ? P(r, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : r[t] = e, p = (r, t, e) => (_(r, typeof t != "symbol" ? t + "" : t, e), e);
|
|
127
|
+
class z {
|
|
128
|
+
constructor() {
|
|
129
|
+
p(this, "isCDNUrl", (t = "") => t.indexOf("/cdn/") > -1), p(this, "getOptionsPage", (t, e = 25, o = 1) => ({
|
|
130
|
+
...t,
|
|
131
|
+
per_page: e,
|
|
132
|
+
page: o
|
|
133
|
+
})), p(this, "delay", (t) => new Promise((e) => setTimeout(e, t))), p(this, "arrayFrom", (t = 0, e) => [...Array(t)].map(e)), p(this, "range", (t = 0, e = t) => {
|
|
134
|
+
const o = Math.abs(e - t) || 0, s = t < e ? 1 : -1;
|
|
135
|
+
return this.arrayFrom(o, (a, n) => n * s + t);
|
|
136
|
+
}), p(this, "asyncMap", async (t, e) => Promise.all(t.map(e))), p(this, "flatMap", (t = [], e) => t.map(e).reduce((o, s) => [...o, ...s], [])), p(this, "escapeHTML", function(t) {
|
|
137
|
+
const e = {
|
|
138
|
+
"&": "&",
|
|
139
|
+
"<": "<",
|
|
140
|
+
">": ">",
|
|
141
|
+
'"': """,
|
|
142
|
+
"'": "'"
|
|
143
|
+
}, o = /[&<>"']/g, s = RegExp(o.source);
|
|
144
|
+
return t && s.test(t) ? t.replace(o, (a) => e[a]) : t;
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* @method stringify
|
|
149
|
+
* @param {Object} params
|
|
150
|
+
* @param {String} prefix
|
|
151
|
+
* @param {Boolean} isArray
|
|
152
|
+
* @return {String} Stringified object
|
|
153
|
+
*/
|
|
154
|
+
stringify(t, e, o) {
|
|
155
|
+
const s = [];
|
|
156
|
+
for (const a in t) {
|
|
157
|
+
if (!Object.prototype.hasOwnProperty.call(t, a))
|
|
158
|
+
continue;
|
|
159
|
+
const n = t[a], c = o ? "" : encodeURIComponent(a);
|
|
160
|
+
let l;
|
|
161
|
+
typeof n == "object" ? l = this.stringify(
|
|
162
|
+
n,
|
|
163
|
+
e ? e + encodeURIComponent("[" + c + "]") : c,
|
|
164
|
+
Array.isArray(n)
|
|
165
|
+
) : l = (e ? e + encodeURIComponent("[" + c + "]") : c) + "=" + encodeURIComponent(n), s.push(l);
|
|
166
|
+
}
|
|
167
|
+
return s.join("&");
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* @method getRegionURL
|
|
171
|
+
* @param {String} regionCode region code, could be eu, us or cn
|
|
172
|
+
* @return {String} The base URL of the region
|
|
173
|
+
*/
|
|
174
|
+
getRegionURL(t) {
|
|
175
|
+
const e = "api.storyblok.com", o = "api-us.storyblok.com", s = "app.storyblokchina.cn";
|
|
176
|
+
switch (t) {
|
|
177
|
+
case "us":
|
|
178
|
+
return o;
|
|
179
|
+
case "cn":
|
|
180
|
+
return s;
|
|
181
|
+
default:
|
|
182
|
+
return e;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
const U = function(r, t) {
|
|
187
|
+
const e = {};
|
|
129
188
|
for (const o in r) {
|
|
130
|
-
const
|
|
131
|
-
|
|
189
|
+
const s = r[o];
|
|
190
|
+
t.indexOf(o) > -1 && s !== null && (e[o] = s);
|
|
132
191
|
}
|
|
133
|
-
return
|
|
134
|
-
}, D = (r) => r === "email",
|
|
192
|
+
return e;
|
|
193
|
+
}, D = (r) => r === "email", q = () => ({
|
|
135
194
|
singleTag: "hr"
|
|
136
|
-
}),
|
|
195
|
+
}), F = () => ({
|
|
137
196
|
tag: "blockquote"
|
|
138
197
|
}), B = () => ({
|
|
139
198
|
tag: "ul"
|
|
140
|
-
}),
|
|
199
|
+
}), J = (r) => ({
|
|
141
200
|
tag: [
|
|
142
201
|
"pre",
|
|
143
202
|
{
|
|
@@ -145,15 +204,15 @@ const _ = function(r, e) {
|
|
|
145
204
|
attrs: r.attrs
|
|
146
205
|
}
|
|
147
206
|
]
|
|
148
|
-
}),
|
|
207
|
+
}), K = () => ({
|
|
149
208
|
singleTag: "br"
|
|
150
|
-
}), K = (r) => ({
|
|
151
|
-
tag: `h${r.attrs.level}`
|
|
152
209
|
}), V = (r) => ({
|
|
210
|
+
tag: `h${r.attrs.level}`
|
|
211
|
+
}), H = (r) => ({
|
|
153
212
|
singleTag: [
|
|
154
213
|
{
|
|
155
214
|
tag: "img",
|
|
156
|
-
attrs:
|
|
215
|
+
attrs: U(r.attrs, ["src", "alt", "title"])
|
|
157
216
|
}
|
|
158
217
|
]
|
|
159
218
|
}), G = () => ({
|
|
@@ -162,7 +221,7 @@ const _ = function(r, e) {
|
|
|
162
221
|
tag: "ol"
|
|
163
222
|
}), Y = () => ({
|
|
164
223
|
tag: "p"
|
|
165
|
-
}),
|
|
224
|
+
}), Q = (r) => ({
|
|
166
225
|
tag: [
|
|
167
226
|
{
|
|
168
227
|
tag: "span",
|
|
@@ -173,23 +232,23 @@ const _ = function(r, e) {
|
|
|
173
232
|
}
|
|
174
233
|
}
|
|
175
234
|
]
|
|
176
|
-
}), Q = () => ({
|
|
177
|
-
tag: "b"
|
|
178
235
|
}), X = () => ({
|
|
179
|
-
tag: "
|
|
236
|
+
tag: "b"
|
|
180
237
|
}), Z = () => ({
|
|
181
|
-
tag: "
|
|
238
|
+
tag: "strike"
|
|
182
239
|
}), ee = () => ({
|
|
183
|
-
tag: "
|
|
240
|
+
tag: "u"
|
|
184
241
|
}), te = () => ({
|
|
185
|
-
tag: "
|
|
242
|
+
tag: "strong"
|
|
186
243
|
}), re = () => ({
|
|
244
|
+
tag: "code"
|
|
245
|
+
}), oe = () => ({
|
|
187
246
|
tag: "i"
|
|
188
|
-
}),
|
|
189
|
-
const e = { ...r.attrs }, { linktype:
|
|
190
|
-
if (
|
|
191
|
-
for (const
|
|
192
|
-
e[
|
|
247
|
+
}), se = (r) => {
|
|
248
|
+
const t = new z().escapeHTML, e = { ...r.attrs }, { linktype: o = "url" } = r.attrs;
|
|
249
|
+
if (e.href && (e.href = t(r.attrs.href || "")), D(o) && (e.href = `mailto:${e.href}`), e.anchor && (e.href = `${e.href}#${e.anchor}`, delete e.anchor), e.custom) {
|
|
250
|
+
for (const s in e.custom)
|
|
251
|
+
e[s] = e.custom[s];
|
|
193
252
|
delete e.custom;
|
|
194
253
|
}
|
|
195
254
|
return {
|
|
@@ -200,27 +259,27 @@ const _ = function(r, e) {
|
|
|
200
259
|
}
|
|
201
260
|
]
|
|
202
261
|
};
|
|
203
|
-
},
|
|
262
|
+
}, ae = (r) => ({
|
|
204
263
|
tag: [
|
|
205
264
|
{
|
|
206
265
|
tag: "span",
|
|
207
266
|
attrs: r.attrs
|
|
208
267
|
}
|
|
209
268
|
]
|
|
210
|
-
}), ae = () => ({
|
|
211
|
-
tag: "sub"
|
|
212
269
|
}), ne = () => ({
|
|
270
|
+
tag: "sub"
|
|
271
|
+
}), le = () => ({
|
|
213
272
|
tag: "sup"
|
|
214
|
-
}),
|
|
273
|
+
}), ie = (r) => ({
|
|
215
274
|
tag: [
|
|
216
275
|
{
|
|
217
276
|
tag: "span",
|
|
218
277
|
attrs: r.attrs
|
|
219
278
|
}
|
|
220
279
|
]
|
|
221
|
-
}),
|
|
222
|
-
var
|
|
223
|
-
return (
|
|
280
|
+
}), ce = (r) => {
|
|
281
|
+
var t;
|
|
282
|
+
return (t = r.attrs) != null && t.color ? {
|
|
224
283
|
tag: [
|
|
225
284
|
{
|
|
226
285
|
tag: "span",
|
|
@@ -232,9 +291,9 @@ const _ = function(r, e) {
|
|
|
232
291
|
} : {
|
|
233
292
|
tag: ""
|
|
234
293
|
};
|
|
235
|
-
},
|
|
236
|
-
var
|
|
237
|
-
return (
|
|
294
|
+
}, ge = (r) => {
|
|
295
|
+
var t;
|
|
296
|
+
return (t = r.attrs) != null && t.color ? {
|
|
238
297
|
tag: [
|
|
239
298
|
{
|
|
240
299
|
tag: "span",
|
|
@@ -246,61 +305,61 @@ const _ = function(r, e) {
|
|
|
246
305
|
} : {
|
|
247
306
|
tag: ""
|
|
248
307
|
};
|
|
249
|
-
},
|
|
308
|
+
}, ue = {
|
|
250
309
|
nodes: {
|
|
251
|
-
horizontal_rule:
|
|
252
|
-
blockquote:
|
|
310
|
+
horizontal_rule: q,
|
|
311
|
+
blockquote: F,
|
|
253
312
|
bullet_list: B,
|
|
254
|
-
code_block:
|
|
255
|
-
hard_break:
|
|
256
|
-
heading:
|
|
257
|
-
image:
|
|
313
|
+
code_block: J,
|
|
314
|
+
hard_break: K,
|
|
315
|
+
heading: V,
|
|
316
|
+
image: H,
|
|
258
317
|
list_item: G,
|
|
259
318
|
ordered_list: W,
|
|
260
319
|
paragraph: Y,
|
|
261
|
-
emoji:
|
|
320
|
+
emoji: Q
|
|
262
321
|
},
|
|
263
322
|
marks: {
|
|
264
|
-
bold:
|
|
265
|
-
strike:
|
|
266
|
-
underline:
|
|
267
|
-
strong:
|
|
268
|
-
code:
|
|
269
|
-
italic:
|
|
270
|
-
link:
|
|
271
|
-
styled:
|
|
272
|
-
subscript:
|
|
273
|
-
superscript:
|
|
274
|
-
anchor:
|
|
275
|
-
highlight:
|
|
276
|
-
textStyle:
|
|
323
|
+
bold: X,
|
|
324
|
+
strike: Z,
|
|
325
|
+
underline: ee,
|
|
326
|
+
strong: te,
|
|
327
|
+
code: re,
|
|
328
|
+
italic: oe,
|
|
329
|
+
link: se,
|
|
330
|
+
styled: ae,
|
|
331
|
+
subscript: ne,
|
|
332
|
+
superscript: le,
|
|
333
|
+
anchor: ie,
|
|
334
|
+
highlight: ce,
|
|
335
|
+
textStyle: ge
|
|
277
336
|
}
|
|
278
|
-
},
|
|
279
|
-
const
|
|
337
|
+
}, pe = function(r) {
|
|
338
|
+
const t = {
|
|
280
339
|
"&": "&",
|
|
281
340
|
"<": "<",
|
|
282
341
|
">": ">",
|
|
283
342
|
'"': """,
|
|
284
343
|
"'": "'"
|
|
285
|
-
},
|
|
286
|
-
return r && o.test(r) ? r.replace(
|
|
344
|
+
}, e = /[&<>"']/g, o = RegExp(e.source);
|
|
345
|
+
return r && o.test(r) ? r.replace(e, (s) => t[s]) : r;
|
|
287
346
|
};
|
|
288
347
|
class fe {
|
|
289
|
-
constructor(
|
|
290
|
-
|
|
348
|
+
constructor(t) {
|
|
349
|
+
p(this, "marks"), p(this, "nodes"), t || (t = ue), this.marks = t.marks || [], this.nodes = t.nodes || [];
|
|
291
350
|
}
|
|
292
|
-
addNode(
|
|
293
|
-
this.nodes[
|
|
351
|
+
addNode(t, e) {
|
|
352
|
+
this.nodes[t] = e;
|
|
294
353
|
}
|
|
295
|
-
addMark(
|
|
296
|
-
this.marks[
|
|
354
|
+
addMark(t, e) {
|
|
355
|
+
this.marks[t] = e;
|
|
297
356
|
}
|
|
298
|
-
render(
|
|
299
|
-
if (
|
|
357
|
+
render(t, e = { optimizeImages: !1 }) {
|
|
358
|
+
if (t && t.content && Array.isArray(t.content)) {
|
|
300
359
|
let o = "";
|
|
301
|
-
return
|
|
302
|
-
o += this.renderNode(
|
|
303
|
-
}),
|
|
360
|
+
return t.content.forEach((s) => {
|
|
361
|
+
o += this.renderNode(s);
|
|
362
|
+
}), e.optimizeImages ? this.optimizeImages(o, e.optimizeImages) : o;
|
|
304
363
|
}
|
|
305
364
|
return console.warn(
|
|
306
365
|
`The render method must receive an Object with a "content" field.
|
|
@@ -329,147 +388,144 @@ class fe {
|
|
|
329
388
|
}`
|
|
330
389
|
), "";
|
|
331
390
|
}
|
|
332
|
-
optimizeImages(
|
|
333
|
-
let o = 0,
|
|
334
|
-
typeof
|
|
335
|
-
const
|
|
336
|
-
return
|
|
391
|
+
optimizeImages(t, e) {
|
|
392
|
+
let o = 0, s = 0, a = "", n = "";
|
|
393
|
+
typeof e != "boolean" && (typeof e.width == "number" && e.width > 0 && (a += `width="${e.width}" `, o = e.width), typeof e.height == "number" && e.height > 0 && (a += `height="${e.height}" `, s = e.height), (e.loading === "lazy" || e.loading === "eager") && (a += `loading="${e.loading}" `), typeof e.class == "string" && e.class.length > 0 && (a += `class="${e.class}" `), e.filters && (typeof e.filters.blur == "number" && e.filters.blur >= 0 && e.filters.blur <= 100 && (n += `:blur(${e.filters.blur})`), typeof e.filters.brightness == "number" && e.filters.brightness >= -100 && e.filters.brightness <= 100 && (n += `:brightness(${e.filters.brightness})`), e.filters.fill && (e.filters.fill.match(/[0-9A-Fa-f]{6}/g) || e.filters.fill === "transparent") && (n += `:fill(${e.filters.fill})`), e.filters.format && ["webp", "png", "jpeg"].includes(e.filters.format) && (n += `:format(${e.filters.format})`), typeof e.filters.grayscale == "boolean" && e.filters.grayscale && (n += ":grayscale()"), typeof e.filters.quality == "number" && e.filters.quality >= 0 && e.filters.quality <= 100 && (n += `:quality(${e.filters.quality})`), e.filters.rotate && [90, 180, 270].includes(e.filters.rotate) && (n += `:rotate(${e.filters.rotate})`), n.length > 0 && (n = "/filters" + n))), a.length > 0 && (t = t.replace(/<img/g, `<img ${a.trim()}`));
|
|
394
|
+
const c = o > 0 || s > 0 || n.length > 0 ? `${o}x${s}${n}` : "";
|
|
395
|
+
return t = t.replace(
|
|
337
396
|
/a.storyblok.com\/f\/(\d+)\/([^.]+)\.(gif|jpg|jpeg|png|tif|tiff|bmp)/g,
|
|
338
|
-
`a.storyblok.com/f/$1/$2.$3/m/${
|
|
339
|
-
), typeof
|
|
340
|
-
var i,
|
|
397
|
+
`a.storyblok.com/f/$1/$2.$3/m/${c}`
|
|
398
|
+
), typeof e != "boolean" && (e.sizes || e.srcset) && (t = t.replace(/<img.*?src=["|'](.*?)["|']/g, (l) => {
|
|
399
|
+
var i, g;
|
|
341
400
|
const f = l.match(
|
|
342
401
|
/a.storyblok.com\/f\/(\d+)\/([^.]+)\.(gif|jpg|jpeg|png|tif|tiff|bmp)/g
|
|
343
402
|
);
|
|
344
403
|
if (f && f.length > 0) {
|
|
345
|
-
const
|
|
346
|
-
srcset: (i =
|
|
347
|
-
if (typeof
|
|
348
|
-
return `//${f}/m/${
|
|
349
|
-
if (typeof
|
|
350
|
-
let
|
|
351
|
-
return typeof
|
|
404
|
+
const h = {
|
|
405
|
+
srcset: (i = e.srcset) == null ? void 0 : i.map((u) => {
|
|
406
|
+
if (typeof u == "number")
|
|
407
|
+
return `//${f}/m/${u}x0${n} ${u}w`;
|
|
408
|
+
if (typeof u == "object" && u.length === 2) {
|
|
409
|
+
let m = 0, y = 0;
|
|
410
|
+
return typeof u[0] == "number" && (m = u[0]), typeof u[1] == "number" && (y = u[1]), `//${f}/m/${m}x${y}${n} ${m}w`;
|
|
352
411
|
}
|
|
353
412
|
}).join(", "),
|
|
354
|
-
sizes: (
|
|
413
|
+
sizes: (g = e.sizes) == null ? void 0 : g.map((u) => u).join(", ")
|
|
355
414
|
};
|
|
356
|
-
let
|
|
357
|
-
return
|
|
415
|
+
let d = "";
|
|
416
|
+
return h.srcset && (d += `srcset="${h.srcset}" `), h.sizes && (d += `sizes="${h.sizes}" `), l.replace(/<img/g, `<img ${d.trim()}`);
|
|
358
417
|
}
|
|
359
418
|
return l;
|
|
360
|
-
})),
|
|
419
|
+
})), t;
|
|
361
420
|
}
|
|
362
|
-
renderNode(
|
|
363
|
-
const
|
|
364
|
-
|
|
365
|
-
const
|
|
366
|
-
|
|
421
|
+
renderNode(t) {
|
|
422
|
+
const e = [];
|
|
423
|
+
t.marks && t.marks.forEach((s) => {
|
|
424
|
+
const a = this.getMatchingMark(s);
|
|
425
|
+
a && a.tag !== "" && e.push(this.renderOpeningTag(a.tag));
|
|
367
426
|
});
|
|
368
|
-
const o = this.getMatchingNode(
|
|
369
|
-
return o && o.tag &&
|
|
370
|
-
|
|
371
|
-
}) :
|
|
372
|
-
const
|
|
373
|
-
|
|
374
|
-
}),
|
|
427
|
+
const o = this.getMatchingNode(t);
|
|
428
|
+
return o && o.tag && e.push(this.renderOpeningTag(o.tag)), t.content ? t.content.forEach((s) => {
|
|
429
|
+
e.push(this.renderNode(s));
|
|
430
|
+
}) : t.text ? e.push(pe(t.text)) : o && o.singleTag ? e.push(this.renderTag(o.singleTag, " /")) : o && o.html ? e.push(o.html) : t.type === "emoji" && e.push(this.renderEmoji(t)), o && o.tag && e.push(this.renderClosingTag(o.tag)), t.marks && t.marks.slice(0).reverse().forEach((s) => {
|
|
431
|
+
const a = this.getMatchingMark(s);
|
|
432
|
+
a && a.tag !== "" && e.push(this.renderClosingTag(a.tag));
|
|
433
|
+
}), e.join("");
|
|
375
434
|
}
|
|
376
|
-
renderTag(
|
|
377
|
-
return
|
|
435
|
+
renderTag(t, e) {
|
|
436
|
+
return t.constructor === String ? `<${t}${e}>` : t.map((o) => {
|
|
378
437
|
if (o.constructor === String)
|
|
379
|
-
return `<${o}${
|
|
438
|
+
return `<${o}${e}>`;
|
|
380
439
|
{
|
|
381
|
-
let
|
|
440
|
+
let s = `<${o.tag}`;
|
|
382
441
|
if (o.attrs)
|
|
383
|
-
for (const
|
|
384
|
-
const n = o.attrs[
|
|
385
|
-
n !== null && (
|
|
442
|
+
for (const a in o.attrs) {
|
|
443
|
+
const n = o.attrs[a];
|
|
444
|
+
n !== null && (s += ` ${a}="${n}"`);
|
|
386
445
|
}
|
|
387
|
-
return `${
|
|
446
|
+
return `${s}${e}>`;
|
|
388
447
|
}
|
|
389
448
|
}).join("");
|
|
390
449
|
}
|
|
391
|
-
renderOpeningTag(
|
|
392
|
-
return this.renderTag(
|
|
450
|
+
renderOpeningTag(t) {
|
|
451
|
+
return this.renderTag(t, "");
|
|
393
452
|
}
|
|
394
|
-
renderClosingTag(
|
|
395
|
-
return
|
|
453
|
+
renderClosingTag(t) {
|
|
454
|
+
return t.constructor === String ? `</${t}>` : t.slice(0).reverse().map((e) => e.constructor === String ? `</${e}>` : `</${e.tag}>`).join("");
|
|
396
455
|
}
|
|
397
|
-
getMatchingNode(
|
|
398
|
-
const
|
|
399
|
-
if (typeof
|
|
400
|
-
return t
|
|
456
|
+
getMatchingNode(t) {
|
|
457
|
+
const e = this.nodes[t.type];
|
|
458
|
+
if (typeof e == "function")
|
|
459
|
+
return e(t);
|
|
401
460
|
}
|
|
402
|
-
getMatchingMark(
|
|
403
|
-
const
|
|
404
|
-
if (typeof
|
|
405
|
-
return t
|
|
461
|
+
getMatchingMark(t) {
|
|
462
|
+
const e = this.marks[t.type];
|
|
463
|
+
if (typeof e == "function")
|
|
464
|
+
return e(t);
|
|
406
465
|
}
|
|
407
|
-
renderEmoji(
|
|
408
|
-
if (
|
|
409
|
-
return
|
|
410
|
-
const
|
|
466
|
+
renderEmoji(t) {
|
|
467
|
+
if (t.attrs.emoji)
|
|
468
|
+
return t.attrs.emoji;
|
|
469
|
+
const e = [
|
|
411
470
|
{
|
|
412
471
|
tag: "img",
|
|
413
472
|
attrs: {
|
|
414
|
-
src:
|
|
473
|
+
src: t.attrs.fallbackImage,
|
|
415
474
|
draggable: "false",
|
|
416
475
|
loading: "lazy",
|
|
417
476
|
align: "absmiddle"
|
|
418
477
|
}
|
|
419
478
|
}
|
|
420
479
|
];
|
|
421
|
-
return this.renderTag(
|
|
480
|
+
return this.renderTag(e, " /");
|
|
422
481
|
}
|
|
423
482
|
}
|
|
424
|
-
const
|
|
483
|
+
const ke = (r) => {
|
|
425
484
|
if (typeof r != "object" || typeof r._editable > "u")
|
|
426
485
|
return {};
|
|
427
|
-
const
|
|
486
|
+
const t = JSON.parse(
|
|
428
487
|
r._editable.replace(/^<!--#storyblok#/, "").replace(/-->$/, "")
|
|
429
488
|
);
|
|
430
489
|
return {
|
|
431
|
-
"data-blok-c": JSON.stringify(
|
|
432
|
-
"data-blok-uid":
|
|
490
|
+
"data-blok-c": JSON.stringify(t),
|
|
491
|
+
"data-blok-uid": t.id + "-" + t.uid
|
|
433
492
|
};
|
|
434
493
|
};
|
|
435
|
-
let
|
|
436
|
-
const
|
|
437
|
-
r.addNode("blok", (
|
|
494
|
+
let he;
|
|
495
|
+
const de = "https://app.storyblok.com/f/storyblok-v2-latest.js", me = (r, t) => {
|
|
496
|
+
r.addNode("blok", (e) => {
|
|
438
497
|
let o = "";
|
|
439
|
-
return
|
|
440
|
-
o +=
|
|
498
|
+
return e.attrs.body.forEach((s) => {
|
|
499
|
+
o += t(s.component, s);
|
|
441
500
|
}), {
|
|
442
501
|
html: o
|
|
443
502
|
};
|
|
444
503
|
});
|
|
445
|
-
}, be = (r) => {
|
|
446
|
-
|
|
447
|
-
return !r || ((e = r == null ? void 0 : r.content) == null ? void 0 : e[0].type) !== "blok" && !((t = r == null ? void 0 : r.content) != null && t[0].content);
|
|
448
|
-
}, me = (r, e, t) => {
|
|
449
|
-
let o = t || de;
|
|
504
|
+
}, be = (r) => !r || !(r != null && r.content.some((t) => t.content || t.type === "blok" || t.type === "horizontal_rule")), ye = (r, t, e) => {
|
|
505
|
+
let o = e || he;
|
|
450
506
|
if (!o) {
|
|
451
507
|
console.error(
|
|
452
508
|
"Please initialize the Storyblok SDK before calling the renderRichText function"
|
|
453
509
|
);
|
|
454
510
|
return;
|
|
455
511
|
}
|
|
456
|
-
return be(r) ? "" : (
|
|
457
|
-
},
|
|
458
|
-
function
|
|
512
|
+
return be(r) ? "" : (t && (o = new fe(t.schema), t.resolver && me(o, t.resolver)), o.render(r));
|
|
513
|
+
}, $e = () => M(de);
|
|
514
|
+
function ve() {
|
|
459
515
|
return globalThis.storyblokApiInstance || console.error("storyblokApiInstance has not been initialized correctly"), globalThis.storyblokApiInstance;
|
|
460
516
|
}
|
|
461
|
-
function
|
|
462
|
-
const
|
|
463
|
-
if (!
|
|
517
|
+
function Ie(r, t) {
|
|
518
|
+
const e = globalThis.storyblokApiInstance.richTextResolver;
|
|
519
|
+
if (!e) {
|
|
464
520
|
console.error(
|
|
465
521
|
"Please initialize the Storyblok SDK before calling the renderRichText function"
|
|
466
522
|
);
|
|
467
523
|
return;
|
|
468
524
|
}
|
|
469
|
-
return
|
|
525
|
+
return ye(r, t, e);
|
|
470
526
|
}
|
|
471
|
-
function
|
|
472
|
-
const
|
|
527
|
+
function we(r) {
|
|
528
|
+
const t = {
|
|
473
529
|
useCustomApi: !1,
|
|
474
530
|
bridge: !0,
|
|
475
531
|
componentsDir: "src",
|
|
@@ -479,40 +535,40 @@ function Ie(r) {
|
|
|
479
535
|
return {
|
|
480
536
|
name: "@storyblok/astro",
|
|
481
537
|
hooks: {
|
|
482
|
-
"astro:config:setup": ({ injectScript:
|
|
538
|
+
"astro:config:setup": ({ injectScript: e, updateConfig: o }) => {
|
|
483
539
|
if (o({
|
|
484
540
|
vite: {
|
|
485
541
|
plugins: [
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
542
|
+
T(
|
|
543
|
+
t.accessToken,
|
|
544
|
+
t.useCustomApi,
|
|
545
|
+
t.apiOptions
|
|
490
546
|
),
|
|
491
547
|
N(
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
548
|
+
t.componentsDir,
|
|
549
|
+
t.components,
|
|
550
|
+
t.enableFallbackComponent,
|
|
551
|
+
t.customFallbackComponent
|
|
496
552
|
),
|
|
497
|
-
L(
|
|
553
|
+
L(t)
|
|
498
554
|
]
|
|
499
555
|
}
|
|
500
|
-
}),
|
|
556
|
+
}), e(
|
|
501
557
|
"page-ssr",
|
|
502
558
|
`
|
|
503
559
|
import { storyblokApiInstance } from "virtual:storyblok-init";
|
|
504
560
|
globalThis.storyblokApiInstance = storyblokApiInstance;
|
|
505
561
|
`
|
|
506
|
-
),
|
|
507
|
-
const
|
|
508
|
-
|
|
562
|
+
), t.bridge) {
|
|
563
|
+
const s = { ...t.bridge };
|
|
564
|
+
e(
|
|
509
565
|
"page",
|
|
510
566
|
`
|
|
511
567
|
import { loadStoryblokBridge } from "@storyblok/astro";
|
|
512
568
|
loadStoryblokBridge().then(() => {
|
|
513
569
|
const { StoryblokBridge, location } = window;
|
|
514
570
|
const storyblokInstance = new StoryblokBridge(${JSON.stringify(
|
|
515
|
-
|
|
571
|
+
s
|
|
516
572
|
)});
|
|
517
573
|
|
|
518
574
|
storyblokInstance.on(["published", "change"], (event) => {
|
|
@@ -530,10 +586,10 @@ function Ie(r) {
|
|
|
530
586
|
}
|
|
531
587
|
export {
|
|
532
588
|
fe as RichTextResolver,
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
589
|
+
ue as RichTextSchema,
|
|
590
|
+
we as default,
|
|
591
|
+
$e as loadStoryblokBridge,
|
|
592
|
+
Ie as renderRichText,
|
|
593
|
+
ke as storyblokEditable,
|
|
594
|
+
ve as useStoryblokApi
|
|
539
595
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@storyblok/astro",
|
|
3
|
-
"version": "2.5.
|
|
3
|
+
"version": "2.5.8",
|
|
4
4
|
"description": "Official Astro integration for the Storyblok Headless CMS",
|
|
5
5
|
"main": "./dist/storyblok-astro.js",
|
|
6
6
|
"module": "./dist/storyblok-astro.mjs",
|
|
@@ -33,20 +33,20 @@
|
|
|
33
33
|
"prepublishOnly": "npm run build && cp ../README.md ./"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@storyblok/js": "^2.2.
|
|
36
|
+
"@storyblok/js": "^2.2.8",
|
|
37
37
|
"camelcase": "^7.0.1"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
40
|
"@cypress/vite-dev-server": "^5.0.5",
|
|
41
41
|
"@rollup/plugin-dynamic-import-vars": "^2.0.4",
|
|
42
|
-
"@types/node": "20.4.
|
|
43
|
-
"astro": "2.
|
|
42
|
+
"@types/node": "20.4.9",
|
|
43
|
+
"astro": "2.10.3",
|
|
44
44
|
"cypress": "^12.17.3",
|
|
45
|
-
"eslint-plugin-cypress": "^2.
|
|
45
|
+
"eslint-plugin-cypress": "^2.14.0",
|
|
46
46
|
"start-server-and-test": "^2.0.0",
|
|
47
47
|
"typescript": "5.1.6",
|
|
48
|
-
"vite": "^4.4.
|
|
49
|
-
"vite-plugin-dts": "^3.
|
|
48
|
+
"vite": "^4.4.9",
|
|
49
|
+
"vite-plugin-dts": "^3.5.1"
|
|
50
50
|
},
|
|
51
51
|
"repository": {
|
|
52
52
|
"type": "git",
|