@storyblok/vue 6.1.0 → 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/index.d.ts +1 -1
- package/dist/storyblok-vue.js +5 -3
- package/dist/storyblok-vue.mjs +285 -4
- package/package.json +3 -3
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { Ref, Plugin } from "vue";
|
|
2
2
|
import type { StoryblokClient, StoryblokBridgeConfigV2, StoryData, StoriesParams } from "./types";
|
|
3
3
|
export declare const useStoryblokApi: () => StoryblokClient;
|
|
4
|
-
export { useStoryblokBridge, apiPlugin } from "@storyblok/js";
|
|
4
|
+
export { useStoryblokBridge, apiPlugin, renderRichText } from "@storyblok/js";
|
|
5
5
|
export { default as StoryblokComponent } from "./StoryblokComponent.vue";
|
|
6
6
|
export declare const useStoryblok: (url: string, apiOptions?: StoriesParams, bridgeOptions?: StoryblokBridgeConfigV2) => Promise<Ref<StoryData<import("storyblok-js-client").StoryblokComponent<string> & {
|
|
7
7
|
[index: string]: any;
|
package/dist/storyblok-vue.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
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
|
|
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
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 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
|
-
|
|
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
|
@@ -66,6 +66,272 @@ 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
336
|
* storyblok-js-client v4.5.2
|
|
71
337
|
* Universal JavaScript SDK for Storyblok's API
|
|
@@ -299,7 +565,7 @@ class h {
|
|
|
299
565
|
if (e3._stopResolving)
|
|
300
566
|
return;
|
|
301
567
|
for (let r2 in e3)
|
|
302
|
-
e3.component && e3._uid || e3.type === "link" ? (this._insertRelations(e3, r2, t2), this._insertLinks(e3, r2)) : e3.fieldtype === "asset" && this._insertAssetsRelations(e3, t2), s2(e3[r2]);
|
|
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]);
|
|
303
569
|
}
|
|
304
570
|
}
|
|
305
571
|
};
|
|
@@ -349,7 +615,7 @@ class h {
|
|
|
349
615
|
}
|
|
350
616
|
async resolveStories(e2, t2) {
|
|
351
617
|
let s2 = [];
|
|
352
|
-
if (t2.resolve_relations !== void 0 && t2.resolve_relations.length > 0 && (s2 = t2.resolve_relations.split(","), await this.resolveRelations(e2, t2)), ["1", "story", "url"].indexOf(t2.resolve_links) > -1 && await this.resolveLinks(e2, t2), this.resolveNestedRelations)
|
|
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)
|
|
353
619
|
for (const e3 in this.relations)
|
|
354
620
|
this.iterateTree(this.relations[e3], s2);
|
|
355
621
|
e2.story ? this.iterateTree(e2.story, s2) : e2.stories.forEach((e3) => {
|
|
@@ -361,8 +627,11 @@ class h {
|
|
|
361
627
|
if (s2)
|
|
362
628
|
for (const e3 of s2)
|
|
363
629
|
this.iterateTree(e3, t2);
|
|
364
|
-
else
|
|
630
|
+
else {
|
|
631
|
+
if (!r2)
|
|
632
|
+
return e2;
|
|
365
633
|
this.iterateTree(r2, t2);
|
|
634
|
+
}
|
|
366
635
|
}
|
|
367
636
|
cacheResponse(e2, t2, s2) {
|
|
368
637
|
return s2 === void 0 && (s2 = 0), new Promise(async (r2, i2) => {
|
|
@@ -431,6 +700,7 @@ var editable = (blok) => {
|
|
|
431
700
|
"data-blok-uid": options.id + "-" + options.uid
|
|
432
701
|
};
|
|
433
702
|
};
|
|
703
|
+
const resolver = new RichTextResolver();
|
|
434
704
|
const bridgeLatest = "https://app.storyblok.com/f/storyblok-v2-latest.js";
|
|
435
705
|
const useStoryblokBridge = (id, cb, options = {}) => {
|
|
436
706
|
if (typeof window === "undefined") {
|
|
@@ -468,6 +738,17 @@ const storyblokInit = (pluginOptions = {}) => {
|
|
|
468
738
|
}
|
|
469
739
|
return result;
|
|
470
740
|
};
|
|
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
|
+
};
|
|
471
752
|
const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
472
753
|
__name: "StoryblokComponent",
|
|
473
754
|
props: {
|
|
@@ -521,4 +802,4 @@ const StoryblokVue = {
|
|
|
521
802
|
storyblokApiInstance = storyblokApi;
|
|
522
803
|
}
|
|
523
804
|
};
|
|
524
|
-
export { _sfc_main as StoryblokComponent, StoryblokVue, apiFactory as apiPlugin, useStoryblok, useStoryblokApi, useStoryblokBridge };
|
|
805
|
+
export { _sfc_main as StoryblokComponent, StoryblokVue, apiFactory as apiPlugin, renderRichText, useStoryblok, useStoryblokApi, useStoryblokBridge };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@storyblok/vue",
|
|
3
|
-
"version": "6.
|
|
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",
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"prepublishOnly": "npm run build && cp ../README.md ./"
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@storyblok/js": "^1.
|
|
27
|
+
"@storyblok/js": "^1.7.0"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
30
|
"@babel/core": "^7.18.5",
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"cypress": "^9.6.0",
|
|
39
39
|
"eslint-plugin-cypress": "^2.12.1",
|
|
40
40
|
"eslint-plugin-jest": "^26.1.5",
|
|
41
|
-
"jest": "^
|
|
41
|
+
"jest": "^28.1.3",
|
|
42
42
|
"typescript": "^4.7.3",
|
|
43
43
|
"vite": "^2.9.9",
|
|
44
44
|
"vue": "^3.2.33",
|