@storyblok/vue 7.3.2-next.1 → 8.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/dist/FallbackComponent-hOszcW1L.mjs +24 -0
- package/dist/FallbackComponent.vue.d.ts +9 -10
- package/dist/StoryblokComponent.vue.d.ts +10 -11
- package/dist/storyblok-vue.js +3 -3
- package/dist/storyblok-vue.mjs +215 -208
- package/package.json +14 -10
- package/dist/FallbackComponent-ddf2f161.mjs +0 -25
package/README.md
CHANGED
|
@@ -338,6 +338,8 @@ Possible values:
|
|
|
338
338
|
|
|
339
339
|
- `eu` (default): For spaces created in the EU
|
|
340
340
|
- `us`: For spaces created in the US
|
|
341
|
+
- `ap`: For spaces created in Australia
|
|
342
|
+
- `ca`: For spaces created in Canada
|
|
341
343
|
- `cn`: For spaces created in China
|
|
342
344
|
|
|
343
345
|
Full example for a space created in the US:
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { defineComponent as l, openBlock as r, createElementBlock as p, createElementVNode as n, createTextVNode as c, toDisplayString as _ } from "vue";
|
|
2
|
+
const m = { class: "fallback-component" }, d = { class: "component" }, f = /* @__PURE__ */ l({
|
|
3
|
+
__name: "FallbackComponent",
|
|
4
|
+
props: {
|
|
5
|
+
blok: {}
|
|
6
|
+
},
|
|
7
|
+
setup(o) {
|
|
8
|
+
return (e, t) => (r(), p("div", m, [
|
|
9
|
+
n("p", null, [
|
|
10
|
+
c(" Component could not be found for blok "),
|
|
11
|
+
n("span", d, _(e.blok.component), 1),
|
|
12
|
+
c("! Is it configured correctly? ")
|
|
13
|
+
])
|
|
14
|
+
]));
|
|
15
|
+
}
|
|
16
|
+
}), i = (o, e) => {
|
|
17
|
+
const t = o.__vccOpts || o;
|
|
18
|
+
for (const [s, a] of e)
|
|
19
|
+
t[s] = a;
|
|
20
|
+
return t;
|
|
21
|
+
}, u = /* @__PURE__ */ i(f, [["__scopeId", "data-v-93c770c0"]]);
|
|
22
|
+
export {
|
|
23
|
+
u as default
|
|
24
|
+
};
|
|
@@ -2,15 +2,14 @@ import type { SbBlokData } from "./types";
|
|
|
2
2
|
export interface SbComponentProps {
|
|
3
3
|
blok: SbBlokData;
|
|
4
4
|
}
|
|
5
|
-
declare const _default: import("vue").DefineComponent<{
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
type: import(
|
|
5
|
+
declare const _default: import("vue").DefineComponent<__VLS_TypePropsToRuntimeProps<SbComponentProps>, {}, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<import("vue").ExtractPropTypes<__VLS_TypePropsToRuntimeProps<SbComponentProps>>>, {}, {}>;
|
|
6
|
+
export default _default;
|
|
7
|
+
type __VLS_NonUndefinedable<T> = T extends undefined ? never : T;
|
|
8
|
+
type __VLS_TypePropsToRuntimeProps<T> = {
|
|
9
|
+
[K in keyof T]-?: {} extends Pick<T, K> ? {
|
|
10
|
+
type: import('vue').PropType<__VLS_NonUndefinedable<T[K]>>;
|
|
11
|
+
} : {
|
|
12
|
+
type: import('vue').PropType<T[K]>;
|
|
13
13
|
required: true;
|
|
14
14
|
};
|
|
15
|
-
}
|
|
16
|
-
export default _default;
|
|
15
|
+
};
|
|
@@ -2,17 +2,16 @@ import type { SbBlokData } from "./types";
|
|
|
2
2
|
export interface SbComponentProps {
|
|
3
3
|
blok: SbBlokData;
|
|
4
4
|
}
|
|
5
|
-
declare const _default: import("vue").DefineComponent<{
|
|
6
|
-
blok: {
|
|
7
|
-
type: import("vue").PropType<SbBlokData>;
|
|
8
|
-
required: true;
|
|
9
|
-
};
|
|
10
|
-
}, {
|
|
5
|
+
declare const _default: import("vue").DefineComponent<__VLS_TypePropsToRuntimeProps<SbComponentProps>, {
|
|
11
6
|
value: import("vue").Ref<any>;
|
|
12
|
-
}, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<import("vue").ExtractPropTypes<{
|
|
13
|
-
|
|
14
|
-
|
|
7
|
+
}, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<import("vue").ExtractPropTypes<__VLS_TypePropsToRuntimeProps<SbComponentProps>>>, {}, {}>;
|
|
8
|
+
export default _default;
|
|
9
|
+
type __VLS_NonUndefinedable<T> = T extends undefined ? never : T;
|
|
10
|
+
type __VLS_TypePropsToRuntimeProps<T> = {
|
|
11
|
+
[K in keyof T]-?: {} extends Pick<T, K> ? {
|
|
12
|
+
type: import('vue').PropType<__VLS_NonUndefinedable<T[K]>>;
|
|
13
|
+
} : {
|
|
14
|
+
type: import('vue').PropType<T[K]>;
|
|
15
15
|
required: true;
|
|
16
16
|
};
|
|
17
|
-
}
|
|
18
|
-
export default _default;
|
|
17
|
+
};
|
package/dist/storyblok-vue.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(function(d,u){typeof exports=="object"&&typeof module<"u"?u(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],u):(d=typeof globalThis<"u"?globalThis:d||self,u(d.storyblokVue={},d.Vue))})(this,function(d,u){"use strict";let
|
|
1
|
+
(function(d,u){typeof exports=="object"&&typeof module<"u"?u(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],u):(d=typeof globalThis<"u"?globalThis:d||self,u(d.storyblokVue={},d.Vue))})(this,function(d,u){"use strict";let C=!1;const $=[],L=o=>new Promise((e,t)=>{if(typeof window>"u"||(window.storyblokRegisterEvent=r=>{if(window.location===window.parent.location){console.warn("You are not in Draft Mode or in the Visual Editor.");return}C?r():$.push(r)},document.getElementById("storyblok-javascript-bridge")))return;const s=document.createElement("script");s.async=!0,s.src=o,s.id="storyblok-javascript-bridge",s.onerror=r=>t(r),s.onload=r=>{$.forEach(n=>n()),C=!0,e(r)},document.getElementsByTagName("head")[0].appendChild(s)});var M=Object.defineProperty,D=(o,e,t)=>e in o?M(o,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):o[e]=t,h=(o,e,t)=>(D(o,typeof e!="symbol"?e+"":e,t),t);function E(o){return!(o!==o||o===1/0||o===-1/0)}function F(o,e,t){if(!E(e))throw new TypeError("Expected `limit` to be a finite number");if(!E(t))throw new TypeError("Expected `interval` to be a finite number");const s=[];let r=[],n=0;const i=function(){n++;const a=setTimeout(function(){n--,s.length>0&&i(),r=r.filter(function(p){return p!==a})},t);r.indexOf(a)<0&&r.push(a);const c=s.shift();c.resolve(o.apply(c.self,c.args))},l=function(...a){const c=this;return new Promise(function(p,m){s.push({resolve:p,reject:m,args:a,self:c}),n<e&&i()})};return l.abort=function(){r.forEach(clearTimeout),r=[],s.forEach(function(a){a.reject(function(){Error.call(this,"Throttled function aborted"),this.name="AbortError"})}),s.length=0},l}class v{constructor(){h(this,"isCDNUrl",(e="")=>e.indexOf("/cdn/")>-1),h(this,"getOptionsPage",(e,t=25,s=1)=>({...e,per_page:t,page:s})),h(this,"delay",e=>new Promise(t=>setTimeout(t,e))),h(this,"arrayFrom",(e=0,t)=>[...Array(e)].map(t)),h(this,"range",(e=0,t=e)=>{const s=Math.abs(t-e)||0,r=e<t?1:-1;return this.arrayFrom(s,(n,i)=>i*r+e)}),h(this,"asyncMap",async(e,t)=>Promise.all(e.map(t))),h(this,"flatMap",(e=[],t)=>e.map(t).reduce((s,r)=>[...s,...r],[])),h(this,"escapeHTML",function(e){const t={"&":"&","<":"<",">":">",'"':""","'":"'"},s=/[&<>"']/g,r=RegExp(s.source);return e&&r.test(e)?e.replace(s,n=>t[n]):e})}stringify(e,t,s){const r=[];for(const n in e){if(!Object.prototype.hasOwnProperty.call(e,n))continue;const i=e[n],l=s?"":encodeURIComponent(n);let a;typeof i=="object"?a=this.stringify(i,t?t+encodeURIComponent("["+l+"]"):l,Array.isArray(i)):a=(t?t+encodeURIComponent("["+l+"]"):l)+"="+encodeURIComponent(i),r.push(a)}return r.join("&")}getRegionURL(e){const t="api.storyblok.com",s="api-us.storyblok.com",r="app.storyblokchina.cn",n="api-ap.storyblok.com",i="api-ca.storyblok.com";switch(e){case"us":return s;case"cn":return r;case"ap":return n;case"ca":return i;default:return t}}}const V=function(o,e){const t={};for(const s in o){const r=o[s];e.indexOf(s)>-1&&r!==null&&(t[s]=r)}return t},B=o=>o==="email",H=()=>({singleTag:"hr"}),z=()=>({tag:"blockquote"}),q=()=>({tag:"ul"}),G=o=>({tag:["pre",{tag:"code",attrs:o.attrs}]}),J=()=>({singleTag:"br"}),K=o=>({tag:`h${o.attrs.level}`}),Y=o=>({singleTag:[{tag:"img",attrs:V(o.attrs,["src","alt","title"])}]}),W=()=>({tag:"li"}),X=()=>({tag:"ol"}),Z=()=>({tag:"p"}),Q=o=>({tag:[{tag:"span",attrs:{"data-type":"emoji","data-name":o.attrs.name,emoji:o.attrs.emoji}}]}),ee=()=>({tag:"b"}),te=()=>({tag:"s"}),se=()=>({tag:"u"}),re=()=>({tag:"strong"}),oe=()=>({tag:"code"}),ne=()=>({tag:"i"}),ie=o=>{if(!o.attrs)return{tag:""};const e=new v().escapeHTML,t={...o.attrs},{linktype:s="url"}=o.attrs;if(delete t.linktype,t.href&&(t.href=e(o.attrs.href||"")),B(s)&&(t.href=`mailto:${t.href}`),t.anchor&&(t.href=`${t.href}#${t.anchor}`,delete t.anchor),t.custom){for(const r in t.custom)t[r]=t.custom[r];delete t.custom}return{tag:[{tag:"a",attrs:t}]}},ae=o=>({tag:[{tag:"span",attrs:o.attrs}]}),le=()=>({tag:"sub"}),ce=()=>({tag:"sup"}),he=o=>({tag:[{tag:"span",attrs:o.attrs}]}),ue=o=>{var e;return(e=o.attrs)!=null&&e.color?{tag:[{tag:"span",attrs:{style:`background-color:${o.attrs.color};`}}]}:{tag:""}},pe=o=>{var e;return(e=o.attrs)!=null&&e.color?{tag:[{tag:"span",attrs:{style:`color:${o.attrs.color}`}}]}:{tag:""}},j={nodes:{horizontal_rule:H,blockquote:z,bullet_list:q,code_block:G,hard_break:J,heading:K,image:Y,list_item:W,ordered_list:X,paragraph:Z,emoji:Q},marks:{bold:ee,strike:te,underline:se,strong:re,code:oe,italic:ne,link:ie,styled:ae,subscript:le,superscript:ce,anchor:he,highlight:ue,textStyle:pe}},de=function(o){const e={"&":"&","<":"<",">":">",'"':""","'":"'"},t=/[&<>"']/g,s=RegExp(t.source);return o&&s.test(o)?o.replace(t,r=>e[r]):o};class y{constructor(e){h(this,"marks"),h(this,"nodes"),e||(e=j),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 s="";return e.content.forEach(r=>{s+=this.renderNode(r)}),t.optimizeImages?this.optimizeImages(s,t.optimizeImages):s}return console.warn(`The render method must receive an Object with a "content" field.
|
|
2
2
|
The "content" field must be an array of nodes as the type ISbRichtext.
|
|
3
3
|
ISbRichtext:
|
|
4
4
|
content?: ISbRichtext[]
|
|
@@ -21,5 +21,5 @@
|
|
|
21
21
|
}
|
|
22
22
|
],
|
|
23
23
|
type: 'doc'
|
|
24
|
-
}`),""}optimizeImages(e,t){let s=0,r=0,n="",i="";typeof t!="boolean"&&(typeof t.width=="number"&&t.width>0&&(n+=`width="${t.width}" `,s=t.width),typeof t.height=="number"&&t.height>0&&(n+=`height="${t.height}" `,r=t.height),(t.loading==="lazy"||t.loading==="eager")&&(n+=`loading="${t.loading}" `),typeof t.class=="string"&&t.class.length>0&&(n+=`class="${t.class}" `),t.filters&&(typeof t.filters.blur=="number"&&t.filters.blur>=0&&t.filters.blur<=100&&(i+=`:blur(${t.filters.blur})`),typeof t.filters.brightness=="number"&&t.filters.brightness>=-100&&t.filters.brightness<=100&&(i+=`:brightness(${t.filters.brightness})`),t.filters.fill&&(t.filters.fill.match(/[0-9A-Fa-f]{6}/g)||t.filters.fill==="transparent")&&(i+=`:fill(${t.filters.fill})`),t.filters.format&&["webp","png","jpeg"].includes(t.filters.format)&&(i+=`:format(${t.filters.format})`),typeof t.filters.grayscale=="boolean"&&t.filters.grayscale&&(i+=":grayscale()"),typeof t.filters.quality=="number"&&t.filters.quality>=0&&t.filters.quality<=100&&(i+=`:quality(${t.filters.quality})`),t.filters.rotate&&[90,180,270].includes(t.filters.rotate)&&(i+=`:rotate(${t.filters.rotate})`),i.length>0&&(i="/filters"+i))),n.length>0&&(e=e.replace(/<img/g,`<img ${n.trim()}`));const l=s>0||r>0||i.length>0?`${s}x${r}${i}`:"";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/${l}`),typeof t!="boolean"&&(t.sizes||t.srcset)&&(e=e.replace(/<img.*?src=["|'](.*?)["|']/g,a=>{var c,p;const f=a.match(/a.storyblok.com\/f\/(\d+)\/([^.]+)\.(gif|jpg|jpeg|png|tif|tiff|bmp)/g);if(f&&f.length>0){const m={srcset:(c=t.srcset)==null?void 0:c.map(g=>{if(typeof g=="number")return`//${f}/m/${g}x0${i} ${g}w`;if(typeof g=="object"&&g.length===2){let R=0,M=0;return typeof g[0]=="number"&&(R=g[0]),typeof g[1]=="number"&&(M=g[1]),`//${f}/m/${R}x${M}${i} ${R}w`}}).join(", "),sizes:(p=t.sizes)==null?void 0:p.map(g=>g).join(", ")};let T="";return m.srcset&&(T+=`srcset="${m.srcset}" `),m.sizes&&(T+=`sizes="${m.sizes}" `),a.replace(/<img/g,`<img ${T.trim()}`)}return a})),e}renderNode(e){const t=[];e.marks&&e.marks.forEach(r=>{const n=this.getMatchingMark(r);n&&n.tag!==""&&t.push(this.renderOpeningTag(n.tag))});const s=this.getMatchingNode(e);return s&&s.tag&&t.push(this.renderOpeningTag(s.tag)),e.content?e.content.forEach(r=>{t.push(this.renderNode(r))}):e.text?t.push(de(e.text)):s&&s.singleTag?t.push(this.renderTag(s.singleTag," /")):s&&s.html?t.push(s.html):e.type==="emoji"&&t.push(this.renderEmoji(e)),s&&s.tag&&t.push(this.renderClosingTag(s.tag)),e.marks&&e.marks.slice(0).reverse().forEach(r=>{const n=this.getMatchingMark(r);n&&n.tag!==""&&t.push(this.renderClosingTag(n.tag))}),t.join("")}renderTag(e,t){return e.constructor===String?`<${e}${t}>`:e.map(s=>{if(s.constructor===String)return`<${s}${t}>`;{let r=`<${s.tag}`;if(s.attrs)for(const n in s.attrs){const i=s.attrs[n];i!==null&&(r+=` ${n}="${i}"`)}return`${r}${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," /")}}class fe{constructor(e){h(this,"baseURL"),h(this,"timeout"),h(this,"headers"),h(this,"responseInterceptor"),h(this,"fetch"),h(this,"ejectInterceptor"),h(this,"url"),h(this,"parameters"),this.baseURL=e.baseURL,this.headers=e.headers||new Headers,this.timeout=e!=null&&e.timeout?e.timeout*1e3:0,this.responseInterceptor=e.responseInterceptor,this.fetch=(...t)=>e.fetch?e.fetch(...t):fetch(...t),this.ejectInterceptor=!1,this.url="",this.parameters={}}get(e,t){return this.url=e,this.parameters=t,this._methodHandler("get")}post(e,t){return this.url=e,this.parameters=t,this._methodHandler("post")}put(e,t){return this.url=e,this.parameters=t,this._methodHandler("put")}delete(e,t){return this.url=e,this.parameters=t,this._methodHandler("delete")}async _responseHandler(e){const t=[],s={data:{},headers:{},status:0,statusText:""};e.status!==204&&await e.json().then(r=>{s.data=r});for(const r of e.headers.entries())t[r[0]]=r[1];return s.headers={...t},s.status=e.status,s.statusText=e.statusText,s}async _methodHandler(e){let t=`${this.baseURL}${this.url}`,s=null;if(e==="get"){const a=new v;t=`${this.baseURL}${this.url}?${a.stringify(this.parameters)}`}else s=JSON.stringify(this.parameters);const r=new URL(t),n=new AbortController,{signal:i}=n;let l;this.timeout&&(l=setTimeout(()=>n.abort(),this.timeout));try{const a=await this.fetch(`${r}`,{method:e,headers:this.headers,body:s,signal:i});this.timeout&&clearTimeout(l);const c=await this._responseHandler(a);return this.responseInterceptor&&!this.ejectInterceptor?this._statusHandler(this.responseInterceptor(c)):this._statusHandler(c)}catch(a){return{message:a}}}eject(){this.ejectInterceptor=!0}_statusHandler(e){const t=/20[0-6]/g;return new Promise(s=>{if(t.test(`${e.status}`))return s(e);const r={message:e.statusText,status:e.status,response:Array.isArray(e.data)?e.data[0]:e.data.error||e.data.slug};throw new Error(JSON.stringify(r))})}}const x="SB-Agent",w={defaultAgentName:"SB-JS-CLIENT",defaultAgentVersion:"SB-Agent-Version",packageVersion:"5.14.2"};let _={};const y={};class ge{constructor(e,t){h(this,"client"),h(this,"maxRetries"),h(this,"throttle"),h(this,"accessToken"),h(this,"cache"),h(this,"helpers"),h(this,"resolveCounter"),h(this,"relations"),h(this,"links"),h(this,"richTextResolver"),h(this,"resolveNestedRelations");let s=e.endpoint||t;if(!s){const i=new v().getRegionURL,l=e.https===!1?"http":"https";e.oauthToken?s=`${l}://${i(e.region)}/v1`:s=`${l}://${i(e.region)}/v2`}const r=new Headers;if(r.set("Content-Type","application/json"),r.set("Accept","application/json"),e.headers)for(const i in e.headers)r.set(i,e.headers[i]);r.has(x)||(r.set(x,w.defaultAgentName),r.set(w.defaultAgentVersion,w.packageVersion));let n=5;e.oauthToken&&(r.set("Authorization",e.oauthToken),n=3),e.rateLimit&&(n=e.rateLimit),e.richTextSchema?this.richTextResolver=new b(e.richTextSchema):this.richTextResolver=new b,e.componentResolver&&this.setComponentResolver(e.componentResolver),this.maxRetries=e.maxRetries||5,this.throttle=U(this.throttledRequest,n,1e3),this.accessToken=e.accessToken||"",this.relations={},this.links={},this.cache=e.cache||{clear:"manual"},this.helpers=new v,this.resolveCounter=0,this.resolveNestedRelations=e.resolveNestedRelations||!0,this.client=new fe({baseURL:s,timeout:e.timeout||0,headers:r,responseInterceptor:e.responseInterceptor,fetch:e.fetch})}setComponentResolver(e){this.richTextResolver.addNode("blok",t=>{let s="";return t.attrs.body&&t.attrs.body.forEach(r=>{s+=e(r.component,r)}),{html:s}})}parseParams(e){return e.version||(e.version="published"),e.token||(e.token=this.getToken()),e.cv||(e.cv=y[e.token]),Array.isArray(e.resolve_relations)&&(e.resolve_relations=e.resolve_relations.join(",")),e}factoryParamOptions(e,t){return this.helpers.isCDNUrl(e)?this.parseParams(t):t}makeRequest(e,t,s,r){const n=this.factoryParamOptions(e,this.helpers.getOptionsPage(t,s,r));return this.cacheResponse(e,n)}get(e,t){t||(t={});const s=`/${e}`,r=this.factoryParamOptions(s,t);return this.cacheResponse(s,r)}async getAll(e,t,s){const r=(t==null?void 0:t.per_page)||25,n=`/${e}`,i=n.split("/"),l=s||i[i.length-1],a=1,c=await this.makeRequest(n,t,r,a),p=c.total?Math.ceil(c.total/r):1,f=await this.helpers.asyncMap(this.helpers.range(a,p),m=>this.makeRequest(n,t,r,m+1));return this.helpers.flatMap([c,...f],m=>Object.values(m.data[l]))}post(e,t){const s=`/${e}`;return Promise.resolve(this.throttle("post",s,t))}put(e,t){const s=`/${e}`;return Promise.resolve(this.throttle("put",s,t))}delete(e,t){const s=`/${e}`;return Promise.resolve(this.throttle("delete",s,t))}getStories(e){return this.get("cdn/stories",e)}getStory(e,t){return this.get(`cdn/stories/${e}`,t)}getToken(){return this.accessToken}ejectInterceptor(){this.client.eject()}_cleanCopy(e){return JSON.parse(JSON.stringify(e))}_insertLinks(e,t,s){const r=e[t];r&&r.fieldtype=="multilink"&&r.linktype=="story"&&typeof r.id=="string"&&this.links[s][r.id]?r.story=this._cleanCopy(this.links[s][r.id]):r&&r.linktype==="story"&&typeof r.uuid=="string"&&this.links[s][r.uuid]&&(r.story=this._cleanCopy(this.links[s][r.uuid]))}_insertRelations(e,t,s,r){if(s.indexOf(`${e.component}.${t}`)>-1){if(typeof e[t]=="string")this.relations[r][e[t]]&&(e[t]=this._cleanCopy(this.relations[r][e[t]]));else if(e[t]&&e[t].constructor===Array){const n=[];e[t].forEach(i=>{this.relations[r][i]&&n.push(this._cleanCopy(this.relations[r][i]))}),e[t]=n}}}iterateTree(e,t,s){const r=n=>{if(n!=null){if(n.constructor===Array)for(let i=0;i<n.length;i++)r(n[i]);else if(n.constructor===Object){if(n._stopResolving)return;for(const i in n)(n.component&&n._uid||n.type==="link")&&(this._insertRelations(n,i,t,s),this._insertLinks(n,i,s)),r(n[i])}}};r(e.content)}async resolveLinks(e,t,s){let r=[];if(e.link_uuids){const n=e.link_uuids.length,i=[],l=50;for(let a=0;a<n;a+=l){const c=Math.min(n,a+l);i.push(e.link_uuids.slice(a,c))}for(let a=0;a<i.length;a++)(await this.getStories({per_page:l,language:t.language,version:t.version,by_uuids:i[a].join(",")})).data.stories.forEach(c=>{r.push(c)})}else r=e.links;r.forEach(n=>{this.links[s][n.uuid]={...n,_stopResolving:!0}})}async resolveRelations(e,t,s){let r=[];if(e.rel_uuids){const n=e.rel_uuids.length,i=[],l=50;for(let a=0;a<n;a+=l){const c=Math.min(n,a+l);i.push(e.rel_uuids.slice(a,c))}for(let a=0;a<i.length;a++)(await this.getStories({per_page:l,language:t.language,version:t.version,by_uuids:i[a].join(",")})).data.stories.forEach(c=>{r.push(c)})}else r=e.rels;r&&r.length>0&&r.forEach(n=>{this.relations[s][n.uuid]={...n,_stopResolving:!0}})}async resolveStories(e,t,s){var r,n;let i=[];if(this.links[s]={},this.relations[s]={},typeof t.resolve_relations<"u"&&t.resolve_relations.length>0&&(typeof t.resolve_relations=="string"&&(i=t.resolve_relations.split(",")),await this.resolveRelations(e,t,s)),t.resolve_links&&["1","story","url","link"].indexOf(t.resolve_links)>-1&&((r=e.links)!=null&&r.length||(n=e.link_uuids)!=null&&n.length)&&await this.resolveLinks(e,t,s),this.resolveNestedRelations)for(const l in this.relations[s])this.iterateTree(this.relations[s][l],i,s);e.story?this.iterateTree(e.story,i,s):e.stories.forEach(l=>{this.iterateTree(l,i,s)}),delete this.links[s],delete this.relations[s]}async cacheResponse(e,t,s){(typeof s>"u"||!s)&&(s=0);const r=this.helpers.stringify({url:e,params:t}),n=this.cacheProvider();if(this.cache.clear==="auto"&&t.version==="draft"&&await this.flushCache(),t.version==="published"&&e!="/cdn/spaces/me"){const i=await n.get(r);if(i)return Promise.resolve(i)}return new Promise(async(i,l)=>{var a;try{const c=await this.throttle("get",e,t);if(c.status!==200)return l(c);let p={data:c.data,headers:c.headers};if((a=c.headers)!=null&&a["per-page"]&&(p=Object.assign({},p,{perPage:c.headers["per-page"]?parseInt(c.headers["per-page"]):0,total:c.headers["per-page"]?parseInt(c.headers.total):0})),p.data.story||p.data.stories){const f=this.resolveCounter=++this.resolveCounter%1e3;await this.resolveStories(p.data,t,`${f}`)}return t.version==="published"&&e!="/cdn/spaces/me"&&await n.set(r,p),p.data.cv&&t.token&&(t.version=="draft"&&y[t.token]!=p.data.cv&&await this.flushCache(),y[t.token]=p.data.cv),i(p)}catch(c){if(c.response&&c.response.status===429&&(s=s?s+1:0,s<this.maxRetries))return console.log(`Hit rate limit. Retrying in ${s} seconds.`),await this.helpers.delay(1e3*s),this.cacheResponse(e,t,s).then(i).catch(l);l(c.message)}})}throttledRequest(e,t,s){return this.client[e](t,s)}cacheVersions(){return y}cacheVersion(){return y[this.accessToken]}setCacheVersion(e){this.accessToken&&(y[this.accessToken]=e)}cacheProvider(){switch(this.cache.type){case"memory":return{get(e){return Promise.resolve(_[e])},getAll(){return Promise.resolve(_)},set(e,t){return _[e]=t,Promise.resolve(void 0)},flush(){return _={},Promise.resolve(void 0)}};case"custom":if(this.cache.custom)return this.cache.custom;default:return{get(){return Promise.resolve(void 0)},getAll(){return Promise.resolve(void 0)},set(){return Promise.resolve(void 0)},flush(){return Promise.resolve(void 0)}}}}async flushCache(){return await this.cacheProvider().flush(),this}}const me=(o={})=>{const{apiOptions:e}=o;if(!e.accessToken){console.error("You need to provide an access token to interact with Storyblok API. Read https://www.storyblok.com/docs/api/content-delivery#topics/authentication");return}return{storyblokApi:new ge(e)}},ye=o=>{if(typeof o!="object"||typeof o._editable>"u")return{};const e=JSON.parse(o._editable.replace(/^<!--#storyblok#/,"").replace(/-->$/,""));return e?{"data-blok-c":JSON.stringify(e),"data-blok-uid":e.id+"-"+e.uid}:{}};let $,E="https://app.storyblok.com/f/storyblok-v2-latest.js";const I=(o,e,t={})=>{var s;const r=!(typeof window>"u")&&typeof window.storyblokRegisterEvent<"u",n=+new URL((s=window.location)==null?void 0:s.href).searchParams.get("_storyblok")===o;if(!(!r||!n)){if(!o){console.warn("Story ID is not defined. Please provide a valid ID.");return}window.storyblokRegisterEvent(()=>{new window.StoryblokBridge(t).on(["input","published","change"],i=>{i.action==="input"&&i.story.id===o?e(i.story):(i.action==="change"||i.action==="published")&&i.storyId===o&&window.location.reload()})})}},be=(o={})=>{var e,t;const{bridge:s,accessToken:r,use:n=[],apiOptions:i={},richText:l={},bridgeUrl:a}=o;i.accessToken=i.accessToken||r;const c={bridge:s,apiOptions:i};let p={};n.forEach(m=>{p={...p,...m(c)}}),a&&(E=a);const f=!(typeof window>"u")&&((t=(e=window.location)==null?void 0:e.search)==null?void 0:t.includes("_storyblok_tk"));return s!==!1&&f&&L(E),$=new b(l.schema),l.resolver&&A($,l.resolver),p},A=(o,e)=>{o.addNode("blok",t=>{let s="";return t.attrs.body.forEach(r=>{s+=e(r.component,r)}),{html:s}})},ke=o=>!o||!(o!=null&&o.content.some(e=>e.content||e.type==="blok"||e.type==="horizontal_rule")),ve=(o,e,t)=>{let s=t||$;if(!s){console.error("Please initialize the Storyblok SDK before calling the renderRichText function");return}return ke(o)?"":(e&&(s=new b(e.schema),e.resolver&&A(s,e.resolver)),s.render(o))},N=u.defineComponent({__name:"StoryblokComponent",props:{blok:{}},setup(o,{expose:e}){const t=o,s=u.ref();e({value:s});const r=typeof u.resolveDynamicComponent(t.blok.component)!="string",n=u.inject("VueSDKOptions"),i=u.ref(t.blok.component);return r||(n.enableFallbackComponent?(i.value=n.customFallbackComponent??"FallbackComponent",typeof u.resolveDynamicComponent(i.value)=="string"&&console.error(`Is the Fallback component "${i.value}" registered properly?`)):console.error(`Component could not be found for blok "${t.blok.component}"! Is it defined in main.ts as "app.component("${t.blok.component}", ${t.blok.component});"?`)),(l,a)=>(u.openBlock(),u.createBlock(u.resolveDynamicComponent(i.value),u.mergeProps({ref_key:"blokRef",ref:s},{...l.$props,...l.$attrs}),null,16))}}),_e={beforeMount(o,e){if(e.value){const t=ye(e.value);Object.keys(t).length>0&&(o.setAttribute("data-blok-c",t["data-blok-c"]),o.setAttribute("data-blok-uid",t["data-blok-uid"]),o.classList.add("storyblok__outline"))}}},O=o=>{console.error(`You can't use ${o} if you're not loading apiPlugin. Please provide it on StoryblokVue initialization.
|
|
25
|
-
`)};let
|
|
24
|
+
}`),""}optimizeImages(e,t){let s=0,r=0,n="",i="";typeof t!="boolean"&&(typeof t.width=="number"&&t.width>0&&(n+=`width="${t.width}" `,s=t.width),typeof t.height=="number"&&t.height>0&&(n+=`height="${t.height}" `,r=t.height),(t.loading==="lazy"||t.loading==="eager")&&(n+=`loading="${t.loading}" `),typeof t.class=="string"&&t.class.length>0&&(n+=`class="${t.class}" `),t.filters&&(typeof t.filters.blur=="number"&&t.filters.blur>=0&&t.filters.blur<=100&&(i+=`:blur(${t.filters.blur})`),typeof t.filters.brightness=="number"&&t.filters.brightness>=-100&&t.filters.brightness<=100&&(i+=`:brightness(${t.filters.brightness})`),t.filters.fill&&(t.filters.fill.match(/[0-9A-Fa-f]{6}/g)||t.filters.fill==="transparent")&&(i+=`:fill(${t.filters.fill})`),t.filters.format&&["webp","png","jpeg"].includes(t.filters.format)&&(i+=`:format(${t.filters.format})`),typeof t.filters.grayscale=="boolean"&&t.filters.grayscale&&(i+=":grayscale()"),typeof t.filters.quality=="number"&&t.filters.quality>=0&&t.filters.quality<=100&&(i+=`:quality(${t.filters.quality})`),t.filters.rotate&&[90,180,270].includes(t.filters.rotate)&&(i+=`:rotate(${t.filters.rotate})`),i.length>0&&(i="/filters"+i))),n.length>0&&(e=e.replace(/<img/g,`<img ${n.trim()}`));const l=s>0||r>0||i.length>0?`${s}x${r}${i}`:"";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/${l}`),typeof t!="boolean"&&(t.sizes||t.srcset)&&(e=e.replace(/<img.*?src=["|'](.*?)["|']/g,a=>{var c,p;const m=a.match(/a.storyblok.com\/f\/(\d+)\/([^.]+)\.(gif|jpg|jpeg|png|tif|tiff|bmp)/g);if(m&&m.length>0){const f={srcset:(c=t.srcset)==null?void 0:c.map(g=>{if(typeof g=="number")return`//${m}/m/${g}x0${i} ${g}w`;if(typeof g=="object"&&g.length===2){let w=0,P=0;return typeof g[0]=="number"&&(w=g[0]),typeof g[1]=="number"&&(P=g[1]),`//${m}/m/${w}x${P}${i} ${w}w`}}).join(", "),sizes:(p=t.sizes)==null?void 0:p.map(g=>g).join(", ")};let T="";return f.srcset&&(T+=`srcset="${f.srcset}" `),f.sizes&&(T+=`sizes="${f.sizes}" `),a.replace(/<img/g,`<img ${T.trim()}`)}return a})),e}renderNode(e){const t=[];e.marks&&e.marks.forEach(r=>{const n=this.getMatchingMark(r);n&&n.tag!==""&&t.push(this.renderOpeningTag(n.tag))});const s=this.getMatchingNode(e);return s&&s.tag&&t.push(this.renderOpeningTag(s.tag)),e.content?e.content.forEach(r=>{t.push(this.renderNode(r))}):e.text?t.push(de(e.text)):s&&s.singleTag?t.push(this.renderTag(s.singleTag," /")):s&&s.html?t.push(s.html):e.type==="emoji"&&t.push(this.renderEmoji(e)),s&&s.tag&&t.push(this.renderClosingTag(s.tag)),e.marks&&e.marks.slice(0).reverse().forEach(r=>{const n=this.getMatchingMark(r);n&&n.tag!==""&&t.push(this.renderClosingTag(n.tag))}),t.join("")}renderTag(e,t){return e.constructor===String?`<${e}${t}>`:e.map(s=>{if(s.constructor===String)return`<${s}${t}>`;{let r=`<${s.tag}`;if(s.attrs)for(const n in s.attrs){const i=s.attrs[n];i!==null&&(r+=` ${n}="${i}"`)}return`${r}${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," /")}}class me{constructor(e){h(this,"baseURL"),h(this,"timeout"),h(this,"headers"),h(this,"responseInterceptor"),h(this,"fetch"),h(this,"ejectInterceptor"),h(this,"url"),h(this,"parameters"),this.baseURL=e.baseURL,this.headers=e.headers||new Headers,this.timeout=e!=null&&e.timeout?e.timeout*1e3:0,this.responseInterceptor=e.responseInterceptor,this.fetch=(...t)=>e.fetch?e.fetch(...t):fetch(...t),this.ejectInterceptor=!1,this.url="",this.parameters={}}get(e,t){return this.url=e,this.parameters=t,this._methodHandler("get")}post(e,t){return this.url=e,this.parameters=t,this._methodHandler("post")}put(e,t){return this.url=e,this.parameters=t,this._methodHandler("put")}delete(e,t){return this.url=e,this.parameters=t,this._methodHandler("delete")}async _responseHandler(e){const t=[],s={data:{},headers:{},status:0,statusText:""};e.status!==204&&await e.json().then(r=>{s.data=r});for(const r of e.headers.entries())t[r[0]]=r[1];return s.headers={...t},s.status=e.status,s.statusText=e.statusText,s}async _methodHandler(e){let t=`${this.baseURL}${this.url}`,s=null;if(e==="get"){const a=new v;t=`${this.baseURL}${this.url}?${a.stringify(this.parameters)}`}else s=JSON.stringify(this.parameters);const r=new URL(t),n=new AbortController,{signal:i}=n;let l;this.timeout&&(l=setTimeout(()=>n.abort(),this.timeout));try{const a=await fetch(`${r}`,{method:e,headers:this.headers,body:s,signal:i});this.timeout&&clearTimeout(l);const c=await this._responseHandler(a);return this.responseInterceptor&&!this.ejectInterceptor?this._statusHandler(this.responseInterceptor(c)):this._statusHandler(c)}catch(a){return{message:a}}}eject(){this.ejectInterceptor=!0}_statusHandler(e){const t=/20[0-6]/g;return new Promise((s,r)=>{if(t.test(`${e.status}`))return s(e);const n={message:e.statusText,status:e.status,response:Array.isArray(e.data)?e.data[0]:e.data.error||e.data.slug};r(n)})}}var ge={NVM_INC:"/Users/lisilinhart/.nvm/versions/node/v18.16.0/include/node",TERM_PROGRAM:"iTerm.app",NODE:"/Users/lisilinhart/.nvm/versions/node/v18.16.0/bin/node",NVM_CD_FLAGS:"-q",INIT_CWD:"/Users/lisilinhart/Code/storyblok-js-client",SHELL:"/bin/zsh",TERM:"xterm-256color",TMPDIR:"/var/folders/9v/t3hq3s9n2rj6_x9jlsjjq95w0000gn/T/",npm_config_metrics_registry:"https://registry.npmjs.org/",npm_config_global_prefix:"/Users/lisilinhart/.nvm/versions/node/v18.16.0",TERM_PROGRAM_VERSION:"3.4.20",TERM_SESSION_ID:"w0t0p1:12B7CE01-010D-40B5-B6DA-DFE3CF20B8FF",COLOR:"0",npm_config_noproxy:"",ZSH:"/Users/lisilinhart/.oh-my-zsh",npm_config_local_prefix:"/Users/lisilinhart/Code/storyblok-js-client",USER:"lisilinhart",NVM_DIR:"/Users/lisilinhart/.nvm",COMMAND_MODE:"unix2003",npm_config_globalconfig:"/Users/lisilinhart/.nvm/versions/node/v18.16.0/etc/npmrc",SSH_AUTH_SOCK:"/private/tmp/com.apple.launchd.oUounWp9qr/Listeners",__CF_USER_TEXT_ENCODING:"0x1F5:0x0:0x5C",npm_execpath:"/Users/lisilinhart/.nvm/versions/node/v18.16.0/lib/node_modules/npm/bin/npm-cli.js",PAGER:"less",npm_package_integrity:"null",LSCOLORS:"Gxfxcxdxbxegedabagacad",PATH:"/Users/lisilinhart/Code/storyblok-js-client/node_modules/.bin:/Users/lisilinhart/Code/node_modules/.bin:/Users/lisilinhart/node_modules/.bin:/Users/node_modules/.bin:/node_modules/.bin:/Users/lisilinhart/.nvm/versions/node/v18.16.0/lib/node_modules/npm/node_modules/@npmcli/run-script/lib/node-gyp-bin:/Users/lisilinhart/Code/storyblok-js-client/node_modules/.bin:/Users/lisilinhart/Code/node_modules/.bin:/Users/lisilinhart/node_modules/.bin:/Users/node_modules/.bin:/node_modules/.bin:/Users/lisilinhart/.nvm/versions/node/v18.16.0/lib/node_modules/npm/node_modules/@npmcli/run-script/lib/node-gyp-bin:/usr/local/sbin:/Users/lisilinhart/.rbenv/shims:/Users/lisilinhart/.yarn/bin:/Users/lisilinhart/.config/yarn/global/node_modules/.bin:/Users/lisilinhart/.rbenv/shims:/Users/lisilinhart/.nvm/versions/node/v18.16.0/bin:/Users/lisilinhart/bin:/usr/local/bin:/usr/local/bin:/System/Cryptexes/App/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/local/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/appleinternal/bin:/Library/Apple/usr/bin:/Users/lisilinhart/.cargo/bin",RUBY_CONFIGURE_OPTS:"--with-openssl-dir=/usr/local/opt/openssl@1.1",LaunchInstanceID:"9D2A03D3-35CC-4CDD-810D-0D5C25991BBB",_:"/Users/lisilinhart/.nvm/versions/node/v18.16.0/bin/node",npm_package_json:"/Users/lisilinhart/Code/storyblok-js-client/package.json",__CFBundleIdentifier:"com.googlecode.iterm2",npm_config_init_module:"/Users/lisilinhart/.npm-init.js",npm_config_userconfig:"/Users/lisilinhart/.npmrc",PWD:"/Users/lisilinhart/Code/storyblok-js-client",npm_command:"run-script",P9K_SSH:"0",EDITOR:"vi",npm_lifecycle_event:"build",LANG:"de_AT.UTF-8",P9K_TTY:"old",npm_package_name:"storyblok-js-client",ITERM_PROFILE:"Default",XPC_FLAGS:"0x0",RBENV_SHELL:"zsh",npm_config_node_gyp:"/Users/lisilinhart/.nvm/versions/node/v18.16.0/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js",XPC_SERVICE_NAME:"0",npm_package_version:"6.4.1",COLORFGBG:"7;0",HOME:"/Users/lisilinhart",SHLVL:"3",npm_package_resolved:"/Users/lisilinhart/Code/storyblok-js-client",LC_TERMINAL_VERSION:"3.4.20",ITERM_SESSION_ID:"w0t0p1:12B7CE01-010D-40B5-B6DA-DFE3CF20B8FF",LOGNAME:"lisilinhart",LESS:"-R",npm_config_cache:"/Users/lisilinhart/.npm",npm_lifecycle_script:"node vite.build.mjs && tsc",NVM_BIN:"/Users/lisilinhart/.nvm/versions/node/v18.16.0/bin",npm_config_user_agent:"npm/9.5.1 node/v18.16.0 darwin x64 workspaces/false",LC_TERMINAL:"iTerm2",SECURITYSESSIONID:"186a1",COLORTERM:"truecolor",npm_config_prefix:"/Users/lisilinhart/.nvm/versions/node/v18.16.0",npm_node_execpath:"/Users/lisilinhart/.nvm/versions/node/v18.16.0/bin/node",NODE_ENV:"production"};const x="SB-Agent",R={defaultAgentName:"SB-JS-CLIENT",defaultAgentVersion:"SB-Agent-Version",packageVersion:ge.npm_package_version};let k={};const b={};class fe{constructor(e,t){h(this,"client"),h(this,"maxRetries"),h(this,"throttle"),h(this,"accessToken"),h(this,"cache"),h(this,"helpers"),h(this,"resolveCounter"),h(this,"relations"),h(this,"links"),h(this,"richTextResolver"),h(this,"resolveNestedRelations"),h(this,"stringifiedStoriesCache");let s=e.endpoint||t;if(!s){const i=new v().getRegionURL,l=e.https===!1?"http":"https";e.oauthToken?s=`${l}://${i(e.region)}/v1`:s=`${l}://${i(e.region)}/v2`}const r=new Headers;if(r.set("Content-Type","application/json"),r.set("Accept","application/json"),e.headers)for(const i in e.headers)r.set(i,e.headers[i]);r.has(x)||(r.set(x,R.defaultAgentName),r.set(R.defaultAgentVersion,R.packageVersion));let n=5;e.oauthToken&&(r.set("Authorization",e.oauthToken),n=3),e.rateLimit&&(n=e.rateLimit),e.richTextSchema?this.richTextResolver=new y(e.richTextSchema):this.richTextResolver=new y,e.componentResolver&&this.setComponentResolver(e.componentResolver),this.maxRetries=e.maxRetries||5,this.throttle=F(this.throttledRequest,n,1e3),this.accessToken=e.accessToken||"",this.relations={},this.links={},this.cache=e.cache||{clear:"manual"},this.helpers=new v,this.resolveCounter=0,this.resolveNestedRelations=e.resolveNestedRelations||!0,this.stringifiedStoriesCache={},this.client=new me({baseURL:s,timeout:e.timeout||0,headers:r,responseInterceptor:e.responseInterceptor,fetch:e.fetch})}setComponentResolver(e){this.richTextResolver.addNode("blok",t=>{let s="";return t.attrs.body&&t.attrs.body.forEach(r=>{s+=e(r.component,r)}),{html:s}})}parseParams(e){return e.token||(e.token=this.getToken()),e.cv||(e.cv=b[e.token]),Array.isArray(e.resolve_relations)&&(e.resolve_relations=e.resolve_relations.join(",")),e}factoryParamOptions(e,t){return this.helpers.isCDNUrl(e)?this.parseParams(t):t}makeRequest(e,t,s,r){const n=this.factoryParamOptions(e,this.helpers.getOptionsPage(t,s,r));return this.cacheResponse(e,n)}get(e,t){t||(t={});const s=`/${e}`,r=this.factoryParamOptions(s,t);return this.cacheResponse(s,r)}async getAll(e,t,s){const r=(t==null?void 0:t.per_page)||25,n=`/${e}`,i=n.split("/"),l=s||i[i.length-1],a=1,c=await this.makeRequest(n,t,r,a),p=c.total?Math.ceil(c.total/r):1,m=await this.helpers.asyncMap(this.helpers.range(a,p),f=>this.makeRequest(n,t,r,f+1));return this.helpers.flatMap([c,...m],f=>Object.values(f.data[l]))}post(e,t){const s=`/${e}`;return Promise.resolve(this.throttle("post",s,t))}put(e,t){const s=`/${e}`;return Promise.resolve(this.throttle("put",s,t))}delete(e,t){const s=`/${e}`;return Promise.resolve(this.throttle("delete",s,t))}getStories(e){return this.get("cdn/stories",e)}getStory(e,t){return this.get(`cdn/stories/${e}`,t)}getToken(){return this.accessToken}ejectInterceptor(){this.client.eject()}_cleanCopy(e){return JSON.parse(JSON.stringify(e))}_insertLinks(e,t,s){const r=e[t];r&&r.fieldtype=="multilink"&&r.linktype=="story"&&typeof r.id=="string"&&this.links[s][r.id]?r.story=this._cleanCopy(this.links[s][r.id]):r&&r.linktype==="story"&&typeof r.uuid=="string"&&this.links[s][r.uuid]&&(r.story=this._cleanCopy(this.links[s][r.uuid]))}getStoryReference(e,t){return this.relations[e][t]?(this.stringifiedStoriesCache[t]||(this.stringifiedStoriesCache[t]=JSON.stringify(this.relations[e][t])),JSON.parse(this.stringifiedStoriesCache[t])):t}_insertRelations(e,t,s,r){s.indexOf(`${e.component}.${t}`)>-1&&(typeof e[t]=="string"?e[t]=this.getStoryReference(r,e[t]):Array.isArray(e[t])&&(e[t]=e[t].map(n=>this.getStoryReference(r,n)).filter(Boolean)))}iterateTree(e,t,s){const r=n=>{if(n!=null){if(n.constructor===Array)for(let i=0;i<n.length;i++)r(n[i]);else if(n.constructor===Object){if(n._stopResolving)return;for(const i in n)(n.component&&n._uid||n.type==="link")&&(this._insertRelations(n,i,t,s),this._insertLinks(n,i,s)),r(n[i])}}};r(e.content)}async resolveLinks(e,t,s){let r=[];if(e.link_uuids){const n=e.link_uuids.length,i=[],l=50;for(let a=0;a<n;a+=l){const c=Math.min(n,a+l);i.push(e.link_uuids.slice(a,c))}for(let a=0;a<i.length;a++)(await this.getStories({per_page:l,language:t.language,version:t.version,by_uuids:i[a].join(",")})).data.stories.forEach(c=>{r.push(c)})}else r=e.links;r.forEach(n=>{this.links[s][n.uuid]={...n,_stopResolving:!0}})}async resolveRelations(e,t,s){let r=[];if(e.rel_uuids){const n=e.rel_uuids.length,i=[],l=50;for(let a=0;a<n;a+=l){const c=Math.min(n,a+l);i.push(e.rel_uuids.slice(a,c))}for(let a=0;a<i.length;a++)(await this.getStories({per_page:l,language:t.language,version:t.version,by_uuids:i[a].join(","),excluding_fields:t.excluding_fields})).data.stories.forEach(c=>{r.push(c)})}else r=e.rels;r&&r.length>0&&r.forEach(n=>{this.relations[s][n.uuid]={...n,_stopResolving:!0}})}async resolveStories(e,t,s){var r,n;let i=[];if(this.links[s]={},this.relations[s]={},typeof t.resolve_relations<"u"&&t.resolve_relations.length>0&&(typeof t.resolve_relations=="string"&&(i=t.resolve_relations.split(",")),await this.resolveRelations(e,t,s)),t.resolve_links&&["1","story","url","link"].indexOf(t.resolve_links)>-1&&((r=e.links)!=null&&r.length||(n=e.link_uuids)!=null&&n.length)&&await this.resolveLinks(e,t,s),this.resolveNestedRelations)for(const l in this.relations[s])this.iterateTree(this.relations[s][l],i,s);e.story?this.iterateTree(e.story,i,s):e.stories.forEach(l=>{this.iterateTree(l,i,s)}),this.stringifiedStoriesCache={},delete this.links[s],delete this.relations[s]}async cacheResponse(e,t,s){(typeof s>"u"||!s)&&(s=0);const r=this.helpers.stringify({url:e,params:t}),n=this.cacheProvider();if(this.cache.clear==="auto"&&t.version==="draft"&&await this.flushCache(),t.version==="published"&&e!="/cdn/spaces/me"){const i=await n.get(r);if(i)return Promise.resolve(i)}return new Promise(async(i,l)=>{var a;try{const c=await this.throttle("get",e,t);if(c.status!==200)return l(c);let p={data:c.data,headers:c.headers};if((a=c.headers)!=null&&a["per-page"]&&(p=Object.assign({},p,{perPage:c.headers["per-page"]?parseInt(c.headers["per-page"]):0,total:c.headers["per-page"]?parseInt(c.headers.total):0})),p.data.story||p.data.stories){const m=this.resolveCounter=++this.resolveCounter%1e3;await this.resolveStories(p.data,t,`${m}`)}return t.version==="published"&&e!="/cdn/spaces/me"&&await n.set(r,p),p.data.cv&&t.token&&(t.version==="draft"&&b[t.token]!=p.data.cv&&await this.flushCache(),b[t.token]=t.cv?t.cv:p.data.cv),i(p)}catch(c){if(c.response&&c.response.status===429&&(s=s?s+1:0,s<this.maxRetries))return console.log(`Hit rate limit. Retrying in ${s} seconds.`),await this.helpers.delay(1e3*s),this.cacheResponse(e,t,s).then(i).catch(l);l(c)}})}throttledRequest(e,t,s){return this.client[e](t,s)}cacheVersions(){return b}cacheVersion(){return b[this.accessToken]}cacheProvider(){switch(this.cache.type){case"memory":return{get(e){return Promise.resolve(k[e])},getAll(){return Promise.resolve(k)},set(e,t){return k[e]=t,Promise.resolve(void 0)},flush(){return k={},Promise.resolve(void 0)}};case"custom":if(this.cache.custom)return this.cache.custom;default:return{get(){return Promise.resolve()},getAll(){return Promise.resolve(void 0)},set(){return Promise.resolve(void 0)},flush(){return Promise.resolve(void 0)}}}}async flushCache(){return await this.cacheProvider().flush(),this}}const ye=(o={})=>{const{apiOptions:e}=o;if(!e.accessToken){console.error("You need to provide an access token to interact with Storyblok API. Read https://www.storyblok.com/docs/api/content-delivery#topics/authentication");return}return{storyblokApi:new fe(e)}},be=o=>{if(typeof o!="object"||typeof o._editable>"u")return{};const e=JSON.parse(o._editable.replace(/^<!--#storyblok#/,"").replace(/-->$/,""));return e?{"data-blok-c":JSON.stringify(e),"data-blok-uid":e.id+"-"+e.uid}:{}};let S,I="https://app.storyblok.com/f/storyblok-v2-latest.js";const U=(o,e,t={})=>{var s;const r=!(typeof window>"u")&&typeof window.storyblokRegisterEvent<"u",n=+new URL((s=window.location)==null?void 0:s.href).searchParams.get("_storyblok")===o;if(!(!r||!n)){if(!o){console.warn("Story ID is not defined. Please provide a valid ID.");return}window.storyblokRegisterEvent(()=>{new window.StoryblokBridge(t).on(["input","published","change"],i=>{i.action==="input"&&i.story.id===o?e(i.story):(i.action==="change"||i.action==="published")&&i.storyId===o&&window.location.reload()})})}},_e=(o={})=>{var e,t;const{bridge:s,accessToken:r,use:n=[],apiOptions:i={},richText:l={},bridgeUrl:a}=o;i.accessToken=i.accessToken||r;const c={bridge:s,apiOptions:i};let p={};n.forEach(f=>{p={...p,...f(c)}}),a&&(I=a);const m=!(typeof window>"u")&&((t=(e=window.location)==null?void 0:e.search)==null?void 0:t.includes("_storyblok_tk"));return s!==!1&&m&&L(I),S=new y(l.schema),l.resolver&&O(S,l.resolver),p},O=(o,e)=>{o.addNode("blok",t=>{let s="";return t.attrs.body.forEach(r=>{s+=e(r.component,r)}),{html:s}})},ve=o=>!o||!(o!=null&&o.content.some(e=>e.content||e.type==="blok"||e.type==="horizontal_rule")),ke=(o,e,t)=>{let s=t||S;if(!s){console.error("Please initialize the Storyblok SDK before calling the renderRichText function");return}return ve(o)?"":(e&&(s=new y(e.schema),e.resolver&&O(s,e.resolver)),s.render(o))},A=u.defineComponent({__name:"StoryblokComponent",props:{blok:{}},setup(o,{expose:e}){const t=o,s=u.ref();e({value:s});const r=typeof u.resolveDynamicComponent(t.blok.component)!="string",n=u.inject("VueSDKOptions"),i=u.ref(t.blok.component);return r||(n.enableFallbackComponent?(i.value=n.customFallbackComponent??"FallbackComponent",typeof u.resolveDynamicComponent(i.value)=="string"&&console.error(`Is the Fallback component "${i.value}" registered properly?`)):console.error(`Component could not be found for blok "${t.blok.component}"! Is it defined in main.ts as "app.component("${t.blok.component}", ${t.blok.component});"?`)),(l,a)=>(u.openBlock(),u.createBlock(u.resolveDynamicComponent(i.value),u.mergeProps({ref_key:"blokRef",ref:s},{...l.$props,...l.$attrs}),null,16))}}),Re={beforeMount(o,e){if(e.value){const t=be(e.value);Object.keys(t).length>0&&(o.setAttribute("data-blok-c",t["data-blok-c"]),o.setAttribute("data-blok-uid",t["data-blok-uid"]),o.classList.add("storyblok__outline"))}}},N=o=>{console.error(`You can't use ${o} if you're not loading apiPlugin. Please provide it on StoryblokVue initialization.
|
|
25
|
+
`)};let _=null;const Se=()=>(_||N("useStoryblokApi"),_),Te=async(o,e={},t={})=>{const s=u.ref(null);if(t.resolveRelations=t.resolveRelations??e.resolve_relations,t.resolveLinks=t.resolveLinks??e.resolve_links,u.onMounted(()=>{s.value&&s.value.id&&U(s.value.id,r=>s.value=r,t)}),_){const{data:r}=await _.get(`cdn/stories/${o}`,e);s.value=r.story}else N("useStoryblok");return s},we={install(o,e={}){o.directive("editable",Re),o.component("StoryblokComponent",A),e.enableFallbackComponent&&!e.customFallbackComponent&&o.component("FallbackComponent",u.defineAsyncComponent(()=>Promise.resolve().then(()=>Ee)));const{storyblokApi:t}=_e(e);_=t,o.provide("VueSDKOptions",e)}},Ce={class:"fallback-component"},$e={class:"component"},Ee=Object.freeze(Object.defineProperty({__proto__:null,default:((o,e)=>{const t=o.__vccOpts||o;for(const[s,r]of e)t[s]=r;return t})(u.defineComponent({__name:"FallbackComponent",props:{blok:{}},setup(o){return(e,t)=>(u.openBlock(),u.createElementBlock("div",Ce,[u.createElementVNode("p",null,[u.createTextVNode(" Component could not be found for blok "),u.createElementVNode("span",$e,u.toDisplayString(e.blok.component),1),u.createTextVNode("! Is it configured correctly? ")])]))}}),[["__scopeId","data-v-93c770c0"]])},Symbol.toStringTag,{value:"Module"}));d.RichTextResolver=y,d.RichTextSchema=j,d.StoryblokComponent=A,d.StoryblokVue=we,d.apiPlugin=ye,d.renderRichText=ke,d.useStoryblok=Te,d.useStoryblokApi=Se,d.useStoryblokBridge=U,Object.defineProperty(d,Symbol.toStringTag,{value:"Module"})});
|
package/dist/storyblok-vue.mjs
CHANGED
|
@@ -1,34 +1,34 @@
|
|
|
1
|
-
import { defineComponent as
|
|
2
|
-
let
|
|
3
|
-
const
|
|
1
|
+
import { defineComponent as O, ref as S, resolveDynamicComponent as R, inject as N, openBlock as P, createBlock as L, mergeProps as M, onMounted as D, defineAsyncComponent as F } from "vue";
|
|
2
|
+
let $ = !1;
|
|
3
|
+
const E = [], B = (o) => new Promise((e, t) => {
|
|
4
4
|
if (typeof window > "u" || (window.storyblokRegisterEvent = (r) => {
|
|
5
5
|
if (window.location === window.parent.location) {
|
|
6
6
|
console.warn("You are not in Draft Mode or in the Visual Editor.");
|
|
7
7
|
return;
|
|
8
8
|
}
|
|
9
|
-
|
|
9
|
+
$ ? r() : E.push(r);
|
|
10
10
|
}, document.getElementById("storyblok-javascript-bridge")))
|
|
11
11
|
return;
|
|
12
12
|
const s = document.createElement("script");
|
|
13
13
|
s.async = !0, s.src = o, s.id = "storyblok-javascript-bridge", s.onerror = (r) => t(r), s.onload = (r) => {
|
|
14
|
-
|
|
14
|
+
E.forEach((i) => i()), $ = !0, e(r);
|
|
15
15
|
}, document.getElementsByTagName("head")[0].appendChild(s);
|
|
16
16
|
});
|
|
17
|
-
var
|
|
18
|
-
function
|
|
17
|
+
var H = Object.defineProperty, V = (o, e, t) => e in o ? H(o, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : o[e] = t, h = (o, e, t) => (V(o, typeof e != "symbol" ? e + "" : e, t), t);
|
|
18
|
+
function x(o) {
|
|
19
19
|
return !(o !== o || o === 1 / 0 || o === -1 / 0);
|
|
20
20
|
}
|
|
21
|
-
function
|
|
22
|
-
if (!
|
|
21
|
+
function z(o, e, t) {
|
|
22
|
+
if (!x(e))
|
|
23
23
|
throw new TypeError("Expected `limit` to be a finite number");
|
|
24
|
-
if (!
|
|
24
|
+
if (!x(t))
|
|
25
25
|
throw new TypeError("Expected `interval` to be a finite number");
|
|
26
26
|
const s = [];
|
|
27
|
-
let r = [],
|
|
28
|
-
const
|
|
29
|
-
|
|
27
|
+
let r = [], i = 0;
|
|
28
|
+
const n = function() {
|
|
29
|
+
i++;
|
|
30
30
|
const a = setTimeout(function() {
|
|
31
|
-
|
|
31
|
+
i--, s.length > 0 && n(), r = r.filter(function(u) {
|
|
32
32
|
return u !== a;
|
|
33
33
|
});
|
|
34
34
|
}, t);
|
|
@@ -43,7 +43,7 @@ function F(o, e, t) {
|
|
|
43
43
|
reject: p,
|
|
44
44
|
args: a,
|
|
45
45
|
self: c
|
|
46
|
-
}),
|
|
46
|
+
}), i < e && n();
|
|
47
47
|
});
|
|
48
48
|
};
|
|
49
49
|
return l.abort = function() {
|
|
@@ -62,7 +62,7 @@ class b {
|
|
|
62
62
|
page: s
|
|
63
63
|
})), h(this, "delay", (e) => new Promise((t) => setTimeout(t, e))), h(this, "arrayFrom", (e = 0, t) => [...Array(e)].map(t)), h(this, "range", (e = 0, t = e) => {
|
|
64
64
|
const s = Math.abs(t - e) || 0, r = e < t ? 1 : -1;
|
|
65
|
-
return this.arrayFrom(s, (
|
|
65
|
+
return this.arrayFrom(s, (i, n) => n * r + e);
|
|
66
66
|
}), h(this, "asyncMap", async (e, t) => Promise.all(e.map(t))), h(this, "flatMap", (e = [], t) => e.map(t).reduce((s, r) => [...s, ...r], [])), h(this, "escapeHTML", function(e) {
|
|
67
67
|
const t = {
|
|
68
68
|
"&": "&",
|
|
@@ -71,7 +71,7 @@ class b {
|
|
|
71
71
|
'"': """,
|
|
72
72
|
"'": "'"
|
|
73
73
|
}, s = /[&<>"']/g, r = RegExp(s.source);
|
|
74
|
-
return e && r.test(e) ? e.replace(s, (
|
|
74
|
+
return e && r.test(e) ? e.replace(s, (i) => t[i]) : e;
|
|
75
75
|
});
|
|
76
76
|
}
|
|
77
77
|
/**
|
|
@@ -83,50 +83,54 @@ class b {
|
|
|
83
83
|
*/
|
|
84
84
|
stringify(e, t, s) {
|
|
85
85
|
const r = [];
|
|
86
|
-
for (const
|
|
87
|
-
if (!Object.prototype.hasOwnProperty.call(e,
|
|
86
|
+
for (const i in e) {
|
|
87
|
+
if (!Object.prototype.hasOwnProperty.call(e, i))
|
|
88
88
|
continue;
|
|
89
|
-
const
|
|
89
|
+
const n = e[i], l = s ? "" : encodeURIComponent(i);
|
|
90
90
|
let a;
|
|
91
|
-
typeof
|
|
92
|
-
|
|
91
|
+
typeof n == "object" ? a = this.stringify(
|
|
92
|
+
n,
|
|
93
93
|
t ? t + encodeURIComponent("[" + l + "]") : l,
|
|
94
|
-
Array.isArray(
|
|
95
|
-
) : a = (t ? t + encodeURIComponent("[" + l + "]") : l) + "=" + encodeURIComponent(
|
|
94
|
+
Array.isArray(n)
|
|
95
|
+
) : a = (t ? t + encodeURIComponent("[" + l + "]") : l) + "=" + encodeURIComponent(n), r.push(a);
|
|
96
96
|
}
|
|
97
97
|
return r.join("&");
|
|
98
98
|
}
|
|
99
99
|
/**
|
|
100
100
|
* @method getRegionURL
|
|
101
|
-
* @param {String} regionCode region code, could be eu, us or
|
|
101
|
+
* @param {String} regionCode region code, could be eu, us, cn, ap or ca
|
|
102
102
|
* @return {String} The base URL of the region
|
|
103
103
|
*/
|
|
104
104
|
getRegionURL(e) {
|
|
105
|
-
const t = "api.storyblok.com", s = "api-us.storyblok.com", r = "app.storyblokchina.cn";
|
|
105
|
+
const t = "api.storyblok.com", s = "api-us.storyblok.com", r = "app.storyblokchina.cn", i = "api-ap.storyblok.com", n = "api-ca.storyblok.com";
|
|
106
106
|
switch (e) {
|
|
107
107
|
case "us":
|
|
108
108
|
return s;
|
|
109
109
|
case "cn":
|
|
110
110
|
return r;
|
|
111
|
+
case "ap":
|
|
112
|
+
return i;
|
|
113
|
+
case "ca":
|
|
114
|
+
return n;
|
|
111
115
|
default:
|
|
112
116
|
return t;
|
|
113
117
|
}
|
|
114
118
|
}
|
|
115
119
|
}
|
|
116
|
-
const
|
|
120
|
+
const q = function(o, e) {
|
|
117
121
|
const t = {};
|
|
118
122
|
for (const s in o) {
|
|
119
123
|
const r = o[s];
|
|
120
124
|
e.indexOf(s) > -1 && r !== null && (t[s] = r);
|
|
121
125
|
}
|
|
122
126
|
return t;
|
|
123
|
-
},
|
|
127
|
+
}, G = (o) => o === "email", J = () => ({
|
|
124
128
|
singleTag: "hr"
|
|
125
|
-
}),
|
|
129
|
+
}), K = () => ({
|
|
126
130
|
tag: "blockquote"
|
|
127
|
-
}),
|
|
131
|
+
}), Y = () => ({
|
|
128
132
|
tag: "ul"
|
|
129
|
-
}),
|
|
133
|
+
}), W = (o) => ({
|
|
130
134
|
tag: [
|
|
131
135
|
"pre",
|
|
132
136
|
{
|
|
@@ -134,15 +138,15 @@ const B = function(o, e) {
|
|
|
134
138
|
attrs: o.attrs
|
|
135
139
|
}
|
|
136
140
|
]
|
|
137
|
-
}),
|
|
141
|
+
}), X = () => ({
|
|
138
142
|
singleTag: "br"
|
|
139
|
-
}), X = (o) => ({
|
|
140
|
-
tag: `h${o.attrs.level}`
|
|
141
143
|
}), Z = (o) => ({
|
|
144
|
+
tag: `h${o.attrs.level}`
|
|
145
|
+
}), Q = (o) => ({
|
|
142
146
|
singleTag: [
|
|
143
147
|
{
|
|
144
148
|
tag: "img",
|
|
145
|
-
attrs:
|
|
149
|
+
attrs: q(o.attrs, ["src", "alt", "title"])
|
|
146
150
|
}
|
|
147
151
|
]
|
|
148
152
|
}), ee = () => ({
|
|
@@ -164,9 +168,9 @@ const B = function(o, e) {
|
|
|
164
168
|
]
|
|
165
169
|
}), oe = () => ({
|
|
166
170
|
tag: "b"
|
|
167
|
-
}), ne = () => ({
|
|
168
|
-
tag: "strike"
|
|
169
171
|
}), ie = () => ({
|
|
172
|
+
tag: "s"
|
|
173
|
+
}), ne = () => ({
|
|
170
174
|
tag: "u"
|
|
171
175
|
}), ae = () => ({
|
|
172
176
|
tag: "strong"
|
|
@@ -175,8 +179,12 @@ const B = function(o, e) {
|
|
|
175
179
|
}), ce = () => ({
|
|
176
180
|
tag: "i"
|
|
177
181
|
}), he = (o) => {
|
|
182
|
+
if (!o.attrs)
|
|
183
|
+
return {
|
|
184
|
+
tag: ""
|
|
185
|
+
};
|
|
178
186
|
const e = new b().escapeHTML, t = { ...o.attrs }, { linktype: s = "url" } = o.attrs;
|
|
179
|
-
if (t.href && (t.href = e(o.attrs.href || "")),
|
|
187
|
+
if (delete t.linktype, t.href && (t.href = e(o.attrs.href || "")), G(s) && (t.href = `mailto:${t.href}`), t.anchor && (t.href = `${t.href}#${t.anchor}`, delete t.anchor), t.custom) {
|
|
180
188
|
for (const r in t.custom)
|
|
181
189
|
t[r] = t.custom[r];
|
|
182
190
|
delete t.custom;
|
|
@@ -200,14 +208,14 @@ const B = function(o, e) {
|
|
|
200
208
|
tag: "sub"
|
|
201
209
|
}), de = () => ({
|
|
202
210
|
tag: "sup"
|
|
203
|
-
}),
|
|
211
|
+
}), me = (o) => ({
|
|
204
212
|
tag: [
|
|
205
213
|
{
|
|
206
214
|
tag: "span",
|
|
207
215
|
attrs: o.attrs
|
|
208
216
|
}
|
|
209
217
|
]
|
|
210
|
-
}),
|
|
218
|
+
}), ge = (o) => {
|
|
211
219
|
var e;
|
|
212
220
|
return (e = o.attrs) != null && e.color ? {
|
|
213
221
|
tag: [
|
|
@@ -221,7 +229,7 @@ const B = function(o, e) {
|
|
|
221
229
|
} : {
|
|
222
230
|
tag: ""
|
|
223
231
|
};
|
|
224
|
-
},
|
|
232
|
+
}, fe = (o) => {
|
|
225
233
|
var e;
|
|
226
234
|
return (e = o.attrs) != null && e.color ? {
|
|
227
235
|
tag: [
|
|
@@ -237,13 +245,13 @@ const B = function(o, e) {
|
|
|
237
245
|
};
|
|
238
246
|
}, ye = {
|
|
239
247
|
nodes: {
|
|
240
|
-
horizontal_rule:
|
|
241
|
-
blockquote:
|
|
242
|
-
bullet_list:
|
|
243
|
-
code_block:
|
|
244
|
-
hard_break:
|
|
245
|
-
heading:
|
|
246
|
-
image:
|
|
248
|
+
horizontal_rule: J,
|
|
249
|
+
blockquote: K,
|
|
250
|
+
bullet_list: Y,
|
|
251
|
+
code_block: W,
|
|
252
|
+
hard_break: X,
|
|
253
|
+
heading: Z,
|
|
254
|
+
image: Q,
|
|
247
255
|
list_item: ee,
|
|
248
256
|
ordered_list: te,
|
|
249
257
|
paragraph: se,
|
|
@@ -251,8 +259,8 @@ const B = function(o, e) {
|
|
|
251
259
|
},
|
|
252
260
|
marks: {
|
|
253
261
|
bold: oe,
|
|
254
|
-
strike:
|
|
255
|
-
underline:
|
|
262
|
+
strike: ie,
|
|
263
|
+
underline: ne,
|
|
256
264
|
strong: ae,
|
|
257
265
|
code: le,
|
|
258
266
|
italic: ce,
|
|
@@ -260,9 +268,9 @@ const B = function(o, e) {
|
|
|
260
268
|
styled: ue,
|
|
261
269
|
subscript: pe,
|
|
262
270
|
superscript: de,
|
|
263
|
-
anchor:
|
|
264
|
-
highlight:
|
|
265
|
-
textStyle:
|
|
271
|
+
anchor: me,
|
|
272
|
+
highlight: ge,
|
|
273
|
+
textStyle: fe
|
|
266
274
|
}
|
|
267
275
|
}, be = function(o) {
|
|
268
276
|
const e = {
|
|
@@ -274,7 +282,7 @@ const B = function(o, e) {
|
|
|
274
282
|
}, t = /[&<>"']/g, s = RegExp(t.source);
|
|
275
283
|
return o && s.test(o) ? o.replace(t, (r) => e[r]) : o;
|
|
276
284
|
};
|
|
277
|
-
class
|
|
285
|
+
class v {
|
|
278
286
|
constructor(e) {
|
|
279
287
|
h(this, "marks"), h(this, "nodes"), e || (e = ye), this.marks = e.marks || [], this.nodes = e.nodes || [];
|
|
280
288
|
}
|
|
@@ -319,9 +327,9 @@ class k {
|
|
|
319
327
|
), "";
|
|
320
328
|
}
|
|
321
329
|
optimizeImages(e, t) {
|
|
322
|
-
let s = 0, r = 0,
|
|
323
|
-
typeof t != "boolean" && (typeof t.width == "number" && t.width > 0 && (
|
|
324
|
-
const l = s > 0 || r > 0 ||
|
|
330
|
+
let s = 0, r = 0, i = "", n = "";
|
|
331
|
+
typeof t != "boolean" && (typeof t.width == "number" && t.width > 0 && (i += `width="${t.width}" `, s = t.width), typeof t.height == "number" && t.height > 0 && (i += `height="${t.height}" `, r = t.height), (t.loading === "lazy" || t.loading === "eager") && (i += `loading="${t.loading}" `), typeof t.class == "string" && t.class.length > 0 && (i += `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))), i.length > 0 && (e = e.replace(/<img/g, `<img ${i.trim()}`));
|
|
332
|
+
const l = s > 0 || r > 0 || n.length > 0 ? `${s}x${r}${n}` : "";
|
|
325
333
|
return e = e.replace(
|
|
326
334
|
/a.storyblok.com\/f\/(\d+)\/([^.]+)\.(gif|jpg|jpeg|png|tif|tiff|bmp)/g,
|
|
327
335
|
`a.storyblok.com/f/$1/$2.$3/m/${l}`
|
|
@@ -331,19 +339,19 @@ class k {
|
|
|
331
339
|
/a.storyblok.com\/f\/(\d+)\/([^.]+)\.(gif|jpg|jpeg|png|tif|tiff|bmp)/g
|
|
332
340
|
);
|
|
333
341
|
if (p && p.length > 0) {
|
|
334
|
-
const
|
|
342
|
+
const m = {
|
|
335
343
|
srcset: (c = t.srcset) == null ? void 0 : c.map((d) => {
|
|
336
344
|
if (typeof d == "number")
|
|
337
|
-
return `//${p}/m/${d}x0${
|
|
345
|
+
return `//${p}/m/${d}x0${n} ${d}w`;
|
|
338
346
|
if (typeof d == "object" && d.length === 2) {
|
|
339
|
-
let
|
|
340
|
-
return typeof d[0] == "number" && (
|
|
347
|
+
let k = 0, C = 0;
|
|
348
|
+
return typeof d[0] == "number" && (k = d[0]), typeof d[1] == "number" && (C = d[1]), `//${p}/m/${k}x${C}${n} ${k}w`;
|
|
341
349
|
}
|
|
342
350
|
}).join(", "),
|
|
343
351
|
sizes: (u = t.sizes) == null ? void 0 : u.map((d) => d).join(", ")
|
|
344
352
|
};
|
|
345
|
-
let
|
|
346
|
-
return
|
|
353
|
+
let _ = "";
|
|
354
|
+
return m.srcset && (_ += `srcset="${m.srcset}" `), m.sizes && (_ += `sizes="${m.sizes}" `), a.replace(/<img/g, `<img ${_.trim()}`);
|
|
347
355
|
}
|
|
348
356
|
return a;
|
|
349
357
|
})), e;
|
|
@@ -351,15 +359,15 @@ class k {
|
|
|
351
359
|
renderNode(e) {
|
|
352
360
|
const t = [];
|
|
353
361
|
e.marks && e.marks.forEach((r) => {
|
|
354
|
-
const
|
|
355
|
-
|
|
362
|
+
const i = this.getMatchingMark(r);
|
|
363
|
+
i && i.tag !== "" && t.push(this.renderOpeningTag(i.tag));
|
|
356
364
|
});
|
|
357
365
|
const s = this.getMatchingNode(e);
|
|
358
366
|
return s && s.tag && t.push(this.renderOpeningTag(s.tag)), e.content ? e.content.forEach((r) => {
|
|
359
367
|
t.push(this.renderNode(r));
|
|
360
368
|
}) : e.text ? t.push(be(e.text)) : s && s.singleTag ? t.push(this.renderTag(s.singleTag, " /")) : s && s.html ? t.push(s.html) : e.type === "emoji" && t.push(this.renderEmoji(e)), s && s.tag && t.push(this.renderClosingTag(s.tag)), e.marks && e.marks.slice(0).reverse().forEach((r) => {
|
|
361
|
-
const
|
|
362
|
-
|
|
369
|
+
const i = this.getMatchingMark(r);
|
|
370
|
+
i && i.tag !== "" && t.push(this.renderClosingTag(i.tag));
|
|
363
371
|
}), t.join("");
|
|
364
372
|
}
|
|
365
373
|
renderTag(e, t) {
|
|
@@ -369,9 +377,9 @@ class k {
|
|
|
369
377
|
{
|
|
370
378
|
let r = `<${s.tag}`;
|
|
371
379
|
if (s.attrs)
|
|
372
|
-
for (const
|
|
373
|
-
const
|
|
374
|
-
|
|
380
|
+
for (const i in s.attrs) {
|
|
381
|
+
const n = s.attrs[i];
|
|
382
|
+
n !== null && (r += ` ${i}="${n}"`);
|
|
375
383
|
}
|
|
376
384
|
return `${r}${t}>`;
|
|
377
385
|
}
|
|
@@ -410,7 +418,7 @@ class k {
|
|
|
410
418
|
return this.renderTag(t, " /");
|
|
411
419
|
}
|
|
412
420
|
}
|
|
413
|
-
class
|
|
421
|
+
class ve {
|
|
414
422
|
constructor(e) {
|
|
415
423
|
h(this, "baseURL"), h(this, "timeout"), h(this, "headers"), h(this, "responseInterceptor"), h(this, "fetch"), h(this, "ejectInterceptor"), h(this, "url"), h(this, "parameters"), this.baseURL = e.baseURL, this.headers = e.headers || new Headers(), this.timeout = e != null && e.timeout ? e.timeout * 1e3 : 0, this.responseInterceptor = e.responseInterceptor, this.fetch = (...t) => e.fetch ? e.fetch(...t) : fetch(...t), this.ejectInterceptor = !1, this.url = "", this.parameters = {};
|
|
416
424
|
}
|
|
@@ -455,15 +463,15 @@ class ke {
|
|
|
455
463
|
)}`;
|
|
456
464
|
} else
|
|
457
465
|
s = JSON.stringify(this.parameters);
|
|
458
|
-
const r = new URL(t),
|
|
466
|
+
const r = new URL(t), i = new AbortController(), { signal: n } = i;
|
|
459
467
|
let l;
|
|
460
|
-
this.timeout && (l = setTimeout(() =>
|
|
468
|
+
this.timeout && (l = setTimeout(() => i.abort(), this.timeout));
|
|
461
469
|
try {
|
|
462
|
-
const a = await
|
|
470
|
+
const a = await fetch(`${r}`, {
|
|
463
471
|
method: e,
|
|
464
472
|
headers: this.headers,
|
|
465
473
|
body: s,
|
|
466
|
-
signal:
|
|
474
|
+
signal: n
|
|
467
475
|
});
|
|
468
476
|
this.timeout && clearTimeout(l);
|
|
469
477
|
const c = await this._responseHandler(a);
|
|
@@ -479,48 +487,49 @@ class ke {
|
|
|
479
487
|
}
|
|
480
488
|
_statusHandler(e) {
|
|
481
489
|
const t = /20[0-6]/g;
|
|
482
|
-
return new Promise((s) => {
|
|
490
|
+
return new Promise((s, r) => {
|
|
483
491
|
if (t.test(`${e.status}`))
|
|
484
492
|
return s(e);
|
|
485
|
-
const
|
|
493
|
+
const i = {
|
|
486
494
|
message: e.statusText,
|
|
487
495
|
status: e.status,
|
|
488
496
|
response: Array.isArray(e.data) ? e.data[0] : e.data.error || e.data.slug
|
|
489
497
|
};
|
|
490
|
-
|
|
498
|
+
r(i);
|
|
491
499
|
});
|
|
492
500
|
}
|
|
493
501
|
}
|
|
494
|
-
|
|
502
|
+
var _e = { NVM_INC: "/Users/lisilinhart/.nvm/versions/node/v18.16.0/include/node", TERM_PROGRAM: "iTerm.app", NODE: "/Users/lisilinhart/.nvm/versions/node/v18.16.0/bin/node", NVM_CD_FLAGS: "-q", INIT_CWD: "/Users/lisilinhart/Code/storyblok-js-client", SHELL: "/bin/zsh", TERM: "xterm-256color", TMPDIR: "/var/folders/9v/t3hq3s9n2rj6_x9jlsjjq95w0000gn/T/", npm_config_metrics_registry: "https://registry.npmjs.org/", npm_config_global_prefix: "/Users/lisilinhart/.nvm/versions/node/v18.16.0", TERM_PROGRAM_VERSION: "3.4.20", TERM_SESSION_ID: "w0t0p1:12B7CE01-010D-40B5-B6DA-DFE3CF20B8FF", COLOR: "0", npm_config_noproxy: "", ZSH: "/Users/lisilinhart/.oh-my-zsh", npm_config_local_prefix: "/Users/lisilinhart/Code/storyblok-js-client", USER: "lisilinhart", NVM_DIR: "/Users/lisilinhart/.nvm", COMMAND_MODE: "unix2003", npm_config_globalconfig: "/Users/lisilinhart/.nvm/versions/node/v18.16.0/etc/npmrc", SSH_AUTH_SOCK: "/private/tmp/com.apple.launchd.oUounWp9qr/Listeners", __CF_USER_TEXT_ENCODING: "0x1F5:0x0:0x5C", npm_execpath: "/Users/lisilinhart/.nvm/versions/node/v18.16.0/lib/node_modules/npm/bin/npm-cli.js", PAGER: "less", npm_package_integrity: "null", LSCOLORS: "Gxfxcxdxbxegedabagacad", PATH: "/Users/lisilinhart/Code/storyblok-js-client/node_modules/.bin:/Users/lisilinhart/Code/node_modules/.bin:/Users/lisilinhart/node_modules/.bin:/Users/node_modules/.bin:/node_modules/.bin:/Users/lisilinhart/.nvm/versions/node/v18.16.0/lib/node_modules/npm/node_modules/@npmcli/run-script/lib/node-gyp-bin:/Users/lisilinhart/Code/storyblok-js-client/node_modules/.bin:/Users/lisilinhart/Code/node_modules/.bin:/Users/lisilinhart/node_modules/.bin:/Users/node_modules/.bin:/node_modules/.bin:/Users/lisilinhart/.nvm/versions/node/v18.16.0/lib/node_modules/npm/node_modules/@npmcli/run-script/lib/node-gyp-bin:/usr/local/sbin:/Users/lisilinhart/.rbenv/shims:/Users/lisilinhart/.yarn/bin:/Users/lisilinhart/.config/yarn/global/node_modules/.bin:/Users/lisilinhart/.rbenv/shims:/Users/lisilinhart/.nvm/versions/node/v18.16.0/bin:/Users/lisilinhart/bin:/usr/local/bin:/usr/local/bin:/System/Cryptexes/App/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/local/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/appleinternal/bin:/Library/Apple/usr/bin:/Users/lisilinhart/.cargo/bin", RUBY_CONFIGURE_OPTS: "--with-openssl-dir=/usr/local/opt/openssl@1.1", LaunchInstanceID: "9D2A03D3-35CC-4CDD-810D-0D5C25991BBB", _: "/Users/lisilinhart/.nvm/versions/node/v18.16.0/bin/node", npm_package_json: "/Users/lisilinhart/Code/storyblok-js-client/package.json", __CFBundleIdentifier: "com.googlecode.iterm2", npm_config_init_module: "/Users/lisilinhart/.npm-init.js", npm_config_userconfig: "/Users/lisilinhart/.npmrc", PWD: "/Users/lisilinhart/Code/storyblok-js-client", npm_command: "run-script", P9K_SSH: "0", EDITOR: "vi", npm_lifecycle_event: "build", LANG: "de_AT.UTF-8", P9K_TTY: "old", npm_package_name: "storyblok-js-client", ITERM_PROFILE: "Default", XPC_FLAGS: "0x0", RBENV_SHELL: "zsh", npm_config_node_gyp: "/Users/lisilinhart/.nvm/versions/node/v18.16.0/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js", XPC_SERVICE_NAME: "0", npm_package_version: "6.4.1", COLORFGBG: "7;0", HOME: "/Users/lisilinhart", SHLVL: "3", npm_package_resolved: "/Users/lisilinhart/Code/storyblok-js-client", LC_TERMINAL_VERSION: "3.4.20", ITERM_SESSION_ID: "w0t0p1:12B7CE01-010D-40B5-B6DA-DFE3CF20B8FF", LOGNAME: "lisilinhart", LESS: "-R", npm_config_cache: "/Users/lisilinhart/.npm", npm_lifecycle_script: "node vite.build.mjs && tsc", NVM_BIN: "/Users/lisilinhart/.nvm/versions/node/v18.16.0/bin", npm_config_user_agent: "npm/9.5.1 node/v18.16.0 darwin x64 workspaces/false", LC_TERMINAL: "iTerm2", SECURITYSESSIONID: "186a1", COLORTERM: "truecolor", npm_config_prefix: "/Users/lisilinhart/.nvm/versions/node/v18.16.0", npm_node_execpath: "/Users/lisilinhart/.nvm/versions/node/v18.16.0/bin/node", NODE_ENV: "production" };
|
|
503
|
+
const j = "SB-Agent", w = {
|
|
495
504
|
defaultAgentName: "SB-JS-CLIENT",
|
|
496
505
|
defaultAgentVersion: "SB-Agent-Version",
|
|
497
|
-
packageVersion:
|
|
506
|
+
packageVersion: _e.npm_package_version
|
|
498
507
|
};
|
|
499
508
|
let y = {};
|
|
500
|
-
const
|
|
501
|
-
class
|
|
509
|
+
const g = {};
|
|
510
|
+
class ke {
|
|
502
511
|
/**
|
|
503
512
|
*
|
|
504
513
|
* @param config ISbConfig interface
|
|
505
514
|
* @param endpoint string, optional
|
|
506
515
|
*/
|
|
507
516
|
constructor(e, t) {
|
|
508
|
-
h(this, "client"), h(this, "maxRetries"), h(this, "throttle"), h(this, "accessToken"), h(this, "cache"), h(this, "helpers"), h(this, "resolveCounter"), h(this, "relations"), h(this, "links"), h(this, "richTextResolver"), h(this, "resolveNestedRelations");
|
|
517
|
+
h(this, "client"), h(this, "maxRetries"), h(this, "throttle"), h(this, "accessToken"), h(this, "cache"), h(this, "helpers"), h(this, "resolveCounter"), h(this, "relations"), h(this, "links"), h(this, "richTextResolver"), h(this, "resolveNestedRelations"), h(this, "stringifiedStoriesCache");
|
|
509
518
|
let s = e.endpoint || t;
|
|
510
519
|
if (!s) {
|
|
511
|
-
const
|
|
512
|
-
e.oauthToken ? s = `${l}://${
|
|
520
|
+
const n = new b().getRegionURL, l = e.https === !1 ? "http" : "https";
|
|
521
|
+
e.oauthToken ? s = `${l}://${n(e.region)}/v1` : s = `${l}://${n(e.region)}/v2`;
|
|
513
522
|
}
|
|
514
523
|
const r = new Headers();
|
|
515
524
|
if (r.set("Content-Type", "application/json"), r.set("Accept", "application/json"), e.headers)
|
|
516
|
-
for (const
|
|
517
|
-
r.set(
|
|
518
|
-
r.has(
|
|
519
|
-
|
|
520
|
-
|
|
525
|
+
for (const n in e.headers)
|
|
526
|
+
r.set(n, e.headers[n]);
|
|
527
|
+
r.has(j) || (r.set(j, w.defaultAgentName), r.set(
|
|
528
|
+
w.defaultAgentVersion,
|
|
529
|
+
w.packageVersion
|
|
521
530
|
));
|
|
522
|
-
let
|
|
523
|
-
e.oauthToken && (r.set("Authorization", e.oauthToken),
|
|
531
|
+
let i = 5;
|
|
532
|
+
e.oauthToken && (r.set("Authorization", e.oauthToken), i = 3), e.rateLimit && (i = e.rateLimit), e.richTextSchema ? this.richTextResolver = new v(e.richTextSchema) : this.richTextResolver = new v(), e.componentResolver && this.setComponentResolver(e.componentResolver), this.maxRetries = e.maxRetries || 5, this.throttle = z(this.throttledRequest, i, 1e3), this.accessToken = e.accessToken || "", this.relations = {}, this.links = {}, this.cache = e.cache || { clear: "manual" }, this.helpers = new b(), this.resolveCounter = 0, this.resolveNestedRelations = e.resolveNestedRelations || !0, this.stringifiedStoriesCache = {}, this.client = new ve({
|
|
524
533
|
baseURL: s,
|
|
525
534
|
timeout: e.timeout || 0,
|
|
526
535
|
headers: r,
|
|
@@ -539,17 +548,17 @@ class ve {
|
|
|
539
548
|
});
|
|
540
549
|
}
|
|
541
550
|
parseParams(e) {
|
|
542
|
-
return e.
|
|
551
|
+
return e.token || (e.token = this.getToken()), e.cv || (e.cv = g[e.token]), Array.isArray(e.resolve_relations) && (e.resolve_relations = e.resolve_relations.join(",")), e;
|
|
543
552
|
}
|
|
544
553
|
factoryParamOptions(e, t) {
|
|
545
554
|
return this.helpers.isCDNUrl(e) ? this.parseParams(t) : t;
|
|
546
555
|
}
|
|
547
556
|
makeRequest(e, t, s, r) {
|
|
548
|
-
const
|
|
557
|
+
const i = this.factoryParamOptions(
|
|
549
558
|
e,
|
|
550
559
|
this.helpers.getOptionsPage(t, s, r)
|
|
551
560
|
);
|
|
552
|
-
return this.cacheResponse(e,
|
|
561
|
+
return this.cacheResponse(e, i);
|
|
553
562
|
}
|
|
554
563
|
get(e, t) {
|
|
555
564
|
t || (t = {});
|
|
@@ -557,13 +566,13 @@ class ve {
|
|
|
557
566
|
return this.cacheResponse(s, r);
|
|
558
567
|
}
|
|
559
568
|
async getAll(e, t, s) {
|
|
560
|
-
const r = (t == null ? void 0 : t.per_page) || 25,
|
|
569
|
+
const r = (t == null ? void 0 : t.per_page) || 25, i = `/${e}`, n = i.split("/"), l = s || n[n.length - 1], a = 1, c = await this.makeRequest(i, t, r, a), u = c.total ? Math.ceil(c.total / r) : 1, p = await this.helpers.asyncMap(
|
|
561
570
|
this.helpers.range(a, u),
|
|
562
|
-
(
|
|
571
|
+
(m) => this.makeRequest(i, t, r, m + 1)
|
|
563
572
|
);
|
|
564
573
|
return this.helpers.flatMap(
|
|
565
574
|
[c, ...p],
|
|
566
|
-
(
|
|
575
|
+
(m) => Object.values(m.data[l])
|
|
567
576
|
);
|
|
568
577
|
}
|
|
569
578
|
post(e, t) {
|
|
@@ -597,40 +606,40 @@ class ve {
|
|
|
597
606
|
const r = e[t];
|
|
598
607
|
r && r.fieldtype == "multilink" && r.linktype == "story" && typeof r.id == "string" && this.links[s][r.id] ? r.story = this._cleanCopy(this.links[s][r.id]) : r && r.linktype === "story" && typeof r.uuid == "string" && this.links[s][r.uuid] && (r.story = this._cleanCopy(this.links[s][r.uuid]));
|
|
599
608
|
}
|
|
609
|
+
/**
|
|
610
|
+
*
|
|
611
|
+
* @param resolveId A counter number as a string
|
|
612
|
+
* @param uuid The uuid of the story
|
|
613
|
+
* @returns string | object
|
|
614
|
+
*/
|
|
615
|
+
getStoryReference(e, t) {
|
|
616
|
+
return this.relations[e][t] ? (this.stringifiedStoriesCache[t] || (this.stringifiedStoriesCache[t] = JSON.stringify(
|
|
617
|
+
this.relations[e][t]
|
|
618
|
+
)), JSON.parse(this.stringifiedStoriesCache[t])) : t;
|
|
619
|
+
}
|
|
600
620
|
_insertRelations(e, t, s, r) {
|
|
601
|
-
|
|
602
|
-
if (typeof e[t] == "string")
|
|
603
|
-
this.relations[r][e[t]] && (e[t] = this._cleanCopy(
|
|
604
|
-
this.relations[r][e[t]]
|
|
605
|
-
));
|
|
606
|
-
else if (e[t] && e[t].constructor === Array) {
|
|
607
|
-
const n = [];
|
|
608
|
-
e[t].forEach((i) => {
|
|
609
|
-
this.relations[r][i] && n.push(this._cleanCopy(this.relations[r][i]));
|
|
610
|
-
}), e[t] = n;
|
|
611
|
-
}
|
|
612
|
-
}
|
|
621
|
+
s.indexOf(`${e.component}.${t}`) > -1 && (typeof e[t] == "string" ? e[t] = this.getStoryReference(r, e[t]) : Array.isArray(e[t]) && (e[t] = e[t].map((i) => this.getStoryReference(r, i)).filter(Boolean)));
|
|
613
622
|
}
|
|
614
623
|
iterateTree(e, t, s) {
|
|
615
|
-
const r = (
|
|
616
|
-
if (
|
|
617
|
-
if (
|
|
618
|
-
for (let
|
|
619
|
-
r(n
|
|
620
|
-
else if (
|
|
621
|
-
if (
|
|
624
|
+
const r = (i) => {
|
|
625
|
+
if (i != null) {
|
|
626
|
+
if (i.constructor === Array)
|
|
627
|
+
for (let n = 0; n < i.length; n++)
|
|
628
|
+
r(i[n]);
|
|
629
|
+
else if (i.constructor === Object) {
|
|
630
|
+
if (i._stopResolving)
|
|
622
631
|
return;
|
|
623
|
-
for (const
|
|
624
|
-
(
|
|
625
|
-
n,
|
|
632
|
+
for (const n in i)
|
|
633
|
+
(i.component && i._uid || i.type === "link") && (this._insertRelations(
|
|
626
634
|
i,
|
|
635
|
+
n,
|
|
627
636
|
t,
|
|
628
637
|
s
|
|
629
638
|
), this._insertLinks(
|
|
630
|
-
n,
|
|
631
639
|
i,
|
|
640
|
+
n,
|
|
632
641
|
s
|
|
633
|
-
)), r(n
|
|
642
|
+
)), r(i[n]);
|
|
634
643
|
}
|
|
635
644
|
}
|
|
636
645
|
};
|
|
@@ -639,17 +648,17 @@ class ve {
|
|
|
639
648
|
async resolveLinks(e, t, s) {
|
|
640
649
|
let r = [];
|
|
641
650
|
if (e.link_uuids) {
|
|
642
|
-
const
|
|
643
|
-
for (let a = 0; a <
|
|
644
|
-
const c = Math.min(
|
|
645
|
-
|
|
651
|
+
const i = e.link_uuids.length, n = [], l = 50;
|
|
652
|
+
for (let a = 0; a < i; a += l) {
|
|
653
|
+
const c = Math.min(i, a + l);
|
|
654
|
+
n.push(e.link_uuids.slice(a, c));
|
|
646
655
|
}
|
|
647
|
-
for (let a = 0; a <
|
|
656
|
+
for (let a = 0; a < n.length; a++)
|
|
648
657
|
(await this.getStories({
|
|
649
658
|
per_page: l,
|
|
650
659
|
language: t.language,
|
|
651
660
|
version: t.version,
|
|
652
|
-
by_uuids:
|
|
661
|
+
by_uuids: n[a].join(",")
|
|
653
662
|
})).data.stories.forEach(
|
|
654
663
|
(c) => {
|
|
655
664
|
r.push(c);
|
|
@@ -657,9 +666,9 @@ class ve {
|
|
|
657
666
|
);
|
|
658
667
|
} else
|
|
659
668
|
r = e.links;
|
|
660
|
-
r.forEach((
|
|
661
|
-
this.links[s][
|
|
662
|
-
...
|
|
669
|
+
r.forEach((i) => {
|
|
670
|
+
this.links[s][i.uuid] = {
|
|
671
|
+
...i,
|
|
663
672
|
_stopResolving: !0
|
|
664
673
|
};
|
|
665
674
|
});
|
|
@@ -667,52 +676,53 @@ class ve {
|
|
|
667
676
|
async resolveRelations(e, t, s) {
|
|
668
677
|
let r = [];
|
|
669
678
|
if (e.rel_uuids) {
|
|
670
|
-
const
|
|
671
|
-
for (let a = 0; a <
|
|
672
|
-
const c = Math.min(
|
|
673
|
-
|
|
679
|
+
const i = e.rel_uuids.length, n = [], l = 50;
|
|
680
|
+
for (let a = 0; a < i; a += l) {
|
|
681
|
+
const c = Math.min(i, a + l);
|
|
682
|
+
n.push(e.rel_uuids.slice(a, c));
|
|
674
683
|
}
|
|
675
|
-
for (let a = 0; a <
|
|
684
|
+
for (let a = 0; a < n.length; a++)
|
|
676
685
|
(await this.getStories({
|
|
677
686
|
per_page: l,
|
|
678
687
|
language: t.language,
|
|
679
688
|
version: t.version,
|
|
680
|
-
by_uuids:
|
|
689
|
+
by_uuids: n[a].join(","),
|
|
690
|
+
excluding_fields: t.excluding_fields
|
|
681
691
|
})).data.stories.forEach((c) => {
|
|
682
692
|
r.push(c);
|
|
683
693
|
});
|
|
684
694
|
} else
|
|
685
695
|
r = e.rels;
|
|
686
|
-
r && r.length > 0 && r.forEach((
|
|
687
|
-
this.relations[s][
|
|
688
|
-
...
|
|
696
|
+
r && r.length > 0 && r.forEach((i) => {
|
|
697
|
+
this.relations[s][i.uuid] = {
|
|
698
|
+
...i,
|
|
689
699
|
_stopResolving: !0
|
|
690
700
|
};
|
|
691
701
|
});
|
|
692
702
|
}
|
|
693
703
|
async resolveStories(e, t, s) {
|
|
694
|
-
var r,
|
|
695
|
-
let
|
|
696
|
-
if (this.links[s] = {}, this.relations[s] = {}, typeof t.resolve_relations < "u" && t.resolve_relations.length > 0 && (typeof t.resolve_relations == "string" && (
|
|
704
|
+
var r, i;
|
|
705
|
+
let n = [];
|
|
706
|
+
if (this.links[s] = {}, this.relations[s] = {}, typeof t.resolve_relations < "u" && t.resolve_relations.length > 0 && (typeof t.resolve_relations == "string" && (n = t.resolve_relations.split(",")), await this.resolveRelations(e, t, s)), t.resolve_links && ["1", "story", "url", "link"].indexOf(t.resolve_links) > -1 && ((r = e.links) != null && r.length || (i = e.link_uuids) != null && i.length) && await this.resolveLinks(e, t, s), this.resolveNestedRelations)
|
|
697
707
|
for (const l in this.relations[s])
|
|
698
708
|
this.iterateTree(
|
|
699
709
|
this.relations[s][l],
|
|
700
|
-
|
|
710
|
+
n,
|
|
701
711
|
s
|
|
702
712
|
);
|
|
703
|
-
e.story ? this.iterateTree(e.story,
|
|
704
|
-
this.iterateTree(l,
|
|
705
|
-
}), delete this.links[s], delete this.relations[s];
|
|
713
|
+
e.story ? this.iterateTree(e.story, n, s) : e.stories.forEach((l) => {
|
|
714
|
+
this.iterateTree(l, n, s);
|
|
715
|
+
}), this.stringifiedStoriesCache = {}, delete this.links[s], delete this.relations[s];
|
|
706
716
|
}
|
|
707
717
|
async cacheResponse(e, t, s) {
|
|
708
718
|
(typeof s > "u" || !s) && (s = 0);
|
|
709
|
-
const r = this.helpers.stringify({ url: e, params: t }),
|
|
719
|
+
const r = this.helpers.stringify({ url: e, params: t }), i = this.cacheProvider();
|
|
710
720
|
if (this.cache.clear === "auto" && t.version === "draft" && await this.flushCache(), t.version === "published" && e != "/cdn/spaces/me") {
|
|
711
|
-
const
|
|
712
|
-
if (
|
|
713
|
-
return Promise.resolve(
|
|
721
|
+
const n = await i.get(r);
|
|
722
|
+
if (n)
|
|
723
|
+
return Promise.resolve(n);
|
|
714
724
|
}
|
|
715
|
-
return new Promise(async (
|
|
725
|
+
return new Promise(async (n, l) => {
|
|
716
726
|
var a;
|
|
717
727
|
try {
|
|
718
728
|
const c = await this.throttle("get", e, t);
|
|
@@ -726,11 +736,11 @@ class ve {
|
|
|
726
736
|
const p = this.resolveCounter = ++this.resolveCounter % 1e3;
|
|
727
737
|
await this.resolveStories(u.data, t, `${p}`);
|
|
728
738
|
}
|
|
729
|
-
return t.version === "published" && e != "/cdn/spaces/me" && await
|
|
739
|
+
return t.version === "published" && e != "/cdn/spaces/me" && await i.set(r, u), u.data.cv && t.token && (t.version === "draft" && g[t.token] != u.data.cv && await this.flushCache(), g[t.token] = t.cv ? t.cv : u.data.cv), n(u);
|
|
730
740
|
} catch (c) {
|
|
731
741
|
if (c.response && c.response.status === 429 && (s = s ? s + 1 : 0, s < this.maxRetries))
|
|
732
|
-
return console.log(`Hit rate limit. Retrying in ${s} seconds.`), await this.helpers.delay(1e3 * s), this.cacheResponse(e, t, s).then(
|
|
733
|
-
l(c
|
|
742
|
+
return console.log(`Hit rate limit. Retrying in ${s} seconds.`), await this.helpers.delay(1e3 * s), this.cacheResponse(e, t, s).then(n).catch(l);
|
|
743
|
+
l(c);
|
|
734
744
|
}
|
|
735
745
|
});
|
|
736
746
|
}
|
|
@@ -738,13 +748,10 @@ class ve {
|
|
|
738
748
|
return this.client[e](t, s);
|
|
739
749
|
}
|
|
740
750
|
cacheVersions() {
|
|
741
|
-
return
|
|
751
|
+
return g;
|
|
742
752
|
}
|
|
743
753
|
cacheVersion() {
|
|
744
|
-
return
|
|
745
|
-
}
|
|
746
|
-
setCacheVersion(e) {
|
|
747
|
-
this.accessToken && (f[this.accessToken] = e);
|
|
754
|
+
return g[this.accessToken];
|
|
748
755
|
}
|
|
749
756
|
cacheProvider() {
|
|
750
757
|
switch (this.cache.type) {
|
|
@@ -769,7 +776,7 @@ class ve {
|
|
|
769
776
|
default:
|
|
770
777
|
return {
|
|
771
778
|
get() {
|
|
772
|
-
return Promise.resolve(
|
|
779
|
+
return Promise.resolve();
|
|
773
780
|
},
|
|
774
781
|
getAll() {
|
|
775
782
|
return Promise.resolve(void 0);
|
|
@@ -795,8 +802,8 @@ const xe = (o = {}) => {
|
|
|
795
802
|
);
|
|
796
803
|
return;
|
|
797
804
|
}
|
|
798
|
-
return { storyblokApi: new
|
|
799
|
-
},
|
|
805
|
+
return { storyblokApi: new ke(e) };
|
|
806
|
+
}, Re = (o) => {
|
|
800
807
|
if (typeof o != "object" || typeof o._editable > "u")
|
|
801
808
|
return {};
|
|
802
809
|
const e = JSON.parse(
|
|
@@ -807,42 +814,42 @@ const xe = (o = {}) => {
|
|
|
807
814
|
"data-blok-uid": e.id + "-" + e.uid
|
|
808
815
|
} : {};
|
|
809
816
|
};
|
|
810
|
-
let T,
|
|
811
|
-
const
|
|
817
|
+
let T, I = "https://app.storyblok.com/f/storyblok-v2-latest.js";
|
|
818
|
+
const we = (o, e, t = {}) => {
|
|
812
819
|
var s;
|
|
813
|
-
const r = !(typeof window > "u") && typeof window.storyblokRegisterEvent < "u",
|
|
820
|
+
const r = !(typeof window > "u") && typeof window.storyblokRegisterEvent < "u", i = +new URL((s = window.location) == null ? void 0 : s.href).searchParams.get(
|
|
814
821
|
"_storyblok"
|
|
815
822
|
) === o;
|
|
816
|
-
if (!(!r || !
|
|
823
|
+
if (!(!r || !i)) {
|
|
817
824
|
if (!o) {
|
|
818
825
|
console.warn("Story ID is not defined. Please provide a valid ID.");
|
|
819
826
|
return;
|
|
820
827
|
}
|
|
821
828
|
window.storyblokRegisterEvent(() => {
|
|
822
|
-
new window.StoryblokBridge(t).on(["input", "published", "change"], (
|
|
823
|
-
|
|
829
|
+
new window.StoryblokBridge(t).on(["input", "published", "change"], (n) => {
|
|
830
|
+
n.action === "input" && n.story.id === o ? e(n.story) : (n.action === "change" || n.action === "published") && n.storyId === o && window.location.reload();
|
|
824
831
|
});
|
|
825
832
|
});
|
|
826
833
|
}
|
|
827
|
-
},
|
|
834
|
+
}, Se = (o = {}) => {
|
|
828
835
|
var e, t;
|
|
829
836
|
const {
|
|
830
837
|
bridge: s,
|
|
831
838
|
accessToken: r,
|
|
832
|
-
use:
|
|
833
|
-
apiOptions:
|
|
839
|
+
use: i = [],
|
|
840
|
+
apiOptions: n = {},
|
|
834
841
|
richText: l = {},
|
|
835
842
|
bridgeUrl: a
|
|
836
843
|
} = o;
|
|
837
|
-
|
|
838
|
-
const c = { bridge: s, apiOptions:
|
|
844
|
+
n.accessToken = n.accessToken || r;
|
|
845
|
+
const c = { bridge: s, apiOptions: n };
|
|
839
846
|
let u = {};
|
|
840
|
-
|
|
841
|
-
u = { ...u, ...
|
|
842
|
-
}), a && (
|
|
847
|
+
i.forEach((m) => {
|
|
848
|
+
u = { ...u, ...m(c) };
|
|
849
|
+
}), a && (I = a);
|
|
843
850
|
const p = !(typeof window > "u") && ((t = (e = window.location) == null ? void 0 : e.search) == null ? void 0 : t.includes("_storyblok_tk"));
|
|
844
|
-
return s !== !1 && p &&
|
|
845
|
-
},
|
|
851
|
+
return s !== !1 && p && B(I), T = new v(l.schema), l.resolver && U(T, l.resolver), u;
|
|
852
|
+
}, U = (o, e) => {
|
|
846
853
|
o.addNode("blok", (t) => {
|
|
847
854
|
let s = "";
|
|
848
855
|
return t.attrs.body.forEach((r) => {
|
|
@@ -851,7 +858,7 @@ const $e = (o, e, t = {}) => {
|
|
|
851
858
|
html: s
|
|
852
859
|
};
|
|
853
860
|
});
|
|
854
|
-
},
|
|
861
|
+
}, Te = (o) => !o || !(o != null && o.content.some((e) => e.content || e.type === "blok" || e.type === "horizontal_rule")), je = (o, e, t) => {
|
|
855
862
|
let s = t || T;
|
|
856
863
|
if (!s) {
|
|
857
864
|
console.error(
|
|
@@ -859,31 +866,31 @@ const $e = (o, e, t = {}) => {
|
|
|
859
866
|
);
|
|
860
867
|
return;
|
|
861
868
|
}
|
|
862
|
-
return
|
|
863
|
-
},
|
|
869
|
+
return Te(o) ? "" : (e && (s = new v(e.schema), e.resolver && U(s, e.resolver)), s.render(o));
|
|
870
|
+
}, Ce = /* @__PURE__ */ O({
|
|
864
871
|
__name: "StoryblokComponent",
|
|
865
872
|
props: {
|
|
866
873
|
blok: {}
|
|
867
874
|
},
|
|
868
875
|
setup(o, { expose: e }) {
|
|
869
|
-
const t = o, s =
|
|
876
|
+
const t = o, s = S();
|
|
870
877
|
e({
|
|
871
878
|
value: s
|
|
872
879
|
});
|
|
873
|
-
const r = typeof
|
|
874
|
-
return r || (
|
|
875
|
-
`Is the Fallback component "${
|
|
880
|
+
const r = typeof R(t.blok.component) != "string", i = N("VueSDKOptions"), n = S(t.blok.component);
|
|
881
|
+
return r || (i.enableFallbackComponent ? (n.value = i.customFallbackComponent ?? "FallbackComponent", typeof R(n.value) == "string" && console.error(
|
|
882
|
+
`Is the Fallback component "${n.value}" registered properly?`
|
|
876
883
|
)) : console.error(
|
|
877
884
|
`Component could not be found for blok "${t.blok.component}"! Is it defined in main.ts as "app.component("${t.blok.component}", ${t.blok.component});"?`
|
|
878
|
-
)), (l, a) => (
|
|
885
|
+
)), (l, a) => (P(), L(R(n.value), M({
|
|
879
886
|
ref_key: "blokRef",
|
|
880
887
|
ref: s
|
|
881
888
|
}, { ...l.$props, ...l.$attrs }), null, 16));
|
|
882
889
|
}
|
|
883
|
-
}),
|
|
890
|
+
}), $e = {
|
|
884
891
|
beforeMount(o, e) {
|
|
885
892
|
if (e.value) {
|
|
886
|
-
const t =
|
|
893
|
+
const t = Re(e.value);
|
|
887
894
|
Object.keys(t).length > 0 && (o.setAttribute("data-blok-c", t["data-blok-c"]), o.setAttribute("data-blok-uid", t["data-blok-uid"]), o.classList.add("storyblok__outline"));
|
|
888
895
|
}
|
|
889
896
|
}
|
|
@@ -891,17 +898,17 @@ const $e = (o, e, t = {}) => {
|
|
|
891
898
|
console.error(`You can't use ${o} if you're not loading apiPlugin. Please provide it on StoryblokVue initialization.
|
|
892
899
|
`);
|
|
893
900
|
};
|
|
894
|
-
let
|
|
895
|
-
const
|
|
896
|
-
const s =
|
|
897
|
-
if (t.resolveRelations = t.resolveRelations ?? e.resolve_relations, t.resolveLinks = t.resolveLinks ?? e.resolve_links,
|
|
898
|
-
s.value && s.value.id &&
|
|
901
|
+
let f = null;
|
|
902
|
+
const Ie = () => (f || A("useStoryblokApi"), f), Ue = async (o, e = {}, t = {}) => {
|
|
903
|
+
const s = S(null);
|
|
904
|
+
if (t.resolveRelations = t.resolveRelations ?? e.resolve_relations, t.resolveLinks = t.resolveLinks ?? e.resolve_links, D(() => {
|
|
905
|
+
s.value && s.value.id && we(
|
|
899
906
|
s.value.id,
|
|
900
907
|
(r) => s.value = r,
|
|
901
908
|
t
|
|
902
909
|
);
|
|
903
|
-
}),
|
|
904
|
-
const { data: r } = await
|
|
910
|
+
}), f) {
|
|
911
|
+
const { data: r } = await f.get(
|
|
905
912
|
`cdn/stories/${o}`,
|
|
906
913
|
e
|
|
907
914
|
);
|
|
@@ -909,24 +916,24 @@ const Pe = () => (m || A("useStoryblokApi"), m), Ee = async (o, e = {}, t = {})
|
|
|
909
916
|
} else
|
|
910
917
|
A("useStoryblok");
|
|
911
918
|
return s;
|
|
912
|
-
},
|
|
919
|
+
}, Ae = {
|
|
913
920
|
install(o, e = {}) {
|
|
914
|
-
o.directive("editable",
|
|
921
|
+
o.directive("editable", $e), o.component("StoryblokComponent", Ce), e.enableFallbackComponent && !e.customFallbackComponent && o.component(
|
|
915
922
|
"FallbackComponent",
|
|
916
|
-
|
|
923
|
+
F(() => import("./FallbackComponent-hOszcW1L.mjs"))
|
|
917
924
|
);
|
|
918
|
-
const { storyblokApi: t } =
|
|
919
|
-
|
|
925
|
+
const { storyblokApi: t } = Se(e);
|
|
926
|
+
f = t, o.provide("VueSDKOptions", e);
|
|
920
927
|
}
|
|
921
928
|
};
|
|
922
929
|
export {
|
|
923
|
-
|
|
930
|
+
v as RichTextResolver,
|
|
924
931
|
ye as RichTextSchema,
|
|
925
|
-
|
|
926
|
-
|
|
932
|
+
Ce as StoryblokComponent,
|
|
933
|
+
Ae as StoryblokVue,
|
|
927
934
|
xe as apiPlugin,
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
935
|
+
je as renderRichText,
|
|
936
|
+
Ue as useStoryblok,
|
|
937
|
+
Ie as useStoryblokApi,
|
|
938
|
+
we as useStoryblokBridge
|
|
932
939
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@storyblok/vue",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "8.0.0",
|
|
4
4
|
"description": "Storyblok directive for get editable elements.",
|
|
5
5
|
"main": "./dist/storyblok-vue.js",
|
|
6
6
|
"module": "./dist/storyblok-vue.mjs",
|
|
@@ -25,26 +25,26 @@
|
|
|
25
25
|
"prepublishOnly": "npm run build && cp ../README.md ./"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@storyblok/js": "^
|
|
28
|
+
"@storyblok/js": "^3.0.0"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
|
-
"@babel/core": "^7.23.
|
|
31
|
+
"@babel/core": "^7.23.6",
|
|
32
32
|
"@cypress/vite-dev-server": "^5.0.6",
|
|
33
33
|
"@cypress/vue": "^6.0.0",
|
|
34
|
-
"@vitejs/plugin-vue": "^4.
|
|
34
|
+
"@vitejs/plugin-vue": "^4.5.2",
|
|
35
35
|
"@vue/babel-preset-app": "^5.0.8",
|
|
36
|
-
"@vue/test-utils": "2.4.
|
|
36
|
+
"@vue/test-utils": "2.4.3",
|
|
37
37
|
"@vue/tsconfig": "^0.1.3",
|
|
38
38
|
"@vue/vue3-jest": "^29.2.6",
|
|
39
39
|
"babel-jest": "^29.4.3",
|
|
40
|
-
"cypress": "^13.
|
|
40
|
+
"cypress": "^13.5.1",
|
|
41
41
|
"eslint-plugin-cypress": "^2.15.1",
|
|
42
|
-
"eslint-plugin-jest": "^27.
|
|
42
|
+
"eslint-plugin-jest": "^27.6.0",
|
|
43
43
|
"jest": "^29.6.4",
|
|
44
44
|
"typescript": "^4.9.5",
|
|
45
|
-
"vite": "^
|
|
45
|
+
"vite": "^5.0.8",
|
|
46
46
|
"vue": "^3.3.4",
|
|
47
|
-
"vue-tsc": "^1.8.
|
|
47
|
+
"vue-tsc": "^1.8.25"
|
|
48
48
|
},
|
|
49
49
|
"babel": {
|
|
50
50
|
"presets": [
|
|
@@ -70,7 +70,7 @@
|
|
|
70
70
|
"vue",
|
|
71
71
|
"storyblok"
|
|
72
72
|
],
|
|
73
|
-
"author": "Alexander Feiglstorfer
|
|
73
|
+
"author": "Alexander Feiglstorfer",
|
|
74
74
|
"bugs": {
|
|
75
75
|
"url": "https://github.com/storyblok/storyblok-vue/issues"
|
|
76
76
|
},
|
|
@@ -81,6 +81,10 @@
|
|
|
81
81
|
{
|
|
82
82
|
"name": "next",
|
|
83
83
|
"prerelease": true
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
"name": "beta",
|
|
87
|
+
"prerelease": true
|
|
84
88
|
}
|
|
85
89
|
]
|
|
86
90
|
},
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { defineComponent as _, openBlock as a, createElementBlock as p, createElementVNode as n, createTextVNode as c, toDisplayString as r } from "vue";
|
|
2
|
-
const d = { class: "fallback-component" }, m = { class: "component" }, i = /* @__PURE__ */ _({
|
|
3
|
-
__name: "FallbackComponent",
|
|
4
|
-
props: {
|
|
5
|
-
blok: {}
|
|
6
|
-
},
|
|
7
|
-
setup(o) {
|
|
8
|
-
return (e, t) => (a(), p("div", d, [
|
|
9
|
-
n("p", null, [
|
|
10
|
-
c(" Component could not be found for blok "),
|
|
11
|
-
n("span", m, r(e.blok.component), 1),
|
|
12
|
-
c("! Is it configured correctly? ")
|
|
13
|
-
])
|
|
14
|
-
]));
|
|
15
|
-
}
|
|
16
|
-
});
|
|
17
|
-
const u = (o, e) => {
|
|
18
|
-
const t = o.__vccOpts || o;
|
|
19
|
-
for (const [l, s] of e)
|
|
20
|
-
t[l] = s;
|
|
21
|
-
return t;
|
|
22
|
-
}, k = /* @__PURE__ */ u(i, [["__scopeId", "data-v-93c770c0"]]);
|
|
23
|
-
export {
|
|
24
|
-
k as default
|
|
25
|
-
};
|