@storyblok/astro 2.3.0 → 2.3.2
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 +25 -2
- package/dist/storyblok-astro.mjs +101 -68
- package/package.json +8 -8
package/dist/storyblok-astro.js
CHANGED
|
@@ -6,7 +6,30 @@
|
|
|
6
6
|
apiOptions: ${JSON.stringify(t)},
|
|
7
7
|
});
|
|
8
8
|
export const storyblokApiInstance = storyblokApi;
|
|
9
|
-
`}}}const
|
|
9
|
+
`}}}const j=/[\p{Lu}]/u,R=/[\p{Ll}]/u,k=/^[\p{Lu}](?![\p{Lu}])/gu,$=/([\p{Alpha}\p{N}_]|$)/u,b=/[_.\- ]+/,N=new RegExp("^"+b.source),v=new RegExp(b.source+$.source,"gu"),I=new RegExp("\\d+"+$.source,"gu"),O=(r,e,t,o)=>{let a=!1,s=!1,n=!1,f=!1;for(let i=0;i<r.length;i++){const l=r[i];f=i>2?r[i-3]==="-":!0,a&&j.test(l)?(r=r.slice(0,i)+"-"+r.slice(i),a=!1,n=s,s=!0,i++):s&&n&&R.test(l)&&(!f||o)?(r=r.slice(0,i-1)+"-"+r.slice(i-1),n=s,s=!1,a=!0):(a=e(l)===l&&t(l)!==l,n=s,s=t(l)===l&&e(l)!==l)}return r},L=(r,e)=>(k.lastIndex=0,r.replace(k,t=>e(t))),M=(r,e)=>(v.lastIndex=0,I.lastIndex=0,r.replace(v,(t,o)=>e(o)).replace(I,t=>e(t)));function T(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?b.test(r)?"":e.pascalCase?o(r):t(r):(r!==t(r)&&(r=O(r,t,o,e.preserveConsecutiveUppercase)),r=r.replace(N,""),r=e.preserveConsecutiveUppercase?L(r,t):t(r),e.pascalCase&&(r=o(r.charAt(0))+r.slice(1)),M(r,o))}function P(r,e,t,o){const a="virtual:storyblok-components",s="\0"+a;return{name:"vite-plugin-storyblok-components",async resolveId(n){if(n===a)return s},async load(n){if(n===s){const f=[],i=[];for await(const[c,d]of Object.entries(e)){const h=await this.resolve("/"+r+"/"+d+".astro");if(h)f.push(`import ${T(c)} from "${h.id}"`);else if(t)i.push(c);else throw new Error(`Component could not be found for blok "${c}"! Does "${"/"+r+"/"+d}.astro" exist?`)}let l="";if(t)if(l=",FallbackComponent",o){const c=await this.resolve("/"+r+"/"+o+".astro");if(!c)throw new Error(`Custom fallback component could not be found. Does "${"/"+r+"/"+o}.astro" exist?`);f.push(`import FallbackComponent from "${c.id}"`)}else f.push("import FallbackComponent from '@storyblok/astro/FallbackComponent.astro';");return`${f.join(";")};export default {${Object.keys(e).filter(c=>!i.includes(c)).map(c=>T(c)).join(",")}${l}}`}}}}function _(r){const e="virtual:storyblok-options",t="\0"+e;return{name:"vite-plugin-storyblok-options",async resolveId(o){if(o===e)return t},async load(o){if(o===t)return`export default ${JSON.stringify(r)}`}}}let w=!1;const E=[],z=r=>new Promise((e,t)=>{if(typeof window>"u"||(window.storyblokRegisterEvent=a=>{if(window.location===window.parent.location){console.warn("You are not in Draft Mode or in the Visual Editor.");return}w?a():E.push(a)},document.getElementById("storyblok-javascript-bridge")))return;const o=document.createElement("script");o.async=!0,o.src=r,o.id="storyblok-javascript-bridge",o.onerror=a=>t(a),o.onload=a=>{E.forEach(s=>s()),w=!0,e(a)},document.getElementsByTagName("head")[0].appendChild(o)});var D=Object.defineProperty,U=(r,e,t)=>e in r?D(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,A=(r,e,t)=>(U(r,typeof e!="symbol"?e+"":e,t),t);const F=function(r,e){const t={};for(const o in r){const a=r[o];e.indexOf(o)>-1&&a!==null&&(t[o]=a)}return t},q=r=>r==="email",B=()=>({singleTag:"hr"}),J=()=>({tag:"blockquote"}),K=()=>({tag:"ul"}),V=r=>({tag:["pre",{tag:"code",attrs:r.attrs}]}),G=()=>({singleTag:"br"}),W=r=>({tag:`h${r.attrs.level}`}),H=r=>({singleTag:[{tag:"img",attrs:F(r.attrs,["src","alt","title"])}]}),Y=()=>({tag:"li"}),Q=()=>({tag:"ol"}),X=()=>({tag:"p"}),Z=r=>({tag:[{tag:"span",attrs:{["data-type"]:"emoji",["data-name"]:r.attrs.name,emoji:r.attrs.emoji}}]}),ee=()=>({tag:"b"}),te=()=>({tag:"strike"}),re=()=>({tag:"u"}),oe=()=>({tag:"strong"}),se=()=>({tag:"code"}),ae=()=>({tag:"i"}),ne=r=>{const e={...r.attrs},{linktype:t="url"}=r.attrs;if(q(t)&&(e.href=`mailto:${e.href}`),e.anchor&&(e.href=`${e.href}#${e.anchor}`,delete e.anchor),e.custom){for(const o in e.custom)e[o]=e.custom[o];delete e.custom}return{tag:[{tag:"a",attrs:e}]}},ie=r=>({tag:[{tag:"span",attrs:r.attrs}]}),le=()=>({tag:"sub"}),ce=()=>({tag:"sup"}),ge=r=>({tag:[{tag:"span",attrs:r.attrs}]}),ue=r=>{var e;return(e=r.attrs)!=null&&e.color?{tag:[{tag:"span",attrs:{style:`background-color:${r.attrs.color};`}}]}:{tag:""}},fe=r=>{var e;return(e=r.attrs)!=null&&e.color?{tag:[{tag:"span",attrs:{style:`color:${r.attrs.color}`}}]}:{tag:""}},C={nodes:{horizontal_rule:B,blockquote:J,bullet_list:K,code_block:V,hard_break:G,heading:W,image:H,list_item:Y,ordered_list:Q,paragraph:X,emoji:Z},marks:{bold:ee,strike:te,underline:re,strong:oe,code:se,italic:ae,link:ne,styled:ie,subscript:le,superscript:ce,anchor:ge,highlight:ue,textStyle:fe}},de=function(r){const e={"&":"&","<":"<",">":">",'"':""","'":"'"},t=/[&<>"']/g,o=RegExp(t.source);return r&&o.test(r)?r.replace(t,a=>e[a]):r};class x{constructor(e){A(this,"marks"),A(this,"nodes"),e||(e=C),this.marks=e.marks||[],this.nodes=e.nodes||[]}addNode(e,t){this.nodes[e]=t}addMark(e,t){this.marks[e]=t}render(e,t={optimizeImages:!1}){if(e&&e.content&&Array.isArray(e.content)){let o="";return e.content.forEach(a=>{o+=this.renderNode(a)}),t.optimizeImages?this.optimizeImages(o,t.optimizeImages):o}return console.warn(`The render method must receive an Object with a "content" field.
|
|
10
|
+
The "content" field must be an array of nodes as the type ISbRichtext.
|
|
11
|
+
ISbRichtext:
|
|
12
|
+
content?: ISbRichtext[]
|
|
13
|
+
marks?: ISbRichtext[]
|
|
14
|
+
attrs?: any
|
|
15
|
+
text?: string
|
|
16
|
+
type: string
|
|
17
|
+
|
|
18
|
+
Example:
|
|
19
|
+
{
|
|
20
|
+
content: [
|
|
21
|
+
{
|
|
22
|
+
content: [
|
|
23
|
+
{
|
|
24
|
+
text: 'Hello World',
|
|
25
|
+
type: 'text'
|
|
26
|
+
}
|
|
27
|
+
],
|
|
28
|
+
type: 'paragraph'
|
|
29
|
+
}
|
|
30
|
+
],
|
|
31
|
+
type: 'doc'
|
|
32
|
+
}`),""}optimizeImages(e,t){let o=0,a=0,s="",n="";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}" `,a=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&&(n+=`:blur(${t.filters.blur})`),typeof t.filters.brightness=="number"&&t.filters.brightness>=-100&&t.filters.brightness<=100&&(n+=`:brightness(${t.filters.brightness})`),t.filters.fill&&(t.filters.fill.match(/[0-9A-Fa-f]{6}/g)||t.filters.fill==="transparent")&&(n+=`:fill(${t.filters.fill})`),t.filters.format&&["webp","png","jpeg"].includes(t.filters.format)&&(n+=`:format(${t.filters.format})`),typeof t.filters.grayscale=="boolean"&&t.filters.grayscale&&(n+=":grayscale()"),typeof t.filters.quality=="number"&&t.filters.quality>=0&&t.filters.quality<=100&&(n+=`:quality(${t.filters.quality})`),t.filters.rotate&&[90,180,270].includes(t.filters.rotate)&&(n+=`:rotate(${t.filters.rotate})`),n.length>0&&(n="/filters"+n))),s.length>0&&(e=e.replace(/<img/g,`<img ${s.trim()}`));const f=o>0||a>0||n.length>0?`${o}x${a}${n}`:"";return e=e.replace(/a.storyblok.com\/f\/(\d+)\/([^.]+)\.(gif|jpg|jpeg|png|tif|tiff|bmp)/g,`a.storyblok.com/f/$1/$2.$3/m/${f}`),typeof t!="boolean"&&(t.sizes||t.srcset)&&(e=e.replace(/<img.*?src=["|'](.*?)["|']/g,i=>{var l,c;const d=i.match(/a.storyblok.com\/f\/(\d+)\/([^.]+)\.(gif|jpg|jpeg|png|tif|tiff|bmp)/g);if(d&&d.length>0){const h={srcset:(l=t.srcset)==null?void 0:l.map(u=>{if(typeof u=="number")return`//${d}/m/${u}x0${n} ${u}w`;if(typeof u=="object"&&u.length===2){let y=0,S=0;return typeof u[0]=="number"&&(y=u[0]),typeof u[1]=="number"&&(S=u[1]),`//${d}/m/${y}x${S}${n} ${y}w`}}).join(", "),sizes:(c=t.sizes)==null?void 0:c.map(u=>u).join(", ")};let m="";return h.srcset&&(m+=`srcset="${h.srcset}" `),h.sizes&&(m+=`sizes="${h.sizes}" `),i.replace(/<img/g,`<img ${m.trim()}`)}return i})),e}renderNode(e){const t=[];e.marks&&e.marks.forEach(a=>{const s=this.getMatchingMark(a);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(a=>{t.push(this.renderNode(a))}):e.text?t.push(de(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(a=>{const s=this.getMatchingMark(a);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 a=`<${o.tag}`;if(o.attrs)for(const s in o.attrs){const n=o.attrs[s];n!==null&&(a+=` ${s}="${n}"`)}return`${a}${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 he=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 pe;const be="https://app.storyblok.com/f/storyblok-v2-latest.js",me=(r,e)=>{r.addNode("blok",t=>{let o="";return t.attrs.body.forEach(a=>{o+=e(a.component,a)}),{html:o}})},ye=(r,e,t)=>{let o=t||pe;if(!o){console.error("Please initialize the Storyblok SDK before calling the renderRichText function");return}return r===""?"":r?(e&&(o=new x(e.schema),e.resolver&&me(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.
|
|
10
33
|
|
|
11
34
|
For more info about the richtext object check https://github.com/storyblok/storyblok-js#rendering-rich-text`),"")},ke=()=>z(be);function $e(){return globalThis.storyblokApiInstance||console.error("storyblokApiInstance has not been initialized correctly"),globalThis.storyblokApiInstance}function ve(r,e){const t=globalThis.storyblokApiInstance.richTextResolver;if(!t){console.error("Please initialize the Storyblok SDK before calling the renderRichText function");return}return ye(r,e,t)}function Ie(r){const e={useCustomApi:!1,bridge:!0,componentsDir:"src",enableFallbackComponent:!1,...r};return{name:"@storyblok/astro",hooks:{"astro:config:setup":({injectScript:t,updateConfig:o})=>{o({vite:{plugins:[p(e.accessToken,e.useCustomApi,e.apiOptions),P(e.componentsDir,e.components,e.enableFallbackComponent,e.customFallbackComponent),_(e)]}}),t("page-ssr",`
|
|
12
35
|
import { storyblokApiInstance } from "virtual:storyblok-init";
|
|
@@ -23,4 +46,4 @@
|
|
|
23
46
|
}
|
|
24
47
|
});
|
|
25
48
|
});
|
|
26
|
-
`)}}}}g.RichTextResolver=
|
|
49
|
+
`)}}}}g.RichTextResolver=x,g.RichTextSchema=C,g.default=Ie,g.loadStoryblokBridge=ke,g.renderRichText=ve,g.storyblokEditable=he,g.useStoryblokApi=$e,Object.defineProperties(g,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|
package/dist/storyblok-astro.mjs
CHANGED
|
@@ -20,11 +20,11 @@ function T(r, e, t) {
|
|
|
20
20
|
}
|
|
21
21
|
};
|
|
22
22
|
}
|
|
23
|
-
const
|
|
24
|
-
let a = !1, s = !1,
|
|
25
|
-
for (let
|
|
26
|
-
const
|
|
27
|
-
u =
|
|
23
|
+
const C = /[\p{Lu}]/u, A = /[\p{Ll}]/u, y = /^[\p{Lu}](?![\p{Lu}])/gu, E = /([\p{Alpha}\p{N}_]|$)/u, b = /[_.\- ]+/, j = new RegExp("^" + b.source), k = new RegExp(b.source + E.source, "gu"), $ = new RegExp("\\d+" + E.source, "gu"), S = (r, e, t, o) => {
|
|
24
|
+
let a = !1, s = !1, n = !1, u = !1;
|
|
25
|
+
for (let l = 0; l < r.length; l++) {
|
|
26
|
+
const i = r[l];
|
|
27
|
+
u = l > 2 ? r[l - 3] === "-" : !0, a && C.test(i) ? (r = r.slice(0, l) + "-" + r.slice(l), a = !1, n = s, s = !0, l++) : s && n && A.test(i) && (!u || o) ? (r = r.slice(0, l - 1) + "-" + r.slice(l - 1), n = s, s = !1, a = !0) : (a = e(i) === i && t(i) !== i, n = s, s = t(i) === i && e(i) !== i);
|
|
28
28
|
}
|
|
29
29
|
return r;
|
|
30
30
|
}, R = (r, e) => (y.lastIndex = 0, r.replace(y, (t) => e(t))), N = (r, e) => (k.lastIndex = 0, $.lastIndex = 0, r.replace(k, (t, o) => e(o)).replace($, (t) => e(t)));
|
|
@@ -38,19 +38,19 @@ function v(r, e) {
|
|
|
38
38
|
}, Array.isArray(r) ? r = r.map((s) => s.trim()).filter((s) => s.length).join("-") : r = r.trim(), r.length === 0)
|
|
39
39
|
return "";
|
|
40
40
|
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);
|
|
41
|
-
return r.length === 1 ? b.test(r) ? "" : e.pascalCase ? o(r) : t(r) : (r !== t(r) && (r = S(r, t, o, e.preserveConsecutiveUppercase)), r = r.replace(
|
|
41
|
+
return r.length === 1 ? b.test(r) ? "" : e.pascalCase ? o(r) : t(r) : (r !== t(r) && (r = S(r, t, o, e.preserveConsecutiveUppercase)), r = r.replace(j, ""), r = e.preserveConsecutiveUppercase ? R(r, t) : t(r), e.pascalCase && (r = o(r.charAt(0)) + r.slice(1)), N(r, o));
|
|
42
42
|
}
|
|
43
|
-
function
|
|
43
|
+
function O(r, e, t, o) {
|
|
44
44
|
const a = "virtual:storyblok-components", s = "\0" + a;
|
|
45
45
|
return {
|
|
46
46
|
name: "vite-plugin-storyblok-components",
|
|
47
|
-
async resolveId(
|
|
48
|
-
if (
|
|
47
|
+
async resolveId(n) {
|
|
48
|
+
if (n === a)
|
|
49
49
|
return s;
|
|
50
50
|
},
|
|
51
|
-
async load(
|
|
52
|
-
if (
|
|
53
|
-
const u = [],
|
|
51
|
+
async load(n) {
|
|
52
|
+
if (n === s) {
|
|
53
|
+
const u = [], l = [];
|
|
54
54
|
for await (const [c, f] of Object.entries(e)) {
|
|
55
55
|
const d = await this.resolve(
|
|
56
56
|
"/" + r + "/" + f + ".astro"
|
|
@@ -58,15 +58,15 @@ function L(r, e, t, o) {
|
|
|
58
58
|
if (d)
|
|
59
59
|
u.push(`import ${v(c)} from "${d.id}"`);
|
|
60
60
|
else if (t)
|
|
61
|
-
|
|
61
|
+
l.push(c);
|
|
62
62
|
else
|
|
63
63
|
throw new Error(
|
|
64
64
|
`Component could not be found for blok "${c}"! Does "${"/" + r + "/" + f}.astro" exist?`
|
|
65
65
|
);
|
|
66
66
|
}
|
|
67
|
-
let
|
|
67
|
+
let i = "";
|
|
68
68
|
if (t)
|
|
69
|
-
if (
|
|
69
|
+
if (i = ",FallbackComponent", o) {
|
|
70
70
|
const c = await this.resolve(
|
|
71
71
|
"/" + r + "/" + o + ".astro"
|
|
72
72
|
);
|
|
@@ -81,12 +81,12 @@ function L(r, e, t, o) {
|
|
|
81
81
|
u.push(
|
|
82
82
|
"import FallbackComponent from '@storyblok/astro/FallbackComponent.astro';"
|
|
83
83
|
);
|
|
84
|
-
return `${u.join(";")};export default {${Object.keys(e).filter((c) => !
|
|
84
|
+
return `${u.join(";")};export default {${Object.keys(e).filter((c) => !l.includes(c)).map((c) => v(c)).join(",")}${i}}`;
|
|
85
85
|
}
|
|
86
86
|
}
|
|
87
87
|
};
|
|
88
88
|
}
|
|
89
|
-
function
|
|
89
|
+
function L(r) {
|
|
90
90
|
const e = "virtual:storyblok-options", t = "\0" + e;
|
|
91
91
|
return {
|
|
92
92
|
name: "vite-plugin-storyblok-options",
|
|
@@ -115,7 +115,7 @@ const w = [], z = (r) => new Promise((e, t) => {
|
|
|
115
115
|
w.forEach((s) => s()), I = !0, e(a);
|
|
116
116
|
}, document.getElementsByTagName("head")[0].appendChild(o);
|
|
117
117
|
});
|
|
118
|
-
var M = Object.defineProperty, P = (r, e, t) => e in r ? M(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t,
|
|
118
|
+
var M = Object.defineProperty, P = (r, e, t) => e in r ? M(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t, x = (r, e, t) => (P(r, typeof e != "symbol" ? e + "" : e, t), t);
|
|
119
119
|
const _ = function(r, e) {
|
|
120
120
|
const t = {};
|
|
121
121
|
for (const o in r) {
|
|
@@ -152,9 +152,9 @@ const _ = function(r, e) {
|
|
|
152
152
|
tag: "li"
|
|
153
153
|
}), W = () => ({
|
|
154
154
|
tag: "ol"
|
|
155
|
-
}),
|
|
155
|
+
}), H = () => ({
|
|
156
156
|
tag: "p"
|
|
157
|
-
}),
|
|
157
|
+
}), Y = (r) => ({
|
|
158
158
|
tag: [
|
|
159
159
|
{
|
|
160
160
|
tag: "span",
|
|
@@ -201,34 +201,44 @@ const _ = function(r, e) {
|
|
|
201
201
|
]
|
|
202
202
|
}), ae = () => ({
|
|
203
203
|
tag: "sub"
|
|
204
|
-
}),
|
|
204
|
+
}), ne = () => ({
|
|
205
205
|
tag: "sup"
|
|
206
|
-
}),
|
|
206
|
+
}), le = (r) => ({
|
|
207
207
|
tag: [
|
|
208
208
|
{
|
|
209
209
|
tag: "span",
|
|
210
210
|
attrs: r.attrs
|
|
211
211
|
}
|
|
212
212
|
]
|
|
213
|
-
}),
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
213
|
+
}), ie = (r) => {
|
|
214
|
+
var e;
|
|
215
|
+
return (e = r.attrs) != null && e.color ? {
|
|
216
|
+
tag: [
|
|
217
|
+
{
|
|
218
|
+
tag: "span",
|
|
219
|
+
attrs: {
|
|
220
|
+
style: `background-color:${r.attrs.color};`
|
|
221
|
+
}
|
|
219
222
|
}
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
223
|
+
]
|
|
224
|
+
} : {
|
|
225
|
+
tag: ""
|
|
226
|
+
};
|
|
227
|
+
}, ce = (r) => {
|
|
228
|
+
var e;
|
|
229
|
+
return (e = r.attrs) != null && e.color ? {
|
|
230
|
+
tag: [
|
|
231
|
+
{
|
|
232
|
+
tag: "span",
|
|
233
|
+
attrs: {
|
|
234
|
+
style: `color:${r.attrs.color}`
|
|
235
|
+
}
|
|
228
236
|
}
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
237
|
+
]
|
|
238
|
+
} : {
|
|
239
|
+
tag: ""
|
|
240
|
+
};
|
|
241
|
+
}, ge = {
|
|
232
242
|
nodes: {
|
|
233
243
|
horizontal_rule: U,
|
|
234
244
|
blockquote: F,
|
|
@@ -239,8 +249,8 @@ const _ = function(r, e) {
|
|
|
239
249
|
image: V,
|
|
240
250
|
list_item: G,
|
|
241
251
|
ordered_list: W,
|
|
242
|
-
paragraph:
|
|
243
|
-
emoji:
|
|
252
|
+
paragraph: H,
|
|
253
|
+
emoji: Y
|
|
244
254
|
},
|
|
245
255
|
marks: {
|
|
246
256
|
bold: Q,
|
|
@@ -252,9 +262,9 @@ const _ = function(r, e) {
|
|
|
252
262
|
link: oe,
|
|
253
263
|
styled: se,
|
|
254
264
|
subscript: ae,
|
|
255
|
-
superscript:
|
|
256
|
-
anchor:
|
|
257
|
-
highlight:
|
|
265
|
+
superscript: ne,
|
|
266
|
+
anchor: le,
|
|
267
|
+
highlight: ie,
|
|
258
268
|
textStyle: ce
|
|
259
269
|
}
|
|
260
270
|
}, ue = function(r) {
|
|
@@ -269,7 +279,7 @@ const _ = function(r, e) {
|
|
|
269
279
|
};
|
|
270
280
|
class fe {
|
|
271
281
|
constructor(e) {
|
|
272
|
-
|
|
282
|
+
x(this, "marks"), x(this, "nodes"), e || (e = ge), this.marks = e.marks || [], this.nodes = e.nodes || [];
|
|
273
283
|
}
|
|
274
284
|
addNode(e, t) {
|
|
275
285
|
this.nodes[e] = t;
|
|
@@ -285,51 +295,74 @@ class fe {
|
|
|
285
295
|
}), t.optimizeImages ? this.optimizeImages(o, t.optimizeImages) : o;
|
|
286
296
|
}
|
|
287
297
|
return console.warn(
|
|
288
|
-
|
|
298
|
+
`The render method must receive an Object with a "content" field.
|
|
299
|
+
The "content" field must be an array of nodes as the type ISbRichtext.
|
|
300
|
+
ISbRichtext:
|
|
301
|
+
content?: ISbRichtext[]
|
|
302
|
+
marks?: ISbRichtext[]
|
|
303
|
+
attrs?: any
|
|
304
|
+
text?: string
|
|
305
|
+
type: string
|
|
306
|
+
|
|
307
|
+
Example:
|
|
308
|
+
{
|
|
309
|
+
content: [
|
|
310
|
+
{
|
|
311
|
+
content: [
|
|
312
|
+
{
|
|
313
|
+
text: 'Hello World',
|
|
314
|
+
type: 'text'
|
|
315
|
+
}
|
|
316
|
+
],
|
|
317
|
+
type: 'paragraph'
|
|
318
|
+
}
|
|
319
|
+
],
|
|
320
|
+
type: 'doc'
|
|
321
|
+
}`
|
|
289
322
|
), "";
|
|
290
323
|
}
|
|
291
324
|
optimizeImages(e, t) {
|
|
292
|
-
let o = 0, a = 0, s = "",
|
|
293
|
-
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}" `, a = 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 && (
|
|
294
|
-
const u = o > 0 || a > 0 ||
|
|
325
|
+
let o = 0, a = 0, s = "", n = "";
|
|
326
|
+
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}" `, a = 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 && (n += `:blur(${t.filters.blur})`), typeof t.filters.brightness == "number" && t.filters.brightness >= -100 && t.filters.brightness <= 100 && (n += `:brightness(${t.filters.brightness})`), t.filters.fill && (t.filters.fill.match(/[0-9A-Fa-f]{6}/g) || t.filters.fill === "transparent") && (n += `:fill(${t.filters.fill})`), t.filters.format && ["webp", "png", "jpeg"].includes(t.filters.format) && (n += `:format(${t.filters.format})`), typeof t.filters.grayscale == "boolean" && t.filters.grayscale && (n += ":grayscale()"), typeof t.filters.quality == "number" && t.filters.quality >= 0 && t.filters.quality <= 100 && (n += `:quality(${t.filters.quality})`), t.filters.rotate && [90, 180, 270].includes(t.filters.rotate) && (n += `:rotate(${t.filters.rotate})`), n.length > 0 && (n = "/filters" + n))), s.length > 0 && (e = e.replace(/<img/g, `<img ${s.trim()}`));
|
|
327
|
+
const u = o > 0 || a > 0 || n.length > 0 ? `${o}x${a}${n}` : "";
|
|
295
328
|
return e = e.replace(
|
|
296
329
|
/a.storyblok.com\/f\/(\d+)\/([^.]+)\.(gif|jpg|jpeg|png|tif|tiff|bmp)/g,
|
|
297
330
|
`a.storyblok.com/f/$1/$2.$3/m/${u}`
|
|
298
|
-
), typeof t != "boolean" && (t.sizes || t.srcset) && (e = e.replace(/<img.*?src=["|'](.*?)["|']/g, (
|
|
299
|
-
var
|
|
300
|
-
const f =
|
|
331
|
+
), typeof t != "boolean" && (t.sizes || t.srcset) && (e = e.replace(/<img.*?src=["|'](.*?)["|']/g, (l) => {
|
|
332
|
+
var i, c;
|
|
333
|
+
const f = l.match(
|
|
301
334
|
/a.storyblok.com\/f\/(\d+)\/([^.]+)\.(gif|jpg|jpeg|png|tif|tiff|bmp)/g
|
|
302
335
|
);
|
|
303
336
|
if (f && f.length > 0) {
|
|
304
337
|
const d = {
|
|
305
|
-
srcset: (
|
|
338
|
+
srcset: (i = t.srcset) == null ? void 0 : i.map((g) => {
|
|
306
339
|
if (typeof g == "number")
|
|
307
|
-
return `//${f}/m/${g}x0${
|
|
340
|
+
return `//${f}/m/${g}x0${n} ${g}w`;
|
|
308
341
|
if (typeof g == "object" && g.length === 2) {
|
|
309
|
-
let
|
|
310
|
-
return typeof g[0] == "number" && (
|
|
342
|
+
let h = 0, m = 0;
|
|
343
|
+
return typeof g[0] == "number" && (h = g[0]), typeof g[1] == "number" && (m = g[1]), `//${f}/m/${h}x${m}${n} ${h}w`;
|
|
311
344
|
}
|
|
312
345
|
}).join(", "),
|
|
313
346
|
sizes: (c = t.sizes) == null ? void 0 : c.map((g) => g).join(", ")
|
|
314
347
|
};
|
|
315
|
-
let
|
|
316
|
-
return d.srcset && (
|
|
348
|
+
let p = "";
|
|
349
|
+
return d.srcset && (p += `srcset="${d.srcset}" `), d.sizes && (p += `sizes="${d.sizes}" `), l.replace(/<img/g, `<img ${p.trim()}`);
|
|
317
350
|
}
|
|
318
|
-
return
|
|
351
|
+
return l;
|
|
319
352
|
})), e;
|
|
320
353
|
}
|
|
321
354
|
renderNode(e) {
|
|
322
355
|
const t = [];
|
|
323
356
|
e.marks && e.marks.forEach((a) => {
|
|
324
357
|
const s = this.getMatchingMark(a);
|
|
325
|
-
s && t.push(this.renderOpeningTag(s.tag));
|
|
358
|
+
s && s.tag !== "" && t.push(this.renderOpeningTag(s.tag));
|
|
326
359
|
});
|
|
327
360
|
const o = this.getMatchingNode(e);
|
|
328
361
|
return o && o.tag && t.push(this.renderOpeningTag(o.tag)), e.content ? e.content.forEach((a) => {
|
|
329
362
|
t.push(this.renderNode(a));
|
|
330
363
|
}) : e.text ? t.push(ue(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((a) => {
|
|
331
364
|
const s = this.getMatchingMark(a);
|
|
332
|
-
s && t.push(this.renderClosingTag(s.tag));
|
|
365
|
+
s && s.tag !== "" && t.push(this.renderClosingTag(s.tag));
|
|
333
366
|
}), t.join("");
|
|
334
367
|
}
|
|
335
368
|
renderTag(e, t) {
|
|
@@ -340,8 +373,8 @@ class fe {
|
|
|
340
373
|
let a = `<${o.tag}`;
|
|
341
374
|
if (o.attrs)
|
|
342
375
|
for (const s in o.attrs) {
|
|
343
|
-
const
|
|
344
|
-
|
|
376
|
+
const n = o.attrs[s];
|
|
377
|
+
n !== null && (a += ` ${s}="${n}"`);
|
|
345
378
|
}
|
|
346
379
|
return `${a}${t}>`;
|
|
347
380
|
}
|
|
@@ -392,7 +425,7 @@ const me = (r) => {
|
|
|
392
425
|
};
|
|
393
426
|
};
|
|
394
427
|
let de;
|
|
395
|
-
const
|
|
428
|
+
const pe = "https://app.storyblok.com/f/storyblok-v2-latest.js", he = (r, e) => {
|
|
396
429
|
r.addNode("blok", (t) => {
|
|
397
430
|
let o = "";
|
|
398
431
|
return t.attrs.body.forEach((a) => {
|
|
@@ -409,10 +442,10 @@ const he = "https://app.storyblok.com/f/storyblok-v2-latest.js", pe = (r, e) =>
|
|
|
409
442
|
);
|
|
410
443
|
return;
|
|
411
444
|
}
|
|
412
|
-
return r === "" ? "" : r ? (e && (o = new fe(e.schema), e.resolver &&
|
|
445
|
+
return r === "" ? "" : r ? (e && (o = new fe(e.schema), e.resolver && he(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.
|
|
413
446
|
|
|
414
447
|
For more info about the richtext object check https://github.com/storyblok/storyblok-js#rendering-rich-text`), "");
|
|
415
|
-
}, ye = () => z(
|
|
448
|
+
}, ye = () => z(pe);
|
|
416
449
|
function ke() {
|
|
417
450
|
return globalThis.storyblokApiInstance || console.error("storyblokApiInstance has not been initialized correctly"), globalThis.storyblokApiInstance;
|
|
418
451
|
}
|
|
@@ -446,13 +479,13 @@ function ve(r) {
|
|
|
446
479
|
e.useCustomApi,
|
|
447
480
|
e.apiOptions
|
|
448
481
|
),
|
|
449
|
-
|
|
482
|
+
O(
|
|
450
483
|
e.componentsDir,
|
|
451
484
|
e.components,
|
|
452
485
|
e.enableFallbackComponent,
|
|
453
486
|
e.customFallbackComponent
|
|
454
487
|
),
|
|
455
|
-
|
|
488
|
+
L(e)
|
|
456
489
|
]
|
|
457
490
|
}
|
|
458
491
|
}), t(
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@storyblok/astro",
|
|
3
|
-
"version": "2.3.
|
|
3
|
+
"version": "2.3.2",
|
|
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",
|
|
@@ -30,20 +30,20 @@
|
|
|
30
30
|
"prepublishOnly": "npm run build && cp ../README.md ./"
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@storyblok/js": "^2.1.
|
|
33
|
+
"@storyblok/js": "^2.1.5",
|
|
34
34
|
"camelcase": "^7.0.1"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
37
|
"@cypress/vite-dev-server": "^5.0.5",
|
|
38
38
|
"@rollup/plugin-dynamic-import-vars": "^2.0.3",
|
|
39
|
-
"@types/node": "
|
|
40
|
-
"astro": "2.3
|
|
41
|
-
"cypress": "^12.
|
|
42
|
-
"eslint-plugin-cypress": "^2.13.
|
|
39
|
+
"@types/node": "20.2.3",
|
|
40
|
+
"astro": "2.5.3",
|
|
41
|
+
"cypress": "^12.12.0",
|
|
42
|
+
"eslint-plugin-cypress": "^2.13.3",
|
|
43
43
|
"start-server-and-test": "^2.0.0",
|
|
44
44
|
"typescript": "5.0.4",
|
|
45
|
-
"vite": "^4.
|
|
46
|
-
"vite-plugin-dts": "^2.
|
|
45
|
+
"vite": "^4.3.8",
|
|
46
|
+
"vite-plugin-dts": "^2.3.0"
|
|
47
47
|
},
|
|
48
48
|
"repository": {
|
|
49
49
|
"type": "git",
|