@storyblok/astro 1.2.0 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -0
- package/StoryblokComponent.astro +6 -0
- package/dist/storyblok-astro.js +8 -8
- package/dist/storyblok-astro.mjs +210 -239
- package/package.json +12 -9
package/README.md
CHANGED
|
@@ -59,6 +59,8 @@ export default defineConfig({
|
|
|
59
59
|
});
|
|
60
60
|
```
|
|
61
61
|
|
|
62
|
+
> ⚠️ 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).
|
|
63
|
+
|
|
62
64
|
### Options
|
|
63
65
|
|
|
64
66
|
When you initialize the integration, you can pass all [_@storyblok/js_ options](https://github.com/storyblok/storyblok-js#features-and-api). For spaces created in the United States, you have to set the `region` parameter accordingly `{ apiOptions: { region: 'us' } }`.
|
package/StoryblokComponent.astro
CHANGED
package/dist/storyblok-astro.js
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
(function(
|
|
1
|
+
(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`
|
|
2
2
|
import { storyblokInit, apiPlugin } from "@storyblok/js";
|
|
3
3
|
const { storyblokApi } = storyblokInit({
|
|
4
|
-
accessToken: "${
|
|
4
|
+
accessToken: "${t}",
|
|
5
5
|
use: ${e?"[]":"[apiPlugin]"},
|
|
6
|
-
apiOptions: ${JSON.stringify(
|
|
6
|
+
apiOptions: ${JSON.stringify(r)},
|
|
7
7
|
});
|
|
8
|
-
export const storyblokApiInstance = storyblokApi;
|
|
9
|
-
`}}}const
|
|
8
|
+
export const storyblokApiInstance = storyblokApi;
|
|
9
|
+
`}}}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.
|
|
10
10
|
|
|
11
|
-
For more info about the richtext object check https://github.com/storyblok/storyblok-js#rendering-rich-text`),"")},
|
|
11
|
+
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",`
|
|
12
12
|
import { storyblokApiInstance } from "virtual:storyblok-init";
|
|
13
13
|
globalThis.storyblokApiInstance = storyblokApiInstance;
|
|
14
|
-
`),
|
|
14
|
+
`),t.bridge&&e("page",`
|
|
15
15
|
import { loadStoryblokBridge } from "@storyblok/astro";
|
|
16
16
|
loadStoryblokBridge().then(() => {
|
|
17
17
|
const { StoryblokBridge, location } = window;
|
|
@@ -23,4 +23,4 @@
|
|
|
23
23
|
}
|
|
24
24
|
});
|
|
25
25
|
});
|
|
26
|
-
`)}}}}
|
|
26
|
+
`)}}}}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"}})});
|
package/dist/storyblok-astro.mjs
CHANGED
|
@@ -1,271 +1,234 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const o = "virtual:storyblok-init", n = "\0" + o;
|
|
1
|
+
function k(t, e, r) {
|
|
2
|
+
const o = "virtual:storyblok-init", s = "\0" + o;
|
|
4
3
|
return {
|
|
5
4
|
name: "vite-plugin-storyblok-init",
|
|
6
|
-
async resolveId(
|
|
7
|
-
if (
|
|
8
|
-
return
|
|
5
|
+
async resolveId(n) {
|
|
6
|
+
if (n === o)
|
|
7
|
+
return s;
|
|
9
8
|
},
|
|
10
|
-
async load(
|
|
11
|
-
if (
|
|
9
|
+
async load(n) {
|
|
10
|
+
if (n === s)
|
|
12
11
|
return `
|
|
13
12
|
import { storyblokInit, apiPlugin } from "@storyblok/js";
|
|
14
13
|
const { storyblokApi } = storyblokInit({
|
|
15
|
-
accessToken: "${
|
|
14
|
+
accessToken: "${t}",
|
|
16
15
|
use: ${e ? "[]" : "[apiPlugin]"},
|
|
17
|
-
apiOptions: ${JSON.stringify(
|
|
16
|
+
apiOptions: ${JSON.stringify(r)},
|
|
18
17
|
});
|
|
19
|
-
export const storyblokApiInstance = storyblokApi;
|
|
18
|
+
export const storyblokApiInstance = storyblokApi;
|
|
20
19
|
`;
|
|
21
20
|
}
|
|
22
21
|
};
|
|
23
22
|
}
|
|
24
|
-
const
|
|
25
|
-
let o = !1,
|
|
26
|
-
for (let
|
|
27
|
-
const
|
|
28
|
-
o &&
|
|
23
|
+
const v = /[\p{Lu}]/u, I = /[\p{Ll}]/u, c = /^[\p{Lu}](?![\p{Lu}])/gu, m = /([\p{Alpha}\p{N}_]|$)/u, i = /[_.\- ]+/, T = new RegExp("^" + i.source), u = new RegExp(i.source + m.source, "gu"), d = new RegExp("\\d+" + m.source, "gu"), E = (t, e, r) => {
|
|
24
|
+
let o = !1, s = !1, n = !1;
|
|
25
|
+
for (let a = 0; a < t.length; a++) {
|
|
26
|
+
const l = t[a];
|
|
27
|
+
o && v.test(l) ? (t = t.slice(0, a) + "-" + t.slice(a), o = !1, n = s, s = !0, a++) : s && n && I.test(l) ? (t = t.slice(0, a - 1) + "-" + t.slice(a - 1), n = s, s = !1, o = !0) : (o = e(l) === l && r(l) !== l, n = s, s = r(l) === l && e(l) !== l);
|
|
29
28
|
}
|
|
30
|
-
return
|
|
31
|
-
},
|
|
32
|
-
function
|
|
33
|
-
if (!(typeof
|
|
29
|
+
return t;
|
|
30
|
+
}, A = (t, e) => (c.lastIndex = 0, t.replace(c, (r) => e(r))), w = (t, e) => (u.lastIndex = 0, d.lastIndex = 0, t.replace(u, (r, o) => e(o)).replace(d, (r) => e(r)));
|
|
31
|
+
function g(t, e) {
|
|
32
|
+
if (!(typeof t == "string" || Array.isArray(t)))
|
|
34
33
|
throw new TypeError("Expected the input to be `string | string[]`");
|
|
35
34
|
if (e = {
|
|
36
35
|
pascalCase: !1,
|
|
37
36
|
preserveConsecutiveUppercase: !1,
|
|
38
37
|
...e
|
|
39
|
-
}, Array.isArray(
|
|
38
|
+
}, Array.isArray(t) ? t = t.map((n) => n.trim()).filter((n) => n.length).join("-") : t = t.trim(), t.length === 0)
|
|
40
39
|
return "";
|
|
41
|
-
const
|
|
42
|
-
return
|
|
40
|
+
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);
|
|
41
|
+
return t.length === 1 ? i.test(t) ? "" : e.pascalCase ? o(t) : r(t) : (t !== r(t) && (t = E(t, r, o)), t = t.replace(T, ""), t = e.preserveConsecutiveUppercase ? A(t, r) : r(t), e.pascalCase && (t = o(t.charAt(0)) + t.slice(1)), w(t, o));
|
|
43
42
|
}
|
|
44
|
-
function
|
|
45
|
-
const e = "virtual:storyblok-components",
|
|
43
|
+
function S(t) {
|
|
44
|
+
const e = "virtual:storyblok-components", r = "\0" + e;
|
|
46
45
|
return {
|
|
47
46
|
name: "vite-plugin-storyblok-components",
|
|
48
47
|
async resolveId(o) {
|
|
49
48
|
if (o === e)
|
|
50
|
-
return
|
|
49
|
+
return r;
|
|
51
50
|
},
|
|
52
51
|
async load(o) {
|
|
53
|
-
if (o ===
|
|
54
|
-
const
|
|
55
|
-
for await (const [
|
|
56
|
-
const { id:
|
|
57
|
-
|
|
52
|
+
if (o === r) {
|
|
53
|
+
const s = [];
|
|
54
|
+
for await (const [n, a] of Object.entries(t)) {
|
|
55
|
+
const { id: l } = await this.resolve("/src/" + a + ".astro");
|
|
56
|
+
s.push(`import ${g(n)} from "${l}"`);
|
|
58
57
|
}
|
|
59
|
-
return `${
|
|
58
|
+
return `${s.join(";")};export default {${Object.keys(t).map((n) => g(n)).join(",")}}`;
|
|
60
59
|
}
|
|
61
60
|
}
|
|
62
61
|
};
|
|
63
62
|
}
|
|
64
|
-
var
|
|
65
|
-
for (var
|
|
66
|
-
R.call(e,
|
|
63
|
+
var C = Object.defineProperty, h = Object.getOwnPropertySymbols, R = Object.prototype.hasOwnProperty, _ = Object.prototype.propertyIsEnumerable, f = (t, e, r) => e in t ? C(t, e, { enumerable: !0, configurable: !0, writable: !0, value: r }) : t[e] = r, x = (t, e) => {
|
|
64
|
+
for (var r in e || (e = {}))
|
|
65
|
+
R.call(e, r) && f(t, r, e[r]);
|
|
67
66
|
if (h)
|
|
68
|
-
for (var
|
|
69
|
-
_.call(e,
|
|
70
|
-
return
|
|
67
|
+
for (var r of h(e))
|
|
68
|
+
_.call(e, r) && f(t, r, e[r]);
|
|
69
|
+
return t;
|
|
71
70
|
};
|
|
72
|
-
let
|
|
73
|
-
const
|
|
74
|
-
if (typeof window > "u" || (window.storyblokRegisterEvent = (
|
|
71
|
+
let p = !1;
|
|
72
|
+
const b = [], $ = (t) => new Promise((e, r) => {
|
|
73
|
+
if (typeof window > "u" || (window.storyblokRegisterEvent = (s) => {
|
|
75
74
|
if (window.location === window.parent.location) {
|
|
76
75
|
console.warn("You are not in Draft Mode or in the Visual Editor.");
|
|
77
76
|
return;
|
|
78
77
|
}
|
|
79
|
-
|
|
78
|
+
p ? s() : b.push(s);
|
|
80
79
|
}, document.getElementById("storyblok-javascript-bridge")))
|
|
81
80
|
return;
|
|
82
81
|
const o = document.createElement("script");
|
|
83
|
-
o.async = !0, o.src =
|
|
84
|
-
|
|
82
|
+
o.async = !0, o.src = t, o.id = "storyblok-javascript-bridge", o.onerror = (s) => r(s), o.onload = (s) => {
|
|
83
|
+
b.forEach((n) => n()), p = !0, e(s);
|
|
85
84
|
}, document.getElementsByTagName("head")[0].appendChild(o);
|
|
86
|
-
})
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
for (
|
|
91
|
-
|
|
92
|
-
e.indexOf(o) > -1 &&
|
|
85
|
+
});
|
|
86
|
+
var O = Object.defineProperty, P = (t, e, r) => e in t ? O(t, e, { enumerable: !0, configurable: !0, writable: !0, value: r }) : t[e] = r, y = (t, e, r) => (P(t, typeof e != "symbol" ? e + "" : e, r), r);
|
|
87
|
+
const N = function(t, e) {
|
|
88
|
+
const r = {};
|
|
89
|
+
for (const o in t) {
|
|
90
|
+
const s = t[o];
|
|
91
|
+
e.indexOf(o) > -1 && s !== null && (r[o] = s);
|
|
93
92
|
}
|
|
94
|
-
return
|
|
95
|
-
},
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
},
|
|
108
|
-
bullet_list() {
|
|
109
|
-
return {
|
|
110
|
-
tag: "ul"
|
|
111
|
-
};
|
|
112
|
-
},
|
|
113
|
-
code_block(r) {
|
|
114
|
-
return {
|
|
115
|
-
tag: [
|
|
116
|
-
"pre",
|
|
117
|
-
{
|
|
118
|
-
tag: "code",
|
|
119
|
-
attrs: r.attrs
|
|
120
|
-
}
|
|
121
|
-
]
|
|
122
|
-
};
|
|
123
|
-
},
|
|
124
|
-
hard_break() {
|
|
125
|
-
return {
|
|
126
|
-
singleTag: "br"
|
|
127
|
-
};
|
|
128
|
-
},
|
|
129
|
-
heading(r) {
|
|
130
|
-
return {
|
|
131
|
-
tag: `h${r.attrs.level}`
|
|
132
|
-
};
|
|
133
|
-
},
|
|
134
|
-
image(r) {
|
|
135
|
-
return {
|
|
136
|
-
singleTag: [
|
|
137
|
-
{
|
|
138
|
-
tag: "img",
|
|
139
|
-
attrs: $(r.attrs, ["src", "alt", "title"])
|
|
140
|
-
}
|
|
141
|
-
]
|
|
142
|
-
};
|
|
143
|
-
},
|
|
144
|
-
list_item() {
|
|
145
|
-
return {
|
|
146
|
-
tag: "li"
|
|
147
|
-
};
|
|
148
|
-
},
|
|
149
|
-
ordered_list() {
|
|
150
|
-
return {
|
|
151
|
-
tag: "ol"
|
|
152
|
-
};
|
|
153
|
-
},
|
|
154
|
-
paragraph() {
|
|
155
|
-
return {
|
|
156
|
-
tag: "p"
|
|
157
|
-
};
|
|
93
|
+
return r;
|
|
94
|
+
}, j = (t) => t === "email", L = () => ({
|
|
95
|
+
singleTag: "hr"
|
|
96
|
+
}), M = () => ({
|
|
97
|
+
tag: "blockquote"
|
|
98
|
+
}), U = () => ({
|
|
99
|
+
tag: "ul"
|
|
100
|
+
}), D = (t) => ({
|
|
101
|
+
tag: [
|
|
102
|
+
"pre",
|
|
103
|
+
{
|
|
104
|
+
tag: "code",
|
|
105
|
+
attrs: t.attrs
|
|
158
106
|
}
|
|
107
|
+
]
|
|
108
|
+
}), B = () => ({
|
|
109
|
+
singleTag: "br"
|
|
110
|
+
}), z = (t) => ({
|
|
111
|
+
tag: `h${t.attrs.level}`
|
|
112
|
+
}), F = (t) => ({
|
|
113
|
+
singleTag: [
|
|
114
|
+
{
|
|
115
|
+
tag: "img",
|
|
116
|
+
attrs: N(t.attrs, ["src", "alt", "title"])
|
|
117
|
+
}
|
|
118
|
+
]
|
|
119
|
+
}), V = () => ({
|
|
120
|
+
tag: "li"
|
|
121
|
+
}), q = () => ({
|
|
122
|
+
tag: "ol"
|
|
123
|
+
}), J = () => ({
|
|
124
|
+
tag: "p"
|
|
125
|
+
}), G = () => ({
|
|
126
|
+
tag: "b"
|
|
127
|
+
}), K = () => ({
|
|
128
|
+
tag: "strike"
|
|
129
|
+
}), H = () => ({
|
|
130
|
+
tag: "u"
|
|
131
|
+
}), W = () => ({
|
|
132
|
+
tag: "strong"
|
|
133
|
+
}), Y = () => ({
|
|
134
|
+
tag: "code"
|
|
135
|
+
}), Q = () => ({
|
|
136
|
+
tag: "i"
|
|
137
|
+
}), X = (t) => {
|
|
138
|
+
const e = x({}, t.attrs), { linktype: r = "url" } = t.attrs;
|
|
139
|
+
return j(r) && (e.href = `mailto:${e.href}`), e.anchor && (e.href = `${e.href}#${e.anchor}`, delete e.anchor), {
|
|
140
|
+
tag: [
|
|
141
|
+
{
|
|
142
|
+
tag: "a",
|
|
143
|
+
attrs: e
|
|
144
|
+
}
|
|
145
|
+
]
|
|
146
|
+
};
|
|
147
|
+
}, Z = (t) => ({
|
|
148
|
+
tag: [
|
|
149
|
+
{
|
|
150
|
+
tag: "span",
|
|
151
|
+
attrs: t.attrs
|
|
152
|
+
}
|
|
153
|
+
]
|
|
154
|
+
}), ee = {
|
|
155
|
+
nodes: {
|
|
156
|
+
horizontal_rule: L,
|
|
157
|
+
blockquote: M,
|
|
158
|
+
bullet_list: U,
|
|
159
|
+
code_block: D,
|
|
160
|
+
hard_break: B,
|
|
161
|
+
heading: z,
|
|
162
|
+
image: F,
|
|
163
|
+
list_item: V,
|
|
164
|
+
ordered_list: q,
|
|
165
|
+
paragraph: J
|
|
159
166
|
},
|
|
160
167
|
marks: {
|
|
161
|
-
bold
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
};
|
|
170
|
-
},
|
|
171
|
-
underline() {
|
|
172
|
-
return {
|
|
173
|
-
tag: "u"
|
|
174
|
-
};
|
|
175
|
-
},
|
|
176
|
-
strong() {
|
|
177
|
-
return {
|
|
178
|
-
tag: "strong"
|
|
179
|
-
};
|
|
180
|
-
},
|
|
181
|
-
code() {
|
|
182
|
-
return {
|
|
183
|
-
tag: "code"
|
|
184
|
-
};
|
|
185
|
-
},
|
|
186
|
-
italic() {
|
|
187
|
-
return {
|
|
188
|
-
tag: "i"
|
|
189
|
-
};
|
|
190
|
-
},
|
|
191
|
-
link(r) {
|
|
192
|
-
const e = C({}, r.attrs), { linktype: t = "url" } = r.attrs;
|
|
193
|
-
return O(t) && (e.href = `mailto:${e.href}`), e.anchor && (e.href = `${e.href}#${e.anchor}`, delete e.anchor), {
|
|
194
|
-
tag: [
|
|
195
|
-
{
|
|
196
|
-
tag: "a",
|
|
197
|
-
attrs: e
|
|
198
|
-
}
|
|
199
|
-
]
|
|
200
|
-
};
|
|
201
|
-
},
|
|
202
|
-
styled(r) {
|
|
203
|
-
return {
|
|
204
|
-
tag: [
|
|
205
|
-
{
|
|
206
|
-
tag: "span",
|
|
207
|
-
attrs: r.attrs
|
|
208
|
-
}
|
|
209
|
-
]
|
|
210
|
-
};
|
|
211
|
-
}
|
|
168
|
+
bold: G,
|
|
169
|
+
strike: K,
|
|
170
|
+
underline: H,
|
|
171
|
+
strong: W,
|
|
172
|
+
code: Y,
|
|
173
|
+
italic: Q,
|
|
174
|
+
link: X,
|
|
175
|
+
styled: Z
|
|
212
176
|
}
|
|
213
|
-
}
|
|
214
|
-
const P = function(r) {
|
|
177
|
+
}, te = function(t) {
|
|
215
178
|
const e = {
|
|
216
179
|
"&": "&",
|
|
217
180
|
"<": "<",
|
|
218
181
|
">": ">",
|
|
219
182
|
'"': """,
|
|
220
183
|
"'": "'"
|
|
221
|
-
},
|
|
222
|
-
return
|
|
184
|
+
}, r = /[&<>"']/g, o = RegExp(r.source);
|
|
185
|
+
return t && o.test(t) ? t.replace(r, (s) => e[s]) : t;
|
|
223
186
|
};
|
|
224
|
-
class
|
|
187
|
+
class re {
|
|
225
188
|
constructor(e) {
|
|
226
|
-
e || (e =
|
|
189
|
+
y(this, "marks"), y(this, "nodes"), e || (e = ee), this.marks = e.marks || [], this.nodes = e.nodes || [];
|
|
227
190
|
}
|
|
228
|
-
addNode(e,
|
|
229
|
-
this.nodes[e] =
|
|
191
|
+
addNode(e, r) {
|
|
192
|
+
this.nodes[e] = r;
|
|
230
193
|
}
|
|
231
|
-
addMark(e,
|
|
232
|
-
this.marks[e] =
|
|
194
|
+
addMark(e, r) {
|
|
195
|
+
this.marks[e] = r;
|
|
233
196
|
}
|
|
234
|
-
render(e
|
|
235
|
-
if (e.content && Array.isArray(e.content)) {
|
|
236
|
-
let
|
|
197
|
+
render(e) {
|
|
198
|
+
if (e && e.content && Array.isArray(e.content)) {
|
|
199
|
+
let r = "";
|
|
237
200
|
return e.content.forEach((o) => {
|
|
238
|
-
|
|
239
|
-
}),
|
|
201
|
+
r += this.renderNode(o);
|
|
202
|
+
}), r;
|
|
240
203
|
}
|
|
241
204
|
return console.warn("The render method must receive an object with a content field, which is an array"), "";
|
|
242
205
|
}
|
|
243
206
|
renderNode(e) {
|
|
244
|
-
|
|
245
|
-
e.marks && e.marks.forEach((
|
|
246
|
-
const
|
|
247
|
-
|
|
207
|
+
const r = [];
|
|
208
|
+
e.marks && e.marks.forEach((s) => {
|
|
209
|
+
const n = this.getMatchingMark(s);
|
|
210
|
+
n && r.push(this.renderOpeningTag(n.tag));
|
|
248
211
|
});
|
|
249
212
|
const o = this.getMatchingNode(e);
|
|
250
|
-
return o && o.tag &&
|
|
251
|
-
|
|
252
|
-
}) : e.text ?
|
|
253
|
-
const
|
|
254
|
-
|
|
255
|
-
}),
|
|
213
|
+
return o && o.tag && r.push(this.renderOpeningTag(o.tag)), e.content ? e.content.forEach((s) => {
|
|
214
|
+
r.push(this.renderNode(s));
|
|
215
|
+
}) : e.text ? r.push(te(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) => {
|
|
216
|
+
const n = this.getMatchingMark(s);
|
|
217
|
+
n && r.push(this.renderClosingTag(n.tag));
|
|
218
|
+
}), r.join("");
|
|
256
219
|
}
|
|
257
|
-
renderTag(e,
|
|
258
|
-
return e.constructor === String ? `<${e}${
|
|
259
|
-
if (
|
|
260
|
-
return `<${
|
|
220
|
+
renderTag(e, r) {
|
|
221
|
+
return e.constructor === String ? `<${e}${r}>` : e.map((o) => {
|
|
222
|
+
if (o.constructor === String)
|
|
223
|
+
return `<${o}${r}>`;
|
|
261
224
|
{
|
|
262
|
-
let s = `<${
|
|
263
|
-
if (
|
|
264
|
-
for (
|
|
265
|
-
|
|
266
|
-
a !== null && (s += ` ${
|
|
225
|
+
let s = `<${o.tag}`;
|
|
226
|
+
if (o.attrs)
|
|
227
|
+
for (const n in o.attrs) {
|
|
228
|
+
const a = o.attrs[n];
|
|
229
|
+
a !== null && (s += ` ${n}="${a}"`);
|
|
267
230
|
}
|
|
268
|
-
return `${s}${
|
|
231
|
+
return `${s}${r}>`;
|
|
269
232
|
}
|
|
270
233
|
}).join("");
|
|
271
234
|
}
|
|
@@ -273,74 +236,81 @@ class L {
|
|
|
273
236
|
return this.renderTag(e, "");
|
|
274
237
|
}
|
|
275
238
|
renderClosingTag(e) {
|
|
276
|
-
return e.constructor === String ? `</${e}>` : e.slice(0).reverse().map((
|
|
239
|
+
return e.constructor === String ? `</${e}>` : e.slice(0).reverse().map((r) => r.constructor === String ? `</${r}>` : `</${r.tag}>`).join("");
|
|
277
240
|
}
|
|
278
241
|
getMatchingNode(e) {
|
|
279
|
-
|
|
280
|
-
|
|
242
|
+
const r = this.nodes[e.type];
|
|
243
|
+
if (typeof r == "function")
|
|
244
|
+
return r(e);
|
|
281
245
|
}
|
|
282
246
|
getMatchingMark(e) {
|
|
283
|
-
|
|
284
|
-
|
|
247
|
+
const r = this.marks[e.type];
|
|
248
|
+
if (typeof r == "function")
|
|
249
|
+
return r(e);
|
|
285
250
|
}
|
|
286
251
|
}
|
|
287
|
-
var
|
|
288
|
-
if (typeof
|
|
252
|
+
var le = (t) => {
|
|
253
|
+
if (typeof t != "object" || typeof t._editable > "u")
|
|
289
254
|
return {};
|
|
290
|
-
const e = JSON.parse(
|
|
255
|
+
const e = JSON.parse(t._editable.replace(/^<!--#storyblok#/, "").replace(/-->$/, ""));
|
|
291
256
|
return {
|
|
292
257
|
"data-blok-c": JSON.stringify(e),
|
|
293
258
|
"data-blok-uid": e.id + "-" + e.uid
|
|
294
259
|
};
|
|
295
260
|
};
|
|
296
|
-
let
|
|
297
|
-
const
|
|
298
|
-
|
|
261
|
+
let oe;
|
|
262
|
+
const se = "https://app.storyblok.com/f/storyblok-v2-latest.js", ne = (t, e) => {
|
|
263
|
+
t.addNode("blok", (r) => {
|
|
299
264
|
let o = "";
|
|
300
|
-
return
|
|
301
|
-
o += e(
|
|
265
|
+
return r.attrs.body.forEach((s) => {
|
|
266
|
+
o += e(s.component, s);
|
|
302
267
|
}), {
|
|
303
268
|
html: o
|
|
304
269
|
};
|
|
305
270
|
});
|
|
306
|
-
},
|
|
307
|
-
let o =
|
|
271
|
+
}, ae = (t, e, r) => {
|
|
272
|
+
let o = r || oe;
|
|
308
273
|
if (!o) {
|
|
309
274
|
console.error("Please initialize the Storyblok SDK before calling the renderRichText function");
|
|
310
275
|
return;
|
|
311
276
|
}
|
|
312
|
-
return
|
|
277
|
+
return t === "" ? "" : t ? (e && (o = new re(e.schema), e.resolver && ne(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.
|
|
313
278
|
|
|
314
279
|
For more info about the richtext object check https://github.com/storyblok/storyblok-js#rendering-rich-text`), "");
|
|
315
|
-
},
|
|
316
|
-
function
|
|
317
|
-
return globalThis.storyblokApiInstance || console.error("storyblokApiInstance has not been initialized correctly"), storyblokApiInstance;
|
|
280
|
+
}, ie = () => $(se);
|
|
281
|
+
function ce() {
|
|
282
|
+
return globalThis.storyblokApiInstance || console.error("storyblokApiInstance has not been initialized correctly"), globalThis.storyblokApiInstance;
|
|
318
283
|
}
|
|
319
|
-
function
|
|
320
|
-
const
|
|
321
|
-
if (!
|
|
284
|
+
function ue(t, e) {
|
|
285
|
+
const r = globalThis.storyblokApiInstance.richTextResolver;
|
|
286
|
+
if (!r) {
|
|
322
287
|
console.error(
|
|
323
288
|
"Please initialize the Storyblok SDK before calling the renderRichText function"
|
|
324
289
|
);
|
|
325
290
|
return;
|
|
326
291
|
}
|
|
327
|
-
return
|
|
292
|
+
return ae(t, e, r);
|
|
328
293
|
}
|
|
329
|
-
function
|
|
294
|
+
function de(t = {
|
|
295
|
+
accessToken: "",
|
|
296
|
+
useCustomApi: !1,
|
|
297
|
+
apiOptions: {},
|
|
298
|
+
bridge: !0,
|
|
299
|
+
components: {}
|
|
300
|
+
}) {
|
|
330
301
|
return {
|
|
331
302
|
name: "@storyblok/astro",
|
|
332
303
|
hooks: {
|
|
333
|
-
"astro:config:setup": ({ injectScript: e, updateConfig:
|
|
334
|
-
|
|
335
|
-
t({
|
|
304
|
+
"astro:config:setup": ({ injectScript: e, updateConfig: r }) => {
|
|
305
|
+
r({
|
|
336
306
|
vite: {
|
|
337
307
|
plugins: [
|
|
338
308
|
k(
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
309
|
+
t.accessToken,
|
|
310
|
+
t.useCustomApi,
|
|
311
|
+
t.apiOptions
|
|
342
312
|
),
|
|
343
|
-
|
|
313
|
+
S(t.components)
|
|
344
314
|
]
|
|
345
315
|
}
|
|
346
316
|
}), e(
|
|
@@ -349,7 +319,7 @@ function q(r) {
|
|
|
349
319
|
import { storyblokApiInstance } from "virtual:storyblok-init";
|
|
350
320
|
globalThis.storyblokApiInstance = storyblokApiInstance;
|
|
351
321
|
`
|
|
352
|
-
),
|
|
322
|
+
), t.bridge && e(
|
|
353
323
|
"page",
|
|
354
324
|
`
|
|
355
325
|
import { loadStoryblokBridge } from "@storyblok/astro";
|
|
@@ -370,10 +340,11 @@ function q(r) {
|
|
|
370
340
|
};
|
|
371
341
|
}
|
|
372
342
|
export {
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
343
|
+
re as RichTextResolver,
|
|
344
|
+
ee as RichTextSchema,
|
|
345
|
+
de as default,
|
|
346
|
+
ie as loadStoryblokBridge,
|
|
347
|
+
ue as renderRichText,
|
|
348
|
+
le as storyblokEditable,
|
|
349
|
+
ce as useStoryblokApi
|
|
379
350
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@storyblok/astro",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
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",
|
|
@@ -15,9 +15,10 @@
|
|
|
15
15
|
},
|
|
16
16
|
"./StoryblokComponent.astro": "./StoryblokComponent.astro"
|
|
17
17
|
},
|
|
18
|
+
"types": "./dist/index.d.ts",
|
|
18
19
|
"scripts": {
|
|
19
20
|
"dev": "vite build --watch",
|
|
20
|
-
"build": "vite build",
|
|
21
|
+
"build": "vite build && tsc",
|
|
21
22
|
"test": "npm run test:e2e",
|
|
22
23
|
"test:e2e": "start-server-and-test cy:playground http-get://localhost:3000/ cy:run",
|
|
23
24
|
"test:e2e-watch": "start-server-and-test cy:playground http-get://localhost:3000/ cy:open",
|
|
@@ -27,17 +28,19 @@
|
|
|
27
28
|
"prepublishOnly": "npm run build && cp ../README.md ./"
|
|
28
29
|
},
|
|
29
30
|
"dependencies": {
|
|
30
|
-
"@storyblok/js": "^
|
|
31
|
+
"@storyblok/js": "^2.0.4",
|
|
31
32
|
"camelcase": "^7.0.0"
|
|
32
33
|
},
|
|
33
34
|
"devDependencies": {
|
|
34
|
-
"@cypress/vite-dev-server": "^
|
|
35
|
-
"@rollup/plugin-dynamic-import-vars": "^
|
|
36
|
-
"
|
|
37
|
-
"cypress": "^10.9.0",
|
|
35
|
+
"@cypress/vite-dev-server": "^5.0.2",
|
|
36
|
+
"@rollup/plugin-dynamic-import-vars": "^2.0.1",
|
|
37
|
+
"cypress": "^12.1.0",
|
|
38
38
|
"eslint-plugin-cypress": "^2.12.1",
|
|
39
|
-
"start-server-and-test": "^1.
|
|
40
|
-
"vite": "^
|
|
39
|
+
"start-server-and-test": "^1.15.2",
|
|
40
|
+
"vite": "^4.0.1",
|
|
41
|
+
"typescript": "4.9.4",
|
|
42
|
+
"@types/node": "18.11.10",
|
|
43
|
+
"astro": "1.6.15"
|
|
41
44
|
},
|
|
42
45
|
"repository": {
|
|
43
46
|
"type": "git",
|