@storyblok/vue-2
Advanced tools
Comparing version 1.3.0 to 1.3.1
import type { SbSDKOptions } from "./types"; | ||
import type { PluginObject } from "vue"; | ||
export declare const useStoryblokApi: () => import("storyblok-js-client").default; | ||
export { useStoryblokBridge, apiPlugin, renderRichText } from "@storyblok/js"; | ||
export { useStoryblokBridge, apiPlugin, renderRichText, RichTextSchema, } from "@storyblok/js"; | ||
export { default as StoryblokComponent } from "./StoryblokComponent.vue"; | ||
@@ -6,0 +6,0 @@ export { default as useStoryblok } from "./useStoryblok.js"; |
@@ -1,8 +0,8 @@ | ||
(function(h,y){typeof exports=="object"&&typeof module!="undefined"?y(exports,require("axios"),require("@vue/composition-api")):typeof define=="function"&&define.amd?define(["exports","axios","@vue/composition-api"],y):(h=typeof globalThis!="undefined"?globalThis:h||self,y(h.storyblokVue={},h.e,h.VueCompositionAPI))})(this,function(h,y,T){"use strict";function q(n){return n&&typeof n=="object"&&"default"in n?n:{default:n}}var L=q(y),z=Object.defineProperty,B=Object.defineProperties,U=Object.getOwnPropertyDescriptors,w=Object.getOwnPropertySymbols,D=Object.prototype.hasOwnProperty,F=Object.prototype.propertyIsEnumerable,R=(n,e,t)=>e in n?z(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t,f=(n,e)=>{for(var t in e||(e={}))D.call(e,t)&&R(n,t,e[t]);if(w)for(var t of w(e))F.call(e,t)&&R(n,t,e[t]);return n},v=(n,e)=>B(n,U(e));let $=!1;const S=[],H=n=>new Promise((e,t)=>{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}$?s():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=>t(s),r.onload=s=>{S.forEach(o=>o()),$=!0,e(s)},document.getElementsByTagName("head")[0].appendChild(r)}),J=function(n,e){if(!n)return null;let t={};for(let r in n){let s=n[r];e.indexOf(r)>-1&&s!==null&&(t[r]=s)}return t},Y=n=>n==="email";var X={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:J(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 e=f({},n.attrs),{linktype:t="url"}=n.attrs;return Y(t)&&(e.href=`mailto:${e.href}`),e.anchor&&(e.href=`${e.href}#${e.anchor}`,delete e.anchor),{tag:[{tag:"a",attrs:e}]}},styled(n){return{tag:[{tag:"span",attrs:n.attrs}]}}}};const K=function(n){const e={"&":"&","<":"<",">":">",'"':""","'":"'"},t=/[&<>"']/g,r=RegExp(t.source);return n&&r.test(n)?n.replace(t,s=>e[s]):n};class E{constructor(e){e||(e=X),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(s=>{const o=this.getMatchingMark(s);o&&t.push(this.renderOpeningTag(o.tag))});const r=this.getMatchingNode(e);return r&&r.tag&&t.push(this.renderOpeningTag(r.tag)),e.content?e.content.forEach(s=>{t.push(this.renderNode(s))}):e.text?t.push(K(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(s=>{const o=this.getMatchingMark(s);o&&t.push(this.renderClosingTag(o.tag))}),t.join("")}renderTag(e,t){return e.constructor===String?`<${e}${t}>`:e.map(s=>{if(s.constructor===String)return`<${s}${t}>`;{let o=`<${s.tag}`;if(s.attrs)for(let l in s.attrs){let i=s.attrs[l];i!==null&&(o+=` ${l}="${i}"`)}return`${o}${t}>`}}).join("")}renderOpeningTag(e){return this.renderTag(e,"")}renderClosingTag(e){return e.constructor===String?`</${e}>`:e.slice(0).reverse().map(r=>r.constructor===String?`</${r}>`:`</${r.tag}>`).join("")}getMatchingNode(e){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)}}/*! | ||
(function(h,y){typeof exports=="object"&&typeof module!="undefined"?y(exports,require("axios"),require("@vue/composition-api")):typeof define=="function"&&define.amd?define(["exports","axios","@vue/composition-api"],y):(h=typeof globalThis!="undefined"?globalThis:h||self,y(h.storyblokVue={},h.e,h.VueCompositionAPI))})(this,function(h,y,T){"use strict";function L(n){return n&&typeof n=="object"&&"default"in n?n:{default:n}}var z=L(y),B=Object.defineProperty,U=Object.defineProperties,D=Object.getOwnPropertyDescriptors,w=Object.getOwnPropertySymbols,F=Object.prototype.hasOwnProperty,H=Object.prototype.propertyIsEnumerable,R=(n,e,t)=>e in n?B(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t,f=(n,e)=>{for(var t in e||(e={}))F.call(e,t)&&R(n,t,e[t]);if(w)for(var t of w(e))H.call(e,t)&&R(n,t,e[t]);return n},v=(n,e)=>U(n,D(e));let $=!1;const S=[],J=n=>new Promise((e,t)=>{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}$?s():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=>t(s),r.onload=s=>{S.forEach(o=>o()),$=!0,e(s)},document.getElementsByTagName("head")[0].appendChild(r)}),Y=function(n,e){if(!n)return null;let t={};for(let r in n){let s=n[r];e.indexOf(r)>-1&&s!==null&&(t[r]=s)}return t},X=n=>n==="email";var E={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:Y(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 e=f({},n.attrs),{linktype:t="url"}=n.attrs;return X(t)&&(e.href=`mailto:${e.href}`),e.anchor&&(e.href=`${e.href}#${e.anchor}`,delete e.anchor),{tag:[{tag:"a",attrs:e}]}},styled(n){return{tag:[{tag:"span",attrs:n.attrs}]}}}};const K=function(n){const e={"&":"&","<":"<",">":">",'"':""","'":"'"},t=/[&<>"']/g,r=RegExp(t.source);return n&&r.test(n)?n.replace(t,s=>e[s]):n};class O{constructor(e){e||(e=E),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(s=>{const o=this.getMatchingMark(s);o&&t.push(this.renderOpeningTag(o.tag))});const r=this.getMatchingNode(e);return r&&r.tag&&t.push(this.renderOpeningTag(r.tag)),e.content?e.content.forEach(s=>{t.push(this.renderNode(s))}):e.text?t.push(K(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(s=>{const o=this.getMatchingMark(s);o&&t.push(this.renderClosingTag(o.tag))}),t.join("")}renderTag(e,t){return e.constructor===String?`<${e}${t}>`:e.map(s=>{if(s.constructor===String)return`<${s}${t}>`;{let o=`<${s.tag}`;if(s.attrs)for(let l in s.attrs){let i=s.attrs[l];i!==null&&(o+=` ${l}="${i}"`)}return`${o}${t}>`}}).join("")}renderOpeningTag(e){return this.renderTag(e,"")}renderClosingTag(e){return e.constructor===String?`</${e}>`:e.slice(0).reverse().map(r=>r.constructor===String?`</${r}>`:`</${r.tag}>`).join("")}getMatchingNode(e){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)}}/*! | ||
* storyblok-js-client v4.5.2 | ||
* Universal JavaScript SDK for Storyblok's API | ||
* (c) 2020-2022 Stobylok Team | ||
*/function O(n){return typeof n=="number"&&n==n&&n!==1/0&&n!==-1/0}function j(n,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=[],s=[],o=0,l=function(){o++;var a=setTimeout(function(){o--,r.length>0&&l(),s=s.filter(function(u){return u!==a})},t);s.indexOf(a)<0&&s.push(a);var c=r.shift();c.resolve(n.apply(c.self,c.args))},i=function(){var a=arguments,c=this;return new Promise(function(u,p){r.push({resolve:u,reject:p,args:a,self:c}),o<e&&l()})};return i.abort=function(){s.forEach(clearTimeout),s=[],r.forEach(function(a){a.reject(new throttle.AbortError)}),r.length=0},i}j.AbortError=function(){Error.call(this,"Throttled function aborted"),this.name="AbortError"};const W=function(n,e){if(!n)return null;let t={};for(let r in n){let s=n[r];e.indexOf(r)>-1&&s!==null&&(t[r]=s)}return t};var G={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:W(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 e=f({},n.attrs),{linktype:t="url"}=n.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:n=>({tag:[{tag:"span",attrs:n.attrs}]})}};class Q{constructor(e){e||(e=G),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(s=>{const o=this.getMatchingMark(s);o&&t.push(this.renderOpeningTag(o.tag))});const r=this.getMatchingNode(e);return r&&r.tag&&t.push(this.renderOpeningTag(r.tag)),e.content?e.content.forEach(s=>{t.push(this.renderNode(s))}):e.text?t.push(function(s){const o={"&":"&","<":"<",">":">",'"':""","'":"'"},l=/[&<>"']/g,i=RegExp(l.source);return s&&i.test(s)?s.replace(l,a=>o[a]):s}(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(s=>{const o=this.getMatchingMark(s);o&&t.push(this.renderClosingTag(o.tag))}),t.join("")}renderTag(e,t){return e.constructor===String?`<${e}${t}>`:e.map(r=>{if(r.constructor===String)return`<${r}${t}>`;{let s=`<${r.tag}`;if(r.attrs)for(let o in r.attrs){let l=r.attrs[o];l!==null&&(s+=` ${o}="${l}"`)}return`${s}${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 Z=(n=0,e=n)=>{const t=Math.abs(e-n)||0,r=n<e?1:-1;return((s=0,o)=>[...Array(s)].map(o))(t,(s,o)=>o*r+n)},b=(n,e,t)=>{const r=[];for(const s in n){if(!Object.prototype.hasOwnProperty.call(n,s))continue;const o=n[s],l=t?"":encodeURIComponent(s);let i;i=typeof o=="object"?b(o,e?e+encodeURIComponent("["+l+"]"):l,Array.isArray(o)):(e?e+encodeURIComponent("["+l+"]"):l)+"="+encodeURIComponent(o),r.push(i)}return r.join("&")};let m={},g={};class ee{constructor(e,t){if(!t){let o=e.region?`-${e.region}`:"",l=e.https===!1?"http":"https";t=e.oauthToken===void 0?`${l}://api${o}.storyblok.com/v2`:`${l}://api${o}.storyblok.com/v1`}let r=Object.assign({},e.headers),s=5;e.oauthToken!==void 0&&(r.Authorization=e.oauthToken,s=3),e.rateLimit!==void 0&&(s=e.rateLimit),this.richTextResolver=new Q(e.richTextSchema),typeof e.componentResolver=="function"&&this.setComponentResolver(e.componentResolver),this.maxRetries=e.maxRetries||5,this.throttle=j(this.throttledRequest,s,1e3),this.accessToken=e.accessToken,this.relations={},this.links={},this.cache=e.cache||{clear:"manual"},this.client=L.default.create({baseURL:t,timeout:e.timeout||0,headers:r,proxy:e.proxy||!1}),e.responseInterceptor&&this.client.interceptors.response.use(o=>e.responseInterceptor(o)),this.resolveNestedRelations=e.resolveNestedRelations||!0}setComponentResolver(e){this.richTextResolver.addNode("blok",t=>{let r="";return t.attrs.body.forEach(s=>{r+=e(s.component,s)}),{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,s){const o=this.factoryParamOptions(e,((l={},i=25,a=1)=>v(f({},l),{per_page:i,page:a}))(t,r,s));return this.cacheResponse(e,o)}get(e,t){let r=`/${e}`;const s=this.factoryParamOptions(r,t);return this.cacheResponse(r,s)}async getAll(e,t={},r){const s=t.per_page||25,o=`/${e}`,l=o.split("/");r=r||l[l.length-1];const i=await this.makeRequest(o,t,s,1),a=Math.ceil(i.total/s);return((c=[],u)=>c.map(u).reduce((p,d)=>[...p,...d],[]))([i,...await(async(c=[],u)=>Promise.all(c.map(u)))(Z(1,a),async c=>this.makeRequest(o,t,s,c+1))],c=>Object.values(c.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 s=[];e[t].forEach(o=>{this.relations[o]&&s.push(this._cleanCopy(this.relations[o]))}),e[t]=s}}}_insertAssetsRelations(e,t){t.forEach(r=>{e.id===r.id&&(e.original=r,e.original.filename=e.filename,e.original.filename=e.original.filename.includes("https://s3.amazonaws.com/")?e.original.filename:e.original.filename.replace("https://","https://s3.amazonaws.com/"),delete e.original.s3_filename)})}iterateTree(e,t){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,t),this._insertLinks(s,o)):"id"in s&&s.fieldtype==="asset"&&this._insertAssetsRelations(s,t),r(s[o])}}};r(e.content)}async resolveLinks(e,t){let r=[];if(e.link_uuids){const s=e.link_uuids.length;let o=[];const l=50;for(let i=0;i<s;i+=l){const a=Math.min(s,i+l);o.push(e.link_uuids.slice(i,a))}for(let i=0;i<o.length;i++)(await this.getStories({per_page:l,language:t.language,version:t.version,by_uuids:o[i].join(",")})).data.stories.forEach(a=>{r.push(a)})}else r=e.links;r.forEach(s=>{this.links[s.uuid]=v(f({},s),{_stopResolving:!0})})}async resolveRelations(e,t){let r=[];if(e.rel_uuids){const s=e.rel_uuids.length;let o=[];const l=50;for(let i=0;i<s;i+=l){const a=Math.min(s,i+l);o.push(e.rel_uuids.slice(i,a))}for(let i=0;i<o.length;i++)(await this.getStories({per_page:l,language:t.language,version:t.version,by_uuids:o[i].join(",")})).data.stories.forEach(a=>{r.push(a)})}else r=e.rels;r.forEach(s=>{this.relations[s.uuid]=v(f({},s),{_stopResolving:!0})})}async resolveStories(e,t){let r=[];if(t.resolve_relations!==void 0&&t.resolve_relations.length>0&&(e.rels||e.rel_uuids)&&(r=t.resolve_relations.split(","),await this.resolveRelations(e,t)),["1","story","url"].indexOf(t.resolve_links)>-1&&(e.links||e.link_uuids)&&await this.resolveLinks(e,t),this.resolveNestedRelations)for(const s in this.relations)this.iterateTree(this.relations[s],r);e.story?this.iterateTree(e.story,r):e.stories.forEach(s=>{this.iterateTree(s,r)})}resolveAssetsRelations(e){const{assets:t,stories:r,story:s}=e;if(r)for(const o of r)this.iterateTree(o,t);else{if(!s)return e;this.iterateTree(s,t)}}cacheResponse(e,t,r){return r===void 0&&(r=0),new Promise(async(s,o)=>{let l=b({url:e,params:t}),i=this.cacheProvider();if(this.cache.clear==="auto"&&t.version==="draft"&&await this.flushCache(),t.version==="published"&&e!="/cdn/spaces/me"){const c=await i.get(l);if(c)return s(c)}try{let c=await this.throttle("get",e,{params:t,paramsSerializer:p=>b(p)}),u={data:c.data,headers:c.headers};if(u.data.assets&&u.data.assets.length&&this.resolveAssetsRelations(u.data),c.headers["per-page"]&&(u=Object.assign({},u,{perPage:parseInt(c.headers["per-page"]),total:parseInt(c.headers.total)})),c.status!=200)return o(c);(u.data.story||u.data.stories)&&await this.resolveStories(u.data,t),t.version==="published"&&e!="/cdn/spaces/me"&&i.set(l,u),u.data.cv&&(t.version=="draft"&&g[t.token]!=u.data.cv&&this.flushCache(),g[t.token]=u.data.cv),s(u)}catch(c){if(c.response&&c.response.status===429&&(r+=1)<this.maxRetries)return console.log(`Hit rate limit. Retrying in ${r} seconds.`),await(a=1e3*r,new Promise(u=>setTimeout(u,a))),this.cacheResponse(e,t,r).then(s).catch(o);o(c)}var a})}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(){return this.cache.type==="memory"?{get:e=>m[e],getAll:()=>m,set(e,t){m[e]=t},flush(){m={}}}:{get(){},getAll(){},set(){},flush(){}}}async flushCache(){return await this.cacheProvider().flush(),this}}const te=(n={})=>{const{apiOptions:e}=n;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 ee(e)}};var re=n=>{if(typeof n!="object"||typeof n._editable=="undefined")return{};const e=JSON.parse(n._editable.replace(/^<!--#storyblok#/,"").replace(/-->$/,""));return{"data-blok-c":JSON.stringify(e),"data-blok-uid":e.id+"-"+e.uid}};let k;const se="https://app.storyblok.com/f/storyblok-v2-latest.js",C=(n,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(!n){console.warn("Story ID is not defined. Please provide a valid ID.");return}window.storyblokRegisterEvent(()=>{new window.StoryblokBridge(t).on(["input","published","change"],s=>{s.story.id===n&&(s.action==="input"?e(s.story):window.location.reload())})})}},ne=(n={})=>{const{bridge:e,accessToken:t,use:r=[],apiOptions:s={},richText:o={}}=n;s.accessToken=s.accessToken||t;const l={bridge:e,apiOptions:s};let i={};return r.forEach(a=>{i=f(f({},i),a(l))}),e!==!1&&H(se),k=new E(o.schema),o.resolver&&P(k,o.resolver),i},P=(n,e)=>{n.addNode("blok",t=>{let r="";return t.attrs.body.forEach(s=>{r+=e(s.component,s)}),{html:r}})},oe=(n,e)=>{if(!k){console.error("Please initialize the Storyblok SDK before calling the renderRichText function");return}if(n==="")return"";if(!n)return console.warn(`${n} is not a valid Richtext object. This might be because the value of the richtext field is empty. | ||
*/function j(n){return typeof n=="number"&&n==n&&n!==1/0&&n!==-1/0}function C(n,e,t){if(!j(e))throw new TypeError("Expected `limit` to be a finite number");if(!j(t))throw new TypeError("Expected `interval` to be a finite number");var r=[],s=[],o=0,l=function(){o++;var a=setTimeout(function(){o--,r.length>0&&l(),s=s.filter(function(u){return u!==a})},t);s.indexOf(a)<0&&s.push(a);var c=r.shift();c.resolve(n.apply(c.self,c.args))},i=function(){var a=arguments,c=this;return new Promise(function(u,p){r.push({resolve:u,reject:p,args:a,self:c}),o<e&&l()})};return i.abort=function(){s.forEach(clearTimeout),s=[],r.forEach(function(a){a.reject(new throttle.AbortError)}),r.length=0},i}C.AbortError=function(){Error.call(this,"Throttled function aborted"),this.name="AbortError"};const W=function(n,e){if(!n)return null;let t={};for(let r in n){let s=n[r];e.indexOf(r)>-1&&s!==null&&(t[r]=s)}return t};var G={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:W(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 e=f({},n.attrs),{linktype:t="url"}=n.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:n=>({tag:[{tag:"span",attrs:n.attrs}]})}};class Q{constructor(e){e||(e=G),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(s=>{const o=this.getMatchingMark(s);o&&t.push(this.renderOpeningTag(o.tag))});const r=this.getMatchingNode(e);return r&&r.tag&&t.push(this.renderOpeningTag(r.tag)),e.content?e.content.forEach(s=>{t.push(this.renderNode(s))}):e.text?t.push(function(s){const o={"&":"&","<":"<",">":">",'"':""","'":"'"},l=/[&<>"']/g,i=RegExp(l.source);return s&&i.test(s)?s.replace(l,a=>o[a]):s}(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(s=>{const o=this.getMatchingMark(s);o&&t.push(this.renderClosingTag(o.tag))}),t.join("")}renderTag(e,t){return e.constructor===String?`<${e}${t}>`:e.map(r=>{if(r.constructor===String)return`<${r}${t}>`;{let s=`<${r.tag}`;if(r.attrs)for(let o in r.attrs){let l=r.attrs[o];l!==null&&(s+=` ${o}="${l}"`)}return`${s}${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 Z=(n=0,e=n)=>{const t=Math.abs(e-n)||0,r=n<e?1:-1;return((s=0,o)=>[...Array(s)].map(o))(t,(s,o)=>o*r+n)},b=(n,e,t)=>{const r=[];for(const s in n){if(!Object.prototype.hasOwnProperty.call(n,s))continue;const o=n[s],l=t?"":encodeURIComponent(s);let i;i=typeof o=="object"?b(o,e?e+encodeURIComponent("["+l+"]"):l,Array.isArray(o)):(e?e+encodeURIComponent("["+l+"]"):l)+"="+encodeURIComponent(o),r.push(i)}return r.join("&")};let m={},g={};class ee{constructor(e,t){if(!t){let o=e.region?`-${e.region}`:"",l=e.https===!1?"http":"https";t=e.oauthToken===void 0?`${l}://api${o}.storyblok.com/v2`:`${l}://api${o}.storyblok.com/v1`}let r=Object.assign({},e.headers),s=5;e.oauthToken!==void 0&&(r.Authorization=e.oauthToken,s=3),e.rateLimit!==void 0&&(s=e.rateLimit),this.richTextResolver=new Q(e.richTextSchema),typeof e.componentResolver=="function"&&this.setComponentResolver(e.componentResolver),this.maxRetries=e.maxRetries||5,this.throttle=C(this.throttledRequest,s,1e3),this.accessToken=e.accessToken,this.relations={},this.links={},this.cache=e.cache||{clear:"manual"},this.client=z.default.create({baseURL:t,timeout:e.timeout||0,headers:r,proxy:e.proxy||!1}),e.responseInterceptor&&this.client.interceptors.response.use(o=>e.responseInterceptor(o)),this.resolveNestedRelations=e.resolveNestedRelations||!0}setComponentResolver(e){this.richTextResolver.addNode("blok",t=>{let r="";return t.attrs.body.forEach(s=>{r+=e(s.component,s)}),{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,s){const o=this.factoryParamOptions(e,((l={},i=25,a=1)=>v(f({},l),{per_page:i,page:a}))(t,r,s));return this.cacheResponse(e,o)}get(e,t){let r=`/${e}`;const s=this.factoryParamOptions(r,t);return this.cacheResponse(r,s)}async getAll(e,t={},r){const s=t.per_page||25,o=`/${e}`,l=o.split("/");r=r||l[l.length-1];const i=await this.makeRequest(o,t,s,1),a=Math.ceil(i.total/s);return((c=[],u)=>c.map(u).reduce((p,d)=>[...p,...d],[]))([i,...await(async(c=[],u)=>Promise.all(c.map(u)))(Z(1,a),async c=>this.makeRequest(o,t,s,c+1))],c=>Object.values(c.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 s=[];e[t].forEach(o=>{this.relations[o]&&s.push(this._cleanCopy(this.relations[o]))}),e[t]=s}}}_insertAssetsRelations(e,t){t.forEach(r=>{e.id===r.id&&(e.original=r,e.original.filename=e.filename,e.original.filename=e.original.filename.includes("https://s3.amazonaws.com/")?e.original.filename:e.original.filename.replace("https://","https://s3.amazonaws.com/"),delete e.original.s3_filename)})}iterateTree(e,t){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,t),this._insertLinks(s,o)):"id"in s&&s.fieldtype==="asset"&&this._insertAssetsRelations(s,t),r(s[o])}}};r(e.content)}async resolveLinks(e,t){let r=[];if(e.link_uuids){const s=e.link_uuids.length;let o=[];const l=50;for(let i=0;i<s;i+=l){const a=Math.min(s,i+l);o.push(e.link_uuids.slice(i,a))}for(let i=0;i<o.length;i++)(await this.getStories({per_page:l,language:t.language,version:t.version,by_uuids:o[i].join(",")})).data.stories.forEach(a=>{r.push(a)})}else r=e.links;r.forEach(s=>{this.links[s.uuid]=v(f({},s),{_stopResolving:!0})})}async resolveRelations(e,t){let r=[];if(e.rel_uuids){const s=e.rel_uuids.length;let o=[];const l=50;for(let i=0;i<s;i+=l){const a=Math.min(s,i+l);o.push(e.rel_uuids.slice(i,a))}for(let i=0;i<o.length;i++)(await this.getStories({per_page:l,language:t.language,version:t.version,by_uuids:o[i].join(",")})).data.stories.forEach(a=>{r.push(a)})}else r=e.rels;r.forEach(s=>{this.relations[s.uuid]=v(f({},s),{_stopResolving:!0})})}async resolveStories(e,t){let r=[];if(t.resolve_relations!==void 0&&t.resolve_relations.length>0&&(e.rels||e.rel_uuids)&&(r=t.resolve_relations.split(","),await this.resolveRelations(e,t)),["1","story","url"].indexOf(t.resolve_links)>-1&&(e.links||e.link_uuids)&&await this.resolveLinks(e,t),this.resolveNestedRelations)for(const s in this.relations)this.iterateTree(this.relations[s],r);e.story?this.iterateTree(e.story,r):e.stories.forEach(s=>{this.iterateTree(s,r)})}resolveAssetsRelations(e){const{assets:t,stories:r,story:s}=e;if(r)for(const o of r)this.iterateTree(o,t);else{if(!s)return e;this.iterateTree(s,t)}}cacheResponse(e,t,r){return r===void 0&&(r=0),new Promise(async(s,o)=>{let l=b({url:e,params:t}),i=this.cacheProvider();if(this.cache.clear==="auto"&&t.version==="draft"&&await this.flushCache(),t.version==="published"&&e!="/cdn/spaces/me"){const c=await i.get(l);if(c)return s(c)}try{let c=await this.throttle("get",e,{params:t,paramsSerializer:p=>b(p)}),u={data:c.data,headers:c.headers};if(u.data.assets&&u.data.assets.length&&this.resolveAssetsRelations(u.data),c.headers["per-page"]&&(u=Object.assign({},u,{perPage:parseInt(c.headers["per-page"]),total:parseInt(c.headers.total)})),c.status!=200)return o(c);(u.data.story||u.data.stories)&&await this.resolveStories(u.data,t),t.version==="published"&&e!="/cdn/spaces/me"&&i.set(l,u),u.data.cv&&(t.version=="draft"&&g[t.token]!=u.data.cv&&this.flushCache(),g[t.token]=u.data.cv),s(u)}catch(c){if(c.response&&c.response.status===429&&(r+=1)<this.maxRetries)return console.log(`Hit rate limit. Retrying in ${r} seconds.`),await(a=1e3*r,new Promise(u=>setTimeout(u,a))),this.cacheResponse(e,t,r).then(s).catch(o);o(c)}var a})}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(){return this.cache.type==="memory"?{get:e=>m[e],getAll:()=>m,set(e,t){m[e]=t},flush(){m={}}}:{get(){},getAll(){},set(){},flush(){}}}async flushCache(){return await this.cacheProvider().flush(),this}}const te=(n={})=>{const{apiOptions:e}=n;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 ee(e)}};var re=n=>{if(typeof n!="object"||typeof n._editable=="undefined")return{};const e=JSON.parse(n._editable.replace(/^<!--#storyblok#/,"").replace(/-->$/,""));return{"data-blok-c":JSON.stringify(e),"data-blok-uid":e.id+"-"+e.uid}};let k;const se="https://app.storyblok.com/f/storyblok-v2-latest.js",P=(n,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(!n){console.warn("Story ID is not defined. Please provide a valid ID.");return}window.storyblokRegisterEvent(()=>{new window.StoryblokBridge(t).on(["input","published","change"],s=>{s.story.id===n&&(s.action==="input"?e(s.story):window.location.reload())})})}},ne=(n={})=>{const{bridge:e,accessToken:t,use:r=[],apiOptions:s={},richText:o={}}=n;s.accessToken=s.accessToken||t;const l={bridge:e,apiOptions:s};let i={};return r.forEach(a=>{i=f(f({},i),a(l))}),e!==!1&&J(se),k=new O(o.schema),o.resolver&&A(k,o.resolver),i},A=(n,e)=>{n.addNode("blok",t=>{let r="";return t.attrs.body.forEach(s=>{r+=e(s.component,s)}),{html:r}})},oe=(n,e)=>{if(!k){console.error("Please initialize the Storyblok SDK before calling the renderRichText function");return}if(n==="")return"";if(!n)return console.warn(`${n} is not a valid Richtext object. This might be because the value of the richtext field is empty. | ||
For more info about the richtext object check https://github.com/storyblok/storyblok-js#rendering-rich-text`),"";let t=k;return e&&(t=new E(e.schema),e.resolver&&P(t,e.resolver)),t.render(n)};var ie=function(){var e=this,t=e.$createElement,r=e._self._c||t;return r(e.blok.component,e._g(e._b({tag:"component"},"component",Object.assign({},e.$props,e.$attrs),!1),e.$listeners))},ae=[];function le(n,e,t,r,s,o,l,i){var a=typeof n=="function"?n.options:n;e&&(a.render=e,a.staticRenderFns=t,a._compiled=!0),r&&(a.functional=!0),o&&(a._scopeId="data-v-"+o);var c;if(l?(c=function(d){d=d||this.$vnode&&this.$vnode.ssrContext||this.parent&&this.parent.$vnode&&this.parent.$vnode.ssrContext,!d&&typeof __VUE_SSR_CONTEXT__!="undefined"&&(d=__VUE_SSR_CONTEXT__),s&&s.call(this,d),d&&d._registeredComponents&&d._registeredComponents.add(l)},a._ssrRegister=c):s&&(c=i?function(){s.call(this,(a.functional?this.parent:this).$root.$options.shadowRoot)}:s),c)if(a.functional){a._injectStyles=c;var u=a.render;a.render=function(fe,V){return c.call(V),u(fe,V)}}else{var p=a.beforeCreate;a.beforeCreate=p?[].concat(p,c):[c]}return{exports:n,options:a}}const ce={props:{blok:{type:Object}}},A={};var ue=le(ce,ie,ae,!1,he,null,null,null);function he(n){for(let e in A)this[e]=A[e]}var M=function(){return ue.exports}();const N=n=>{console.error(`You can't use ${n} if you're not loading apiPlugin. Please provide it on StoryblokVue initialization. | ||
`)};var de=(n,e={},t={})=>{const r=T.ref(null),s=x();return T.onMounted(async()=>{if(s){const{data:o}=await s.get(`cdn/stories/${n}`,e);r.value=o.story}else N("useStoryblok");r.value&&r.value.id&&C(r.value.id,o=>r.value=o,t)}),r};const pe={bind:(n,e)=>{if(e.value){const t=re(e.value);n.setAttribute("data-blok-c",t["data-blok-c"]),n.setAttribute("data-blok-uid",t["data-blok-uid"]),n.classList.add("storyblok__outline")}}};let _=null;const x=()=>(_||N("useStoryblokApi"),_),I={install(n,e={}){n.directive("editable",pe),n.component("StoryblokComponent",M);const{storyblokApi:t}=ne(e);_=t,n.prototype.$storyblokApi=t}};typeof window!="undefined"&&window.Vue&&window.Vue.use(I),h.StoryblokComponent=M,h.StoryblokVue=I,h.apiPlugin=te,h.renderRichText=oe,h.useStoryblok=de,h.useStoryblokApi=x,h.useStoryblokBridge=C,Object.defineProperties(h,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}); | ||
For more info about the richtext object check https://github.com/storyblok/storyblok-js#rendering-rich-text`),"";let t=k;return e&&(t=new O(e.schema),e.resolver&&A(t,e.resolver)),t.render(n)};var ie=function(){var e=this,t=e.$createElement,r=e._self._c||t;return r(e.blok.component,e._g(e._b({tag:"component"},"component",Object.assign({},e.$props,e.$attrs),!1),e.$listeners))},ae=[];function le(n,e,t,r,s,o,l,i){var a=typeof n=="function"?n.options:n;e&&(a.render=e,a.staticRenderFns=t,a._compiled=!0),r&&(a.functional=!0),o&&(a._scopeId="data-v-"+o);var c;if(l?(c=function(d){d=d||this.$vnode&&this.$vnode.ssrContext||this.parent&&this.parent.$vnode&&this.parent.$vnode.ssrContext,!d&&typeof __VUE_SSR_CONTEXT__!="undefined"&&(d=__VUE_SSR_CONTEXT__),s&&s.call(this,d),d&&d._registeredComponents&&d._registeredComponents.add(l)},a._ssrRegister=c):s&&(c=i?function(){s.call(this,(a.functional?this.parent:this).$root.$options.shadowRoot)}:s),c)if(a.functional){a._injectStyles=c;var u=a.render;a.render=function(fe,q){return c.call(q),u(fe,q)}}else{var p=a.beforeCreate;a.beforeCreate=p?[].concat(p,c):[c]}return{exports:n,options:a}}const ce={props:{blok:{type:Object}}},M={};var ue=le(ce,ie,ae,!1,he,null,null,null);function he(n){for(let e in M)this[e]=M[e]}var N=function(){return ue.exports}();const x=n=>{console.error(`You can't use ${n} if you're not loading apiPlugin. Please provide it on StoryblokVue initialization. | ||
`)};var de=(n,e={},t={})=>{const r=T.ref(null),s=I();return T.onMounted(async()=>{if(s){const{data:o}=await s.get(`cdn/stories/${n}`,e);r.value=o.story}else x("useStoryblok");r.value&&r.value.id&&P(r.value.id,o=>r.value=o,t)}),r};const pe={bind:(n,e)=>{if(e.value){const t=re(e.value);n.setAttribute("data-blok-c",t["data-blok-c"]),n.setAttribute("data-blok-uid",t["data-blok-uid"]),n.classList.add("storyblok__outline")}}};let _=null;const I=()=>(_||x("useStoryblokApi"),_),V={install(n,e={}){n.directive("editable",pe),n.component("StoryblokComponent",N);const{storyblokApi:t}=ne(e);_=t,n.prototype.$storyblokApi=t}};typeof window!="undefined"&&window.Vue&&window.Vue.use(V),h.RichTextSchema=E,h.StoryblokComponent=N,h.StoryblokVue=V,h.apiPlugin=te,h.renderRichText=oe,h.useStoryblok=de,h.useStoryblokApi=I,h.useStoryblokBridge=P,Object.defineProperties(h,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}); |
{ | ||
"name": "@storyblok/vue-2", | ||
"version": "1.3.0", | ||
"version": "1.3.1", | ||
"description": "Storyblok SDK for Vue 2 to interact with Storyblok API and connect to Storyblok Visual Editor", | ||
@@ -5,0 +5,0 @@ "main": "./dist/storyblok-vue-2.js", |
@@ -113,3 +113,3 @@ <div align="center"> | ||
app.use(StoryblokVue, { | ||
Vue.use(StoryblokVue, { | ||
accessToken: "<your-token>", | ||
@@ -119,4 +119,4 @@ use: [apiPlugin], | ||
app.component("Page", Page); | ||
app.component("Teaser", Teaser); | ||
Vue.component("Page", Page); | ||
Vue.component("Teaser", Teaser); | ||
``` | ||
@@ -147,4 +147,4 @@ | ||
<script setup> | ||
import { computed } from "@vue/composition-api"; | ||
import { renderRichText } from "@storyblok/vue"; | ||
import { computed } from "vue"; | ||
import { renderRichText } from "@storyblok/vue-2"; | ||
@@ -155,2 +155,48 @@ const articleContent = computed(() => renderRichText(blok.articleContent)); | ||
You can set a **custom Schema and component resolver globally** at init time by using the `richText` init option: | ||
```js | ||
import { RichTextSchema, StoryblokVue } from "@storyblok/vue-2"; | ||
import cloneDeep from "clone-deep"; | ||
const mySchema = cloneDeep(RichTextSchema); // you can make a copy of the default RichTextSchema | ||
// ... and edit the nodes and marks, or add your own. | ||
// Check the base RichTextSchema source here https://github.com/storyblok/storyblok-js-client/blob/master/source/schema.js | ||
app.use(StoryblokVue, { | ||
accessToken: "YOUR_ACCESS_TOKEN", | ||
use: [apiPlugin], | ||
richText: { | ||
schema: mySchema, | ||
resolver: (component, blok) => { | ||
switch (component) { | ||
case "my-custom-component": | ||
return `<div class="my-component-class">${blok.text}</div>`; | ||
default: | ||
return "Resolver not defined"; | ||
} | ||
}, | ||
}, | ||
}); | ||
``` | ||
You can also set a **custom Schema and component resolver only once** by passing the options as the second parameter to `renderRichText` function: | ||
```js | ||
import { renderRichText } from "@storyblok/vue-2"; | ||
renderRichText(blok.richTextField, { | ||
schema: mySchema, | ||
resolver: (component, blok) => { | ||
switch (component) { | ||
case "my-custom-component": | ||
return `<div class="my-component-class">${blok.text}</div>`; | ||
break; | ||
default: | ||
return `Component ${component} not found`; | ||
} | ||
}, | ||
}); | ||
``` | ||
#### Long Form | ||
@@ -157,0 +203,0 @@ |
Sorry, the diff of this file is not supported yet
66416
378