@storyblok/vue 6.0.3 → 6.2.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/dist/StoryblokComponent.vue.d.ts +59 -0
- package/dist/index.d.ts +10 -0
- package/dist/storyblok-vue.js +6 -4
- package/dist/storyblok-vue.mjs +541 -249
- package/dist/types.d.ts +7 -0
- package/package.json +17 -13
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import type { SbBlokData } from "./types";
|
|
2
|
+
export interface SbComponentProps {
|
|
3
|
+
blok: SbBlokData;
|
|
4
|
+
}
|
|
5
|
+
declare const _default: {
|
|
6
|
+
new (...args: any[]): {
|
|
7
|
+
$: import("vue").ComponentInternalInstance;
|
|
8
|
+
$data: {};
|
|
9
|
+
$props: Partial<{}> & Omit<Readonly<import("vue").ExtractPropTypes<__VLS_TypePropsToRuntimeProps<SbComponentProps>>> & import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, never>;
|
|
10
|
+
$attrs: {
|
|
11
|
+
[x: string]: unknown;
|
|
12
|
+
};
|
|
13
|
+
$refs: {
|
|
14
|
+
[x: string]: unknown;
|
|
15
|
+
};
|
|
16
|
+
$slots: Readonly<{
|
|
17
|
+
[name: string]: import("vue").Slot;
|
|
18
|
+
}>;
|
|
19
|
+
$root: import("vue").ComponentPublicInstance<{}, {}, {}, {}, {}, {}, {}, {}, false, import("vue").ComponentOptionsBase<any, any, any, any, any, any, any, any, any, {}>>;
|
|
20
|
+
$parent: import("vue").ComponentPublicInstance<{}, {}, {}, {}, {}, {}, {}, {}, false, import("vue").ComponentOptionsBase<any, any, any, any, any, any, any, any, any, {}>>;
|
|
21
|
+
$emit: (event: string, ...args: any[]) => void;
|
|
22
|
+
$el: any;
|
|
23
|
+
$options: import("vue").ComponentOptionsBase<Readonly<import("vue").ExtractPropTypes<__VLS_TypePropsToRuntimeProps<SbComponentProps>>>, {}, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, Record<string, any>, string, {}> & {
|
|
24
|
+
beforeCreate?: (() => void) | (() => void)[];
|
|
25
|
+
created?: (() => void) | (() => void)[];
|
|
26
|
+
beforeMount?: (() => void) | (() => void)[];
|
|
27
|
+
mounted?: (() => void) | (() => void)[];
|
|
28
|
+
beforeUpdate?: (() => void) | (() => void)[];
|
|
29
|
+
updated?: (() => void) | (() => void)[];
|
|
30
|
+
activated?: (() => void) | (() => void)[];
|
|
31
|
+
deactivated?: (() => void) | (() => void)[];
|
|
32
|
+
beforeDestroy?: (() => void) | (() => void)[];
|
|
33
|
+
beforeUnmount?: (() => void) | (() => void)[];
|
|
34
|
+
destroyed?: (() => void) | (() => void)[];
|
|
35
|
+
unmounted?: (() => void) | (() => void)[];
|
|
36
|
+
renderTracked?: ((e: import("vue").DebuggerEvent) => void) | ((e: import("vue").DebuggerEvent) => void)[];
|
|
37
|
+
renderTriggered?: ((e: import("vue").DebuggerEvent) => void) | ((e: import("vue").DebuggerEvent) => void)[];
|
|
38
|
+
errorCaptured?: ((err: unknown, instance: import("vue").ComponentPublicInstance<{}, {}, {}, {}, {}, {}, {}, {}, false, import("vue").ComponentOptionsBase<any, any, any, any, any, any, any, any, any, {}>>, info: string) => boolean | void) | ((err: unknown, instance: import("vue").ComponentPublicInstance<{}, {}, {}, {}, {}, {}, {}, {}, false, import("vue").ComponentOptionsBase<any, any, any, any, any, any, any, any, any, {}>>, info: string) => boolean | void)[];
|
|
39
|
+
};
|
|
40
|
+
$forceUpdate: () => void;
|
|
41
|
+
$nextTick: typeof import("vue").nextTick;
|
|
42
|
+
$watch(source: string | Function, cb: Function, options?: import("vue").WatchOptions<boolean>): import("vue").WatchStopHandle;
|
|
43
|
+
} & Readonly<import("vue").ExtractPropTypes<__VLS_TypePropsToRuntimeProps<SbComponentProps>>> & import("vue").ShallowUnwrapRef<{}> & {} & import("vue").ComponentCustomProperties;
|
|
44
|
+
__isFragment?: never;
|
|
45
|
+
__isTeleport?: never;
|
|
46
|
+
__isSuspense?: never;
|
|
47
|
+
} & import("vue").ComponentOptionsBase<Readonly<import("vue").ExtractPropTypes<__VLS_TypePropsToRuntimeProps<SbComponentProps>>>, {}, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, Record<string, any>, string, {}> & import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps & (new () => {
|
|
48
|
+
$slots: typeof import('./StoryblokComponent.vue.__VLS_template').default;
|
|
49
|
+
});
|
|
50
|
+
export default _default;
|
|
51
|
+
declare type __VLS_NonUndefinedable<T> = T extends undefined ? never : T;
|
|
52
|
+
declare type __VLS_TypePropsToRuntimeProps<T> = {
|
|
53
|
+
[K in keyof T]-?: {} extends Pick<T, K> ? {
|
|
54
|
+
type: import('vue').PropType<__VLS_NonUndefinedable<T[K]>>;
|
|
55
|
+
} : {
|
|
56
|
+
type: import('vue').PropType<T[K]>;
|
|
57
|
+
required: true;
|
|
58
|
+
};
|
|
59
|
+
};
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Ref, Plugin } from "vue";
|
|
2
|
+
import type { StoryblokClient, StoryblokBridgeConfigV2, StoryData, StoriesParams } from "./types";
|
|
3
|
+
export declare const useStoryblokApi: () => StoryblokClient;
|
|
4
|
+
export { useStoryblokBridge, apiPlugin, renderRichText } from "@storyblok/js";
|
|
5
|
+
export { default as StoryblokComponent } from "./StoryblokComponent.vue";
|
|
6
|
+
export declare const useStoryblok: (url: string, apiOptions?: StoriesParams, bridgeOptions?: StoryblokBridgeConfigV2) => Promise<Ref<StoryData<import("storyblok-js-client").StoryblokComponent<string> & {
|
|
7
|
+
[index: string]: any;
|
|
8
|
+
}>>>;
|
|
9
|
+
export declare const StoryblokVue: Plugin;
|
|
10
|
+
export * from "./types";
|
package/dist/storyblok-vue.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
var
|
|
2
|
-
* storyblok-js-client
|
|
1
|
+
(function(d,u){typeof exports=="object"&&typeof module!="undefined"?u(exports,require("vue"),require("axios")):typeof define=="function"&&define.amd?define(["exports","vue","axios"],u):(d=typeof globalThis!="undefined"?globalThis:d||self,u(d.storyblokVue={},d.Vue,d.e))})(this,function(d,u,p){"use strict";var lt=Object.defineProperty;var A=Object.getOwnPropertySymbols;var ct=Object.prototype.hasOwnProperty,ut=Object.prototype.propertyIsEnumerable;var M=(d,u,p)=>u in d?lt(d,u,{enumerable:!0,configurable:!0,writable:!0,value:p}):d[u]=p,_=(d,u)=>{for(var p in u||(u={}))ct.call(u,p)&&M(d,p,u[p]);if(A)for(var p of A(u))ut.call(u,p)&&M(d,p,u[p]);return d};function C(n){return n&&typeof n=="object"&&"default"in n?n:{default:n}}var x=C(p),N=Object.defineProperty,I=Object.defineProperties,q=Object.getOwnPropertyDescriptors,T=Object.getOwnPropertySymbols,L=Object.prototype.hasOwnProperty,B=Object.prototype.propertyIsEnumerable,w=(n,t,e)=>t in n?N(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e,f=(n,t)=>{for(var e in t||(t={}))L.call(t,e)&&w(n,e,t[e]);if(T)for(var e of T(t))B.call(t,e)&&w(n,e,t[e]);return n},b=(n,t)=>I(n,q(t));let R=!1;const $=[],V=n=>new Promise((t,e)=>{if(typeof window=="undefined"||(window.storyblokRegisterEvent=s=>{if(window.location===window.parent.location){console.warn("You are not in Draft Mode or in the Visual Editor.");return}R?s():$.push(s)},document.getElementById("storyblok-javascript-bridge")))return;const r=document.createElement("script");r.async=!0,r.src=n,r.id="storyblok-javascript-bridge",r.onerror=s=>e(s),r.onload=s=>{$.forEach(o=>o()),R=!0,t(s)},document.getElementsByTagName("head")[0].appendChild(r)}),z=function(n,t){if(!n)return null;let e={};for(let r in n){let s=n[r];t.indexOf(r)>-1&&s!==null&&(e[r]=s)}return e},D=n=>n==="email";var U={nodes:{horizontal_rule(){return{singleTag:"hr"}},blockquote(){return{tag:"blockquote"}},bullet_list(){return{tag:"ul"}},code_block(n){return{tag:["pre",{tag:"code",attrs:n.attrs}]}},hard_break(){return{singleTag:"br"}},heading(n){return{tag:`h${n.attrs.level}`}},image(n){return{singleTag:[{tag:"img",attrs:z(n.attrs,["src","alt","title"])}]}},list_item(){return{tag:"li"}},ordered_list(){return{tag:"ol"}},paragraph(){return{tag:"p"}}},marks:{bold(){return{tag:"b"}},strike(){return{tag:"strike"}},underline(){return{tag:"u"}},strong(){return{tag:"strong"}},code(){return{tag:"code"}},italic(){return{tag:"i"}},link(n){const t=f({},n.attrs),{linktype:e="url"}=n.attrs;return D(e)&&(t.href=`mailto:${t.href}`),t.anchor&&(t.href=`${t.href}#${t.anchor}`,delete t.anchor),{tag:[{tag:"a",attrs:t}]}},styled(n){return{tag:[{tag:"span",attrs:n.attrs}]}}}};const H=function(n){const t={"&":"&","<":"<",">":">",'"':""","'":"'"},e=/[&<>"']/g,r=RegExp(e.source);return n&&r.test(n)?n.replace(e,s=>t[s]):n};class J{constructor(t){t||(t=U),this.marks=t.marks||[],this.nodes=t.nodes||[]}addNode(t,e){this.nodes[t]=e}addMark(t,e){this.marks[t]=e}render(t={}){if(t.content&&Array.isArray(t.content)){let e="";return t.content.forEach(r=>{e+=this.renderNode(r)}),e}return console.warn("The render method must receive an object with a content field, which is an array"),""}renderNode(t){let e=[];t.marks&&t.marks.forEach(s=>{const o=this.getMatchingMark(s);o&&e.push(this.renderOpeningTag(o.tag))});const r=this.getMatchingNode(t);return r&&r.tag&&e.push(this.renderOpeningTag(r.tag)),t.content?t.content.forEach(s=>{e.push(this.renderNode(s))}):t.text?e.push(H(t.text)):r&&r.singleTag?e.push(this.renderTag(r.singleTag," /")):r&&r.html&&e.push(r.html),r&&r.tag&&e.push(this.renderClosingTag(r.tag)),t.marks&&t.marks.slice(0).reverse().forEach(s=>{const o=this.getMatchingMark(s);o&&e.push(this.renderClosingTag(o.tag))}),e.join("")}renderTag(t,e){return t.constructor===String?`<${t}${e}>`:t.map(s=>{if(s.constructor===String)return`<${s}${e}>`;{let o=`<${s.tag}`;if(s.attrs)for(let i in s.attrs){let a=s.attrs[i];a!==null&&(o+=` ${i}="${a}"`)}return`${o}${e}>`}}).join("")}renderOpeningTag(t){return this.renderTag(t,"")}renderClosingTag(t){return t.constructor===String?`</${t}>`:t.slice(0).reverse().map(r=>r.constructor===String?`</${r}>`:`</${r.tag}>`).join("")}getMatchingNode(t){if(typeof this.nodes[t.type]=="function")return this.nodes[t.type](t)}getMatchingMark(t){if(typeof this.marks[t.type]=="function")return this.marks[t.type](t)}}/*!
|
|
2
|
+
* storyblok-js-client v4.5.2
|
|
3
3
|
* Universal JavaScript SDK for Storyblok's API
|
|
4
4
|
* (c) 2020-2022 Stobylok Team
|
|
5
|
-
*/function O(s){return typeof s=="number"&&s==s&&s!==1/0&&s!==-1/0}function P(s,e,t){if(!O(e))throw new TypeError("Expected `limit` to be a finite number");if(!O(t))throw new TypeError("Expected `interval` to be a finite number");var r=[],o=[],n=0,i=function(){n++;var c=setTimeout(function(){n--,r.length>0&&i(),o=o.filter(function(d){return d!==c})},t);o.indexOf(c)<0&&o.push(c);var l=r.shift();l.resolve(s.apply(l.self,l.args))},a=function(){var c=arguments,l=this;return new Promise(function(d,k){r.push({resolve:d,reject:k,args:c,self:l}),n<e&&i()})};return a.abort=function(){o.forEach(clearTimeout),o=[],r.forEach(function(c){c.reject(new throttle.AbortError)}),r.length=0},a}P.AbortError=function(){Error.call(this,"Throttled function aborted"),this.name="AbortError"};const D=function(s,e){if(!s)return null;let t={};for(let r in s){let o=s[r];e.indexOf(r)>-1&&o!==null&&(t[r]=o)}return t};var z={nodes:{horizontal_rule:s=>({singleTag:"hr"}),blockquote:s=>({tag:"blockquote"}),bullet_list:s=>({tag:"ul"}),code_block:s=>({tag:["pre",{tag:"code",attrs:s.attrs}]}),hard_break:s=>({singleTag:"br"}),heading:s=>({tag:"h"+s.attrs.level}),image:s=>({singleTag:[{tag:"img",attrs:D(s.attrs,["src","alt","title"])}]}),list_item:s=>({tag:"li"}),ordered_list:s=>({tag:"ol"}),paragraph:s=>({tag:"p"})},marks:{bold:()=>({tag:"b"}),strike:()=>({tag:"strike"}),underline:()=>({tag:"u"}),strong:()=>({tag:"strong"}),code:()=>({tag:"code"}),italic:()=>({tag:"i"}),link(s){const e=f({},s.attrs),{linktype:t="url"}=s.attrs;return t==="email"&&(e.href="mailto:"+e.href),e.anchor&&(e.href=`${e.href}#${e.anchor}`,delete e.anchor),{tag:[{tag:"a",attrs:e}]}},styled:s=>({tag:[{tag:"span",attrs:s.attrs}]})}};class U{constructor(e){e||(e=z),this.marks=e.marks||[],this.nodes=e.nodes||[]}addNode(e,t){this.nodes[e]=t}addMark(e,t){this.marks[e]=t}render(e={}){if(e.content&&Array.isArray(e.content)){let t="";return e.content.forEach(r=>{t+=this.renderNode(r)}),t}return console.warn("The render method must receive an object with a content field, which is an array"),""}renderNode(e){let t=[];e.marks&&e.marks.forEach(o=>{const n=this.getMatchingMark(o);n&&t.push(this.renderOpeningTag(n.tag))});const r=this.getMatchingNode(e);return r&&r.tag&&t.push(this.renderOpeningTag(r.tag)),e.content?e.content.forEach(o=>{t.push(this.renderNode(o))}):e.text?t.push(function(o){const n={"&":"&","<":"<",">":">",'"':""","'":"'"},i=/[&<>"']/g,a=RegExp(i.source);return o&&a.test(o)?o.replace(i,c=>n[c]):o}(e.text)):r&&r.singleTag?t.push(this.renderTag(r.singleTag," /")):r&&r.html&&t.push(r.html),r&&r.tag&&t.push(this.renderClosingTag(r.tag)),e.marks&&e.marks.slice(0).reverse().forEach(o=>{const n=this.getMatchingMark(o);n&&t.push(this.renderClosingTag(n.tag))}),t.join("")}renderTag(e,t){return e.constructor===String?`<${e}${t}>`:e.map(r=>{if(r.constructor===String)return`<${r}${t}>`;{let o="<"+r.tag;if(r.attrs)for(let n in r.attrs){let i=r.attrs[n];i!==null&&(o+=` ${n}="${i}"`)}return`${o}${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){if(typeof this.nodes[e.type]=="function")return this.nodes[e.type](e)}getMatchingMark(e){if(typeof this.marks[e.type]=="function")return this.marks[e.type](e)}}const J=(s=0,e=s)=>{const t=Math.abs(e-s)||0,r=s<e?1:-1;return((o=0,n)=>[...Array(o)].map(n))(t,(o,n)=>n*r+s)},v=(s,e,t)=>{const r=[];for(const o in s){if(!Object.prototype.hasOwnProperty.call(s,o))continue;const n=s[o],i=t?"":encodeURIComponent(o);let a;a=typeof n=="object"?v(n,e?e+encodeURIComponent("["+i+"]"):i,Array.isArray(n)):(e?e+encodeURIComponent("["+i+"]"):i)+"="+encodeURIComponent(n),r.push(a)}return r.join("&")};let m={},g={};class Y{constructor(e,t){if(!t){let n=e.region?"-"+e.region:"",i=e.https===!1?"http":"https";t=e.oauthToken===void 0?`${i}://api${n}.storyblok.com/v2`:`${i}://api${n}.storyblok.com/v1`}let r=Object.assign({},e.headers),o=5;e.oauthToken!==void 0&&(r.Authorization=e.oauthToken,o=3),e.rateLimit!==void 0&&(o=e.rateLimit),this.richTextResolver=new U(e.richTextSchema),typeof e.componentResolver=="function"&&this.setComponentResolver(e.componentResolver),this.maxRetries=e.maxRetries||5,this.throttle=P(this.throttledRequest,o,1e3),this.accessToken=e.accessToken,this.relations={},this.links={},this.cache=e.cache||{clear:"manual"},this.client=I.default.create({baseURL:t,timeout:e.timeout||0,headers:r,proxy:e.proxy||!1}),e.responseInterceptor&&this.client.interceptors.response.use(n=>e.responseInterceptor(n))}setComponentResolver(e){this.richTextResolver.addNode("blok",t=>{let r="";return t.attrs.body.forEach(o=>{r+=e(o.component,o)}),{html:r}})}parseParams(e={}){return e.version||(e.version="published"),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}factoryParamOptions(e,t={}){return((r="")=>r.indexOf("/cdn/")>-1)(e)?this.parseParams(t):t}makeRequest(e,t,r,o){const n=this.factoryParamOptions(e,((i={},a=25,c=1)=>b(f({},i),{per_page:a,page:c}))(t,r,o));return this.cacheResponse(e,n)}get(e,t){let r="/"+e;const o=this.factoryParamOptions(r,t);return this.cacheResponse(r,o)}async getAll(e,t={},r){const o=t.per_page||25,n="/"+e,i=n.split("/");r=r||i[i.length-1];const a=await this.makeRequest(n,t,o,1),c=Math.ceil(a.total/o);return((l=[],d)=>l.map(d).reduce((k,ee)=>[...k,...ee],[]))([a,...await(async(l=[],d)=>Promise.all(l.map(d)))(J(1,c),async l=>this.makeRequest(n,t,o,l+1))],l=>Object.values(l.data[r]))}post(e,t){let r="/"+e;return this.throttle("post",r,t)}put(e,t){let r="/"+e;return this.throttle("put",r,t)}delete(e,t){let r="/"+e;return this.throttle("delete",r,t)}getStories(e){return this.get("cdn/stories",e)}getStory(e,t){return this.get("cdn/stories/"+e,t)}setToken(e){this.accessToken=e}getToken(){return this.accessToken}_cleanCopy(e){return JSON.parse(JSON.stringify(e))}_insertLinks(e,t){const r=e[t];r&&r.fieldtype=="multilink"&&r.linktype=="story"&&typeof r.id=="string"&&this.links[r.id]?r.story=this._cleanCopy(this.links[r.id]):r&&r.linktype==="story"&&typeof r.uuid=="string"&&this.links[r.uuid]&&(r.story=this._cleanCopy(this.links[r.uuid]))}_insertRelations(e,t,r){if(r.indexOf(e.component+"."+t)>-1){if(typeof e[t]=="string")this.relations[e[t]]&&(e[t]=this._cleanCopy(this.relations[e[t]]));else if(e[t].constructor===Array){let o=[];e[t].forEach(n=>{this.relations[n]&&o.push(this._cleanCopy(this.relations[n]))}),e[t]=o}}}iterateTree(e,t){let r=o=>{if(o!=null){if(o.constructor===Array)for(let n=0;n<o.length;n++)r(o[n]);else if(o.constructor===Object){if(o._stopResolving)return;for(let n in o)(o.component&&o._uid||o.type==="link")&&(this._insertRelations(o,n,t),this._insertLinks(o,n)),r(o[n])}}};r(e.content)}async resolveLinks(e,t){let r=[];if(e.link_uuids){const o=e.link_uuids.length;let n=[];const i=50;for(let a=0;a<o;a+=i){const c=Math.min(o,a+i);n.push(e.link_uuids.slice(a,c))}for(let a=0;a<n.length;a++)(await this.getStories({per_page:i,language:t.language,version:t.version,by_uuids:n[a].join(",")})).data.stories.forEach(c=>{r.push(c)})}else r=e.links;r.forEach(o=>{this.links[o.uuid]=b(f({},o),{_stopResolving:!0})})}async resolveRelations(e,t){let r=[];if(e.rel_uuids){const o=e.rel_uuids.length;let n=[];const i=50;for(let a=0;a<o;a+=i){const c=Math.min(o,a+i);n.push(e.rel_uuids.slice(a,c))}for(let a=0;a<n.length;a++)(await this.getStories({per_page:i,language:t.language,version:t.version,by_uuids:n[a].join(",")})).data.stories.forEach(c=>{r.push(c)})}else r=e.rels;r.forEach(o=>{this.relations[o.uuid]=b(f({},o),{_stopResolving:!0})})}async resolveStories(e,t){let r=[];t.resolve_relations!==void 0&&t.resolve_relations.length>0&&(r=t.resolve_relations.split(","),await this.resolveRelations(e,t)),["1","story","url"].indexOf(t.resolve_links)>-1&&await this.resolveLinks(e,t);for(const o in this.relations)this.iterateTree(this.relations[o],r);e.story?this.iterateTree(e.story,r):e.stories.forEach(o=>{this.iterateTree(o,r)})}cacheResponse(e,t,r){return r===void 0&&(r=0),new Promise(async(o,n)=>{let i=v({url:e,params:t}),a=this.cacheProvider();if(this.cache.clear==="auto"&&t.version==="draft"&&await this.flushCache(),t.version==="published"&&e!="/cdn/spaces/me"){const l=await a.get(i);if(l)return o(l)}try{let l=await this.throttle("get",e,{params:t,paramsSerializer:k=>v(k)}),d={data:l.data,headers:l.headers};if(l.headers["per-page"]&&(d=Object.assign({},d,{perPage:parseInt(l.headers["per-page"]),total:parseInt(l.headers.total)})),l.status!=200)return n(l);(d.data.story||d.data.stories)&&await this.resolveStories(d.data,t),t.version==="published"&&e!="/cdn/spaces/me"&&a.set(i,d),d.data.cv&&(t.version=="draft"&&g[t.token]!=d.data.cv&&this.flushCache(),g[t.token]=d.data.cv),o(d)}catch(l){if(l.response&&l.response.status===429&&(r+=1)<this.maxRetries)return console.log(`Hit rate limit. Retrying in ${r} seconds.`),await(c=1e3*r,new Promise(d=>setTimeout(d,c))),this.cacheResponse(e,t,r).then(o).catch(n);n(l)}var c})}throttledRequest(e,t,r){return this.client[e](t,r)}cacheVersions(){return g}cacheVersion(){return g[this.accessToken]}setCacheVersion(e){this.accessToken&&(g[this.accessToken]=e)}cacheProvider(){switch(this.cache.type){case"memory":return{get:e=>m[e],getAll:()=>m,set(e,t){m[e]=t},flush(){m={}}};default:return{get(){},getAll(){},set(){},flush(){}}}}async flushCache(){return await this.cacheProvider().flush(),this}}var H=(s={})=>{const{apiOptions:e}=s;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 Y(e)}},F=s=>{if(typeof s!="object"||typeof s._editable=="undefined")return{};const e=JSON.parse(s._editable.replace(/^<!--#storyblok#/,"").replace(/-->$/,""));return{"data-blok-c":JSON.stringify(e),"data-blok-uid":e.id+"-"+e.uid}};const G="https://app.storyblok.com/f/storyblok-v2-latest.js",E=(s,e,t={})=>{if(typeof window!="undefined"){if(typeof window.storyblokRegisterEvent=="undefined"){console.error("Storyblok Bridge is disabled. Please enable it to use it. Read https://github.com/storyblok/storyblok-js");return}if(!s){console.warn("Story ID is not defined. Please provide a valid ID.");return}window.storyblokRegisterEvent(()=>{new window.StoryblokBridge(t).on(["input","published","change"],o=>{o.action=="input"&&o.story.id===s?e(o.story):window.location.reload()})})}},K=(s={})=>{const{bridge:e,accessToken:t,use:r=[],apiOptions:o={}}=s;o.accessToken=o.accessToken||t;const n={bridge:e,apiOptions:o};let i={};return r.forEach(a=>{i=f(f({},i),a(n))}),e!==!1&&V(G),i},j={props:{blok:Object},setup(s){return(e,t)=>(h.openBlock(),h.createBlock(h.resolveDynamicComponent(s.blok.component),h.normalizeProps(h.guardReactiveProps(_(_({},e.$props),e.$attrs))),null,16))}},Q={beforeMount(s,e){if(e.value){const t=F(e.value);s.setAttribute("data-blok-c",t["data-blok-c"]),s.setAttribute("data-blok-uid",t["data-blok-uid"]),s.classList.add("storyblok__outline")}}},A=s=>{console.error(`You can't use ${s} if you're not loading apiPlugin. Please provide it on StoryblokVue initialization.
|
|
6
|
-
|
|
5
|
+
*/function E(n){return typeof n=="number"&&n==n&&n!==1/0&&n!==-1/0}function S(n,t,e){if(!E(t))throw new TypeError("Expected `limit` to be a finite number");if(!E(e))throw new TypeError("Expected `interval` to be a finite number");var r=[],s=[],o=0,i=function(){o++;var c=setTimeout(function(){o--,r.length>0&&i(),s=s.filter(function(h){return h!==c})},e);s.indexOf(c)<0&&s.push(c);var l=r.shift();l.resolve(n.apply(l.self,l.args))},a=function(){var c=arguments,l=this;return new Promise(function(h,k){r.push({resolve:h,reject:k,args:c,self:l}),o<t&&i()})};return a.abort=function(){s.forEach(clearTimeout),s=[],r.forEach(function(c){c.reject(new throttle.AbortError)}),r.length=0},a}S.AbortError=function(){Error.call(this,"Throttled function aborted"),this.name="AbortError"};const Y=function(n,t){if(!n)return null;let e={};for(let r in n){let s=n[r];t.indexOf(r)>-1&&s!==null&&(e[r]=s)}return e};var F={nodes:{horizontal_rule:()=>({singleTag:"hr"}),blockquote:()=>({tag:"blockquote"}),bullet_list:()=>({tag:"ul"}),code_block:n=>({tag:["pre",{tag:"code",attrs:n.attrs}]}),hard_break:()=>({singleTag:"br"}),heading:n=>({tag:`h${n.attrs.level}`}),image:n=>({singleTag:[{tag:"img",attrs:Y(n.attrs,["src","alt","title"])}]}),list_item:()=>({tag:"li"}),ordered_list:()=>({tag:"ol"}),paragraph:()=>({tag:"p"})},marks:{bold:()=>({tag:"b"}),strike:()=>({tag:"strike"}),underline:()=>({tag:"u"}),strong:()=>({tag:"strong"}),code:()=>({tag:"code"}),italic:()=>({tag:"i"}),link(n){const t=f({},n.attrs),{linktype:e="url"}=n.attrs;return e==="email"&&(t.href=`mailto:${t.href}`),t.anchor&&(t.href=`${t.href}#${t.anchor}`,delete t.anchor),{tag:[{tag:"a",attrs:t}]}},styled:n=>({tag:[{tag:"span",attrs:n.attrs}]})}};class G{constructor(t){t||(t=F),this.marks=t.marks||[],this.nodes=t.nodes||[]}addNode(t,e){this.nodes[t]=e}addMark(t,e){this.marks[t]=e}render(t={}){if(t.content&&Array.isArray(t.content)){let e="";return t.content.forEach(r=>{e+=this.renderNode(r)}),e}return console.warn("The render method must receive an object with a content field, which is an array"),""}renderNode(t){let e=[];t.marks&&t.marks.forEach(s=>{const o=this.getMatchingMark(s);o&&e.push(this.renderOpeningTag(o.tag))});const r=this.getMatchingNode(t);return r&&r.tag&&e.push(this.renderOpeningTag(r.tag)),t.content?t.content.forEach(s=>{e.push(this.renderNode(s))}):t.text?e.push(function(s){const o={"&":"&","<":"<",">":">",'"':""","'":"'"},i=/[&<>"']/g,a=RegExp(i.source);return s&&a.test(s)?s.replace(i,c=>o[c]):s}(t.text)):r&&r.singleTag?e.push(this.renderTag(r.singleTag," /")):r&&r.html&&e.push(r.html),r&&r.tag&&e.push(this.renderClosingTag(r.tag)),t.marks&&t.marks.slice(0).reverse().forEach(s=>{const o=this.getMatchingMark(s);o&&e.push(this.renderClosingTag(o.tag))}),e.join("")}renderTag(t,e){return t.constructor===String?`<${t}${e}>`:t.map(r=>{if(r.constructor===String)return`<${r}${e}>`;{let s=`<${r.tag}`;if(r.attrs)for(let o in r.attrs){let i=r.attrs[o];i!==null&&(s+=` ${o}="${i}"`)}return`${s}${e}>`}}).join("")}renderOpeningTag(t){return this.renderTag(t,"")}renderClosingTag(t){return t.constructor===String?`</${t}>`:t.slice(0).reverse().map(e=>e.constructor===String?`</${e}>`:`</${e.tag}>`).join("")}getMatchingNode(t){if(typeof this.nodes[t.type]=="function")return this.nodes[t.type](t)}getMatchingMark(t){if(typeof this.marks[t.type]=="function")return this.marks[t.type](t)}}const K=(n=0,t=n)=>{const e=Math.abs(t-n)||0,r=n<t?1:-1;return((s=0,o)=>[...Array(s)].map(o))(e,(s,o)=>o*r+n)},v=(n,t,e)=>{const r=[];for(const s in n){if(!Object.prototype.hasOwnProperty.call(n,s))continue;const o=n[s],i=e?"":encodeURIComponent(s);let a;a=typeof o=="object"?v(o,t?t+encodeURIComponent("["+i+"]"):i,Array.isArray(o)):(t?t+encodeURIComponent("["+i+"]"):i)+"="+encodeURIComponent(o),r.push(a)}return r.join("&")};let m={},g={};class Q{constructor(t,e){if(!e){let o=t.region?`-${t.region}`:"",i=t.https===!1?"http":"https";e=t.oauthToken===void 0?`${i}://api${o}.storyblok.com/v2`:`${i}://api${o}.storyblok.com/v1`}let r=Object.assign({},t.headers),s=5;t.oauthToken!==void 0&&(r.Authorization=t.oauthToken,s=3),t.rateLimit!==void 0&&(s=t.rateLimit),this.richTextResolver=new G(t.richTextSchema),typeof t.componentResolver=="function"&&this.setComponentResolver(t.componentResolver),this.maxRetries=t.maxRetries||5,this.throttle=S(this.throttledRequest,s,1e3),this.accessToken=t.accessToken,this.relations={},this.links={},this.cache=t.cache||{clear:"manual"},this.client=x.default.create({baseURL:e,timeout:t.timeout||0,headers:r,proxy:t.proxy||!1}),t.responseInterceptor&&this.client.interceptors.response.use(o=>t.responseInterceptor(o)),this.resolveNestedRelations=t.resolveNestedRelations||!0}setComponentResolver(t){this.richTextResolver.addNode("blok",e=>{let r="";return e.attrs.body.forEach(s=>{r+=t(s.component,s)}),{html:r}})}parseParams(t={}){return t.version||(t.version="published"),t.token||(t.token=this.getToken()),t.cv||(t.cv=g[t.token]),Array.isArray(t.resolve_relations)&&(t.resolve_relations=t.resolve_relations.join(",")),t}factoryParamOptions(t,e={}){return((r="")=>r.indexOf("/cdn/")>-1)(t)?this.parseParams(e):e}makeRequest(t,e,r,s){const o=this.factoryParamOptions(t,((i={},a=25,c=1)=>b(f({},i),{per_page:a,page:c}))(e,r,s));return this.cacheResponse(t,o)}get(t,e){let r=`/${t}`;const s=this.factoryParamOptions(r,e);return this.cacheResponse(r,s)}async getAll(t,e={},r){const s=e.per_page||25,o=`/${t}`,i=o.split("/");r=r||i[i.length-1];const a=await this.makeRequest(o,e,s,1),c=Math.ceil(a.total/s);return((l=[],h)=>l.map(h).reduce((k,at)=>[...k,...at],[]))([a,...await(async(l=[],h)=>Promise.all(l.map(h)))(K(1,c),async l=>this.makeRequest(o,e,s,l+1))],l=>Object.values(l.data[r]))}post(t,e){let r=`/${t}`;return this.throttle("post",r,e)}put(t,e){let r=`/${t}`;return this.throttle("put",r,e)}delete(t,e){let r=`/${t}`;return this.throttle("delete",r,e)}getStories(t){return this.get("cdn/stories",t)}getStory(t,e){return this.get(`cdn/stories/${t}`,e)}setToken(t){this.accessToken=t}getToken(){return this.accessToken}_cleanCopy(t){return JSON.parse(JSON.stringify(t))}_insertLinks(t,e){const r=t[e];r&&r.fieldtype=="multilink"&&r.linktype=="story"&&typeof r.id=="string"&&this.links[r.id]?r.story=this._cleanCopy(this.links[r.id]):r&&r.linktype==="story"&&typeof r.uuid=="string"&&this.links[r.uuid]&&(r.story=this._cleanCopy(this.links[r.uuid]))}_insertRelations(t,e,r){if(r.indexOf(t.component+"."+e)>-1){if(typeof t[e]=="string")this.relations[t[e]]&&(t[e]=this._cleanCopy(this.relations[t[e]]));else if(t[e].constructor===Array){let s=[];t[e].forEach(o=>{this.relations[o]&&s.push(this._cleanCopy(this.relations[o]))}),t[e]=s}}}_insertAssetsRelations(t,e){e.forEach(r=>{t.id===r.id&&(t.original=r,t.original.filename=t.filename,t.original.filename=t.original.filename.includes("https://s3.amazonaws.com/")?t.original.filename:t.original.filename.replace("https://","https://s3.amazonaws.com/"),delete t.original.s3_filename)})}iterateTree(t,e){let r=s=>{if(s!=null){if(s.constructor===Array)for(let o=0;o<s.length;o++)r(s[o]);else if(s.constructor===Object){if(s._stopResolving)return;for(let o in s)s.component&&s._uid||s.type==="link"?(this._insertRelations(s,o,e),this._insertLinks(s,o)):"id"in s&&s.fieldtype==="asset"&&this._insertAssetsRelations(s,e),r(s[o])}}};r(t.content)}async resolveLinks(t,e){let r=[];if(t.link_uuids){const s=t.link_uuids.length;let o=[];const i=50;for(let a=0;a<s;a+=i){const c=Math.min(s,a+i);o.push(t.link_uuids.slice(a,c))}for(let a=0;a<o.length;a++)(await this.getStories({per_page:i,language:e.language,version:e.version,by_uuids:o[a].join(",")})).data.stories.forEach(c=>{r.push(c)})}else r=t.links;r.forEach(s=>{this.links[s.uuid]=b(f({},s),{_stopResolving:!0})})}async resolveRelations(t,e){let r=[];if(t.rel_uuids){const s=t.rel_uuids.length;let o=[];const i=50;for(let a=0;a<s;a+=i){const c=Math.min(s,a+i);o.push(t.rel_uuids.slice(a,c))}for(let a=0;a<o.length;a++)(await this.getStories({per_page:i,language:e.language,version:e.version,by_uuids:o[a].join(",")})).data.stories.forEach(c=>{r.push(c)})}else r=t.rels;r.forEach(s=>{this.relations[s.uuid]=b(f({},s),{_stopResolving:!0})})}async resolveStories(t,e){let r=[];if(e.resolve_relations!==void 0&&e.resolve_relations.length>0&&(t.rels||t.rel_uuids)&&(r=e.resolve_relations.split(","),await this.resolveRelations(t,e)),["1","story","url"].indexOf(e.resolve_links)>-1&&(t.links||t.link_uuids)&&await this.resolveLinks(t,e),this.resolveNestedRelations)for(const s in this.relations)this.iterateTree(this.relations[s],r);t.story?this.iterateTree(t.story,r):t.stories.forEach(s=>{this.iterateTree(s,r)})}resolveAssetsRelations(t){const{assets:e,stories:r,story:s}=t;if(r)for(const o of r)this.iterateTree(o,e);else{if(!s)return t;this.iterateTree(s,e)}}cacheResponse(t,e,r){return r===void 0&&(r=0),new Promise(async(s,o)=>{let i=v({url:t,params:e}),a=this.cacheProvider();if(this.cache.clear==="auto"&&e.version==="draft"&&await this.flushCache(),e.version==="published"&&t!="/cdn/spaces/me"){const l=await a.get(i);if(l)return s(l)}try{let l=await this.throttle("get",t,{params:e,paramsSerializer:k=>v(k)}),h={data:l.data,headers:l.headers};if(h.data.assets&&h.data.assets.length&&this.resolveAssetsRelations(h.data),l.headers["per-page"]&&(h=Object.assign({},h,{perPage:parseInt(l.headers["per-page"]),total:parseInt(l.headers.total)})),l.status!=200)return o(l);(h.data.story||h.data.stories)&&await this.resolveStories(h.data,e),e.version==="published"&&t!="/cdn/spaces/me"&&a.set(i,h),h.data.cv&&(e.version=="draft"&&g[e.token]!=h.data.cv&&this.flushCache(),g[e.token]=h.data.cv),s(h)}catch(l){if(l.response&&l.response.status===429&&(r+=1)<this.maxRetries)return console.log(`Hit rate limit. Retrying in ${r} seconds.`),await(c=1e3*r,new Promise(h=>setTimeout(h,c))),this.cacheResponse(t,e,r).then(s).catch(o);o(l)}var c})}throttledRequest(t,e,r){return this.client[t](e,r)}cacheVersions(){return g}cacheVersion(){return g[this.accessToken]}setCacheVersion(t){this.accessToken&&(g[this.accessToken]=t)}cacheProvider(){return this.cache.type==="memory"?{get:t=>m[t],getAll:()=>m,set(t,e){m[t]=e},flush(){m={}}}:{get(){},getAll(){},set(){},flush(){}}}async flushCache(){return await this.cacheProvider().flush(),this}}const W=(n={})=>{const{apiOptions:t}=n;if(!t.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 Q(t)}};var X=n=>{if(typeof n!="object"||typeof n._editable=="undefined")return{};const t=JSON.parse(n._editable.replace(/^<!--#storyblok#/,"").replace(/-->$/,""));return{"data-blok-c":JSON.stringify(t),"data-blok-uid":t.id+"-"+t.uid}};const Z=new J,tt="https://app.storyblok.com/f/storyblok-v2-latest.js",O=(n,t,e={})=>{if(typeof window!="undefined"){if(typeof window.storyblokRegisterEvent=="undefined"){console.error("Storyblok Bridge is disabled. Please enable it to use it. Read https://github.com/storyblok/storyblok-js");return}if(!n){console.warn("Story ID is not defined. Please provide a valid ID.");return}window.storyblokRegisterEvent(()=>{new window.StoryblokBridge(e).on(["input","published","change"],s=>{s.action=="input"&&s.story.id===n?t(s.story):window.location.reload()})})}},et=(n={})=>{const{bridge:t,accessToken:e,use:r=[],apiOptions:s={}}=n;s.accessToken=s.accessToken||e;const o={bridge:t,apiOptions:s};let i={};return r.forEach(a=>{i=f(f({},i),a(o))}),t!==!1&&V(tt),i},rt=n=>n===""?"":n?Z.render(n):(console.warn(`${n} is not a valid Richtext object. This might be because the value of the richtext field is empty.
|
|
6
|
+
|
|
7
|
+
For more info about the richtext object check https://github.com/storyblok/storyblok-js#rendering-rich-text`),""),P=u.defineComponent({__name:"StoryblokComponent",props:{blok:null},setup(n){return(t,e)=>(u.openBlock(),u.createBlock(u.resolveDynamicComponent(n.blok.component),u.normalizeProps(u.guardReactiveProps(_(_({},t.$props),t.$attrs))),null,16))}}),st={beforeMount(n,t){if(t.value){const e=X(t.value);n.setAttribute("data-blok-c",e["data-blok-c"]),n.setAttribute("data-blok-uid",e["data-blok-uid"]),n.classList.add("storyblok__outline")}}},j=n=>{console.error(`You can't use ${n} if you're not loading apiPlugin. Please provide it on StoryblokVue initialization.
|
|
8
|
+
`)};let y=null;const nt=()=>(y||j("useStoryblokApi"),y),ot=async(n,t={},e={})=>{const r=u.ref(null);if(u.onMounted(()=>{r.value&&r.value.id&&O(r.value.id,s=>r.value=s,e)}),y){const{data:s}=await y.get(`cdn/stories/${n}`,t);r.value=s.story}else j("useStoryblok");return r},it={install(n,t={}){n.directive("editable",st),n.component("StoryblokComponent",P);const{storyblokApi:e}=et(t);y=e}};d.StoryblokComponent=P,d.StoryblokVue=it,d.apiPlugin=W,d.renderRichText=rt,d.useStoryblok=ot,d.useStoryblokApi=nt,d.useStoryblokBridge=O,Object.defineProperties(d,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|
package/dist/storyblok-vue.mjs
CHANGED
|
@@ -14,8 +14,8 @@ var __spreadValues = (a2, b) => {
|
|
|
14
14
|
}
|
|
15
15
|
return a2;
|
|
16
16
|
};
|
|
17
|
-
import { openBlock, createBlock, resolveDynamicComponent, normalizeProps, guardReactiveProps, ref, onMounted } from "vue";
|
|
18
|
-
import
|
|
17
|
+
import { defineComponent, openBlock, createBlock, resolveDynamicComponent, normalizeProps, guardReactiveProps, ref, onMounted } from "vue";
|
|
18
|
+
import e from "axios";
|
|
19
19
|
var __defProp2 = Object.defineProperty;
|
|
20
20
|
var __defProps = Object.defineProperties;
|
|
21
21
|
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
@@ -66,314 +66,596 @@ const loadBridge = (src) => {
|
|
|
66
66
|
document.getElementsByTagName("head")[0].appendChild(script);
|
|
67
67
|
});
|
|
68
68
|
};
|
|
69
|
+
const pick = function(attrs, allowed) {
|
|
70
|
+
if (!attrs) {
|
|
71
|
+
return null;
|
|
72
|
+
}
|
|
73
|
+
let h2 = {};
|
|
74
|
+
for (let key in attrs) {
|
|
75
|
+
let value = attrs[key];
|
|
76
|
+
if (allowed.indexOf(key) > -1 && value !== null) {
|
|
77
|
+
h2[key] = value;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
return h2;
|
|
81
|
+
};
|
|
82
|
+
const isEmailLinkType = (type) => type === "email";
|
|
83
|
+
var defaultHtmlSerializer = {
|
|
84
|
+
nodes: {
|
|
85
|
+
horizontal_rule() {
|
|
86
|
+
return {
|
|
87
|
+
singleTag: "hr"
|
|
88
|
+
};
|
|
89
|
+
},
|
|
90
|
+
blockquote() {
|
|
91
|
+
return {
|
|
92
|
+
tag: "blockquote"
|
|
93
|
+
};
|
|
94
|
+
},
|
|
95
|
+
bullet_list() {
|
|
96
|
+
return {
|
|
97
|
+
tag: "ul"
|
|
98
|
+
};
|
|
99
|
+
},
|
|
100
|
+
code_block(node) {
|
|
101
|
+
return {
|
|
102
|
+
tag: [
|
|
103
|
+
"pre",
|
|
104
|
+
{
|
|
105
|
+
tag: "code",
|
|
106
|
+
attrs: node.attrs
|
|
107
|
+
}
|
|
108
|
+
]
|
|
109
|
+
};
|
|
110
|
+
},
|
|
111
|
+
hard_break() {
|
|
112
|
+
return {
|
|
113
|
+
singleTag: "br"
|
|
114
|
+
};
|
|
115
|
+
},
|
|
116
|
+
heading(node) {
|
|
117
|
+
return {
|
|
118
|
+
tag: `h${node.attrs.level}`
|
|
119
|
+
};
|
|
120
|
+
},
|
|
121
|
+
image(node) {
|
|
122
|
+
return {
|
|
123
|
+
singleTag: [
|
|
124
|
+
{
|
|
125
|
+
tag: "img",
|
|
126
|
+
attrs: pick(node.attrs, ["src", "alt", "title"])
|
|
127
|
+
}
|
|
128
|
+
]
|
|
129
|
+
};
|
|
130
|
+
},
|
|
131
|
+
list_item() {
|
|
132
|
+
return {
|
|
133
|
+
tag: "li"
|
|
134
|
+
};
|
|
135
|
+
},
|
|
136
|
+
ordered_list() {
|
|
137
|
+
return {
|
|
138
|
+
tag: "ol"
|
|
139
|
+
};
|
|
140
|
+
},
|
|
141
|
+
paragraph() {
|
|
142
|
+
return {
|
|
143
|
+
tag: "p"
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
},
|
|
147
|
+
marks: {
|
|
148
|
+
bold() {
|
|
149
|
+
return {
|
|
150
|
+
tag: "b"
|
|
151
|
+
};
|
|
152
|
+
},
|
|
153
|
+
strike() {
|
|
154
|
+
return {
|
|
155
|
+
tag: "strike"
|
|
156
|
+
};
|
|
157
|
+
},
|
|
158
|
+
underline() {
|
|
159
|
+
return {
|
|
160
|
+
tag: "u"
|
|
161
|
+
};
|
|
162
|
+
},
|
|
163
|
+
strong() {
|
|
164
|
+
return {
|
|
165
|
+
tag: "strong"
|
|
166
|
+
};
|
|
167
|
+
},
|
|
168
|
+
code() {
|
|
169
|
+
return {
|
|
170
|
+
tag: "code"
|
|
171
|
+
};
|
|
172
|
+
},
|
|
173
|
+
italic() {
|
|
174
|
+
return {
|
|
175
|
+
tag: "i"
|
|
176
|
+
};
|
|
177
|
+
},
|
|
178
|
+
link(node) {
|
|
179
|
+
const attrs = __spreadValues2({}, node.attrs);
|
|
180
|
+
const { linktype = "url" } = node.attrs;
|
|
181
|
+
if (isEmailLinkType(linktype)) {
|
|
182
|
+
attrs.href = `mailto:${attrs.href}`;
|
|
183
|
+
}
|
|
184
|
+
if (attrs.anchor) {
|
|
185
|
+
attrs.href = `${attrs.href}#${attrs.anchor}`;
|
|
186
|
+
delete attrs.anchor;
|
|
187
|
+
}
|
|
188
|
+
return {
|
|
189
|
+
tag: [
|
|
190
|
+
{
|
|
191
|
+
tag: "a",
|
|
192
|
+
attrs
|
|
193
|
+
}
|
|
194
|
+
]
|
|
195
|
+
};
|
|
196
|
+
},
|
|
197
|
+
styled(node) {
|
|
198
|
+
return {
|
|
199
|
+
tag: [
|
|
200
|
+
{
|
|
201
|
+
tag: "span",
|
|
202
|
+
attrs: node.attrs
|
|
203
|
+
}
|
|
204
|
+
]
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
};
|
|
209
|
+
const escapeHTML = function(string) {
|
|
210
|
+
const htmlEscapes = {
|
|
211
|
+
"&": "&",
|
|
212
|
+
"<": "<",
|
|
213
|
+
">": ">",
|
|
214
|
+
'"': """,
|
|
215
|
+
"'": "'"
|
|
216
|
+
};
|
|
217
|
+
const reUnescapedHtml = /[&<>"']/g;
|
|
218
|
+
const reHasUnescapedHtml = RegExp(reUnescapedHtml.source);
|
|
219
|
+
return string && reHasUnescapedHtml.test(string) ? string.replace(reUnescapedHtml, (chr) => htmlEscapes[chr]) : string;
|
|
220
|
+
};
|
|
221
|
+
class RichTextResolver {
|
|
222
|
+
constructor(schema) {
|
|
223
|
+
if (!schema) {
|
|
224
|
+
schema = defaultHtmlSerializer;
|
|
225
|
+
}
|
|
226
|
+
this.marks = schema.marks || [];
|
|
227
|
+
this.nodes = schema.nodes || [];
|
|
228
|
+
}
|
|
229
|
+
addNode(key, schema) {
|
|
230
|
+
this.nodes[key] = schema;
|
|
231
|
+
}
|
|
232
|
+
addMark(key, schema) {
|
|
233
|
+
this.marks[key] = schema;
|
|
234
|
+
}
|
|
235
|
+
render(data = {}) {
|
|
236
|
+
if (data.content && Array.isArray(data.content)) {
|
|
237
|
+
let html = "";
|
|
238
|
+
data.content.forEach((node) => {
|
|
239
|
+
html += this.renderNode(node);
|
|
240
|
+
});
|
|
241
|
+
return html;
|
|
242
|
+
}
|
|
243
|
+
console.warn("The render method must receive an object with a content field, which is an array");
|
|
244
|
+
return "";
|
|
245
|
+
}
|
|
246
|
+
renderNode(item) {
|
|
247
|
+
let html = [];
|
|
248
|
+
if (item.marks) {
|
|
249
|
+
item.marks.forEach((m) => {
|
|
250
|
+
const mark = this.getMatchingMark(m);
|
|
251
|
+
if (mark) {
|
|
252
|
+
html.push(this.renderOpeningTag(mark.tag));
|
|
253
|
+
}
|
|
254
|
+
});
|
|
255
|
+
}
|
|
256
|
+
const node = this.getMatchingNode(item);
|
|
257
|
+
if (node && node.tag) {
|
|
258
|
+
html.push(this.renderOpeningTag(node.tag));
|
|
259
|
+
}
|
|
260
|
+
if (item.content) {
|
|
261
|
+
item.content.forEach((content) => {
|
|
262
|
+
html.push(this.renderNode(content));
|
|
263
|
+
});
|
|
264
|
+
} else if (item.text) {
|
|
265
|
+
html.push(escapeHTML(item.text));
|
|
266
|
+
} else if (node && node.singleTag) {
|
|
267
|
+
html.push(this.renderTag(node.singleTag, " /"));
|
|
268
|
+
} else if (node && node.html) {
|
|
269
|
+
html.push(node.html);
|
|
270
|
+
}
|
|
271
|
+
if (node && node.tag) {
|
|
272
|
+
html.push(this.renderClosingTag(node.tag));
|
|
273
|
+
}
|
|
274
|
+
if (item.marks) {
|
|
275
|
+
item.marks.slice(0).reverse().forEach((m) => {
|
|
276
|
+
const mark = this.getMatchingMark(m);
|
|
277
|
+
if (mark) {
|
|
278
|
+
html.push(this.renderClosingTag(mark.tag));
|
|
279
|
+
}
|
|
280
|
+
});
|
|
281
|
+
}
|
|
282
|
+
return html.join("");
|
|
283
|
+
}
|
|
284
|
+
renderTag(tags, ending) {
|
|
285
|
+
if (tags.constructor === String) {
|
|
286
|
+
return `<${tags}${ending}>`;
|
|
287
|
+
}
|
|
288
|
+
const all = tags.map((tag) => {
|
|
289
|
+
if (tag.constructor === String) {
|
|
290
|
+
return `<${tag}${ending}>`;
|
|
291
|
+
} else {
|
|
292
|
+
let h2 = `<${tag.tag}`;
|
|
293
|
+
if (tag.attrs) {
|
|
294
|
+
for (let key in tag.attrs) {
|
|
295
|
+
let value = tag.attrs[key];
|
|
296
|
+
if (value !== null) {
|
|
297
|
+
h2 += ` ${key}="${value}"`;
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
return `${h2}${ending}>`;
|
|
302
|
+
}
|
|
303
|
+
});
|
|
304
|
+
return all.join("");
|
|
305
|
+
}
|
|
306
|
+
renderOpeningTag(tags) {
|
|
307
|
+
return this.renderTag(tags, "");
|
|
308
|
+
}
|
|
309
|
+
renderClosingTag(tags) {
|
|
310
|
+
if (tags.constructor === String) {
|
|
311
|
+
return `</${tags}>`;
|
|
312
|
+
}
|
|
313
|
+
const all = tags.slice(0).reverse().map((tag) => {
|
|
314
|
+
if (tag.constructor === String) {
|
|
315
|
+
return `</${tag}>`;
|
|
316
|
+
} else {
|
|
317
|
+
return `</${tag.tag}>`;
|
|
318
|
+
}
|
|
319
|
+
});
|
|
320
|
+
return all.join("");
|
|
321
|
+
}
|
|
322
|
+
getMatchingNode(item) {
|
|
323
|
+
if (typeof this.nodes[item.type] !== "function") {
|
|
324
|
+
return;
|
|
325
|
+
}
|
|
326
|
+
return this.nodes[item.type](item);
|
|
327
|
+
}
|
|
328
|
+
getMatchingMark(item) {
|
|
329
|
+
if (typeof this.marks[item.type] !== "function") {
|
|
330
|
+
return;
|
|
331
|
+
}
|
|
332
|
+
return this.marks[item.type](item);
|
|
333
|
+
}
|
|
334
|
+
}
|
|
69
335
|
/*!
|
|
70
|
-
* storyblok-js-client
|
|
336
|
+
* storyblok-js-client v4.5.2
|
|
71
337
|
* Universal JavaScript SDK for Storyblok's API
|
|
72
338
|
* (c) 2020-2022 Stobylok Team
|
|
73
339
|
*/
|
|
74
|
-
function
|
|
75
|
-
return typeof
|
|
340
|
+
function t(e2) {
|
|
341
|
+
return typeof e2 == "number" && (e2 == e2 && e2 !== 1 / 0 && e2 !== -1 / 0);
|
|
76
342
|
}
|
|
77
|
-
function
|
|
78
|
-
if (!
|
|
343
|
+
function s(e2, s2, r2) {
|
|
344
|
+
if (!t(s2))
|
|
79
345
|
throw new TypeError("Expected `limit` to be a finite number");
|
|
80
|
-
if (!
|
|
346
|
+
if (!t(r2))
|
|
81
347
|
throw new TypeError("Expected `interval` to be a finite number");
|
|
82
|
-
var
|
|
348
|
+
var i2 = [], n2 = [], o2 = 0, a2 = function() {
|
|
83
349
|
o2++;
|
|
84
|
-
var
|
|
85
|
-
o2--,
|
|
86
|
-
return
|
|
350
|
+
var t2 = setTimeout(function() {
|
|
351
|
+
o2--, i2.length > 0 && a2(), n2 = n2.filter(function(e3) {
|
|
352
|
+
return e3 !== t2;
|
|
87
353
|
});
|
|
88
|
-
},
|
|
89
|
-
|
|
90
|
-
var
|
|
91
|
-
|
|
354
|
+
}, r2);
|
|
355
|
+
n2.indexOf(t2) < 0 && n2.push(t2);
|
|
356
|
+
var s3 = i2.shift();
|
|
357
|
+
s3.resolve(e2.apply(s3.self, s3.args));
|
|
92
358
|
}, l2 = function() {
|
|
93
|
-
var
|
|
94
|
-
return new Promise(function(
|
|
95
|
-
|
|
359
|
+
var e3 = arguments, t2 = this;
|
|
360
|
+
return new Promise(function(r3, n3) {
|
|
361
|
+
i2.push({ resolve: r3, reject: n3, args: e3, self: t2 }), o2 < s2 && a2();
|
|
96
362
|
});
|
|
97
363
|
};
|
|
98
364
|
return l2.abort = function() {
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
}),
|
|
365
|
+
n2.forEach(clearTimeout), n2 = [], i2.forEach(function(e3) {
|
|
366
|
+
e3.reject(new throttle.AbortError());
|
|
367
|
+
}), i2.length = 0;
|
|
102
368
|
}, l2;
|
|
103
369
|
}
|
|
104
|
-
|
|
370
|
+
s.AbortError = function() {
|
|
105
371
|
Error.call(this, "Throttled function aborted"), this.name = "AbortError";
|
|
106
372
|
};
|
|
107
|
-
const
|
|
108
|
-
if (!
|
|
373
|
+
const r = function(e2, t2) {
|
|
374
|
+
if (!e2)
|
|
109
375
|
return null;
|
|
110
|
-
let
|
|
111
|
-
for (let
|
|
112
|
-
let
|
|
113
|
-
|
|
376
|
+
let s2 = {};
|
|
377
|
+
for (let r2 in e2) {
|
|
378
|
+
let i2 = e2[r2];
|
|
379
|
+
t2.indexOf(r2) > -1 && i2 !== null && (s2[r2] = i2);
|
|
114
380
|
}
|
|
115
|
-
return
|
|
381
|
+
return s2;
|
|
116
382
|
};
|
|
117
|
-
var
|
|
118
|
-
const
|
|
119
|
-
return
|
|
120
|
-
}, styled: (
|
|
121
|
-
class
|
|
122
|
-
constructor(
|
|
123
|
-
|
|
124
|
-
}
|
|
125
|
-
addNode(
|
|
126
|
-
this.nodes[
|
|
127
|
-
}
|
|
128
|
-
addMark(
|
|
129
|
-
this.marks[
|
|
130
|
-
}
|
|
131
|
-
render(
|
|
132
|
-
if (
|
|
133
|
-
let
|
|
134
|
-
return
|
|
135
|
-
|
|
136
|
-
}),
|
|
383
|
+
var i = { nodes: { horizontal_rule: () => ({ singleTag: "hr" }), blockquote: () => ({ tag: "blockquote" }), bullet_list: () => ({ tag: "ul" }), code_block: (e2) => ({ tag: ["pre", { tag: "code", attrs: e2.attrs }] }), hard_break: () => ({ singleTag: "br" }), heading: (e2) => ({ tag: `h${e2.attrs.level}` }), image: (e2) => ({ singleTag: [{ tag: "img", attrs: r(e2.attrs, ["src", "alt", "title"]) }] }), list_item: () => ({ tag: "li" }), ordered_list: () => ({ tag: "ol" }), paragraph: () => ({ tag: "p" }) }, marks: { bold: () => ({ tag: "b" }), strike: () => ({ tag: "strike" }), underline: () => ({ tag: "u" }), strong: () => ({ tag: "strong" }), code: () => ({ tag: "code" }), italic: () => ({ tag: "i" }), link(e2) {
|
|
384
|
+
const t2 = __spreadValues2({}, e2.attrs), { linktype: s2 = "url" } = e2.attrs;
|
|
385
|
+
return s2 === "email" && (t2.href = `mailto:${t2.href}`), t2.anchor && (t2.href = `${t2.href}#${t2.anchor}`, delete t2.anchor), { tag: [{ tag: "a", attrs: t2 }] };
|
|
386
|
+
}, styled: (e2) => ({ tag: [{ tag: "span", attrs: e2.attrs }] }) } };
|
|
387
|
+
class n {
|
|
388
|
+
constructor(e2) {
|
|
389
|
+
e2 || (e2 = i), this.marks = e2.marks || [], this.nodes = e2.nodes || [];
|
|
390
|
+
}
|
|
391
|
+
addNode(e2, t2) {
|
|
392
|
+
this.nodes[e2] = t2;
|
|
393
|
+
}
|
|
394
|
+
addMark(e2, t2) {
|
|
395
|
+
this.marks[e2] = t2;
|
|
396
|
+
}
|
|
397
|
+
render(e2 = {}) {
|
|
398
|
+
if (e2.content && Array.isArray(e2.content)) {
|
|
399
|
+
let t2 = "";
|
|
400
|
+
return e2.content.forEach((e3) => {
|
|
401
|
+
t2 += this.renderNode(e3);
|
|
402
|
+
}), t2;
|
|
137
403
|
}
|
|
138
404
|
return console.warn("The render method must receive an object with a content field, which is an array"), "";
|
|
139
405
|
}
|
|
140
|
-
renderNode(
|
|
141
|
-
let
|
|
142
|
-
|
|
143
|
-
const
|
|
144
|
-
|
|
406
|
+
renderNode(e2) {
|
|
407
|
+
let t2 = [];
|
|
408
|
+
e2.marks && e2.marks.forEach((e3) => {
|
|
409
|
+
const s3 = this.getMatchingMark(e3);
|
|
410
|
+
s3 && t2.push(this.renderOpeningTag(s3.tag));
|
|
145
411
|
});
|
|
146
|
-
const
|
|
147
|
-
return
|
|
148
|
-
|
|
149
|
-
}) :
|
|
150
|
-
const
|
|
151
|
-
return
|
|
152
|
-
}(
|
|
153
|
-
const
|
|
154
|
-
|
|
155
|
-
}),
|
|
156
|
-
}
|
|
157
|
-
renderTag(
|
|
158
|
-
if (
|
|
159
|
-
return `<${
|
|
160
|
-
return
|
|
161
|
-
if (
|
|
162
|
-
return `<${
|
|
412
|
+
const s2 = this.getMatchingNode(e2);
|
|
413
|
+
return s2 && s2.tag && t2.push(this.renderOpeningTag(s2.tag)), e2.content ? e2.content.forEach((e3) => {
|
|
414
|
+
t2.push(this.renderNode(e3));
|
|
415
|
+
}) : e2.text ? t2.push(function(e3) {
|
|
416
|
+
const t3 = { "&": "&", "<": "<", ">": ">", '"': """, "'": "'" }, s3 = /[&<>"']/g, r2 = RegExp(s3.source);
|
|
417
|
+
return e3 && r2.test(e3) ? e3.replace(s3, (e4) => t3[e4]) : e3;
|
|
418
|
+
}(e2.text)) : s2 && s2.singleTag ? t2.push(this.renderTag(s2.singleTag, " /")) : s2 && s2.html && t2.push(s2.html), s2 && s2.tag && t2.push(this.renderClosingTag(s2.tag)), e2.marks && e2.marks.slice(0).reverse().forEach((e3) => {
|
|
419
|
+
const s3 = this.getMatchingMark(e3);
|
|
420
|
+
s3 && t2.push(this.renderClosingTag(s3.tag));
|
|
421
|
+
}), t2.join("");
|
|
422
|
+
}
|
|
423
|
+
renderTag(e2, t2) {
|
|
424
|
+
if (e2.constructor === String)
|
|
425
|
+
return `<${e2}${t2}>`;
|
|
426
|
+
return e2.map((e3) => {
|
|
427
|
+
if (e3.constructor === String)
|
|
428
|
+
return `<${e3}${t2}>`;
|
|
163
429
|
{
|
|
164
|
-
let
|
|
165
|
-
if (
|
|
166
|
-
for (let
|
|
167
|
-
let
|
|
168
|
-
|
|
430
|
+
let s2 = `<${e3.tag}`;
|
|
431
|
+
if (e3.attrs)
|
|
432
|
+
for (let t3 in e3.attrs) {
|
|
433
|
+
let r2 = e3.attrs[t3];
|
|
434
|
+
r2 !== null && (s2 += ` ${t3}="${r2}"`);
|
|
169
435
|
}
|
|
170
|
-
return `${
|
|
436
|
+
return `${s2}${t2}>`;
|
|
171
437
|
}
|
|
172
438
|
}).join("");
|
|
173
439
|
}
|
|
174
|
-
renderOpeningTag(
|
|
175
|
-
return this.renderTag(
|
|
440
|
+
renderOpeningTag(e2) {
|
|
441
|
+
return this.renderTag(e2, "");
|
|
176
442
|
}
|
|
177
|
-
renderClosingTag(
|
|
178
|
-
if (
|
|
179
|
-
return `</${
|
|
180
|
-
return
|
|
443
|
+
renderClosingTag(e2) {
|
|
444
|
+
if (e2.constructor === String)
|
|
445
|
+
return `</${e2}>`;
|
|
446
|
+
return e2.slice(0).reverse().map((e3) => e3.constructor === String ? `</${e3}>` : `</${e3.tag}>`).join("");
|
|
181
447
|
}
|
|
182
|
-
getMatchingNode(
|
|
183
|
-
if (typeof this.nodes[
|
|
184
|
-
return this.nodes[
|
|
448
|
+
getMatchingNode(e2) {
|
|
449
|
+
if (typeof this.nodes[e2.type] == "function")
|
|
450
|
+
return this.nodes[e2.type](e2);
|
|
185
451
|
}
|
|
186
|
-
getMatchingMark(
|
|
187
|
-
if (typeof this.marks[
|
|
188
|
-
return this.marks[
|
|
452
|
+
getMatchingMark(e2) {
|
|
453
|
+
if (typeof this.marks[e2.type] == "function")
|
|
454
|
+
return this.marks[e2.type](e2);
|
|
189
455
|
}
|
|
190
456
|
}
|
|
191
|
-
const o = (
|
|
192
|
-
const
|
|
193
|
-
return ((
|
|
194
|
-
}, a = (
|
|
195
|
-
const
|
|
196
|
-
for (const
|
|
197
|
-
if (!Object.prototype.hasOwnProperty.call(
|
|
457
|
+
const o = (e2 = 0, t2 = e2) => {
|
|
458
|
+
const s2 = Math.abs(t2 - e2) || 0, r2 = e2 < t2 ? 1 : -1;
|
|
459
|
+
return ((e3 = 0, t3) => [...Array(e3)].map(t3))(s2, (t3, s3) => s3 * r2 + e2);
|
|
460
|
+
}, a = (e2, t2, s2) => {
|
|
461
|
+
const r2 = [];
|
|
462
|
+
for (const i2 in e2) {
|
|
463
|
+
if (!Object.prototype.hasOwnProperty.call(e2, i2))
|
|
198
464
|
continue;
|
|
199
|
-
const
|
|
465
|
+
const n2 = e2[i2], o2 = s2 ? "" : encodeURIComponent(i2);
|
|
200
466
|
let l2;
|
|
201
|
-
l2 = typeof
|
|
467
|
+
l2 = typeof n2 == "object" ? a(n2, t2 ? t2 + encodeURIComponent("[" + o2 + "]") : o2, Array.isArray(n2)) : (t2 ? t2 + encodeURIComponent("[" + o2 + "]") : o2) + "=" + encodeURIComponent(n2), r2.push(l2);
|
|
202
468
|
}
|
|
203
|
-
return
|
|
469
|
+
return r2.join("&");
|
|
204
470
|
};
|
|
205
471
|
let l = {}, c = {};
|
|
206
|
-
class
|
|
207
|
-
constructor(
|
|
208
|
-
if (!
|
|
209
|
-
let
|
|
210
|
-
|
|
472
|
+
class h {
|
|
473
|
+
constructor(t2, r2) {
|
|
474
|
+
if (!r2) {
|
|
475
|
+
let e2 = t2.region ? `-${t2.region}` : "", s2 = t2.https === false ? "http" : "https";
|
|
476
|
+
r2 = t2.oauthToken === void 0 ? `${s2}://api${e2}.storyblok.com/v2` : `${s2}://api${e2}.storyblok.com/v1`;
|
|
211
477
|
}
|
|
212
|
-
let
|
|
213
|
-
|
|
214
|
-
}
|
|
215
|
-
setComponentResolver(
|
|
216
|
-
this.richTextResolver.addNode("blok", (
|
|
217
|
-
let
|
|
218
|
-
return
|
|
219
|
-
|
|
220
|
-
}), { html:
|
|
478
|
+
let i2 = Object.assign({}, t2.headers), o2 = 5;
|
|
479
|
+
t2.oauthToken !== void 0 && (i2.Authorization = t2.oauthToken, o2 = 3), t2.rateLimit !== void 0 && (o2 = t2.rateLimit), this.richTextResolver = new n(t2.richTextSchema), typeof t2.componentResolver == "function" && this.setComponentResolver(t2.componentResolver), this.maxRetries = t2.maxRetries || 5, this.throttle = s(this.throttledRequest, o2, 1e3), this.accessToken = t2.accessToken, this.relations = {}, this.links = {}, this.cache = t2.cache || { clear: "manual" }, this.client = e.create({ baseURL: r2, timeout: t2.timeout || 0, headers: i2, proxy: t2.proxy || false }), t2.responseInterceptor && this.client.interceptors.response.use((e2) => t2.responseInterceptor(e2)), this.resolveNestedRelations = t2.resolveNestedRelations || true;
|
|
480
|
+
}
|
|
481
|
+
setComponentResolver(e2) {
|
|
482
|
+
this.richTextResolver.addNode("blok", (t2) => {
|
|
483
|
+
let s2 = "";
|
|
484
|
+
return t2.attrs.body.forEach((t3) => {
|
|
485
|
+
s2 += e2(t3.component, t3);
|
|
486
|
+
}), { html: s2 };
|
|
221
487
|
});
|
|
222
488
|
}
|
|
223
|
-
parseParams(
|
|
224
|
-
return
|
|
489
|
+
parseParams(e2 = {}) {
|
|
490
|
+
return e2.version || (e2.version = "published"), e2.token || (e2.token = this.getToken()), e2.cv || (e2.cv = c[e2.token]), Array.isArray(e2.resolve_relations) && (e2.resolve_relations = e2.resolve_relations.join(",")), e2;
|
|
225
491
|
}
|
|
226
|
-
factoryParamOptions(
|
|
227
|
-
return ((
|
|
492
|
+
factoryParamOptions(e2, t2 = {}) {
|
|
493
|
+
return ((e3 = "") => e3.indexOf("/cdn/") > -1)(e2) ? this.parseParams(t2) : t2;
|
|
228
494
|
}
|
|
229
|
-
makeRequest(t2,
|
|
230
|
-
const
|
|
231
|
-
return this.cacheResponse(
|
|
495
|
+
makeRequest(e2, t2, s2, r2) {
|
|
496
|
+
const i2 = this.factoryParamOptions(e2, ((e3 = {}, t3 = 25, s3 = 1) => __spreadProps(__spreadValues2({}, e3), { per_page: t3, page: s3 }))(t2, s2, r2));
|
|
497
|
+
return this.cacheResponse(e2, i2);
|
|
232
498
|
}
|
|
233
|
-
get(
|
|
234
|
-
let
|
|
235
|
-
const
|
|
236
|
-
return this.cacheResponse(
|
|
499
|
+
get(e2, t2) {
|
|
500
|
+
let s2 = `/${e2}`;
|
|
501
|
+
const r2 = this.factoryParamOptions(s2, t2);
|
|
502
|
+
return this.cacheResponse(s2, r2);
|
|
237
503
|
}
|
|
238
|
-
async getAll(
|
|
239
|
-
const
|
|
240
|
-
|
|
241
|
-
const a2 = await this.makeRequest(
|
|
242
|
-
return ((
|
|
504
|
+
async getAll(e2, t2 = {}, s2) {
|
|
505
|
+
const r2 = t2.per_page || 25, i2 = `/${e2}`, n2 = i2.split("/");
|
|
506
|
+
s2 = s2 || n2[n2.length - 1];
|
|
507
|
+
const a2 = await this.makeRequest(i2, t2, r2, 1), l2 = Math.ceil(a2.total / r2);
|
|
508
|
+
return ((e3 = [], t3) => e3.map(t3).reduce((e4, t4) => [...e4, ...t4], []))([a2, ...await (async (e3 = [], t3) => Promise.all(e3.map(t3)))(o(1, l2), async (e3) => this.makeRequest(i2, t2, r2, e3 + 1))], (e3) => Object.values(e3.data[s2]));
|
|
243
509
|
}
|
|
244
|
-
post(
|
|
245
|
-
let
|
|
246
|
-
return this.throttle("post",
|
|
510
|
+
post(e2, t2) {
|
|
511
|
+
let s2 = `/${e2}`;
|
|
512
|
+
return this.throttle("post", s2, t2);
|
|
247
513
|
}
|
|
248
|
-
put(
|
|
249
|
-
let
|
|
250
|
-
return this.throttle("put",
|
|
514
|
+
put(e2, t2) {
|
|
515
|
+
let s2 = `/${e2}`;
|
|
516
|
+
return this.throttle("put", s2, t2);
|
|
251
517
|
}
|
|
252
|
-
delete(
|
|
253
|
-
let
|
|
254
|
-
return this.throttle("delete",
|
|
518
|
+
delete(e2, t2) {
|
|
519
|
+
let s2 = `/${e2}`;
|
|
520
|
+
return this.throttle("delete", s2, t2);
|
|
255
521
|
}
|
|
256
|
-
getStories(
|
|
257
|
-
return this.get("cdn/stories",
|
|
522
|
+
getStories(e2) {
|
|
523
|
+
return this.get("cdn/stories", e2);
|
|
258
524
|
}
|
|
259
|
-
getStory(
|
|
260
|
-
return this.get(
|
|
525
|
+
getStory(e2, t2) {
|
|
526
|
+
return this.get(`cdn/stories/${e2}`, t2);
|
|
261
527
|
}
|
|
262
|
-
setToken(
|
|
263
|
-
this.accessToken =
|
|
528
|
+
setToken(e2) {
|
|
529
|
+
this.accessToken = e2;
|
|
264
530
|
}
|
|
265
531
|
getToken() {
|
|
266
532
|
return this.accessToken;
|
|
267
533
|
}
|
|
268
|
-
_cleanCopy(
|
|
269
|
-
return JSON.parse(JSON.stringify(
|
|
270
|
-
}
|
|
271
|
-
_insertLinks(
|
|
272
|
-
const
|
|
273
|
-
|
|
274
|
-
}
|
|
275
|
-
_insertRelations(
|
|
276
|
-
if (
|
|
277
|
-
if (typeof t2
|
|
278
|
-
this.relations[t2
|
|
279
|
-
else if (t2
|
|
280
|
-
let
|
|
281
|
-
t2
|
|
282
|
-
this.relations[
|
|
283
|
-
}), t2
|
|
534
|
+
_cleanCopy(e2) {
|
|
535
|
+
return JSON.parse(JSON.stringify(e2));
|
|
536
|
+
}
|
|
537
|
+
_insertLinks(e2, t2) {
|
|
538
|
+
const s2 = e2[t2];
|
|
539
|
+
s2 && s2.fieldtype == "multilink" && s2.linktype == "story" && typeof s2.id == "string" && this.links[s2.id] ? s2.story = this._cleanCopy(this.links[s2.id]) : s2 && s2.linktype === "story" && typeof s2.uuid == "string" && this.links[s2.uuid] && (s2.story = this._cleanCopy(this.links[s2.uuid]));
|
|
540
|
+
}
|
|
541
|
+
_insertRelations(e2, t2, s2) {
|
|
542
|
+
if (s2.indexOf(e2.component + "." + t2) > -1) {
|
|
543
|
+
if (typeof e2[t2] == "string")
|
|
544
|
+
this.relations[e2[t2]] && (e2[t2] = this._cleanCopy(this.relations[e2[t2]]));
|
|
545
|
+
else if (e2[t2].constructor === Array) {
|
|
546
|
+
let s3 = [];
|
|
547
|
+
e2[t2].forEach((e3) => {
|
|
548
|
+
this.relations[e3] && s3.push(this._cleanCopy(this.relations[e3]));
|
|
549
|
+
}), e2[t2] = s3;
|
|
284
550
|
}
|
|
285
551
|
}
|
|
286
552
|
}
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
553
|
+
_insertAssetsRelations(e2, t2) {
|
|
554
|
+
t2.forEach((t3) => {
|
|
555
|
+
e2.id === t3.id && (e2.original = t3, e2.original.filename = e2.filename, e2.original.filename = e2.original.filename.includes("https://s3.amazonaws.com/") ? e2.original.filename : e2.original.filename.replace("https://", "https://s3.amazonaws.com/"), delete e2.original.s3_filename);
|
|
556
|
+
});
|
|
557
|
+
}
|
|
558
|
+
iterateTree(e2, t2) {
|
|
559
|
+
let s2 = (e3) => {
|
|
560
|
+
if (e3 != null) {
|
|
561
|
+
if (e3.constructor === Array)
|
|
562
|
+
for (let t3 = 0; t3 < e3.length; t3++)
|
|
563
|
+
s2(e3[t3]);
|
|
564
|
+
else if (e3.constructor === Object) {
|
|
565
|
+
if (e3._stopResolving)
|
|
295
566
|
return;
|
|
296
|
-
for (let
|
|
297
|
-
|
|
567
|
+
for (let r2 in e3)
|
|
568
|
+
e3.component && e3._uid || e3.type === "link" ? (this._insertRelations(e3, r2, t2), this._insertLinks(e3, r2)) : "id" in e3 && e3.fieldtype === "asset" && this._insertAssetsRelations(e3, t2), s2(e3[r2]);
|
|
298
569
|
}
|
|
299
570
|
}
|
|
300
571
|
};
|
|
301
|
-
|
|
302
|
-
}
|
|
303
|
-
async resolveLinks(
|
|
304
|
-
let
|
|
305
|
-
if (
|
|
306
|
-
const
|
|
307
|
-
let
|
|
308
|
-
const
|
|
309
|
-
for (let
|
|
310
|
-
const
|
|
311
|
-
|
|
572
|
+
s2(e2.content);
|
|
573
|
+
}
|
|
574
|
+
async resolveLinks(e2, t2) {
|
|
575
|
+
let s2 = [];
|
|
576
|
+
if (e2.link_uuids) {
|
|
577
|
+
const r2 = e2.link_uuids.length;
|
|
578
|
+
let i2 = [];
|
|
579
|
+
const n2 = 50;
|
|
580
|
+
for (let t3 = 0; t3 < r2; t3 += n2) {
|
|
581
|
+
const s3 = Math.min(r2, t3 + n2);
|
|
582
|
+
i2.push(e2.link_uuids.slice(t3, s3));
|
|
312
583
|
}
|
|
313
|
-
for (let
|
|
314
|
-
(await this.getStories({ per_page:
|
|
315
|
-
|
|
584
|
+
for (let e3 = 0; e3 < i2.length; e3++) {
|
|
585
|
+
(await this.getStories({ per_page: n2, language: t2.language, version: t2.version, by_uuids: i2[e3].join(",") })).data.stories.forEach((e4) => {
|
|
586
|
+
s2.push(e4);
|
|
316
587
|
});
|
|
317
588
|
}
|
|
318
589
|
} else
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
this.links[
|
|
590
|
+
s2 = e2.links;
|
|
591
|
+
s2.forEach((e3) => {
|
|
592
|
+
this.links[e3.uuid] = __spreadProps(__spreadValues2({}, e3), { _stopResolving: true });
|
|
322
593
|
});
|
|
323
594
|
}
|
|
324
|
-
async resolveRelations(
|
|
325
|
-
let
|
|
326
|
-
if (
|
|
327
|
-
const
|
|
328
|
-
let
|
|
329
|
-
const
|
|
330
|
-
for (let
|
|
331
|
-
const
|
|
332
|
-
|
|
595
|
+
async resolveRelations(e2, t2) {
|
|
596
|
+
let s2 = [];
|
|
597
|
+
if (e2.rel_uuids) {
|
|
598
|
+
const r2 = e2.rel_uuids.length;
|
|
599
|
+
let i2 = [];
|
|
600
|
+
const n2 = 50;
|
|
601
|
+
for (let t3 = 0; t3 < r2; t3 += n2) {
|
|
602
|
+
const s3 = Math.min(r2, t3 + n2);
|
|
603
|
+
i2.push(e2.rel_uuids.slice(t3, s3));
|
|
333
604
|
}
|
|
334
|
-
for (let
|
|
335
|
-
(await this.getStories({ per_page:
|
|
336
|
-
|
|
605
|
+
for (let e3 = 0; e3 < i2.length; e3++) {
|
|
606
|
+
(await this.getStories({ per_page: n2, language: t2.language, version: t2.version, by_uuids: i2[e3].join(",") })).data.stories.forEach((e4) => {
|
|
607
|
+
s2.push(e4);
|
|
337
608
|
});
|
|
338
609
|
}
|
|
339
610
|
} else
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
this.relations[
|
|
611
|
+
s2 = e2.rels;
|
|
612
|
+
s2.forEach((e3) => {
|
|
613
|
+
this.relations[e3.uuid] = __spreadProps(__spreadValues2({}, e3), { _stopResolving: true });
|
|
343
614
|
});
|
|
344
615
|
}
|
|
345
|
-
async resolveStories(
|
|
346
|
-
let
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
this.iterateTree(
|
|
616
|
+
async resolveStories(e2, t2) {
|
|
617
|
+
let s2 = [];
|
|
618
|
+
if (t2.resolve_relations !== void 0 && t2.resolve_relations.length > 0 && (e2.rels || e2.rel_uuids) && (s2 = t2.resolve_relations.split(","), await this.resolveRelations(e2, t2)), ["1", "story", "url"].indexOf(t2.resolve_links) > -1 && (e2.links || e2.link_uuids) && await this.resolveLinks(e2, t2), this.resolveNestedRelations)
|
|
619
|
+
for (const e3 in this.relations)
|
|
620
|
+
this.iterateTree(this.relations[e3], s2);
|
|
621
|
+
e2.story ? this.iterateTree(e2.story, s2) : e2.stories.forEach((e3) => {
|
|
622
|
+
this.iterateTree(e3, s2);
|
|
352
623
|
});
|
|
353
624
|
}
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
625
|
+
resolveAssetsRelations(e2) {
|
|
626
|
+
const { assets: t2, stories: s2, story: r2 } = e2;
|
|
627
|
+
if (s2)
|
|
628
|
+
for (const e3 of s2)
|
|
629
|
+
this.iterateTree(e3, t2);
|
|
630
|
+
else {
|
|
631
|
+
if (!r2)
|
|
632
|
+
return e2;
|
|
633
|
+
this.iterateTree(r2, t2);
|
|
634
|
+
}
|
|
635
|
+
}
|
|
636
|
+
cacheResponse(e2, t2, s2) {
|
|
637
|
+
return s2 === void 0 && (s2 = 0), new Promise(async (r2, i2) => {
|
|
638
|
+
let n2 = a({ url: e2, params: t2 }), o2 = this.cacheProvider();
|
|
639
|
+
if (this.cache.clear === "auto" && t2.version === "draft" && await this.flushCache(), t2.version === "published" && e2 != "/cdn/spaces/me") {
|
|
640
|
+
const e3 = await o2.get(n2);
|
|
641
|
+
if (e3)
|
|
642
|
+
return r2(e3);
|
|
361
643
|
}
|
|
362
644
|
try {
|
|
363
|
-
let
|
|
364
|
-
if (
|
|
365
|
-
return
|
|
366
|
-
(l3.data.story || l3.data.stories) && await this.resolveStories(l3.data,
|
|
367
|
-
} catch (
|
|
368
|
-
if (
|
|
369
|
-
return console.log(`Hit rate limit. Retrying in ${
|
|
370
|
-
|
|
645
|
+
let s3 = await this.throttle("get", e2, { params: t2, paramsSerializer: (e3) => a(e3) }), l3 = { data: s3.data, headers: s3.headers };
|
|
646
|
+
if (l3.data.assets && l3.data.assets.length && this.resolveAssetsRelations(l3.data), s3.headers["per-page"] && (l3 = Object.assign({}, l3, { perPage: parseInt(s3.headers["per-page"]), total: parseInt(s3.headers.total) })), s3.status != 200)
|
|
647
|
+
return i2(s3);
|
|
648
|
+
(l3.data.story || l3.data.stories) && await this.resolveStories(l3.data, t2), t2.version === "published" && e2 != "/cdn/spaces/me" && o2.set(n2, l3), l3.data.cv && (t2.version == "draft" && c[t2.token] != l3.data.cv && this.flushCache(), c[t2.token] = l3.data.cv), r2(l3);
|
|
649
|
+
} catch (n3) {
|
|
650
|
+
if (n3.response && n3.response.status === 429 && (s2 += 1) < this.maxRetries)
|
|
651
|
+
return console.log(`Hit rate limit. Retrying in ${s2} seconds.`), await (l2 = 1e3 * s2, new Promise((e3) => setTimeout(e3, l2))), this.cacheResponse(e2, t2, s2).then(r2).catch(i2);
|
|
652
|
+
i2(n3);
|
|
371
653
|
}
|
|
372
654
|
var l2;
|
|
373
655
|
});
|
|
374
656
|
}
|
|
375
|
-
throttledRequest(
|
|
376
|
-
return this.client[
|
|
657
|
+
throttledRequest(e2, t2, s2) {
|
|
658
|
+
return this.client[e2](t2, s2);
|
|
377
659
|
}
|
|
378
660
|
cacheVersions() {
|
|
379
661
|
return c;
|
|
@@ -381,36 +663,31 @@ class StoryblokClient {
|
|
|
381
663
|
cacheVersion() {
|
|
382
664
|
return c[this.accessToken];
|
|
383
665
|
}
|
|
384
|
-
setCacheVersion(
|
|
385
|
-
this.accessToken && (c[this.accessToken] =
|
|
666
|
+
setCacheVersion(e2) {
|
|
667
|
+
this.accessToken && (c[this.accessToken] = e2);
|
|
386
668
|
}
|
|
387
669
|
cacheProvider() {
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
}, getAll() {
|
|
398
|
-
}, set() {
|
|
399
|
-
}, flush() {
|
|
400
|
-
} };
|
|
401
|
-
}
|
|
670
|
+
return this.cache.type === "memory" ? { get: (e2) => l[e2], getAll: () => l, set(e2, t2) {
|
|
671
|
+
l[e2] = t2;
|
|
672
|
+
}, flush() {
|
|
673
|
+
l = {};
|
|
674
|
+
} } : { get() {
|
|
675
|
+
}, getAll() {
|
|
676
|
+
}, set() {
|
|
677
|
+
}, flush() {
|
|
678
|
+
} };
|
|
402
679
|
}
|
|
403
680
|
async flushCache() {
|
|
404
681
|
return await this.cacheProvider().flush(), this;
|
|
405
682
|
}
|
|
406
683
|
}
|
|
407
|
-
|
|
684
|
+
const apiFactory = (options = {}) => {
|
|
408
685
|
const { apiOptions } = options;
|
|
409
686
|
if (!apiOptions.accessToken) {
|
|
410
687
|
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");
|
|
411
688
|
return;
|
|
412
689
|
}
|
|
413
|
-
const storyblokApi = new
|
|
690
|
+
const storyblokApi = new h(apiOptions);
|
|
414
691
|
return { storyblokApi };
|
|
415
692
|
};
|
|
416
693
|
var editable = (blok) => {
|
|
@@ -423,6 +700,7 @@ var editable = (blok) => {
|
|
|
423
700
|
"data-blok-uid": options.id + "-" + options.uid
|
|
424
701
|
};
|
|
425
702
|
};
|
|
703
|
+
const resolver = new RichTextResolver();
|
|
426
704
|
const bridgeLatest = "https://app.storyblok.com/f/storyblok-v2-latest.js";
|
|
427
705
|
const useStoryblokBridge = (id, cb, options = {}) => {
|
|
428
706
|
if (typeof window === "undefined") {
|
|
@@ -460,14 +738,28 @@ const storyblokInit = (pluginOptions = {}) => {
|
|
|
460
738
|
}
|
|
461
739
|
return result;
|
|
462
740
|
};
|
|
463
|
-
const
|
|
464
|
-
|
|
741
|
+
const renderRichText = (text) => {
|
|
742
|
+
if (text === "") {
|
|
743
|
+
return "";
|
|
744
|
+
} else if (!text) {
|
|
745
|
+
console.warn(`${text} is not a valid Richtext object. This might be because the value of the richtext field is empty.
|
|
746
|
+
|
|
747
|
+
For more info about the richtext object check https://github.com/storyblok/storyblok-js#rendering-rich-text`);
|
|
748
|
+
return "";
|
|
749
|
+
}
|
|
750
|
+
return resolver.render(text);
|
|
751
|
+
};
|
|
752
|
+
const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
753
|
+
__name: "StoryblokComponent",
|
|
754
|
+
props: {
|
|
755
|
+
blok: null
|
|
756
|
+
},
|
|
465
757
|
setup(__props) {
|
|
466
758
|
return (_ctx, _cache) => {
|
|
467
759
|
return openBlock(), createBlock(resolveDynamicComponent(__props.blok.component), normalizeProps(guardReactiveProps(__spreadValues(__spreadValues({}, _ctx.$props), _ctx.$attrs))), null, 16);
|
|
468
760
|
};
|
|
469
761
|
}
|
|
470
|
-
};
|
|
762
|
+
});
|
|
471
763
|
const vEditableDirective = {
|
|
472
764
|
beforeMount(el, binding) {
|
|
473
765
|
if (binding.value) {
|
|
@@ -510,4 +802,4 @@ const StoryblokVue = {
|
|
|
510
802
|
storyblokApiInstance = storyblokApi;
|
|
511
803
|
}
|
|
512
804
|
};
|
|
513
|
-
export { _sfc_main as StoryblokComponent, StoryblokVue,
|
|
805
|
+
export { _sfc_main as StoryblokComponent, StoryblokVue, apiFactory as apiPlugin, renderRichText, useStoryblok, useStoryblokApi, useStoryblokBridge };
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type StoryblokComponent from "./StoryblokComponent.vue";
|
|
2
|
+
declare module "@vue/runtime-core" {
|
|
3
|
+
interface GlobalComponents {
|
|
4
|
+
StoryblokComponent: typeof StoryblokComponent;
|
|
5
|
+
}
|
|
6
|
+
}
|
|
7
|
+
export type { AlternateObject, Richtext, RichtextInstance, SbBlokData, SbBlokKeyDataTypes, SbSDKOptions, Stories, StoriesParams, Story, StoryData, StoryParams, StoryblokBridgeConfigV2, StoryblokBridgeV2, StoryblokCache, StoryblokCacheProvider, StoryblokComponentType, StoryblokClient, StoryblokConfig, StoryblokManagmentApiResult, StoryblokResult, apiPlugin, useStoryblokBridge, } from "@storyblok/js";
|
package/package.json
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@storyblok/vue",
|
|
3
|
-
"version": "6.0
|
|
3
|
+
"version": "6.2.0",
|
|
4
4
|
"description": "Storyblok directive for get editable elements.",
|
|
5
5
|
"main": "./dist/storyblok-vue.js",
|
|
6
6
|
"module": "./dist/storyblok-vue.mjs",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
7
8
|
"files": [
|
|
8
9
|
"dist"
|
|
9
10
|
],
|
|
@@ -15,7 +16,7 @@
|
|
|
15
16
|
},
|
|
16
17
|
"scripts": {
|
|
17
18
|
"dev": "vite build --watch",
|
|
18
|
-
"build": "vite build",
|
|
19
|
+
"build": "vite build && vue-tsc --declaration --emitDeclarationOnly",
|
|
19
20
|
"test": "npm run test:unit && npm run test:e2e",
|
|
20
21
|
"test:unit": "jest __tests__",
|
|
21
22
|
"test:e2e": "cypress run-ct",
|
|
@@ -23,23 +24,26 @@
|
|
|
23
24
|
"prepublishOnly": "npm run build && cp ../README.md ./"
|
|
24
25
|
},
|
|
25
26
|
"dependencies": {
|
|
26
|
-
"@storyblok/js": "^1.
|
|
27
|
+
"@storyblok/js": "^1.7.0"
|
|
27
28
|
},
|
|
28
29
|
"devDependencies": {
|
|
29
|
-
"@babel/core": "^7.
|
|
30
|
+
"@babel/core": "^7.18.5",
|
|
30
31
|
"@cypress/vite-dev-server": "^2.0.7",
|
|
31
|
-
"@cypress/vue": "^3.
|
|
32
|
-
"@vitejs/plugin-vue": "^2.3.
|
|
32
|
+
"@cypress/vue": "^3.1.2",
|
|
33
|
+
"@vitejs/plugin-vue": "^2.3.3",
|
|
33
34
|
"@vue/babel-preset-app": "^5.0.4",
|
|
34
35
|
"@vue/test-utils": "next",
|
|
35
|
-
"
|
|
36
|
-
"
|
|
36
|
+
"@vue/tsconfig": "^0.1.3",
|
|
37
|
+
"babel-jest": "^26.0.0",
|
|
38
|
+
"cypress": "^9.6.0",
|
|
37
39
|
"eslint-plugin-cypress": "^2.12.1",
|
|
38
|
-
"eslint-plugin-jest": "^26.1.
|
|
39
|
-
"jest": "^
|
|
40
|
-
"
|
|
41
|
-
"
|
|
42
|
-
"vue
|
|
40
|
+
"eslint-plugin-jest": "^26.1.5",
|
|
41
|
+
"jest": "^28.1.3",
|
|
42
|
+
"typescript": "^4.7.3",
|
|
43
|
+
"vite": "^2.9.9",
|
|
44
|
+
"vue": "^3.2.33",
|
|
45
|
+
"vue-jest": "next",
|
|
46
|
+
"vue-tsc": "^0.37.9"
|
|
43
47
|
},
|
|
44
48
|
"babel": {
|
|
45
49
|
"presets": [
|