@storyblok/vue 6.0.4 → 6.1.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 +4 -4
- package/dist/storyblok-vue.mjs +10 -7
- package/dist/types.d.ts +7 -0
- package/package.json +10 -6
|
@@ -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 } 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,6 @@
|
|
|
1
|
-
(function(
|
|
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 et=Object.defineProperty;var j=Object.getOwnPropertySymbols;var rt=Object.prototype.hasOwnProperty,st=Object.prototype.propertyIsEnumerable;var C=(d,u,p)=>u in d?et(d,u,{enumerable:!0,configurable:!0,writable:!0,value:p}):d[u]=p,_=(d,u)=>{for(var p in u||(u={}))rt.call(u,p)&&C(d,p,u[p]);if(j)for(var p of j(u))st.call(u,p)&&C(d,p,u[p]);return d};function M(o){return o&&typeof o=="object"&&"default"in o?o:{default:o}}var x=M(p),I=Object.defineProperty,N=Object.defineProperties,B=Object.getOwnPropertyDescriptors,w=Object.getOwnPropertySymbols,q=Object.prototype.hasOwnProperty,L=Object.prototype.propertyIsEnumerable,T=(o,t,e)=>t in o?I(o,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):o[t]=e,f=(o,t)=>{for(var e in t||(t={}))q.call(t,e)&&T(o,e,t[e]);if(w)for(var e of w(t))L.call(t,e)&&T(o,e,t[e]);return o},b=(o,t)=>N(o,B(t));let R=!1;const S=[],V=o=>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():S.push(s)},document.getElementById("storyblok-javascript-bridge")))return;const r=document.createElement("script");r.async=!0,r.src=o,r.id="storyblok-javascript-bridge",r.onerror=s=>e(s),r.onload=s=>{S.forEach(n=>n()),R=!0,t(s)},document.getElementsByTagName("head")[0].appendChild(r)});/*!
|
|
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 S(o){return typeof o=="number"&&o==o&&o!==1/0&&o!==-1/0}function E(o,t,e){if(!S(t))throw new TypeError("Expected `limit` to be a finite number");if(!S(e))throw new TypeError("Expected `interval` to be a finite number");var r=[],s=[],n=0,i=function(){n++;var c=setTimeout(function(){n--,r.length>0&&i(),s=s.filter(function(u){return u!==c})},e);s.indexOf(c)<0&&s.push(c);var l=r.shift();l.resolve(o.apply(l.self,l.args))},a=function(){var c=arguments,l=this;return new Promise(function(u,m){r.push({resolve:u,reject:m,args:c,self:l}),n<t&&i()})};return a.abort=function(){s.forEach(clearTimeout),s=[],r.forEach(function(c){c.reject(new throttle.AbortError)}),r.length=0},a}E.AbortError=function(){Error.call(this,"Throttled function aborted"),this.name="AbortError"};const D=function(o,t){if(!o)return null;let e={};for(let r in o){let s=o[r];t.indexOf(r)>-1&&s!==null&&(e[r]=s)}return e};var z={nodes:{horizontal_rule:()=>({singleTag:"hr"}),blockquote:()=>({tag:"blockquote"}),bullet_list:()=>({tag:"ul"}),code_block:o=>({tag:["pre",{tag:"code",attrs:o.attrs}]}),hard_break:()=>({singleTag:"br"}),heading:o=>({tag:`h${o.attrs.level}`}),image:o=>({singleTag:[{tag:"img",attrs:D(o.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(o){const t=f({},o.attrs),{linktype:e="url"}=o.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:o=>({tag:[{tag:"span",attrs:o.attrs}]})}};class U{constructor(t){t||(t=z),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 n=this.getMatchingMark(s);n&&e.push(this.renderOpeningTag(n.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 n={"&":"&","<":"<",">":">",'"':""","'":"'"},i=/[&<>"']/g,a=RegExp(i.source);return s&&a.test(s)?s.replace(i,c=>n[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 n=this.getMatchingMark(s);n&&e.push(this.renderClosingTag(n.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 n in r.attrs){let i=r.attrs[n];i!==null&&(s+=` ${n}="${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 J=(o=0,t=o)=>{const e=Math.abs(t-o)||0,r=o<t?1:-1;return((s=0,n)=>[...Array(s)].map(n))(e,(s,n)=>n*r+o)},v=(o,t,e)=>{const r=[];for(const s in o){if(!Object.prototype.hasOwnProperty.call(o,s))continue;const n=o[s],i=e?"":encodeURIComponent(s);let a;a=typeof n=="object"?v(n,t?t+encodeURIComponent("["+i+"]"):i,Array.isArray(n)):(t?t+encodeURIComponent("["+i+"]"):i)+"="+encodeURIComponent(n),r.push(a)}return r.join("&")};let k={},g={};class Y{constructor(t,e){if(!e){let n=t.region?`-${t.region}`:"",i=t.https===!1?"http":"https";e=t.oauthToken===void 0?`${i}://api${n}.storyblok.com/v2`:`${i}://api${n}.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 U(t.richTextSchema),typeof t.componentResolver=="function"&&this.setComponentResolver(t.componentResolver),this.maxRetries=t.maxRetries||5,this.throttle=E(this.throttledRequest,s,1e3),this.accessToken=t.accessToken,this.relations={},this.links={},this.cache=t.cache||{clear:"manual"},this.client=I.default.create({baseURL:e,timeout:t.timeout||0,headers:r,proxy:t.proxy||!1}),t.responseInterceptor&&this.client.interceptors.response.use(n=>t.responseInterceptor(n)),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 n=this.factoryParamOptions(t,((i={},a=25,c=1)=>b(f({},i),{per_page:a,page:c}))(e,r,s));return this.cacheResponse(t,n)}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,n=`/${t}`,i=n.split("/");r=r||i[i.length-1];const a=await this.makeRequest(n,e,s,1),c=Math.ceil(a.total/s);return((l=[],u)=>l.map(u).reduce((m,tt)=>[...m,...tt],[]))([a,...await(async(l=[],u)=>Promise.all(l.map(u)))(J(1,c),async l=>this.makeRequest(n,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(n=>{this.relations[n]&&s.push(this._cleanCopy(this.relations[n]))}),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 n=0;n<s.length;n++)r(s[n]);else if(s.constructor===Object){if(s._stopResolving)return;for(let n in s)s.component&&s._uid||s.type==="link"?(this._insertRelations(s,n,e),this._insertLinks(s,n)):s.fieldtype==="asset"&&this._insertAssetsRelations(s,e),r(s[n])}}};r(t.content)}async resolveLinks(t,e){let r=[];if(t.link_uuids){const s=t.link_uuids.length;let n=[];const i=50;for(let a=0;a<s;a+=i){const c=Math.min(s,a+i);n.push(t.link_uuids.slice(a,c))}for(let a=0;a<n.length;a++)(await this.getStories({per_page:i,language:e.language,version:e.version,by_uuids:n[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 n=[];const i=50;for(let a=0;a<s;a+=i){const c=Math.min(s,a+i);n.push(t.rel_uuids.slice(a,c))}for(let a=0;a<n.length;a++)(await this.getStories({per_page:i,language:e.language,version:e.version,by_uuids:n[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&&(r=e.resolve_relations.split(","),await this.resolveRelations(t,e)),["1","story","url"].indexOf(e.resolve_links)>-1&&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 n of r)this.iterateTree(n,e);else this.iterateTree(s,e)}cacheResponse(t,e,r){return r===void 0&&(r=0),new Promise(async(s,n)=>{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:m=>v(m)}),u={data:l.data,headers:l.headers};if(u.data.assets&&u.data.assets.length&&this.resolveAssetsRelations(u.data),l.headers["per-page"]&&(u=Object.assign({},u,{perPage:parseInt(l.headers["per-page"]),total:parseInt(l.headers.total)})),l.status!=200)return n(l);(u.data.story||u.data.stories)&&await this.resolveStories(u.data,e),e.version==="published"&&t!="/cdn/spaces/me"&&a.set(i,u),u.data.cv&&(e.version=="draft"&&g[e.token]!=u.data.cv&&this.flushCache(),g[e.token]=u.data.cv),s(u)}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(u=>setTimeout(u,c))),this.cacheResponse(t,e,r).then(s).catch(n);n(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=>k[t],getAll:()=>k,set(t,e){k[t]=e},flush(){k={}}}:{get(){},getAll(){},set(){},flush(){}}}async flushCache(){return await this.cacheProvider().flush(),this}}var H=(o={})=>{const{apiOptions:t}=o;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 Y(t)}},F=o=>{if(typeof o!="object"||typeof o._editable=="undefined")return{};const t=JSON.parse(o._editable.replace(/^<!--#storyblok#/,"").replace(/-->$/,""));return{"data-blok-c":JSON.stringify(t),"data-blok-uid":t.id+"-"+t.uid}};const G="https://app.storyblok.com/f/storyblok-v2-latest.js",P=(o,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(!o){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===o?t(s.story):window.location.reload()})})}},K=(o={})=>{const{bridge:t,accessToken:e,use:r=[],apiOptions:s={}}=o;s.accessToken=s.accessToken||e;const n={bridge:t,apiOptions:s};let i={};return r.forEach(a=>{i=f(f({},i),a(n))}),t!==!1&&V(G),i},$={props:{blok:Object},setup(o){return(t,e)=>(d.openBlock(),d.createBlock(d.resolveDynamicComponent(o.blok.component),d.normalizeProps(d.guardReactiveProps(_(_({},t.$props),t.$attrs))),null,16))}},Q={beforeMount(o,t){if(t.value){const e=F(t.value);o.setAttribute("data-blok-c",e["data-blok-c"]),o.setAttribute("data-blok-uid",e["data-blok-uid"]),o.classList.add("storyblok__outline")}}},A=o=>{console.error(`You can't use ${o} if you're not loading apiPlugin. Please provide it on StoryblokVue initialization.
|
|
6
|
-
`)};let y=null;const W=()=>(y||A("useStoryblokApi"),y),X=async(o,t={},e={})=>{const r=
|
|
5
|
+
*/function E(o){return typeof o=="number"&&o==o&&o!==1/0&&o!==-1/0}function O(o,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=[],n=0,i=function(){n++;var c=setTimeout(function(){n--,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(o.apply(l.self,l.args))},a=function(){var c=arguments,l=this;return new Promise(function(h,m){r.push({resolve:h,reject:m,args:c,self:l}),n<t&&i()})};return a.abort=function(){s.forEach(clearTimeout),s=[],r.forEach(function(c){c.reject(new throttle.AbortError)}),r.length=0},a}O.AbortError=function(){Error.call(this,"Throttled function aborted"),this.name="AbortError"};const D=function(o,t){if(!o)return null;let e={};for(let r in o){let s=o[r];t.indexOf(r)>-1&&s!==null&&(e[r]=s)}return e};var z={nodes:{horizontal_rule:()=>({singleTag:"hr"}),blockquote:()=>({tag:"blockquote"}),bullet_list:()=>({tag:"ul"}),code_block:o=>({tag:["pre",{tag:"code",attrs:o.attrs}]}),hard_break:()=>({singleTag:"br"}),heading:o=>({tag:`h${o.attrs.level}`}),image:o=>({singleTag:[{tag:"img",attrs:D(o.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(o){const t=f({},o.attrs),{linktype:e="url"}=o.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:o=>({tag:[{tag:"span",attrs:o.attrs}]})}};class U{constructor(t){t||(t=z),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 n=this.getMatchingMark(s);n&&e.push(this.renderOpeningTag(n.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 n={"&":"&","<":"<",">":">",'"':""","'":"'"},i=/[&<>"']/g,a=RegExp(i.source);return s&&a.test(s)?s.replace(i,c=>n[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 n=this.getMatchingMark(s);n&&e.push(this.renderClosingTag(n.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 n in r.attrs){let i=r.attrs[n];i!==null&&(s+=` ${n}="${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 J=(o=0,t=o)=>{const e=Math.abs(t-o)||0,r=o<t?1:-1;return((s=0,n)=>[...Array(s)].map(n))(e,(s,n)=>n*r+o)},v=(o,t,e)=>{const r=[];for(const s in o){if(!Object.prototype.hasOwnProperty.call(o,s))continue;const n=o[s],i=e?"":encodeURIComponent(s);let a;a=typeof n=="object"?v(n,t?t+encodeURIComponent("["+i+"]"):i,Array.isArray(n)):(t?t+encodeURIComponent("["+i+"]"):i)+"="+encodeURIComponent(n),r.push(a)}return r.join("&")};let k={},g={};class Y{constructor(t,e){if(!e){let n=t.region?`-${t.region}`:"",i=t.https===!1?"http":"https";e=t.oauthToken===void 0?`${i}://api${n}.storyblok.com/v2`:`${i}://api${n}.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 U(t.richTextSchema),typeof t.componentResolver=="function"&&this.setComponentResolver(t.componentResolver),this.maxRetries=t.maxRetries||5,this.throttle=O(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(n=>t.responseInterceptor(n)),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 n=this.factoryParamOptions(t,((i={},a=25,c=1)=>b(f({},i),{per_page:a,page:c}))(e,r,s));return this.cacheResponse(t,n)}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,n=`/${t}`,i=n.split("/");r=r||i[i.length-1];const a=await this.makeRequest(n,e,s,1),c=Math.ceil(a.total/s);return((l=[],h)=>l.map(h).reduce((m,tt)=>[...m,...tt],[]))([a,...await(async(l=[],h)=>Promise.all(l.map(h)))(J(1,c),async l=>this.makeRequest(n,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(n=>{this.relations[n]&&s.push(this._cleanCopy(this.relations[n]))}),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 n=0;n<s.length;n++)r(s[n]);else if(s.constructor===Object){if(s._stopResolving)return;for(let n in s)s.component&&s._uid||s.type==="link"?(this._insertRelations(s,n,e),this._insertLinks(s,n)):s.fieldtype==="asset"&&this._insertAssetsRelations(s,e),r(s[n])}}};r(t.content)}async resolveLinks(t,e){let r=[];if(t.link_uuids){const s=t.link_uuids.length;let n=[];const i=50;for(let a=0;a<s;a+=i){const c=Math.min(s,a+i);n.push(t.link_uuids.slice(a,c))}for(let a=0;a<n.length;a++)(await this.getStories({per_page:i,language:e.language,version:e.version,by_uuids:n[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 n=[];const i=50;for(let a=0;a<s;a+=i){const c=Math.min(s,a+i);n.push(t.rel_uuids.slice(a,c))}for(let a=0;a<n.length;a++)(await this.getStories({per_page:i,language:e.language,version:e.version,by_uuids:n[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&&(r=e.resolve_relations.split(","),await this.resolveRelations(t,e)),["1","story","url"].indexOf(e.resolve_links)>-1&&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 n of r)this.iterateTree(n,e);else this.iterateTree(s,e)}cacheResponse(t,e,r){return r===void 0&&(r=0),new Promise(async(s,n)=>{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:m=>v(m)}),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 n(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(n);n(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=>k[t],getAll:()=>k,set(t,e){k[t]=e},flush(){k={}}}:{get(){},getAll(){},set(){},flush(){}}}async flushCache(){return await this.cacheProvider().flush(),this}}const F=(o={})=>{const{apiOptions:t}=o;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 Y(t)}};var H=o=>{if(typeof o!="object"||typeof o._editable=="undefined")return{};const t=JSON.parse(o._editable.replace(/^<!--#storyblok#/,"").replace(/-->$/,""));return{"data-blok-c":JSON.stringify(t),"data-blok-uid":t.id+"-"+t.uid}};const G="https://app.storyblok.com/f/storyblok-v2-latest.js",P=(o,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(!o){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===o?t(s.story):window.location.reload()})})}},K=(o={})=>{const{bridge:t,accessToken:e,use:r=[],apiOptions:s={}}=o;s.accessToken=s.accessToken||e;const n={bridge:t,apiOptions:s};let i={};return r.forEach(a=>{i=f(f({},i),a(n))}),t!==!1&&V(G),i},$=u.defineComponent({__name:"StoryblokComponent",props:{blok:null},setup(o){return(t,e)=>(u.openBlock(),u.createBlock(u.resolveDynamicComponent(o.blok.component),u.normalizeProps(u.guardReactiveProps(_(_({},t.$props),t.$attrs))),null,16))}}),Q={beforeMount(o,t){if(t.value){const e=H(t.value);o.setAttribute("data-blok-c",e["data-blok-c"]),o.setAttribute("data-blok-uid",e["data-blok-uid"]),o.classList.add("storyblok__outline")}}},A=o=>{console.error(`You can't use ${o} if you're not loading apiPlugin. Please provide it on StoryblokVue initialization.
|
|
6
|
+
`)};let y=null;const W=()=>(y||A("useStoryblokApi"),y),X=async(o,t={},e={})=>{const r=u.ref(null);if(u.onMounted(()=>{r.value&&r.value.id&&P(r.value.id,s=>r.value=s,e)}),y){const{data:s}=await y.get(`cdn/stories/${o}`,t);r.value=s.story}else A("useStoryblok");return r},Z={install(o,t={}){o.directive("editable",Q),o.component("StoryblokComponent",$);const{storyblokApi:e}=K(t);y=e}};d.StoryblokComponent=$,d.StoryblokVue=Z,d.apiPlugin=F,d.useStoryblok=X,d.useStoryblokApi=W,d.useStoryblokBridge=P,Object.defineProperties(d,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|
package/dist/storyblok-vue.mjs
CHANGED
|
@@ -14,7 +14,7 @@ var __spreadValues = (a2, b) => {
|
|
|
14
14
|
}
|
|
15
15
|
return a2;
|
|
16
16
|
};
|
|
17
|
-
import { openBlock, createBlock, resolveDynamicComponent, normalizeProps, guardReactiveProps, ref, onMounted } from "vue";
|
|
17
|
+
import { defineComponent, openBlock, createBlock, resolveDynamicComponent, normalizeProps, guardReactiveProps, ref, onMounted } from "vue";
|
|
18
18
|
import e from "axios";
|
|
19
19
|
var __defProp2 = Object.defineProperty;
|
|
20
20
|
var __defProps = Object.defineProperties;
|
|
@@ -67,7 +67,7 @@ const loadBridge = (src) => {
|
|
|
67
67
|
});
|
|
68
68
|
};
|
|
69
69
|
/*!
|
|
70
|
-
* storyblok-js-client
|
|
70
|
+
* storyblok-js-client v4.5.2
|
|
71
71
|
* Universal JavaScript SDK for Storyblok's API
|
|
72
72
|
* (c) 2020-2022 Stobylok Team
|
|
73
73
|
*/
|
|
@@ -412,7 +412,7 @@ class h {
|
|
|
412
412
|
return await this.cacheProvider().flush(), this;
|
|
413
413
|
}
|
|
414
414
|
}
|
|
415
|
-
|
|
415
|
+
const apiFactory = (options = {}) => {
|
|
416
416
|
const { apiOptions } = options;
|
|
417
417
|
if (!apiOptions.accessToken) {
|
|
418
418
|
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");
|
|
@@ -468,14 +468,17 @@ const storyblokInit = (pluginOptions = {}) => {
|
|
|
468
468
|
}
|
|
469
469
|
return result;
|
|
470
470
|
};
|
|
471
|
-
const _sfc_main = {
|
|
472
|
-
|
|
471
|
+
const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
472
|
+
__name: "StoryblokComponent",
|
|
473
|
+
props: {
|
|
474
|
+
blok: null
|
|
475
|
+
},
|
|
473
476
|
setup(__props) {
|
|
474
477
|
return (_ctx, _cache) => {
|
|
475
478
|
return openBlock(), createBlock(resolveDynamicComponent(__props.blok.component), normalizeProps(guardReactiveProps(__spreadValues(__spreadValues({}, _ctx.$props), _ctx.$attrs))), null, 16);
|
|
476
479
|
};
|
|
477
480
|
}
|
|
478
|
-
};
|
|
481
|
+
});
|
|
479
482
|
const vEditableDirective = {
|
|
480
483
|
beforeMount(el, binding) {
|
|
481
484
|
if (binding.value) {
|
|
@@ -518,4 +521,4 @@ const StoryblokVue = {
|
|
|
518
521
|
storyblokApiInstance = storyblokApi;
|
|
519
522
|
}
|
|
520
523
|
};
|
|
521
|
-
export { _sfc_main as StoryblokComponent, StoryblokVue,
|
|
524
|
+
export { _sfc_main as StoryblokComponent, StoryblokVue, apiFactory as apiPlugin, 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.1.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,7 +24,7 @@
|
|
|
23
24
|
"prepublishOnly": "npm run build && cp ../README.md ./"
|
|
24
25
|
},
|
|
25
26
|
"dependencies": {
|
|
26
|
-
"@storyblok/js": "^1.
|
|
27
|
+
"@storyblok/js": "^1.6.1"
|
|
27
28
|
},
|
|
28
29
|
"devDependencies": {
|
|
29
30
|
"@babel/core": "^7.18.5",
|
|
@@ -32,14 +33,17 @@
|
|
|
32
33
|
"@vitejs/plugin-vue": "^2.3.3",
|
|
33
34
|
"@vue/babel-preset-app": "^5.0.4",
|
|
34
35
|
"@vue/test-utils": "next",
|
|
35
|
-
"
|
|
36
|
+
"@vue/tsconfig": "^0.1.3",
|
|
37
|
+
"babel-jest": "^26.0.0",
|
|
36
38
|
"cypress": "^9.6.0",
|
|
37
39
|
"eslint-plugin-cypress": "^2.12.1",
|
|
38
40
|
"eslint-plugin-jest": "^26.1.5",
|
|
39
|
-
"jest": "^
|
|
41
|
+
"jest": "^26.1.0",
|
|
42
|
+
"typescript": "^4.7.3",
|
|
40
43
|
"vite": "^2.9.9",
|
|
41
44
|
"vue": "^3.2.33",
|
|
42
|
-
"vue-jest": "next"
|
|
45
|
+
"vue-jest": "next",
|
|
46
|
+
"vue-tsc": "^0.37.9"
|
|
43
47
|
},
|
|
44
48
|
"babel": {
|
|
45
49
|
"presets": [
|